Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pep8 E501:行太长错误_Python_Twitter_Pep8 - Fatal编程技术网

Python Pep8 E501:行太长错误

Python Pep8 E501:行太长错误,python,twitter,pep8,Python,Twitter,Pep8,我从以下代码中得到错误E501:行太长: header, response = client.request('https://api.twitter.com/1.1/statuses /user_timeline.json?include_entities=true&screen_name='+username+'&count=1') 但如果我这样或那样写: header, response = client.request('\ https://a

我从以下代码中得到错误
E501:行太长

header, response = client.request('https://api.twitter.com/1.1/statuses   /user_timeline.json?include_entities=true&screen_name='+username+'&count=1')
但如果我这样或那样写:

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

ValueError: Unsupported URL             https://api.twitter.com/1.1/statuses/user_timeline            .json?include_entities=true&screen_name=username&count=1 ().
ValueError: No JSON object could be decoded
或者我得到这个错误:

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

那么请告诉我,我如何才能传递此错误?

如果您这样打断字符串,行开头的空格将成为字符串的一部分

试试这个:

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

字符串将被删除。

您可以在多行上构建字符串:

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)

您还可以进入代码分析,忽略此类错误或警告。我正在使用eclipse和Pydev

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

then add to arguments : --ignore=E501 

重新启动Eclipse,该警告就可以了

尝试跨多行连接字符串,而不是以反斜杠结束行。通常,自动字符串连接优于构建字符串模式。在这种情况下,它不应该影响性能,但是Python字符串是不可变的,所以执行
strA='foo';与strA='foo'\n'bar'
相比,strA+='bar'需要大约两倍的内存和一半的速度。不过总的原则,不是硬性规定。谢谢,我在tkinter widgets args上疯了。。。在我读到这篇文章之前,无法在没有e501错误的情况下拆分它们。。。现在我明白了,我必须转到打开的括号后的下一行