Wednesday, April 21, 2010

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

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

comp.lang.python@googlegroups.com

Today's topics:

* Write web apps in Python? - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/7caab317a1d56d6e?hl=en
* Code redundancy - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/00286d4686672e21?hl=en
* rfind bug ? - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/d03fbdcacfbf5794?hl=en
* shove does not store data as expected - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/0f10299bbb0fb5e8?hl=en
* Declarative programming for the Model part of an application - 1 messages, 1
author
http://groups.google.com/group/comp.lang.python/t/b0eccbdce4abe24b?hl=en
* Tkinter question - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/5caea7948a47b645?hl=en
* error when printing a UTF-8 string (python 2.6.2) - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/fddf1ad516252069?hl=en
* Japanese (speaking) developer needed for a bit of regex magic - 3 messages,
3 authors
http://groups.google.com/group/comp.lang.python/t/1aa8c6029c8c3a1b?hl=en
* ARE U AGE 20--40 GET UR FRIENDSHIP HERE - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d84b55b768e92856?hl=en
* socked and bytes operation - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/ac7a8d11aa1458c3?hl=en
* Inline Calculation of Dictionary Values - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/9728b336da92ad8e?hl=en

==============================================================================
TOPIC: Write web apps in Python?
http://groups.google.com/group/comp.lang.python/t/7caab317a1d56d6e?hl=en
==============================================================================

== 1 of 3 ==
Date: Wed, Apr 21 2010 2:40 am
From: Paul Rubin


Bruno Desthuilliers <bruno.42.desthuilliers@websiteburo.invalid> writes:
> Nope. I want to keep all my settings parsed, my librairies loaded, all
> my connections opened etc. That is, all the time consuming stuff at
> app startup - which, with PHP, mostly happens for each and every
> request.

I thought we have WSGI for this? Nothing stops a Python app from
working like PHP. PHP has an advantage when you want to run mutually
hostile apps in the same process (relevant if you're running ultra-cheap
shared hosting and you want to put 1000 customers' virtual hosts in the
same mod_php instance), but I don't think you're looking to do that.


== 2 of 3 ==
Date: Wed, Apr 21 2010 3:06 am
From: Chris Rebert


On Wed, Apr 21, 2010 at 2:33 AM, Adam Tauno Williams
<awilliam@whitemice.org> wrote:
> On Wed, 2010-04-21 at 10:28 +0200, Bruno Desthuilliers wrote:
>> Bryan a écrit :
>> >
>> > I think I see what you mean
>>
>> Err...
>>
>> > -- correct me if I'm wrong:
>>
>> You are, sorry !-)
>>
>> > You want to
>> > keep complex application data structures around between requests.
>>
>> Nope. I want to keep all my settings parsed,
>
> Store them in the session.

I don't think that makes sense. You still have to re-parse the
settings upon starting each new session to store it in the session in
the first place.
Even then, you're suggesting needlessly keeping separate copies of the
settings data for each session, going from O(1) to O(N) in space;
that's rather wasteful.

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


== 3 of 3 ==
Date: Wed, Apr 21 2010 6:15 am
From: Bryan


Bruno Desthuilliers wrote:
> Nope. I want to keep all my settings parsed, my librairies loaded, all
> my connections opened etc. That is, all the time consuming stuff at app
> startup - which, with PHP, mostly happens for each and every request.

O.K. I wasn't clear on your objection. As I said the first time, I
think you've gotten some bad info on PHP. Or maybe you're just behind
the times.

> Many large, sopĥisticated etc applications are written in C. Does that
> make C a practical application programming language ?

It's at least a strong clue.

> Now I'm sorry to say that for quite a few "sophisticated" PHP apps I've
> seen (and eventually had to work on), the "startup" part - parsing the
> include files, configuration, establishing connections etc - took a good
> part of the total processing time.

You didn't say when that was, but PHP caching has come a long way.
Google is your friend.

--
--Bryan

==============================================================================
TOPIC: Code redundancy
http://groups.google.com/group/comp.lang.python/t/00286d4686672e21?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 21 2010 3:03 am
From: Andreas Löscher


You can do something like this:

>>> class A(): pass
>>> inst=A()
>>> exec("""
... a=1
... b=2
... c=3
... d=4
... """) in inst.__dict__
>>> inst.a
1
>>>

