Default save path for Python IDLE?
Asked Answered
A

11

11

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?

Agitator answered 14/9, 2009 at 23:28 Comment(1)
possible duplicate: #15368188Stores
B
7

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.

Brachyuran answered 15/9, 2009 at 4:13 Comment(0)
Z
3

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!

Zimmer answered 10/12, 2013 at 16:44 Comment(0)
K
3

In Windows 10+, click the Windows Start button, then type idle, and then right-click on the IDLE desktop app and open the file location. This should bring you to the Start Menu shortcuts for Python, and you'll find a shortcut to IDLE there. Right-click on the IDLE shortcut and select properties. Set the "Start in" directory to be where you want default save path to be.

Kassel answered 16/11, 2018 at 15:26 Comment(0)
M
2

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.

Moises answered 1/3, 2011 at 22:37 Comment(0)
H
1

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.

Histoplasmosis answered 15/9, 2009 at 0:12 Comment(0)
B
1

In my case, the default directory is set to the directory from which I launched IDLE. For instance, if I launched IDLE from a directory called 'tmp' in my home directory, the default save path is set to ~/tmp. So start your IDLE like this:

~/tmp $ idle
[...]
Blastoderm answered 15/9, 2009 at 0:56 Comment(1)
This is true - but there isn't a way to do it from an Application Executable.Agitator
M
1

On Windows (Vista at least, which is what I'm looking at here), shortcut icons on the desktop have a "Start in" field where you can set the directory used as the current working directory when the program starts. Changing that works for me. Anything like that on the Mac? (Starting in the desired directory from the command line works, too.)

Mavis answered 15/9, 2009 at 1:45 Comment(0)
C
1

For OS X:

Open a new finder window,then head over to applications. Locate your Python application. (For my mac,it's Python 3.5)

Double click on it. Right click on the IDLE icon,show package contents. Then go into the contents folder,then resources.

Now,this is the important part:

(Note: You must be the administrator or have the administrator's password for the below to work)

Right click on the idlemain.py,Get Info.

Scroll all the way down. Make sure under the Sharing & Permissions tab,your "name"(Me) is on it with the privilege as Read & Write. If not click on the lock symbol and unlock it. Then add/edit yourself to have the Read & Write privilege.

Lastly,as per Ned Deily's instructions,edit the line:

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

with your desired path and then save the changes.

Upon restarting the Python IDLE,you should find that your default Save as path to be the path you've indicated.

Corbin answered 13/2, 2016 at 4:14 Comment(0)
E
1

I am using windows 7 and by going to Start-> IDLE(Python 3.6 32-bit)

The click on properties and then in the shortcut tab go to Start in and entering the desired path worked for me kindly note if IDLE is open and running while you do this you'll have to shut it down and restart it for this to work

Encephaloma answered 10/5, 2017 at 18:49 Comment(0)
R
0

If you locate the idlelib directory in your Python install, it will have a few files with the .def extension. config-main.def has instructions on where to put the custom config files. However, looking through these I did not find any configurable paths (your install may vary). Looks like you might need to crack open the editor code to alter it.

Revenant answered 15/9, 2009 at 0:10 Comment(1)
Yeah this was what I ran up against too. I looked through the *.defs expecting to see an obvious save dir variable but nope..Agitator
A
0

If you are using linux, you can create simple .sh file as presented below::

#!/bin/sh
cd /fullPath/PythonScripts/  

idle
  • make the file executable by right click-> properties-> permissions-> check the execute as program checkbox-> done

Run the file :)

Airship answered 9/8, 2019 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.