views:

81

answers:

3

Hi, I'm doing a real silly mistake in Python but unable to find what it is

I'm doing something like this in python

filename="file1"
if name == 'file1'
    print 1

I'm getting an invalid syntax error

+6  A: 

You are missing a colon

filename="file1"
if name == 'file1':
    print 1
gnibbler
+4  A: 

You need to put a colon at the end of the if statment

filename="file1"
if name == 'file1':
    print 1
Yacoby
+1  A: 

what is name?? did you define it elsewhere?? I assume its "filename" instead, so

filename="file1"
if filename == 'file1':
    print 1

if "name" is defined, then the problem is indeed the ":" at the end of "if" line.

ghostdog74
while `name` is not defined, it wouldn't cause the `SyntaxError`. `SyntaxError` is generated on compilation time and completely independent of the `NameError`.
SilentGhost
i see. I didn't see the last part that describes the error he's got. thanks
ghostdog74