| | |
What does the sys module do in python?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 162
Reputation:
Solved Threads: 1
That's exactly where I checked. I don't understand what the documentation says..
More specifically I don't understand this
"sys.argv¶
The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string."
More specifically I don't understand this
"sys.argv¶
The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string."
Maybe a little example will help ...
python Syntax (Toggle Plain Text)
import sys args = sys.argv print(args) print( "Source file: %s" % args[0] ) # use any of these arguments in your code print( "Argument one: %s" % args[1] ) print( "Argument two: %s" % args[2] ) """ my output after saving this code as sysargs1.py and entering a few arguments on the command line --> ['D:/Python25/Bull/sysargs1.py', 'myarg1', 'myarg2'] Source file: D:/Python25/Bull/sysargs1.py Argument one: myarg1 Argument two: myarg2 """
May 'the Google' be with you!
You can run it with module subprocess as well
python Syntax (Toggle Plain Text)
import subprocess child = subprocess.Popen("sysargs1.py myarg1 myrag2", shell=True)
![]() |
Similar Threads
- Starting Python (Python)
- python with html (Python)
- Python - statistical functions + a list (Python)
- Python for Laptop Robot Speech recognition and TTS. (Python)
- python and bash (Python)
- Where's Nemo? (Python)
- python extending with c(doubts) (Python)
- Convert from JAVA/JSP to Python (Python)
- using distutils to install a python module (Python)
- How to use 'top' using Python (Python)
Other Threads in the Python Forum
- Previous Thread: Download function
- Next Thread: stcuk with dictionary
Views: 580 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm aliased application beginner calculator casino character code command cursor cx-freeze definedlines development dictionary dynamic error event examples excel exe file filename float format ftp function google graphics gui homework ideas import input java launcher line linux list lists logging loop matching microphone mouse movingimageswithpygame newb number numbers obexftp output parsing path permissions phonebook port prime program programming projects py2exe pygame pygtk pyqt pysimplewizard python random recursion recursive refresh return reverse scrolledtext shebang simple skinning sprite ssh statistics string strings table terminal text thread threading time tkinter tlapse tricks tuple tutorial ubuntu unicode urllib urllib2 valueerror variable voip windows wxpython






