Re: Performance of Python 3

2009-03-02 Thread Stefan Behnel
Isaac Gouy wrote:
> On Mar 1, 11:24 am, Stefan Behnel wrote:
>> Isaac Gouy wrote:
>>> On Mar 1, 8:10 am, Stefan Behnel wrote:
 As long as that gives you improvements of
 100-1000 times almost for free, I wouldn't bother too much with changing
 the platform just because someone shows me benchmark results of some code
 that I absolutely don't need in my daily work.
>>> What examples do you have of 1000x improvement?
>> We hear that from time to time on the Cython mailing list. Here's a recent
>> example of a user who reported an 80 times speed-up before we helped in
>> getting the code straight, which brought another factor of 20.
>>
>> http://permalink.gmane.org/gmane.comp.python.cython.devel/4619
>>
>> Speed-ups in the order of several hundred times are not uncommon for
>> computing intensive tasks and large data sets when you move from Python to
>> Cython, as it generates very optimised C code.
>>
>> Stefan
> 
> "Now only the def line and the return line are using Python..." ;-)

So? I did see your smiley, but I hope you are not trying to make a point
here. If you look at the code (especially in this case, it might be more
C-ish in others), you will see that it's Python. It just gets translated to
very fast C code. Cython even has a "pure Python" mode where you can let
your code run in ordinary Python and have Cython compile it if you feel
like it. That gives you the best of both worlds: readable, easy to maintain
code, that you can compile to C speed when you need high performance.

Coming back to the original topic of this thread, when I look at the code
examples that are compared here, I wouldn't be surprised if Cython could
compile them to a faster executable straight away, without modification.
Just install Cython 0.11 (which is close to release) and add

import pyximport; pyximport.install(pyimport=True)

before importing the benchmarked module. If you want more performance than
what plain compilation gives you by itself, just add a few type
declarations. You can use Python decorators for that, if you prefer keeping
a standard Python program.

Stefan
--
http://mail.python.org/mailman/listinfo/python-list


Re: imaplib fetch message flags

2009-03-02 Thread Lawrence D'Oliveiro
In message , Gabriel 
Genellina wrote:

> RFC1730  defines IMAP4 and isn't
> hard to read.

This  may also be worth reading.

--
http://mail.python.org/mailman/listinfo/python-list


os module

2009-03-02 Thread M Kumar
Hi,

I am writing a server side program, clients can be any machine but the
server machine is Linux. In program I want to use the OS module based on the
client's operating system. But when I do "import os" m only able to get the
module with the property of Linux. ANy idea how to import the module with
the property of clients OS.

-- 
Regards,

Maneesh KB

Comat Technologies

Bangalore

Mob: 9740-192309



We work with the underprivileged and in rural India. If you are interested
to be a part of it, please mail or call me. I will be happy to share and
inform - http://www.comat.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread Chris Rebert
On Mon, Mar 2, 2009 at 12:26 AM, M Kumar  wrote:
>
> Hi,
>
> I am writing a server side program, clients can be any machine but the
> server machine is Linux. In program I want to use the OS module based on the
> client's operating system. But when I do "import os" m only able to get the
> module with the property of Linux. ANy idea how to import the module with
> the property of clients OS.

You want sys.platform; see http://docs.python.org/library/sys.html#sys.platform

Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: file locking...

2009-03-02 Thread Lawrence D'Oliveiro
In message , Nigel 
Rantor wrote:

> In other words, why would you rely on a scheme that limits some
> processes to certain parts of the data?

That could be part of the original requirements, it's not clear from the 
description so far.

--
http://mail.python.org/mailman/listinfo/python-list


RE: file locking...

2009-03-02 Thread Lawrence D'Oliveiro
In message , bruce 
wrote:

> using any kind of file locking process requires that i essentially have a
> gatekeeper, allowing a single process to enter, access the files at a
> time...

The gatekeeper doesn't need to do any more than ensure that any particular 
filename is only locked by a maximum of one process at a time.

Given that interprocess communication (and consequent context-switching) is 
going to be orders of magnitude faster than accessing disk files, there's no 
a-priori reason to assume that this need be a performance bottleneck.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread Hussein B
On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
> On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > Hey,
> > I'm retrieving records from MySQL database that contains non english
> > characters.
> > Then I create a String that contains HTML markup and column values
> > from the previous result set.
> > +
> > markup = u'''.'''
> > for row in rows:
> >     markup = markup + '' + row['id']
> > markup = markup + '
> > +
> > Then I'm sending the email according to this tip:
> >http://code.activestate.com/recipes/473810/
> > Well, the email contains ? characters for each non english ones.
> > Any ideas?
>
> There's so many places where this could go wrong and you haven't  
> narrowed down the problem.
>
> Are the characters stored in the database correctly?
Yes they are.

> Are they stored consistently (i.e. all using the same encoding, not  
> some using utf-8 and others using iso-8859-1)?
Yes.

> What are you getting out of the database? Is it being converted to  
> Unicode correctly, or at all?
I don't know, how to make sure of this point?

> Are you sure that the program you're using to view the email  
> understands the encoding?
Yes.

> Isolate those questions one at a time. Add some debugging breakpoints.  
> Ensure that you have what you think you have. You might not fix your  
> problem, but you will make it much smaller and more specific.
>
> Good luck
> Philip

--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread Hussein B
On Mar 1, 11:27 pm, "J. Clifford Dyer"  wrote:
> On Sun, 2009-03-01 at 09:51 -0500, Philip Semanchuk wrote:
> > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > Hey,
> > > I'm retrieving records from MySQL database that contains non english
> > > characters.
> > > Then I create a String that contains HTML markup and column values
> > > from the previous result set.
> > > +
> > > markup = u'''.'''
> > > for row in rows:
> > >     markup = markup + '' + row['id']
> > > markup = markup + '
> > > +
> > > Then I'm sending the email according to this tip:
> > >http://code.activestate.com/recipes/473810/
> > > Well, the email contains ? characters for each non english ones.
> > > Any ideas?
>
> > There's so many places where this could go wrong and you haven't  
> > narrowed down the problem.
>
> > Are the characters stored in the database correctly?
>
> > Are they stored consistently (i.e. all using the same encoding, not  
> > some using utf-8 and others using iso-8859-1)?
>
> > What are you getting out of the database? Is it being converted to  
> > Unicode correctly, or at all?
>
> > Are you sure that the program you're using to view the email  
> > understands the encoding?
>
> > Isolate those questions one at a time. Add some debugging breakpoints.  
> > Ensure that you have what you think you have. You might not fix your  
> > problem, but you will make it much smaller and more specific.
>
> > Good luck
> > Philip
>
> Let me add to that checklist:
>
> Are you sure the email you are creating has the encoding declared
> properly in the headers?
>
>
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Cheers,
> Cliff

My HTML markup contains only table tags (you know, table, tr and td)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Email Program

2009-03-02 Thread Paul McGuire
On Mar 2, 1:11 am, Paul Rubin  wrote:
> Paul McGuire  writes:
> > As to your question of whether Python can be used to write an e-mail
> > client, or to create a programming language, I assure you both are
> > possible.  But also, given your unfamiliarity with Python, both are
> > well beyond your skills for some time yet, and you are nowhere near
> > reaching any of Python's limits any time soon.  
>
> Mitch Kapor (of Lotus 1-2-3 fame) spent a lot of money hiring
> very sharp Python programmers to write an email client called
> Chandler, but from what I understand, progress so far has been
> disappointing, at least in part for performance reasons.

Yipes, have you read the book ("Dreaming in Code")?  Chandler's
problems were much more organizational than technical.  The staff was
loaded with Netscape/Microsoft/Apple alumni, well-respected, but also
well-heeled, perhaps a little too comfortable and complacent with
their IPO and stock option money, not hungry enough.  And Kapor's
leadership from the top was too easy-going, not enough urgency or
drive.  The project would tread water for months at a time, waiting
for some collective eureka to resolve philosophical design questions,
while the operational burn rate burned on.  Kapor was both majority
investor and CEO/COO, which would make it difficult for Kapor the
Manager to see core problems when Kapor the Investor could just
plaster over them with more money.  But when even the added cash ($5MM
initial + $2.5MM add-on) was burned through, the basic problems still
remained and ultimately, no product.  (A partial package has been
released - for $7.5MM one would hope so!)

When starting a project, you have three priority factors: time, money,
and scope.  You have to pick the top 2, and the third has to give.
Chandler did not have any time driver, fuzzy scope, and *lots* of
money, maybe too much.  If the money had been tighter, the deadlines
and scope would have had to get a lot crisper.

Python performance may be the reason why the delivered package is
sluggish, but it is far from being the root reason for the project's
lackluster results.

-- Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread M Kumar
Hi Chris,
Thanks for quick and kind reply, but the python program runs on the server,
sys.platform is linux only. What I want is I need to get a module, which
shud be exactly same as if I import os module on the client machine

On Mon, Mar 2, 2009 at 1:59 PM, Chris Rebert  wrote:

> On Mon, Mar 2, 2009 at 12:26 AM, M Kumar  wrote:
> >
> > Hi,
> >
> > I am writing a server side program, clients can be any machine but the
> > server machine is Linux. In program I want to use the OS module based on
> the
> > client's operating system. But when I do "import os" m only able to get
> the
> > module with the property of Linux. ANy idea how to import the module with
> > the property of clients OS.
>
> You want sys.platform; see
> http://docs.python.org/library/sys.html#sys.platform
>
> Cheers,
> Chris
>
> --
> Shameless self-promotion:
> http://blog.rebertia.com
>



-- 
Regards,

Maneesh KB

Comat Technologies

Bangalore

Mob: 9740-192309



We work with the underprivileged and in rural India. If you are interested
to be a part of it, please mail or call me. I will be happy to share and
inform - http://www.comat.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread Chris Rebert
> On Mon, Mar 2, 2009 at 1:59 PM, Chris Rebert  wrote:
>>
>> On Mon, Mar 2, 2009 at 12:26 AM, M Kumar  wrote:
>> >
>> > Hi,
>> >
>> > I am writing a server side program, clients can be any machine but the
>> > server machine is Linux. In program I want to use the OS module based on
>> > the
>> > client's operating system. But when I do "import os" m only able to get
>> > the
>> > module with the property of Linux. ANy idea how to import the module
>> > with
>> > the property of clients OS.
>>
>> You want sys.platform; see
>> http://docs.python.org/library/sys.html#sys.platform
On Mon, Mar 2, 2009 at 12:43 AM, M Kumar  wrote:
> Hi Chris,
> Thanks for quick and kind reply, but the python program runs on the server,
> sys.platform is linux only. What I want is I need to get a module, which
> shud be exactly same as if I import os module on the client machine

Um, you're not phrasing your request very clearly, so perhaps I'm not
understanding what you're looking for, but I can tell you that
sys.platform is certainly not Linux-only. If you'll read the docs I
pointed you to, you'll see a table:
System  platform value
Windows 'win32'


Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iterator class to allow self-restarting generator expressions?

2009-03-02 Thread Lie Ryan
Gabriel Genellina wrote:
> En Sun, 01 Mar 2009 15:51:07 -0200, Chris Rebert 
> escribió:
>> On Sun, Mar 1, 2009 at 8:54 AM, Gabriel Genellina
>>  wrote:
>>> En Sun, 01 Mar 2009 13:20:28 -0200, John O'Hagan
>>> 
>>> escribió:
>>>
 Inspired by some recent threads here about using classes to extend the
 behaviour of iterators, I'm trying to replace some some top-level
 functions
 aimed at doing such things with a class.
> 
>>> I'm afraid you can't do that. There is no way of "cloning" a generator:
>>
>> Really? What about itertools.tee()? Sounds like it'd do the job,
>> albeit with some caveats.
>> http://docs.python.org/library/itertools.html#itertools.tee
> 
> It doesn't clone the generator, it just stores the generated objects in
> a temporary array to be re-yielded later.
> 

How about creating something like itertools.tee() that will save and
dump items as necessary. The "new tee" (let's call it tea) would return
several generators that all will refer to a common "tea" object. The
common tea object will keep track of which items has been collected by
each generators and generate new items as necessary. If an item has
already been collected by all generators, that item will be dumped.

Somewhat like this: # untested

class Tea(object):
def __init__(self, iterable, nusers):
self.iterable = iterable
self.cache = {}
self.nusers = nusers

def next(self, n):
try:
item, nusers = self.cache[n]
self.cache[n] = (item, nusers - 1)
except IndexError: # the item hasn't been generated
item = self.iterable.next()
self.cache[n] = (item, nusers)
else:
if nusers == 0:
del self.cache[n]
return item

class TeaClient(object):
def __init__(self, tea):
self.n = 0
self.tea = tea
def next(self):
self.n += 1
return self.tea.next(self.n)

def tea(iterable, nusers):
teaobj = Tea(iterable, nusers)
return [TeaClient(teaobj) for _ in range(nusers)]

--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple conditional expression

2009-03-02 Thread Bruno Desthuilliers

Steve Holden a écrit :

Anjanesh Lekshminarayanan wrote:

How do we know that from the what the OP posted?

Its CGI alright.
spaces = form.has_key('spaces') and form.getvalue('spaces') == '1'

But I just dont see how
spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ?
True: False : False)
is complicated in anyway. Its not that hard to read at all.


In that case I fear Python will be far too simple for your clearly
impressive mind. You've been programming for way too long ...


+1 QOTW !-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread M Kumar
Oh that might be the problem, I m new to this and new to this kind of
conversations. What you said was correct. But what I am looking for is, if
one client reqst comes I need to process the data which I got from the
client, so I need to use the os module. But since my program executes on the
server os.sys.platform has the value "linux2". What I want is a module
having clients platform value for os.sys.platform. Any way to get that?

On Mon, Mar 2, 2009 at 2:17 PM, Chris Rebert  wrote:

