You are not logged in.
Pages: 1
Okay, I'm mentally retarded when it comes to python. Nah not really, but I'm pretty new. I wanna parse the pacman.log for some info to use, sounds easy but it's not. I used to do a bit of PHP and I know I could do it super easy with that so this is driving me crazy that it doens't just work. I'm obviously doing something wrong somewhere I just can't figure out where.
I'm using code something like this, I want to get a list of what was installed and when.
import re
r = open('/var/log/pacman.log')
log = r.read()
r.close()
exp = re.compile('[(.+)] installed (.+)', re.MULTILINE)
prnt exp.match(log)
Every time it prints 'None" which isn't what I'm after. Basic debugging says log contains the data I'm chasing. Any tips would be greatly appreciated.
Thanks
Offline
what are you trying to do?
If you just want a python list (for gods sake, why can't they just call it an array), with each element being one of the strings found...
import re
r=open('/var/log/pacman.log','r')
log = r.read()
r.close()
rexp = re.findall('^.*installed.*$',log,re.M)
##rexp is now a list of install lines.
print rexp
ps. I am new to python too.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Thanks, works well enough that I can go from here I'll split the string up to get the name and date, that's easy enough. There'll be a thread in the user contributions forum soon with the result of this
Offline
ps. I am new to python too.
as am I - it's funny to see how long python has been around...
Offline
cactus wrote:ps. I am new to python too.
as am I - it's funny to see how long python has been around...
me three
and cactus, they call it a list because a list can have multiple types in it, whereas an array implies a single type.
list sounds cooler too
Offline
Pages: 1