Shell Interaction in Python: Difference between revisions
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
* [[Python Code Examples#Code_Examples|Python Code Examples]] | * [[Python Code Examples#Code_Examples|Python Code Examples]] | ||
* [[Python_Module_shutil|shutil]] | * [[Python_Module_shutil|shutil]] | ||
=Command Line Argument Processing== | |||
<syntaxhighlight lang='python'> | |||
import sys | |||
def main(): | |||
print(f"Arguments count: {len(sys.argv)}") | |||
for i, arg in enumerate(sys.argv): | |||
print(f"Argument {i:>6}: {arg}") | |||
if __name__ == '__main__': | |||
main() | |||
</syntaxhighlight> | |||
=Organizatorium= | =Organizatorium= |
Revision as of 04:36, 2 March 2022
Internal
Command Line Argument Processing=
import sys
def main():
print(f"Arguments count: {len(sys.argv)}")
for i, arg in enumerate(sys.argv):
print(f"Argument {i:>6}: {arg}")
if __name__ == '__main__':
main()
Organizatorium
from shutil import which
commands={
"aws": "awscli",
"aws-login": "aws-login",
"aws-eks-configure": "aws-eks-configure"
}
for c in commands:
print("{:20}{:7}".format(commands[c], "OK" if which(c) else "missing"))