Re: SV: Running test01.py under Windows (basic level)



En Fri, 29 Feb 2008 02:30:43 -0200, K Viltersten <tmp1@xxxxxxxxxxxxxx> escribió:

I have v2.5.2 installed and i've composed
a source code i'm sure everybody will be
impressed by. It goes like this.

def bloppA ():
print "a very advanced piece of code"

What i get to work is to make it run from
the the snakes shell. Then, i realised
that such a masterpiece needs storing in
a file. So i saved it in a file called
great.py but when i executed:

python great.py
from the system prompt (cmd).
Or, if you are using IDLE ...
File -> Open, open your saved file, and use
the Run menu (or press F5).

There will be poking around with %PATH%, i can
tell. Never liked to do that under Windows.

No need to do that... Create an "alias.txt" file containing:
python=c:\path\to\your\python.exe $*

Execute (once, logged as administrator):
reg add "HKLM\SOFTWARE\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "doskey /macrofile=path\to\your\alias.txt"

Open a new cmd console. Typing python is enough to invoke the interpreter - no need to modify PATH.

Documentation for the DOSKEY command: http://technet2.microsoft.com/WindowsServer/en/library/f7f45601-5178-48c6-9219-51bd6f7abd3f1033.mspx

If you don't like the above recipe, create a "python.cmd" file containing:
@c:\path\to\your\python.exe %*
and save it somewhere in your PATH.

Beware of \ as it's the escape character, so
you have to use "c:\\loj\\python\\great.py"
or r"c:\loj\python\great.py"...

I've tried to add the extra backslashes (or "r"
attribute) but i still get the same error at
the colon. Should i understand that i made two
mistakes (the first being not using double "\"
and the second calling exec alltogether)?

exec is used to execute a string containing python code, not a file name. execfile does what you want, but don't use it. Either execute your program with `python name.py`, or load it into IDLE and run it with F5, or learn how to make your favorite IDE/text editor Python-aware (if supported).

have you worked out the Tutorial?

Not yet. I started off using some small things.
I tend to learn by doing. Or rather making. A
lot of errors, that is. :)

At least overview it. Python syntax is very clear and legible, so probably you can figure yourself a lot of things, but there are some important topics that you have to know and are explained in the Tutorial. It isn't very long.

--
Gabriel Genellina

.



Relevant Pages

  • Re: Learning Tkinter
    ... and how the command option is used to call the function callback. ... gui programming to see if the python programs I have written can be made ... search their computer for this file, execute the python code and then ... This is the meaning of the test on __name__: this magical variable is set to the string '__main__' if and only if the current script is the top-most one, i.e the one you ran python on. ...
    (comp.lang.python)
  • Re: Using Python in ActiveX task - works when run as separate step
    ... when executing the package. ... Peter Yang, if you can detail some of what you did to get Perl working, I'd ... >> was trying to use Python in this case because I know it a little better than ... >>>You could execute the step in DTS package window. ...
    (microsoft.public.sqlserver.dts)
  • Re: Simple Python class questions
    ... code (ie not contained within a def block) in the module might run ... Python starts executing at the top of your main script and then proceeds ... module and execute the lines of code in the module from top to bottom ... then the import simply returns immediately and does the assignment. ...
    (comp.lang.python)
  • Re: Import without executing module
    ... ten different places only the first will compile and execute the code, ... Python user....let me give it a try. ... It is the execution of the byte code that creates the module's namespace ...
    (comp.lang.python)
  • Re: Python, multithreading & GIL
    ... written in Python, and the part written in C - modules written ... actually be executing the interpreter, ... They will execute serially. ... Donn Cave, donn@u.washington.edu ...
    (comp.lang.python)