Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python : an integer is required (got type str)

Tags:

python

I just need to print a list of int to ASCII.

a=list(str(12345))
for q in a:
    print(chr(q))

an integer is required (got type str)

why I'm getting that error?

like image 685
Akash D Avatar asked Oct 29 '22 23:10

Akash D


1 Answers

You are passing a string value into the chr() function. This should work:

a=list(str(12345))
for q in a:
    print(chr(int(q)))

#The above code will work but this will print out characters, as 1-5
# in the ASCII table are not visible characters.

a = [65,66,67,68,69]
for q in a:
    print(chr(q))
like image 178
Connor Avatar answered Nov 15 '22 05:11

Connor