LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-05-2007, 10:00 AM   #1
LinuxCrayon
Member
 
Registered: Nov 2007
Location: Georgia, USA
Distribution: FreeBSD
Posts: 274

Rep: Reputation: 31
[Python] Invalid Syntax - If statement


Hey guys. I have an if statement (below) with some invalid syntax (as reported by Python).

Code:
if add_yes == n:
                        add_folders = 1
Quote:
Originally Posted by Python Debug Info
File "compression.py", line 19
if add_yes == n:
^
SyntaxError: invalid syntax
The caret is at the colon.

I tried removing the colon from my if statement, but then I receive this error:

Quote:
Originally Posted by Python Debug Info
File "compression.py", line 20
add_folders = 1
^
SyntaxError: invalid syntax
The caret is at the "s" in "add_folders."

I have no idea what the problem is. Any ideas?
 
Old 12-05-2007, 08:16 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,828

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
you'll have to post more code, I'd guess the error is caused by some previous line, since what you posted is valid python...
 
Old 12-06-2007, 09:38 AM   #3
LinuxCrayon
Member
 
Registered: Nov 2007
Location: Georgia, USA
Distribution: FreeBSD
Posts: 274

Original Poster
Rep: Reputation: 31
Okay. Not a problem.

Code:
  6 add_folders = 0
  7 # The folders to add
  8 while add_folders != 1:
  9         folder_name = raw_input("What folder would you like to import? Plea    se use absolute paths" + " to avoid confusion. > ")
 10
 11         # TODO: Add a method to check if the directory exists.
 12
 13         add_yes = ""
 14
 15         while add_yes != y and add_yes != n:
 16                 add_yes = raw_input("Would you like to add more folders? [y    /n] "
 17
 18                 # If the user doesn't want to add more files, break the loo    p
 19                 if add_yes == n:
 20                         add_folders = 1
That's it really. There's some stuff after that, but obviously the interpreter's not getting that far, so I don't think it wouldmattertoo much.
 
Old 12-06-2007, 02:19 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,828

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
You forgot to close the parenthesis on line 16
 
Old 12-07-2007, 09:11 AM   #5
LinuxCrayon
Member
 
Registered: Nov 2007
Location: Georgia, USA
Distribution: FreeBSD
Posts: 274

Original Poster
Rep: Reputation: 31
Hahahahahahaha. Wow. Now I feel stupid. I looked and looked and looked. It works perfectly now (so far). Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LDAP Problem Invalid DN Syntax (34) steve007 Linux - Newbie 3 08-24-2009 07:53 AM
htdig.conf start url: statement syntax for local indexing. AwesomeMachine Linux - Software 0 05-02-2006 02:02 AM
LDAP Problem Invalid DN syntax (34) steve007 Linux - Newbie 3 10-18-2005 05:03 AM
Python ignores global statement? voyciz Programming 3 04-08-2005 02:07 PM
Python EXEC Statement ranger_nemo Programming 3 07-24-2003 08:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration