Reputation: 97
My question might be simple but I really cannot figure out where I went wrong. I would like to pass one variable from a function to another function. I use return therefore but I'm always getting an error message, that my variable is not defined.
My code is:
url = "http://www.419scam.org/emails/2004-01/30/001378.7.htm"
def FirstStrike(url):
...
return tokens
def analyze(tokens):
...
if __name__ == "__main__":
FirstStrike(url)
analyze(tokens)
If I run this I got an error message: NameError: name 'tokens' is not defined.
Upvotes: 1
Views: 135
Reputation: 2770
tokens = FirstStrike(url)
You must assign FirstStrike return value to tokens variable before calling analyze(tokens)
Upvotes: 4
Reputation: 122336
When you run the code, you haven't assigned the result of FirstStrike
to a variable:
if __name__ == "__main__":
tokens = FirstStrike(url)
analyze(tokens)
This is necessary because otherwise tokens
is not defined when you call analyze
.
Upvotes: 9