-4

i have to call the main function based on the number of arguments passed. When i call the script the functions are not working.

Sample Code:

    def func1():
      somecode
    def func2():
      somecode
    def func3():
      somecode
    def main():
      if len(sys.argv) == "5":
        func1()
        func3()
      elif len(sys.argv) == "8":
       func2()
       func3()
    if __name__ == '__main__':
      main()
Ramesh Eol
  • 31
  • 5

2 Answers2

0

In your code you are comparing len(sys.argv) with a string:

  if len(sys.argv) == "5":
    func1()
    func3()
  elif len(sys.argv) == "8":
   func2()
   func3()

changing to

  if len(sys.argv) == 5:
    func1()
    func3()
  elif len(sys.argv) == 8:
   func2()
   func3()

should do the trick

FlyingTeller
  • 13,811
  • 2
  • 31
  • 45
0

Your code is not calling those functions because this if-test:

if len(sys.argv) == "5":

is always False. The function len() returns an integer and an integer in Python is never equal to a string. Do this instead:

if len(sys.argv) == 5:
BoarGules
  • 15,507
  • 2
  • 28
  • 42