[Tutor] new to python

Anish Tambe anish.tambe.lists at gmail.com
Sun Jul 23 04:06:35 EDT 2017


> for line in file:

This line is not required as the you have opened your file to 'f'.
'file' is a built-in class. Type -
help(file)
on the interpreter to know more about it.

>     for line in f:
>         print(line.rstripe())
>         f.close()

Are you sure that you need to close the file after reading each line?

>
> I want to try the different methods of opening files and reading them.
and processing the data.  from there I will then start with writing to
files.

Bonus : read about the 'with' keyword.

> any idea why that does not work?

When you say the code does not work, you should provide the exact error or
stacktrace that you see.

Thanks,
Anish


More information about the Tutor mailing list