Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83128 > unrolled thread

Command Line Inputs from Windows

Started by"Ken Stewart" <gordon_ken_stewart@msn.com>
First post2015-01-02 12:44 -0700
Last post2015-01-02 12:44 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Command Line Inputs from Windows "Ken Stewart" <gordon_ken_stewart@msn.com> - 2015-01-02 12:44 -0700

#83128 — Command Line Inputs from Windows

From"Ken Stewart" <gordon_ken_stewart@msn.com>
Date2015-01-02 12:44 -0700
SubjectCommand Line Inputs from Windows
Message-ID<mailman.17330.1420229023.18130.python-list@python.org>
Court of King Arthur,

I’d appreciate any help you can provide.  I’m having problems passing 
command line parameters from Windows 7 into a Python script (using Python 
3.4.2).  It works correctly when I call the interpreter explicitly from the 
Windows command prompt, but it doesn’t work when I enter the script name 
without calling the Python interpreter.

This works:
python myScript.py arg1 arg2 arg3

This doesn’t work:
myScript.py arg1 arg2 arg3

The Windows PATH environment variable contains the path to Python, as well 
as the path to the Script directory.  The PATHEXT environment variable 
contains the Python extension (.py).

There are other anomalies too between the two methods of invoking the script 
depending on whether I include the extension (.py) along with the script 
name.  For now I’m only interested in passing the arguments without 
explicitly calling the Python interpreter.

************************************
Here is the script:

#! python

import sys

def getargs():
    sys.stdout.write("\nHello from Python %s\n\n" % (sys.version,))
    print ('    Number of arguments =', len(sys.argv))
    print ('    Argument List =', str(sys.argv))

if __name__ == '__main__':
    getargs()

************************************
Result_1 (working correctly):

C:\Python34\Scripts> python myScript.py arg1 arg2 arg3

Hello from Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC 
v.1600 32 bit (Intel)]

    Number of arguments = 4
    Argument List = ['myScript.py', 'arg1', 'arg2', 'arg3']

************************************
Result_ 2 (Fail)

C:\Python34\Scripts> myScript.py arg1 arg2 arg3

Hello from Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC 
v.1600 32 bit (Intel)]

    Number of arguments = 1
    Argument List = ['C:\\Python34\\Scripts\\myScript.py']

As a beginner I’m probably making a mistake somewhere but I can’t find it. 
I don’t think the shebang does anything in Windows but I’ve tried several 
variations without success.  I’ve tried writing the script using only 
commands, without the accouterments of a full program (without the def 
statement and without the if __name__ == ‘__main__’ …) to no avail.  I’m out 
of ideas.  Any suggestions?

Ken Stewart

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web