Δημοσιεύτηκε: 26 Σεπ 2011, 09:43
Όλα γίνονται. 
Από την άλλη, μπορείς να φτιάξεις argument parser: http://docs.python.org/library/argparse ... e-argparse
- Κώδικας: Επιλογή όλων
#!/usr/bin/python
import sys
print("Arguments: %s" % (", ".join(sys.argv)))
def main():
defdict = {
"myfunction": myfunction(),
"myfunction2": myfunction2(),
}
print("List of supported functions: %s" % (", ".join(defdict.keys())))
if sys.argv[1] in defdict.keys():
defdict[sys.argv[1]].run()
class myfunction():
def run(self):
print("You have called myfunction")
class myfunction2():
def run(self):
try:
print("You have called myfunction2 with argument: %s" % (sys.argv[2]))
except:
print("You have called myfunction2 with no arguments")
if __name__ == "__main__":
main()
- Κώδικας: Επιλογή όλων
python test.py myfunction2 xyz
Από την άλλη, μπορείς να φτιάξεις argument parser: http://docs.python.org/library/argparse ... e-argparse