> > On Mon, Mar 2, 2009 at 1:59 PM, Chris Rebert  wrote:
> >>
> >> On Mon, Mar 2, 2009 at 12:26 AM, M Kumar  wrote:
> >> >
> >> > Hi,
> >> >
> >> > I am writing a server side program, clients can be any machine but the
> >> > server machine is Linux. In program I want to use the OS module based
> on
> >> > the
> >> > client's operating system. But when I do "import os" m only able to
> get
> >> > the
> >> > module with the property of Linux. ANy idea how to import the module
> >> > with
> >> > the property of clients OS.
> >>
> >> You want sys.platform; see
> >> http://docs.python.org/library/sys.html#sys.platform
> On Mon, Mar 2, 2009 at 12:43 AM, M Kumar  wrote:
> > Hi Chris,
> > Thanks for quick and kind reply, but the python program runs on the
> server,
> > sys.platform is linux only. What I want is I need to get a module, which
> > shud be exactly same as if I import os module on the client machine
>
> Um, you're not phrasing your request very clearly, so perhaps I'm not
> understanding what you're looking for, but I can tell you that
> sys.platform is certainly not Linux-only. If you'll read the docs I
> pointed you to, you'll see a table:
> System  platform value
> Windows 'win32'
> 
>
> Cheers,
> Chris
>
> --
> Shameless self-promotion:
> http://blog.rebertia.com
>



-- 
Regards,

Maneesh KB

Comat Technologies

Bangalore

Mob: 9740-192309



We work with the underprivileged and in rural India. If you are interested
to be a part of it, please mail or call me. I will be happy to share and
inform - http://www.comat.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread Chris Rebert
> On Mon, Mar 2, 2009 at 2:17 PM, Chris Rebert  wrote:
>>
>> > On Mon, Mar 2, 2009 at 1:59 PM, Chris Rebert  wrote:
>> >>
>> >> On Mon, Mar 2, 2009 at 12:26 AM, M Kumar  wrote:
>> >> >
>> >> > Hi,
>> >> >
>> >> > I am writing a server side program, clients can be any machine but
>> >> > the
>> >> > server machine is Linux. In program I want to use the OS module based
>> >> > on
>> >> > the
>> >> > client's operating system. But when I do "import os" m only able to
>> >> > get
>> >> > the
>> >> > module with the property of Linux. ANy idea how to import the module
>> >> > with
>> >> > the property of clients OS.
>> >>
>> >> You want sys.platform; see
>> >> http://docs.python.org/library/sys.html#sys.platform
>> On Mon, Mar 2, 2009 at 12:43 AM, M Kumar  wrote:
>> > Hi Chris,
>> > Thanks for quick and kind reply, but the python program runs on the
>> > server,
>> > sys.platform is linux only. What I want is I need to get a module, which
>> > shud be exactly same as if I import os module on the client machine
>>
>> Um, you're not phrasing your request very clearly, so perhaps I'm not
>> understanding what you're looking for, but I can tell you that
>> sys.platform is certainly not Linux-only. If you'll read the docs I
>> pointed you to, you'll see a table:
>> System  platform value
>> Windows         'win32'
>> 
>>
>> Cheers,
>> Chris

On Mon, Mar 2, 2009 at 12:57 AM, M Kumar  wrote:
> Oh that might be the problem, I m new to this and new to this kind of
> conversations. What you said was correct. But what I am looking for is, if
> one client reqst comes I need to process the data which I got from the
> client, so I need to use the os module. But since my program executes on the
> server os.sys.platform has the value "linux2". What I want is a module
> having clients platform value for os.sys.platform. Any way to get that?> --

How are you getting the request? HTTP? XML-RPC? SOAP? Something else altogether?
If you have control of both the client and the server, it'd be easiest
just to have the client include a parameter specifying what platform
it is in its request to the server.

Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread M Kumar
Its just http, I am using pylons. Right now I am doing tht with extra
parameter. But even if I get to know about the platform of the client
machine, I need to use the other properties of the corresponding machine's
os module. for example I need to use "os.path". So even if I know about the
platform name how to use that information to get os module with the property
of tht particular platform.

On Mon, Mar 2, 2009 at 2:31 PM, Chris Rebert  wrote:

> > On Mon, Mar 2, 2009 at 2:17 PM, Chris Rebert  wrote:
> >>
> >> > On Mon, Mar 2, 2009 at 1:59 PM, Chris Rebert 
> wrote:
> >> >>
> >> >> On Mon, Mar 2, 2009 at 12:26 AM, M Kumar 
> wrote:
> >> >> >
> >> >> > Hi,
> >> >> >
> >> >> > I am writing a server side program, clients can be any machine but
> >> >> > the
> >> >> > server machine is Linux. In program I want to use the OS module
> based
> >> >> > on
> >> >> > the
> >> >> > client's operating system. But when I do "import os" m only able to
> >> >> > get
> >> >> > the
> >> >> > module with the property of Linux. ANy idea how to import the
> module
> >> >> > with
> >> >> > the property of clients OS.
> >> >>
> >> >> You want sys.platform; see
> >> >> http://docs.python.org/library/sys.html#sys.platform
> >> On Mon, Mar 2, 2009 at 12:43 AM, M Kumar  wrote:
> >> > Hi Chris,
> >> > Thanks for quick and kind reply, but the python program runs on the
> >> > server,
> >> > sys.platform is linux only. What I want is I need to get a module,
> which
> >> > shud be exactly same as if I import os module on the client machine
> >>
> >> Um, you're not phrasing your request very clearly, so perhaps I'm not
> >> understanding what you're looking for, but I can tell you that
> >> sys.platform is certainly not Linux-only. If you'll read the docs I
> >> pointed you to, you'll see a table:
> >> System  platform value
> >> Windows 'win32'
> >> 
> >>
> >> Cheers,
> >> Chris
>
> On Mon, Mar 2, 2009 at 12:57 AM, M Kumar  wrote:
> > Oh that might be the problem, I m new to this and new to this kind of
> > conversations. What you said was correct. But what I am looking for is,
> if
> > one client reqst comes I need to process the data which I got from the
> > client, so I need to use the os module. But since my program executes on
> the
> > server os.sys.platform has the value "linux2". What I want is a module
> > having clients platform value for os.sys.platform. Any way to get that?>
> --
>
> How are you getting the request? HTTP? XML-RPC? SOAP? Something else
> altogether?
> If you have control of both the client and the server, it'd be easiest
> just to have the client include a parameter specifying what platform
> it is in its request to the server.
>
> Cheers,
> Chris
>
> --
> Shameless self-promotion:
> http://blog.rebertia.com
>



-- 
Regards,

Maneesh KB

Comat Technologies

Bangalore

Mob: 9740-192309



We work with the underprivileged and in rural India. If you are interested
to be a part of it, please mail or call me. I will be happy to share and
inform - http://www.comat.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread Chris Rebert
> On Mon, Mar 2, 2009 at 2:31 PM, Chris Rebert  wrote:
>> > On Mon, Mar 2, 2009 at 2:17 PM, Chris Rebert  wrote:
>> >> > On Mon, Mar 2, 2009 at 1:59 PM, Chris Rebert 
>> >> > wrote:
>> >> >> On Mon, Mar 2, 2009 at 12:26 AM, M Kumar 
>> >> >> wrote:
>> >> >> >
>> >> >> > Hi,
>> >> >> >
>> >> >> > I am writing a server side program, clients can be any machine but
>> >> >> > the
>> >> >> > server machine is Linux. In program I want to use the OS module
>> >> >> > based
>> >> >> > on
>> >> >> > the
>> >> >> > client's operating system. But when I do "import os" m only able
>> >> >> > to
>> >> >> > get
>> >> >> > the
>> >> >> > module with the property of Linux. ANy idea how to import the
>> >> >> > module
>> >> >> > with
>> >> >> > the property of clients OS.
>> >> >>
>> >> >> You want sys.platform; see
>> >> >> http://docs.python.org/library/sys.html#sys.platform
>> >> On Mon, Mar 2, 2009 at 12:43 AM, M Kumar  wrote:
>> >> > Hi Chris,
>> >> > Thanks for quick and kind reply, but the python program runs on the
>> >> > server,
>> >> > sys.platform is linux only. What I want is I need to get a module,
>> >> > which
>> >> > shud be exactly same as if I import os module on the client machine
>> >>
>> >> Um, you're not phrasing your request very clearly, so perhaps I'm not
>> >> understanding what you're looking for, but I can tell you that
>> >> sys.platform is certainly not Linux-only. If you'll read the docs I
>> >> pointed you to, you'll see a table:
>> >> System  platform value
>> >> Windows         'win32'
>> >> 
>> >>
>> >> Cheers,
>> >> Chris
>>
>> On Mon, Mar 2, 2009 at 12:57 AM, M Kumar  wrote:
>> > Oh that might be the problem, I m new to this and new to this kind of
>> > conversations. What you said was correct. But what I am looking for is,
>> > if
>> > one client reqst comes I need to process the data which I got from the
>> > client, so I need to use the os module. But since my program executes on
>> > the
>> > server os.sys.platform has the value "linux2". What I want is a module
>> > having clients platform value for os.sys.platform. Any way to get that?>
>> > --
>>
>> How are you getting the request? HTTP? XML-RPC? SOAP? Something else
>> altogether?
>> If you have control of both the client and the server, it'd be easiest
>> just to have the client include a parameter specifying what platform
>> it is in its request to the server.
>>
>> Cheers,
>> Chris

On Mon, Mar 2, 2009 at 1:12 AM, M Kumar  wrote:
> Its just http, I am using pylons. Right now I am doing tht with extra
> parameter. But even if I get to know about the platform of the client
> machine, I need to use the other properties of the corresponding machine's
> os module. for example I need to use "os.path". So even if I know about the
> platform name how to use that information to get os module with the property
> of tht particular platform.

Then send os.path and whatever else you need along too. Alternatively,
you might want to switch to something better suited to your purposes
than a web app framework, such as pyro (http://pyro.sourceforge.net/),
ICE (http://www.zeroc.com/ice.html), or PB
(http://twistedmatrix.com/projects/core/documentation/howto/pb-intro.html).

Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple conditional expression

2009-03-02 Thread Christian Tismer

On 3/2/09 12:53 AM, Bruno Desthuilliers wrote:

Steve Holden a écrit :

Anjanesh Lekshminarayanan wrote:

How do we know that from the what the OP posted?

Its CGI alright.
spaces = form.has_key('spaces') and form.getvalue('spaces') == '1'

But I just dont see how
spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ?
True: False : False)
is complicated in anyway. Its not that hard to read at all.


In that case I fear Python will be far too simple for your clearly
impressive mind. You've been programming for way too long ...


+1 QOTW !-)


Bruhahaa, my biggest laugh since months

--
Christian Tismer :^)   
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: ordinal not in range

2009-03-02 Thread Jaap van Wingerde
Stefan Behnel wrote:
>> Jaap van Wingerde wrote:
>> outfile = codecs.open(output, "w", "utf_8")
> I guess you mixed up the case here.
> Does this help?
> outfile = codecs.open(output, "wb", encoding="UTF-8")

According to the Python "Codec registry an base classes"
 "U8", "UTF", and
"utf8" are aliases and is the codec: utf_8.

Jaap.



-- 
Jaap van Wingerde
e-mail: 1234567...@vanwingerde.net
web: http://jaap.vanwingerde.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: How best to test functions which use date.today

2009-03-02 Thread Yuan HOng
Hello,

Thanks for all the great ideas. Based on your input, I was able to solve my
problem by way of a FakeDate in a fakedate module.

In the testing module, before importing the tested module, I would load my
fakedate module into sys.modules under the key 'datetime'. So when the
tested module is imported, it will get my fakedate module in stead of the
original C-extension datetime module.

That way, the tested module needs no modification.

-- 
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn
--
http://mail.python.org/mailman/listinfo/python-list


RE: file locking...

2009-03-02 Thread bruce
hi lawrence..

my concern about a "gatekeeper" wasn't so much related to performance, as
the possibility of race conditions... if you only have a few client apps
trying to access the files in the target dir, than you can in theory
probably be ok..

for my app, the client process seeking files in the dir are client processes
hitting a web service. i don't want these guys to be in a potential "wait"
state, which could happen if i had the back end app simply do a try and hope
for the best on the lock file.

what i believe i'm ultimately going to need, is some form of a queuing
system, where the client app, via a backend webservice/process, puts in a
queue/order saying it's ready for a batch of files.. and have this fifo
process somehow gets the files ready for processing for the client...

thanks



-Original Message-
From: python-list-bounces+bedouglas=earthlink@python.org
[mailto:python-list-bounces+bedouglas=earthlink@python.org]on Behalf
Of Lawrence D'Oliveiro
Sent: Monday, March 02, 2009 12:29 AM
To: python-list@python.org
Subject: RE: file locking...


In message , bruce
wrote:

> using any kind of file locking process requires that i essentially have a
> gatekeeper, allowing a single process to enter, access the files at a
> time...

The gatekeeper doesn't need to do any more than ensure that any particular
filename is only locked by a maximum of one process at a time.

Given that interprocess communication (and consequent context-switching) is
going to be orders of magnitude faster than accessing disk files, there's no
a-priori reason to assume that this need be a performance bottleneck.

--
http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-02 Thread Tim Rowe
2009/3/1 Paul Rubin :
> Steve Holden  writes:
>> I'm not sure what you think the speed of Ruby has to do with Python.
>
> In the real world, people care about the relative speed of programs.

Yes, and they care about the cost of programs, and about the
functionality of programs. If I wanted fast code I wouldn't use Python
*or* Ruby (I'd probably use FORTH; C would be a more mainstream
choice) -- but don't expect the program soon. Even where speed does
matter, plain Python against plain Ruby isn't a meaningful comparison,
because a common style in Python (and probably in Ruby too) is to get
the code working, then if there are any *measured* bottlenecks to
optimise them in C++.  That means that in practice there won't be a
perceptible speed difference for the user.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread Tim Chase

Its just http, I am using pylons. Right now I am doing tht
with extra parameter. But even if I get to know about the
platform of the client machine, I need to use the other
properties of the corresponding machine's os module.


HTTP doesn't require the client browser to send any such 
information to you, so there's no way you can be sure to get it.


The User-Agent header _may_ include some sort of platform 
information[1].  However, it may omit this information, or the 
user can change it so it downright lies[2].


Therefore, unless you control the application running on the 
client end (possible within a corporate environment, or if you're 
running a rich client that just happens to use HTTP as its 
communication transport; wherein your user-agent app on the 
client side can send "X-*" extended headers that your server can 
parse), you're at the mercy of your user to give you information 
that you need/want.  Compounding this problem, even *with* 
benevolent user-agent strings, it won't include other 
sys/os-module type information such the $PATH.