This executes the Statement in the exec function and uses inst.__dict__
as namespace. But be aware, that this is not recommended. If you mess
with __dict__, you won't be able to replace it with some logic
(parameter) if you need to do something more than setting a variable.

Best


==============================================================================
TOPIC: rfind bug ?
http://groups.google.com/group/comp.lang.python/t/d03fbdcacfbf5794?hl=en
==============================================================================

== 1 of 5 ==
Date: Wed, Apr 21 2010 3:13 am
From: Jean-Michel Pichavant


Stef Mientki wrote:
> On 21-04-2010 10:56, Chris Rebert wrote:
>
>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki@gmail.com> wrote:
>>
>>
>>> With the following code, I would expect a result of 5 !!
>>>
>>>
>>>
>>>>>> a= 'word1 word2 word3'
>>>>>> a.rfind(' ',7)
>>>>>>
>>>>>>
>>> 11
>>>
>>> Is this a bug ?
>>>
>>>
>> No. Don't you think someone would have found such an obvious bug by now?
>>
>>
> if it's not a bug,
> then the start index has no meaning ...
> ... and some would call that a bug.
>
> cheers,
> Stef
>
a.rfind(' ', 12)
Out[12]: -1

looks like the start index has a meaning ...

JM

== 2 of 5 ==
Date: Wed, Apr 21 2010 3:26 am
From: Chris Rebert


On Wed, Apr 21, 2010 at 2:59 AM, Stef Mientki <stef.mientki@gmail.com> wrote:
> On 21-04-2010 10:56, Chris Rebert wrote:
>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki@gmail.com> wrote:
>>> With the following code, I would expect a result of 5 !!
>>>
>>>>>> a= 'word1 word2 word3'
>>>>>> a.rfind(' ',7)
>>>>>>
>>> 11
>>>
>>> Is this a bug ?
>>>
>> No. Don't you think someone would have found such an obvious bug by now?
>>
> if it's not a bug,
> then the start index has no meaning ...
> ... and some would call that a bug.

Ah, I neglected to take your use of .rfind()'s second parameter into account!

As can be interpolated from the part of the docs James quotes:
s.rfind(' ', 7) === s[7:].rfind(' ') + 7 # overlooking the 'not present' case

That is, the second parameter to .rfind(), namely `start`, is relative
to the *left* end of the string, not the right end. I can see how this
might be unintuitive, but it does make the API more uniform.

Cheers,
Chris


== 3 of 5 ==
Date: Wed, Apr 21 2010 3:33 am
From: "Alf P. Steinbach"


* Chris Rebert:
> On Wed, Apr 21, 2010 at 2:59 AM, Stef Mientki <stef.mientki@gmail.com> wrote:
>> On 21-04-2010 10:56, Chris Rebert wrote:
>>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki@gmail.com> wrote:
>>>> With the following code, I would expect a result of 5 !!
>>>>
>>>>>>> a= 'word1 word2 word3'
>>>>>>> a.rfind(' ',7)
>>>>>>>
>>>> 11
>>>>
>>>> Is this a bug ?
>>>>
>>> No. Don't you think someone would have found such an obvious bug by now?
>>>
>> if it's not a bug,
>> then the start index has no meaning ...
>> ... and some would call that a bug.
>
> Ah, I neglected to take your use of .rfind()'s second parameter into account!
>
> As can be interpolated from the part of the docs James quotes:
> s.rfind(' ', 7) === s[7:].rfind(' ') + 7 # overlooking the 'not present' case
>
> That is, the second parameter to .rfind(), namely `start`, is relative
> to the *left* end of the string, not the right end. I can see how this
> might be unintuitive, but it does make the API more uniform.

It seems that the OP also thought it was relative to the left end of the string.

The difference is what it signifies: start of search, or end of search.

With rfind the "start" parameter signifies the end of the search, and
conversely, the third parameter "end" signifies where the search starts. :-)


Cheers,

- Alf


== 4 of 5 ==
Date: Wed, Apr 21 2010 4:09 am
From: Stef Mientki


