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

Marcus Goldfish magoldfish at gmail.com
Thu Dec 7 17:09:48 CET 2006


On 11/27/06, Michael P. Reilly <arcege at gmail.com> wrote:
>
> 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).


Doesn't python receive the command line argument, path-to-script in this
case, for its own use and parsing?

It seems like the solution I really seek is a command line switch that tells
python that I am using namespace conventions, and that it should begin
searching in the directory that PYTHONPATH points to.  For example,

c:> python -namespace utils.commands.mygrep.py

Do either of you know of such a convenience? I suppose I could write a batch
file, python.bat, that could implement this wrapping logic.


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.


Good spot-- forward slashes work, simply as relative path specifiers, so you
have to be in the correct directory.  I was not.  Thus the problem.  Also:
it appears forward slashes only work as relative path specifiers (e.g., cd
/temp), but fail if with a drive letter (e.g., c:/temp).

Thanks guys.
Marcus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061207/fb2e2fbe/attachment.htm 


More information about the Tutor mailing list