I'd suggest reading up on HTTP[3] so you know what is and isn't 
included in the protocol so you can set your expectations 
according to its limitations.


-tkc


[1]
http://www.zytrax.com/tech/web/browser_ids.htm

[2]

https://addons.mozilla.org/en-US/firefox/addon/59

[3]
http://www.ietf.org/rfc/rfc2616.txt




--
http://mail.python.org/mailman/listinfo/python-list


Python parser

2009-03-02 Thread Clarendon
Can somebody recommend a good parser that can be used in Python
programs? I need a parser with large grammar that can cover a large
amount of random texts.

Thank you very much.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python parser

2009-03-02 Thread Lie Ryan
Clarendon wrote:
> Can somebody recommend a good parser that can be used in Python
> programs?

Do you want parser that can parse python source code or parser that
works in python? If the latter, pyparsing is a popular choice. Ply is
another. There are many choice:
http://nedbatchelder.com/text/python-parsers.html

For simple parsing, the re module might be enough.

> I need a parser with large grammar that can cover a large
> amount of random texts.

Random text? Uh... what's the purpose of parsing random text?
--
http://mail.python.org/mailman/listinfo/python-list


RichCompare and RichCompareBool

2009-03-02 Thread Aaron Brady
Hi,

In the source for 3.0.1, PyObject_RichCompareBool seems to perform an
extra check on identity that PyObjecct_RichCompare does not perform.

Here's the excerpt from RichCompareBool (line 612):

/* Quick result when objects are the same.
   Guarantees that identity implies equality. */
if (v == w) {
if (op == Py_EQ)
return 1;
else if (op == Py_NE)
return 0;
}

res = PyObject_RichCompare(v, w, op);

The code for PyObject_RichCompare does not contain this, it doesn't
seem.  Is it a bug?
--
http://mail.python.org/mailman/listinfo/python-list


Re: OTish: convince the team to drop VBScript

2009-03-02 Thread jkn
On Feb 28, 8:19 pm, rdmur...@bitdance.com wrote:
[...]
>
> IMO the first thing you ought to do is dig in, really listen, and find
> out what his issue is with module distribution.
>
> Listening well is your most powerful asset.  Overcome your own prejudices
> first, and his may follow :)

I agree with this. Find out what troubles him ... leave aside for now
whether it's a true, or false, picture of reality as you understand
it.

This then leads to you painting a picture for him:

"So ... if I could demonstrate for you a way in which Python [X Y
Z ...], how would that be for you?"

Keep refining this until his answer (in words or otherwise) is
"Fantastic, great, super!".

Find out what will allow him to buy into it for himself, and then
build/demonstrate that.

HTH
J^n
--
http://mail.python.org/mailman/listinfo/python-list


Re: RichCompare and RichCompareBool

2009-03-02 Thread Duncan Booth
Aaron Brady  wrote:

> Hi,
> 
> In the source for 3.0.1, PyObject_RichCompareBool seems to perform an
> extra check on identity that PyObjecct_RichCompare does not perform.
> 
> Here's the excerpt from RichCompareBool (line 612):
> 
>  /* Quick result when objects are the same.
> Guarantees that identity implies equality. */
>  if (v == w) {
>   if (op == Py_EQ)
>return 1;
>   else if (op == Py_NE)
>return 0;
>  }
> 
>  res = PyObject_RichCompare(v, w, op);
> 
> The code for PyObject_RichCompare does not contain this, it doesn't
> seem.  Is it a bug?

Without looking at the code it sounds like a bug: identity doesn't always 
imply equality.

It may be that the code you've found only gets called in specific cases 
where you can make that assumption, but otherwise it should be removed.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: os module

2009-03-02 Thread Gabriel Genellina
En Mon, 02 Mar 2009 07:12:55 -0200, M Kumar   
escribió:



Its just http, I am using pylons. Right now I am doing tht with extra
parameter. But even if I get to know about the platform of the client
machine, I need to use the other properties of the corresponding  
machine's
os module. for example I need to use "os.path". So even if I know about  
the
platform name how to use that information to get os module with the  
property

of tht particular platform.


The Windows version of os.path is ntpath; the Linux&Co version is  
posixpath. You may import any of them explicitely. For other values, see  
the os.py source.
(I think this answers your question, but I'm not sure it's the answer to  
your problems)


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: RichCompare and RichCompareBool

2009-03-02 Thread Aaron Brady
On Mar 2, 5:00 am, Duncan Booth  wrote:
> Aaron Brady  wrote:
> > Hi,
>
> > In the source for 3.0.1, PyObject_RichCompareBool seems to perform an
> > extra check on identity that PyObjecct_RichCompare does not perform.
snip
> > The code for PyObject_RichCompare does not contain this, it doesn't
> > seem.  Is it a bug?
>
> Without looking at the code it sounds like a bug: identity doesn't always
> imply equality.
>
> It may be that the code you've found only gets called in specific cases
> where you can make that assumption, but otherwise it should be removed.
>
> --
> Duncan Boothhttp://kupuguy.blogspot.com

For reference, here's what the docs say (3.0.1):

'''
PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid)
Return value: New reference.
Compare the values of o1 and o2 using the operation specified by opid,
which must be one of Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or Py_GE,
corresponding to <, <=, ==, !=, >, or >= respectively. This is the
equivalent of the Python expression o1 op o2, where op is the operator
corresponding to opid. Returns the value of the comparison on success,
or NULL on failure.

int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid)
Compare the values of o1 and o2 using the operation specified by opid,
which must be one of Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or Py_GE,
corresponding to <, <=, ==, !=, >, or >= respectively. Returns -1 on
error, 0 if the result is false, 1 otherwise. This is the equivalent
of the Python expression o1 op o2, where op is the operator
corresponding to opid.
'''

As you can see, the only difference is the statement of the return
value.

As an aside, though, it's interesting that '__eq__' &c. can return any
object, in addition to True and False.  I hadn't thought of that.
'RichCompareBool' just calls 'PyObject_IsTrue' on the result.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iterator class to allow self-restarting generator expressions?

2009-03-02 Thread Gabriel Genellina

En Mon, 02 Mar 2009 06:48:02 -0200, Lie Ryan  escribió:

Gabriel Genellina wrote:

En Sun, 01 Mar 2009 15:51:07 -0200, Chris Rebert 
escribió:

On Sun, Mar 1, 2009 at 8:54 AM, Gabriel Genellina
 wrote:

En Sun, 01 Mar 2009 13:20:28 -0200, John O'Hagan

escribió:

Inspired by some recent threads here about using classes to extend  
the

behaviour of iterators, I'm trying to replace some some top-level
functions
aimed at doing such things with a class.


I'm afraid you can't do that. There is no way of "cloning" a  
generator:


Really? What about itertools.tee()? Sounds like it'd do the job,
albeit with some caveats.
http://docs.python.org/library/itertools.html#itertools.tee


It doesn't clone the generator, it just stores the generated objects in
a temporary array to be re-yielded later.


