This is the main difference:
A file readlines object but not split :
>>> print hasattr(file, 'split') False >>> print hasattr(file, 'readlines') True
A str a split object but not readlines :
>>> hasattr("somestring", 'split') True >>> hasattr("somestring", 'readlines') False
And to answer your question, one works with a string object, and one works with a file object.
They do not do the same, since each returns a list of lines when working on a file, and one returns a dividing line when working with a line.
source share