Reputation: 3917
I am trying to run this file from the ebook Learning Python The Hard Way with the "python ex18.py" command, but it is not outputting anything. What's wrong?
# this one is like your scripts with argv
def print_two(*args):
arg1, arg2 = args
print "arg1: %r, arg2: %r" % (arg1, arg2)
# ok, that *args is actually pointless, we can just do this
def print_two_again(arg1, arg2):
print "arg1: %r, arg2: %r" % (arg1, arg2)
# this takes just one argument
def print_one(arg1):
print "arg1: %r" % arg1
# this one takes no arguments
def print_none():
print "I got nothin'."
Upvotes: 3
Views: 174
Reputation: 91139
If you come from a C or Java background, "you defined a bunch of functions but have no main loop".
Upvotes: 0
Reputation: 5822
Chances are, you aren't calling the function after defining them.
After those methods. Call them eg:
print_none()
You can either put this at the end of the file, or if you are importing the file in the shell, you can just type it in straight afterwards.
Upvotes: 3
Reputation: 104090
Because that file doesn't actually call any functions, there's nothing to output.
That file just defines four functions and then does nothing with them. :)
Try adding calls to print_none
, print_one
, and so forth:
print_none()
print_one("hello")
print_two("hello", "world")
print_two_again("hello", "world")
Upvotes: 8
Reputation: 2045
You are defining functions, but it doesn't look like you are calling them.
Upvotes: 2