[Tutor] Re: Tutor digest, Vol 1 #2066 - 15 msgs
fleet@teachout.org
fleet@teachout.org
Tue Nov 19 07:23:13 2002
test.py
import readline
s=readline.readline("Name: ")
[~/python]$ python2 test.py
Traceback (most recent call last):
File "test.py", line 3, in ?
s=readline.readline("name: ")
AttributeError: 'module' object has no attribute 'readline'
???
- fleet -
On Tue, 19 Nov 2002 tutor-request@python.org wrote:
> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-request@python.org
>
> You can reach the person managing the list at
> tutor-admin@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
> 1. RE: while with function (fleet@teachout.org)
> 2. regexes, thanks (Matt)
> 3. Re: regexes, thanks (lumbricus@gmx.net)
> 4. RE: while with function (lumbricus@gmx.net)
> 5. Re: regexes, thanks (lumbricus@gmx.net)
> 6. bEGINNING PROGRAMMER NEEDS HELP WITH CLASSES. CHECK CODE (DAVID BRALLIER)
> 7. RE: my newbie program (alan.gauld@bt.com)
> 8. RE: while with function (alan.gauld@bt.com)
> 9. Re: bEGINNING PROGRAMMER NEEDS HELP WITH CLASSES. CHECK CODE (Thomi Richards)
> 10. RE: Any Suggestions? (Magnus Lycka)
> 11. Re: speeding code along (Thomi Richards)
> 12. Re: my newbie program (Gregor Lingl)
> 13. Re: bEGINNING PROGRAMMER NEEDS HELP WITH CLASSES. CHECK CODE (Gregor Lingl)
> 14. RE: while with function (Magnus Lycka)
> 15. Re: regexes, thanks (Magnus Lycka)
>
> --__--__--
>
> Message: 1
> Date: Mon, 18 Nov 2002 22:07:33 -0500 (EST)
> From: <fleet@teachout.org>
> Reply-To: <fleet@teachout.org>
> To: Magnus Lycka <magnus@thinkware.se>
> cc: <tutor@python.org>
> Subject: RE: [Tutor] while with function
>
> On Mon, 18 Nov 2002, Magnus Lycka wrote:
>
> > At 15:42 2002-11-18 -0500, fleet@teachout.org wrote:
> > >The "address book" entries will be created, maintained and utilized from a
> > >command line.
>
> That's a Linux command line, btw.
>
> - fleet -
>
>
>
> --__--__--
>
> Message: 2
> Date: Mon, 18 Nov 2002 22:52:00 -0500
> From: Matt <matt@ipwib.net>
> To: tutor@python.org
> Subject: [Tutor] regexes, thanks
>
> I'm working on a renaming utility for use in renaming mp3's that I
> ripped from cd while using Windows (and consequently using my preferred
> naming convention at the time, which I no longer wish to use). I
> created a file listing, then tried manipulating it. I wanted to make it
> change every word (defined by only letter sequences) to have the first
> letter changed to uppercase. Only it doesn't seem that regexes are
> fully implemented in python (\u,\U)... So, I tried using a function:
>
> def upper(a)
> return(string.capitalize(a))
>
> words = re.compile('([a-zA-Z]+)')
> new_filename = words.sub(upper, filename)
>
> Only this doesn't work, as it doesn't pass the matched string, but a
> MatchObject. This seemed really strange to me. Eventually I came up
> with this:
>
> def upper(a):
> return(string.capitalize(a.string[a.start():a.end()]))
>
> words = re.compile('([a-zA-Z]+)')
> new_filename = words.sub(upper, filename)
>
> This seems like a really complicated way to do something that I thought
> would be relatively simple. Is this the best way to do it? Or am I off
> track and creating unnecessary complexity?
>
> Btw, thanks to Danny Yoo for helping me out with python audio
> information. Several of the sites have proved extremely helpful.
>
> -Matt
>
>
>
> --__--__--
>
> Message: 3
> Date: Tue, 19 Nov 2002 05:51:33 +0100 (MET)
> From: lumbricus@gmx.net
> To: tutor@python.org
> Subject: Re: [Tutor] regexes, thanks
>
> Hi!
>
> > def upper(a)
> > return(string.capitalize(a))
>
> This already exists:
> >>> "hello".upper()
> 'HELLO'
>
> > words = re.compile('([a-zA-Z]+)')
> > new_filename = words.sub(upper, filename)
> >
> > Only this doesn't work, as it doesn't pass the matched string, but a
> > MatchObject. This seemed really strange to me.
>
> >>> help(re.compile)
> Help on function compile:
>
> compile(pattern, flags=0)
> Compile a regular expression pattern, returning a pattern object.
>
> >
> > def upper(a):
> > return(string.capitalize(a.string[a.start():a.end()]))
> >
> > words = re.compile('([a-zA-Z]+)')
> > new_filename = words.sub(upper, filename)
>
> Something along
>
> import glob
> for f in glob.glob("*.mp3"):
> new=f.upper()
>
> might be what you want?
>
> HTH, J"o!
>
>