Prev: ANN: GMPY 1.12 and GMPY2 unstable released
Next: CONTROLLED DEMOLITION INC explosive-charge placement technician Tom ?Sullivan 911 TESTIMONIAL Video
From: Kermit Rose on 27 Jun 2010 06:52 On 6/26/2010 9:30 PM, python-list-request(a)python.org wrote: > > Today's Topics: > > 2. Re: Python interface problem with Windows (Benjamin Kaplan) > > Message: 2 > Date: Sat, 26 Jun 2010 16:26:47 -0700 > From: Benjamin Kaplan <benjamin.kaplan(a)case.edu> > To: python-list(a)python.org > Subject: Re: Python interface problem with Windows > Message-ID: > <AANLkTinFCPAdsVfR0z4nmlwRAakSzRkUa9oEQGypB7bS(a)mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > You don't need to save scripts in C:\Python26. In fact, doing so is a > very bad idea. You should keep the libraries in one place (that would > be C:\Python26 ) and all of your individual programs somewhere else > (like your Documents folder) where you don't have to worry if two > different projects have files of the same name. For security reasons, > you don't have permission to write to the whole hard drive, just your > home directory. I do not know how to import code from any other directory than the default, C:\Python26. And how do I save the code in a different directory than the default, c:\Python26? Kermit Rose
From: rantingrick on 27 Jun 2010 07:11 On Jun 27, 5:52 am, Kermit Rose <ker...(a)polaris.net> wrote: > On 6/26/2010 9:30 PM, python-list-requ...(a)python.org wrote: > I do not know how to import code from any other directory than the > default, C:\Python26. Kermit, There are a couple of ways to import python modules from various places. But first create a folder somewhere (like was mentioned earlier) to keep all your personal modules and scripts in. Now create a file named "myconfig.pth" and throw it in your main PythonXX folder. Any paths in this file will be added to the search path of Python modules. Now you can import from these folders Also so you will be aware. You can add folders to the python search path by appending or inserting to the sys.path array. >>> import sys >>> print sys.path [...list of paths here...] >>> sys.path.append('path\to\some\directory\containing\script.py') >>> import script.py There are other ways...
From: Terry Reedy on 27 Jun 2010 12:34
On 6/27/2010 6:52 AM, Kermit Rose wrote: > I do not know how to import code from any other directory than the > default, C:\Python26. I personally took the easy way. I put my package of modules in pthonxy/Lib/site-packages, which is already on the search path from package import mymod from package.mymod import myfunc > And how do I save the code in a different directory than the default, > c:\Python26? For miscellaneous scripts, I use a directory I added? pythonxy/misc. I edit with IDLE. When it starts up, the current directory is pythonxy/. When I start a new file, I immediately select save-as, change to ./misc, and save something.py. Note that one needs to type the .py even if the type is selected. Also, I keep a ./misc/tem file. That is easy to select from 'recent files' on the menu. If I decide I want to keep the file, I save under a new name, leaving misc/tem to be erased and reused for another throwaway script. The python uninstaller does not delete user-made directories. When I install a new version, it is easy to move or copy to the new tree. -- Terry Jan Reedy |