please forgive my lack of Deutsche, but I don't know where else to ask for help.
I have several files with file names that look like this:
mas.4.res.120
mas.4.res.124
mas.4.res.122
mas.4.res.128
mas.4.res.129
I need to extract the last three numbers and print it to a file.
Please help me with either python or awk
thanks again
editing batch filenames
Just split the names at the dots and use the last element:
Code: Alles auswählen
In [14]:filenames = ['mas.4.res.120', 'mas.4.res.124', 'mas.4.res.122']
In [15]:for filename in filenames:
.15.: print filename.split('.')[-1]
.15.:
120
124
122
danke!
can I replace
with
?
can I replace
Code: Alles auswählen
for filename in filenames
Code: Alles auswählen
for filename in path
- gerold
- Python-Forum Veteran
- Beiträge: 5555
- Registriert: Samstag 28. Februar 2004, 22:04
- Wohnort: Oberhofen im Inntal (Tirol)
- Kontaktdaten:
Hi drpython!drpython hat geschrieben:can I replacewithCode: Alles auswählen
for filename in filenames
Code: Alles auswählen
for filename in path
I think, the simplest way is, to use "glob". Here´s an example:
Code: Alles auswählen
import glob
filelist = glob.glob("./mas*")
for filename in filelist:
print filename.split(".")[-1]
Gerold
Zuletzt geändert von gerold am Samstag 24. Juni 2006, 00:01, insgesamt 1-mal geändert.
http://halvar.at | Kleiner Bascom AVR Kurs
Wissen hat eine wunderbare Eigenschaft: Es verdoppelt sich, wenn man es teilt.
Wissen hat eine wunderbare Eigenschaft: Es verdoppelt sich, wenn man es teilt.
Hi drpythondrpython hat geschrieben:is filename a variable? forgive me, I'm VERY new to python.
Yes it is a variable. How can i explain it to you?
ok a simple example:
Code: Alles auswählen
for x in (1, 2, 3, 4, 5):
print x
But I think here
and here (7.3) it is besser explained.
mfg
Thomas :-)
Thomas :-)
no, that was a great explanation! thanks again!!!
I tried to run my Python code and there was something wrong...infinite loop I think...I must have typed something wrong...so I'll check tomorrow
thanks again !
Dankeshun...i think?
I tried to run my Python code and there was something wrong...infinite loop I think...I must have typed something wrong...so I'll check tomorrow
thanks again !
Dankeshun...i think?