How Do I Keep Python Code Under 80 Chars Without Making It Ugly?

后端 未结 7 489
醉梦人生
醉梦人生 2021-01-31 14:27

This is a question that keeps recurring in all of my programming, python and otherwise. I really like to keep my code under 80 chars if at all possible/not horribly ugly. In a l

7条回答
  •  一生所求
    2021-01-31 15:03

    self.SomeLongLongName = SomeLongLongName.\
        SomeLongLongName(some_obj, self.user1, self.user2)
    

    '\' is your friend. Of course, you already know that you can split lines in an argument list at commas, without using '\'. Also, if you have long strings:

    myLongString = "This is a really long string that is going to be longer than 80 characters so oh my what do I do to make this work out?"
    

    becomes:

    myLongString = "This is a really long string that is going to be longer than"\
        " 80 characters so oh my what do I do to make this work out?"
    

    This works because Python will combine adjacent string literals, ignoring whitespace between the adjacent literal strings.

提交回复
热议问题