Python Forum
list from a data file problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list from a data file problem
#1
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
Reply
#2
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?
Reply
#3
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
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 317 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Problem with "Number List" problem on HackerRank Pnerd 5 2,034 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  Why changing data in a copied list changes the original list? plumberpy 3 2,190 Aug-14-2021, 02:26 AM
Last Post: plumberpy
  Looking for data/info on a perticular data-proccesing problem. MvGulik 9 3,780 May-01-2021, 07:43 AM
Last Post: MvGulik
  xml file creation from an XML file template and data from an excel file naji_python 1 2,069 Dec-21-2020, 03:24 PM
Last Post: Gribouillis
  Regex text file to store data in list TheSithSiggi 1 1,500 Dec-03-2020, 04:46 PM
Last Post: bowlofred
  How to save CSV file data into the Azure Data Lake Storage Gen2 table? Mangesh121 0 2,079 Jun-26-2020, 11:59 AM
Last Post: Mangesh121
  Problem reading data from file player1681 2 3,676 May-22-2020, 08:57 AM
Last Post: player1681
  problem coverting string data file to dictionary AKNL 22 6,268 Mar-10-2020, 01:27 PM
Last Post: AKNL
  Writing list as a file, then reading that file as a list Zoastria_Balnala 3 2,551 Oct-17-2019, 07:54 PM
Last Post: Zoastria_Balnala

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020