Wednesday, December 16, 2009

comp.lang.python - 25 new messages in 14 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* i re-write it - 4 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/03d0cd34de668ab2?hl=en
* another problem.. - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/4bebf7c7325a04fa?hl=en
* I have a cross platform os.startfile but I need to asociate files with xdg-
open in linux how do I do that?? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/02942965b56a9f3f?hl=en
* Python Imaging Library status - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/cb928686bac3c48e?hl=en
* Subclassing RegexObject - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6fb8b8b5157145f1?hl=en
* basic grammer error.. - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/4ff5449f3576a3aa?hl=en
* Wrapping paper, anyone ? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/838f8a30ff56b007?hl=en
* regex help - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/4bbda0d73ff54a44?hl=en
* http://rob-zombie143.blogspot.com/ then here the site visit now http://
health-tips57.blogspot.com/ http://al-service.blogspot.com/ this is mobile
software and ringtones and much more tips usage tips now visit it http://
mobile-phoneusage.blogs - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/8ccd14c72a297e3b?hl=en
* Raw string substitution problem - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/61fdda4299b6a7b4?hl=en
* Python tricks with applescript in OS-X - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/3facb17e11e4e2cb?hl=en
* Apple Mac OS X 10.6 support & compatability with Python 3 ? - 1 messages, 1
author
http://groups.google.com/group/comp.lang.python/t/b49628afaf1ae4dc?hl=en
* iterators and views of lists - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/22d674ee0510cd97?hl=en
* python and command shell on Windows - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/8cb69422bbd1a52d?hl=en

==============================================================================
TOPIC: i re-write it
http://groups.google.com/group/comp.lang.python/t/03d0cd34de668ab2?hl=en
==============================================================================

== 1 of 4 ==
Date: Wed, Dec 16 2009 7:50 am
From: codefly


On Dec 17, 12:43 am, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
> codefly wrote:
> > error message is here..
> > when i type import code2
>
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> >   File "code2.py", line 11
> >     ~
> >                        ^
> > SyntaxError: invalid syntax
>
> > and source code is here
>
> No, it isn't. The above error says "line 11", but the code you show doesn't
> have 11 lines.
>
> From the above error, it looks as if you have a stray "tilde"-character on
> the last or so line in code.py. Remove it.
>
> Diez

now.. another problem..

when i type me = code2()

the error is here..
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable


== 2 of 4 ==
Date: Wed, Dec 16 2009 8:33 am
From: "Diez B. Roggisch"


codefly wrote:

> On Dec 17, 12:43 am, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
>> codefly wrote:
>> > error message is here..
>> > when i type import code2
>>
>> > Traceback (most recent call last):
>> > File "<stdin>", line 1, in <module>
>> > File "code2.py", line 11
>> > ~
>> > ^
>> > SyntaxError: invalid syntax
>>
>> > and source code is here
>>
>> No, it isn't. The above error says "line 11", but the code you show
>> doesn't have 11 lines.
>>
>> From the above error, it looks as if you have a stray "tilde"-character
>> on the last or so line in code.py. Remove it.
>>
>> Diez
>
> now.. another problem..
>
> when i type me = code2()
>
> the error is here..
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'module' object is not callable

Not surprisingly, because you try to instantiate a module. Which isn't
possible.

What you most probably want is

me = code2.codefly()

May I suggest you move your questions here:

http://mail.python.org/mailman/listinfo/tutor

It seems that you have some very basic misconceptions about python, so that
might be a forum more geared towards your needs.

Diez


== 3 of 4 ==
Date: Wed, Dec 16 2009 8:50 am
From: Bruno Desthuilliers


codefly a écrit :
> now.. another problem..
>
> when i type me = code2()

where ? and what is 'code2' in this context ? Sorry, my crystal ball is
out for repair...

> the error is here..
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'module' object is not callable
>

Ok, so it's in the python shell, you imported your module named 'code2',
and tried to call it.