On 21-04-2010 12:33, Alf P. Steinbach wrote:
> * Chris Rebert:
>> On Wed, Apr 21, 2010 at 2:59 AM, Stef Mientki
>> <stef.mientki@gmail.com> wrote:
>>> On 21-04-2010 10:56, Chris Rebert wrote:
>>>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki
>>>> <stef.mientki@gmail.com> wrote:
>>>>> With the following code, I would expect a result of 5 !!
>>>>>
>>>>>>>> a= 'word1 word2 word3'
>>>>>>>> a.rfind(' ',7)
>>>>>>>>
>>>>> 11
>>>>>
>>>>> Is this a bug ?
>>>>>
>>>> No. Don't you think someone would have found such an obvious bug by
>>>> now?
>>>>
>>> if it's not a bug,
>>> then the start index has no meaning ...
>>> ... and some would call that a bug.
>>
>> Ah, I neglected to take your use of .rfind()'s second parameter into
>> account!
>>
>> As can be interpolated from the part of the docs James quotes:
>> s.rfind(' ', 7) === s[7:].rfind(' ') + 7 # overlooking the 'not
>> present' case
>>
>> That is, the second parameter to .rfind(), namely `start`, is relative
>> to the *left* end of the string, not the right end. I can see how this
>> might be unintuitive, but it does make the API more uniform.
>
> It seems that the OP also thought it was relative to the left end of
> the string.
>
> The difference is what it signifies: start of search, or end of search.
>
> With rfind the "start" parameter signifies the end of the search, and
> conversely, the third parameter "end" signifies where the search
> starts. :-)
>
thanks Alf,
that's indeed what I was missing.

cheers,
Stef

>
> Cheers,
>
> - Alf

== 5 of 5 ==
Date: Wed, Apr 21 2010 4:11 am
From: Chris Rebert


On Wed, Apr 21, 2010 at 3:33 AM, Alf P. Steinbach <alfps@start.no> wrote:
> * Chris Rebert:
>> On Wed, Apr 21, 2010 at 2:59 AM, Stef Mientki <stef.mientki@gmail.com>
>> wrote:
>>> On 21-04-2010 10:56, Chris Rebert wrote:
>>>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki@gmail.com>
>>>> wrote:
>>>>>
>>>>> With the following code, I would expect a result of 5 !!
>>>>>
>>>>>>>> a= 'word1 word2 word3'
>>>>>>>> a.rfind(' ',7)
>>>>>>>>
>>>>> 11
>>>>>
>>>>> Is this a bug ?
>>>>>
>>>> No. Don't you think someone would have found such an obvious bug by now?
>>>>
>>> if it's not a bug,
>>> then the start index has no meaning ...
>>> ... and some would call that a bug.
>>
>> Ah, I neglected to take your use of .rfind()'s second parameter into
>> account!
>>
>> As can be interpolated from the part of the docs James quotes:
>> s.rfind(' ', 7) === s[7:].rfind(' ') + 7 # overlooking the 'not present'
>> case
>>
>> That is, the second parameter to .rfind(), namely `start`, is relative
>> to the *left* end of the string, not the right end. I can see how this
>> might be unintuitive, but it does make the API more uniform.
>
> It seems that the OP also thought it was relative to the left end of the
> string.

It really doesn't help that the example in question is kinda lousy
(particularly, it's symmetrical with respect to whitespace and has
only 2 spaces).
Case in point, my misinterpretation of the OP's misinterpretation
(i.e. having the indexing of `start` be relative to the end of the
string) still plausibly explains his confusion.

Cheers,
Chris
--
Excellent catch.
*Considers getting Alien Life-Form merch*

> The difference is what it signifies: start of search, or end of search.
>
> With rfind the "start" parameter signifies the end of the search, and
> conversely, the third parameter "end" signifies where the search starts. :-)

==============================================================================
TOPIC: shove does not store data as expected
http://groups.google.com/group/comp.lang.python/t/0f10299bbb0fb5e8?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Apr 21 2010 3:36 am
From: Chris Rebert


