Im working on a project where i have to get the number of printers that are allocated to a certain job and need to split the file name up so that i can read the type and the number of printers and if its a half bed or not. The file name will look something similar to this <name>_P<AQT or INI>_B<0-9>[h - for half beds] but would be like 20140702_PAQT_B6h and im wanting the _P and the _B part of it.
abaddon2031
0
Junior Poster in Training
Recommended Answers
Jump to Postuse split in a loop on "_"
for letter in file.split("_"): if letter[2] == 'B': do_something elif letter[2] == 'P': do_something else: something_else
Jump to PostIn the spirit of more than one way to do it, you can also do this:
for i in '20140702_PAQT_B6h'.split('_'): if i.startswith('P'): print (i) elif i.startswith('B'): print (i)
Output will be like:
PAQT B6h
Note however, that you can use this if …
All 6 Replies
David W
131
Practically a Posting Shark
flebber
12
Light Poster
2teez
43
Posting Whiz
Gribouillis
1,391
Programming Explorer
Team Colleague
2teez
43
Posting Whiz
snippsat
661
Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.