Well... the error message say it all: module objects are not callable
(IOW : they are not functions). If I may ask : what's your background in
programming ?

== 4 of 4 ==
Date: Wed, Dec 16 2009 9:05 am
From: Dave Angel


codefly wrote:
> On Dec 17, 12:43 am, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
>
>> codefly wrote:
>>
>>> error message is here..
>>> when i type import code2
>>>
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in <module>
>>> File "code2.py", line 11
>>> ~
>>> ^
>>> SyntaxError: invalid syntax
>>>
>>> and source code is here
>>>
>> No, it isn't. The above error says "line 11", but the code you show doesn't
>> have 11 lines.
>>
>> From the above error, it looks as if you have a stray "tilde"-character on
>> the last or so line in code.py. Remove it.
>>
>> Diez
>>
>
> now.. another problem..
>
> when i type me = code2()
>
> the error is here..
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'module' object is not callable
>
>
>

Your code was/is in code2.py
-----------------

class codefly:
def WaitFreecatz(self, hours):
hours = self.hours
i =1
while i < hours:
print ' i wait for %s hours' %(i)
i = i+1
if i ==hours:
print 'he never comes'

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

The message is pretty clear. Why are you trying to call the module you
just imported? Perhaps you meant to instantiate the class that was
defined there. In that case, the syntax would be:
me = code2.codefly()

To save you some trouble on your next bug, let me point out that your
class does not initialize its instance variable self.hours That's
normally done in the __init__() method. Also, you can interactively see
the objects of an object with the dir() function. So try
dir(code2) dir(code2.codefly) and dir(me)

DaveA

==============================================================================
TOPIC: another problem..
http://groups.google.com/group/comp.lang.python/t/4bebf7c7325a04fa?hl=en
==============================================================================

== 1 of 3 ==
Date: Wed, Dec 16 2009 8:03 am
From: codefly


now.. another problem..
when i type me = code2()
the error is here..
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable


== 2 of 3 ==
Date: Wed, Dec 16 2009 8:58 am
From: Dave Angel


codefly wrote:
> now.. another problem..
> when i type me = code2()
> the error is here..
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'module' object is not callable
>
>
By creating a new thread for each new question, you're forcing yourself
to repeat the code and environment answers, which you did not. So let's
ignore this thread, and I'll respond on the previous one.

== 3 of 3 ==
Date: Wed, Dec 16 2009 9:30 am
From: Grant Edwards


On 2009-12-16, codefly <corona10@gmail.com> wrote:

> now.. another problem..

Sorry to be so blunt, but your main problem is that you don't
know how to ask questions. Fix that, and everything else will
become much easier:

1) Read this: http://catb.org/~esr/faqs/smart-questions.html

2) Read it again.

3) Read these sections one more time:

http://catb.org/~esr/faqs/smart-questions.html#beprecise
http://catb.org/~esr/faqs/smart-questions.html#code

--
Grant Edwards grante Yow! Is it NOUVELLE
at CUISINE when 3 olives are
visi.com struggling with a scallop
in a plate of SAUCE MORNAY?

==============================================================================
TOPIC: I have a cross platform os.startfile but I need to asociate files with
xdg-open in linux how do I do that??
http://groups.google.com/group/comp.lang.python/t/02942965b56a9f3f?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Dec 16 2009 8:03 am
From: "Eric_Dexter@msn.com"


#this should be a cross platform example of os.startfile ( startfile )
#for windows and linux. this is the first version and
#linux, mac, other os's commands for exceptions to the
#rule would be appreciated. at some point this will be
#in the dex tracker project.

import os
import subprocess

def startfile(filename)
try:
os.startfile(filename)
except:
subprocess.Popen(['xdg-open', filename])


_______________________________
http://dextracker.blogspot.com/


== 2 of 2 ==
Date: Wed, Dec 16 2009 8:36 am
From: Paul Boddie


