Python Pep8 E501:行太长错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18685184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pep8 E501: line too long error
提问by Amy Obrian
I get the error E501: line too long
from this code:
我E501: line too long
从这段代码中得到错误:
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?
所以请告诉我,我怎样才能通过这个错误?
采纳答案by mata
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.
字符串将自动连接。
回答by mata
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)
回答by Mathieu Chateauvert
You could also go to into the code analysis and ignore that kind or error/warning. I am using eclipse and Pydev.
您也可以进入代码分析并忽略那种或错误/警告。我正在使用 Eclipse 和 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.
重新启动 Eclipse,应该没问题。