Wednesday, March 3, 2010

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

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

comp.lang.python@googlegroups.com

Today's topics:

* cpan for python? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/ecd51ced8d24593e?hl=en
* process mp3 file - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/f8bb2321216facc4?hl=en
* case do problem - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d73f6f6a59d3bbfd?hl=en
* nonunique string replacements - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/78e04e7fd683fd61?hl=en
* python 2.6: how to modify a PIL image from C without copying forth and back -
4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/c456d88ea2773a7e?hl=en
* Image.frombuffer and warning - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/ee441d531cec25fe?hl=en
* conditional import into global namespace - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/8718bce88cea1cf5?hl=en
* Interest check in some delicious syntactic sugar for "except:pass" - 4
messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/b493c6208ea724a2?hl=en
* Docstrings considered too complicated - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/dea5c94f3d058e26?hl=en
* exp_internal in pexpect - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/998910a6e13bda92?hl=en
* PYTHONPATH and eggs - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f40da95d87441720?hl=en
* Method / Functions - What are the differences? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/72ab93ba395822ed?hl=en
* Re Interest check in some delicious syntactic sugar for "except:pass" - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/0041fb118a65a722?hl=en
* monkey patching with @classmethod - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/2290ae917e52fd44?hl=en

==============================================================================
TOPIC: cpan for python?
http://groups.google.com/group/comp.lang.python/t/ecd51ced8d24593e?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 12:23 am
From: TomF


On 2010-03-02 19:59:01 -0800, Lie Ryan <lie.1296@gmail.com> said:

> On 03/03/2010 09:47 AM, TomF wrote:
>> On 2010-03-02 13:14:50 -0800, R Fritz <rfritz@u.washington.edu> said:
>>
>>> On 2010-02-28 06:31:56 -0800, ssteinerX@gmail.com said:
>>>>
>>>> On Feb 28, 2010, at 9:28 AM, Someone Something wrote:
>>>>
>>>>> Is there something like cpan for python? I like python's syntax, but
>>>>> Iuse perl because of cpan and the tremendous modules that it has. --
>>>>
>>>> Please search the mailing list archives.
>>>>
>>>> This subject has been discussed to absolute death.
>>>
>>> But somehow the question is not in the FAQ, though the answer is. See:
>>>
>>> <http://www.python.org/doc/faq/library/#how-do-i-find-a-module-or-application-to-perform-task-x>


There
>>>
>> is also a program called cpan, distributed with Perl. It is used for
>> searching, downloading, installing and testing modules from the CPAN
>> repository. It's far more extensive than setuptools. AFAIK the python
>> community has developed nothing like it.
>
> python have easy_install

easy_install is part of setuptools. As I said, nothing like cpan.

-Tom


==============================================================================
TOPIC: process mp3 file
http://groups.google.com/group/comp.lang.python/t/f8bb2321216facc4?hl=en
==============================================================================

== 1 of 4 ==
Date: Wed, Mar 3 2010 12:33 am
From: asit


Somebody suggest me a python library for processing mp3 file. Here I
don't want to play the file.

Thank you


== 2 of 4 ==
Date: Wed, Mar 3 2010 2:25 am
From: Chris Rebert


On Wed, Mar 3, 2010 at 12:33 AM, asit <lipun4u@gmail.com> wrote:
> Somebody suggest me a python library for processing mp3 file.  Here I
> don't want to play the file.

Define "processing".

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


== 3 of 4 ==
Date: Wed, Mar 3 2010 2:43 am
From: asit

> Define "processing".

getting the title, song name, etc of the file and updating in a
database


== 4 of 4 ==
Date: Wed, Mar 3 2010 3:06 am
From: Chris Rebert


On Wed, Mar 3, 2010 at 2:43 AM, asit <lipun4u@gmail.com> wrote:
>> Define "processing".
>
> getting the title, song name, etc of the file and updating in a
> database

You'd want an ID3 tag library then. Here's one:

http://eyed3.nicfit.net/

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

==============================================================================
TOPIC: case do problem
http://groups.google.com/group/comp.lang.python/t/d73f6f6a59d3bbfd?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 12:39 am
From: Peter Otten <__peter__@web.de>


Tracubik wrote:

