list from a data file problem - 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: list from a data file problem (/thread-29674.html) |
list from a data file problem - Marre - Sep-15-2020 hello. i need advice for an simple problem. with open("clusters.csv", "r") as data_file: all_words = [] for line in data_file.readlines(): for word in line.split("'. "): all_words.append(word.lower()) unique_words = set(all_words) xlen = len(unique_words) #print xlen xlist = list(unique_words) for i in range(xlen): print xlist[i] # i get the result: (173, 151, 68) ; 1 (255, 230, 191) ; 1 (103, 88, 31) ; 1 (14, 15, 0) ; 1 (48, 45, 19) ; 1 # i want the result to bee (173, 151, 68) (255, 230, 191) (103, 88, 31) (14, 15, 0) (48, 45, 19)to use it as a variabel value i am greatful for your help Br Marre RE: list from a data file problem - Gribouillis - Sep-15-2020 The split statement seems incorrect. Could you post a few lines of the data file? Also why do you still run Python 2 instead of Python 3? RE: list from a data file problem - Marre - Sep-16-2020 I have 4 old python2 programs.I have try to use python3,but it allways complain obout some modules,and print error etc. thats why. But i want to send the csv file to you ,but i dont understand how.Cn you help me Br Marre RE: list from a data file problem - Marre - Sep-22-2020 i have struggle with the problem and get my solusion: with open("clusters.csv", "r") as data_file: all_words = [] for line in data_file.readlines(): for word in line.split("'. "): all_words.append(word.lower()) unique_words = set(all_words) i = 0 xlen = len(unique_words) xlist = list(unique_words) while i <= (xlen): x = xlist[i].find(";"); # längd x1 = xlist[i].find(",") # 1 comma plats x2 = x1 + xlist[i].find(",") # 2 comma plats x3 = xlist[i].find(")") # ) plats ww = (xlist[i][0:x]) # clusterdata rr = int(ww[1:x1]) # röd gg = int(ww[x1+2:x2+1]) # grön bb = int(ww[x2+3:x3]) # blue korr_value = (rr, gg, bb, 255) pixel_value = (rr, gg, bb, 255) print korr_value filename = ( str(rr)+"_"+str(gg)+"_"+str(bb) ) suffix = ".png" thanks to all that hav toughtabout it. |