How about creating something like itertools.tee() that will save and
dump items as necessary. The "new tee" (let's call it tea) would return
several generators that all will refer to a common "tea" object. The
common tea object will keep track of which items has been collected by
each generators and generate new items as necessary. If an item has
already been collected by all generators, that item will be dumped.


That's exactly what itertools.tee does! Or I'm missing something?

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-02 Thread Paul Boddie
On 1 Mar, 15:20, Steve Holden  wrote:
> Kless wrote:
> > Does anybody has seen the performance of Python 3?
> > Respect to speed it's the last language together to Ruby 1.8, but Ruby
> > 1.9 has a lot of better performance. :(
>
> I'm not sure what you think the speed of Ruby has to do with Python.

I imagine the author was contrasting the priorities of the developers
of each language implementation. Ruby 1.8 and earlier were regarded as
being very slow; Ruby 1.9 is faster because the developers have used
techniques similar to those employed in the CPython implementation.
Although one shouldn't extrapolate performance improvements from the
difference between two consecutive releases, one can observe that one
set of developers has prioritised performance (admittedly to remedy
deficiencies) while another set has prioritised features.

One is left to wonder how the performance of the next major Ruby
release will compare with the next major Python releases. Such things
were barely worth considering before - maybe that was the author's
point.

Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: unziping a file in python..

2009-03-02 Thread MRAB

Steven D'Aprano wrote:

On Mon, 02 Mar 2009 01:00:54 -0500, David Lyon wrote:


It might seem a simple question.. but how does one programmaticaly unzip
a file in python?



A quick and dirty solution would be something like this:

zf = zipfile.ZipFile('Archive.zip')
for name in zf.namelist():
open(name, 'w').write(zf.read(name))


You might want to specify an output folder (and the data might be binary
too):

zf = zipfile.ZipFile('Archive.zip')
for name in zf.namelist():
open(os.path.join(output_folder, name), 'wb').write(zf.read(name))

--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread J. Clifford Dyer
On Mon, 2009-03-02 at 00:33 -0800, Hussein B wrote:
> On Mar 1, 11:27 pm, "J. Clifford Dyer"  wrote:
> > On Sun, 2009-03-01 at 09:51 -0500, Philip Semanchuk wrote:
> > > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
> >
> > > > Hey,
> > > > I'm retrieving records from MySQL database that contains non english
> > > > characters.
> > > > Then I create a String that contains HTML markup and column values
> > > > from the previous result set.
> > > > +
> > > > markup = u'''.'''
> > > > for row in rows:
> > > > markup = markup + '' + row['id']
> > > > markup = markup + '
> > > > +
> > > > Then I'm sending the email according to this tip:
> > > >http://code.activestate.com/recipes/473810/
> > > > Well, the email contains ? characters for each non english ones.
> > > > Any ideas?
> >
> > > There's so many places where this could go wrong and you haven't  
> > > narrowed down the problem.
> >
> > > Are the characters stored in the database correctly?
> >
> > > Are they stored consistently (i.e. all using the same encoding, not  
> > > some using utf-8 and others using iso-8859-1)?
> >
> > > What are you getting out of the database? Is it being converted to  
> > > Unicode correctly, or at all?
> >
> > > Are you sure that the program you're using to view the email  
> > > understands the encoding?
> >
> > > Isolate those questions one at a time. Add some debugging breakpoints.  
> > > Ensure that you have what you think you have. You might not fix your  
> > > problem, but you will make it much smaller and more specific.
> >
> > > Good luck
> > > Philip
> >
> > Let me add to that checklist:
> >
> > Are you sure the email you are creating has the encoding declared
> > properly in the headers?
> >
> >
> >
> >
> > Cheers,
> > Cliff
> 
> My HTML markup contains only table tags (you know, table, tr and td)

Ah.  The issue is not with the HTML markup, but the email headers.  For
example, the email you sent me has a header that says: 

Content-type: text/plain; charset="iso-8859-1"

Guessing from the recipe you linked to, you probably need something
like:

msgRoot['Content-type'] = 'text/plain; charset="utf-16"'

replacing utf-16 with whatever encoding you have encoded your email
with.

Or it may be that the header has to be attached to the individual mime
parts.  I'm not as familiar with MIME.


Cheers,
Cliff



--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread Hussein B
On Mar 2, 4:03 pm, "J. Clifford Dyer"  wrote:
> On Mon, 2009-03-02 at 00:33 -0800, Hussein B wrote:
> > On Mar 1, 11:27 pm, "J. Clifford Dyer"  wrote:
> > > On Sun, 2009-03-01 at 09:51 -0500, Philip Semanchuk wrote:
> > > > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > > > Hey,
> > > > > I'm retrieving records from MySQL database that contains non english
> > > > > characters.
> > > > > Then I create a String that contains HTML markup and column values
> > > > > from the previous result set.
> > > > > +
> > > > > markup = u'''.'''
> > > > > for row in rows:
> > > > >     markup = markup + '' + row['id']
> > > > > markup = markup + '
> > > > > +
> > > > > Then I'm sending the email according to this tip:
> > > > >http://code.activestate.com/recipes/473810/
> > > > > Well, the email contains ? characters for each non english ones.
> > > > > Any ideas?
>
> > > > There's so many places where this could go wrong and you haven't  
> > > > narrowed down the problem.
>
> > > > Are the characters stored in the database correctly?
>
> > > > Are they stored consistently (i.e. all using the same encoding, not  
> > > > some using utf-8 and others using iso-8859-1)?
>
> > > > What are you getting out of the database? Is it being converted to  
> > > > Unicode correctly, or at all?
>
> > > > Are you sure that the program you're using to view the email  
> > > > understands the encoding?
>
> > > > Isolate those questions one at a time. Add some debugging breakpoints.  
> > > > Ensure that you have what you think you have. You might not fix your  
> > > > problem, but you will make it much smaller and more specific.
>
> > > > Good luck
> > > > Philip
>
> > > Let me add to that checklist:
>
> > > Are you sure the email you are creating has the encoding declared
> > > properly in the headers?
>
> > > Cheers,
> > > Cliff
>
> > My HTML markup contains only table tags (you know, table, tr and td)
>
> Ah.  The issue is not with the HTML markup, but the email headers.  For
> example, the email you sent me has a header that says:
>
> Content-type: text/plain; charset="iso-8859-1"
>
> Guessing from the recipe you linked to, you probably need something
> like:
>
> msgRoot['Content-type'] = 'text/plain; charset="utf-16"'
>
> replacing utf-16 with whatever encoding you have encoded your email
> with.
>
> Or it may be that the header has to be attached to the individual mime
> parts.  I'm not as familiar with MIME.
>
> Cheers,
> Cliff

Hey Cliff,
I tried your tip and I still get the same thing (?)
I added print statement to print each value of the result set into the
console, which also prints  characters instead of the real
characters values.
Maybe a conversion is happened upon getting the data from the
database?
(the values are stored correctly in the database)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python parser

2009-03-02 Thread andrew cooke

if this is for natural language texts you may want to look at
http://www.nltk.org/

andrew

Clarendon wrote:
> Can somebody recommend a good parser that can be used in Python
> programs? I need a parser with large grammar that can cover a large
> amount of random texts.
>
> Thank you very much.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread John Machin
On Mar 2, 7:30 pm, Hussein B  wrote:
> On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
>
> > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > Hey,
> > > I'm retrieving records from MySQL database that contains non english
> > > characters.

Can you reveal which language???

> > > Then I create a String that contains HTML markup and column values
> > > from the previous result set.
> > > +
> > > markup = u'''.'''
> > > for row in rows:
> > >     markup = markup + '' + row['id']
> > > markup = markup + '
> > > +
> > > Then I'm sending the email according to this tip:
> > >http://code.activestate.com/recipes/473810/
> > > Well, the email contains ? characters for each non english ones.
> > > Any ideas?
>
> > There's so many places where this could go wrong and you haven't  
> > narrowed down the problem.
>
> > Are the characters stored in the database correctly?
>
> Yes they are.

How do you KNOW that they are stored correctly? What makes you so
sure?

>
> > Are they stored consistently (i.e. all using the same encoding, not  
> > some using utf-8 and others using iso-8859-1)?
>
> Yes.

So what is the encoding used to store them?

>
> > What are you getting out of the database? Is it being converted to  
> > Unicode correctly, or at all?
>
> I don't know, how to make sure of this point?

You could show us some of the output from the database query. As well
as
   print the_output
you should
   print repr(the_output)
and show us both, and also tell us what you *expect* to see.

And let's get the database output sorted out before we worry about the
email message.
--
http://mail.python.org/mailman/listinfo/python-list


socket problem

2009-03-02 Thread step
  my server program is writed with c in windows using mingw,using
"select" model

 client is writed with python

 the problem is , when the client connect the server, the function
FD_ISSET(cilentfd,&set) always true, but it hvae read no data, i also
no send data to server.

 why? i use telnet program in windows to test my server ,it
good ,FD_ISSET  is work ok, it return false
--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread Hussein B
On Mar 2, 4:31 pm, John Machin  wrote:
> On Mar 2, 7:30 pm, Hussein B  wrote:
>
> > On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
>
> > > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > > Hey,
> > > > I'm retrieving records from MySQL database that contains non english
> > > > characters.
>
> Can you reveal which language???
>
>
>
Arabic

> > > > Then I create a String that contains HTML markup and column values
> > > > from the previous result set.
> > > > +
> > > > markup = u'''.'''
> > > > for row in rows:
> > > >     markup = markup + '' + row['id']
> > > > markup = markup + '
> > > > +
> > > > Then I'm sending the email according to this tip:
> > > >http://code.activestate.com/recipes/473810/
> > > > Well, the email contains ? characters for each non english ones.
> > > > Any ideas?
>
> > > There's so many places where this could go wrong and you haven't  
> > > narrowed down the problem.
>
> > > Are the characters stored in the database correctly?
>
> > Yes they are.
>
> How do you KNOW that they are stored correctly? What makes you so
> sure?
>
>
Because MySQL Query Browser displays them correctly, in addition I use
BIRT as the reporting system and it shows them correctly.

>
> > > Are they stored consistently (i.e. all using the same encoding, not  
> > > some using utf-8 and others using iso-8859-1)?
>
> > Yes.
>
> So what is the encoding used to store them?
>
>
>
Tables are created with UTF-8 encoding option

> > > What are you getting out of the database? Is it being converted to  
> > > Unicode correctly, or at all?
>
> > I don't know, how to make sure of this point?
>
> You could show us some of the output from the database query. As well
> as
>    print the_output
> you should
>    print repr(the_output)
> and show us both, and also tell us what you *expect* to see.
>

The result of print repr(row['name']) is '??? ??'
The '?' characters are supposed to be Arabic characters.

> And let's get the database output sorted out before we worry about the
> email message.

Thanks all for help.
--
http://mail.python.org/mailman/listinfo/python-list


Restructure dictionary (Python 2.5)

2009-03-02 Thread Fencer

Hello, I have a dictionary that has strings as keys and for each key the
associated value is a list of strings. Many of the lists contain only 
one element and a given element may appear for more than one key.
What I need to do now is create a new dictionary where the strings in 
the list are keys and their values is a list of which keys in the "old" 
dictionary that contained them.

So I want to go from:
aa:[a, b, c]
bb:[c, d]
to
a:[aa]
b:[aa]
c[aa, bb]
d:[bb]

I tried this code:
old_dict = {'xyz':['a','b','c'],'baz':['c','d']}
new_dict = {}
for dkey, vallist in old_dict.iteritems():
for val in vallist:
if val in new_dict:
theset = new_dict[val]
theset.add(dkey)
new_dict[val] = theset
else:
new_dict[val] = set([dkey])
print new_dict

Which yields the output {'a': set(['xyz']), 'c': set(['xyz', 'baz']), 
'b': set(['xyz']), 'd': set(['baz'])}, so it seems to work but I have a 
feeling this is a crappy solution that's underusing Python. Please 
enlighten me of a better way!


- Fencer
--
http://mail.python.org/mailman/listinfo/python-list


Re: socket problem

2009-03-02 Thread Jean-Paul Calderone

On Mon, 2 Mar 2009 06:40:57 -0800 (PST), step  wrote:

 my server program is writed with c in windows using mingw,using
"select" model

client is writed with python

the problem is , when the client connect the server, the function
FD_ISSET(cilentfd,&set) always true, but it hvae read no data, i also
no send data to server.

why? i use telnet program in windows to test my server ,it
good ,FD_ISSET  is work ok, it return false


Perhaps there is a bug in your C program and it only works sometimes.
There is *no* misuse of socket APIs which the Python client could be
committing which would cause a correctly written server (in C or any
other language with BSD socket APIs) to fail.  I suggest investigating
how telnet and your Python client differ, then looking into the C code
to find out how that difference can trigger a bug in it.

Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: unziping a file in python..

2009-03-02 Thread Luis Zarrabeitia

Quoting MRAB :
> Steven D'Aprano wrote:
> > A quick and dirty solution would be something like this:
> > 
> > zf = zipfile.ZipFile('Archive.zip')
> > for name in zf.namelist():
> > open(name, 'w').write(zf.read(name))
> > 
> You might want to specify an output folder (and the data might be binary
> too):
> 
> zf = zipfile.ZipFile('Archive.zip')
> for name in zf.namelist():
>  open(os.path.join(output_folder, name), 'wb').write(zf.read(name))
> 

Question here... wouldn't you also need to create all the intermediate folders
from "output_folder" to "output_folder/name" (assuming that 'name' has several
path parts in it)? Is there any elegant way to do it? 

(is there any way to make os.mkdir behave like mkdir -p?)

-- 
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie

 Participe en Universidad 2010, del 8 al 12 de febrero de 2010
 La Habana, Cuba 
 http://www.universidad2010.cu
 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Restructure dictionary (Python 2.5)

2009-03-02 Thread Tim Chase

I tried this code:
old_dict = {'xyz':['a','b','c'],'baz':['c','d']}
new_dict = {}
for dkey, vallist in old_dict.iteritems():
for val in vallist:
if val in new_dict:
theset = new_dict[val]
theset.add(dkey)
new_dict[val] = theset
else:
new_dict[val] = set([dkey])
print new_dict

Which yields the output {'a': set(['xyz']), 'c': set(['xyz', 'baz']), 
'b': set(['xyz']), 'd': set(['baz'])}, so it seems to work but I have a 
feeling this is a crappy solution that's underusing Python. Please 
enlighten me of a better way!


In python2.5, collections.defaultdict was added which could clean 
this up a bit:


  import collections
  # using a set to remove duplication
  new_dict = collections.defaultdict(set)
  for dkey, vallist in old_dict.iteritems():
for val in vallist:
  new_dict[val].add(dkey)

  # using a list to keep all keys
  new_dict = collections.defaultdict(list)
  for dkey, vallist in old_dict.iteritems():
for val in vallist:
  new_dict[val].append(dkey)

If you're working in pre-2.5 python, you could use

  new_dict = {}
  ...
  # use a set()
  new_dict.setdefault(val, set()).add(dkey)
  # use a list()
  new_dict.setdefault(val, []).append(dkey)

-tkc




--
http://mail.python.org/mailman/listinfo/python-list


Looking for a General Method to Configure Tkinter Widgets

2009-03-02 Thread W. eWatson
I'm modifying a Tkinter Python program that uses hard coded initial values 
for several widgets. For example, latitude = 40. My plan is to put the names 
and values for configuration purposes into a file. For example, a pseudo 
statement like the one just given. ConfigObj provides a mechanism for it.


I am only at an early stage of learning Tkinter, but it looks like a hang up 
is in the use of control variables passed between widgets and non-Tkinter 
objects that setup up the widget and retrieve the changed values. Roughly, 
the main loop contains code like self.longitude = 40. Non-Tkinter objects 
set up the parameters to the widgets, and when a widget* is complete the 
setup program resets the main loop globals. As I see it, it looks like 
IntVar, etc. used must be hard coded, as in the original program, to 
preserve types like boolean, strings, integers, floats, etc. It's either 
that or use of eval or some like function. Comments?


* For example, in one setup program, I see code like this after its call to 
a dialog returns:


try:
s = dialog.stopVar.get()
d = [ int(x) for x in s.split(":") ]
self.stop_time = datetime.time(d[0],d[1],d[2])

stop_time is a string like "10:30:15".
--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple conditional expression

2009-03-02 Thread John Machin
On Feb 27, 7:55 pm, bearophileh...@lycos.com wrote:
> Chris Rebert:
>
> > That seems to just be an overly complicated way of writing:
>
> > spaces = bool(form.has_key('spaces') and form.getvalue('spaces') == 1)
>
> Better:
>
> spaces = bool(('spaces' in form) and form.getvalue('spaces') == 1)

Huh?? Much better is:
spaces = 'spaces' in form and form.getvalue('spaces') == 1

Then you go looking at "form": form.getvalue behaves just like
dict.get, and returns a non-None object (a str object). So the guard
clause can be retired; the ingloriously superobfuscatory original can
be compressed LEGIBLY into
   spaces = form.getvalue('spaces') == "1"


--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread Philip Semanchuk


On Mar 2, 2009, at 9:50 AM, Hussein B wrote:


On Mar 2, 4:31 pm, John Machin  wrote:

On Mar 2, 7:30 pm, Hussein B  wrote:


On Mar 1, 4:51 pm, Philip Semanchuk  wrote:

What are you getting out of the database? Is it being converted to
Unicode correctly, or at all?



I don't know, how to make sure of this point?


Personally, I'd add a debug breakpoint just after extracting the  
characters from the database, like so:


   import pdb
   pdb.set_trace()

When you're stopped at the breakpoint, examine the string you get  
back. Is it what you expect? For instance, is it Unicode?


   isinstance(my_string, unicode)

Or maybe you're expecting a utf-8 encoded string, so examine one of  
the non-ASCII characters. Is it really utf-8 encoded?


>>> my_string = u"snö".encode("utf-8")
>>> my_string[0]
's'
>>> my_string[1]
'n'
>>> my_string[2]
'\xc3'
>>> my_string[3]
'\xb6'


Since you feel pretty confident that you're getting what you expect  
out of the database, maybe you want to eliminate that from  
consideration. As a test, construct "by hand" a string that represents  
the email message you're trying to send. If you send that with the  
proper content-type header and you still don't get the results you  
want, then we can all stop discussing the database. Make sense?


Forget about the HTML markup, too. That's just a distraction. Start  
with the simplest problem first, and then add pieces on.


See if you can successfully construct and send an email that says  
"Hello world" in English/ASCII. If that works, change it to Arabic. If  
that works, change the email format to HTML. If that works, starts  
pulling the content from the database. If that works, then you're  
done. =)


bye
Philip








--
http://mail.python.org/mailman/listinfo/python-list


Re: Restructure dictionary (Python 2.5)

2009-03-02 Thread imageguy
> ...  this is a crappy solution that's underusing Python. Please
> enlighten me of a better way!
>
> - Fencer

One thing that springs to mind is using the dict method .setdefault


for dkey, vallist in old_dict.iteritems():
for val in vallist:
new_dict.setdefault(val, set()).add(dkey)



--
http://mail.python.org/mailman/listinfo/python-list


executable

2009-03-02 Thread toks teewey
Hello,

I want to ask if it is possible to link a program written in python to a 
database and also on how
to make a program written in python executable.

Regards 



  --
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread John Machin
On Mar 3, 1:50 am, Hussein B  wrote:
> On Mar 2, 4:31 pm, John Machin  wrote:> On Mar 2, 
> 7:30 pm, Hussein B  wrote:
>
> > > On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
>
> > > > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > > > Hey,
> > > > > I'm retrieving records from MySQL database that contains non english
> > > > > characters.
>
> > Can you reveal which language???
>
> Arabic
>
>
>
> > > > > Then I create a String that contains HTML markup and column values
> > > > > from the previous result set.
> > > > > +
> > > > > markup = u'''.'''
> > > > > for row in rows:
> > > > >     markup = markup + '' + row['id']
> > > > > markup = markup + '
> > > > > +
> > > > > Then I'm sending the email according to this tip:
> > > > >http://code.activestate.com/recipes/473810/
> > > > > Well, the email contains ? characters for each non english ones.
> > > > > Any ideas?
>
> > > > There's so many places where this could go wrong and you haven't  
> > > > narrowed down the problem.
>
> > > > Are the characters stored in the database correctly?
>
> > > Yes they are.
>
> > How do you KNOW that they are stored correctly? What makes you so
> > sure?
>
> Because MySQL Query Browser displays them correctly, in addition I use
> BIRT as the reporting system and it shows them correctly.
>
>
>
> > > > Are they stored consistently (i.e. all using the same encoding, not  
> > > > some using utf-8 and others using iso-8859-1)?
>
> > > Yes.
>
> > So what is the encoding used to store them?
>
> Tables are created with UTF-8 encoding option
>
> > > > What are you getting out of the database? Is it being converted to  
> > > > Unicode correctly, or at all?
>
> > > I don't know, how to make sure of this point?
>
> > You could show us some of the output from the database query. As well
> > as
> >    print the_output
> > you should
> >    print repr(the_output)
> > and show us both, and also tell us what you *expect* to see.
>
> The result of print repr(row['name']) is '??? ??'
> The '?' characters are supposed to be Arabic characters.

Are you expecting 3 Arabic characters, a space, and then 6 Arabic
characters?

We now have some interesting evidence: row['name'] is NOT a unicode
object -- otherwise the print would show u'??? ??'; it's a str
object.

So: A utf8-encoded string is being decoded to unicode, and then re-
encoded to some other encoding, using the "replace" (with "?") error-
handling method. That shouldn't be hard to spot! It's about time you
showed us the code you are using to extract the data from the
database, including the print statements you have put in.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread John Machin
On Mar 3, 2:22 am, Philip Semanchuk  wrote:
> On Mar 2, 2009, at 9:50 AM, Hussein B wrote:
>
> > On Mar 2, 4:31 pm, John Machin  wrote:
> >> On Mar 2, 7:30 pm, Hussein B  wrote:
>
> >>> On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
>  What are you getting out of the database? Is it being converted to
>  Unicode correctly, or at all?
>
> >>> I don't know, how to make sure of this point?
>
> Personally, I'd add a debug breakpoint just after extracting the  
> characters from the database, like so:
>
>     import pdb
>     pdb.set_trace()
>
> When you're stopped at the breakpoint, examine the string you get  
> back. Is it what you expect? For instance, is it Unicode?
>
>     isinstance(my_string, unicode)
>
> Or maybe you're expecting a utf-8 encoded string, so examine one of  
> the non-ASCII characters. Is it really utf-8 encoded?
>
>  >>> my_string = u"snö".encode("utf-8")
>  >>> my_string[0]
> 's'
>  >>> my_string[1]
> 'n'
>  >>> my_string[2]
> '\xc3'
>  >>> my_string[3]
> '\xb6'
>
> Since you feel pretty confident that you're getting what you expect  
> out of the database, maybe you want to eliminate that from  
> consideration. As a test, construct "by hand" a string that represents  
> the email message you're trying to send. If you send that with the  
> proper content-type header and you still don't get the results you  
> want, then we can all stop discussing the database. Make sense?
>
> Forget about the HTML markup, too. That's just a distraction. Start  
> with the simplest problem first, and then add pieces on.
>
> See if you can successfully construct and send an email that says  
> "Hello world" in English/ASCII. If that works, change it to Arabic. If  
> that works, change the email format to HTML. If that works, starts  
> pulling the content from the database. If that works, then you're  
> done. =)