On Wed, Apr 21, 2010 at 2:51 AM, Alex <metallourlante@gmail.com> wrote:
> I'm trying to use the shove module (http://pypi.python.org/pypi/shove)
> for a simple script. The script read a CSV file ad store the data.
> When I check the content of the "store" object (instance of Shove)
> *before* I close it, the data are all there but when I close and re-
> open it some data are lost. How it is possible? There is something
> wrong in my code or I didn't understand how shove works?
>
> Thanks in advance.
>
> Here is a sample of my code:
>
> DBNAME = "file://store.db"
>
>    csv_file ="test.csv"
>    cities = csv.reader(open(csv_file), delimiter=";")
>    store = Shove(DBNAME, compress=True)
>    for city,region,code in cities:
>        entry_list = store.setdefault(region, [])
>        data = 'just a sample'
>        entry = {city:data}
>        entry_list.append(entry)

If `shove` is like the std lib `shelve` module, the following might
fix the problem:

#untested
for city,region,code in cities:
entry_list = store.get(region, [])
data = 'just a sample'
entry = {city:data}
entry_list.append(entry)
store[region] = entry_list

Explanation:
The explicit assignment back to the `store` pseudo-dictionary lets it
properly update its internal state to reflect the change to the value
(in this case, the list) associated with the region key. In your
original version, you merely modified the list in-place, and (due to
the way Python works) `store` has no way of knowing that you've done
that and thus doesn't do the necessary bookkeeping, hence the behavior
you're observing.

See also: http://docs.python.org/library/shelve.html#example

And further note that shove seems to be beta and (apart from
docstrings in the source code) undocumented.

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


== 2 of 2 ==
Date: Wed, Apr 21 2010 4:37 am
From: Alex


On 21 Apr, 12:36, Chris Rebert <c...@rebertia.com> wrote:
[cut]
>
> Explanation:
> The explicit assignment back to the `store` pseudo-dictionary lets it
> properly update its internal state to reflect the change to the value
> (in this case, the list) associated with the region key. In your
> original version, you merely modified the list in-place, and (due to
> the way Python works) `store` has no way of knowing that you've done
> that and thus doesn't do the necessary bookkeeping, hence the behavior
> you're observing.
>
> See also:http://docs.python.org/library/shelve.html#example
>
> And further note that shove seems to be beta and (apart from
> docstrings in the source code) undocumented.

Thanks a lot for the clear explanation. It works!
I will read the docs more carefully next time :-)

Alex

==============================================================================
TOPIC: Declarative programming for the Model part of an application
http://groups.google.com/group/comp.lang.python/t/b0eccbdce4abe24b?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 21 2010 3:41 am
From: pca


Dear all,

Last week, I raised the question "Could declarative programming be
useful for the Model part of an application ?", and I suggested an
open-source project, Yoopf, to provide such a paradigm in Python.
Stefan told me that the proposal lacked clarity. I have thus updated
the description, and he now finds it much clearer. You can find it at
http://www.yoopf.org

So, I would appreciate your feedback again on such a project : can
declarative programming be useful for the Model part of an
application ? Do you think that Yoopf and its "programming by
formula" paradigm can bring value to python developments ? How would
it compare to database triggers and stored procedures, for example ?
What could be some typical applications ?

Many thanks in advance !
Pierre C.

==============================================================================
TOPIC: Tkinter question
http://groups.google.com/group/comp.lang.python/t/5caea7948a47b645?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Apr 21 2010 3:45 am
From: Rotwang


Apologies in advance if this is a totally stupid question, I've tried
looking at the Tkinter documentation on the web but since I'm something
of an ignoramus when it comes to programming generally I didn't
understand what I was reading. Anyway...

I've written a module that allows me to manipulate sound data, and I've
been trying to add a method to my sound class that shows me what a
waveform looks like while I'm working on it in IDLE. After reading a bit
about Tkinter, and via some trial and error, I came up with something a
bit like this:

def draw(self, w, h):
out = Tkinter.Canvas(width = w, height = h)
# a load of out.create_line(...)'s go here
out.pack()
out.mainloop()

It works, but the problem is that I can't do anything else with IDLE
until I close the image window. Is there a way around this, so that I
can leave the image open while I continue to do other stuff?


== 2 of 2 ==
Date: Wed, Apr 21 2010 4:25 am
From: James Mills


