[Tutor] __init__.py for running a file from commandline?
kent37 at tds.net
Mon Nov 27 18:38:59 CET 2006
Marcus Goldfish wrote:
> On 11/11/06, *Kent Johnson* <kent37 at tds.net <mailto: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
> > files. For example, PYTHONPATH points to ~pyroot, and I have the
> > ~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
> > line. I would like to do this:
> > > python utils.commands.mygrep.py <http://utils.commands.mygrep.py>
> > but it doesn't work. Is there a trick, or something that I am
> > 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
> if it will work with imports.
> 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?
It works for me on WinXP to run a simple script with no dependencies,
with forward or back slashes. I don't have PYTHONPATH set at all. How
does it fail for you?
More information about the Tutor