0

I want to be able to dynamically change the value of a variable of a Python program outside of the program from another Python program. I have this function:

def main():
    PATH = 'path/to/file'

Is there a way to edit this variable from another Python program? The only way I can think of is sharing a text file between the two files, one inputs into it, one extracts from it.

5
  • Have you considered RPC calls like XMLRPC? Commented Jul 1, 2014 at 13:07
  • Hmm no I haven't heard of that. I'll look into that, thanks. Commented Jul 1, 2014 at 13:08
  • 2
    What's your use case? There are so many ways of doing this. Commented Jul 1, 2014 at 13:09
  • A similar use case to the shared text file would be a database. Commented Jul 1, 2014 at 13:10
  • 1
    If you simply want to pass a path to some file to another program, maybe the easiest thing to do is to have the function accept that path as an argument? def main(path='/default/path'): ... Commented Jul 1, 2014 at 13:13

1 Answer 1

0

You indeed need to make configuration file. You can write some kind of parser for your .py file, search for desired string and edit it, but that's something I would not recommend you to do (take a look at this question).
For 'text file' solution take a look at ConfigParser

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.