Python - Things I shouldn't be doing?

Posted by cornjuliox on Stack Overflow See other posts from Stack Overflow or by cornjuliox
Published on 2009-12-23T06:31:03Z Indexed on 2010/04/27 2:43 UTC
Read the original article Hit count: 313

Filed under:
|

I've got a few questions about best practices in Python. Not too long ago I would do something like this with my code:

...
junk_block = "".join(open("foo.txt","rb").read().split())
...

I don't do this anymore because I can see that it makes code harder to read, but would the code run slower if I split the statements up like so:

f_obj = open("foo.txt", "rb")
f_data = f_obj.read()
f_data_list = f_data.split()
junk_block = "".join(f_data_list)

I also noticed that there's nothing keeping you from doing an 'import' within a function block, is there any reason why I should do that?

© Stack Overflow or respective owner

Related posts about python

Related posts about best-practices