Yuk. You are asking him to write extra speculative code when he's
having extreme difficulty debugging the code he's already got! He's
already said he's getting ?? soon after the database retrieval ---
you want him to work on the downstream problem when the upstream is
still very muddy???

Sheeesh.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iterator class to allow self-restarting generator expressions?

2009-03-02 Thread John O'Hagan
On Sun, 1 Mar 2009, Terry Reedy wrote:
> John O'Hagan wrote:
> > Inspired by some recent threads here about using classes to extend the
> > behaviour of iterators, I'm trying to replace some some top-level
> > functions aimed at doing such things with a class.
> >
> > So far it's got a test for emptiness, a non-consuming peek-ahead method,
> > and an extended next() which can return slices as well as the normal
> > mode, but one thing I'm having a little trouble with is getting generator
> > expressions to restart when exhausted. This code works for generator
> > functions:
> >
> > class Regen(object):
> > """Optionally restart generator functions"""
> > def __init__(self, generator, options=None, restart=False):
> > self.gen = generator
>
> Your 'generator' parameter is actually a generator function -- a
> function that created a generator when called.
>
> > self.options = options
>
> Common practice would use 'args' instead of 'options'.
>
> > self.gen_call = generator(options)
>
> If the callable takes multiple args, you want '*options' (or *args)
> instead of 'options'.
>
> That aside, your 'gen_call' parameter is actually a generator -- a
> special type of iterator (uncallable object with __next__ (3.0) method).
>
> It is worthwhile keeping the nomenclature straight.  As you discovered,
> generator expressions create generators, not generator functions.  Other
> than being given the default .__name__ attribute '', there is
> otherwise nothing special about their result.  So I would not try to
> treat them specially.  Initializing a Regen instance with *any*
> generator (or other iterator) will fail.
>
> On the other hand, your Regen instances could be initialized with *any*
> callable that produces iterators, including iterator classes.  So you
> might as well call the parameters iter_func and iterator.
>
> In general, for all iterators and not just generators, reiteration
> requires a new iterator, either by duplicating the original or by saving
> the values in a list and iterating through that.
>

Thanks to all who replied for helping to clear up my various confusions on 
this subject. For now I'm content to formulate my iterators as generator 
function calls and I'll study the various approaches offered here. For now 
here's my attempt at a class that does what I want:

class Exgen(object):
"""works for generator functions"""
def __init__(self, iter_func, restart=False, *args):
self.iter_func = iter_func
self.args = args
self.iterator = iter_func(*args)
self.restart = restart
self._buffer = []
self._buff()

def __iter__(self):
return (self)

def __nonzero__(self):
if self._buffer:
return True
return False

def _buff(self, stop=1):
"""Store items in a list as required"""
for _ in range(stop - len(self._buffer)):
try:
self._buffer.append(self.iterator.next())
except StopIteration:
if self.restart:
self.iterator = self.iter_func(self.args)
self._buffer.append(self.iterator.next()) 
else:
break

def peek(self, start=0, stop=1):
"""See a slice of whats coming up"""
self._buff(stop)
return self._buffer[start:stop]

def next(self, start=0, stop=1):
"""Consume a slice"""
self._buff(stop)
if self._buffer:
result = self._buffer[start:stop]
self._buffer = self._buffer[:start] + self._buffer[stop:]
return result
else:
raise StopIteration

def clear(self):
"""Empty the buffer"""
self._buffer = []
self._buff()

Regards,

John
--
http://mail.python.org/mailman/listinfo/python-list


Python 2.6.1 urllib error on Mac os x PPC

2009-03-02 Thread Attila Soki
hi,

i trying to compile Python 2.6.1 on Mac OS X (ppc).
After configure/make/make install i test the compiled python with
the followig file (t.py) (example from 
http://docs.python.org/library/urllib.html):
-
import urllib
params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query";, params)
print f.read()
-

and i get this error:

python /tmp/t.py 
Traceback (most recent call last):
  File "/tmp/t.py", line 3, in 
f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query";, params)
  File "/usr/local/test/python/lib/python2.6/urllib.py", line 82, in urlopen
opener = FancyURLopener()
  File "/usr/local/test/python/lib/python2.6/urllib.py", line 611, in __init__
URLopener.__init__(self, *args, **kwargs)
  File "/usr/local/test/python/lib/python2.6/urllib.py", line 129, in __init__
proxies = getproxies()
  File "/usr/local/test/python/lib/python2.6/urllib.py", line 1555, in 
getproxies
return getproxies_environment() or getproxies_macosx_sysconf()
  File "/usr/local/test/python/lib/python2.6/urllib.py", line 1449, in 
getproxies_macosx_sysconf
_CFSetup(sc)
  File "/usr/local/test/python/lib/python2.6/urllib.py", line 1330, in _CFSetup
sc.CFStringCreateWithCString.argtypes = [ c_void_p, c_char_p, c_int32 ]
  File "/usr/local/test/python/lib/python2.6/ctypes/__init__.py", line 366, in 
__getattr__
func = self.__getitem__(name)
  File "/usr/local/test/python/lib/python2.6/ctypes/__init__.py", line 371, in 
__getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, CFStringCreateWithCString): symbol not found
Exception AttributeError: "FancyURLopener instance has no attribute 
'tempcache'" in > ignored


The same build works on Mac Os X with intel CPU without errors. MAC OS and 
developertools are the same on both Computer. 

Mac OS X: 10.5.6
Developertools: xcode311_2517
How i build it:

export MACOSX_DEPLOYMENT_TARGET=10.5
configure --prefix/usr/local/test/python
make
make install

How i test:

export 
PYTHONPATH=/usr/local/test/python:/usr/local/test/python/lib/python2.6/site-packages

/usr/local/test/python/bin/ is in the PATH

python /tmp/t.py



please help me to find out why this error occurs.



thanks,

Attila Soki

-- 
Pt! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: 
http://www.gmx.net/de/go/multimessenger01
--
http://mail.python.org/mailman/listinfo/python-list


Re: unziping a file in python..

2009-03-02 Thread MRAB

Luis Zarrabeitia wrote:

Quoting MRAB :

Steven D'Aprano wrote:

A quick and dirty solution would be something like this:

zf = zipfile.ZipFile('Archive.zip')
for name in zf.namelist():
open(name, 'w').write(zf.read(name))


You might want to specify an output folder (and the data might be binary
too):

zf = zipfile.ZipFile('Archive.zip')
for name in zf.namelist():
 open(os.path.join(output_folder, name), 'wb').write(zf.read(name))



Question here... wouldn't you also need to create all the intermediate folders
from "output_folder" to "output_folder/name" (assuming that 'name' has several
path parts in it)? Is there any elegant way to do it? 


Of course there is; this is Python! :-)

> (is there any way to make os.mkdir behave like mkdir -p?)
>

Perhaps:

zf = zipfile.ZipFile('Archive.zip')
for name in zf.namelist():
new_path = os.path.join(output_folder, name)
data = zf.read(name)
try:
open(new_path, 'wb').write(data)
except IOError:
# Create intermediate folders and try again
os.makedirs(os.path.dirname(new_path))
open(new_path, 'wb').write(data)
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's so wrong about execfile?

2009-03-02 Thread John Nagle

Carl Banks wrote:

On Feb 27, 7:21 pm, Sammo  wrote:

Given that execfile has been removed in py3k, I want to understand
exactly why.

Okay, I get that execfile is bad from the following thread:

On Jul 29 2007, 2:39 pm, Steven D'Aprano



 wrote:

(1) Don't use eval, exec or execfile.
(2) If you're an expert, don't use eval, exec or execfile.
(3) If you're an expert, and are fully aware of the security risks, don't
use eval, exec or execfile.
(4) If you're an expert, and are fully aware of the security risks, and
have a task that can only be solved by using eval, exec or execfile, find
another solution.
(5) If there really is no other solution, you haven't looked hard enough.
(6) If you've looked REALLY hard, and can't find another solution, AND
you're an expert and are fully aware of the security risks, THEN you can
think about using eval, exec or execfile.

What are some of the reasons why execfile should not be used?

What are some examples of cases where execfile is the correct way of
doing something?



[For instance, the package I use to generate my web site uses exec and
eval, because it processes templates with embedded Python code.  


   Now there's an example of exactly what exec and eval shouldn't be used for.

   You don't put general-purpose execution mechanisms into your web site
template system.  That's just asking for trouble.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: unziping a file in python..

2009-03-02 Thread Gabriel Genellina
En Mon, 02 Mar 2009 13:09:05 -0200, Luis Zarrabeitia   
escribió:

Quoting MRAB :

Steven D'Aprano wrote:
>
You might want to specify an output folder (and the data might be binary
too):

zf = zipfile.ZipFile('Archive.zip')
for name in zf.namelist():
 open(os.path.join(output_folder, name), 'wb').write(zf.read(name))



Question here... wouldn't you also need to create all the intermediate  
folders
from "output_folder" to "output_folder/name" (assuming that 'name' has  
several

path parts in it)? Is there any elegant way to do it?


Perhaps it would be easier to grab a copy of the 2.6 sources. extract()  
and extractall() are not so complex, but "the devil is in the details"



(is there any way to make os.mkdir behave like mkdir -p?)


if not os.path.isdir(d):
  os.makedirs(d)

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: What's so wrong about execfile?

2009-03-02 Thread Carl Banks
On Mar 2, 8:43 am, John Nagle  wrote:
> Carl Banks wrote:
> > On Feb 27, 7:21 pm, Sammo  wrote:
> >> Given that execfile has been removed in py3k, I want to understand
> >> exactly why.
>
> >> Okay, I get that execfile is bad from the following thread:
>
> >> On Jul 29 2007, 2:39 pm, Steven D'Aprano
>
> >>  wrote:
> >>> (1) Don't use eval, exec or execfile.
> >>> (2) If you're an expert, don't use eval, exec or execfile.
> >>> (3) If you're an expert, and are fully aware of the security risks, don't
> >>> use eval, exec or execfile.
> >>> (4) If you're an expert, and are fully aware of the security risks, and
> >>> have a task that can only be solved by using eval, exec or execfile, find
> >>> another solution.
> >>> (5) If there really is no other solution, you haven't looked hard enough.
> >>> (6) If you've looked REALLY hard, and can't find another solution, AND
> >>> you're an expert and are fully aware of the security risks, THEN you can
> >>> think about using eval, exec or execfile.
> >> What are some of the reasons why execfile should not be used?
>
> >> What are some examples of cases where execfile is the correct way of
> >> doing something?
>
> > [For instance, the package I use to generate my web site uses exec and
> > eval, because it processes templates with embedded Python code.  
>
>     Now there's an example of exactly what exec and eval shouldn't be used 
> for.
>
>     You don't put general-purpose execution mechanisms into your web site
> template system.  That's just asking for trouble.

It really isn't for a static web site generator with a single author,
which is what my package is for.


Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread Philip Semanchuk


On Mar 2, 2009, at 10:50 AM, John Machin wrote:


On Mar 3, 2:22 am, Philip Semanchuk  wrote:

See if you can successfully construct and send an email that says
"Hello world" in English/ASCII. If that works, change it to Arabic.  
If

that works, change the email format to HTML. If that works, starts
pulling the content from the database. If that works, then you're
done. =)


Yuk. You are asking him to write extra speculative code when he's
having extreme difficulty debugging the code he's already got! He's
already said he's getting ?? soon after the database retrieval ---
you want him to work on the downstream problem when the upstream is
still very muddy???


First of all, I preceded that paragraph with a detailed example of how  
to verify that he's getting what he expects out of the database. So  
no, I am not asking the OP to write extra speculative code. I'm giving  
him another tool with which to work at his problem.


He claims to have done what I asked him to do in the first place --  
break the problem into steps and verify the database steps. He says  
they're working OK. I chose to take him at his word.


If he's right, then we can move on to the next step of troubleshooting  
the email. If he's wrong and the problem is indeed with the database  
code, then we'll eventually discover that and he'll have learned a  
valuable lesson. It will be time-consuming and therefore painful for  
him, but then he'll be more likely to remember it.


There's more than one way to attack this problem/set of problems, yes?

This is all kind of OT since it is about general debugging and not  
about Python. The only Python-specific aspect I see is that debugging  
non-ASCII problems with print is a little tricky since it introduces  
yet another variable -- the terminal's encoding settings. If, for  
instance, the OP's terminal is set to ISO 8859-6 or some such (I don't  
know anything about encodings to handle Arabic) and he's feeding it  
UTF-8, then ??? might indeed be the result.



