little programming probleme
Paul Watson
pwatson at redlinec.com
Wed Mar 12 17:49:02 EST 2003
import string
blob = "now is\nthe was#yesterday\ntime\n"
chunk = string.split(blob, "\n")
print chunk
for i in range(len(chunk)):
print chunk[i]
for j in range(len(chunk[i])):
if chunk[i][j] == '#': break
print chunk[i][j]
import re
p = re.compile("\#")
for i in range(len(chunk)):
m = p.split(chunk[i])
print m[0]
"Jonas Geiregat" <kemu at sdf-eu.org> wrote in message
news:3e6fab9d$0$83883$ba620e4c at news.skynet.be...
> I have a string and I want to delete all comments , comments start with a
#
>
> here is my code
> conf is my string where I want to delete comments I think the probleme
> is that if he finds a comment he delete's the element of the list but
> then he can't loop true that element anymore so I should break the loop
> and start the first one again but I don't know how if it could be any
> help I added my error code un the code
>
>
> chunk = string.split(conf,"\n")
> for i in range(len(chunk)):
> for x in range(len(chunk[i])):
> if chunk[i][x] == "#":
> print chunk[i]
>
>
>
>
>
>
>
>
>
>
>
>
> for x in range(len(chunk[i])):
> IndexError: list index out of range
>
>
> regards Jonas
>
More information about the Python-list
mailing list