[Tutor] Help

krayzie_jm at yahoo.com krayzie_jm at yahoo.com
Sun Apr 12 02:53:19 CEST 2009


Sent from my BlackBerry® device from Digicel

-----Original Message-----
From: tutor-request at python.org

Date: Sun, 12 Apr 2009 02:51:01 
To: <tutor at python.org>
Subject: Tutor Digest, Vol 62, Issue 42


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: Yet another Python book (Dotan Cohen)
   2. Re: Yet another Python book (python at bdurham.com)
   3. Re: Yet another Python book (vishwajeet singh)
   4. Re: Problem with converting Python to EXE using py2exe
      (Dave Angel)
   5. PHP as seen by a Python lover (OkaMthembo)
   6. Optional groups in RE's (Moos Heintzen)
   7. Re: Optional groups in RE's (Mark Tolonen)


----------------------------------------------------------------------

Message: 1
Date: Sat, 11 Apr 2009 18:57:10 +0300
From: Dotan Cohen <dotancohen at gmail.com>
Subject: Re: [Tutor] Yet another Python book
To: tutor at python.org
Message-ID:
	<880dece00904110857sba47b01j4f449e1697209cd1 at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

While the content looks to provide a reasonable learning curve, there
is no mention of the Python  version used. One of the first examples
shows the interpreter for Python 2.6. I really think that a book
coming out today should cover Python 3.0, and from the look of things
that can be done with very little effort.

Other than that, I'd really like to see a chapter on PyQt. PyGTK is
nice from what I understand (I've actually never used it) but PyQt
with Qt 4 really is the cutting edge, and is very cross-platform
compatible.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il


------------------------------

Message: 2
Date: Sat, 11 Apr 2009 12:01:00 -0400
From: python at bdurham.com
Subject: Re: [Tutor] Yet another Python book
To: tutor at python.org
Message-ID: <1239465660.22178.1310049665 at webmail.messagingengine.com>
Content-Type: text/plain; charset="ISO-8859-1"

Dave,

Great stuff!!! Thanks for sharing your hard work with the community!

Malcolm


------------------------------

Message: 3
Date: Sat, 11 Apr 2009 21:32:50 +0530
From: vishwajeet singh <dextrous85 at gmail.com>
Subject: Re: [Tutor] Yet another Python book
To: python at bdurham.com
Cc: tutor at python.org
Message-ID:
	<5487b3060904110902j70b25e09o4646fe4beeba0bc0 at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

awesome; I really like the Jython part :)

Thanks for your efforts.

On Sat, Apr 11, 2009 at 9:31 PM, <python at bdurham.com> wrote:

> Dave,
>
> Great stuff!!! Thanks for sharing your hard work with the community!
>
> Malcolm
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090411/757d2433/attachment-0001.htm>

------------------------------

Message: 4
Date: Sat, 11 Apr 2009 15:07:38 -0400
From: Dave Angel <davea at ieee.org>
Subject: Re: [Tutor] Problem with converting Python to EXE using
	py2exe
To: tutor at python.org
Message-ID: <49E0EA7A.7020104 at ieee.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed


Alan Gould wrote:
> <snip...>
> Good idea, I forgot that in Python you can find the full path that way.
> Too used to working in C/C++ where the file macro only gives the
> filename...
>   
In C++, you wouldn't want the full path to the source file, but the full 
path to the .EXE file.  That can be gotten in Windows, by using 
GetModuleHandle(0), and some other function on that handle.  Sorry I 
don't remember the name of the second function, but I haven't done any 
C++ work in a few years.  It might have a name like 
GetModuleXXXXX(handle).  Anyway, that's the technique I used in that 
environment.  To me, if it's possible to avoid an install entirely, I'm 
in favor.

Two other tricks I used in the C++/Win world; 

1) Let the name of the exe, as well as the location, be significant.  If 
you put most of the code in dll's, it doesn't cost much to have multiple 
copies of the .EXE, each one with a different behavior.  That's 
especially useful when you make file associations or SendTo associations 
to those various executables.  Windows launches the program with only 
the filename as an argument, but I can have one more parameter hidden in 
the filename.

2) You can append arbitrary data to the EXE, and it won't affect normal 
running.  Windows only maps in the amount specified in the header.  But 
you can fetch readonly data from the end of the file, and use it any way 
you like.   To append, you can simply do    COPY /B  myprog.exe + 
extradata.bin

I wish Python.exe was designed this way.  We could package up small 
scripts by appending them to a renamed EXE,   The user could treat that 
as a self-contained executable, ready to run.  This wouldn't obviate the 
need for installing Python itself, but it could make integrating it into 
normal usage simpler.

