我可以成功地从文件中读取。但是,我无法得到一个操作结果来编写。
前任:
我编辑的包括完整的代码和推荐的更改
if 5:
from pathlib import Path
a = Path(r"C:\Users\l\Desktop\a.txt").read_text()
a = int(a)
qqa = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~'
def x(qqc, qqd):
qqe = []
while qqc > 0:
qqf = qqc % qqd
qqe.append(qqf)
qqc = qqc // qqd
qqg = []
while qqe:
qqg.append(qqa[qqe.pop()])
return ''.join(qqg)
b = open(r"C:\Users\l\Desktop\b.txt","w")
b.write(str(x(a,12)))为了解释这一点:
a.txt contains only the string “24” (excluding the quotes)
x is a base-10 to base-_ conversion operation
“12” is the base我不希望写操作写文字操作“x(a,12)”(不包括引号)。
我希望写操作写结果“20”(不包括引号)。(基数为“24”-12为“20”)
如何使它在Python 3中正常工作?
发布于 2019-05-18 02:10:01
据我所知,您正在获得TypeError: write() argument must be str, not int,您所要做的就是将int转换为str b.write(str(x(a,12)))
发布于 2019-05-18 02:09:23
write()参数必须是字符串,因此以一种简单的方式:
b.write(str(x(a,12)))https://stackoverflow.com/questions/56195377
复制相似问题