> For the complete documentation index, see [llms.txt](https://docs.arkannis.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arkannis.net/programming/courses/python-pcap-31-03-course/file-io-and-exception-handling/argv-command-line-arguments-and-the-re-module.md).

# argv Command Line Arguments and the re Module

## Accepting arguments from command line

```python
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 below
* You would run this from the command line like this:

```
python3 /path/to/application.py <arg1> <arg2>
```

## The [re module](https://www.w3schools.com/python/python_regex.asp) (RegEX Module)

* Search for things using regular expressions
* The `re.findall("string", text_variable)` returns a list of the times it found the string
  * Example:

```python
import re

text = "The rain in Spain"
x = re.findall("ai", txt)
print(x)
# Returns list ["ai", "ai"]
```
