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

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. Note: If you are running in windows you should use double slash “//” otherwise it gives error 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 … Read more

python IDLE shell appears not to handle some escapes correctly

What am I doing wrong or what should I be looking for? Is it reasonable to expect backspace, specifically, to work? No, IDLE does not support backspace, nor carriage-return, nor formfeed, nor ANSI escape sequences. You are expecting \b to move the cursor one cell to the left in IDLE’s interactive shell window. It doesn’t … Read more

Import module works in terminal but not in IDLE

This typically occurs when multiple versions of python are installed with different paths. You can check to see if you have multiple installations by opening up the IDLE terminal and using import sys sys.version sys.path These commands will print the system PATH and version of the current instance of python. Use this in both IDLE … Read more

tech