0

I have these scripts with the following contents:

first.py:

bob = 0

if bob = 0:
    bob + 1

second.py:

from first import bob
print bob

How do I get second.py to return 1 and not 0?

9
  • Your question's title is a bit misleading. You don't have any local variables or functions, but rather global variables in two modules. Commented Jan 30, 2014 at 1:43
  • @Blckknght edit away! Commented Jan 30, 2014 at 1:44
  • OP, did you not get an error when running second.py? I'd assume if bob = 0 would throw a SyntaxError. Commented Jan 30, 2014 at 1:46
  • 1
    @jmu303: I would, but the wrong wording may be significant to the questioner's misunderstanding of what is going on. Perhaps the code shown is an oversimplified version of what they're really doing, and they do actually have functions and local variables in the real code. Commented Jan 30, 2014 at 1:47
  • its working now just a stupid mistake Commented Jan 30, 2014 at 1:47

1 Answer 1

2

Your syntax in first.py is wrong and won't do what you want. One equals sign is used for assignment, not comparison, and you don't actually save the result of adding one to bob in the variable.

bob = 0

if bob == 0:
    bob += 1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.