Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am using the shell interpreter for python2.6.2 on Ubuntu Jaunty, when I try to use the elif statement I get invalid syntax error.
I don't think it has to do with indentation or anything on my part. It seems like the shell isn't able to handle it because I can copy and paste my code in the edit window then save and execute and it will run as expected.
When I type elif it changes color but when I hit enter to go to the next line instead of automatically indenting it gives me the invalid syntax error. I have typed it fifty different ways so I don't think it has anything to with syntax or indentation as it will work if I save it as a program and then execute it.
I am doing a tutorial for python and it would be helpful to run everything from the python shell interpreter so I don't have to keep saving everything
I tried upgrading but that didn't work. I was hoping it was something like a missing library, because as far as documentation goes I am the only one who has mentioned it and I find it hard to believe that I am the only one who uses Ubuntu and the shell interpreter.
It's very important to know more exactly the steps you do/done. For example, if you got a syntax error, a good idea could be to post the exact code (or a piece of it) you tried to run.
Otherwise, you could try to define this example code (be aware with indentations and other characters like ':'...)
I am using the shell interpreter for python2.6.2 on Ubuntu Jaunty, when I try to use the elif statement I get invalid syntax error.
I don't think it has to do with indentation or anything on my part. It seems like the shell isn't able to handle it because I can copy and paste my code in the edit window then save and execute and it will run as expected.
When I type elif it changes color but when I hit enter to go to the next line instead of automatically indenting it gives me the invalid syntax error. I have typed it fifty different ways so I don't think it has anything to with syntax or indentation as it will work if I save it as a program and then execute it.
I am doing a tutorial for python and it would be helpful to run everything from the python shell interpreter so I don't have to keep saving everything
How do you know python is being called to interpret the script? This isn't automatic, you know -- you have to take certain steps to assure that your script gets interpreted by Python. Based on your report, the code works in one environment but not another -- this makes me think the system is invoking the wrong interpreter.
And, as usual, no code, no clue about the nature of the script.
Thanks you guys for taking the time to try and help me solve this problem, I havn't been able to get online in a while but any help is appreciated.
The code that glus posted is almost identical to the example I have been trying to execute
Quote:
>>> x=5
>>> if x<5:
y=-1
z=5
elif x>5:
after hitting enter after the last line is when I recieve the syntax error and is does not matter whether or not if "if" and "elif" indentations are aligned or not
sorry It wont let me post code the way it looks in the interpreter but the lines have the proper indentations and the elif statement is indented less than y and z but is aligned with the if statement
Last edited by danred; 10-17-2009 at 10:43 AM.
Reason: trying to post code example
I didn't yet find your problem. Using the interactive mode, I test your code in,
a) Python 2.6.3 and 3.1.1 (Debian Squeeze environment -system installed)
b) Python 2.6.2 (Ubuntu Jaunty 9.04 -working directly inside a Live CD session)
And no problem occurs... further than... in interactive mode you could break the "print" statement from the previous code unless you know the way to join the "if...elif...else" structure with it (I don't).
Although, note that this runs,
Quote:
>>> x=5; print x
To continue checking you could try to do what I make in b)... and tell us.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.