On 16 Des, 17:03, "Eric_Dex...@msn.com" <Eric_Dex...@msn.com> wrote:
> #this should be a cross platform example of os.startfile ( startfile )
> #for windows and linux.  this is the first version and
> #linux, mac, other os's commands for exceptions to the
> #rule would be appreciated.  at some point this will be
> #in the dex tracker project.

You could look at the desktop package for something similar:

http://pypi.python.org/pypi/desktop

The desktop.open function supports a few extra workarounds, mostly
because it pre-dates xdg-open.

Paul

==============================================================================
TOPIC: Python Imaging Library status
http://groups.google.com/group/comp.lang.python/t/cb928686bac3c48e?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Dec 16 2009 8:07 am
From: "paulo.jpinto@gmail.com"


Hi guys,

is the famous PIL now a dead project?

Latest available download is from 2006 and I still don't see any signs
of having it updated for Python 2.6 or 3.x versions.

Thanks in Advance,
Paulo


==============================================================================
TOPIC: Subclassing RegexObject
http://groups.google.com/group/comp.lang.python/t/6fb8b8b5157145f1?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Dec 16 2009 8:10 am
From: Tobias Weber


In article <hgav3n$d2c$03$1@news.t-online.com>,
Peter Otten <__peter__@web.de> wrote:

> >>> class S(type(r)): pass

Thanks for showing the introspection way!

> type '_sre.SRE_Pattern' is not an acceptable base type

And again the Python documentation only writes about how things would be
if they were actually implemented in Python...

> Now who would want to do that? And why?

My class only really needs one attribute, which is a regular expression,
so I thought to save a line or two by subclassing that ;)

--
Tobias Weber

==============================================================================
TOPIC: basic grammer error..
http://groups.google.com/group/comp.lang.python/t/4ff5449f3576a3aa?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Dec 16 2009 8:10 am
From: Dave Angel


codefly wrote:
> class codefly:
>
> def WaitFreecatz(self, hours):
> hours = self.hours
> i = 1
> while i < hours:
> print 'i wait %s hours' %(i)
> i = i+1
> if i == hours:
> print '\nhe never comes'
>
>
> run error// what's wrong??
>
>
You can't get a runtime error there, because nothing instantiates the
class, nor calls its method. Once you add that code, you'll find an
uninitialized instance attribute, plus a couple of logic errors.

So, if you actually have a question, how about stating it completely?
Given a complete code sample, you run it (on what version of what
computer language, on what OS), and you get some error (show complete
traceback). Explain what you tried, to identify the error, and then
state what has you stumped.

And if you don't get a Python error, but get the wrong results, then
state what you expected, and what you got.

DaveA

== 2 of 2 ==
Date: Wed, Dec 16 2009 8:36 am
From: Bruno Desthuilliers


codefly a écrit :
> class codefly:
>
> def WaitFreecatz(self, hours):
> hours = self.hours
> i = 1
> while i < hours:
> print 'i wait %s hours' %(i)
> i = i+1
> if i == hours:
> print '\nhe never comes'
>
>
> run error// what's wrong??

wrt/ the code : bad capitalisation on the class name and method name,
access to an inexistant attribute, useless param 'hours' (not used),
failure to use the appropriate iteration construct.

wrt/ your post: failure to post both the full traceback and the minimal
required code to produce this traceback.


==============================================================================
TOPIC: Wrapping paper, anyone ?
http://groups.google.com/group/comp.lang.python/t/838f8a30ff56b007?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Dec 16 2009 8:35 am
From: "bartc"

"simon" <pianomaestro@gmail.com> wrote in message
news:a50b1c21-287b-498d-a8c3-51a3a2f94871@k9g2000vbl.googlegroups.com...
> #!/usr/bin/env python
>
> from math import *
>
> from random import *
>
> import cairo
> from cairo import Context

What's cairo?


== 2 of 2 ==
Date: Wed, Dec 16 2009 9:12 am
From: r0g


