Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default save path for Python IDLE?

Does anyone know where or how to set the default path/directory on saving python scripts prior to running?

On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?

like image 708
rh0dium Avatar asked Sep 14 '09 23:09

rh0dium


People also ask

How do I save a Python program in IDLE?

Right-click the Python window and select Save As to save your code either as a Python file (. py) or Text file (. txt). If saving to a Python file, only the Python code will be saved.


4 Answers

On OS X, if you launch IDLE.app (by double-clicking or using open(1), for example), the default directory is hardwired to ~/Documents. If you want to change the default permanently, you'll need to edit the file idlemain.py within the IDLE.app application bundle; depending on which Python(s) you have installed, it will likely be in one of:

/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPorts/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 3.x/IDLE.app/Contents/Resources

Edit the line:

os.chdir(os.path.expanduser('~/Documents'))

On the other hand, if you start IDLE from the command line, for example, with:

$ cd /some/directory    
$ /usr/local/bin/idle

IDLE will use that current directory as the default.

like image 167
Ned Deily Avatar answered Sep 22 '22 06:09

Ned Deily


I actually just discovered the easiest answer, if you use the shortcut link labeled "IDLE (Python GUI)". This is in Windows Vista, so I don't know if it'll work in other OS's.

1) Right-click "Properties".

2) Select "Shortcut" tab.

3) In "Start In", write file path (e.g. "C:\Users...").

Let me know if this works!

like image 45
Steven Choi Avatar answered Sep 20 '22 06:09

Steven Choi


It seems like you can get idle into the directory you want if you run any module from that directory.

I had previously tried opening idlemain.py through the path browser. I was able to open and edit the file, but it seemed like I wasn't able to save my modifications.

I'm just glad to hear other people are having this problem. I just thought I was being stupid.

like image 37
s.dicks Avatar answered Sep 22 '22 06:09

s.dicks


If you open a module, that sets the default working directory.

Start IDLE.

File -> Open to open your file. And set the current working directory.

like image 24
S.Lott Avatar answered Sep 22 '22 06:09

S.Lott