argv Command Line Arguments and the re Module
Accepting arguments from command line
import sys
argument_1 = sys.argv[1]
argument_2 = sys.argv[2]
print(argument_1, argument_2)
# To accept an unlimited amount of args:
agrument_infinite = sys.argv[1:]
# agrument_infinite will be a list
# To itterate through arguments:
for arg in agrument_infinite:
print(arg)
argv[0]
- is by default the name of the application -application.py
from belowYou would run this from the command line like this:
python3 /path/to/application.py <arg1> <arg2>
The re module (RegEX Module)
Search for things using regular expressions
The
re.findall("string", text_variable)
returns a list of the times it found the stringExample:
import re
text = "The rain in Spain"
x = re.findall("ai", txt)
print(x)
# Returns list ["ai", "ai"]
Last updated