Convert Int Value bigger 256 to Unicode - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Convert Int Value bigger 256 to Unicode (/thread-25066.html) |
Convert Int Value bigger 256 to Unicode - lastyle - Mar-17-2020 Hi all, i need to save a list which contains mixed data of unicode and int values. I`d need to convert the int values before adding them to the list to unicode else the io.open moans that the values need to be unicde only when savaing. So far so good, but how to convert a value bigger 256 to unicode ? I dont expect Values bigger than a 16 bit value RE: Convert Int Value bigger 256 to Unicode - DeaD_EyE - Mar-18-2020 chr(4096)
RE: Convert Int Value bigger 256 to Unicode - ndc85430 - Mar-18-2020 Why do you have these mixed values in the first place? RE: Convert Int Value bigger 256 to Unicode - lastyle - Mar-18-2020 (Mar-18-2020, 07:22 AM)DeaD_EyE Wrote: (Mar-18-2020, 07:28 AM)ndc85430 Wrote: Why do you have these mixed values in the first place? I need to exchange the content "PRG" with a Filecounter each 5th Line beginning at line 9 so i created a Value that counts the Files backwards If i would know how to start with a unicode Counter that would help aswell. I`ll attach the File (inside the zip)i am Parsing with the Function i am using for that for better understanding. When using the chr decoder the script stops as the Number is decoded to str instead unicode. def changeprg(): a = 0 fc = 0 lc = 1 lst3=[] addstr="" with io.open("ud- "+sys.argv[1]+"fr.seq", encoding='ascii', errors='replace') as f: for line in f: addstr=line a +=1 lc +=1 if a == 4: # get numer of Files stored in this List fc = int(line) print (fc) lc = 0 if lc ==5: # stop each 5th Line where PRG Filetype is stored, beginning with Line 9 in File print (fc) print(line) print (a) lc = 0 fc -=1 addstr=chr(fc) lst3.append(addstr) with io.open("ud- "+sys.argv[1]+"-fr-renumbered.seq", 'w', encoding='ascii', errors='replace', newline='\r') as f: for item in lst3: f.write(item) RE: Convert Int Value bigger 256 to Unicode - lastyle - Mar-19-2020 Fixed it myself. Sometimes it s so easy,but you simply are to blind and dont notice it s already a Function availabledef changeprg(): a = 0 fc = 0 lc = 1 lst3=[] addstr="" with io.open("ud- "+sys.argv[1]+"fr.seq", encoding='ascii', errors='replace') as f: for line in f: addstr=line a +=1 lc +=1 if a == 4: # get numer of Files stored in this List fc = int(line) lc = 0 if lc ==5: # stop each 5th Line where PRG Filetype is stored, beginning with Line 9 in File addstr="" addstr=unicode(fc) + '\n' # toggle Value to unicode lc = 0 fc -=1 lst3.append(addstr) with io.open("ud- "+sys.argv[1]+"-fr-renumbered.seq", 'w', encoding='ascii', errors='replace', newline='\r') as f: for item in lst3: f.write(item) |