What’s the working directory when using IDLE?

You can easily check that yourself using os.getcwd: >>> import os >>> os.getcwd() ‘C:\\Program Files\\Python33’ That’s on my Windows machine, so it’s probably the installation directory of Python itself. You can change that directory at runtime using os.chdir: >>> os.chdir(‘C:\\Users\\poke\\Desktop\\’) >>> os.getcwd() ‘C:\\Users\\poke\\Desktop’ >>> with open(‘someFile.txt’, ‘w+’) as f: f.write(‘This should be at C:\\Users\\poke\\Desktop\\someFile.txt now.’) … Read more

Pasting multiple lines into IDLE

Probably not the most beautiful procedure, but this works: cmds=””‘ paste your commands, followed by ”’: a = 1 b = 2 c = 3 ”’ Then exec(cmds) will execute them. Or more directly, exec(”’ then paste your commands, followed by ”’): a = 1 b = 2 c = 3 ”’) It’s just a … Read more

How to run a python script from IDLE interactive shell?

Python3: exec(open(‘helloworld.py’).read()) If your file not in the same dir: exec(open(‘./app/filename.py’).read()) See https://stackoverflow.com/a/437857/739577 for passing global/local variables. In deprecated Python versions Python2 Built-in function: execfile execfile(‘helloworld.py’) It normally cannot be called with arguments. But here’s a workaround: import sys sys.argv = [‘helloworld.py’, ‘arg’] # argv[0] should still be the script name execfile(‘helloworld.py’) Deprecated since 2.6: … Read more

Can multiprocessing Process class be run from IDLE

Yes. The following works in that function f is run in a separate (third) process. from multiprocessing import Process def f(name): print(‘hello’, name) if __name__ == ‘__main__’: p = Process(target=f, args=(‘bob’,)) p.start() p.join() However, to see the print output, at least on Windows, one must start IDLE from a console like so. C:\Users\Terry>python -m idlelib … Read more