You are not logged in.

#1 2005-04-15 06:48:36

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

python and pacman.log

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 smile

Offline

#2 2005-04-15 07:24:07

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: python and pacman.log

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.  tongue


"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

#3 2005-04-15 07:56:47

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

Re: python and pacman.log

Thanks, works well enough that I can go from here smile 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 big_smile

Offline

#4 2005-04-15 15:50:26

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: python and pacman.log

cactus wrote:

ps. I am new to python too.  tongue

as am I - it's funny to see how long python has been around...

Offline

#5 2005-04-16 02:55:37

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: python and pacman.log

phrakture wrote:
cactus wrote:

ps. I am new to python too.  tongue

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 tongue

Offline

Board footer

Powered by FluxBB