Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pep8 E501: line too long error

I get the error E501: line too long from this code:

header, response = client.request('https://api.twitter.com/1.1/statuses   /user_timeline.json?include_entities=true&screen_name='+username+'&count=1')

but if I write this way or another way:

    header, response = client.request('\
       https://api.twitter.com/1.1/statuses/user_timeline.\
           json?include_entities=true&screen_name='+username+'&count=1')

I get this error:

ValueError: Unsupported URL             https://api.twitter.com/1.1/statuses/user_timeline            .json?include_entities=true&screen_name=username&count=1 ().

or I get this error:

ValueError: No JSON object could be decoded

So please tell me, how can I pass this error?

like image 594
Amy Obrian Avatar asked Sep 08 '13 15:09

Amy Obrian


People also ask

How do you fix a line that is too long in Python?

The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. If necessary, you can add an extra pair of parentheses around an expression, but sometimes using a backslash looks better. Make sure to indent the continued line appropriately.

What is E501 Python?

E501 is not a python error, rather than a PEP8 error. Meaning your line is longer than 80 chars (in your case it's 137 chars long). Your editor or runtime are verifying that your code is correct by PEP8 rules and that's why you are getting this "error".


2 Answers

The whitespaces at the beginning of the lines become part of your string if you break it like this.

Try this:

header, response = client.request(
   'https://api.twitter.com/1.1/statuses/user_timeline.'
   'json?include_entities=true&screen_name=' + username + '&count=1')

The strings will automatically be concatenated.

like image 173
mata Avatar answered Sep 25 '22 16:09

mata


You could also go to into the code analysis and ignore that kind or error/warning. I am using eclipse and Pydev.

Windows > Preferences > Pydev > Editor > Code Analysis > pycodestyle.py (pep8)

then add to arguments : --ignore=E501 

Restart Eclipse and it should be fine for this warning.

like image 40
Mathieu Châteauvert Avatar answered Sep 24 '22 16:09

Mathieu Châteauvert