3/4 questions resolu
02 mai 2009 A suivre, ICI
Python V3

Bonjour tout le monde, (Je met a jour ce post pour que ce soit plus simple)

Je suis debutant en programmation, c'est avec un amis que je decouvre le language "Python".
Je souhaiterais recuperer des donnees depuis un fichier .txt

1) Le nom de la "target".
(dans ce cas c'est "Longhorn Krond the Unliving" mais ca peut etre "an Undead")
La target : Longhorn Krond the Unliving

2) Si "Guzzlerobeer" apparait dans le texte, le citer [FONCTIONE]
Guzzlerobeer : vous a "heal" durant ce combat

3) Le nombre de fois que Guzzlerobeer me "heal" [FONCTIONE]
(en locurence, une fois dans ce log)
Nombre de fois que Guzzlerobeer vous a "heal" : 1

4) Cummuler toutes sorte de valeurs et les classer [FONCTIONE]

On vous a heal pour : 3000 points


Fichier Texte type :
Longhorn Krond the Unliving has been awakened by Tallaared.
[Mon Dec 01 22:51:07 2008] Your target is too far away, get closer!
[Mon Dec 01 22:51:08 2008] Boldak's holy blade cleanses his target!(20696)
[Mon Dec 01 22:51:08 2008] Your target is too far away, get closer!
[Mon Dec 01 22:51:10 2008] You crush Longhorn Krond the Unliving for 236 points of damage.
[Mon Dec 01 22:51:11 2008] You cannot see your target.
[Mon Dec 01 22:51:13 2008] Gogad hit Longhorn Krond the Unliving for 176 points of non-melee damage.
[Mon Dec 01 22:51:17 2008] Gogad`s pet slashes Longhorn Krond the Unliving for 107 points of damage.
[Mon Dec 01 22:51:18 2008] The pounding hooves deafen you. You have taken 3520 points of damage.
[Mon Dec 01 22:51:19 2008] a jester of bristlebane says 'How's the weather up there?'
[Mon Dec 01 22:51:19 2008] Gogad scores a critical hit! (244)
[Mon Dec 01 22:51:33 2008] Your Focused Paragon of Spirit spell has worn off of Hotdamm.
[Mon Dec 01 22:51:35 2008] The stomping echoes fade away.
[Mon Dec 01 22:52:04 2008] Your Belt of Contempt feels alive with power.
[Mon Dec 01 22:52:26 2008] Guzzlerobeer has healed you for 1000 points.
[Mon Dec 01 22:52:32 2008] Pierro has healed you for 2000 points.
[Mon Dec 01 22:52:39 2008] Your Runed Diamond flickers with a pale light.
[Mon Dec 01 22:52:39 2008] Your Spiritcaller Totem of the Feral feels alive with power.
[Mon Dec 01 22:53:57 2008] You gained raid experience!
[Mon Dec 01 22:53:57 2008] Longhorn Krond the Unliving's corpse falls.
Voici ou j'en suis dans mon Code Python :
Ce qui fonctionne uniquement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
import re
 
def foo (fichier):
	z = open(fichier, 'r')
	s = 0
	somme1 = 0
	somme2 = 0
 
	for ligne in z:
		ligne = ligne[:-1]
		a = re.search('Guzzlerobeer',ligne)
		d = a
 
		c = re.findall('Guzzlerobeer',ligne)
		s = s + len(c)
 
		p1 = re.compile('(?P<nombre>[0-9]+) points of damage')
		n = p1.search(ligne)
 
		p2 = re.compile('(?P<nombre>[0-9]+) points of non-melee damage')
		m = p2.search(ligne)
 
		if n:
			str_nc = n.group('nombre')
			somme1 = somme1 + int(str_nc)
		if m:
			str_nb = m.group('nombre')
			somme2 = somme2 + int(str_nb)
		if a:
			Guzzlerobeer = a
 
 
	print ("Le mot recherche est :", Guzzlerobeer.group())
	print ("Le nombre de fois que ce mot apparait est :", s)
	print ("total points of damage : ", somme1)
	print ("total points non-melee of damage : ", somme2)
	z.close()

Voila, si vous avez d'autres indices SVP
Merci.