Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Windows': 0.02; 'parameters': 0.04; 'argument': 0.05; 'beginner': 0.05; 'explicitly': 0.05; 'interpreter': 0.05; '(using': 0.07; 'interpreter.': 0.07; 'sys': 0.07; '__name__': 0.09; 'arguments': 0.09; 'i\xe2\x80\x99ve': 0.09; '\xe2\x80\xa6)': 0.09; 'python': 0.11; 'def': 0.12; 'windows': 0.15; "'__main__':": 0.16; '(without': 0.16; 'arthur,': 0.16; 'invoking': 0.16; 'i\xe2\x80\x99d': 0.16; 'i\xe2\x80\x99m': 0.16; 'received:65.55.34.15': 0.16; 'skip:[ 30': 0.16; 'subject:Line': 0.16; 'variations': 0.16; 'variable': 0.18; 'bit': 0.19; 'passing': 0.19; 'command': 0.22; 'import': 0.22; 'print': 0.22; 'commands,': 0.24; 'directory.': 0.24; 'environment': 0.24; 'script': 0.25; 'extension': 0.26; 'somewhere': 0.26; 'tried': 0.27; 'court': 0.30; 'statement': 0.30; 'skip:( 20': 0.30; 'along': 0.30; 'provide.': 0.31; 'work:': 0.31; 'probably': 0.32; 'subject:from': 0.34; 'but': 0.35; 'there': 0.35; 'too': 0.37; 'two': 0.37; 'list': 0.37; 'problems': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'does': 0.39; 'success.': 0.39; 'to:addr:python.org': 0.39; 'full': 0.61; 'making': 0.63; 'name': 0.63; 'skip:\xe2 10': 0.65; 'here': 0.66; 'between': 0.67; '8bit%:43': 0.74; '2014,': 0.84; 'can\xe2\x80\x99t': 0.84; 'ideas.': 0.84; 'stewart': 0.84; 'don\xe2\x80\x99t': 0.91; 'mistake': 0.91; 'from:addr:msn.com': 0.97 X-TMN: [fAoDBeQJ2C0ICSGeGXZq2YvSg3H1+gwP] X-Originating-Email: [gordon_ken_stewart@msn.com] From: "Ken Stewart" To: Subject: Command Line Inputs from Windows Date: Fri, 2 Jan 2015 12:44:55 -0700 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=original Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 16.4.3528.331 X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3528.331 X-OriginalArrivalTime: 02 Jan 2015 19:45:02.0777 (UTC) FILETIME=[99B20290:01D026C4] X-Mailman-Approved-At: Fri, 02 Jan 2015 21:03:41 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 69 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420229023 news.xs4all.nl 2970 [2001:888:2000:d::a6]:47588 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83128 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