Convert an input file to ascii python -
i'm trying write programme opens file, reads file , converts file ascii characters , writes characters , output file. however, when run programme <_io.textiowrapper name='output.txt' mode='r' encoding='cp1252'>
def convert_to_ascii(file,output): f = open(file, 'r') b = open(output, 'w') f_line=str(f.readline()) _ in f: b.write([ord(str(f_line[i])) in f_line]) f.close() b.close() file = input('what file wish convert?') convert_to_ascii(file,'output.txt') p=open('output.txt', 'r') print(p)
you can seek this,
file_content = open(file, 'r').read() file_content = ''.join(str(ord(c)) c in file_content)) open('output.txt','w').write(file_content)
python ascii
No comments:
Post a Comment