Let's say I input "A" to the Python program and run it. This would take some time. Rather than waiting and doing nothing, I change the input to "B" in the source code and run another instance of the program. The two instances will output some results when they're done. Would this work or would this mess up some stuff?
2 Answers
This should work, assuming the permissions on your system allow you to edit a file that has already been started running - as abarnert indicates in his comment, on Windows your editor and the python.exe process may both try to lock the file while it's being used. When a Python script is started, the contents of the file are read into memory, so theoretically you should be able to then modify those contents and rerun the file again. However, these changes will not affect the initial run.
There are some cases where Python needs to read the source after execution has begun: a few instances are printing exceptions and various methods related to code introspection, for example. However, if you're just changing a small bit of information, such as a hard-coded source data file, or a beginning directory, there shouldn't be any issues. Ultimately, in the long run, if you find yourself doing this a lot, do as abarnert suggested up top and structure your program in such a way that you don't hard-code the information you need to change, and instead pass it as a command-line argument, config file, or dynamically-read parameter such as an input() (or raw_input(), in Python 2) statement.
AorBthrough, e.g., a command-line argument, or a config file, so you don't have to edit the source? If you want to look at the contents of one directory, then look at the contents of a different directory, you don't edit thelsordircommand, do you?