Pep8 E501: line too long error

被刻印的时光 ゝ 提交于 2019-12-05 15:48:59

问题


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?


回答1:


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.




回答2:


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.




回答3:


You could build the string on multiple lines:

st='https://api.twitter.com/1.1/statuses/user_timeline.json?'
st=st+'include_entities=true&screen_name='+username+'&count=1'

header, response = client.request(st)


来源:https://stackoverflow.com/questions/18685184/pep8-e501-line-too-long-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!