+ 3
Explain me this snippet pls
Hello everyonen could someone please explain me how this snippet work? when i open cmd and launch my script with python i can see something happened but can't explain why.. here is the part i don't understand: if __name__=='__main__': import sys pluto=Dog() if len(sys.argv)>1: pluto.sound=sys.argv[1] print(pluto.make_sound()) to look at the full code please check this link : https://code.sololearn.com/c0UbA9o1NLq6 thanks you in advence for your help ;)
2 odpowiedzi
+ 3
So if you run your file from cmd and pass addition arguments
like:
python3 Animal.py meow
sys.argv makes a list of ['Animal.py','meow'] and then if condition checks it's length which in this case is greater than 1 ,so second argument(meow) is assigned to Object pluto sound property and printed thereafter ,but if no additional argument is passed barks get printed
+ 1
thanks for this nice explanation ! ;)