我遵循这个链接https://gist.github.com/thoas/1589496,它将表从数据库复制到目标数据库。
我在这个问题上出了错
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:不是所有在字符串格式化期间转换的参数
我的绳子有什么问题?谢谢!
发布于 2015-03-09 07:54:38
格式字符串中只有一个%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], ))
https://stackoverflow.com/questions/28946076
复制