Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Help
#1
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
Reply
#2
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.
Reply
#3
(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)
Reply
#4
Thanks for sharing this post.I am very pleased to read this article.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Python Python Compiler Canoris 21 8,241 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,159 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 733 02-12-2010, 09:07 PM
Last Post: Kharnage
  "==" and "is" in Python Canoris 1 726 02-07-2010, 03:55 PM
Last Post: uber1337
  I Need Help with Python Kharnage 19 3,524 02-06-2010, 08:58 AM
Last Post: Kharnage

Forum Jump:


Users browsing this thread: 1 Guest(s)