[Tutor] __init__.py for running a file from commandline?

Michael P. Reilly arcege at gmail.com
Mon Nov 27 18:40:26 CET 2006


Marcus,

When you type something from the command-line, you are at the whims of the
WinXP command shell.  You have to follow its rules, not Python's.  It would
need to have "python" in %PATH%, and then it would need to have to run
"python C:\path\to\pyroot\utils\commands\mygrep.py".  The arguments are
determined before Python is even started, and they are parsed by the WinXP
DOS-a-like shell. (Also why you cannot have ".", only Python understands
dots).

Kent mentioned issues with importing modules, and those would still hold
true since those are after Python starts.  Also, the WinXP shell, does
handle forward slashs, but you were probably not in the proper directory for
the shell to find the file using "utils/commands/mygrep.py" pathname.

HTH,
  -Arcege

On 11/27/06, Marcus Goldfish <magoldfish at gmail.com> wrote:
>
>
>
> On 11/11/06, Kent Johnson <kent37 at tds.net> wrote:
> >
> > Marcus Goldfish wrote:
> > > Hoping someone can help with this...
> > >
> > > I have a logical python namespace using a directory tree and
> > __init__.py
> > > files.  For example, PYTHONPATH points to ~pyroot, and I have the
> > following:
> > >
> > > ~pyroot/
> > > ~pyroot/utils/
> > > ~pyroot/utils/commands/mygrep.py
> > >
> > > Which makes it nice to code:
> > >
> > > # some python script
> > > import utils.commands.mygrep as grep
> > >
> > > However, I have a problem when running python scripts from the command
> > > line.  I would like to do this:
> > >
> > >  > python utils.commands.mygrep.py
> > >
> > > but it doesn't work.  Is there a trick, or something that I am
> > missing,
> > > that will let me run scripts like that?
> >
> > python utils/commands/mygrep.py
> > will work if mygrep.py doesn't import other modules from utils; not sure
> >
> > if it will work with imports.
> >
> > Kent
>
>
> Kent,
>
> Hmmm... I tried this on my WinXP box-- didn't work nor with
> backslashing).  I checked my environment variables in my shell, and
> PYTHONPATH points to ~pyroot.  Am I missing something?  Could this be a 'nix
> thing?
>
> Marcus
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>


-- 
There's so many different worlds,
So many different suns.
And we have just one world,
But we live in different ones.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061127/dddc4772/attachment.htm 


More information about the Tutor mailing list