Python Style Guide Questions

koranthala koranthala at gmail.com
Fri Jan 16 02:28:38 EST 2009


On Jan 16, 12:00 pm, Terry Reedy <tjre... at udel.edu> wrote:
> koranthala wrote:
> > Hi,
> >    Which is more advisable?
> > import x
> > b = x.a
> >              or
> > from x import a
> > b = a
>
> If I know I want just one thing from x, I tend to use latter.
> I also like 'import xyzlib as x'
>
> >    I read in Learning Python that it is always better to use the
> > former - especially since namespace wont be dirtied.
>
> Namespace get cluttered, not dirtied.  In any case, either 'x' or 'a'
> gets added.  One new name either way.
>
> > 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())
>
> Use 4 spaces instead of 5 for indents
>
> > Almost every line requires the '\'.
>
> As Steven said, usually no
>
> > 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.
>
> '\' causes no indentation
>
> Beyond that, consider find a style you like.  I agree with Stvhen about
> using 'thought-sized' expressions.
>
> tjr

Thank you Steven and TJR. I will try to implement the thought sized
expressions.
I was rather misled by trying to decrease the line count as much as
possible.



More information about the Python-list mailing list