[问题] Python3 print出参数左右有空格

楼主: coolchung (惊叹号)   2015-06-28 22:36:14
在下 python 新手一枚,来请教一个笨问题 Orz
我要读一个文字档,里面有两栏:
1111 aaaa
2222 bbbb
3333 cccc
我用strip和split分成两个参数并且写到另一个档案里
写入的格式大概是:
'1111', 'aaaa'
'2222', 'bbbb'
'3333', 'cccc'
我的写法大概如下(我是用python3):
(number, english)=i.strip().split()
print("'", address,"', '", goto, "'", file=out.txt)
结果输出的结果是:
' 1111 ', ' aaaa '
' 2222 ', ' bbbb '
' 3333 ', ' cccc '
请问多出来的空白有办法处理吗?还有有什么关键字可以查呢?
作者: kerwinhui (kezza)   2015-06-28 22:54:00
print("'"+address+..., ...),可能要str(address)
作者: tiefblau (tiefblau)   2015-06-28 23:03:00
可以把它转成str 然后加起来 或是print参数加上sep=''http://pydoing.blogspot.tw/2011/02/python-print.html随手找的教学~
作者: darkgerm (黑骏)   2015-06-28 23:57:00
建意用 format string 做
作者: tiefblau (tiefblau)   2015-06-29 02:09:00
print("'%s', '%s'"%(address, goto))
楼主: coolchung (惊叹号)   2015-06-29 23:56:00
感谢以上大大的建议~<(_ _)>

Links booklink

Contact Us: admin [ a t ] ucptt.com