我怎样才能使一个ASCII字符串转换器在Python中使用:''.join(chr(i)为我在templist中)

问题描述:

我试图使ASCII到字符串转换器(不知道这是否是正确的术语)使用chr()但是当我输入类似于68(大写字母D)的东西时,没有任何反应。我试图用这种想法来完成它:我怎样才能使一个ASCII字符串转换器在Python中使用:''.join(chr(i)为我在templist中)

>>> L = [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100] 
>>> ''.join(chr(i) for i in L) 
'hello, world' 

我希望它与用户自定义输入的程序运行,所以我想出了这个:

templist = [] 
number = int(input("Please enter an ASCII number here: ")) 
templist.append(number) 
''.join(chr(i) for i in templist) 

正如我上面可是说,当我输入一个值时,没有任何反应。

任何帮助,非常感谢。

编辑:我已经尝试打印templist,但它只是让我回到我想要转换为字符(68)的数字。

+0

https://docs.python.org/3 /library/functions.html#print – davidism

+1

没有代码会导致数字出现在输出中。按照davidism的建议,参见print()函数。 – lit

+0

在第一种情况下,您正在使用REPL。第二,你正在运行自定义脚本。在REPL中,最后一个隐含值将被隐式打印。在脚本中,您需要明确地打印它。 –

我需要把 ''。加入(CHR(i)对于我在templist)在打印语句,这样的代码看起来像这样

templist = [] 
number = int(input("Please enter an ASCII number here: ")) 
templist.append(number) 
print(''.join(chr(i) for i in templist))