Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting SQLAlchemy code

Tags:

We're trying to follow the PEP8 guidelines for formatting our Python code and staying below 80 characters per line.

Our SQLAlchemy lines are particularly troublesome, having lots of chained methods and tons of complex parameters, logic, and nested functions.

Are there any particular best practices for formatting Python SQLAlchemy with the constraints of PEP8?

The closest answer I've found is here, but the code I'm dealing with is far, far more complicated.

like image 326
Dustin Kirkland Avatar asked Feb 28 '12 00:02

Dustin Kirkland


1 Answers

Came here hoping for a better solution, but I think I prefer the parentheses wrapping style:

subkeyword = (     Session.query(         Subkeyword.subkeyword_id,          Subkeyword.subkeyword_word     )     .filter_by(subkeyword_company_id=self.e_company_id)     .filter_by(subkeyword_word=subkeyword_word)     .filter_by(subkeyword_active=True)     .one() ) 

This is nice and clear, and avoids the dreaded backslash.

like image 145
Nick Sloan Avatar answered Oct 21 '22 00:10

Nick Sloan