> hi, i've to convert from Pascal this code:

program loop;

function generic_condition: boolean;
begin
generic_condition := random > 0.7
end;

procedure loop;
var
iterations, count, m: integer;
begin
iterations := 0;
count := 0;
m := 0;
repeat
iterations := iterations+1;
(*...*)
writeln(iterations:2, count:2, m:4);
(*...*)
if generic_condition then
inc(count);
(*...*)
case count of
1: m := 1;
2: m := 10;
3: m := 100
end
until (count = 4) or (iterations = 20)
end;

begin
loop;
writeln("That's all, folks")
end.

Hey, I have a Pascal compiler just one apt-get away ;)

Here's how I'd translate the above, without trying to be too clever:

from random import random

def generic_condition():
return random() > 0.7

def loop():
count = 0
m = 0
lookup = {1: 1, 2: 10, 3: 100}
for iterations in range(20): # off by one
# ...
print "%2d %1d %3d" % (iterations, count, m)
# ...
if generic_condition():
count += 1
# ...
m = lookup.get(count, m)
if count == 4:
break

if __name__ == "__main__":
loop()
print "That's all, folks"

Something must be wrong with me today because I find the Pascal code /more/
readable...

Peter

==============================================================================
TOPIC: nonunique string replacements
http://groups.google.com/group/comp.lang.python/t/78e04e7fd683fd61?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Mar 3 2010 12:42 am
From: Steven D'Aprano


On Tue, 02 Mar 2010 23:06:13 -0800, Ben Racine wrote:

> All,
>
> Say I have a string "l" ...
>
> l = 'PBUSH 201005 K 1. 1. 1. 1. 1.
> 1.'
>
> And I want to replace the first " 1." with a "500.2" and the second "
> 1." with " 5.2" ...
>
> What pythonic means would you all recommend?

l = l.replace(" 1.", "500.2", 1)
l = l.replace(" 1.", "5.2", 1)


--
Steven


== 2 of 2 ==
Date: Wed, Mar 3 2010 12:49 am
From: Peter Otten <__peter__@web.de>


Ben Racine wrote:

> Say I have a string "l" ...
>
> l = 'PBUSH 201005 K 1. 1. 1. 1. 1.
> 1.'
>
> And I want to replace the first " 1." with a "500.2" and the second "
> 1." with " 5.2" ...
>
> What pythonic means would you all recommend?

With regular expressions:

