[Tutor] sound implementation problems
eryksun
eryksun at gmail.com
Fri Jun 14 17:49:29 CEST 2013
On Thu, Jun 13, 2013 at 11:55 PM, Jim Mooney <cybervigilante at gmail.com> wrote:
>
> My IDE startup script has been changed to also go to the proper working
> directory.
> BUT - Py 3.3 at the command prompt uses my 3.3 working directory, and Py 2.7
> ALSO uses the 3.3 working directory, which is not what I want, obviously.
> Those are two different sets of scripts that won't always play together.
Why would running python.exe change the current working directory?
Anyway, I don't know much about ActivePython, so I shouldn't even ask.
> Is there a way to set up each different interpreter, either Py 3.3 or Py
> 2.2, to automatically change to a particular working directory when you call
> it - with a command line switch for instance? I can os.chdir after it
> starts, of course, but that's a drag and I'll forget to do it at some point.
> If I can do that from the call to Python I can make a batch file for each
> one, with two different names - and easy typing ones like Py27 and Py33 ;')
Is this for imports relative to the current directory? If so I
recommend using the user site-packages in your profile directory. Run
the following to print its location:
import site
print(site.getusersitepackages())
It's probably the following directory (but I know next to nothing
about ActivePython):
"%appdata%\Python\Python??\site-packages"
(substitute the 2-digit version number for ??)
Using this directory avoids sharing paths between interpreters via the
PYTHONPATH environment variable. Just add a .pth file containing the
absolute path to your personal library of modules/packages for
Python??.
> I see one possible candidate in python --help
> -c cmd : program passed in as string (terminates option list)
>
> But what does "program passed in as a string(terminates option list)" mean?
> How do I stringify import os > os.chdir('my directory') ? That's unclear to
> me.
I don't agree with the end goal here, but running a micro-script from
the shell can be convenient, especially when paired with
macros/aliases. Here's how to start Python in a particular directory:
C:\>python -i -c "import os; os.chdir('C:/Python33')"
>>> os.getcwd()
'C:\\Python33'
-i drops into interactive mode after the command completes. In Windows
you have to use double quotes for the argument after -c. But
single-quotes are fine for string literals within the command.
The Windows command-line is a bit weird in that it stores
per-executable input history and aliases in the console itself instead
of in the shell. In some ways it's convenient because it lets you
define aliases that target a particular exe, such as python.exe or
cmd.exe. And if you quit and restart (the program, not the console
window), it remembers your history (press F7 for a pop-up scrollbox).
Anyway, the interface should be familiar to anyone who ever used
MS-DOS. It's doskey (no, it's not a DOS program):
C:\>doskey calc=c:\python33\python -c "from cmath import *;print($*)"
C:\>calc e**(1j*pi/3)
(0.5000000000000001+0.8660254037844386j)
$1 is parameter 1, and so on, and $* globs all of the parameters.
More information about the Tutor
mailing list