See EXEMAKER for an implementation of #1, though it doesn't work with 
some imports, and has the problem that a console gets created even if 
you're running a GUI python script.  It's a good start, though.




------------------------------

Message: 5
Date: Sat, 11 Apr 2009 22:13:59 +0200
From: OkaMthembo <zebra05 at gmail.com>
Subject: [Tutor] PHP as seen by a Python lover
To: Python <tutor at python.org>
Message-ID:
	<c7c6f3bc0904111313p3982a0e4sd525e4fd5e4341dd at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi All,

I just tried setting up PHP on my machine,with Apache 2.2-something (Win.
XP).

I came back running.

It's a SCHLEP.

I love Python.

Happy Easter to you all - and to those that do not celebrate it, have a
great weekend!

-- 
Lloyd Dube
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090411/6d6b2ed2/attachment-0001.htm>

------------------------------

Message: 6
Date: Sat, 11 Apr 2009 15:46:18 -0700
From: Moos Heintzen <iwasroot at gmail.com>
Subject: [Tutor] Optional groups in RE's
To: "tutor at python.org" <tutor at python.org>
Message-ID:
	<7b13ba330904111546n21d90202i7572a75c55b02a23 at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hello Tutors!

I was trying to make some groups optional in a regular expression, but
I couldn't do it.

For example, I have the string:

>>> data = "<price>42</price> sdlfks d f<ship>60</ship> sdf sdf  <title>Title</title>"

and the pattern:
>>> pattern = "<price>(.*?)</price>.*?<ship>(.*?)</ship>.*?<title>(.*?)</title>"

This works when all the groups are present.

>>> re.search(pattern, data).groups()
('42', '60', 'Title')

However, I don't know how to make an re to deal with possibly missing groups.
For example, with:
>>> data = "<price>42</price> sdlfks d f<ship>60</ship> sdf sdf"

I tried
>>> pattern = "<price>(.*?)</price>.*?<ship>(.*?)</ship>.*?(?:<title>(.*?)</title>)?"
>>> re.search(pattern, data).groups()
('42', '60', None)

but it doesn't work when <title> _is_ present.

>>> data = "<price>42</price> sdlfks d f<ship>60</ship> sdf sdf  <title>Title</title>"
>>> re.search(pattern, data).groups()
('42', '60', None)

I tried something like (?:pattern)+ and (?:pattern)* but I couldn't
get what I wanted.
(.*?)? doesn't seem to be a valid re either.

I know (?:pattern) is a non-capturing group.
I just read that | has very low precedence, so I used parenthesis
liberally to "or" pattern and a null string.

>>> pattern = "<price>(.*?)</price>.*?<ship>(.*?)</ship>.*?(?:(?:<title>(.*?)</title>)|)"
>>> re.search(pattern, data).groups()
('42', '60', None)

(?:(?:pattern)|(?:.*)) didn't work either.

I want to be able to have some groups as optional, so when that group
isn't matched, it returns None. When it's match it should return what
is matched.

Is that possible with one re?

I could probably do it with more than one re (and did it) but with one
re the solution is much more elegant.
(i.e. I could have named groups, then pass the resultant dictionary to
a processing function)

I also tried matching optional groups before, and curious about the solution.

Moos


------------------------------

Message: 7
Date: Sat, 11 Apr 2009 17:50:44 -0700
From: "Mark Tolonen" <metolone+gmane at gmail.com>
Subject: Re: [Tutor] Optional groups in RE's
To: tutor at python.org
Message-ID: <grrdt0$5os$1 at ger.gmane.org>


"Moos Heintzen" <iwasroot at gmail.com> wrote in message 
news:7b13ba330904111546n21d90202i7572a75c55b02a23 at mail.gmail.com...
> Hello Tutors!
>
> I was trying to make some groups optional in a regular expression, but
> I couldn't do it.
>
> For example, I have the string:
>
>>>> data = "<price>42</price> sdlfks d f<ship>60</ship> sdf sdf 
>>>> <title>Title</title>"

[ re attempts stripped]

Your data looks like XML.  If it is actually well-formed XML, have you tried 
ElementTree?

PythonWin 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit 
(Intel)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for 
further copyright information.
>>> from xml.etree import ElementTree as ET
>>> data = "<object><price>42</price> sdlfks d f<ship>60</ship> sdf sdf 
>>> <title>Title</title></object>"
>>> t=ET.fromstring(data)
>>> t.tag
'object'
>>> for e in t.getchildren():
...  print e.tag,e.text
...
price 42
ship 60
title Title
>>>

-Mark 





------------------------------

_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


End of Tutor Digest, Vol 62, Issue 42
*************************************


More information about the Tutor mailing list