[Tutor] new to python

Alex Kleider akleider at sonic.net
Sun Jul 23 11:16:26 EDT 2017

On 2017-07-23 01:06, Anish Tambe wrote:
>> 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.

This appears to be true in python2x but not in python3:

alex at X301n3:~$ python3
Python 3.4.3 (default, Nov 17 2016, 01:11:57)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help(file)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
NameError: name 'file' is not defined
>>> exit()
alex at X301n3:~$ python
Python 2.7.6 (default, Oct 26 2016, 20:32:47)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help(file)
Help on class file in module __builtin__:

class file(object)
  |  file(name[, mode[, buffering]]) -> file object

Also puzzling is that the 'intro' to python2 declares itself to be 'on 
linux2' vs just 'on linux' in the case of python3.  (Something I'd not 
previously noticed.)

More information about the Tutor mailing list