--
http://mail.python.org/mailman/listinfo/python-list


Re: executable

2009-03-02 Thread Gabriel Genellina
En Mon, 02 Mar 2009 13:24:20 -0200, toks teewey   
escribió:


I want to ask if it is possible to link a program written in python to a  
database


http://wiki.python.org/moin/DatabaseInterfaces


and also on how to make a program written in python executable.


http://wiki.python.org/moin/deployment
http://wiki.python.org/moin/DistributionUtilities
--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-02 Thread Terry Reedy

Paul Boddie wrote:

On 1 Mar, 15:20, Steve Holden  wrote:

Kless wrote:

Does anybody has seen the performance of Python 3?
Respect to speed it's the last language together to Ruby 1.8, but Ruby
1.9 has a lot of better performance. :(

I'm not sure what you think the speed of Ruby has to do with Python.


I imagine the author was contrasting the priorities of the developers
of each language implementation. Ruby 1.8 and earlier were regarded as
being very slow; Ruby 1.9 is faster because the developers have used
techniques similar to those employed in the CPython implementation.
Although one shouldn't extrapolate performance improvements from the
difference between two consecutive releases, one can observe that one
set of developers has prioritised performance (admittedly to remedy
deficiencies) while another set has prioritised features.


It seems to me that comparing the Py2.5/6 -- Py3.0 change to the 
Ruby1.8 -- Ruby1.9 change is a bit like comparing apples and oranges. 
The latter apparently was mostly a 'speed up existing features' change 
while the former was a 'make major features changes' release.  Changing 
Python's basic text model from extended ascii to unicode *is* a major 
change and one that is still being worked out.  Python has had speedup 
releases before and will again (3.1).  I presume Ruby has had and will 
have feature oriented releases.


All of this is about 'current phase of development' rather than the 
'priorities of the developers'.


It ignores 'performance of code writing and reading', which certain is 
at least a Python priority and strength.  For some people, the 3.0 
switch to unicode rather than just ascii identifiers already improves this.


tjr

--
http://mail.python.org/mailman/listinfo/python-list


Re: Email Program

2009-03-02 Thread Mike Driscoll
On Feb 28, 7:56 pm, J  wrote:
> Is it possible to make a GUI email program in Python that stores
> emails, composes, ect? Also, could I create my own programming
> language in Python? What are Pythons limits, or is this just a waste
> of my time to learn it.

The book, "Programming Python 3rd ed." by Lutz has a command-line and
a Tkinter-based GUI email program in it. I don't recall if it stored
emails or not, but that should be fairly trivial to add. I've written
a simple GUI program for sending emails via POP3, but haven't dug into
downloading or displaying emails on a server.

Mike
--
http://mail.python.org/mailman/listinfo/python-list


Re: Email Program

2009-03-02 Thread James Matthews
You can look at Digsby for an example of an email program.

On Mon, Mar 2, 2009 at 8:34 PM, Mike Driscoll  wrote:

> On Feb 28, 7:56 pm, J  wrote:
> > Is it possible to make a GUI email program in Python that stores
> > emails, composes, ect? Also, could I create my own programming
> > language in Python? What are Pythons limits, or is this just a waste
> > of my time to learn it.
>
> The book, "Programming Python 3rd ed." by Lutz has a command-line and
> a Tkinter-based GUI email program in it. I don't recall if it stored
> emails or not, but that should be fairly trivial to add. I've written
> a simple GUI program for sending emails via POP3, but haven't dug into
> downloading or displaying emails on a server.
>
> Mike
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.astorandblack.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: RichCompare and RichCompareBool

2009-03-02 Thread Terry Reedy

Aaron Brady wrote:

Hi,

In the source for 3.0.1, PyObject_RichCompareBool seems to perform an
extra check on identity that PyObjecct_RichCompare does not perform.


To me, the existence of two functions suggests that they are *intended* 
to act differently.


Here's the excerpt from RichCompareBool (line 612):

/* Quick result when objects are the same.
   Guarantees that identity implies equality. */
if (v == w) {
if (op == Py_EQ)
return 1;
else if (op == Py_NE)
return 0;
}

res = PyObject_RichCompare(v, w, op);

The code for PyObject_RichCompare does not contain this, it doesn't
seem.  Is it a bug?
--
http://mail.python.org/mailman/listinfo/python-list



--
http://mail.python.org/mailman/listinfo/python-list


How can I add space in to several numbers?

2009-03-02 Thread Bo Zhang
I want to parse a file and do this :

A  74.335 -86.474-129.317  1.00 54.12

then add space between -86.474 and -129.317. I can get the file with

A  74.335 -86.474 -129.317  1.00 54.12

How can I do this? Thanks.

--
Best regards,

Zhang Bo (Cindy)
SMA-CSB
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I add space in to several numbers?

2009-03-02 Thread Tim Chase

I want to parse a file and do this :

A  74.335 -86.474-129.317  1.00 54.12

then add space between -86.474 and -129.317. I can get the file with

A  74.335 -86.474 -129.317  1.00 54.12

How can I do this? Thanks.


Is there something wrong with the following?

  for line in file('in.txt'):
line = line.replace('-', ' -')
do_something(line)

calling line.split() on it will work the same way.  If not, you 
can use the regexp module to insert spaces between "a digit 
immediately followed by a dash":


  >>> s  = "A  74.335 -86.474-129.317  1.00 54.12"
  >>> s.replace('-', ' -')
  'A  74.335  -86.474 -129.317  1.00 54.12'
  >>> import re
  >>> r = re.compile(r'(\d)-')
  >>> r.sub(r'\1 -', s)
  'A  74.335 -86.474 -129.317  1.00 54.12'


-tkc




--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I add space in to several numbers?

2009-03-02 Thread Gabriel Genellina
En Mon, 02 Mar 2009 17:58:01 -0200, Bo Zhang   
escribió:



I want to parse a file and do this :

A  74.335 -86.474-129.317  1.00 54.12

then add space between -86.474 and -129.317. I can get the file with

A  74.335 -86.474 -129.317  1.00 54.12


Use a regular expression:

py> import re
py> line = "A  74.335 -86.474-129.317  1.00 54.12"
py> re.sub(r"(\d)-(\d)", r"\1 -\2", line)
'A  74.335 -86.474 -129.317  1.00 54.12'

You many require r"(\d)-([\d\.])" if a number is allowed to start with a  
decimal point.


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Email Program

2009-03-02 Thread Wayne Cannon
The Twisted package (http://twistedmatrix.com/) has some examples of 
interacting with e-mail servers.  Twisted supports interaction between 
asynchronous tasks.  --Wayne


J wrote:

Is it possible to make a GUI email program in Python that stores
emails, composes, ect?

--
http://mail.python.org/mailman/listinfo/python-list


Re: Email Program

2009-03-02 Thread James Matthews
There is always the issue of packaging at the end but Python is your
programming language.

On Mon, Mar 2, 2009 at 10:19 PM, Wayne Cannon  wrote:

> The Twisted package (http://twistedmatrix.com/) has some examples of
> interacting with e-mail servers.  Twisted supports interaction between
> asynchronous tasks.  --Wayne
>
>
> J wrote:
>
>> Is it possible to make a GUI email program in Python that stores
>> emails, composes, ect?
>>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.goldwatches.com/

http://www.jewelerslounge.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Email Program

2009-03-02 Thread Tino Wildenhain

Hi,

Dennis Lee Bieber wrote:

On Sat, 28 Feb 2009 17:50:35 -0800 (PST), J 
declaimed the following in gmane.comp.python.general:


Is it possible to make a GUI email program in Python that stores
emails, composes, ect?


What is "ect"? The latin phrase is "et cetera" -- roughly
translated: and so forth -- and commonly abbreviated as "etc." (with the
common period denoting an abbreviation )

As for a GUI email program... Define the requirements in more
detail... But it is possible... Though I've never needed to -- my email
client programs have always been acceptable, whereas the mail transfer
agents have sometimes been a flop.


Oh I personally think even existing MUAs could be improved. I even
pondered writing a own version in python (If I only could settle
on a GUI lib ;)


Of course, one has to go back to the early days of public Internet
access... When a mail client only read mail from a LOCAL (ie, on the
same machine) mailbox; and spooled mail into a local spool directory.
Mail transfer agents were responsible for pulling mail down from POP3
ISP mailboxes, and for sending via SMTP.


Not necessarily - python has everything (SMTP, IMAP(S), even POP)
included as well and with the help of pgcrypto even smime and friends
should be doable.


My first real Python program -- written with the Amiga version of
Python 1.4 -- was a rudimentary Sendmail daemon, which would take
messages from a local spool directory, connect to my ISPs SMTPd, relay
all the address, then send the body of the message. I wrote this within
a week of discovering Python via the first books available. And I wrote
this as my previous, downloaded, MTAs had severe faults -- the first
properly handled TO, CC, and BCC, but relied upon connecting directly to
the destination address for each recipient, and would hang up the entire
spool if given an address that could not be connected; the second worked
as most current clients, by relaying via one's own ISP... but it totally
ignored BCC and CC addresses!


Ha! I did something the other way round but not with python but with
AREXX those days. It was an SMTPD to accept forwarded mail and spool
directly into YAM (that if someone on the other end of the world has
hit "send" it was immediately rattling in my inbox :-)

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Email Program

2009-03-02 Thread Mike Driscoll
Hi James,

On Mon, Mar 2, 2009 at 12:41 PM, James Matthews  wrote:
> You can look at Digsby for an example of an email program.


I've followed Digsby for a while, but it's an instant messenger /
social network aggregator, not an email client. It's much like a fancy
Pidgin and it's not open source, so I don't see how I can "take a
look" at it.

The developers for Digsby announced it on the wxPython list for some
reason, so I was a little disappointed when the source was
unavailable.

Mike


>
> On Mon, Mar 2, 2009 at 8:34 PM, Mike Driscoll  wrote:
>>
>> On Feb 28, 7:56 pm, J  wrote:
>> > Is it possible to make a GUI email program in Python that stores
>> > emails, composes, ect? Also, could I create my own programming
>> > language in Python? What are Pythons limits, or is this just a waste
>> > of my time to learn it.
>>
>> The book, "Programming Python 3rd ed." by Lutz has a command-line and
>> a Tkinter-based GUI email program in it. I don't recall if it stored
>> emails or not, but that should be fairly trivial to add. I've written
>> a simple GUI program for sending emails via POP3, but haven't dug into
>> downloading or displaying emails on a server.
>>
>> Mike
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
>
> --
> http://www.astorandblack.com
>
--
http://mail.python.org/mailman/listinfo/python-list


New User - Using tutorial and Docs - POST returns 302 Found

2009-03-02 Thread JohnV
I am using Python 2.5 r25:51908 MSC v.1318 32 bit (Intel) on wind32

I am totally new to Python and started yesterday going over a couple
of examples I found in the documentation which address a problem I am
trying to solve.

I have successfully opened a file and read the results adapting this
code snippit:

>>> f = open('/tmp/workfile', 'w')
>>> print f

>>> f.read()
'This is the entire file.\n'
>>> f.close()


Then I tried to POST something to a cgi sytle script on my test
website.  Below is the code I used, I type it in one line at time to
make sure I am doing it correctly.  I am confused about how to format
several of the lines in the below script.

on the params line the name / value pair I want to send is name =
'textarea1' value = 0
on the conn line I put "thenational.us' as the domain
on the conn.request line I put the web path to the html page
(getpost.html) that processes the POST

The data is not being posted to the webpage. Concerning the
conn.request line, "/pages/" is what I call the cgi-bin directory,
"start" is the name of the cgi script I use (no ext), "/test/
getpost.html" is the web path to the page that accepts the POST.  I do
not use GET because the data will be several k or larger in size when
I get it all working correctly.

>>> import httplib, urllib
>>> params = urllib.urlencode({'textarea1': 0})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
..."Accept": "text/plain"}
>>> conn = httplib.HTTPConnection("thenational.us:80")
>>> conn.request("POST", "/pages/start/test/getpost.html", params, headers)
>>> response = conn.getresponse()
>>> print response.status, response.reason
302 Found
>>> data = response.read()
>>> conn.close()



My project I want to learn how to do is; I have data coming from an
external device over a com port that I manually download and save to a
file on my home computer with the manufacturer's software.  I then
want to move that data to my webserver where others can view the data
from a webpage.  My goal is to open a file on my home computer and
load the contents of that file to my website where I will store the
data and display it.  I could just copy the file to the webserver that
would accomplish the same thing as posting it as a var and saving that
to a file on the server.  Howerver, I am trying to automate the
process as much as possible with Python as when an event is happening,
new data is coming in over a period of seveal hour from the external
device over the com port.

Is there a better solution than POST
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I add space in to several numbers?

2009-03-02 Thread MRAB

Gabriel Genellina wrote:
En Mon, 02 Mar 2009 17:58:01 -0200, Bo Zhang  
escribió:



I want to parse a file and do this :

A  74.335 -86.474-129.317  1.00 54.12

then add space between -86.474 and -129.317. I can get the file with

A  74.335 -86.474 -129.317  1.00 54.12


Use a regular expression:

py> import re
py> line = "A  74.335 -86.474-129.317  1.00 54.12"
py> re.sub(r"(\d)-(\d)", r"\1 -\2", line)
'A  74.335 -86.474 -129.317  1.00 54.12'

You many require r"(\d)-([\d\.])" if a number is allowed to start with a 
decimal point.



It probably doesn't matter what comes after the '-':

re.sub(r"(\d)-", r"\1 -", line)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I add space in to several numbers?

2009-03-02 Thread Gabriel Genellina
En Mon, 02 Mar 2009 19:08:04 -0200, MRAB   
escribió:

Gabriel Genellina wrote:
En Mon, 02 Mar 2009 17:58:01 -0200, Bo Zhang   
escribió:



I want to parse a file and do this :

A  74.335 -86.474-129.317  1.00 54.12

then add space between -86.474 and -129.317. I can get the file with

A  74.335 -86.474 -129.317  1.00 54.12

 Use a regular expression:
 py> import re
py> line = "A  74.335 -86.474-129.317  1.00 54.12"
py> re.sub(r"(\d)-(\d)", r"\1 -\2", line)
'A  74.335 -86.474 -129.317  1.00 54.12'
 You many require r"(\d)-([\d\.])" if a number is allowed to start with  
a decimal point.



It probably doesn't matter what comes after the '-':

 re.sub(r"(\d)-", r"\1 -", line)


Yes, that's better.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: handling multiple software repositories

2009-03-02 Thread Ferran . Jorba
We are happy users of DrProject 1.2 with SQLite and scgi.  It works
very well for our purposes, not exactly software development, but just
for tracking our tasks and documentation, several projects, single
login, different roles for each users, clean urls.

The only trouble I have with it is that I understand that the last
official stable release is this 1.2 (or 1.2.1, according to the
Subversion tags), and then there is some confusing movements with a
2.0-dev, an 3.0-dev and this Django rewrite called Basie.  We don't
know exactly which will be our migration path, but we hope we can
follow them.

Ferran
--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-02 Thread Isaac Gouy
On Mar 2, 12:02 am, Stefan Behnel  wrote:
> Isaac Gouy wrote:
> > On Mar 1, 11:24 am, Stefan Behnel wrote:
> >> Isaac Gouy wrote:
> >>> On Mar 1, 8:10 am, Stefan Behnel wrote:
>  As long as that gives you improvements of
>  100-1000 times almost for free, I wouldn't bother too much with changing
>  the platform just because someone shows me benchmark results of some code
>  that I absolutely don't need in my daily work.
> >>> What examples do you have of 1000x improvement?
> >> We hear that from time to time on the Cython mailing list. Here's a recent
> >> example of a user who reported an 80 times speed-up before we helped in
> >> getting the code straight, which brought another factor of 20.
>
> >>http://permalink.gmane.org/gmane.comp.python.cython.devel/4619
>
> >> Speed-ups in the order of several hundred times are not uncommon for
> >> computing intensive tasks and large data sets when you move from Python to
> >> Cython, as it generates very optimised C code.
>
> >> Stefan
>
> > "Now only the def line and the return line are using Python..." ;-)
>
> So? I did see your smiley, but I hope you are not trying to make a point
> here. If you look at the code (especially in this case, it might be more
> C-ish in others), you will see that it's Python. It just gets translated to
> very fast C code. Cython even has a "pure Python" mode where you can let
> your code run in ordinary Python and have Cython compile it if you feel
> like it. That gives you the best of both worlds: readable, easy to maintain
> code, that you can compile to C speed when you need high performance.
>
> Coming back to the original topic of this thread, when I look at the code
> examples that are compared here, I wouldn't be surprised if Cython could
> compile them to a faster executable straight away, without modification.
> Just install Cython 0.11 (which is close to release) and add
>
>     import pyximport; pyximport.install(pyimport=True)
>
> before importing the benchmarked module. If you want more performance than
> what plain compilation gives you by itself, just add a few type
> declarations. You can use Python decorators for that, if you prefer keeping
> a standard Python program.


I think it would be silly to dispute whether or not programs that have
import psyco; psyco.bind are Python programs.

I'm not sure it would be equally silly to dispute whether or not
programs with type declarations have moved away from being Python
programs.

Of course, Cython is still kind-of neat.

--
http://mail.python.org/mailman/listinfo/python-list


RE: file locking...

2009-03-02 Thread Lawrence D'Oliveiro
In message , bruce 
wrote:

> my concern about a "gatekeeper" wasn't so much related to performance, as
> the possibility of race conditions... 

Which is what the gatekeeper will prevent. It serializes the granting of 
locks, and that means no race conditions.

--
http://mail.python.org/mailman/listinfo/python-list


Upgrade Python on a Mac

2009-03-02 Thread Rey Bango
Hi,

I'd like to upgrade the installed version of Python that came standard
on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot
in it, I just wanted to get a better understanding of the process.

If I download the disk image installer from here: 
http://www.python.org/download/
will it allow me to upgrade my existing version or is it more involved
(eg: making a new build).

I've looked through the python.org page for upgrade instructions for a
Mac and haven't found it.

Any help would be appreciated.

Rey...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-02 Thread andrew cooke
Isaac Gouy wrote:
[...]
> I think it would be silly to dispute whether or not programs that have
> import psyco; psyco.bind are Python programs.
>
> I'm not sure it would be equally silly to dispute whether or not
> programs with type declarations have moved away from being Python
> programs.

i don't have any horse in this race (although i would like the standard
implementation to be as fast as possible), but it may be worth mentioning
that annotations on parameters are available (python 2.6 and 3.0).  those,
along with abcs (same versions) suggests someone, somewhere, might be
wondering about how to introduce optional type declarations in python one
day...

