[Tutor] Newbie append puzzle
Tim Ronning
tim.ronning at start.no
Fri Nov 7 08:55:09 EST 2003
På Wed, 5 Nov 2003 14:07:42 +0100 (CET), skrev Michael Janssen
<Janssen at rz.uni-frankfurt.de>:
> if mp3[-1] != "\n":
> mp3 = mp3 + "\n"
>
>
> or even better use the stringsmethod endswith:
>
> if not mp3.endswith("\n"):
> mp3 = mp3 + "\n"
>
> i would take for "append" (with an optional parameter playlist):
>
> def append(mp3, playlist="playlist"):
> if not mp3.endswith("\n"):
> mp3 = mp3 + "\n"
> app = open(playlist,"a")
> app.write(mp3)
> app.close()
>
> this way you get, with a little luck, functions
> once-defined-working-ever. Helps much to concentrate on new-to-write
> functionality.
>
> Michael
>
Ofcourse. Some years back I did learn Pascal and then some C (most of it
gone now I'm afraid) and I think I have some small problems realizing how
"obvious" Python can be at times. The "if not mp3.endswith("\n")" is a
brilliant example of that. It sounds like something you could throw out in
a conversation with the wife during dinner! I need to "beam" my mind to a
higher level I think!
Thanks again Michael
Best regards
Tim R
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
More information about the Tutor
mailing list