Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is sysargv?
#1
(Something has changed here, I can't seem to mark Python code as code. Sorry!)

I was just looking at this, but I cannot understand what  this part really does:

 
n = 100
    if sys.argv[1:]:
        n = int(sys.argv[1])
That is to say, I don't understand the purpose of sys.argv or what exactly this does:
Quote:if sys.argv[1:]:

Why would I need the above? Why not just put:
n = 100
for i in range(n, 0, -1) ??
 
def myApp():
    import sys

    n = 100
    if sys.argv[1:]:
        n = int(sys.argv[1])

    def bottle(n):
        if n == 0: return "no more bottles of beer"
        if n == 1: return "one bottle of beer"
        return str(n) + " bottles of beer"

    for i in range(n, 0, -1):
        print(bottle(i), "on the wall,")
        print(bottle(i) + ".")
        print("Take one down, pass it around,")
        print(bottle(i-1), "on the wall.")
Reply


Messages In This Thread
What is sysargv? - by Pedroski55 - Oct-11-2020, 09:24 AM
RE: What is sysargv? - by ibreeden - Oct-11-2020, 10:29 AM
RE: What is sysargv? - by Pedroski55 - Oct-12-2020, 08:29 AM
RE: What is sysargv? - by buran - Oct-12-2020, 08:37 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020