I am writing a script and I have a function, call it f(), that needs one of the command line arguments (a filename it needs to open). However, f() is not called directly in the main function.
I was wondering if it was bad coding convention to call sys.argv[1] straight from f()? If I don’t I would have to pass it as an argument to all of the functions that eventually call f().
It would be a bad practice to always assume that the arguments that your function needs are available on the command-line – what if this code was invoked in some other manner?
A function should declare input parameters for the data it needs to access.
At the very least, passing the necessary argument into
f()rather than accessingsys.argvhelps makef()much more re-usable.