[英]SQLAlchemy “def print_usage()” in Python 3 error
I'm following this link https://gist.github.com/thoas/1589496 that copies table from a database to a destination database. 我正在跟踪此链接https://gist.github.com/thoas/1589496 ,该链接将表从数据库复制到目标数据库。
I'm having error with this one 我对此有误
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])
in which I modify following the format for Python 3: 在其中,我按照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]))
I wanted to test first in MySQL but there is an error 我想先在MySQL中测试,但出现错误
TypeError: not all arguments converted during string formatting TypeError:在字符串格式化期间并非所有参数都已转换
What is the problem on my string? 我的琴弦有什么问题? Thanks! 谢谢!
you have only one %s
in your format string while you have two variables to put in string. 格式字符串中只有一个%s
,而字符串中有两个变量。
more details: 更多细节:
when you do 当你做
print("%s -f mysql://root@localhost:3306/db_test -t mysql://root@localhost:3306/db_test1" % (sys.argv[0], sys.argv[0]))
you replace each '%s'
with a value from (sys.argv[0], sys.argv[0])
so you must have the same number of '%s'
and values in the tuple. 您用(sys.argv[0], sys.argv[0])
的值替换每个'%s'
,因此在元组中必须具有相同数量的'%s'
和值。
try change your code to this: 尝试将您的代码更改为此:
print("%s -f mysql://root@localhost:3306/db_test -t mysql://root@localhost:3306/db_test1" % (sys.argv[0], ))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.