I am creating a program that will iterate through a folder and it sub folders. It pulls the desired info and stores it in a list but some of the items in the list look like ['85670', '3'] instead of ['85670']. How can i fix this ?
code:
partNumbers = []
entries = (r'S:\WebDrawings\_Archive_&&&(Old WebDrawings Folder)&&&')
for subdir, dirs, files in os.walk(entries):
for name in files:
if name.startswith(("prnt", "prnt_")):
partNumbertemp = re.findall('[0-9]+', name)
partNumbers.append(partNumbertemp) # Appends the array with the regex function to parse only the integers of the file name to be used later
while ([] in partNumbers):
partNumbers.remove([])
print(partNumbers)
I tried converting it to a set to get rid of duplicates and also tried to remove it using the same method I used to remove blank entries and nothing worked.
my data prints out like this
['34010'], ['34011', '3'], ['34011'], ['34012', '3'], ['34012'], ['34013', '3'], ['34013'], ['34015', '3'], ['34015'], ['34016', '3'], ['34016'], ['34017', '3'], ['34017'], ['34018', '3'], ['34018'], ['33300', '3'], ['33300'], ['33301', '3'], ['33301'], ['33302', '3'], ['33302'], ['33303', '3'], ['33303'], ['33304', '3'], ['33304'], ['33305', '3'], ['33305'], ['47311'], ['89294'], ['89295'], ['87536'], ['88385'], ['88386'], ['88387'], ['87535'], ['88386'], ['87535'], ['03682'], ['03683'], ['36347'], ['37603'], ['53384'], ['34545'], ['85626'], ['85627'], ['85639'], ['85644'], ['85617'], ['85622'], ['85623'], ['85630'], ['85631'], ['85632'], ['85633'], ['85638'], ['85639'], ['85640'], ['85641'], ['85643'], ['85644'], ['85670'], ['85671'], ['85515'], ['85516'], ['85604'], ['85624'], ['85548'], ['85580'], ['85581'], ['85663'], ['85688'], ['85699'], ['85717'], ['85722'], ['86025'], ['83927910'], ['85705'], ['85539'], ['85582'], ['85649', '3'], ['85618'], ['85511', '3'], ['85512', '3'], ['85513', '3'], ['85543', '3'], ['85545', '3'], ['85546', '3'], ['85547', '3'], ['85548', '3'], ['85549', '3'], ['85550', '3'], ['85551', '3'], ['85552', '3'], ['85553', '3'], ['85554', '3'], ['85587', '3'], ['85588', '3'], ['85663', '3'], ['85678', '3'], ['85717', '3'], ['85722', '3'], ['85617', '3'], ['85622', '3'], ['85623', '3'], ['85624', '3'], ['85625', '3'], ['85626', '3'], ['85630', '3'], ['85631', '3'], ['85632', '3'], ['85633', '3'], ['85638', '3'], ['85640', '3'], ['85641', '3'], ['85643', '3'], ['85664', '3'], ['85665', '3'], ['85666', '3'], ['85670', '3'], ['85688', '3'], ['85705', '3'], ['86025', '3'], ['54403', '3'], ['54404', '3'], ['53272'], ['83340'], ['53261'], ['53261'], ['53261'], ['55017'], ['35481'], ['35482'], ['35483'], ['35484'], ['35485'], ['35486'], ['35487'], ['35488'], ['35489']]
If you only want the first number you can do a list slice:
partNumbertemp = re.findall('[0-9]+', name)[:1]