Reputation: 1243
When I run my code, I get an error in the for
loop line.
This is the error:
File.readlines(): IndentationError: unexpected indent
And this is my code:
File = open('/home/shar/Desktop/list','r')
for line in File.readlines():
Are there any ideas?
Upvotes: 1
Views: 8739
Reputation: 174696
You don't need to indent the for
since you get the file object by assignment.
File = open('/home/shar/Desktop/list','r')
for line in File.readlines():
Upvotes: 4
Reputation: 4130
When using a for
loop, it should look something like this:
for x in y:
...
You don't need to indent the initial line; only the lines contained inside the loop itself.
Upvotes: 0