comp.lang.python - 25 new messages in 12 topics - digest
comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en
comp.lang.python@googlegroups.com
Today's topics:
* More stuff added to ch 2 of my programming intro - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/12728334858e25c3?hl=en
* power of explicit self? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/17a3369aef70fd38?hl=en
* Moving from PHP to Python. Is it Possible - 5 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/6e91d87a9a3a3edb?hl=en
* eiger replacement? - 2 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/dc9abec47ba1a604?hl=en
* How can I get the target platform info of a dll with Python 3.1.1? - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/618a63c6f109b6d1?hl=en
* Dangerous behavior of list(generator) - 6 messages, 5 authors
http://groups.google.com/group/comp.lang.python/t/ae70dfa12677c1d5?hl=en
* "katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif kareena
kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina kaif and salman
khan" "kaif katrina blogspot" "bollywood kaif" on http://desi-girls-club.
blogspot.com/ - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a9a69c2e7a789998?hl=en
* Moving from PHP to Python. Part Two - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/4c295a7ca96f65c3?hl=en
* a list/re problem - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/5be177b96856476e?hl=en
* What is the differences between tkinter in windows and Tkinter in the other
platform? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/4556d5688bd67a67?hl=en
* setup.py and PyPI - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d6565f437af3556d?hl=en
* insert unique data in a list - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/80491b9bc2f45547?hl=en
==============================================================================
TOPIC: More stuff added to ch 2 of my programming intro
http://groups.google.com/group/comp.lang.python/t/12728334858e25c3?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Dec 13 2009 11:23 pm
From: "Alf P. Steinbach"
* Alf P. Steinbach:
> Format: PDF
> <url: http://preview.tinyurl.com/ProgrammingBookP3>
>
> The new stuff, section 2.7, is about programs as simulations and
> handling data, focusing on modeling things. It includes some Python GUI
> programming. The plan is to discuss containers like lists and
> dictionaries in perhaps two more subsections of 2.7, but I'm not quite
> sure about how to approach that or exactly how much to cover, since the
> intent of ch 2 is to introduce mostly general concepts and enable the
> reader to try out (more or less) interesting things.
>
>
> Cheers,
>
> - Alf
>
> PS: comments welcome!
Well, I posted the current doc. It has a not yet quite complete section 2.7.7
about arrays, and that will be the last subsection of the chapter. I thought
using the Josephus circle problem as example was pretty neat... :-)
But anyway, comments welcome, even if that last section's not yet finished.
Cheers,
- Alf
PS: Oh, I changed the manuscript title to "Intelligent Person's Intro to
Programming" -- is that good?
==============================================================================
TOPIC: power of explicit self?
http://groups.google.com/group/comp.lang.python/t/17a3369aef70fd38?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Dec 14 2009 1:14 am
From: Bruno Desthuilliers
Fire Crow a écrit :
> I'm looking for an explanation of how explicit self is implimented
It's not "implemented" - it's just the first argument of the function,
and you have to declare it explicitely in the function's args list.
If your question is about how "obj.func()" becomes
"obj.___class__.func(obj)", then the answer is "protocol deescriptor" +
"method type". The function type implements the protocol descriptor so
that its __get__ method returns a method instance which wraps around the
function, class and instance. Then the method's __call__ method will
delegate to the function, injecting the instance as first positional param.
> and
> what features are only possible because of, or are greatly improved,
> because of it.
Simplicity (methods are built of the combination of two "general
purpose" features - descriptor protocol and callable objects),
flexibility (you can use any callable object as a 'method' as long as it
correctly implements the descriptor protocol), and of course readability
(no special rules wrt/ 'self', it's nothing else than the first argument
of the function, period).
Oh, and yes - you can use methods as functions too, it's sometimes handy
for dispatching purposes !-)
== 2 of 2 ==
Date: Mon, Dec 14 2009 4:56 am
From: Carl Banks
On Dec 12, 12:20 pm, Fire Crow <m...@firecrow.com> wrote:
> > It's not implemented in the compiler. There's a place in the runtime
> > for invoking a method where the object is inserted at the beginning
> > of the parameter list. IIRC, that's done by wrapping the function
> > object.
>
> This is the source of Objects/methodobject.c it look like this is
> where
> self is added to the argument list, but I'll have to do some more
> digging.
No, not really. That code sets the self argument only for functions
implemented in C.
The code that implements self behavior for Python methods is mostly
found in the file classobject.c. Basically whenever a method is
accessed through an object, the object creates an instancemethod for
it. The instancemethod type is defined in classobject.c.
Carl Banks
==============================================================================
TOPIC: Moving from PHP to Python. Is it Possible
http://groups.google.com/group/comp.lang.python/t/6e91d87a9a3a3edb?hl=en
==============================================================================
== 1 of 5 ==
Date: Mon, Dec 14 2009 1:17 am
From: Bruno Desthuilliers
zeph a écrit :
(snip)
> 4) It's better to collect all your eventual output into a string that
> you print
Yuck ! Definitly one of the worst advises you could give.
<OP>
By all mean, *DONT* do that. Use a templating system instead.
</OP>
== 2 of 5 ==
Date: Mon, Dec 14 2009 1:20 am
From: "Diez B. Roggisch"
> Yes, I understood. And I'm using large Global dictionary (or Array) to
> replicate those objects. State of the thing will store in there. But it
> wasn't an object. Just Assocative array. Staying in global space,
>
> Because.
>
> In web programming we do not store anything except session. Every object we
> created was destroyed after execution. Using objects in this conditions was
> non sense to me. (of course I'm not very capable programmer probably it was my
> fault to take full advantage of oo programming)
>
> Plus. In php we can store arrays in files very easy. Combining this with any
> PHP opcode cache can save those arrays in memory. So we got damn cheap state
> saver.
This is possible in python, too. But "damn cheap"... well, the cheapest
solution in terms of speed is to just keep the things in memory. Which
you can't do with PHP, as everything lives just one request, but in
Python with certain app-servers, you can do this.
>
> Of course things may differ in python.
>
> Anyhow I generate a Registry class to replicate global dictionary. Probably it
> much better than my PHP Direct $GLOBAL usage.
>
> So I have no problem with that.
>
>>> Anyway, I need to save my lots and lots of config variables in dictionary
>>> style global accessible location.
>>>
>>> Because.
>>>
>>> In my design We got lots of plugins, and those plugins may show in
>>> multiple times and multiple locations in a page.
>>>
>>> Each plugin may have setup values to affect entire page output.
>>>
>>> Because of this. I have to put those values in global location for future
>>> use.
>> No, you don't. Because of this, you can e.g. use ToscaWidgets as a
>> framework for creating widgets that encapsulate code, HTML, javascript
>> and CSS. And no global state is shared.
>>
>> Also, I think you should *really* look into one of the available
>> web-frameworks such as Django or Turbogears to learn how to write
>> webapps in python - instead of shoehorning your tried & trusted PHP
>> techniques that don't translate well.
>>
>
> Yes I download the django trying to learn but it was much different.
>
> My problem is not writing web apps. I'm doing well.
>
> My design was very good and I'm very proud its abilities.
>
> My problem is with PHP syntax and performance.
>
> I'm just trying to replicate my recepies in python...
Then the result will be a twice as horrible program in python. Because
you work against the language.
In the end of course, what matters is what works for you.
Diez
== 3 of 5 ==
Date: Mon, Dec 14 2009 1:22 am
From: Bruno Desthuilliers
Sancar Saran a écrit :
(snip)
> My problem is with PHP syntax and performance.
> I'm just trying to replicate my recepies in python...
Python is not PHP, and trying to write PHP in Python won't buy you much
except pain and frustration.
== 4 of 5 ==
Date: Mon, Dec 14 2009 1:59 am
From: r0g
Bruno Desthuilliers wrote:
> Sancar Saran a écrit :
> (snip)
>> My problem is with PHP syntax and performance. I'm just trying to
>> replicate my recepies in python...
>
> Python is not PHP, and trying to write PHP in Python won't buy you much
> except pain and frustration.
I think people are being a little harsh here. Replicating exactly what
PHP code does on a micro level i.e. line by line is probably a bad idea
but for all we know a lot of the macro level stuff might be fine, or
mostly fine i.e. structures, algorithms, classes and functions etc.
If this is the case rewriting the same bits in Python might not be
painful and frustrating, indeed seeing how much terser those things can
be written in Python would probably be quite satisfying.
Of course, some PHP is never going to port well but you can't say for
sure without seeing it.
Roger.
== 5 of 5 ==
Date: Mon, Dec 14 2009 3:25 am
From: Bruno Desthuilliers
r0g a écrit :
> Bruno Desthuilliers wrote:
>> Sancar Saran a écrit :
>> (snip)
>>> My problem is with PHP syntax and performance. I'm just trying to
>>> replicate my recepies in python...
>> Python is not PHP, and trying to write PHP in Python won't buy you much
>> except pain and frustration.
>
>
> I think people are being a little harsh here. Replicating exactly what
> PHP code does on a micro level i.e. line by line is probably a bad idea
> but for all we know a lot of the macro level stuff might be fine, or
> mostly fine i.e. structures, algorithms, classes and functions etc.
I was talking about trying to replicate PHP's execution model and idioms
in Python - the "framework" part -, not about application specific
algos, data structures etc.
==============================================================================
TOPIC: eiger replacement?
http://groups.google.com/group/comp.lang.python/t/dc9abec47ba1a604?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Dec 14 2009 1:56 am
From: Robin Becker
On 12/12/2009 05:38, Tim Roberts wrote:
> Steven D'Aprano<steve@REMOVE-THIS-cybersource.com.au> wrote:
>
>> On Fri, 11 Dec 2009 17:45:24 +0000, Robin Becker wrote:
>>
>>> The current hardware
>>>
>>> CPU: Intel(R) Pentium(R) 4 CPU 2.40GHz (2394.01-MHz 686-class CPU)
>> [...]
>>
>> What does this have to do with Python?
>
> I'm guessing Robin had a slight address book malfunction when he sent this.
indeed, an excess of Christmas Spirit as well. Never a doh! moment should be
passed by.
Sorry for any confusion
--
Robin Becker
== 2 of 2 ==
Date: Mon, Dec 14 2009 1:56 am
From: Robin Becker
On 12/12/2009 05:38, Tim Roberts wrote:
> Steven D'Aprano<steve@REMOVE-THIS-cybersource.com.au> wrote:
>
>> On Fri, 11 Dec 2009 17:45:24 +0000, Robin Becker wrote:
>>
>>> The current hardware
>>>
>>> CPU: Intel(R) Pentium(R) 4 CPU 2.40GHz (2394.01-MHz 686-class CPU)
>> [...]
>>
>> What does this have to do with Python?
>
> I'm guessing Robin had a slight address book malfunction when he sent this.
indeed, an excess of Christmas Spirit as well. Never a doh! moment should be
passed by.
Sorry for any confusion
--
Robin Becker
==============================================================================
TOPIC: How can I get the target platform info of a dll with Python 3.1.1?
http://groups.google.com/group/comp.lang.python/t/618a63c6f109b6d1?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Dec 14 2009 2:25 am
From: W00D00
On dec. 12, 03:18, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
> En Fri, 11 Dec 2009 16:39:37 -0300, Isti <istvan.szir...@gmail.com>
> escribió:
>
> > I have manydllfiles and I would like to select them into two
> > different folders (PC and PPC). For this I need to know the target
> > platform of thedllfile or any other details about its platform.
>
> Look at sys.platform and the platform module.
>
> --
> Gabriel Genellina
Hi,
The platform module gives you information about the platform where you
are running on with your script and not about the not loaded dll(s).
So, thanks but, this does not work in this case.
However, I found a solution:
def DLLIdentifier( self ):
'''
Microsoft Portable Executable and Common Object File Format
Specification
http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
After the MS DOS stub, at the file offset specified at offset
0x3c,
is a 4-byte signature that identifies the file as a PE format
image file.
This signature is "PE\0\0" (the letters "P" and "E" followed
by two null bytes).
At the beginning of an object file, or immediately after the
signature of an image file,
is a standard COFF file header in the following format.
Note that the Windows loader limits the number of sections to
96.
The Machine field has one of the following values that
specifies its CPU type.
An image file can be run only on the specified machine or on
a system that emulates the specified machine.
'''
Platform = 'UNKNOWN'
for Row in codecs.open( os.path.join( self.Root, self.File ),
'rb' ):
if b'\x00PE\x00\x00' in Row:
# IMAGE_FILE_MACHINE_UNKNOWN 0x0 The
contents of this field are assumed to be applicable to any machine
type
if b'\x00PE\x00\x00\x00\x00' in Row:
Platform = 'UNKNOWN'
break
# IMAGE_FILE_MACHINE_AM33 0x1d3
Matsushita AM33
elif b'\x00PE\x00\x00\xD3\x01' in Row:
Platform = 'AM33'
break
# IMAGE_FILE_MACHINE_AMD64 0x8664 x64
elif b'\x00PE\x00\x00\x664\x08' in Row:
Platform = 'AMD64'
break
# IMAGE_FILE_MACHINE_ARM 0x1c0 ARM
little endian
elif b'\x00PE\x00\x00\xC0\x01' in Row:
Platform = 'ARM'
break
# IMAGE_FILE_MACHINE_EBC 0xebc EFI byte
code
elif b'\x00PE\x00\x00\xBC\x0E' in Row:
Platform = 'EBC'
break
# IMAGE_FILE_MACHINE_I386 0x14c Intel
386 or later processors and compatible processors
elif b'\x00PE\x00\x00\x4C\x01' in Row:
Platform = 'I386'
break
# IMAGE_FILE_MACHINE_IA64 0x200 Intel
Itanium processor family
elif b'\x00PE\x00\x00\x00\x02' in Row:
Platform = 'IA64'
break
# IMAGE_FILE_MACHINE_M32R 0x9041
Mitsubishi M32R little endian
elif b'\x00PE\x00\x00\x041\x09' in Row:
Platform = 'M32R'
break
# IMAGE_FILE_MACHINE_MIPS16 0x266 MIPS16
elif b'\x00PE\x00\x00\x66\x02' in Row:
Platform = 'MIPS16'
break
# IMAGE_FILE_MACHINE_MIPSFPU 0x366 MIPS
with FPU
elif b'\x00PE\x00\x00\x66\x03' in Row:
Platform = 'MIPSFPU'
break
# IMAGE_FILE_MACHINE_MIPSFPU16 0x466 MIPS16
with FPU
elif b'\x00PE\x00\x00\x66\x04' in Row:
Platform = 'MIPSFPU16'
break
# IMAGE_FILE_MACHINE_POWERPC 0x1f0 Power PC
little endian
elif b'\x00PE\x00\x00\xF0\x01' in Row:
Platform = 'POWERPC'
break
# IMAGE_FILE_MACHINE_POWERPCFP 0x1f1 Power PC
with floating point support
elif b'\x00PE\x00\x00\xF1\x01' in Row:
Platform = 'POWERPCFP'
break
# IMAGE_FILE_MACHINE_R4000 0x166 MIPS
little endian
elif b'\x00PE\x00\x00\x66\x01' in Row:
Platform = 'R4000'
break
# IMAGE_FILE_MACHINE_SH3 0x1a2 Hitachi
SH3
elif b'\x00PE\x00\x00\xA2\x01' in Row:
Platform = 'SH3'
break
# IMAGE_FILE_MACHINE_SH3DSP 0x1a3 Hitachi
SH3 DSP
elif b'\x00PE\x00\x00\xA3\x01' in Row:
Platform = 'SH3DSP'
break
# IMAGE_FILE_MACHINE_SH4 0x1a6 Hitachi
SH4
elif b'\x00PE\x00\x00\xA6\x01' in Row:
Platform = 'SH4'
break
# IMAGE_FILE_MACHINE_SH5 0x1a8 Hitachi
SH5
elif b'\x00PE\x00\x00\xA8\x01' in Row:
Platform = 'SH5'
break
# IMAGE_FILE_MACHINE_THUMB 0x1c2 Thumb
elif b'\x00PE\x00\x00\xC2\x01' in Row:
Platform = 'THUMB'
break
# IMAGE_FILE_MACHINE_WCEMIPSV2 0x169 MIPS
little - endian WCE v2
elif b'\x00PE\x00\x00\x69\x01' in Row:
Platform = 'WCEMIPSV2'
break
else:
StartIndex = Row.find( b'\x00PE\x00\x00' )
EndIndex = StartIndex + 7
PlatformCode = Row[StartIndex:EndIndex]
self.ErrorState = False
self.oLogger.critical( 'The unknown platform code
is "{}".'.format( PlatformCode ) )
assert Platform != 'UNKNOWN', 'Unknown .dll file "{}" at\n
{}'.format( self.File, os.path.join( self.Root, self.File ) )
if Platform == 'I386':
self.PlatformType = 'PC'
elif Platform in ( 'ARM', 'THUMB' ):
self.PlatformType = 'PPC'
else:
self.ErrorState = False
self.oLogger.critical( 'The unknown dll file with "{}"
platform code.'.format( Platform ) )
==============================================================================
TOPIC: Dangerous behavior of list(generator)
http://groups.google.com/group/comp.lang.python/t/ae70dfa12677c1d5?hl=en
==============================================================================
== 1 of 6 ==
Date: Mon, Dec 14 2009 2:26 am
From: Lie Ryan
On 12/14/09, exarkun@twistedmatrix.com <exarkun@twistedmatrix.com> wrote:
> On 02:50 am, lie.1296@gmail.com wrote:
>>On 12/14/2009 9:45 AM, exarkun@twistedmatrix.com wrote:
>>>On 08:18 pm, steve@remove-this-cybersource.com.au wrote:
>>>>On Sun, 13 Dec 2009 14:35:21 +0000, exarkun wrote:
>>>>>>StopIteration is intended to be used only within the .__next__
>>>>>>method of
>>>>>>iterators. The devs know that other 'off-label' use results in the
>>>>>>inconsistency you noted, but their and my view is 'don't do that'.
>>>>>
>>>>>Which is unfortunate, because it's not that hard to get
>>>>>StopIteration
>>>>>without explicitly raising it yourself and this behavior makes it
>>>>>difficult to debug such situations.
>>>>
>>>>I can't think of any way to get StopIteration without explicitly
>>>>raising
>>>>it yourself. It's not like built-ins or common data structures
>>>>routinely
>>>>raise StopIteration. I don't think I've *ever* seen a StopIteration
>>>>that
>>>>I didn't raise myself.
>>>
>>>Call next on an iterator. For example: iter(()).next()
>>
>>.next() is not meant to be called directly
>
> Doesn't matter. Sometimes it makes sense to call it directly. And I
> was just giving an example of a way to get StopIteration raised without
> doing it yourself - which is what Steve said he couldn't think of.
>>>
>>>I'm surprised to hear you say that the magical faerie land behavior
>>>isn't desirable either, though. I'd love a tool that did what I
>>>wanted,
>>>not what I asked. The only serious argument against this, I think, is
>>>that it is beyond our current ability to create (and so anyone
>>>claiming
>>>to be able to do it is probably mistaken).
>>
>>In your world, this is what happens:
>> >>> list = [a, b, c]
>> >>> # print list
>> >>> print list
>>["a", "b", "c"]
>> >>> # make a copy of list
>> >>> alist = list(llst) # oops a mistype
>> >>> alist = alist - "]" + ", "d"]"
>> >>> print alist
>>["a", "b", "c", "d"]
>> >>> alist[:6] + "i", + alist[6:]
>> >>> print alist
>>["a", "i", "b", "c", "d"]
>> >>> print alist
>> >>> # hearing the sound of my deskjet printer...
>> >>> C:\fikle.text.write(alist)
>> >>> print open("C:\file.txt").read()
>><h1>a</h1>
>><ul>
>><li>i</li>
>><li>b</li>
>><li>c d</li>
>> >>> # great, exactly what I needed
>
> I don't understand the point of this code listing, sorry. I suspect you
> didn't completely understand the magical faerie land I was describing -
> where all your programs would work, no matter what mistakes you made
> while writing them.
Exactly, that's what's happening. It just works. It knows that when I
said alist[:6] + "i", + alist[6:] ; I want to insert "i" between the
sixth character of the textual representation of the list. It knows to
find the correct variable when I made a typo. It correctly guess that
I want to print to a paper instead of to screen. It knows that when I
wrote to C:\path.write(), it knows I wanted a HTML output in that
specific format. It just works (TM), whatever mistakes I made. That's
what you wanted, right?
== 2 of 6 ==
Date: Mon, Dec 14 2009 2:35 am
From: Peter Otten <__peter__@web.de>
Terry Reedy wrote:
> On 12/13/2009 11:33 PM, exarkun@twistedmatrix.com wrote:
>> This could provide behavior roughly equivalent to the behavior
>> of a list comprehension.
>
> Impossible. The only serious option for consistency is to special case
> list comps to also trap StopIteration raised in the expression part, but
> the devs decided not to do this as doing do is arguably a bug.
A viable option might be to introduce a different exception type and
translate
(expr(v) for v in items if cond(v))
into
def gen(items, expr, cond):
for v in items:
try:
if cond(v):
yield expr(v)
except StopIteration:
raise TypeError("StopIteration raised in "
"'expr' or 'cond' part of "
"a generator expression")
Peter
== 3 of 6 ==
Date: Mon, Dec 14 2009 6:31 am
From: exarkun@twistedmatrix.com
On 06:46 am, tjreedy@udel.edu wrote:
>On 12/13/2009 10:29 PM, exarkun@twistedmatrix.com wrote:
>>Doesn't matter. Sometimes it makes sense to call it directly.
>
>It only makes sense to call next (or .__next__) when you are prepared
>to explicitly catch StopIteration within a try..except construct.
>You did not catch it, so it stopped execution.
>
>Let me repeat: StopIteration is intended only for stopping iteration.
>Outside that use, it is a normal exception with no special meaning.
You cut out the part of my message where I wrote that one might have
forgotten the exception handling code that you posit is required, and
that the current behavior makes debugging this situation unnecessarily
challenging.
Jean-Paul
== 4 of 6 ==
Date: Mon, Dec 14 2009 6:58 am
From: "M.-A. Lemburg"
exarkun@twistedmatrix.com wrote:
> On 08:45 am, tjreedy@udel.edu wrote:
>> Tom Machinski wrote:
>>> In most cases, `list(generator)` works as expected. Thus,
>>> `list(<generator expression>)` is generally equivalent to `[<generator
>>> expression>]`.
>>>
>>> Here's a minimal case where this equivalence breaks, causing a serious
>>> and hard-to-detect bug in a program:
>>>
>>> >>> def sit(): raise StopIteration()
>>
>> StopIteration is intended to be used only within the .__next__ method
>> of iterators. The devs know that other 'off-label' use results in the
>> inconsistency you noted, but their and my view is 'don't do that'.
>
> Which is unfortunate, because it's not that hard to get StopIteration
> without explicitly raising it yourself and this behavior makes it
> difficult to debug such situations.
>
> What's with this view, exactly? Is it just that it's hard to implement
> the more desirable behavior?
I'm not exactly sure what you're asking for.
The StopIteration exception originated as part of the for-loop
protocol. Later on it was generalized to apply to generators
as well.
The reason for using an exception is simple: raising and catching
exceptions is fast at C level and since the machinery for
communicating exceptions up the call stack was already there
(and doesn't interfere with the regular return values), this
was a convenient method to let the upper call levels know
that an iteration has ended (e.g. a for-loop 4 levels up the
stack).
I'm not sure whether that answers your question, but it's the
reason for things being as they are :-)
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Dec 14 2009)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
== 5 of 6 ==
Date: Mon, Dec 14 2009 7:21 am
From: exarkun@twistedmatrix.com
On 02:58 pm, mal@egenix.com wrote:
>exarkun@twistedmatrix.com wrote:
>>On 08:45 am, tjreedy@udel.edu wrote:
>>>Tom Machinski wrote:
>>>>In most cases, `list(generator)` works as expected. Thus,
>>>>`list(<generator expression>)` is generally equivalent to
>>>>`[<generator
>>>>expression>]`.
>>>>
>>>>Here's a minimal case where this equivalence breaks, causing a
>>>>serious
>>>>and hard-to-detect bug in a program:
>>>>
>>>> >>> def sit(): raise StopIteration()
>>>
>>>StopIteration is intended to be used only within the .__next__ method
>>>of iterators. The devs know that other 'off-label' use results in the
>>>inconsistency you noted, but their and my view is 'don't do that'.
>>
>>Which is unfortunate, because it's not that hard to get StopIteration
>>without explicitly raising it yourself and this behavior makes it
>>difficult to debug such situations.
>>
>>What's with this view, exactly? Is it just that it's hard to
>>implement
>>the more desirable behavior?
>
>I'm not exactly sure what you're asking for.
>
>The StopIteration exception originated as part of the for-loop
>protocol. Later on it was generalized to apply to generators
>as well.
>
>The reason for using an exception is simple: raising and catching
>exceptions is fast at C level and since the machinery for
>communicating exceptions up the call stack was already there
>(and doesn't interfere with the regular return values), this
>was a convenient method to let the upper call levels know
>that an iteration has ended (e.g. a for-loop 4 levels up the
>stack).
>
>I'm not sure whether that answers your question, but it's the
>reason for things being as they are :-)
I'm asking about why the behavior of a StopIteration exception being
handled from the `expression` of a generator expression to mean "stop
the loop" is accepted by "the devs" as acceptable. To continue your
comparison to for loops, it's as if a loop like this:
for a in b:
c
actually meant this:
for a in b:
try:
c
except StopIteration:
break
Note, I know *why* the implementation leads to this behavior. I'm
asking why "the devs" *accept* this.
Jean-Paul
== 6 of 6 ==
Date: Mon, Dec 14 2009 8:09 am
From: Mel
exarkun@twistedmatrix.com wrote:
[ ... ]
it's as if a loop like this:
>
> for a in b:
> c
>
> actually meant this:
>
> for a in b:
> try:
> c
> except StopIteration:
> break
>
> Note, I know *why* the implementation leads to this behavior. I'm
> asking why "the devs" *accept* this.
It's part of the price Python pays for letting people get their hands on the
controls. Consider also:
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class dict2(dict):
... def __getitem__ (self, key):
... if key == 'fatal':
... raise KeyError
...
>>> d = dict2()
>>> d['fatal'] = 'Hello, world!'
>>> print d['fatal']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __getitem__
KeyError
>>>
"KeyError when we just put the item into the dict?"
"Yep."
Mel.
>
> Jean-Paul
==============================================================================
TOPIC: "katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina kaif and
salman khan" "kaif katrina blogspot" "bollywood kaif" on http://desi-girls-
club.blogspot.com/
http://groups.google.com/group/comp.lang.python/t/a9a69c2e7a789998?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Dec 14 2009 3:48 am
From: Naeem
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
"katrina" "katrina kaif" "katrina kaif wallpapers" "katrina kaif
kareena kapoor" "katrina kaif pictures" "katrina kaif pics" "katrina
kaif and salman khan" "kaif katrina blogspot" "bollywood kaif" on
http://desi-girls-club.blogspot.com/ "katrina" "katrina kaif"
"katrina kaif wallpapers" "katrina kaif kareena kapoor" "katrina kaif
pictures" "katrina kaif pics" "katrina kaif and salman khan" "kaif
katrina blogspot" "bollywood kaif" on http://desi-girls-club.blogspot.com/
v
==============================================================================
TOPIC: Moving from PHP to Python. Part Two
http://groups.google.com/group/comp.lang.python/t/4c295a7ca96f65c3?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Dec 14 2009 4:55 am
From: Sancar Saran
Hello Again.
I hope, I don't bug too much.
First of all. I want to Thank to everyone who respond my messages.
I was able to do some of my needs and stuck some others.
So ? I need help again.
And here my progress..
Following was my globalized registry solution
# -*- coding: utf-8 -*-
class Registry:
data = {}
def __init__(self,environ):
self.data['env'] = environ
self.data['init'] = 'hede'
def set_entry(self,key,data):
self.data[key] = data
def get_entry(self,key):
return self.data[key]
def debug(self):
r = '<pre>'
r += repr(self.data)
r += '</pre>'
return r
I have some questions about this code.
First of all. when execute debug function. It wont work in every request.
# -*- coding: utf-8 -*-
import os, sys, cgi, pprint
import cgitb
cgitb.enable()
def application(environ, start_response):
sys.path.append(environ['DOCUMENT_ROOT']+"core")
import registry, k5
# new registry
r = registry.Registry(environ)
r.set_entry('hede','hodo')
#response_headers = [('Content-type',k5.headers['content-type']+';
charset='+k5.headers['charset'])]
#start_response(kk5.headers['status'], response_headers)
response_body = 'The request method was %s' % environ['REQUEST_METHOD']
response_body += '<br/>'
response_body += r.debug()
status = '200 OK'
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', str(len(response_body)))]
start_response(status, response_headers)
return [response_body]
In first request I can see elements of my registry and second request it was
shows noting. Then 3rd request I can see my registry elements again. next
request was empty too. And it was go like that. I don't understand why ?
Second problem is. Formatting.
I need to see my dictionary elements like this.
[k5req] => Array
(
[raw] => heede
[post] => Array
(
)
[proto] => http://
[base_url] => http://k5.int/?
[bend_url] => http://k5.int/?backend/
[ajax_url] => http://k5.int/?ajax/
[domain] => k5.int
[path] => Array
(
[0] => heede
)
[location] => frontend
[page] => heede
[dom_stat] => 1
)
Is there any available solution (like php's print_r) or have I write to my own
?
And
If I understood correctly PSP template execution in mod_wsgi is impossible. So
I have to look something like cheetah or similar marker based template
systems.
And
If I understood correctly I have to import every module in sub imported
module.
And I want to make sure to my 5 different base module was available every other
sub imported module.
Is there any way to this from do and forget from start ?
Regards.
== 2 of 2 ==
Date: Mon, Dec 14 2009 6:55 am
From: "Diez B. Roggisch"
Sancar Saran wrote:
> Hello Again.
>
> I hope, I don't bug too much.
>
> First of all. I want to Thank to everyone who respond my messages.
>
> I was able to do some of my needs and stuck some others.
>
> So ? I need help again.
>
> And here my progress..
>
> Following was my globalized registry solution
>
> # -*- coding: utf-8 -*-
>
> class Registry:
>
> data = {}
>
> def __init__(self,environ):
> self.data['env'] = environ
> self.data['init'] = 'hede'
>
> def set_entry(self,key,data):
> self.data[key] = data
>
> def get_entry(self,key):
> return self.data[key]
>
> def debug(self):
>
> r = '<pre>'
> r += repr(self.data)
> r += '</pre>'
>
> return r
>
> I have some questions about this code.
>
> First of all. when execute debug function. It wont work in every request.
>
> # -*- coding: utf-8 -*-
>
> import os, sys, cgi, pprint
> import cgitb
> cgitb.enable()
>
>
> def application(environ, start_response):
> sys.path.append(environ['DOCUMENT_ROOT']+"core")
> import registry, k5
> # new registry
>
> r = registry.Registry(environ)
> r.set_entry('hede','hodo')
>
> #response_headers = [('Content-type',k5.headers['content-type']+';
> charset='+k5.headers['charset'])]
> #start_response(kk5.headers['status'], response_headers)
>
> response_body = 'The request method was %s' % environ['REQUEST_METHOD']
> response_body += '<br/>'
> response_body += r.debug()
>
>
> status = '200 OK'
>
> response_headers = [('Content-Type', 'text/plain'),
> ('Content-Length', str(len(response_body)))]
>
> start_response(status, response_headers)
>
>
> return [response_body]
>
> In first request I can see elements of my registry and second request it
> was shows noting. Then 3rd request I can see my registry elements again.
> next request was empty too. And it was go like that. I don't understand
> why ?
>
> Second problem is. Formatting.
>
> I need to see my dictionary elements like this.
>
> [k5req] => Array
> (
> [raw] => heede
> [post] => Array
> (
> )
>
> [proto] => http://
> [base_url] => http://k5.int/?
> [bend_url] => http://k5.int/?backend/
> [ajax_url] => http://k5.int/?ajax/
> [domain] => k5.int
> [path] => Array
> (
> [0] => heede
> )
>
> [location] => frontend
> [page] => heede
> [dom_stat] => 1
> )
>
> Is there any available solution (like php's print_r) or have I write to my
> own ?
import pprint
pprint.pformat({"foo" : 10})
> If I understood correctly I have to import every module in sub imported
> module.
>
> And I want to make sure to my 5 different base module was available every
> other sub imported module.
>
> Is there any way to this from do and forget from start ?
Not really. In python, each module must import whatever dependencies it has.
You *can* put stuff into the __builtins__-namespace, and this will make them
available in each piece of code running.
However, I (and any other sane person on this list) will *STRONGLY* advise
you against doing that - polluting this global namespace will very likely
create collisions which will re-define names and thus introduce nasty bugs.
Python has namespaces. Use them.
Diez
==============================================================================
TOPIC: a list/re problem
http://groups.google.com/group/comp.lang.python/t/5be177b96856476e?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Dec 14 2009 5:38 am
From: Neil Cerutti
On 2009-12-11, Grant Edwards <invalid@invalid.invalid> wrote:
> On 2009-12-11, Neil Cerutti <neilc@norwich.edu> wrote:
>> On 2009-12-11, Grant Edwards <invalid@invalid.invalid> wrote:
>>> [s[1:-1] for s in l if (s[0] == s[-1] == '*')]
>>
>> That last bit doesn't work right, does it, since an == expression
>> evaluates to True or False, no the true or false value itself?
>
> It works for me. Doesn't it work for you?
>
> From the fine manual (section 5.9. Comparisons):
>
> Comparisons can be chained arbitrarily, e.g., x < y <= z is
> equivalent to x < y and y <= z, except that y is evaluated
> only once (but in both cases z is not evaluated at all when x
> < y is found to be false).
I did not know that. Thanks, Grant.
--
Neil Cerutti
==============================================================================
TOPIC: What is the differences between tkinter in windows and Tkinter in the
other platform?
http://groups.google.com/group/comp.lang.python/t/4556d5688bd67a67?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Dec 14 2009 7:02 am
From: Hidekazu IWAKI
Hi, I'm hidekazu.
I'm making a Tk application with python.
In the below code, the class App was inherited from Tkinter.Tk and the
__init__ method calls Tk's constructor with `super` method. In windows,
this code is valid (but, Tkinter -> tkinter).
Why does this code happen a type error in not windows platform?
thank you.
#--------------------------------------------------------
from Tkinter import *
class App(Tk):
def __init__(self):
super(Tk,self).__init__()
App().mainloop()
#Traceback (most recent call last):
# File "./app.py", line 16, in <module>
# App().mainloop()
# File "./app.py", line 7, in __init__
# super(Tk,self).__init__()
#TypeError: super() argument 1 must be type, not classobj
/////////////////////////////////////////////////
岩城 秀和(いわき ひでかず)
e-mail: iwaki@iwakihidekazu.net
/////////////////////////////////////////////////
== 2 of 2 ==
Date: Mon, Dec 14 2009 7:44 am
From: Peter Otten <__peter__@web.de>
Hidekazu IWAKI wrote:
> Hi, I'm hidekazu.
>
> I'm making a Tk application with python.
> In the below code, the class App was inherited from Tkinter.Tk and the
> __init__ method calls Tk's constructor with `super` method. In windows,
> this code is valid (but, Tkinter -> tkinter).
>
> Why does this code happen a type error in not windows platform?
>
> thank you.
>
> #--------------------------------------------------------
> from Tkinter import *
>
> class App(Tk):
> def __init__(self):
> super(Tk,self).__init__()
>
> App().mainloop()
>
> #Traceback (most recent call last):
> # File "./app.py", line 16, in <module>
> # App().mainloop()
> # File "./app.py", line 7, in __init__
> # super(Tk,self).__init__()
> #TypeError: super() argument 1 must be type, not classobj
In Python 2.x Tkinter uses classic classes (classes that do not inherit from
object), and super() can't handle these. In 3.x classic classes are gone,
and tkinter uses newstyle classes. So the behaviour changes from 2.x to 3.x,
but should be the same on all platforms.
Peter
==============================================================================
TOPIC: setup.py and PyPI
http://groups.google.com/group/comp.lang.python/t/d6565f437af3556d?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Dec 14 2009 9:04 am
From: Ethan Furman
Greetings!
I'm using Python 2.5 on Windows XP, and trying to get the upload portion
of setup.py to work. According to what I have found, I can put my info
into a .pypirc file to have the process pick up my username/password and
upload the files.
I have tried putting this file into the same folder I'm running setup.py
from, into my home folder (USERPROFILE, I think) -- and the really
frustrating part is that it worked a couple times (but maybe that was
from my home computer) but mostly it does not.
Any and all pointers gratefully accepted!
~Ethan~
==============================================================================
TOPIC: insert unique data in a list
http://groups.google.com/group/comp.lang.python/t/80491b9bc2f45547?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Dec 14 2009 9:13 am
From: mattia
Il Sun, 13 Dec 2009 21:17:28 -0800, knifenomad ha scritto:
> On 12월14일, 오후12시42분, Steven D'Aprano
> <ste...@REMOVE.THIS.cybersource.com.au> wrote:
>> On Sun, 13 Dec 2009 17:19:17 -0800, knifenomad wrote:
>> > this makes the set type hashable.
>>
>> > class Set(set):
>> > __hash__ = lambda self: id(self)
>>
>> That's a *seriously* broken hash function.
>>
>> >>> key = "voila"
>> >>> d = { Set(key): 1 }
>> >>> d
>>
>> {Set(['i', 'a', 'l', 'o', 'v']): 1}>>> d[ Set(key) ]
>>
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> KeyError: Set(['i', 'a', 'l', 'o', 'v'])
>>
>> --
>> Steven
>
> of course it is broken as long as it uses it's instance id. i added this
> to notify that unhashable can become hashable implementing __hash__
> inside the class. which probably set to None by default.
Ok, nice example, but I believe that using id() as the hash function can
lead to unexpected collisions.
==============================================================================
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