LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [Python] Invalid Syntax - If statement (https://www.linuxquestions.org/questions/programming-9/%5Bpython%5D-invalid-syntax-if-statement-604695/)

LinuxCrayon 12-05-2007 10:00 AM

[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?

ntubski 12-05-2007 08:16 PM

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...

LinuxCrayon 12-06-2007 09:38 AM

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.

ntubski 12-06-2007 02:19 PM

You forgot to close the parenthesis on line 16

LinuxCrayon 12-07-2007 09:11 AM

Hahahahahahaha. Wow. Now I feel stupid. I looked and looked and looked. It works perfectly now (so far). Thanks!


All times are GMT -5. The time now is 12:14 AM.