[Tutor] Re: Tutor Digest, Vol 9, Issue 82

Jay Mutter jmutter at uakron.edu
Sun Nov 28 01:26:36 CET 2004


  thanks

On Nov 26, 2004, at 11:07 PM, tutor-request at python.org wrote:

> Send Tutor mailing list submissions to
> 	tutor at 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 at python.org
>
> You can reach the person managing the list at
> 	tutor-owner at 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: String matching (Bernard Lebel)
>    2. Re: String matching (Danny Yoo)
>    3. Re: String matching (Jacob S.)
>    4. RE: String matching (Gooch, John)
>    5. Re: Change to Python 2.4? (Alan Gauld)
>    6. Re: Help with very basic question (Alan Gauld)
>    7. Re: Database questions (Bill Burns)
>    8. Re: time comparison question (Liam Clarke)
>    9. Re: Database questions (Bill Burns)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 26 Nov 2004 15:34:01 -0500
> From: Bernard Lebel <python at bernardlebel.com>
> Subject: Re: [Tutor] String matching
> To: tutor at python.org
> Message-ID: <41A79339.5070806 at bernardlebel.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Allrighty, thanks a lot everyone.
>
> Bernard
>
>
> Danny Yoo wrote:
>>
>>>>>>> mystring = 'helloworldmynameisbernardlebel'
>>>>
>>>> Now I wish to attempt a match with 'bernard'.
>>>>
>>>>
>>>>>>> if not re.compile( 'bernard' ).match( mystring ) == None:
>>>>
>>>> ... 	print 'success'
>>>>
>>>> Well, nothing gets printed. Could anyone tell me how to achieve that
>>>> simple type of matching?
>>>
>>> You need to use search(), not match(). match() tries to match the
>>> pattern to the beginning of the string. IOW, in your case it tries to
>>> see if mystring begins with "bernard".
>>
>>
>>
>> Hi Bernard,
>>
>> If it helps, imagine that match() always puts a beginning anchor '^' 
>> at
>> the beginning of the pattern, and you'll see the difference between
>> match() and search().
>>
>> (I'm lying in a small way: that's not exactly how match() works, but 
>> it's
>> close... *grin*)
>>
>> There's also a brief discussion about it in the documentation:
>>
>>     http://www.python.org/doc/lib/matching-searching.html
>>
>> which tries to show more formally why we have both match() and 
>> search().
>>
>> Good luck to you!
>
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 26 Nov 2004 12:35:05 -0800 (PST)
> From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
> Subject: Re: [Tutor] String matching
> To: Bernard Lebel <python at bernardlebel.com>
> Cc: tutor at python.org
> Message-ID:
> 	<Pine.LNX.4.44.0411261227370.24364-100000 at hkn.eecs.berkeley.edu>
> Content-Type: TEXT/PLAIN; charset=US-ASCII
>
>
>
> On Fri, 26 Nov 2004, Bernard Lebel wrote:
>
>>>>> mystring = 'helloworldmynameisbernardlebel'
>>
>>>>> if not re.compile( 'bernard' ).match( mystring ) == None:
>> ... 	print 'success'
>>
>> Well, nothing gets printed. Could anyone tell me how to achieve that
>> simple type of matching?
>
>
> Hi Bernard,
>
> Oh, one more thing.  If you're just trying to see if a string is a
> substring of another, then you might want to just say something like 
> this:
>
> ###
> if 'bernard' in mystring: ...
> ###
>
>
> This is a simpler way to do a substring match.  In general, we can see 
> if
> one string is a substring of another by using the 'in' operator:
>
>     if substring in anotherstring: ...
>
>
> If we need to know where a substring matches in the larger string, then
> there's a 'find()' string method that should do the trick.
>
> ###
>>>> "this is a test".find("is")
> 2
> ###
>
> Note that this find() method is only checking for substring matching: 
> it
> has no knowledge of words.  If we needed it to match the whole word, 
> then
> we'd probably need regular expressions:
>
> ###
>>>> import re
>>>> re.search(r'\bis\b', "this is a test").start()
> 5
> ###
>
> But if we don't need the full power of regular expressions, then we may
> prefer the simpler exact string matching that find() gives us.
>
>
> Good luck!
>
>
>
> ------------------------------
>
> Message: 3
> Date: Fri, 26 Nov 2004 12:56:55 -0500
> From: "Jacob S." <keridee at jayco.net>
> Subject: Re: [Tutor] String matching
> To: "Bernard Lebel" <python at bernardlebel.com>
> Cc: tutor at python.org
> Message-ID: <000201c4d415$5dd63e60$415328cf at JSLAPTOP>
> Content-Type: text/plain;	charset="iso-8859-1"
>
> Hi Bernard!
>
>> Hello,
>>
>> I'm a little bit confused about the match/search methods of the string
>> module for regular expressions. I have looked the regular expression 
>> doc
>> and I can't that one simple answer.
>>
>> So please excuse the basiqueness of my question, as I am used with the
>> .match method of JScript and it kind of matches anything....
>>
>> Let say I have this string:
>>
>>>>> import re
>>>>> mystring = 'helloworldmynameisbernardlebel'
>>
>> Now I wish to attempt a match with 'bernard'.
>>
>>>>> if not re.compile( 'bernard' ).match( mystring ) == None:
>> ... print 'success'
>
> First, you are printinting redundant code here. You are using double
> negatives.
> You first check to see if re.compile('bernard').match(mystring) 
> registers
> false, if it is false the expression registers true. Then you check to 
> see
> if that expression registers false. So really
> the equivalent expression is
>
> if re.compile('bernard').match(mystring):
>     print 'success'
>
> However, I don't think that solves your problem.
>> Well, nothing gets printed. Could anyone tell me how to achieve that
>> simple type of matching?
>
> Re expressions are a little different from JScript. The match method 
> only
> matches equivalent strings. (Or it only does in this case.) Instead, 
> you
> want
> to use the search method. Oh, and by the way, if you're going to 
> compile the
> expression without assigning it to a variable, you might use the re 
> methods
> instead
> of the re pattern methods. IOW, use this code instead...
>
> import re
> mystring = 'helloworldmynameisbernardlebel'
> if re.search('bernard',mystring):
>     print 'success'
>
> The documentation for the re methods are hidden, IMHO. You can find 
> them
> by typing in 'search() (in module re)' in the index and that should 
> take you
> right to it.
> That page contains explanations for all of the re methods.
>
> Good luck,
> Jacob Schmidt
>
>
>
> ------------------------------
>
> Message: 4
> Date: Fri, 26 Nov 2004 17:22:14 -0700
> From: "Gooch, John" <John.Gooch at echostar.com>
> Subject: RE: [Tutor] String matching
> To: "'tutor at python.org'" <tutor at python.org>
> Message-ID:
> 	<15A1FDA26DAD524DA7A7AF77313EBA8F07BC0166 at riv-excha5.echostar.com>
> Content-Type: text/plain
>
> I am trying to extract data found in an MS Excel workbook using regular
> expressions. For some reason, it plain refuses to recognize the "-" 
> unicode
> character. Here is what happens when I execute:
>     print "Resolving name for "+tname+" type=",type(tname)
>     rePName = re.compile( u"(-)", re.UNICODE  )
>     m = rePName.match( tname )
>     print "Resolved to groups"+unicode(m.groups())
>
>
>
>
> Resolving name for 1.0 Windows - AB - 11/23/04 type= <type 'unicode'>
> Resolved to groups(u'1.0 Windows \u2013 HD - 11/23/04',)
>
> Notice I told it to match on the "-" character, which shows up in the 
> print
> command. But when I tell it to match on the character, it doesn't 
> match. U
> have tried the escape code "\u2013", but that does not match at all.
>
> Any ideas?
>
> John A. Gooch
> Systems Administrator
> IT - Tools
> EchoStar Satellite L.L.C.
> 9601 S. Meridian Blvd.
> Englewood, CO  80112
> Desk: 720-514-5708
>
>
> -----Original Message-----
> From: Jacob S. [mailto:keridee at jayco.net]
> Sent: Friday, November 26, 2004 10:57 AM
> To: Bernard Lebel
> Cc: tutor at python.org
> Subject: Re: [Tutor] String matching
>
>
> Hi Bernard!
>
>> Hello,
>>
>> I'm a little bit confused about the match/search methods of the string
>> module for regular expressions. I have looked the regular expression
>> doc and I can't that one simple answer.
>>
>> So please excuse the basiqueness of my question, as I am used with the
>> .match method of JScript and it kind of matches anything....
>>
>> Let say I have this string:
>>
>>>>> import re
>>>>> mystring = 'helloworldmynameisbernardlebel'
>>
>> Now I wish to attempt a match with 'bernard'.
>>
>>>>> if not re.compile( 'bernard' ).match( mystring ) == None: ...
>> print 'success'
>
> First, you are printinting redundant code here. You are using double
> negatives. You first check to see if 
> re.compile('bernard').match(mystring)
> registers false, if it is false the expression registers true. Then you
> check to see if that expression registers false. So really the 
> equivalent
> expression is
>
> if re.compile('bernard').match(mystring):
>     print 'success'
>
> However, I don't think that solves your problem.
>> Well, nothing gets printed. Could anyone tell me how to achieve that
>> simple type of matching?
>
> Re expressions are a little different from JScript. The match method 
> only
> matches equivalent strings. (Or it only does in this case.) Instead, 
> you
> want to use the search method. Oh, and by the way, if you're going to
> compile the expression without assigning it to a variable, you might 
> use the
> re methods instead of the re pattern methods. IOW, use this code 
> instead...
>
> import re
> mystring = 'helloworldmynameisbernardlebel'
> if re.search('bernard',mystring):
>     print 'success'
>
> The documentation for the re methods are hidden, IMHO. You can find 
> them by
> typing in 'search() (in module re)' in the index and that should take 
> you
> right to it. That page contains explanations for all of the re methods.
>
> Good luck,
> Jacob Schmidt
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> Message: 5
> Date: Sat, 27 Nov 2004 00:58:37 -0000
> From: "Alan Gauld" <alan.gauld at freenet.co.uk>
> Subject: Re: [Tutor] Change to Python 2.4?
> To: "Jacob S." <keridee at jayco.net>, <tutor at python.org>
> Message-ID: <009901c4d41c$3b531550$1abd8651 at xp>
> Content-Type: text/plain;	charset="iso-8859-1"
>
>>     How hard would it be to change to python 2.4?
>
> Probably not very hard but, why would you want to?
> Do you have a need?
>
> At work I am still using Python 2.1, and at home I
> still use 2.2 on my Mac. I only moved to 2.3 on my
> PC so that I could update my tutor, I am not knowingly
> using any 2.3 specific features.
>
> So unless you need something specific in 2.4 there
> should be no reason to ruish to it, wait till a
> safe point in your project - like after you get a
> stable working release - and then upgrade at your
> leasure...
>
>> new things in python 2.4?
>
> THere is usually a list available on the web site.
>
>> I have seen enough on this list to know that it
>> would be advantageous for me to download it.
>
> If you have a specifc advantage that makes the
> advantage worth the risk then go ahead. Python
> release changes are usually pretty easy and
> backwardly compatible.
>
>> scripts written for 2.3 work for 2.4?
>
> Occasionally something might break but in most
> cases(99%?) I'd expect the 2.3 stuff to just work.
>
> Alan G.
>
>
> ------------------------------
>
> Message: 6
> Date: Sat, 27 Nov 2004 01:17:53 -0000
> From: "Alan Gauld" <alan.gauld at freenet.co.uk>
> Subject: Re: [Tutor] Help with very basic question
> To: <revanna at mn.rr.com>,	"Harov Satmandirvich"
> 	<elrood_corrino_ii at yahoo.com>
> Cc: tutor at python.org
> Message-ID: <00a201c4d41e$ec4a3490$1abd8651 at xp>
> Content-Type: text/plain;	charset="iso-8859-1"
>
>
>> Harov Satmandirvich wrote:
>>> Hello.  Before I continue with a tutorial I would like
>>> to know something very basic:  Is there any other way
>>> to advance a line in Python than hitting
>>> "tabtabtabtab"..etc?   When I hit"enter?" it enters
>>> the line as if it was a complete bit of program.
>
> You can use a line continuatoion character (\) if you just want
> to break a line while in the interpreter.
>
> But if you want to type multi line programs without the
> interpreter executing it as you go follow Annas advice
> and use a text file to store the code.
>
> HTH
>
> Alan G
> Author of the Learn to Program web tutor
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> ------------------------------
>
> Message: 7
> Date: Fri, 26 Nov 2004 21:41:06 -0500
> From: Bill Burns <billburns at pennswoods.net>
> Subject: Re: [Tutor] Database questions
> To: tutor at python.org
> Message-ID: <200411262141.06192.billburns at pennswoods.net>
> Content-Type: text/plain;  charset="iso-8859-1"
>
> On Tuesday 23 November 2004 7:56 pm, Jay Mutter wrote:
>> Good evening;
>> I am using OS X 10.3.6 on an ibook where I have python 2.3.3 and
>> wxPython 2.5.3.1 installed with mxDateTime, Postgresql and psycopg.
>>
>> What i would like to know ( remember I have not really started using
>> python or any of the others) is what would you suggest as a GUI
>> designer to work with the above for someone who wants to develop a GUI
>> client interface for a RDBMS system.  I have looked at wxGlade,
>> Pythoncard, wxDesigner, and Boa constructor and am currently clueless.
>> If I wanted to hone my skills by creating a GUI checkbook
>> register/balancing program would I be best off to simply use the DB
>> modules built into Python.
>> Remember I am definitely a newbie.
>>
>
> Warning, the following doesn't meet all of your criteria, but if that 
> doesn't
> bother you, keep reading :-)
>
> Have you looked at Qt Designer + PyQt? This solution is not "wx" based
> (which I think is the only criteria it doesn't meet) but it should 
> provide
> everything else you want, i.e., OS X, works with databases and easy to
> use.
>
> I don't use OS X but I do use these programs (on Linux) and they are 
> very
> newbie friendly. I'm also a fellow n00b :-) and believe me, with Qt, 
> it's very
> simple and fast to make a nice GUI.
>
> Using Qt Designer, you can visually design a GUI without "hand coding" 
> a
> thing.  You literally just drop widgets, which are all accessible on 
> the
> left-hand side of Designer, right on to your forms. After you've 
> created the
> UI, you use a tool called pyuic (python user interface compiler) to 
> compile it
> to python code. You can either make this code directly executable or 
> import
> it into your own module.
>
> If you have access to a Linux box (with a modern distro) try typing 
> "designer"
> (without the quotes) at a command prompt. Maybe you can at least look 
> at the
> GUI builder and get a feel for it.
>
> You'll have to look at the licensing or distribution restrictions if 
> you want
> to distribute this app on Windows. I really don't know all of the 
> restrictions
> but I think if you're developing for just OS X or Linux you should 
> have no
> concerns. There are definitely issues when it comes to using Qt and 
> PyQt
> on the Windows platform. Look in to this, it's probably the single 
> biggest
> reason why Designer & PyQt are not suggested more often. Even so,
> these are outstanding tools. The Qt docs are full of information and 
> even-
> though they apply to C++, it's not hard to understand them and 
> translate
> the info into Python.
>
> Here's some links you might want to check out:
>
> Info & download link for the gpl'ed version of QT for Mac:
> http://www.trolltech.com/download/qt/mac.html
>
> Subscribe to and/or search the PyKDE mailing list (this list is for 
> both PyKDE
> & PyQt):
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
>
> Main web site for PyQt:
> http://www.riverbankcomputing.co.uk/pyqt/index.php
>
> An excellent site for info about PyQt programming:
> http://www.opendocspublishing.com/pyqt/index.lxp
>
> eric3 - A Python IDE
> http://www.die-offenbachs.de/detlev/eric3.html
>
> Black Adder - a commercial IDE:
> http://www.thekompany.com/
>
> HTH
>
> Bill
>
>
>
>
>
>
>
>
>
> ------------------------------
>
> Message: 8
> Date: Sat, 27 Nov 2004 16:53:47 +1300
> From: Liam Clarke <cyresse at gmail.com>
> Subject: Re: [Tutor] time comparison question
> To: Brian van den Broek <bvande at po-box.mcgill.ca>
> Cc: Python Tutor <tutor at python.org>
> Message-ID: <f2ff2d041126195368e7c0d3 at mail.gmail.com>
> Content-Type: text/plain; charset=US-ASCII
>
> Eep, you're right Brian, mea culpa.
>
>
> On Fri, 26 Nov 2004 14:16:40 -0500, Brian van den Broek
> <bvande at po-box.mcgill.ca> wrote:
>> Anna Ravenscroft said unto the world upon 2004-11-26 08:19:
>>> Brian van den Broek wrote:
>>>
>>>> Hi all,
>>>>
>>>> I'm trying to build some Python 2.3.4 code which will determine if 
>>>> the
>>>> actual time when it is run is after the date and time specified in
>>>> some data. I want my data to be able to specify the target date/time
>>>> in a various levels of detail. I.e., I want 2004-11-28 13:25,
>>>> 2004-11-28, 11-28, 11-28 13:25 to all be accepted.
>>
>> Hi all,
>>
>> thanks to Anna, G. Rodrigues, and Liam for the replies. The code that
>> was posted using datetime didn't seem so scary after all :-)
>>
>> As evidence accrues, I think I am going to just have to gather myself
>> together and surmount the aversion to classes and other aspects of 
>> OOP.
>> At least in this case, code has shown it isn't too tricky.
>>
>> One minor quibble with something Liam posted. Of struct_time objects 
>> he
>> said:
>>
>>> The 9 value tuple has year to microsecond, and day of the week
>>> contained, so you can use it if you wish.
>>
>> For future googlers, my understanding is that the first 6 elements of 
>> a
>> struct_time tuple are the date and time from year down to the second
>> (microseconds playing no role), and the last three are weekday, day of
>> year, and DST flag.
>>
>> Anyway, having read the replies, it looks like my problem is solved.
>> Thanks folks!
>>
>>
>>
>> Best to all,
>>
>> Brian vdB
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
> -- 
> 'There is only one basic human right, and that is to do as you damn 
> well please.
> And with it comes the only basic human duty, to take the consequences.
>
>
> ------------------------------
>
> Message: 9
> Date: Fri, 26 Nov 2004 23:14:44 -0500
> From: Bill Burns <billburns at pennswoods.net>
> Subject: Re: [Tutor] Database questions
> To: tutor at python.org
> Message-ID: <200411262314.44800.billburns at pennswoods.net>
> Content-Type: text/plain;  charset="iso-8859-1"
>
> As a follow-up to my previous post:
>
> I just found this on the PyKDE mailing list. A web site that provides 
> a binary
> installer for Qt / PyQt for OS X. Maybe this will make it easier for 
> you to
> try out?
>
> Here's the link:
> http://www.wordtech-software.com/python.html
>
> Bill
>
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 9, Issue 82
> ************************************
>



More information about the Tutor mailing list