Tuesday, March 16, 2010

comp.lang.python - 7 new messages in 6 topics - digest

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

comp.lang.python@googlegroups.com

Today's topics:

* result of os.times() is different with 'time' command Options - 1 messages,
1 author
http://groups.google.com/group/comp.lang.python/t/ab45c1ed3e45401c?hl=en
* Dynamic Class Creation - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/2bd3e29c06ee0899?hl=en
* Reverse engineering CRC? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b22db1e3e63db596?hl=en
* Data entry Work available - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f04be68eb75eff4d?hl=en
* time_struct - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/1905a949453756ba?hl=en
* xml-rpc - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/8ffd132eb331df1e?hl=en

==============================================================================
TOPIC: result of os.times() is different with 'time' command Options
http://groups.google.com/group/comp.lang.python/t/ab45c1ed3e45401c?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Mar 15 2010 10:50 pm
From: "Gabriel Genellina"


En Mon, 15 Mar 2010 03:51:28 -0300, hiral <hiralsmaillist@gmail.com>
escribió:
> On Mar 15, 7:14 am, Tim Roberts <t...@probo.com> wrote:
>> hiral<hiralsmaill...@gmail.com> wrote:

>> >Output:
>> >real 0.0m0.0100000002421s
>> >user 0.0m0.0s
>> >sys 0.0m0.0s
>>
>> >Command:
>> >$ time ls
>>
>> >Output:
>> >real 0m0.007s
>> >user 0m0.000s
>> >sys 0m0.000s
>>
>> You can't really do an analysis like this with a task that only takes a
>> few
>> milliseconds. There are too many variables.
>
> Thanks for your explanation.

Have you tested with the highly recursive function in that 2007 thread you
linked to?
This should take time enough to make a problem like this clearly visible.

--
Gabriel Genellina


==============================================================================
TOPIC: Dynamic Class Creation
http://groups.google.com/group/comp.lang.python/t/2bd3e29c06ee0899?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Mar 15 2010 11:01 pm
From: Josh English


I have a large program with lots of data stored in XML. I'm upgrading
my GUI to use ObjectListView, but with my data in XML, I don't have
regular objects to interact with the OLV. I do have an XML validator
that defines the structure of the XML elements, and I'm trying to
dynamically create a class to wrap the XML element.

So, an element like:

<market code="WotF">
<title>Writers of the Future</title>
</market>

I want to create a class like:

class Market(object):
def __init__(self, elem):
self._elem = elem

def get_code(self):
return self._elem.get('code')

def set_code(self, value):
self._elem.set('code', value)

def get_title(self):
return self._elem.find('title').text

def set_title(self, value):
node = self._elem.find('title')
node.text = value

Naturally, I don't want to hand code this for every interface but
would like to create them dynamically. (The laziness of programming, I
guess.)

I have tried several solutions that I found on various forums, but
they are all several years old.

Questions:

What's the best way to create these helper methods?

How can I attach them to the class and have it run?

I have had a few solutions work where I had a class with three methods
(get_code, get_tier, get_mail) but they all return the same value, not
the individual values.

----
Josh English


== 2 of 2 ==
Date: Mon, Mar 15 2010 11:18 pm
From: Chris Rebert


On Mon, Mar 15, 2010 at 11:01 PM, Josh English
<joshua.r.english@gmail.com> wrote:
> I have a large program with lots of data stored in XML. I'm upgrading
> my GUI to use ObjectListView, but with my data in XML, I don't have
> regular objects to interact with the OLV. I do have an XML validator
> that defines the structure of the XML elements, and I'm trying to
> dynamically create a class to wrap the XML element.
>
> So, an element like:
>
> <market code="WotF">
> <title>Writers of the Future</title>
> </market>
>
> I want to create a class like:
>
> class Market(object):
>    def __init__(self, elem):
>        self._elem = elem
>
>    def get_code(self):
>        return self._elem.get('code')
>
>    def set_code(self, value):
>        self._elem.set('code', value)
>
>    def get_title(self):
>        return self._elem.find('title').text
>
>    def set_title(self, value):
>        node = self._elem.find('title')
>        node.text = value
>
> Naturally, I don't want to hand code this for every interface but
> would like to create them dynamically. (The laziness of programming, I
> guess.)
>
> I have tried several solutions that I found on various forums, but
> they are all several years old.
>
> Questions:
>
> What's the best way to create these helper methods?

