Support Forums

Full Version: Python Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have 2 questions regarding Python and would gladly appreciate any support.

The first one, is when I entered
Code:
>>> elif b = 2:
(It's the last script for the Password Generator program I want to create)

It came up with SyntaxError: invalid syntax. Does anyone know whats wrong with this? It looks like the "elif" thats causing the problem.

The second one is, when I eventually do complete the scripts with no errors, I save the program and then when I want to open it (it's saved as a .py now) it doesn't respond. I then saved it to the type "All Files". I opened it, and still nothing appeared. Then I decided to "Open With" the Command Processor, and it just came up as "/windows/etc/Python 26: >>>"

So basically my questions are : 1) What is wrong with the elif and how can I fix it to not receive the error.. 2) What extension do I have to save the .py file to open the program?

Thanks guys Smile
The error came up, because you did used invalid syntax.
elif is being used within conditional structures, it is being used after a if.
You also have one = instead of ==.

Valid Syntax for that would look like
Code:
if b == 1:
    print "Some"
elif b == 2:
    print "thing"
else:
   print "this"

And you save files with an extension .py or .pyw isn't important which one!
Double click on that file should open up a MS-DOS or a Terminal window, if python was properly installed on the system.
(02-13-2011, 01:00 PM)Gaijin Wrote: [ -> ]And you save files with an extension .py or .pyw isn't important which one!
Double click on that file should open up a MS-DOS or a Terminal window, if python was properly installed on the system.

.pyw would execute the script without a console by default (handy when you have a GUI program) .pyw uses pythonw.exe (console) and .py uses python.exe (with console)

samsmith001

Thanks for sharing this post.I am very pleased to read this article.