You can’t loop through sys.argv or args with the reverse() function applied directly to it, but you can append all the sys.argv elements to a list, reverse the list, and then loop through it.
#!/bin/env python
import sys,re
args = []
for arg in sys.argv:
args.append(arg)
args.reverse()
for arg in args:
print arg
This is useful if you need to look at the last arguments before deciding what to do, possibly for interoperability with some older code where the order of command line arguments is already set in stone.
If you want to eliminate the program name from the list of arguments (sys.argv[0]), then this will work:
for arg in sys.argv[1:]:
args.append(arg)