Search code examples
python-3.xtkinterpep8

Are these blocks according to PEP8?


are these two samples according to PEP8? Are they ugly? I read a lot of PEP8, but I still feel insecure about multiline blocks...

Personally, I think that one line per param is quite readable when there are many parameters to setup. It is easier to find the parameter and change its value... is it?

tkinter.Label(
    self,
    bg='grey'
    bd=5,
    relief='ridge'
    ).pack(fill='both', exand=1)
tkinter.Label(
    self,
    bg='grey'
    bd=5,
    relief='ridge').pack(fill='both', exand=1)

Solution

  • I think, they are both fine. I'm not aware of an official preference of either of them, as long as you are consistent in your project.

    I also don't think there is a need for an official statement as the purpose of line braking is mainly to make the code more readable and every second case would be (from my experience) an exception where the rules don't really fit.

    Also fine would be (which I usually en up with):

    tkinter.Label(self,
                  bg='grey',
                  bd=5,
                  relief='ridge').pack(fill='both', exand=1)
    

    or

    tkinter.Label(self, bg='grey',
                  bd=5, relief='ridge').pack(fill='both', exand=1)
    

    but not

    tkinter.Label(self,
        bg='grey',
        bd=5,
        relief='ridge').pack(fill='both', exand=1)