bartc wrote:
>
> "simon" <pianomaestro@gmail.com> wrote in message
> news:a50b1c21-287b-498d-a8c3-51a3a2f94871@k9g2000vbl.googlegroups.com...
>> #!/usr/bin/env python
>>
>> from math import *
>>
>> from random import *
>>
>> import cairo
>> from cairo import Context
>
> What's cairo?
>
>


A vector graphics library.

http://en.wikipedia.org/wiki/Cairo_(graphics)

Roger.

==============================================================================
TOPIC: regex help
http://groups.google.com/group/comp.lang.python/t/4bbda0d73ff54a44?hl=en
==============================================================================

== 1 of 3 ==
Date: Wed, Dec 16 2009 9:16 am
From: Gabriel Rossetti


Hello everyone,

I'm going nuts with some regex, could someone please show me what I'm
doing wrong?

I have an XMPP msg :

<message xmlns='jabber:client' to='node@host.com'>
<mynode xmlns='myprotocol:core' version='1.0' type='mytype'>
<parameters>
<param1>123</param1>
<param2>456</param2>
</parameters>
<payload type='plain'>...</payload>
</mynode>
<x xmlns='jabber:x:expire' seconds='15'/>
</message>

the <parameter> node may be absent or empty (<parameter/>), the <x> node
may be absent. I'd like to grab everything exept the <payload> nod and
create something new using regex, with the XMPP message example above
I'd get this :

<message xmlns='jabber:client' to='node@host.com'>
<mynode xmlns='myprotocol:core' version='1.0' type='mytype'>
<parameters>
<param1>123</param1>
<param2>456</param2>
</parameters>
</mynode>
<x xmlns='jabber:x:expire' seconds='15'/>
</message>

for some reason my regex doesn't work correctly :

r"(<message .*?>).*?(<mynode
.*?>).*?(?:(<parameters>.*?</parameters>)|<parameters/>)?.*?(<x .*/>)?"

I group the opening <message> node, the opening <mynode> node and if the
<parameters> node is present and not empty I group it and if the <x>
node is present I group it. For some reason this doesn't work correctly :

