“炼金术”;def print_用法()”;在Python3中出现错误
我遵循这个链接将表从数据库复制到目标数据库 我在这一点上有错误“炼金术”;def print_用法()”;在Python3中出现错误,python,mysql,python-3.x,Python,Mysql,Python 3.x,我遵循这个链接将表从数据库复制到目标数据库 我在这一点上有错误 def print_usage(): print """ Usage: %s -f source_server -t destination_server -f, -t = driver://user[:password]@host[:port]/database Example: %s -f oracle://someuser:PaSsWd@db1/TSH1 \\ -t mysql://root@db2:
def print_usage():
print """
Usage: %s -f source_server -t destination_server
-f, -t = driver://user[:password]@host[:port]/database
Example: %s -f oracle://someuser:PaSsWd@db1/TSH1 \\
-t mysql://root@db2:3307/reporting
""" % (sys.argv[0], sys.argv[0])
在其中,我修改了Python 3的以下格式:
def print_usage():
print("%s -f mysql://root@localhost:3306/db_test -t mysql://root@localhost:3306/db_test1" % (sys.argv[0], sys.argv[0]))
我想先在MySQL中进行测试,但出现了一个错误
TypeError:在字符串格式化过程中并非所有参数都已转换
我的绳子有什么问题?谢谢 格式字符串中只有一个
%s
,而字符串中有两个变量
更多详情:
当你这样做的时候
print("%s -f mysql://root@localhost:3306/db_test -t mysql://root@localhost:3306/db_test1" % (sys.argv[0], sys.argv[0]))
将每个'%s'
替换为(sys.argv[0],sys.argv[0])
中的值,因此元组中的'%s'
和值必须相同
尝试将代码更改为:
print("%s -f mysql://root@localhost:3306/db_test -t mysql://root@localhost:3306/db_test1" % (sys.argv[0], ))