>>> import re
>>> replacements = iter(["one", "two", "three"])
>>> re.compile("replaceme").sub(lambda m: next(replacements), "foo replaceme
bar replaceme baz replaceme bang")
'foo one bar two baz three bang'

With string methods:

>>> replacements = iter(["", "one", "two", "three"])
>>> "".join(a + b for a, b in zip(replacements, "foo replaceme bar replaceme
baz replaceme bang".split("replaceme")))
'foo one bar two baz three bang'

Peter

==============================================================================
TOPIC: python 2.6: how to modify a PIL image from C without copying forth and
back
http://groups.google.com/group/comp.lang.python/t/c456d88ea2773a7e?hl=en
==============================================================================

== 1 of 4 ==
Date: Wed, Mar 3 2010 12:43 am
From: News123


Hi Tim,

Tim Roberts wrote:
> News123 <news123@free.fr> wrote:
>> I created a grayscale image with PIL.
>>
>> Now I would like to write a C function, which reads a;most all pixels
>> and will modify a few of them.
>>
>> My current approach is:
>> - transform the image to a string()
>> - create a byte array huge enough to contain the resulting image
>> - call my c_function, which copies over the entire image in order
>> to modify a few pixels
>> How can I achieve this with the least amount of copies?
>
> If it were me, I'd be tempted to go peek at the source code for PIL, then
> pass the Image object to my C routine and poke at the innards to find the
> buffer with the pixels.

Yes, this might be an option
Somehow though it didn't feel right for me to depend on internal non
documented data types, which might change between releases of PIL.

N


== 2 of 4 ==
Date: Wed, Mar 3 2010 1:10 am
From: Stefan Behnel


News123, 03.03.2010 01:38:
> I created a grayscale image with PIL.
>
> Now I would like to write a C function, which reads a;most all pixels
> and will modify a few of them.
>
> My current approach is:
> - transform the image to a string()
> - create a byte array huge enough to contain the resulting image
> - call my c_function, which copies over the entire image in order
> to modify a few pixels
> How can I achieve this with the least amount of copies?

Take a look at Cython instead, it will allow you to access PIL's image
buffer directly, instead of copying the data. It will also simplify and
speed up your C wrapper code.

Stefan

== 3 of 4 ==
Date: Wed, Mar 3 2010 1:37 am
From: News123


Hi Stefan,

Stefan Behnel wrote:
> News123, 03.03.2010 01:38:
>> I created a grayscale image with PIL.
>>
>> Now I would like to write a C function, which reads a;most all pixels
>> and will modify a few of them.
>>
>> My current approach is:
>> - transform the image to a string()
>> - create a byte array huge enough to contain the resulting image
>> - call my c_function, which copies over the entire image in order
>> to modify a few pixels
>> How can I achieve this with the least amount of copies?
>
> Take a look at Cython instead, it will allow you to access PIL's image
> buffer directly, instead of copying the data. It will also simplify and
> speed up your C wrapper code.
>
> Stefan
>

I don't know Cython. Having looked at the web site I'm not entirely
sure, I understood your suggestion.

Do you mean
- to stay with Python 2.6 and to implement only my extension in Cython.
This might be very attractive. If yes, can you recommend some url's /
tutorials / etc. which might help to implement a cython extension for
python2.6. which reads and modifies a pixel of a PIL image.

or do you mean
- to switch entirely from Python 2.6 to Cython. I would be reluctant to
do so, as I have already a lot of existing code. and I do not have the
time to check the entire code base for portability issues

thanks in advance


N


== 4 of 4 ==
Date: Wed, Mar 3 2010 2:10 am
From: Stefan Behnel


News123, 03.03.2010 10:37:
> Stefan Behnel wrote:
>> Take a look at Cython instead, it will allow you to access PIL's image
>> buffer directly, instead of copying the data. It will also simplify and
>> speed up your C wrapper code.
>
> I don't know Cython. Having looked at the web site I'm not entirely
> sure, I understood your suggestion.
>
> Do you mean
> - to stay with Python 2.6 and to implement only my extension in Cython.

Absolutely.


> This might be very attractive. If yes, can you recommend some url's /
> tutorials / etc. which might help to implement a cython extension for
> python2.6. which reads and modifies a pixel of a PIL image.

Check out the tutorial on the web site, and ask on the cython-users mailing
list about integration with PIL. I'm sure you'll get some useful examples.

Here's something closely related, although it doesn't really use PIL (but
the mechanisms are the same):

http://wiki.cython.org/examples/mandelbrot


> or do you mean
> - to switch entirely from Python 2.6 to Cython. I would be reluctant to
> do so, as I have already a lot of existing code. and I do not have the
> time to check the entire code base for portability issues

The nice thing about Cython is that you always have a normal CPython
interpreter running, so you can split your code between the interpreter and
the compiler at any level of granularity. However, the advice was really to
write your image processing algorithm in Cython, not your entire program.

Stefan


==============================================================================
TOPIC: Image.frombuffer and warning
http://groups.google.com/group/comp.lang.python/t/ee441d531cec25fe?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Mar 3 2010 1:05 am
From: Peter Otten <__peter__@web.de>


News123 wrote:

> I am using the PIL function from_buffer in python 2.6.4
>
> I am having the line
> im2 = Image.frombuffer('L',(wx,wy),buf)
>
>
> I receive the warning:
>> ./pytest.py:63: RuntimeWarning: the frombuffer defaults may change in
> a future release; for portability, change the call to read:
>> frombuffer(mode, size, data, 'raw', mode, 0, 1)
>> im2 = Image.frombuffer('L',(wx,wy),buf)
>
>
> Naively I assumed, that changing my code to
>
>
> im2 = Image.frombuffer('L',(wx,wy),buf,'raw','L',0,1)
>
>
> should fix the issue:
>
> However I receive exactly the same error as before.
>
> What am I doing wrong?

I cannot reproduce the problem:

$ cat frombuffer.py
import sys
import Image
wx = 3
wy = 2
buf = "a"*wx*wy
if "--fixed" in sys.argv:
Image.frombuffer("L", (wx, wy), buf, "raw", "L", 0, 1)
else:
Image.frombuffer("L", (wx, wy), buf)

$ python frombuffer.py
frombuffer.py:9: RuntimeWarning: the frombuffer defaults may change in a
future release; for portability, change the call to read:
frombuffer(mode, size, data, 'raw', mode, 0, 1)
Image.frombuffer("L", (wx, wy), buf)
$ python frombuffer.py --fixed
$ python -c"import Image; print Image.VERSION"
1.1.6
$ python -V
Python 2.6.4

Peter


== 2 of 2 ==
Date: Wed, Mar 3 2010 1:44 am
From: News123


Hi Peter,

Peter Otten wrote:
> News123 wrote:
> I cannot reproduce the problem:
>
> $ cat frombuffer.py
> import sys
> import Image
> wx = 3
> wy = 2
> buf = "a"*wx*wy
> if "--fixed" in sys.argv:
> Image.frombuffer("L", (wx, wy), buf, "raw", "L", 0, 1)
> else:
> Image.frombuffer("L", (wx, wy), buf)
>
> $ python frombuffer.py
> frombuffer.py:9: RuntimeWarning: the frombuffer defaults may change in a
> future release; for portability, change the call to read:
> frombuffer(mode, size, data, 'raw', mode, 0, 1)
> Image.frombuffer("L", (wx, wy), buf)
> $ python frombuffer.py --fixed
> $ python -c"import Image; print Image.VERSION"
> 1.1.6
> $ python -V
> Python 2.6.4
>
> Peter

You're absolutely right. It was my error.
I shouldn't do any lat night coding :-(.

I fixed one frombuffer() statement, but overlooked a second one in my
code :-(


Apologies


N

==============================================================================
TOPIC: conditional import into global namespace
http://groups.google.com/group/comp.lang.python/t/8718bce88cea1cf5?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 1:17 am
From: "Diez B. Roggisch"


Am 02.03.10 21:41, schrieb mk:
> Jerry Hill wrote:
>> Just import subprocess at the top of your module. If subprocess
>> hasn't been imported yet, it will be imported when your module is
>> loaded. If it's already been imported, your module will use the
>> cached version that's already been imported.
>>
>> In other words, it sounds like Python already does what you want. You
>> don't need to do anything special.
>
> Oh, thanks!
>
> Hmm it's different than dealing with packages I guess -- IIRC, in
> packages only code in package's __init__.py was executed?

I don't understand this. But there is no difference regarding caching &
execution between packages and modules.

Importing a package will execute the __init__.py, yes. But only once. As
will importing modules execute them, but only once.

All subsequent imports will just return the created module-object.
Unless you import something under a new name! That is, you can alter the
sys.path and then import a package/module under a different name -
python won't detect that.

Simplest example ist this:

---- test.py ----

class Foo(object):

pass

if __name__ == "__main__":
import test # import ourselves
# this holds, because we have
# __main__.Foo and test.Foo
assert Foo is not test.Foo

---- test.py ----

However, unless you mess with python, this is none of your concern.

Diez

==============================================================================
TOPIC: Interest check in some delicious syntactic sugar for "except:pass"
http://groups.google.com/group/comp.lang.python/t/b493c6208ea724a2?hl=en
==============================================================================

== 1 of 4 ==
Date: Wed, Mar 3 2010 1:27 am
From: Oren Elrad


Howdy all, longtime appreciative user, first time mailer-inner.

I'm wondering if there is any support (tepid better than none) for the
following syntactic sugar:

silence:
........ block

------------------------->

try:
........block
except:
........pass

The logic here is that there are a ton of "except: pass" statements[1]
floating around in code that do not need to be there. Meanwhile, the
potential keyword 'silence' does not appear to be in significant use
as a variable[2], or an alternative keyword might be imagined
('quiet', 'hush', 'stfu') but I somewhat like the verbiness of
'silence' since that is precisely what it does to the block (that is,
you have to inflect it as a verb, not a noun -- you are telling the
block to be silent). Finally, since this is the purest form of
syntactic sugar, I cannot fathom any parsing, interpreting or other
complications that would arise.

I appreciate any feedback, including frank statements that you'd
rather not trifle with such nonsense.

~Oren

[1] http://www.google.com/codesearch?q=except%3A\spass&hl=en
[2] http://www.google.com/codesearch?hl=en&lr=&q=silence+lang%3Apy


== 2 of 4 ==
Date: Wed, Mar 3 2010 2:25 am
From: Chris Rebert


On Wed, Mar 3, 2010 at 1:27 AM, Oren Elrad <orenelrad@gmail.com> wrote:
> Howdy all, longtime appreciative user, first time mailer-inner.
>
> I'm wondering if there is any support (tepid better than none) for the
> following syntactic sugar:
>
> silence:
> ........ block
>
> ------------------------->
>
> try:
> ........block
> except:
> ........pass
>
> The logic here is that there are a ton of "except: pass" statements[1]
> floating around in code that do not need to be there.

So, why exactly should the language /encourage/ unnecessary error
silencing? (which is what the proposed sugar would do)

> I appreciate any feedback

Applicable rules of The Zen[1] that the proposal arguably violates:
*Special cases aren't special enough to break the rules.
*There should be one-- and preferably only one --obvious way to do it.

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

[1]: http://www.python.org/dev/peps/pep-0020/


== 3 of 4 ==
Date: Wed, Mar 3 2010 2:40 am
From: Dave Angel


Oren Elrad wrote:
> Howdy all, longtime appreciative user, first time mailer-inner.
>
> I'm wondering if there is any support (tepid better than none) for the
> following syntactic sugar:
>
> silence:
> ........ block
>
> ------------------------->
>
> try:
> ........block
> except:
> ........pass
>
> The logic here is that there are a ton of "except: pass" statements[1]
> floating around in code that do not need to be there. Meanwhile, the
> potential keyword 'silence' does not appear to be in significant use
> as a variable[2], or an alternative keyword might be imagined
> ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of
> 'silence' since that is precisely what it does to the block (that is,
> you have to inflect it as a verb, not a noun -- you are telling the
> block to be silent). Finally, since this is the purest form of
> syntactic sugar, I cannot fathom any parsing, interpreting or other
> complications that would arise.
>
> I appreciate any feedback, including frank statements that you'd
> rather not trifle with such nonsense.
>
> ~Oren
>
> [1] http://www.google.com/codesearch?q=except%3A\spass&hl=en
> [2] http://www.google.com/codesearch?hl=en&lr=&q=silence+lang%3Apy
>
>
I presume you know that there's a feature freeze on for Python. So such
an idea wouldn't be considered for at least a couple of years. But that
shouldn't inhibit such discussions.

I wonder if you're intending that silence: denotes a block in which all
exceptions would be ignored. And that any calls made from there that
threw exceptions would also be ignored.

If so, it's a bad idea. Only if you could qualify it to a particular
exception list might it be reasonable. As it stands, it's just as bad
as the bare try/except that you were already given. Do you really want
to ignore syntax errors, skip bad data, and ignore missing files, and
generally plow down whatever execution path happens to result?


Just my opinion.
DaveA


== 4 of 4 ==
Date: Wed, Mar 3 2010 3:02 am
From: Andre Engels


On Wed, Mar 3, 2010 at 10:27 AM, Oren Elrad <orenelrad@gmail.com> wrote:
> Howdy all, longtime appreciative user, first time mailer-inner.
>
> I'm wondering if there is any support (tepid better than none) for the
> following syntactic sugar:
>
> silence:
> ........ block
>
> ------------------------->
>
> try:
> ........block
> except:
> ........pass
>
> The logic here is that there are a ton of "except: pass" statements[1]
> floating around in code that do not need to be there. Meanwhile, the
> potential keyword 'silence' does not appear to be in significant use
> as a variable[2], or an alternative keyword might be imagined
> ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of
> 'silence' since that is precisely what it does to the block (that is,
> you have to inflect it as a verb, not a noun -- you are telling the
> block to be silent). Finally, since this is the purest form of
> syntactic sugar, I cannot fathom any parsing, interpreting or other
> complications that would arise.
>
> I appreciate any feedback, including frank statements that you'd
> rather not trifle with such nonsense.

I would be against this, because "except: pass" is a terrible code
smell. Usage of exceptions can roughly be divided into two areas:

1. Cases where you do know quite well what might go wrong
2. Cases where all kind of stuff might go wrong, including things you
perhaps did not think of, and want to deal with all of them

In the first case, you should not use a blanket "except", but a more
specific one, catching only the specific error or errors you are
dealing with.

In the second case, a blanket except might well be correct, but in
that case, you should not want to pass over the error silently.
Usually you will want to notify the user that an error has occurred.
Even if that is not the case, you want to make some kind of logging of
the error, so that you have the chance of finding it if it is indeed
an unexpected (and therefore undoubtedly also unintended) error.

Doing a pass over an exception is not a bad thing in itself, but one
should only do it when one _knows_ that it is the right action to
take. If you have a general exception, you don't know _what_ has gone
wrong, so you sure as hell cannot be sure about what's the best action
to take. Doing nothing might well be your best guess, but even in that
case I want to know that your program has been guessing when I use it.

--
André Engels, andreengels@gmail.com

==============================================================================
TOPIC: Docstrings considered too complicated
http://groups.google.com/group/comp.lang.python/t/dea5c94f3d058e26?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 1:40 am
From: BlueBird


On Feb 24, 9:23 pm, Andreas Waldenburger <use...@geekmail.INVALID>
wrote:
> Hi all,
>
> a company that works with my company writes a lot of of their code in
> Python (lucky jerks). I've seen their code and it basically looks like
> this:
>
> """Function that does stuff"""
> def doStuff():
>     while not wise(up):
>         yield scorn
>
> Now my question is this: How do I kill these people without the
> authorities thinking they didn't deserve it?

If they are generating their doc with doxygen, I think it's the right
choice. See:

http://www.stack.nl/~dimitri/doxygen/docblocks.html#pythonblocks

Oops, after a second look, doxygen needs comments before the function,
not doc strings.

Philippe

==============================================================================
TOPIC: exp_internal in pexpect
http://groups.google.com/group/comp.lang.python/t/998910a6e13bda92?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 1:50 am
From: Pankaj


how to enable expect log in pexpect ? (similar as exp_internal in
expect)

==============================================================================
TOPIC: PYTHONPATH and eggs
http://groups.google.com/group/comp.lang.python/t/f40da95d87441720?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 2:14 am
From: geoffbache


Hi all,

I have a very simple problem that seems to have no simple solution.

I have a module which is installed centrally and lives in a Python
egg. I have experimented with some minor changes to it and would like
to set my PYTHONPATH to pick up my local copy of it, but don't want to
have to figure out how to build my own version of the "egg" if
possible.

Unfortunately, the location from PYTHONPATH ends up after the eggs in
sys.path so I can't persuade Python to import my version. The only way
I've found to fix it is to copy the main script and manually hack
sys.path at the start of it which isn't really very nice. I wonder if
there is any better way as I can't be the first person to want to do
this, surely?

I've seen this issue has been discussed elsewhere and flagged as a
problem (e.g.
http://mail.python.org/pipermail/distutils-sig/2009-January/010755.html)

but I've been unable to find any suggestions for workarounds or
indications whether this will be/has been fixed.

Regards,
Geoff Bache

==============================================================================
TOPIC: Method / Functions - What are the differences?
http://groups.google.com/group/comp.lang.python/t/72ab93ba395822ed?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 2:56 am
From: Bruno Desthuilliers


Eike Welk a �crit :
> John Posner wrote:
>> I've updated the text at this location:
>>
>> > http://cl1p.net/bruno_0301.rst/
>
> I think this is a very useful writeup!
>
> It would be perfect with a little bit of introduction that says:
> 1. - What it is: "The rough details of method look-up";
> 2. - which contains some of the questions that that made that authors write
> the text. This way people with similar questions can find it with Google.
>

John, do you think you could something with the following ?

"""
"Is it a function ? is it a method ? No, it's... " - or : What's in a
Python method ?

Python newcomers often have hard time understanding the "magic" behind
Python's methods - and truth is that Python's object model can be a bit
peculiar when compared to most mainstream (or not-so-mainstream) OOPLs.
As a matter of fact, there are quite a few threads on c.l.py with either
direct or indirect questions about what makes a Python method, and I
must have explained the whole mechanism at least 3 or 4 times there. The
following text is an edited version of my last attempt, as edited,
corrected and published by John Posner, MayHisNameBePraised(tm).

This text isn't meant as a replacement for neither the official
FineManual(tm)[XXX : relevant link] nor the very excellent - if somehow
technical - 'Descriptors how-to' [XXX : relevant link]. It's mostly a
brief but hopefully helpful overview of what exactly is a Python method,
and how Python magically inserts the 'self' or 'cls' argument to method
calls.
"""

Feel free to edit / amend / rewrite / trash at will - you're now
officially in charge of publishing this text !-)


==============================================================================
TOPIC: Re Interest check in some delicious syntactic sugar for "except:pass"
http://groups.google.com/group/comp.lang.python/t/0041fb118a65a722?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 3:47 am
From: Oren Elrad


To all that responded, thanks for the prompt response folks, your
criticisms are well taken. Coming from Cland, one is inculcated with
the notion that if the programmer wants to shoot himself in the foot
the language ought not to prevent that (or even should return him a
loaded magnum with the safety off and the hair-trigger pulled). My
apologies for not immediately grokking the cultural difference in
pytown.

With that said, let me at least offer a token defense of my position.
By way of motivation, I wrote that email after copying/pasting the
following a few times around a project until I wrote it into def
SilentlyDelete() and its cousin SilentlyRmdir()

""" code involving somefile """
try:
........os.remove(somefile)
except:
.......pass # The bloody search indexer has got the file and I
can't delete it. Nothing to be done.

Certainly the parade of horribles (bad files! corrupt data! syntax
errors!) is a tad melodramatic. Either os.remove() succeeds or it
doesn't and the execution path (in the estimation of this programmer,
at least) is not at all impacted by whether it succeeds or fails. I
know with certainty at compile time what exceptions might be raised
and what the consequences of passing them are and there is no sense
pestering the user or sweating over it. Nor can I see the logic, as
was suggested, in writing "except OSError:" since (seems to me) mere
surplusage -- it neither causes a semantic difference in the way the
program runs nor provides anything useful to the reader.

Now, perhaps this is a special case that is not nearly special enough
to warrant its own syntactic sugar, I granted that much, but >30,000
examples in Google Code cannot be considered to be a complete corner
case either. Briefly skimming those results, most of them seem to be
of this flavor, not the insane programmer that wants to write
"silence: CommitDBChangesEmailWifeAndAdjustBankAccount()" nor novices
that aren't aware of what they might be ignoring.

At any rate (and since this is far more words than I had intended), I
want to reiterate that the criticism is well-taken as a cultural
matter. I just don't want everyone to think I'm bloody insane or that
I'm not aware this is playing with fire. Maybe we can put it in module
"YesImSureJustBloodyDoItAlreadyGoddamnit" and prints an ASCII skull
and crossbones to the console when imported? :-P

~ Oren

PS. I did like Dave's suggestions that one might want to write
"silence Type1 Type2:" which I suppose goes a long way towards
alleviating the concern that the programmer doesn't know what he's
missing. Doesn't quite meet my desire (both syntaxes would be nice, of
course) to avoid the verbiage involved with explaining to the compiler
(or the next reader) something that it knows well enough by now (or
ought to know, at least).

==============================================================================
TOPIC: monkey patching with @classmethod
http://groups.google.com/group/comp.lang.python/t/2290ae917e52fd44?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 3 2010 3:57 am
From: gentlestone


Hi, is there some well-known problems with class method monkey
patching?

I've got this error message:

unbound method get_pocet_neocislovanych() must be called with Pozemok
instance as first argument (got Subjekt instance instead)

The method is declared as:
@classmethod
@monkeypatch(Dokument)
def get_pocet_neocislovanych(cls, subjekt):
return cls.objects.filter(subjekt = subjekt, cislo__isnull =
True).count() # or pass, this line is not important

and the monkey patch decorator is declared as:
def monkeypatch(cls):
def decorator(func):
setattr(cls, func.__name__, func)
return func
return decorator

If I move the method to class declaration (whitout monkey patching),
everything is ok, but only if I've restarted the server.


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

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