it would also be nice if pypy could actually produce a final, compliant,
fully featured implementation.  that (via llvm?) may be the best way to
introduce the kind of adaptive optimisations that java has made so much
mileage from.  but i'm just stabbing in the dark - their exact status is a
bit opaque to me.

andrew


--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6.1 urllib error on Mac os x PPC

2009-03-02 Thread Ned Deily
In article <20090302161256.120...@gmx.net>,
 "Attila Soki"  wrote:
> i trying to compile Python 2.6.1 on Mac OS X (ppc).
> After configure/make/make install i test the compiled python with
> the followig file (t.py) (example from 
> http://docs.python.org/library/urllib.html):
> -
> import urllib
> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query";, params)
> print f.read()
> -
> 
> and i get this error:
> 
> python /tmp/t.py 
> Traceback (most recent call last):
>   File "/tmp/t.py", line 3, in 
> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query";, params)
>   File "/usr/local/test/python/lib/python2.6/urllib.py", line 82, in urlopen
> opener = FancyURLopener()
>   File "/usr/local/test/python/lib/python2.6/urllib.py", line 611, in 
>   __init__
> URLopener.__init__(self, *args, **kwargs)
>   File "/usr/local/test/python/lib/python2.6/urllib.py", line 129, in 
>   __init__
> proxies = getproxies()
>   File "/usr/local/test/python/lib/python2.6/urllib.py", line 1555, in 
>   getproxies
> return getproxies_environment() or getproxies_macosx_sysconf()
>   File "/usr/local/test/python/lib/python2.6/urllib.py", line 1449, in 
>   getproxies_macosx_sysconf
> _CFSetup(sc)
>   File "/usr/local/test/python/lib/python2.6/urllib.py", line 1330, in 
>   _CFSetup
> sc.CFStringCreateWithCString.argtypes = [ c_void_p, c_char_p, c_int32 ]
>   File "/usr/local/test/python/lib/python2.6/ctypes/__init__.py", line 366, 
>   in __getattr__
> func = self.__getitem__(name)
>   File "/usr/local/test/python/lib/python2.6/ctypes/__init__.py", line 371, 
>   in __getitem__
> func = self._FuncPtr((name_or_ordinal, self))
> AttributeError: dlsym(RTLD_DEFAULT, CFStringCreateWithCString): symbol not 
> found
> Exception AttributeError: "FancyURLopener instance has no attribute 
> 'tempcache'" in  > ignored
> 
> 
> The same build works on Mac Os X with intel CPU without errors. MAC OS and 
> developertools are the same on both Computer.
> 
> Mac OS X: 10.5.6
> Developertools: xcode311_2517
> How i build it:
> 
> export MACOSX_DEPLOYMENT_TARGET=10.5
> configure --prefix/usr/local/test/python
> make
> make install
> 
> How i test:
> 
> export 
> PYTHONPATH=/usr/local/test/python:/usr/local/test/python/lib/python2.6/site-pa
> ckages
> 
> /usr/local/test/python/bin/ is in the PATH
> 
> python /tmp/t.py

I'm not able to reproduce the problem building a similar configuration 
on a ppc G4 other than using Developer Tools 3.1.2.  There is also no 
problem when using 2.6.1 from the python.org OS X installer.  The test 
seems pretty basic.

A few things to try:

First, make sure this is the real problem by trying this snippet:

/usr/local/test/python/bin/python2.6
>>> from ctypes import cdll
>>> from ctypes.util import find_library
>>> sc = cdll.LoadLibrary(find_library("SystemConfiguration"))
>>> x = sc.CFStringCreateWithCString(0, "HTTPEnable", 0)

Presumably, if your original test failed, this snippet should fail, too.

If you can, download the python.org 2.6.1 OSX installer and make sure 
your original test works with it.  If so, perhaps you don't need to 
build your own?  That install works on both Intel and PPC.  One 
difference: it is built with MACOX_DEPLOYMENT_TARGET=10.3, meaning it 
will work on systems >= 10.3 but if you really need 10.5 only there 
might be some side-effects that are important to you.

Otherwise, you might want to try rebuilding on the PPC from scratch 
(i.e. an empty build directory) using the 2.6.1 tarball.  By "same 
build" on Intel CPU, you do mean you've rebuilt on PPC?  You could build 
a "fat" Universal python on either architecture that will work on both 
but you'll need to add a few more options to configure to do that.

-- 
 Ned Deily,
 n...@acm.org

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python parser

2009-03-02 Thread Clarendon
Thank you, Lie and Andrew for your help.

I have studied NLTK quite closely but its parsers seem to be only for
demo. It has a very limited grammar set, and even a parser that is
supposed to be "large" does not have enough grammar to cover common
words like "I".

I need to parse a large amount of texts collected from the web (around
a couple hundred sentences at a time) very quickly, so I need a parser
with a broad scope of grammar, enough to cover all these texts. This
is what I mean by 'random'.

An advanced programmer has advised me that Python is rather slow in
processing large data, and so there are not many parsers written in
Python. He recommends that I use Jython to use parsers written in
Java. What are your views about this?

Thank you very much.



--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-02 Thread Wes James
On Mon, Mar 2, 2009 at 2:53 PM, Rey Bango  wrote:
> Hi,
>
> I'd like to upgrade the installed version of Python that came standard
> on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot
> in it, I just wanted to get a better understanding of the process.

I'd recommend you put your new versions in to /usr/local

Leave the OS X one alone.

-wj
--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-02 Thread Ned Deily
In article 
<50ca1bd0-b8d5-478c-aeaf-dd2b83187...@j38g2000yqa.googlegroups.com>,
 Rey Bango  wrote:
> I'd like to upgrade the installed version of Python that came standard
> on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot
> in it, I just wanted to get a better understanding of the process.
> 
> If I download the disk image installer from here: 
> http://www.python.org/download/
> will it allow me to upgrade my existing version or is it more involved
> (eg: making a new build).
> 
> I've looked through the python.org page for upgrade instructions for a
> Mac and haven't found it.

The python.org OS X installers install a self-contained version of 
python for each major version of python, i.e. the 2.6.x installers 
install or upgrade python2.6, 3.0.x -> python3.0.  They do not interfere 
with or disturb the Apple-supplied 2.5.x version.  Multiple versions of 
python can co-exist on OS X.  See, for instance:


-- 
 Ned Deily,
 n...@acm.org

--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-02 Thread Kevin Walzer

Rey Bango wrote:

Hi,

I'd like to upgrade the installed version of Python that came standard
on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot
in it, I just wanted to get a better understanding of the process.

If I download the disk image installer from here: 
http://www.python.org/download/
will it allow me to upgrade my existing version or is it more involved
(eg: making a new build).

I've looked through the python.org page for upgrade instructions for a
Mac and haven't found it.

Any help would be appreciated.

Rey...


The Python.og installer will not update the system version of Python 
installed on the Mac--that's maintained by Apple and should not be 
touched. Instead, the installer will put in a new version alongside the 
Apple version.


--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: New User - Using tutorial and Docs - POST returns 302 Found

2009-03-02 Thread JohnV
Here is what var data collected:


302 Found

Found
The document has moved http://www.thenational.us/pages/
htmlos/001863.1.059070780420726458">here.

Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8b mod_mono/
2.2 FrontPage/5.0.2.2635 mod_bwlimited/1.4 mod_auth_passthrough/2.1
Server at thenational.us Port 80

--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-02 Thread MRAB

Rey Bango wrote:

Hi,

I'd like to upgrade the installed version of Python that came standard
on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot
in it, I just wanted to get a better understanding of the process.

If I download the disk image installer from here: 
http://www.python.org/download/
will it allow me to upgrade my existing version or is it more involved
(eg: making a new build).

I've looked through the python.org page for upgrade instructions for a
Mac and haven't found it.

Any help would be appreciated.


The current recommendation is 2.x until 3.x has reached 3.1, unless you
want to try out 3.0.1 so you're ready for when 3.1 arrives.
--
http://mail.python.org/mailman/listinfo/python-list


People working in AI using Python

2009-03-02 Thread tleeuwenb...@gmail.com
Hi all,

I work on a natural language generation system for weather
forecasting, using Python. I would like to find out if there is an
active Python AI SIG or whether there is sufficient interest in
forming one.

Please email me offline (tleeuwenb...@gmail.com) if you're interested
in touching base on this topic.

Regards,
-Tennessee
--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-02 Thread John Machin
On Mar 3, 3:27 am, Philip Semanchuk  wrote:
> On Mar 2, 2009, at 10:50 AM, John Machin wrote:
>
> > On Mar 3, 2:22 am, Philip Semanchuk  wrote:
> >> See if you can successfully construct and send an email that says
> >> "Hello world" in English/ASCII. If that works, change it to Arabic.  
> >> If
> >> that works, change the email format to HTML. If that works, starts
> >> pulling the content from the database. If that works, then you're
> >> done. =)
>
> > Yuk. You are asking him to write extra speculative code when he's
> > having extreme difficulty debugging the code he's already got! He's
> > already said he's getting ?? soon after the database retrieval ---
> > you want him to work on the downstream problem when the upstream is
> > still very muddy???
>
> First of all, I preceded that paragraph with a detailed example of how  
> to verify that he's getting what he expects out of the database. So  
> no, I am not asking the OP to write extra speculative code. I'm giving  
> him another tool with which to work at his problem.
>
> He claims to have done what I asked him to do in the first place --  
> break the problem into steps and verify the database steps. He says  
> they're working OK. I chose to take him at his word.

Rule number 1: Don't believe anything an OP says that is not
corroborated by output that looks like it was produced using the repr
() function (2.x) or ascii() function (3.x)

Rule number 2: Don't ignore rule number 1, especially when not
corroborated by any output at all.

Rule number 3: [added since the Great Renaming aka the Mad Hatter's
Tea Party] Ask the OP what version of Python they are using so that
they can be told to use ascii() instead of repr() if using 3.X

