Python Coding style Wrapping Lines
NickName:thclpr Ask DateTime:2012-09-28T20:20:25

Python Coding style Wrapping Lines

As described on http://docs.python.org/tutorial/controlflow.html :

Wrap lines so that they don’t exceed 79 characters.

Usualy i use breaklines on line 80, but sometimes i have functions that requires many arguments, as an example:

extractor.get_trigger_info(cur,con,env,family,iserver,version,login,password,prefix,proxyUser,proxyPass,proxyServer,triggerPage,triggerInfo)

So, what type of advice could be given for keep the guidelines on python coding Style ? what is the best practice for functions with many arguments ?

THanks in advance.

Copyright Notice:Content Author:「thclpr」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12639916/python-coding-style-wrapping-lines

Answers
mgilson 2012-09-28T12:23:05

The definitive reference for questions like these is PEP 8. PEP 8 gives you the freedom to break pretty much anywhere you want (provided you break after a binary operator and use implied line-continuation inside parenthesis). Whenever you break a line, typically the next line starts in the column after the opening parenthesis:\n\ndef func_with_lots_of_args(arg1, arg2, arg3,\n arg4, arg5):\n\n\nMy personal style is to try to arrange things so that the stuff on each line after the break is roughly the same length.\n\ndef func(arg1, arg2, arg3,\n arg4, arg5, arg6,\n kwd='foobar'):\n\n\nrather than:\n\ndef func(arg1, arg2, arg3,\n arg4, arg5, arg6, kwd='foobar'):\n\n\nAlthough PEP8 doesn't really say you need to do it this way.\n\n\n\nAs a side note, if you have a function with that many positional arguments, you should probably reconsider your program design.",


More about “Python Coding style Wrapping Lines” related questions

Python Coding style Wrapping Lines

As described on http://docs.python.org/tutorial/controlflow.html : Wrap lines so that they don’t exceed 79 characters. Usualy i use breaklines on line 80, but sometimes i have functions that re...

Show Detail

Python coding style

I've been reading various python coding style guides, some answers on SO, etc. but none of them mentions some maybe not that important questions, but I would like to know if there is a preferred wa...

Show Detail

Python and Django coding style (PEP)

I write code with Python using Django framework. Now I have read about all these coding style advices, but encountered a vague thing. In djangoproject section here https://docs.djangoproject.com/e...

Show Detail

Coding Style in Python

I have been interviewed recently by an eminent silicon valley based firm . I had been asked to write the code for the following question with O(n) time complexity . Question : Write a function tha...

Show Detail

In pycharm, how can I specify "blank lines before" a class method? (coding style)

pycharm's default coding styles suggest 1 blank line before a class method, and 2 blank lines before functions. I tried to change it in Settings> Editor> Code Style> Python> Blank Lines But ther...

Show Detail

Change default python coding style

In python i'm following camelCase Naming style. I checked my code with "pylint" and it gives error for not following lower_case_with_underscores style. Also i use netBeans IDE for coding. This IDE ...

Show Detail

VSCode Prettier not wrapping lines anymore in JS

I was using basic JS and HTML for coding practice and have installed Prettier extension. I assigned Ctrl+Shift+L to use auto formatting. I used this extension before and I can clearly remember that...

Show Detail

Is there a way to enforce variable declarations in Python through coding style?

I'm using PyCharms to work on Python projects. I find that writing functions is easier when we declare the type of the function parameters or the type of the new variables declared explicitly. It a...

Show Detail

Are there any published coding style guidelines for SQL?

Often I will end up with very complex SQL statements and I wondered if there was style guideline out there that dictates a common way of laying various aspects of a query out. I am look for someth...

Show Detail

Common coding style for Python?

I'm pretty new to Python, and I want to develop my first serious open source project. I want to ask what is the common coding style for python projects. I'll put also what I'm doing right now. 1.-...

Show Detail