> 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"]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET 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?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
