我有一根长长的绳子,像:
cmd = "python %sbin/datax.py -p '-Drun=%s -Drpwd=%s -Drjdbc=%s -Dcond=%s -Dtable=%s \
-Dwun=%s -Dwpwd=%s -Dwjdbc=%s' %s" % ( DATAX_HOME,
rds_reader['username'],
rds_reader['password'],
sub_jdbc_url_generator(args.reader),
where_condition,
args.table,
rds_writer['username'],
rds_writer['password'],
sub_jdbc_url_generator(args.writer),
job_template_file)
我不想把所有的-D
放在一行中,因为这看起来太长,而且上面的代码实际上可以工作,但它返回:
python /tmp/datax/bin/datax.py -p '-Drun=xxx ... -Dtable=demo -Dwun=yyy ...'
结果里面有很长的空间。我也读了一些问题,但这个字符串包含一些%s
要填充的内容。你知道吗
那么如何解决这个问题呢?还是另一种优雅的写作方式?感谢您的帮助。你知道吗
预期输出:
python /tmp/datax/bin/datax.py -p '-Drun=xxx ... -Dtable=demo -Dwun=yyy ...'
Python将连接两个相邻的字符串。带引号的字符串之间的间距将被丢弃。例如:
输出:
因此,您可以通过使用两个完整的字符串来扩展行,其中一个是行继续(
\
),另一个是将字符串括在圆括号中:输出:
相关问题 更多 >
编程相关推荐