Re: newbie question




I'm brand new to using/playing with Python, and I have what is likely a
very simple question but can't seem to figure it out.

Python is fun and it's easier to use a real OS to develop the programs,
then if need be, not that difficult to move them to windows:)

I wrote up a script in my preferred text editor. It contains maybe ten
lines of code. I want to be able to execute those code lines with a
single command either from the inline mode or from IDLE. How do I do
this? I saved the file (myscript.py) in a folder that I've specified
in my PYTHONPATH environment variable, and when I type

If you are going to use a text editor to do python with, may I suggest
gVim, or vim it will take care of ALOT of syntax errors dure to
indentation for you. Grant it I am a command line junky, but still...


import myscript

the script runs. If, later during the same session, I type

myscript

all I get for output is

<module 'myscript' from 'c:\documents and settings\t_crane\my
documents\Python Modules\myscript.pyc'>

Somwhere in the beginning tutorial there's this line:

"The script can be given a executable mode, or permission, using the
chmod command:

$ chmod +x myscript.py"

Ok, the above seems to me like you are useing windows. If so, the chmod
commands are going to be just about worthless. If you install unix
services for windows, you will get some functionality, but not also, and
still what's the point. Linux is free and much more stable, secure,
etc...

Which I took to mean that if I enter that I would be able to do what I
wanted. But no, it just highlights 'myscript' in red and says it's a
syntax error.

What am I missing?
OK, excuseing my editorial comments above, here is what I see and
correct me if I'm wrong.
1) you use windows
2) You have not been around any OS other than windows
and I mean this as no insult, just making sure I understand you. The
answer to your questions are as follows. In Unix/Linux/XXix/Solaris and
most anyother unixy(yes that's a word, I just made it up) OS you can add
the first line of the script being something like
#!/usr/bin/python
or where ever you installed python to, then FROM A COMMAND LINE run
chmod <perms> <file name and path>
and it will make the script executable. What happens is when you tell
the script to run, it looks at the line and then knows where to pull the
inter. from. the # just comments it out so it don't try to run it with
the rest of the script, the ! tells the computer to pay attention to it.
As far as I know, you cannot do this in Windows. to run it in a single
command, you would have to either compile it with py2exe which will give
you the .exe and a dll or two or you can simple make a batch file that
would look something like
@ECHO OFF
<path to python>python <path to script>script.py
the @ECHO OFF is not needed, but I think it looks better and more
professional, but that is just me. I do realize I have rambled on for a
while here but I do hope it helps. I have been out of the python loop
for a while, but am being forced back into it, which really don't hurt
my feelings at all, just had to wait for a project that required it:)
Anyway if you dont understand anything just let me know and i'll try to
do a better job explaining it.

Paul

.



Relevant Pages

  • Re: batch file to delete files based on criteria
    ... The Advanced Version of Snapshot will create date/time coded backups that ... This script is included with the FREE Advanced NT/2K/XP/K3 Command Library ... script will perform CONSISTENTLY under Windows NT4, 2000, XP and Server ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Installing WebDAV server
    ... sh-based UNIX/Linux shell prompt). ... But never with Python, so I hadn't got a clue about the prompt. ... OSes have command shells, too, you know; they are just named and run ... Look for the Windows version. ...
    (comp.lang.python)
  • Re: IP connections
    ... produces output, depending on the command. ... start that script with the systemfunction. ... connect to the telnet port of the hi-tech device in the C ... recommend Python with the "telnetlib" library: ...
    (comp.lang.c)
  • Re: IP connections
    ... produces output, depending on the command. ... start that script with the systemfunction. ... If you already have a favourite, such as perl, python, ... There are lots of complicated areas for experts, but most users can come a long way with the basics and the ready-made libraries. ...
    (comp.lang.c)
  • Re: WshShell.Exec output read impossible until command finished
    ... I've done a script to force remove of old DCs. ... I'm using NTDSUTIL command line tool for that, ... How can I have a live output read (like under Windows 2003 DC)? ...
    (microsoft.public.scripting.vbscript)