On Wed, Apr 21, 2010 at 8:45 PM, Rotwang <sg552@hotmail.co.uk> wrote:
> def draw(self, w, h):
>        out = Tkinter.Canvas(width = w, height = h)
>        # a load of out.create_line(...)'s go here
>        out.pack()
>        out.mainloop()
>
> It works, but the problem is that I can't do anything else with IDLE until I
> close the image window. Is there a way around this, so that I can leave the
> image open while I continue to do other stuff?

>From reading the documentation myself (pydoc)...

It would seem your only option is to make a thread
out of this (not my preferred way - I was hoping it was
possible to poll the Tk event system...).

cheers
James

==============================================================================
TOPIC: error when printing a UTF-8 string (python 2.6.2)
http://groups.google.com/group/comp.lang.python/t/fddf1ad516252069?hl=en
==============================================================================

== 1 of 3 ==
Date: Wed, Apr 21 2010 4:04 am
From:


Thanks for your insights.

I have taken the easy way out, I read on a page that python 3 worked
by default in UTF-8, so I downloaded and installed it.

Apart from a few surprises (print is not a funtion, and rules about
mixing spaces and tabs in indentation are much more strict, and I
guess more is to come :^) everything now works transparently.

Thanks again.

--
Fabrice DELENTE


== 2 of 3 ==
Date: Wed, Apr 21 2010 4:28 am
From: Peter Otten <__peter__@web.de>


fab@slick.airforce-one.org wrote:

> I have taken the easy way out, I read on a page that python 3 worked
> by default in UTF-8, so I downloaded and installed it.

Just a quick reminder: UTF-8 is not the same as unicode. Python3 works in
unicode and by default uses UTF-8 to read from or write into files.

Peter


== 3 of 3 ==
Date: Wed, Apr 21 2010 6:05 am
From: python@bdurham.com


Hi Peter,

> Just a quick reminder: UTF-8 is not the same as unicode. Python3 works in unicode and by default uses UTF-8 to read from or write into files.

I'm not the OP, but wanted to make sure I was fully understanding your
point.

Are you saying all open() calls in Python that read text files,
automatically convert UTF-8 content to Unicode in the same manner as the
following might when using Python 2.6?

codecs.open( fileName, mode='r', encoding='UTF8', ... )

Thanks for your feedback,

Malcolm

==============================================================================
TOPIC: Japanese (speaking) developer needed for a bit of regex magic
http://groups.google.com/group/comp.lang.python/t/1aa8c6029c8c3a1b?hl=en
==============================================================================

== 1 of 3 ==
Date: Wed, Apr 21 2010 4:28 am
From: Ben Finney


Sebastian <basti@redtoad.de> writes:

> My regular expressions turn the Amazon error messages into Python
> exceptions.
>
> This works fine as long as they are in English: "??? is not a valid
> value for BrowseNodeId. Please change this value and retry your
> request.", for instance, will raise an InvalidParameterValue
> exception. However, the Japanese version returns the error message
> "??? は、BrowseNodeIdの値として無効です。値を変更してから、再度リクエス
> トを実行してください。" which will not be successfully handled.
>
> This renders the my module pretty much useless for Japanese users.

Your problem, then, appears to be that you're attacking the issue at the
wrong layer. Parsing messages in natural language and hoping to
reconstruct a structure is going to be an exercise in frustration.

Doesn't the API have defined response codes and parameters that you can
use, instead of parsing error strings in various natural languages?

