python,coding-style,readability,pep8
A couple of relevent snippets from PEP 8 with my italics added. A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is most important. But most importantly: know when to be inconsistent --...
python,indentation,pep8,long-lines
A very long function name is probably unproblematic to import directly: from somelongmodule.SomeLongClassName import VeryLongFunctionName long_variable_name = VeryLongFunctionName(... And/or break the line after the variable name: long_variable_name = \ somelongmodule.SomeLongClassName.VeryLongFunctionName(... Also, you might want to try not having very long names in the first place....
This is not actually a PEP8 violation. I simply do this: from .my_class import MyClass # noqa Edit: Another possibility is to use __all__. In that case, flake8 understands what is going on: from .my_class import MyClass __all__ = ['MyClass',] ...
One place where redundant parentheses can help!-) training_data_without_sports, test_data_without_sports, feature_cols_all = ( divide_data('../data/feature_without_sports.csv', training_ratio)) (although, variable names of more sensible lengths would make your code much more readable!-)...
If you want to check for zero, you should use if n == 0. Your second expression doesn't check for zero, it checks for any value that evaluates as false. I think the answer lies in your requirements; do you really want to check for zero, or do you want...
It's preferred because it's preferred. Casing rules are almost always arbitrary and vary from community to community. The main goal is consistency between various libraries. For instance, without this rule you could have something like this: s.Foo = bar_2.oogaBooga() s.Bar = BAZ.BAZOID() q = spam.egg_soup() Where oogaBooga, BAZOID, and egg_soup...
Generally, there is no preferred order. Depending on the program, a order can be needed: You can decorate classes with functions. Then the decorator function must be defined before the class. OTOH, you can decorate functions with classes. Then the decorator class must be defined before the function. You can...
Quoting PEP-8's Programming Recommendations section, For sequences, (strings, lists, tuples), use the fact that empty sequences are false. Yes: if not seq: if seq: No: if len(seq) if not len(seq) Since empty sequences are Falsy in Python, >>> bool([]) False >>> bool(()) False you can simply use if not as...
It's better to add default values in the __init__ signature -- that way someone only needs to look at the signature to figure out the options. And, in example 2, the default values are now hidden in other functions. Additionally, your documentation will be simpler.
Yes; Wait(self.marionette).until( lambda _: ( self.autocomplete_results.is_open and len(self.autocomplete_results.visible_results) > 1 ) ) Check: $ pep8 --max-line-length=99 --exclude=client foo.py parens to the rescue! :) ...
python,logging,coding-style,pep8
logger.debug(( "Returning a list of Window handles" "with specified Windowtitle: {}" ).format(title)) ...
There are multiple ways to do this: Use a variable to store this def setUp(self): path = 'projectname.common.credential.CredentialCache.mymethodname' self.patcher1 = patch(path) String concatenation: An assignment like v = ("a" "b" "c") gets converted into v = "abc": def setUp(self): self.patcher1 = patch( "projectname.common.credential." "CredentialCache.mymethodname") Tell pep8 that we don't use...
At the end of the day, whats more important is consistency within your own code. Its important that your convention be constant. Or if you are coding with a group that your convention be consistent across your project. With that said, each language will have its own Style Guides. Style...
You can't. Reason is PyCharm doesn't tell you that you have violated any PEP8 Guidelines if you do that or any import statements at all. One, your PyCharm is outdated (newest version is 4.0.2/4.2) or second, your PyCharm seems to be having a bug, thus giving reason to file a...
python,django,pydev,aptana3,pep8
Although I haven't completely solved my problem, I'm posting this as an answer because it does achieve what the title asks for. I reinstalled Aptana and instead of importing an existing folder as project I created a Django project (New > Project > PyDev Django Project) and replaced the default...
python,coding-style,naming-conventions,pep8
There is no handy naming convention, not written down in places like PEP-8 at any rate. The Python standard library does use such a convention to a certain extend. Compare: listobj.sort() listobj.reverse() with sorted_listobj = sorted(listobj) reversed_iterator = reversed(listobj) Using a verb when acting on the object directly, an adjective...
python,eclipse,pydev,pep8,autopep8
The best option I can find is to turn off import sorts in PyDev. This is not a complete solution, but it's better than completely turning off autopep8 code formatting. Just uncheck the Sort imports on save? option in the Eclipse/PyDev Preferences. For Eclipse Kepler, Service Release 2, with PyDev...
python,sublimetext3,sublime-text-plugin,pep8
You need to further indent the str.format() arguments: print (" WARNING: Unknown '{}' ID found in line {}\n" " of '{}' file.\n").format(reader[0], l + 1, pars_f_name) # ^^^^^^^^^^^^ As a personal choice, I'd put those arguments all on one line, indented: print (" WARNING: Unknown '{}' ID found in line...
For your __init__ function, I would go somewhere in the middle and try to put some parameters on each line, finding a logical place to split the line if possible: def __init__(self, title, url, teaser, parseDate, updateDate, redis, id=None): You might also consider if there is a way to refactor...
PyDev will only analyze valid packages in the PYTHONPATH (i.e.: under a source folder). So, Are your sources in the existing project under a source folder and are folders actually packages (i.e.: do they have __init__.py files?) See: http://pydev.org/manual_101_project_conf2.html for details on configuring your source folders....