我没有对此进行详尽的测试,但似乎我在Python中有一个函数[在VS中],并且我决定在已经创建它之后在fct的开头添加一些东西,它不会让我没有造成错误。
这是我的代码最初的方式。我在VS和记事本++中都打开了这个工作。
import httplib2, re
def search_for_Title(content)
searchBounds = re.compile('<title><!\[CDATA\[(.{1,100})\]\]></title>|<description>(.{1,400})</p>')
Title = re.findall(searchBounds,content)
return Title
def main():
url = "http://www.economist.com/sections/international/rss.xml"
h = httplib2.Http('.cache')
content = h.request(url)
titlesArray = search_for_Title(str(content))
for i in titlesArray:
print('Title: ' + i[0] + '\n Description: ' + i[1])
main()
我想格式化正则表达式以获得更好的可见性,因此决定创建一个字符串,我可以使用'''来分隔它(这就是想法)。
当我执行此步骤时,我在VS中遇到错误(对于searchBounds'意外缩进'和'无法分配给错误表达式'以及其他一些进一步向下)。
(相关代码现在看起来如何)
def search_for_Title(content):
regexStr = '<title><!\[CDATA\[(.{1,100})\]\]></title>|<description>(.{1,400})</p>'
searchBounds = re.compile(regexStr)
Title = re.findall(searchBounds,content)
return Title
但在Notepad ++中没有...
除了下载python工具之外,我没有为VS设置任何东西,这可能是我的错误吗?
我可以通过简单地复制我在notepad ++中获得的内容(完全相同!)来实现它,但我宁愿不必同时使用两个IDE。
PS似乎Python中的UTF-8无法解码'ã'。即,不能采取这样的字符串,任何方式?