Heim  >  Artikel  >  Backend-Entwicklung  >  [新人求助] pymysql链接数据库为何会报EOF错误?

[新人求助] pymysql链接数据库为何会报EOF错误?

WBOY
WBOYOriginal
2016-09-03 00:14:111503Durchsuche

1.使用pymysql链接数据库时报了错误
错误代码:

<code>SyntaxError: unexpected EOF while parsing
Process finished with exit code 1
</code>

2.下面是我的代码

<code>import pymysql

## 链接数据库
connection = pymysql.connect(host = 'localhost',user = 'root',passwd = 'gangan',db = 'qiandao')
try:
    cur = connection.cursor()
    cur.execute("SELECT fk_si_user,si_trueName from fbl_stuinfo where si_trueName like '甘%'")

    data = cur.fetchall()

    for row in data:
       print('%s\n%s'%row)
    
    cur.close()
    connection.commit()
    </code>

3.EOF错误是什么意思呢,一般的解决思路是什么? python 3.5 新人求教

回复内容:

1.使用pymysql链接数据库时报了错误
错误代码:

<code>SyntaxError: unexpected EOF while parsing
Process finished with exit code 1
</code>

2.下面是我的代码

<code>import pymysql

## 链接数据库
connection = pymysql.connect(host = 'localhost',user = 'root',passwd = 'gangan',db = 'qiandao')
try:
    cur = connection.cursor()
    cur.execute("SELECT fk_si_user,si_trueName from fbl_stuinfo where si_trueName like '甘%'")

    data = cur.fetchall()

    for row in data:
       print('%s\n%s'%row)
    
    cur.close()
    connection.commit()
    </code>

3.EOF错误是什么意思呢,一般的解决思路是什么? python 3.5 新人求教

你应该把全部错误贴上来,报这个错并不一定是因为连mysql经起,极有可能是你print的问题

print(r'%sn%s'%row)前面加个r试试

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn