Python Style Guide Questions

koranthala koranthala at gmail.com
Fri Jan 16 01:13:06 EST 2009


Hi,
   Which is more advisable?
import x
b = x.a
             or
from x import a
b = a

   I read in Learning Python that it is always better to use the
former - especially since namespace wont be dirtied. But, doing that
with PEP 8 together causes my code to look rather cluttered. Reason
being that - PEP 8 suggests that have max line length = 79 chars.
So my code mostly looks like this:
class x:
     def y():
          try:
              if test:
                  obj.filename = str(os.path.basename
(obj1.find_next_element().\
                                              get_file_path()))
                  obj.modify_time = obj.filename.find_created_time()
+  \
                                              datetime.timedelta
(seconds=time.find_time())

etc .. etc..
Almost every line requires the '\'. Also, especially since Python also
uses whitespace as indentation, I keep confusing the block indentation
with the indentation that the '\' causes in the next line.

Could you please let me know what you guys usually do in such cases?
Is it advisable to go for the
from x import a to avoid this clutter?



More information about the Python-list mailing list