Difference between revisions of "Python"
Jump to navigation
Jump to search
Line 12: | Line 12: | ||
:sys.argv | :sys.argv | ||
− | :List of everything on the commandline. sys.argv[0] is the program itself. | + | :[[Python:DataTypes#list|List]] of everything on the commandline. sys.argv[0] is the program itself. |
;import getopt | ;import getopt |
Revision as of 21:00, 7 September 2018
Generic things:
The Python style guide is described in [PEP 8]
Modules
To add the location of your own modules to the python search path put it in the PYTHONPATH variable.
- import sys
- Number of system variables
- sys.argv
- List of everything on the commandline. sys.argv[0] is the program itself.
- import getopt
- Module to parse the commandline arguments (sys.argv). Default available
- import subprocess
- Module to execute shell commands
In python2
import subprocess
exitcode = subprocess.call("<any command>")
commandoutput = subprocess.check_output("<any command>")
Use ("command",shell=True) to have the call work like it would on the commandline
In python3
import subprocess
CompletedProcess = subprocess.run("<any command>")
The CompletedProcess returned has (args, returncode, stdout, stderr)