#Python Tips
Last active
December 15, 2015 17:59
-
-
Save liuyix/5300279 to your computer and use it in GitHub Desktop.
Python学习备忘
def is_function()
return hasattr(foo, '__call__')
Python doc: linecache
http://stackoverflow.com/a/2081880
To Conclude: Use
fileobject.readlines()
orfor line in fileobject
as a quick solution for small files.
Uselinecache
for a more elegant solution, which will be quite fast for reading many files, possible repeatedly.
Take @Alok's advice and use enumerate() for files which might be very large, and won't fit into memory. Note that using this method might slow because the file is read sequentially.
Link: http://stackoverflow.com/a/2081861
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment