-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
__name__ == '__main__' doesn't seem to be set #69
Comments
What command does What does |
Also, sorry for the confusion. I don't use |
This is some seriously weird behavior: print repr(__name__ == '__main__')
if __name__ == '__main__':
print "Direct yep"
else:
print "Direct nope"
cond = __name__ == '__main__'
if cond:
print "Indirect yep"
else:
print "Indirect nope" Results in:
wtf? :-D |
Heh. It seems I will have to think about that to figure out if I like that behavior. |
The fix should be for Thank you for the report! |
Hi Jorgen, I just saw an update and the bug still remains. I'm using "elpy-20130511.2055". Is this the release that should contain the bug fix? |
Yes. You should be able to use |
Ah. I was using |
Quite often when writing a script, you want to test functions in the script instead of running it (which might even end up with calling Glad it works :-) |
I'm going to use this ticket to ask a semi-off-topic question. I hope that is OK. In the fix above you state
I'm fairly new to python development so I don't see why this is a nice idea. What else should I plan on running when I do if __name == '__main__':
script_code ()
else:
# HERE
# Or should I put it here, not indented, not part of the `if` clause? |
Oh! You preemptively explained it to me and our comments crossed in the ether. THANK YOU! |
Oh. Ok :-D Leaving the below as I already had typed it. Enjoy Python! :-) You can run unittests with A scrip regularly looks something like this: #!/usr/bin/env python
def main():
do something
def foo(a, b):
do something else
def bar(c):
do yet another thing
if __name__ == '__main__':
main() You can then use |
Still a little bit confused. What you show is how I used to have my code, but now The new confusion is because you write above that I can used Thanks again for the explanations. I'm just trying to get some best-practices down and haven't found this information elsewhere. |
Er, yes, I do mean interactive testing. When you use If you want to automatically run tests, I really recommend using unittests and |
Ok. All clear. Thanks again. Sorry for hijacking the thread. |
No problem, it was yours to begin with. :-D |
Hi Jorgen, How do I bind 'C-u C-c C-c' into a hot key, for example, [f7], in my init.el file? |
This should work:
|
It did. Thank you Jorgen. I appreciate it. |
I'm not sure if this is an elpy-bug or not, but I just switched to elpy and this appeared. When I used to load python-mode and ipython-mode and
C-c !
, the following code would run and print both statements:When I run this through elpy, only
Goodbye, Cruel World
is printed, notHello, World
.The text was updated successfully, but these errors were encountered: