How to format a python assert statement that complies with PEP8?

It’s important to remember that PEP8 is only a guideline and even states that there are times when the rules should be broken. But most importantly: know when to be inconsistent — sometimes the style guide just doesn’t apply. With that in mind, I would probably write this with old style line continuation: def afunc(some_param_name): … Read more

How to properly use python’s isinstance() to check if a variable is a number?

In Python 2, you can use the types module: >>> import types >>> var = 1 >>> NumberTypes = (types.IntType, types.LongType, types.FloatType, types.ComplexType) >>> isinstance(var, NumberTypes) True Note the use of a tuple to test against multiple types. Under the hood, IntType is just an alias for int, etc.: >>> isinstance(var, (int, long, float, complex)) … Read more

Correct style for line breaks when chaining methods in Python

PEP 8 recommends using parenthesis so that you don’t need \, and gently suggests breaking before binary operators instead of after them. Thus, the preferred way of formatting you code is like this: my_var = (somethinglikethis .where(we=do_things) .where(we=domore) .where(we=everdomore)) The two relevant passages are this one from the Maximum Line Length section: The preferred way … Read more

pep8 warning on regex string in Python, Eclipse

“\d” is same as “\\d” because there’s no escape sequence for d. But it is not clear for the reader of the code. But, consider \t. “\t” represent tab chracter, while r”\t” represent literal \ and t character. So use raw string when you mean literal \ and d: re.compile(r”\d{3}”) or escape backslash explicitly: re.compile(“\\d{3}”)

what is trailing whitespace and how can I handle this?

Trailing whitespace is any spaces or tabs after the last non-whitespace character on the line until the newline. In your posted question, there is one extra space after try:, and there are 12 extra spaces after pass: >>> post_text=””‘\ … if self.tagname and self.tagname2 in list1: … try: … question = soup.find(“div”, “post-text”) … title … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)