简体   繁体   中英

how to solve problem ord utf_8 in simple pythhon 3.8 programm?

I run the program b.py how can I make the third line of the output look the same as the first b.py:

S='----Ăł---'

def x(S):
  print(f'{S=}')
  RES=[]
  for s in S:
    RES+=[ord(s)]
  return RES

print(x(S))                           # first line result
with open('b.py') as F:
  print(x(F.readlines()[0]))          # thrid line result

I found the answer: open the file with encofding = 'utf_8':

     `with open ('b.py, encoding =' utf_8 ') as F:
        ....
     '

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM