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: mahela007 is an unknown quantity at this point 
Solved Threads: 1
mahela007 mahela007 is offline Offline
Junior Poster

What does the sys module do in python?

 
0
  #1
Aug 22nd, 2009
What does the sys module do in python?
and what is sys.argv?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 223
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: What does the sys module do in python?

 
0
  #2
Aug 23rd, 2009
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 162
Reputation: mahela007 is an unknown quantity at this point 
Solved Threads: 1
mahela007 mahela007 is offline Offline
Junior Poster

Re: What does the sys module do in python?

 
0
  #3
Aug 23rd, 2009
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."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: What does the sys module do in python?

 
0
  #4
Aug 23rd, 2009
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,151
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 952
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: What does the sys module do in python?

 
2
  #5
Aug 23rd, 2009
Maybe a little example will help ...
  1. import sys
  2.  
  3. args = sys.argv
  4.  
  5. print(args)
  6. print( "Source file: %s" % args[0] )
  7. # use any of these arguments in your code
  8. print( "Argument one: %s" % args[1] )
  9. print( "Argument two: %s" % args[2] )
  10.  
  11.  
  12. """
  13. my output after saving this code as sysargs1.py and
  14. entering a few arguments on the command line -->
  15. ['D:/Python25/Bull/sysargs1.py', 'myarg1', 'myarg2']
  16. Source file: D:/Python25/Bull/sysargs1.py
  17. Argument one: myarg1
  18. Argument two: myarg2
  19. """
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 162
Reputation: mahela007 is an unknown quantity at this point 
Solved Threads: 1
mahela007 mahela007 is offline Offline
Junior Poster

Re: What does the sys module do in python?

 
0
  #6
Aug 24th, 2009
So for the last two to have values, is it compulsory for the program to be run via command line?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 223
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: What does the sys module do in python?

 
0
  #7
Aug 24th, 2009
You can run it with module subprocess as well
  1. import subprocess
  2. child = subprocess.Popen("sysargs1.py myarg1 myrag2", shell=True)
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 162
Reputation: mahela007 is an unknown quantity at this point 
Solved Threads: 1
mahela007 mahela007 is offline Offline
Junior Poster

Re: What does the sys module do in python?

 
0
  #8
Aug 25th, 2009
What does that module do?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 223
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: What does the sys module do in python?

 
1
  #9
Aug 25th, 2009
It allows your program to launch other programs and communicate with them.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 162
Reputation: mahela007 is an unknown quantity at this point 
Solved Threads: 1
mahela007 mahela007 is offline Offline
Junior Poster

Re: What does the sys module do in python?

 
0
  #10
Aug 25th, 2009
thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 580 | Replies: 9
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC