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
|
# -*- coding: cp1252 -*-
import re
import sys
def listeMot(ligne):
mot =["empty"]
mots = re.findall('\w*', ligne) #match tous les caractère alphanumérique consécutif
for mot in mots:
if mot == "": #les match nul renvoi une chaine videjusqu au prochain
mots.remove(mot) #match je les supprime donc ici
return mots
def main():
mots =[]
myFile = open("C:\\Documents and Settings\\All Users\\bru-11-r6.car.belbone.rtf",'r') #fichier situé dans le même dossier
for ligne in myFile: #que le script
mots.extend(listeMot(ligne)) #concaténation de chaques listes de mots
print "fini liste des mots : " #recuperés
for mot in mots:
print mot
main() |
Partager