Support Forums
Python Help - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: Python Help (/showthread.php?tid=16163)



Python Help - Dεlluzion - 02-13-2011

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


RE: Python Help - Gaijin - 02-13-2011

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.


RE: Python Help - Doldol - 04-17-2011

(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)


RE: Python Help - samsmith001 - 09-30-2019

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