Ich mache grade meine ersten Schritte mit Python und versuche etwa Folgendes:
Code: Alles auswählen
http://firefoxmac.furbism.com/rss_feed.php|||
http://www.forbes.com/leadership/governance/index.xml|||
http://www.forbes.com/ebusiness/index.xml|||
]...]
Also bastle ich mir eine Klasse Textfile:
Code: Alles auswählen
lass textfile:
ntfiles=0
def __init__(self,fname):
textfile.ntfiles+=1
self.name=fname
self.fh = open(fname)
self.lines=self.fh.readlines()
self.nlines=len(self.lines)
self.nwords=0
self.wordcount()
def wordcount(self):
"finds the number of words in the file"
for l in self.lines:
w=l.split()
self.nwords+=len(w)
def grep(self, target):
"prints out all lines containin target"
for l in self.lines:
if l.find(target)>=0:
print l
Code: Alles auswählen
a=textfile('urls')
# print "the number of text files open is", textfile.ntfiles
print "here is some information about them (name, lines, words):"
for f in [a]:
print f.name, f.nlines
# listenlaenge = f.nlines
# so weit ist das alles klar...
# aber:
for i in range(f.nlines-1):
one_url=(f.lines[i].split())
clean_url=
print clean_url
split() braucht immer einen Separator. Ich habe halt keinen...
Das ist für mich nen Lernbeispiel. Ich kann das sicher ohne Python mit awk auf der Shell machen oder in C++ in 2 Minuten über nen Array.
Allerdings will ich ja Python lernen
Hat da wer ne Idee hier?
Gruß,
zucki