>
> If he's right, then we can move on to the next step of troubleshooting  
> the email. If he's wrong and the problem is indeed with the database  
> code, then we'll eventually discover that

He has *already* demonstrated, at my request, that there is a problem
with, or soon after, the database extraction:

"""
The result of print repr(row['name']) is '??? ??'
The '?' characters are supposed to be Arabic characters.
"""

> and he'll have learned a  
> valuable lesson. It will be time-consuming and therefore painful for  
> him, but then he'll be more likely to remember it.
>
> There's more than one way to attack this problem/set of problems, yes?
>
> This is all kind of OT since it is about general debugging and not  
> about Python. The only Python-specific aspect I see is that debugging  
> non-ASCII problems with print is a little tricky since it introduces  
> yet another variable -- the terminal's encoding settings. If, for  
> instance, the OP's terminal is set to ISO 8859-6 or some such (I don't  
> know anything about encodings to handle Arabic) and he's feeding it  
> UTF-8, then ??? might indeed be the result.

and that is the rationale for Rule #1

--
http://mail.python.org/mailman/listinfo/python-list


HTTPError... read the response body?

2009-03-02 Thread Stuart Davenport
Hi There,

I am trying to connect to a web service but I am getting HTTP 400, I
am not too concerned about the HTTP error - but what I'd like to know
if there is anyway I can read the response body in the HTTP 400 or 500
case? Does the HTTPError allow this? or the urllib2 in anyway?

This is what I have at the moment...

import sys, urllib2
import socket

class APIConnector:
def connect(*args):
length = len(args[2])
headers = {"Content-Length": length, "Content-Type":
"text/xml", "SOAPAction": "\"http://some.api.com/RemovedAction\""}

try:
#url, body, headers
rq = urllib2.Request(args[1], args[3],
headers)
rs = urllib2.urlopen(rq)

print rs.read()
except urllib2.HTTPError, e:
conn = e
print 'error', conn.code, 'message: ',
conn.msg, 'filename: ', conn.filename, 'headers: ', conn.hdrs, 'body:
', conn.read()

I thought that conn.read() may show the body, but it seems not... Can
anyone help please, or suggest another way around? I am using python
2.5 installed with MAC OS X Leopard.


Cheers
Stu
--
http://mail.python.org/mailman/listinfo/python-list


Re: unziping a file in python..

2009-03-02 Thread David Lyon


On Mon, 02 Mar 2009 16:13:39 +, MRAB 
wrote:

> zf = zipfile.ZipFile('Archive.zip')
> for name in zf.namelist():
>  new_path = os.path.join(output_folder, name)
>  data = zf.read(name)
>  try:
>  open(new_path, 'wb').write(data)
>  except IOError:
>  # Create intermediate folders and try again
>  os.makedirs(os.path.dirname(new_path))
>  open(new_path, 'wb').write(data)
> --

Oh thanks for that...

Seems like the answer that i was looking for

Thank you very much...

(It's a 10 liner - I can live with that)

David

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python parser

2009-03-02 Thread Robert Kern

On 2009-03-02 16:14, Clarendon wrote:

Thank you, Lie and Andrew for your help.

I have studied NLTK quite closely but its parsers seem to be only for
demo. It has a very limited grammar set, and even a parser that is
supposed to be "large" does not have enough grammar to cover common
words like "I".

I need to parse a large amount of texts collected from the web (around
a couple hundred sentences at a time) very quickly, so I need a parser
with a broad scope of grammar, enough to cover all these texts. This
is what I mean by 'random'.

An advanced programmer has advised me that Python is rather slow in
processing large data, and so there are not many parsers written in
Python. He recommends that I use Jython to use parsers written in
Java. What are your views about this?


Let me clarify your request: you are asking for a parser of the English 
language, yes? Not just parsers in general? Not many English-language parsers 
are written in *any* language.


AFAIK, there is no English-language parser written in Python beyond those 
available in NLTK. There are probably none (in any language) which will robustly 
parse all of the grammatically correct English texts you will encounter by 
scraping the web, much less all of the incorrect English you will encounter.


Python can be rather slow for certain kinds of processing of large volumes (and 
really quite speedy for others). In this case, it's neither here nor there; the 
algorithms are reasonably slow in any language.


You may try your luck with link-grammar, which is implemented in C:

  http://www.abisource.com/projects/link-grammar/

Or The Stanford Parser, implemented in Java:

  http://nlp.stanford.edu/software/lex-parser.shtml

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-02 Thread Rey Bango
Thank you Kevin (& all who replied). The next question (which I think
will be my last until I've read more info) is:

Once installed, how will I be able to distinguish between the OSX
Apple-supplied, preinstalled version and the newly installed version
that I downloaded from Python.org? Currently, when I go to Terminal
and type in Python, it gives me the Apple-supplied variant. Will I
need to adjust my environment settings to be able to work with the
newly installed version?

Rey...

On Mar 2, 5:15 pm, Kevin Walzer  wrote:
>
> The Python.og installer will not update the system version of Python
> installed on the Mac--that's maintained by Apple and should not be
> touched. Instead, the installer will put in a new version alongside the
> Apple version.
>
> --Kevin
>
> --
> Kevin Walzer
> Code by Kevinhttp://www.codebykevin.com

--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-02 Thread Robert Kern

On 2009-03-02 17:06, Rey Bango wrote:

Thank you Kevin (&  all who replied). The next question (which I think
will be my last until I've read more info) is:

Once installed, how will I be able to distinguish between the OSX
Apple-supplied, preinstalled version and the newly installed version
that I downloaded from Python.org? Currently, when I go to Terminal
and type in Python, it gives me the Apple-supplied variant. Will I
need to adjust my environment settings to be able to work with the
newly installed version?


The installer should update your $PATH environment variable to put the newly 
installed python executable before the system's if you use the bash shell. For 
example, it added this to my ~/.bash_profile file:


# Setting PATH for MacPython 2.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH


If you use a different shell, you may need to edit the appropriate file to add 
the above to the $PATH.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


ActivePython or Python from Python.org

2009-03-02 Thread Rey Bango
Hi everyone. I noticed that ActiveState has their own variation of
Python and was curious if there's a benefit to choosing their version
over the version offered via Python.org.

Could someone lend some insight?

Thanks,

Rey...
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTTPError... read the response body?

2009-03-02 Thread Wojtek Walczak
On Mon, 2 Mar 2009 14:29:12 -0800 (PST), Stuart Davenport wrote:

Hi,

> I am trying to connect to a web service but I am getting HTTP 400, I
> am not too concerned about the HTTP error - but what I'd like to know
> if there is anyway I can read the response body in the HTTP 400 or 500
> case? Does the HTTPError allow this? or the urllib2 in anyway?

HTTP error 400 means 'bad request', so it's almost certainly
your mistake.


> #url, body, headers
> rq = urllib2.Request(args[1], args[3], headers)

Is args[1] a valid URL? And are you sure that you want to send
something to the web serwer? By specifying the second argument
(args[3]) you're asking python to send HTTP "POST" request,
not "GET".

-- 
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
--
http://mail.python.org/mailman/listinfo/python-list


Re: ActivePython or Python from Python.org

2009-03-02 Thread Trent Mick

Rey Bango wrote:

Hi everyone. I noticed that ActiveState has their own variation of
Python and was curious if there's a benefit to choosing their version
over the version offered via Python.org.

Could someone lend some insight?


Here is some reasoning I wrote a while back:

http://mail.python.org/pipermail/python-list/2007-July/447987.html


Cheers,
Trent

--
Trent Mick
trentm at activestate.com
--
http://mail.python.org/mailman/listinfo/python-list


getting all HTTP headers from urllib2 Request?

2009-03-02 Thread cgoldberg
I have a Python web client that uses urllib2.  It is easy enough to
add my own HTTP headers to the outgoing requests. I just create a
dictionary of the headers I want to add, and pass it to the Request
initializer.

These custom headers are not all that gets sent.  urllib2 attaches
headers also.  You can view the headers that urrlib2 adds by looking
at unredirected_hdrs.

However, these aren't the only HTTP headers that get sent on the
wire.  Other standard HTTP headers get added to outgoing requests as
well as the custom ones I explicitly add and urllib2 adds. When I
sniff the request using Wireshark, I see headers besides the ones I
added myself.

My question is how do a I get access to *all* of these headers?  I
want to log every request (including the full set of HTTP headers that
get sent) that gets sent from my program, and can't figure out how.
any pointers?

In a nutshell: How do I get *all* the outgoing headers from an HTTP
request created by urllib2?


- Corey Goldberg


--
http://mail.python.org/mailman/listinfo/python-list


Re: Python parser

2009-03-02 Thread andrew cooke
Clarendon wrote:
[...]
> I need to parse a large amount of texts collected from the web (around
> a couple hundred sentences at a time) very quickly, so I need a parser
> with a broad scope of grammar, enough to cover all these texts. This
> is what I mean by 'random'.

so the most important things are that (1) the grammar be as large as
possible and (2) the parser be as fast as possible.  for something that
specific i would suggest you start by looking at what solutions exist for
*any* programming language and then choosing from what you find.

in short: you should be asking "natural language parsing people" and not
"python people".

sorry i can't be more help,
andrew


--
http://mail.python.org/mailman/listinfo/python-list


Attribute error-- but I'm innocent(?)

2009-03-02 Thread Nick Mellor
Hi all,

I'm pretty sure I'm following all the Python rules: I've put "self"
before "forename" to make sure it's treated as a data attribute
(instance variable.) And from within a class, I'm told, you need to
prefix the var with self too. RandomName is a class that I've tested
(and which still works.) So why do I get this error?

  File "h:\Testing\NameDb\dictfile.py", line 107, in randomName
return {"Forename" : self.forename.randomByWeight(),
AttributeError: RandomPerson instance has no attribute 'forename'

Here's the code (Python 2.6, PythonWin):

class RandomPerson:
def __init(self):
self.forename = RandomName("h:\\Testing\\NameDb\
\Forenames.csv", namefield = "Forename")
self.surname = RandomName("h:\\Testing\\NameDb\\Surnames.csv",
namefield = "Surname")
self.randomAddress = dictfile("h:\\Testing\\NameDb\
\Addresses.csv").cycleShuffled()
[...]

def randomName(self):
return {"Forename" : self.forename.randomByWeight(),
"Surname" : self.surname.randomByWeight()}

if __name__ == "__main__":
person = RandomPerson()
print person.randomName()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Attribute error-- but I'm innocent(?)

2009-03-02 Thread Chris Rebert
On Mon, Mar 2, 2009 at 4:56 PM, Nick Mellor
 wrote:
> Hi all,
>
> I'm pretty sure I'm following all the Python rules: I've put "self"
> before "forename" to make sure it's treated as a data attribute
> (instance variable.) And from within a class, I'm told, you need to
> prefix the var with self too. RandomName is a class that I've tested
> (and which still works.) So why do I get this error?
>
>  File "h:\Testing\NameDb\dictfile.py", line 107, in randomName
>    return {"Forename" : self.forename.randomByWeight(),
> AttributeError: RandomPerson instance has no attribute 'forename'
>
> Here's the code (Python 2.6, PythonWin):
>
> class RandomPerson:
>    def __init(self):

That previous line is supposed to be:
   def __init__(self):

Note the trailing underscores.

Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: New User - Using tutorial and Docs - POST returns 302 Found

2009-03-02 Thread JohnV
I got it!  You can see the code at the bottom of this post.  Sorry for
three posts on this question.

I have to run the program one time just to get the dynamically
generated redirect URL for the POST (it looks like this)
The document has moved http://www.thenational.us/pages/htmlos/
001863.1.059070780420726458">

I then paste the redirected URL ("http://www.thenational.us/pages/
htmlos/001863.1.059070780420726458) into the script and run it again
and it works.

My question now is how do I bypass this manual step and grab the
redirect URL automatically without human intervention.  In other
words, how do I get the python script to find out what the redirect
URL is going to be (it is dynamic and times out after 50 minutes if
idle) and automatically update the script with the redirect URL?

Also, I was able to figured out how to open a file and send the data
so almost all my work is done, excect for this pesky URL redirect on
the POST.

f = open('C:\Users\Owner\Desktop\mydata.txt', 'r')
read_data = f.read()

f.close()

import httplib, urllib
params = urllib.urlencode({'textarea1': read_data})
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = httplib.HTTPConnection("thenational.us:80")
conn.request("POST", "/pages/htmlos/001863.5.083914970120726458",
params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()

f = open('C:\Users\Owner\Desktop\pydata.txt', 'a')
f.write(data)
f.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Attribute error-- but I'm innocent(?)

2009-03-02 Thread John Machin
On Mar 3, 11:56 am, Nick Mellor  wrote:
> Hi all,
>
> I'm pretty sure I'm following all the Python rules: I've put "self"
> before "forename" to make sure it's treated as a data attribute
> (instance variable.) And from within a class, I'm told, you need to
> prefix the var with self too. RandomName is a class that I've tested
> (and which still works.)

Doesn't look like you've executed RandomName() in this particular
example.


> So why do I get this error?
>
>   File "h:\Testing\NameDb\dictfile.py", line 107, in randomName
>     return {"Forename" : self.forename.randomByWeight(),
> AttributeError: RandomPerson instance has no attribute 'forename'

Next time, show the *full* traceback.

>
> Here's the code (Python 2.6, PythonWin):
>
> class RandomPerson:
>     def __init(self):

Because you named this method __init instead of __init__

Next time, before proclaiming innocence, insert a print statement or
two:
   print "Hello from RandomPerson.__init"
and wonder what the problem is if the print statement is not executed
>         self.forename = RandomName("h:\\Testing\\NameDb\
> \Forenames.csv", namefield = "Forename")
>         self.surname = RandomName("h:\\Testing\\NameDb\\Surnames.csv",
> namefield = "Surname")
>         self.randomAddress = dictfile("h:\\Testing\\NameDb\
> \Addresses.csv").cycleShuffled()
> [...]
>
>     def randomName(self):
>         return {"Forename" : self.forename.randomByWeight(),
>                 "Surname" : self.surname.randomByWeight()}
>
> if __name__ == "__main__":
>     person = RandomPerson()

and here's another good place for a print statement:
  print person.__dict__

>     print person.randomName()

Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >