randeepsp
randeepsp

Reputation: 3842

Using if-condition to check filename

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

Upvotes: 1

Views: 1720

Answers (3)

ghostdog74
ghostdog74

Reputation: 342313

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.

Upvotes: 1

Yacoby
Yacoby

Reputation: 55445

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

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

Upvotes: 4

John La Rooy
John La Rooy

Reputation: 304137

You are missing a colon

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

Upvotes: 7

Related Questions