>>> import re
>>> s1 = "<message xmlns='jabber:client' to='node@host.com'><mynode
xmlns='myprotocol:core' version='1.0'
type='mytype'><parameters><param1>123</param1><param2>456</param2></parameters><payload
type='plain'>...</payload></mynode><x xmlns='jabber:x:expire'
seconds='15'/></message>"
>>> s2 = "<message xmlns='jabber:client' to='node@host.com'><mynode
xmlns='myprotocol:core' version='1.0'
type='mytype'><parameters/><payload
type='plain'>...</payload></mynode><x xmlns='jabber:x:expire'
seconds='15'/></message>"
>>> s3 = "<message xmlns='jabber:client' to='node@host.com'><mynode
xmlns='myprotocol:core' version='1.0' type='mytype'><payload
type='plain'>...</payload></mynode><x xmlns='jabber:x:expire'
seconds='15'/></message>"
>>> s4 = "<message xmlns='jabber:client' to='node@host.com'><mynode
xmlns='myprotocol:core' version='1.0'
type='mytype'><parameters><param1>123</param1><param2>456</param2></parameters><payload
type='plain'>...</payload></mynode></message>"
>>> s5 = "<message xmlns='jabber:client' to='node@host.com'><mynode
xmlns='myprotocol:core' version='1.0'
type='mytype'><parameters/><payload
type='plain'>...</payload></mynode></message>"
>>> s6 = "<message xmlns='jabber:client' to='node@host.com'><mynode
xmlns='myprotocol:core' version='1.0' type='mytype'><payload
type='plain'>...</payload></mynode></message>"
>>> exp = r"(<message .*?>).*?(<mynode
.*?>).*?(?:(<parameters>.*?</parameters>)|<parameters/>)?.*?(<x .*/>)?"
>>>
>>> re.match(exp, s1).groups()
("<message xmlns='jabber:client' to='node@host.com'>", "<mynode
xmlns='myprotocol:core' version='1.0' type='mytype'>",
'<parameters><param1>123</param1><param2>456</param2></parameters>', None)
>>>
>>> re.match(exp, s2).groups()
("<message xmlns='jabber:client' to='node@host.com'>", "<mynode
xmlns='myprotocol:core' version='1.0' type='mytype'>", None, None)
>>>
>>> re.match(exp, s3).groups()
("<message xmlns='jabber:client' to='node@host.com'>", "<mynode
xmlns='myprotocol:core' version='1.0' type='mytype'>", None, None)
>>>
>>> re.match(exp, s4).groups()
("<message xmlns='jabber:client' to='node@host.com'>", "<mynode
xmlns='myprotocol:core' version='1.0' type='mytype'>",
'<parameters><param1>123</param1><param2>456</param2></parameters>', None)
>>>
>>> re.match(exp, s5).groups()
("<message xmlns='jabber:client' to='node@host.com'>", "<mynode
xmlns='myprotocol:core' version='1.0' type='mytype'>", None, None)
>>>
>>> re.match(exp, s6).groups()
("<message xmlns='jabber:client' to='node@host.com'>", "<mynode
xmlns='myprotocol:core' version='1.0' type='mytype'>", None, None)
>>>


Does someone know what is wrong with my expression? Thank you, Gabriel


== 2 of 3 ==
Date: Wed, Dec 16 2009 9:22 am
From: r0g


Gabriel Rossetti wrote:
> Hello everyone,
>
> I'm going nuts with some regex, could someone please show me what I'm
> doing wrong?
>
> I have an XMPP msg :
>
<snip>
>
>
> Does someone know what is wrong with my expression? Thank you, Gabriel


Gabriel, trying to debug a long regex in situ can be a nightmare however
the following technique always works for me...

Use the interactive interpreter and see if half the regex works, if it
does your problem is in the second half, if not it's in the first so try
the first half of that and so on an so forth. You'll find the point at
which it goes wrong in a snip.

Non-trivial regexes are always best built up and tested a bit at a time,
the interactive interpreter is great for this.

Roger.


== 3 of 3 ==
Date: Wed, Dec 16 2009 9:38 am
From: "Intchanter / Daniel Fackrell"


On Dec 16, 10:22 am, r0g <aioe....@technicalbloke.com> wrote:
> Gabriel Rossetti wrote:
> > Hello everyone,
>
> > I'm going nuts with some regex, could someone please show me what I'm
> > doing wrong?
>
> > I have an XMPP msg :
>
> <snip>
>
> > Does someone know what is wrong with my expression? Thank you, Gabriel
>
> Gabriel, trying to debug a long regex in situ can be a nightmare however
> the following technique always works for me...
>
> Use the interactive interpreter and see if half the regex works, if it
> does your problem is in the second half, if not it's in the first so try
> the first half of that and so on an so forth. You'll find the point at
> which it goes wrong in a snip.
>
> Non-trivial regexes are always best built up and tested a bit at a time,
> the interactive interpreter is great for this.
>
> Roger.

I'll just add that the "now you have two problems" quip applies here,
especially when there are very good XML parsing libraries for Python
that will keep you from having to reinvent the wheel for every little
change.

See sections 20.5 through 20.13 of the Python Documentation for
several built-in options, and I'm sure there are many community
projects that may fit the bill if none of those happen to.

Personally, I consider regular expressions of any substantial length
and complexity to be bad practice as it inhibits readability and
maintainability. They are also decidedly non-Zen on at least
"Readability counts" and "Sparse is better than dense".

Intchanter
Daniel Fackrell

P.S. I'm not sure how any of these libraries are implemented yet, but
I'd hope they're using a finite state machine tailored to the parsing
task rather than using regexes, but even if they do the latter, having
that abstracted out in a mature library with a clean interface is
still a huge win.

==============================================================================
TOPIC: http://rob-zombie143.blogspot.com/ then here the site visit now http://
health-tips57.blogspot.com/ http://al-service.blogspot.com/ this is mobile
software and ringtones and much more tips usage tips now visit it http://
mobile-phoneusage.blogs
http://groups.google.com/group/comp.lang.python/t/8ccd14c72a297e3b?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Dec 16 2009 9:17 am
From: bakiyaraj p


http://rob-zombie143.blogspot.com/ then here the site visit now
http://health-tips57.blogspot.com/
http://al-service.blogspot.com/
this is mobile software and ringtones and much more tips usage tips
now visit it http://mobile-phoneusage.blogspot.com
http://vijay-thirisha-friendship-cut.blogspot.com/
http://computer-softwares001.blogspot.com/
http://hat-trick-cricket-more.blogspot.com/
http://cancer-information107.blogspot.com/
http://civilengineer-field.blogspot.com/
http://rob-zombie143.blogspot.com/ http://types-ofcancer.blogspot.com/
http://anymobile-software.blogspot.com/ http://unemployment-123.blogspot.com/
http://baki-vettaikaranintrosong.blogspot.com/ http://baki-desktop-computer.blogspot.com/
http://hp-desktop-pc-mother-bo.blogspot.com/ http://white-blood-cell.blogspot.com/

==============================================================================
TOPIC: Raw string substitution problem
http://groups.google.com/group/comp.lang.python/t/61fdda4299b6a7b4?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Dec 16 2009 9:19 am
From: Ed Keith


--- On Wed, 12/16/09, Gabriel Genellina <gagsl-py2@yahoo.com.ar> wrote:

> From: Gabriel Genellina <gagsl-py2@yahoo.com.ar>
> Subject: Re: Raw string substitution problem
> To: python-list@python.org
> Date: Wednesday, December 16, 2009, 9:35 AM
> En Wed, 16 Dec 2009 11:09:32 -0300,
> Ed Keith <e_d_k@yahoo.com>
> escribió:
>
> > I am having a problem when substituting a raw string.
> When I do the following:
> >
> > re.sub('abc', r'a\nb\nc', '123abcdefg')
> >
> > I get
> >
> > """
> > 123a
> > b
> > cdefg
> > """
> >
> > what I want is
> >
> > r'123a\nb\ncdefg'
>
> From http://docs.python.org/library/re.html#re.sub
>
>     re.sub(pattern, repl, string[, count])
>
>     ...repl can be a string or a function;
> if
>     it is a string, any backslash escapes
> in
>     it are processed. That is, \n is
> converted
>     to a single newline character, \r is
>     converted to a linefeed, and so forth.
>
> So you'll have to double your backslashes:
>
> py> re.sub('abc', r'a\\nb\\nc', '123abcdefg')
> '123a\\nb\\ncdefg'
>
> --Gabriel Genellina
>
> --http://mail.python.org/mailman/listinfo/python-list
>

That is going to be a nontrivial exercise. I have control over the pattern, but the texts to be substituted and substituted into will be read from user supplied files. I need to reproduce the exact text the is read from the file.

Maybe what I should do is use re to break the string into two pieces, the part before the pattern to be replaces and the part after it, then splice the replacement text in between them. Seems like doing it the hard way, but it should work.

Thanks,

-EdK


== 2 of 2 ==
Date: Wed, Dec 16 2009 9:51 am
From: Peter Otten <__peter__@web.de>


Ed Keith wrote:

> --- On Wed, 12/16/09, Gabriel Genellina <gagsl-py2@yahoo.com.ar> wrote:
>
>> From: Gabriel Genellina <gagsl-py2@yahoo.com.ar>
>> Subject: Re: Raw string substitution problem
>> To: python-list@python.org
>> Date: Wednesday, December 16, 2009, 9:35 AM
>> En Wed, 16 Dec 2009 11:09:32 -0300,
>> Ed Keith <e_d_k@yahoo.com>
>> escribió:
>>
>> > I am having a problem when substituting a raw string.
>> When I do the following:
>> >
>> > re.sub('abc', r'a\nb\nc', '123abcdefg')
>> >
>> > I get
>> >
>> > """
>> > 123a
>> > b
>> > cdefg
>> > """
>> >
>> > what I want is
>> >
>> > r'123a\nb\ncdefg'
>>
>> From http://docs.python.org/library/re.html#re.sub
>>
>> re.sub(pattern, repl, string[, count])
>>
>> ...repl can be a string or a function;
>> if
>> it is a string, any backslash escapes
>> in
>> it are processed. That is, \n is
>> converted
>> to a single newline character, \r is
>> converted to a linefeed, and so forth.
>>
>> So you'll have to double your backslashes:
>>
>> py> re.sub('abc', r'a\\nb\\nc', '123abcdefg')
>> '123a\\nb\\ncdefg'
>>
>> --Gabriel Genellina
>>
>> --http://mail.python.org/mailman/listinfo/python-list
>>
>
> That is going to be a nontrivial exercise. I have control over the
> pattern, but the texts to be substituted and substituted into will be read
> from user supplied files. I need to reproduce the exact text the is read
> from the file.

There is a helper function re.escape() that you can use to sanitize the
substitution:

>>> print re.sub('abc', re.escape(r'a\nb\nc'), '123abcdefg')
123a\nb\ncdefg

Peter

==============================================================================
TOPIC: Python tricks with applescript in OS-X
http://groups.google.com/group/comp.lang.python/t/3facb17e11e4e2cb?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Dec 16 2009 9:28 am
From: Juanre


Thanks for the pointers to appscript, and for the comments on the
page. I have changed the examples at http://juanreyero.com/article/python/os-x-python.html
to reflect them.

Cheers,

Juan
--
http://juanreyero.com

==============================================================================
TOPIC: Apple Mac OS X 10.6 support & compatability with Python 3 ?
http://groups.google.com/group/comp.lang.python/t/b49628afaf1ae4dc?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Dec 16 2009 9:41 am
From: pdlemper@earthlink.net


I've been given a MAC AIR laptop with OS X 10.6 "Snow Leopard".
On my desktop I dual boot with XP - Ubuntu and have Python on both.
Unfortunately all my Python programs are written on Windows XP and
I heavily rely on WConio for console I/O.
Called Apple tech support. The technician had never heard of Python,
ascertained the MAC AIR does not come preloaded with Python and
did not know if Python 3 would run under OS X 10.6. This was "beyond"
their expertise.
Does anyone have experience with OS X ? Could I use WConio in a
Windows emulator ? I have no experience with MACs and am debating
whether to send this back before opening.
Thanks. Dave WB3DWE

==============================================================================
TOPIC: iterators and views of lists
http://groups.google.com/group/comp.lang.python/t/22d674ee0510cd97?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Dec 16 2009 9:44 am
From: Francesco Bochicchio


On Dec 16, 1:58 pm, Anh Hai Trinh <anh.hai.tr...@gmail.com> wrote:

>
> You might be interested in this library <http://pypi.python.org/pypi/
> stream>.
>
> You can easily create arbitrary "slice", for example
>
>   i = mylist >> takei(primes())
>
> will return an iterator over the items of mylist with a prime number
> index, given that primes() return an iterator over prime numbers.
>


Nice :-)

I was starting to experiment data flow programming with python myself,
although I'm just playing with it..
I find the idea of data flow programming fascinatin, and wonder if it
can be considered a general-purpose program paradigm.

Ciao
-----
FB

==============================================================================
TOPIC: python and command shell on Windows
http://groups.google.com/group/comp.lang.python/t/8cb69422bbd1a52d?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Dec 16 2009 9:58 am
From: josu


Hi

I am trying to execute a windows command based on a shell by mean of
python. I have proven subprocess

test=subprocess.Popen
(['shell_command'],shell=True,stdin=PIPE,stdout=PIPE)

Initally, all seems ok, but, after seconds the python shell is frozen.

Does someone know alternative ways valid for windows OS?

Thanks in advance

josu


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate