Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python append to system arguments - bad practice?

I'm parsing system arguments in my Python project using sys.argv. At some point i had to modify the script after having written the logic that parses system args. I added a line the basically appends a string to sys.argv so the logic that parses it won't be changed -

sys.argv.append('some string here')

Is it a bad practice to modify the system arguments after they have been created for the program ?

like image 383
Caffeine Avatar asked Aug 30 '25 16:08

Caffeine


1 Answers

It is bad practice to modify sys.argv in Python and it's equivalent in other languages.

In these situations I recommend a parsed_args variable which has all your parsed data from sys.argv, any default values that you would like to set, and any modifications that "middleware" would make.

like image 90
dotancohen Avatar answered Sep 02 '25 05:09

dotancohen