--
\ "Giving every man a vote has no more made men wise and free |
`\ than Christianity has made them good." —Henry L. Mencken |
_o__) |
Ben Finney


== 2 of 3 ==
Date: Wed, Apr 21 2010 4:46 am
From: Sebastian


> > My regular expressions turn the Amazon error messages into Python
> > exceptions.
>
> > This works fine as long as they are in English: "??? is not a valid
> > value for BrowseNodeId. Please change this value and retry your
> > request.", for instance, will raise an InvalidParameterValue
> > exception. However, the Japanese version returns the error message
> > "??? は、BrowseNodeIdの値として無効です。値を変更してから、再度リクエス
> > トを実行してください。" which will not be successfully handled.
>
> > This renders the my module pretty much useless for Japanese users.
>
> Your problem, then, appears to be that you're attacking the issue at the
> wrong layer. Parsing messages in natural language and hoping to
> reconstruct a structure is going to be an exercise in frustration.
>
> Doesn't the API have defined response codes and parameters that you can
> use, instead of parsing error strings in various natural languages?

No, unfortunately not. If it did, I would have used it.

The Amazon API returns an XML response which contains error messages
if a request fails. These messages consist of an error code and an
error description in natural language. Luckily, the description seems
to stick to the same format and is (in all but one case) in plain
English. Much to my dismay I discovered that the Japanese locale
translates the error message!

For example, this is the bit of XML returned for the German locale:

<Errors>
<Error>
<Code>AWS.InvalidParameterValue</Code>
<Message>??? is not a valid value for BrowseNodeId. Please
change this value and retry your request.</Message>
</Error>
</Errors>

The corresponding part from the Japanese locale looks like this:

<Errors>
<Error>
<Code>AWS.InvalidParameterValue</Code>
<Message>???
&#12399;&#12289;BrowseNodeId&#12398;&#20516;&#12392;&#12375;&#12390;&#28961;&#21177;&#12391;&#12377;&#12290;&#20516;&#12434;&#22793;&#26356;&#12375;&#12390;&#12363;&#12425;&#12289;&#20877;&#24230;&#12522;&#12463;&#12456;&#12473;&#12488;&#12434;&#23455;&#34892;&#12375;&#12390;&#12367;&#12384;&#12373;&#12356;&#12290;</
Message>
</Error>
</Errors>

Of course, one could argue that the type of error (in this case
"AWS.InvalidParameterValue") would be enough. However, in order to
return a maeningful error message, I would like to parse the
description itself - and for this some knowledge of Japanese would be
helpful.


== 3 of 3 ==
Date: Wed, Apr 21 2010 5:09 am
From: Chris Rebert


On Wed, Apr 21, 2010 at 4:46 AM, Sebastian <basti@redtoad.de> wrote:
>> > My regular expressions turn the Amazon error messages into Python
>> > exceptions.
>>
>> > This works fine as long as they are in English: "??? is not a valid
>> > value for BrowseNodeId. Please change this value and retry your
>> > request.", for instance, will raise an InvalidParameterValue
>> > exception. However, the Japanese version returns the error message
>> > "??? は、BrowseNodeIdの値として無効です。値を変更してから、再度リクエス
>> > トを実行してください。" which will not be successfully handled.
>>
>> > This renders the my module pretty much useless for Japanese users.
>>
>> Your problem, then, appears to be that you're attacking the issue at the
>> wrong layer. Parsing messages in natural language and hoping to
>> reconstruct a structure is going to be an exercise in frustration.
>>
>> Doesn't the API have defined response codes and parameters that you can
>> use, instead of parsing error strings in various natural languages?
>
> No, unfortunately not. If it did, I would have used it.
>
> The Amazon API returns an XML response which contains error messages
> if a request fails. These messages consist of an error code and an
> error description in natural language. Luckily, the description seems
> to stick to the same format and is (in all but one case) in plain
> English. Much to my dismay I discovered that the Japanese locale
> translates the error message!
>
> For example, this is the bit of XML returned for the German locale:
>
>      <Errors>
>        <Error>
>          <Code>AWS.InvalidParameterValue</Code>
>          <Message>??? is not a valid value for BrowseNodeId. Please
> change this value and retry your request.</Message>
>        </Error>
>      </Errors>
>
> The corresponding part from the Japanese locale looks like this:
>
>      <Errors>
>        <Error>
>          <Code>AWS.InvalidParameterValue</Code>
>          <Message>???
> &#12399;&#12289;BrowseNodeId&#12398;&#20516;&#12392;&#12375;&#12390;&#28961;&#21177;&#12391;&#12377;&#12290;&#20516;&#12434;&#22793;&#26356;&#12375;&#12390;&#12363;&#12425;&#12289;&#20877;&#24230;&#12522;&#12463;&#12456;&#12473;&#12488;&#12434;&#23455;&#34892;&#12375;&#12390;&#12367;&#12384;&#12373;&#12356;&#12290;</
> Message>
>        </Error>
>      </Errors>
>
> Of course, one could argue that the type of error (in this case
> "AWS.InvalidParameterValue") would be enough. However, in order to
> return a maeningful error message, I would like to parse the
> description itself - and for this some knowledge of Japanese would be
> helpful.

Just throwing this out there, but perhaps you could grep for the
relevant terms in the error message and intuit it from there?
For example:

# terms = whatever the actual param names are
terms = "BrowseNodeId FooNodeId FooQueryType".split()
for term in terms:
if term in err_msg:
raise AmazonError, err_code + " for " +repr(term)

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

==============================================================================
TOPIC: ARE U AGE 20--40 GET UR FRIENDSHIP HERE
http://groups.google.com/group/comp.lang.python/t/d84b55b768e92856?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 21 2010 5:28 am
From: LLL <4ennel.0569@gmail.com>


http://123maza.com/75/expressions

==============================================================================
TOPIC: socked and bytes operation
http://groups.google.com/group/comp.lang.python/t/ac7a8d11aa1458c3?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Apr 21 2010 5:37 am
From: luca72


Hello i have this question :
i connect to the server in this way:
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect(('192.168.1.11',11502))
rcv = sock.recv(8124)
here i get 14 random bytes , in a string with strange chars like :
¬¨^.á‹•Ò
a„ãj
I think because sock.recv return a string.
Now i have to xor this 14 bytes with a key stored in file as a sting.
Can you help me to understand how to do it.

Thanks

Luca


== 2 of 2 ==
Date: Wed, Apr 21 2010 6:01 am
From: Chris Rebert


On Wed, Apr 21, 2010 at 5:37 AM, luca72 <lucaberto@libero.it> wrote:
> Hello i have this question :
> i connect to the server in this way:
> sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
> sock.connect(('192.168.1.11',11502))
> rcv = sock.recv(8124)
> here i get 14 random bytes , in a string with strange chars like :
> ¬¨^.á‹•Ò
> a„ãj
> I think because sock.recv return a string.
> Now i have to xor this 14 bytes with a key stored in file as a sting.
> Can you help me to understand how to do it.

# Disclaimer: Completely untested
from itertools import cycle
f = open("path/to/key_file", 'r') # open file
key = f.read() # read from file
f.close() # close file
# convert strings to lists of integers
rcv = map(ord, rcv)
key = map(ord, key)
plain_chars = []
# do the XOR-ing
for cypher_char, key_char in zip(rcv, cycle(key)):
plain_char = chr(ord(cypher_char) ^ ord(key_char))
plain_chars.append(plain_char)
# join decrypted characters into a string
# and output it
print ''.join(plain_chars) # Python idiom

You'll probably need to read up on what zip(), map(), ord(), and chr() do:
http://docs.python.org/library/functions.html

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

==============================================================================
TOPIC: Inline Calculation of Dictionary Values
http://groups.google.com/group/comp.lang.python/t/9728b336da92ad8e?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Apr 21 2010 5:51 am
From: "++imanshu"


Hi,

Is it possible to something along these lines in python :-

map = {
'key1': f(),
'key2': modify_state(); val = f(); restore_state(); val,
'key3': f(),
}

For 'key2' I want to store the value returned by f() but after
modifying the state. Do we have something like a "bare block". I am
trying to avoid this :-

def f2():
modify_state()
val = f()
restore_state()
return val

map = {
'key1': f(),
'key2': f2()
'key3': f(),
}

Thank You,
Himanshu


== 2 of 2 ==
Date: Wed, Apr 21 2010 6:10 am
From: Chris Rebert


On Wed, Apr 21, 2010 at 5:51 AM, ++imanshu <himanshu.garg@gmail.com> wrote:
>     Is it possible to something along these lines in python :-
>
> map = {
> 'key1': f(),
> 'key2': modify_state(); val = f(); restore_state(); val,
> 'key3': f(),
> }
>
>      For 'key2' I want to store the value returned by f() but after
> modifying the state. Do we have something like a "bare block".

Based on what I can find about "bare blocks", Nope. And we like it that way :-)

> I am
> trying to avoid this :-
>
> def f2():
>     modify_state()
>     val = f()
>     restore_state()
>     return val
>
> map = {
> 'key1': f(),
> 'key2': f2()
> 'key3': f(),
> }

FWIW, I don't see what's wrong with this. You could probably refactor
f2() to use the `with` statement and a context manager, but that's
getting tangential.
However, the question arises: Why do you have global state in the first place?

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


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

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