Nested functions:

def make_attr_getset(name):
def get(self):
return self._elem.get(name)

def set(self, value):
self._elem.set(name, value)
return get, set

get_code, set_code = make_attr_getset('code')

def make_subelement_getset(name):
def get(self):
return self._elem.find(name).text

def set(self, value):
node = self._elem.find(name)
node.text = value
return get, set

get_title, set_title = make_subelement_getset('title')

> How can I attach them to the class and have it run?

Use properties and setattr():

class Market(object):
def __init__(... #same as before

setattr(Market, 'code', property(get_code, set_code))
setattr(Market, 'title', property(get_title, set_title))

m = Market(the_XML)
print m.title #=> Writers of the Future
m.title = "Writers of the Past"
print m.code #=> WotF
m.code = "WofP"

Cheers,
Chris
--
http://blog.rebertia.com

==============================================================================
TOPIC: Reverse engineering CRC?
http://groups.google.com/group/comp.lang.python/t/b22db1e3e63db596?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Mar 15 2010 11:16 pm
From: "Gabriel Genellina"


En Mon, 15 Mar 2010 07:29:51 -0300, Gregory Ewing
<greg.ewing@canterbury.ac.nz> escribió:

> I've solved the problem now.
>
> It turned out to be a very standard CRC algorithm, complicated
> by the presence of a few extra bytes of data being checked that
> didn't appear explicitly in the file anywhere.
>
> In the process I developed some very general techniques for
> solving this kind of problem, which I've written about here
> if anyone's interested:
>
> http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html

A good solution to an interesting problem - and very nicely explained too!

--
Gabriel Genellina


==============================================================================
TOPIC: Data entry Work available
http://groups.google.com/group/comp.lang.python/t/f04be68eb75eff4d?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Mar 15 2010 11:44 pm
From: Earn money


Data entry works Available At
No need to pay DEposite

http://trading7000.blogspot.com/

Adposting Jobs Availble

http://trading7000.blogspot.com/


No need to work Hard
Earn Money From Home
7000 in Minutes

http://trading7000.blogspot.com/

==============================================================================
TOPIC: time_struct
http://groups.google.com/group/comp.lang.python/t/1905a949453756ba?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Mar 15 2010 11:46 pm
From: "Gabriel Genellina"


En Sun, 07 Mar 2010 10:50:59 -0300, moerchendiser2k3
<googler.1.webmaster@spamgourmet.com> escribió:

> can anyone tell me how to return a time_struct from the timemodule in
> my own C-Module?
> Is that possible? I can just find one function in timefuncs.h, but it
> doesnt return any PyObject.

The type is available as the struct_time attribute in the time module; you
create an instance by calling it with a 9-items sequence.

--
Gabriel Genellina


==============================================================================
TOPIC: xml-rpc
http://groups.google.com/group/comp.lang.python/t/8ffd132eb331df1e?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Mar 16 2010 12:04 am
From: "Gabriel Genellina"


En Sun, 14 Mar 2010 05:14:49 -0300, ahmet erdinc yilmaz
<ahmeterdinc09@gmail.com> escribió:

> Recenetly we are developing a senior project and decide to use xmlrpclib.
> However I have some questions. In the documentation I could not find any
> clue about
> handling requests? Does the server handles each request in a separate
> thread? Or is
> there some queuing mechanism for client calls? Thanks in advance.

xmlrpclib is a *client* library.
Python also provides an XMLRPC *server* in the SimpleXMLRPCServer module.
It inherits from SocketServer.TCPServer. The default behavior is to
process one request at a time, in a single process. You may alter such
behavior by additionally inheriting from ForkingMixIn or ThreadingMixIn.

--
Gabriel Genellina

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

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

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

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

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

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

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate