I have a csv file that looks like this:
Mon-000101,100.27242,9.608597,11.082,10.034,0.39,I,0.39,I,31.1,31.1,,double with 1355,,,,,,,,
Mon-000171,100.2923,9.52286,14.834,14.385,0.45,I,0.45,I,33.7,33.7,,,,,,,,,,
Mon-000174,100.27621,9.563802,11.605,10.134,0.95,I,1.29,I,30.8,30.8,,,,,,,,,,
...it's a few hundred lines long.
I just want to grab the Mon-000101 (not just that specific one, but all the Mon-######) items. I have this really really ugly little script I threw together:
file_list1 = open(raw_input("Enter your list file: "))
file_lines = []
for line in file_list1:
line.replace(' ','\n')
for item in line.split('\n'):
file_lines.append(item)
stringit = ''
for item in file_lines:
stringit += item
IDs = re.findall('Mon-\d\d\d\d\d\d',stringit)
stringIDs = str(IDs)
new = stringIDs.replace(',','\n')
newer = new.replace('\'','')
newer2 = newer.replace('[\]','')
newer3 = newer2.replace(']','')
newer4 = newer3.replace('[','')
newer5 = newer4.replace(' ','')
file_write = open("Testit.txt","w+")
file_write.write(newer4)
print newer4
file_write.close()
I know it's ugly. Clearly I don't know what I'm doing with the regex stuff, but aside from that I want to know a more efficient way of replacing all the characters that I'm replacing. I know this isn't how it's done. I've tried something along the lines of
newer2 = newer.replace('([\',\[\] ])','')
which I sorta pieced together from various posts. That didn't work though, in fact it didn't do anything.
I want to see what a more efficient way of doing this looks like.
Thanks.
I'm also aware that my variable naming is not sufficient/not up to the style guide. This is just something I quickly threw together.
csvlibrary.