我尝试构建一个简单的python脚本来收集“实时”地震数据 来自美国地质勘探局网站,该网站以CSV文件形式提供。我的愿望是抓住 使用python的数据,并更新MySQL服务器 建造。在
C:\Python27\python.exe C:/Users/XXXX/PycharmProjects/QuakeUpload/TestSQLOpen2.py
Traceback (most recent call last):
File "C:/Users/XXXX/PycharmProjects/QuakeUpload/TestSQLOpen2.py", line 19, in <module>
with connection.cursor() as cursor:
File "C:\Python27\lib\site-packages\pymysql\connections.py", line 745, in cursor
return self.cursorclass(self)
TypeError: 'str' object is not callable
Process finished with exit code 1
有趣的是,回溯错误消息没有显示导致错误的行。导致错误的行出现在调用
connection.cursor()
之前(回溯的目标行是问题的根源)。在错误是由
可以通过 removing the double quotes from around the cursorclass:
^{pr2}$注意,
pymysql.cursors.DictCursor
是一个 当"pymysql.cursors.DictCursor"
是字符串时初始化。如果self.cursorclass
是 设置为pymysql.cursors.DictCursor
(通过cursorclass
参数),然后返回
DictCursor
类的实例。如果self.cursorclass
是字符串"pymysql.cursors.DictCursor"
,则调用该字符串将引发因为字符串是不可调用的。在
同样,作为nightuser points out
应该是
(不带括号)因为
csvfile
本身就是iterable。在谢谢各位!我能让它发挥作用。下面是我的最终代码。在
相关问题 更多 >
编程相关推荐