Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Rustom Mody
On Sunday, September 4, 2016 at 11:18:07 AM UTC+5:30, Rustom Mody wrote:
> On Sunday, September 4, 2016 at 9:32:28 AM UTC+5:30, Veek. M wrote:
> > Regarding the name (From field), my name *is* Veek.M though I tend to 
> > shorten it to Vek.M on Google (i think Veek was taken or some such 
> > thing). Just to be clear, my parents call me something closely related 
> > to Veek that is NOT Beek or Peek or Squeak or Sneak and my official name 
> > is something really weird. Identity theft being what it is, I probably 
> > am lying anyhow about all this, but it sounds funny so :p
> 
> Please dont take the name-police bait.
> As far as I am concerned telling someone “I dont like your name” is in the 
> same
> bracket as “I don’t like your religion/skin-color/gender/nationality/etc”
> Ie its highly offensive

Sorry...
That should have been just “offensive” not “highly offensive”
Too much disorder in the world from people ratcheting up their expressions 
beyond appropriate levels.
And since I am at it let me correct more precisely:
Namism — Thomas ‘bogus-appelation’ Lahn’s affliction — lies between
mildly amusing and mildly offensive as does 
racism/sexism/casteism/nationalism/etc

Einstein’s “Nationalism is an infantile disease; its the measles of mankind” 
should be applied to all such
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange behaviour with numbers in exponential notation

2016-09-04 Thread Nobody
On Fri, 02 Sep 2016 18:18:08 +0200, Christian Gollwitzer wrote:

> 1e26 denotes a *floating point number* Floating point has finite 
> precision, in CPython it is a 64bit IEEE number. The largest exact 
> integer there is 2**53 (~10^16), everything beyond cannot be accurately 
> represented.

Uh, that's wrong. All integers smaller than 2**53 can be represented
exactly. Some, but not all, of the integers above 2**53 can be represented
exactly.

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


manually sorting images?

2016-09-04 Thread Ulli Horlacher
I need to sort images (*.jpg), visually, not by file name.
It looks, there is no standard UNIX tool for this job?

So, I have to write one by myself, using Tkinter.

Are there any high-level widgets which can help me, for example a file
browser with thumbnails?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: manually sorting images?

2016-09-04 Thread Thomas 'PointedEars' Lahn
Ulli Horlacher wrote:

> I need to sort images (*.jpg), visually, not by file name.
> It looks, there is no standard UNIX tool for this job?

Depends.  What are the sort keys?

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: manually sorting images?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 06:53 pm, Ulli Horlacher wrote:

> I need to sort images (*.jpg), visually, not by file name.

I don't even understand this. What does it mean to sort images visually?
Which comes first, a 400x500 image of a cat climbing a tree, or a 300x600
image of a toddler playing with a dog?




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 06:53 pm, Thomas 'PointedEars' Lahn wrote:

>> Regarding the name (From field), my name *is* Veek.M […]
> 
> Liar.  *plonk*

You have crossed a line now Thomas.

That is absolutely uncalled for. You have absolutely no legitimate reason to
believe that Veek is not his or her real name.

You owe Veek an apology, and a promise to the entire community that you will
not act in such a bigoted, racist manner again.



-- 
Steve

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


Why doesn't my finaliser run here?

2016-09-04 Thread Steve D'Aprano
Here's a finaliser that runs:


class Spam(object):
def __new__(cls):
instance = object.__new__(cls)
print("instance created successfully")
return instance
def __del__(self):
print("deleting", repr(self))


An example:


py> s = Spam(); del s
instance created successfully
deleting <__main__.Spam object at 0xb7bf270c>



Why doesn't __del__ run here?


class Eggs(object):
def __new__(cls):
instance = object.__new__(cls)
print("instance created successfully")
return instance
def __init__(self):
print("self definitely exists:", self)
raise Exception
def __del__(self):
print("deleting", repr(self))


And an example:


py> e = Eggs()
instance created successfully
self definitely exists: <__main__.Eggs object at 0xb7bf21ec>
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 8, in __init__
Exception
py>





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Why doesn't my finaliser run here?

2016-09-04 Thread Ben Finney
Steve D'Aprano  writes:

> Why doesn't __del__ run here?

Short anser: because nothing has removed the reference to the instance.

> class Eggs(object):
> def __new__(cls):
> instance = object.__new__(cls)
> print("instance created successfully")
> return instance
> def __init__(self):
> print("self definitely exists:", self)
> raise Exception
> def __del__(self):
> print("deleting", repr(self))

This is a good example of why it helps to *never* call ‘__init__’ the
“constructor”. It isn't, because ‘__init__’ acts on an
already-constructed instance.

Hance, an exception raised from ‘__init__’ is not going to affect
whether the instance exists.

> And an example:
>
>
> py> e = Eggs()
> instance created successfully
> self definitely exists: <__main__.Eggs object at 0xb7bf21ec>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 8, in __init__
> Exception
> py>


Right. The instance is constructed successfully (by ‘__new__’, the
constructor). It will be bound to ‘s’, creating a reference to the
instance.

The exception raised from the initialiser does not stop you from binding
the instance to a name. That binding succeeds; the reference remains.
Nothing has caused that reference to go away.

-- 
 \   “I know that we can never get rid of religion …. But that |
  `\   doesn’t mean I shouldn’t hate the lie of faith consistently and |
_o__) without apology.” —Paul Z. Myers, 2011-12-28 |
Ben Finney

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


Re: Why doesn't my finaliser run here?

2016-09-04 Thread Oscar Benjamin
On 4 Sep 2016 13:27, "Steve D'Aprano"  wrote:
>
> Why doesn't __del__ run here?
>
>
> class Eggs(object):
> def __new__(cls):
> instance = object.__new__(cls)
> print("instance created successfully")
> return instance
> def __init__(self):
> print("self definitely exists:", self)
> raise Exception
> def __del__(self):
> print("deleting", repr(self))
>
>
> And an example:
>
>
> py> e = Eggs()
> instance created successfully
> self definitely exists: <__main__.Eggs object at 0xb7bf21ec>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 8, in __init__
> Exception

Maybe the Exception traceback holds a reference to the object. Also try the
example outside of interactive mode since that can hold references.

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't my finaliser run here?

2016-09-04 Thread Chris Angelico
On Sun, Sep 4, 2016 at 10:37 PM, Ben Finney  wrote:
>> And an example:
>>
>>
>> py> e = Eggs()
>> instance created successfully
>> self definitely exists: <__main__.Eggs object at 0xb7bf21ec>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "", line 8, in __init__
>> Exception
>> py>
>
>
> Right. The instance is constructed successfully (by ‘__new__’, the
> constructor). It will be bound to ‘s’, creating a reference to the
> instance.
>
> The exception raised from the initialiser does not stop you from binding
> the instance to a name. That binding succeeds; the reference remains.
> Nothing has caused that reference to go away.

Presumably you mean "bound to 'e'" here. But it isn't; the expression
Eggs() raised an exception, so nothing got assigned anywhere. It
doesn't depend on __new__ either:

>>> class Eggs:
...  def __init__(self):
...   print("init:", self)
...   raise Exception
...  def __del__(self):
...   print("del:", self)
...
>>> e=Eggs()
init: <__main__.Eggs object at 0x7ffa8fc97400>
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 4, in __init__
Exception
>>> e
del: <__main__.Eggs object at 0x7ffa8fc97400>
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'e' is not defined

There's a reference here somewhere, though. My suspicion is it's in
sys.exc_info / sys.last_traceback, which is why triggering another
exception causes the object to be cleaned up.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange behaviour with numbers in exponential notation

2016-09-04 Thread Christian Gollwitzer

Am 04.09.16 um 10:29 schrieb Nobody:

On Fri, 02 Sep 2016 18:18:08 +0200, Christian Gollwitzer wrote:


1e26 denotes a *floating point number* Floating point has finite
precision, in CPython it is a 64bit IEEE number. The largest exact
integer there is 2**53 (~10^16), everything beyond cannot be accurately
represented.


Uh, that's wrong. All integers smaller than 2**53 can be represented
exactly. Some, but not all, of the integers above 2**53 can be represented
exactly.


Agreed. That's what I wanted to say. Of course you can represent 2**327 
exactly in 64 bit binary floating point. The point is, that you can't 
sensibly assumy to get exact integer results for numbers beyond 2**53 - 
except for special cases. For example, 133 * 2**53 is exactly 
representable in FP, but 2**53+1 is not.


Christian

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


Re: manually sorting images?

2016-09-04 Thread Christian Gollwitzer

Am 04.09.16 um 10:53 schrieb Ulli Horlacher:

I need to sort images (*.jpg), visually, not by file name.
It looks, there is no standard UNIX tool for this job?

So, I have to write one by myself, using Tkinter.

Are there any high-level widgets which can help me, for example a file
browser with thumbnails?



There is an example file browser that comes with tktreectrl:

http://tktreectrl.sourceforge.net/pics/imovie.png

Not sure, if there are (good) Python bindings to tktreectrl.
I've written such a beast myself in pure Tcl/Tk (with an extension to 
resize images for the thumbnails):


http://auriocus.de/slideshow/

- maybe it helps.

Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Veek. M
Steve D'Aprano wrote:

> On Sun, 4 Sep 2016 06:53 pm, Thomas 'PointedEars' Lahn wrote:
> 
>>> Regarding the name (From field), my name *is* Veek.M […]
>> 
>> Liar.  *plonk*
> 
> You have crossed a line now Thomas.
> 
> That is absolutely uncalled for. You have absolutely no legitimate
> reason to believe that Veek is not his or her real name.
> 
> You owe Veek an apology, and a promise to the entire community that
> you will not act in such a bigoted, racist manner again.
> 
> 
> 

ah umm.. I'm not overly offended - it was more of a startle. I've gotten 
used to USENET, somewhat - nature of the beast. 

Here's a link: 
https://www.eff.org/deeplinks/2010/01/primer-information-theory-and-privacy

Apparently 33 bits of information are enough to identify you. I don't 
bother about the NSA, but plenty of shady scummy types around, so I tend 
to spread misinformation which *would* make me a big time liar. It's not 
a besetting sin.

Here's a link to my Youtube thingy: 
https://www.youtube.com/channel/UCj93gHgUt69R8oGE5hRXd9g

Really, if someone's feeling racist, hire someone of your own kind 
(whatever that is) to kick you and make you study - that way, you are 
more in control of your destiny. There's plenty of energy the sun kick 
out that just goes to waste. (Not the easiest thing to do - finding 
someone reliable enough to zap the toes, anyway..) It's rather 
unreasonable for humans to expect the Universe to spin around them 
indefinitely..

If there are trolls here, then:
https://www.psychologytoday.com/blog/your-online-secrets/201409/internet-trolls-are-narcissists-psychopaths-and-sadists
(scientific study of some sort)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Larry Hudson via Python-list

On 09/04/2016 09:00 AM, Veek. M wrote:

Steve D'Aprano wrote:


On Sun, 4 Sep 2016 06:53 pm, Thomas 'PointedEars' Lahn wrote:


Regarding the name (From field), my name *is* Veek.M […]


Liar.  *plonk*


You have crossed a line now Thomas.

That is absolutely uncalled for. You have absolutely no legitimate
reason to believe that Veek is not his or her real name.

You owe Veek an apology, and a promise to the entire community that
you will not act in such a bigoted, racist manner again.





ah umm.. I'm not overly offended - it was more of a startle. I've gotten
used to USENET, somewhat - nature of the beast.



If you continue to read this forum, you will quickly learn to ignore "Pointy-Ears".  He rarely 
has anything worth while to post, and his unique fetish about Real Names shows him to be a 
hypocrite as well.


--
 -=- Larry -=-
--
https://mail.python.org/mailman/listinfo/python-list


Re: *args and **kwargs

2016-09-04 Thread Matt Ruffalo
On 2016-09-02 15:44, Ben Finney wrote:
> Note that this has nothing to do with how the function is defined; in
> the definition of the function, parameters are neither positional nor
> keyword. You name each of them, and you define an order for them; and
> neither of those makes any of them “positional” or “keyword”.
> Rather, “positional argument and “keyword argument” are characteristics of 
> the arguments you *supply* in a particular call to the function.
>

To be fair, this isn't quite the case. One can define keyword-only
arguments, which must be supplied as such and don't really have an "order":

"""
>>> def f(arg1, arg2, *, arg3=None):
... pass
...
>>> f(1, 2, 3)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: f() takes 2 positional arguments but 3 were given
"""

One can even omit the default argument for something keyword-only, which
results in the consistent-but-initially-surprising situation of having a
required keyword argument:

"""
>>> def g(arg1, arg2, *, arg3):
... pass
...
>>> g(1, 2, 3)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: g() takes 2 positional arguments but 3 were given
"""

MMR...
-- 
https://mail.python.org/mailman/listinfo/python-list


Question about abstract base classes and abstract properties -- Python 2.7

2016-09-04 Thread Gerald Britton
I was rereading the 2.7 docs  about abstract base classes the other day.  I
found this:

"This defines a read-only property; you can also define a read-write
abstract property using the ‘long’ form of property declaration:"

along with an example.  so I copied the example and put in a little
surrounding code:


from abc import ABCMeta, abstractproperty

class C:
__metaclass__ = ABCMeta
def getx(self): pass
def setx(self, value): pass
x = abstractproperty(getx, setx)

class D(C):
@property
def x(self):self._x

d = D()
print(d)

When I ran this, I expected an exception, since I defined a read/write
abstract property but only implemented the read operation.  However, the
example runs fine. That is the class D can be instantiated without error.
Of course I cannot set the property since I didn't implement that part.

Now, If I don't implement the property at all, I can' instantiate the
class.  I get:

"TypeError: Can't instantiate abstract class D with abstract methods x"

which is what I would expect.  What I don't understand is why I don't get a
similar error when I implement the read operation for the property but not
the write operation.

If this actually doesn't work (catching the non-implementation at
instantiation time), then why is it documented this way.  To me at least
the doc implies that it *will* raise on the missing write property
implementation.

Is this a doc bug, an  ABC bug or just me? (I've been known to be buggy
from time to time!)

-- 
Gerald Britton, MCSE-DP, MVP
LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: manually sorting images?

2016-09-04 Thread Gregory Ewing

Quivis wrote:
2. You want to sort them according to red houses, blue houses, green 
trees, yellow trees (that's autumn leaves), cats, dogs, children, elderly 
people,


But... but... what if you have a picture of a child
playing with a dog that's chasing an elderly cat up a
yellow tree in front of a blue house? What category do
you put it in?

The algorithm has been insufficiently specified!

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Gregory Ewing

Larry Hudson wrote:
If you continue to read this forum, you will quickly learn to ignore 
"Pointy-Ears".  He rarely has anything worth while to post, and his 
unique fetish about Real Names shows him to be a hypocrite as well.


To be fair, it's likely that Thomas Lahn is his real
name, and he's never claimed that one shouldn't also
include a nickname in one's posted identifier.

So Veek should be able to appease P.E. by calling
himself 'Veek "David Smith" M'. The quotes clearly
mark the middle part as an invented addition, so
he's not lying, and it looks enough like a Western
style real name to avoid triggering P.E.'s "fake name"
reflex. :-)

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Ned Batchelder
On Saturday, September 3, 2016 at 7:55:48 AM UTC-4, Veek. M wrote:
> https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm
> 
> Wanted to know if the above link idea, had been implemented and if 
> there's a module that accepts a pattern like 'cap' and give you all the 
> instances of unicode 'CAP' characters.
>  ⋂ \bigcap
>  ⊓ \sqcap
>  ∩ \cap
>  ♑ \capricornus
>  ⪸ \succapprox
>  ⪷ \precapprox
> 
> (above's from tex)
> 
> I found two useful modules in this regard: unicode_tex, unicodedata
> but unicodedata is a builtin which does not do globs, regexs - so it's 
> kind of limiting in nature.
> 
> Would be nice if you could search html/xml character entity references 
> as well.

The unicodedata module has all the information you need for searching
Unicode character names.  While it doesn't provide regex or globs, it's
all in-memory, so it's not bad for just iterating over the characters
and finding what you need.

But, 'CAP' appears in 'CAPITAL', which gives more than 1800 matches:

>>> for c in range(32, 0x11):
...   try:
... name = unicodedata.name(chr(c))
...   except ValueError:
... continue
...   if 'CAP' in name:
... print(c, name)
...
65 LATIN CAPITAL LETTER A
66 LATIN CAPITAL LETTER B
..
.. many other lines, mostly with CAPITAL in them ..
..
917593 TAG LATIN CAPITAL LETTER Y
917594 TAG LATIN CAPITAL LETTER Z
>>>

These were the character names without "CAPITAL":

8419 COMBINING ENCLOSING KEYCAP
8851 SQUARE CAP
9232 SYMBOL FOR DATA LINK ESCAPE
9243 SYMBOL FOR ESCAPE
9809 CAPRICORN
11839 CAPITULUM
41657 YI SYLLABLE CAP
52290 HANGUL SYLLABLE CAP
66003 PHAISTOS DISC SIGN CAPTIVE
119050 MUSICAL SYMBOL DA CAPO
127750 CITYSCAPE AT DUSK
127891 GRADUATION CAP
127956 SNOW CAPPED MOUNTAIN
127961 CITYSCAPE
128287 KEYCAP TEN
128846 ALCHEMICAL SYMBOL FOR CAPUT MORTUUM

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Chris Angelico
On Mon, Sep 5, 2016 at 9:40 AM, Ned Batchelder  wrote:
> But, 'CAP' appears in 'CAPITAL', which gives more than 1800 matches:
>
> >>> for c in range(32, 0x11):
> ...   try:
> ... name = unicodedata.name(chr(c))
> ...   except ValueError:
> ... continue
> ...   if 'CAP' in name:
> ... print(c, name)
> ...
> 65 LATIN CAPITAL LETTER A
> 66 LATIN CAPITAL LETTER B
> ..
> .. many other lines, mostly with CAPITAL in them ..
> ..
> 917593 TAG LATIN CAPITAL LETTER Y
> 917594 TAG LATIN CAPITAL LETTER Z
> >>>

FWIW, hex is much more common for displaying Unicode codepoints than
decimal is. So I'd print it like this (incorporating the 'not CAPITAL'
filter):

>>> for c in range(32, 0x11):
... try:
... name = unicodedata.name(chr(c))
... except ValueError:
... continue
... if 'CAP' in name and 'CAPITAL' not in name:
... print("U+%04X %s" % (c, name))
...
U+20E3 COMBINING ENCLOSING KEYCAP
U+2293 SQUARE CAP
U+2410 SYMBOL FOR DATA LINK ESCAPE
U+241B SYMBOL FOR ESCAPE
U+2651 CAPRICORN
U+2E3F CAPITULUM
U+A2B9 YI SYLLABLE CAP
U+CC42 HANGUL SYLLABLE CAP
U+101D3 PHAISTOS DISC SIGN CAPTIVE
U+1D10A MUSICAL SYMBOL DA CAPO
U+1F306 CITYSCAPE AT DUSK
U+1F393 GRADUATION CAP
U+1F3D4 SNOW CAPPED MOUNTAIN
U+1F3D9 CITYSCAPE
U+1F51F KEYCAP TEN
U+1F74E ALCHEMICAL SYMBOL FOR CAPUT MORTUUM
>>>

Takes advantage of %04X giving a minimum, but not maximum, of four digits :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: manually sorting images?

2016-09-04 Thread cs

On 05Sep2016 10:09, Greg Ewing  wrote:

Quivis wrote:
2. You want to sort them according to red houses, blue houses, green 
trees, yellow trees (that's autumn leaves), cats, dogs, children, 
elderly people,


But... but... what if you have a picture of a child
playing with a dog that's chasing an elderly cat up a
yellow tree in front of a blue house? What category do
you put it in?

The algorithm has been insufficiently specified!


Yeah. Sounds like he wants a tool that lets him associate tags with images.  
Then he can tag all the photos with all the relevant attributes, then write his 
own classifier/sorted later by examining the tags.


I also suspect the OP is using the word "sort" to mean "classify" (eg "what 
sort of thing is this?") versus is more common programming meaning of 
"ordering".  Would be good to clarify that.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Ned Batchelder
On Sunday, September 4, 2016 at 7:52:44 PM UTC-4, Chris Angelico wrote:
> FWIW, hex is much more common for displaying Unicode codepoints than
> decimal is. So I'd print it like this (incorporating the 'not CAPITAL'
> filter):

You are right, I went too quickly, and didn't realize until after I
posted that I had printed decimal instead of hex.

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't my finaliser run here?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 10:37 pm, Ben Finney wrote:

> Steve D'Aprano  writes:
> 
>> Why doesn't __del__ run here?
> 
> Short anser: because nothing has removed the reference to the instance.

Hmmm. You're probably right, but not for the reason you think :-)


>> class Eggs(object):
>> def __new__(cls):
>> instance = object.__new__(cls)
>> print("instance created successfully")
>> return instance
>> def __init__(self):
>> print("self definitely exists:", self)
>> raise Exception
>> def __del__(self):
>> print("deleting", repr(self))
> 
> This is a good example of why it helps to *never* call ‘__init__’ the
> “constructor”. It isn't, because ‘__init__’ acts on an
> already-constructed instance.

I don't believe I did call it the constructor :-)


> Hance, an exception raised from ‘__init__’ is not going to affect
> whether the instance exists.
> 
>> And an example:
>>
>>
>> py> e = Eggs()
>> instance created successfully
>> self definitely exists: <__main__.Eggs object at 0xb7bf21ec>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "", line 8, in __init__
>> Exception
>> py>
> 
> 
> Right. The instance is constructed successfully (by ‘__new__’, the
> constructor). It will be bound to ‘s’, creating a reference to the
> instance.

Bound to `s`? Did you mean `e`?

It's certainly not bound to `e`, since that is unbound. I went back to my
interpreter session and tried to view the value of `e`, and as I expected,
it was unbound:


py> e
deleting <__main__.Eggs object at 0xb7bf21ec>
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'e' is not defined


So it looks like what may have been holding onto the reference to the Eggs
instance was the exception or traceback, and once that got
garbage-collected (by me causing a new exception and traceback) the
finaliser ran.

Which both Oscar and Chris suggested, thanks guys!

So this isn't definite proof, but it is very suggestive that the thing
holding onto the reference to the half-built Eggs instance is something to
do with the exception.


> The exception raised from the initialiser does not stop you from binding
> the instance to a name. That binding succeeds; the reference remains.
> Nothing has caused that reference to go away.

That bit is actually wrong. Given:

name = expression

an exception in `expression` prevents the binding to `name` from occurring
at all. If `name` already existed, then it remains untouched, and if it
didn't it remains unbound.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Michael Torrie
On 09/04/2016 04:22 PM, Gregory Ewing wrote:
> Larry Hudson wrote:
>> If you continue to read this forum, you will quickly learn to ignore 
>> "Pointy-Ears".  He rarely has anything worth while to post, and his 
>> unique fetish about Real Names shows him to be a hypocrite as well.
> 
> To be fair, it's likely that Thomas Lahn is his real
> name, and he's never claimed that one shouldn't also
> include a nickname in one's posted identifier.
> 
> So Veek should be able to appease P.E. by calling
> himself 'Veek "David Smith" M'. The quotes clearly
> mark the middle part as an invented addition, so
> he's not lying, and it looks enough like a Western
> style real name to avoid triggering P.E.'s "fake name"
> reflex. :-)

Or better yet just ignore his posts entirely.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: manually sorting images?

2016-09-04 Thread Michael Torrie
On 09/04/2016 04:09 PM, Gregory Ewing wrote:
> Quivis wrote:
>> 2. You want to sort them according to red houses, blue houses, green 
>> trees, yellow trees (that's autumn leaves), cats, dogs, children, elderly 
>> people,
> 
> But... but... what if you have a picture of a child
> playing with a dog that's chasing an elderly cat up a
> yellow tree in front of a blue house? What category do
> you put it in?

And this is the weakness in all photo sorting schemes (human schemes
that is).  Some people try organizing folders, others try tagging.
Neither system works that well.  Tags sound good in theory, but in
practice they suck almost as much as folders.  Actually all tag-based
indexing systems suck, even for things like ebooks and music.  Keeping
tags consistent is difficult, and making them complete is impossible.
Maybe computer vision will ease this difficulty, but I kind of doubt it.

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


Re: Why doesn't my finaliser run here?

2016-09-04 Thread Ben Finney
Steve D'Aprano  writes:

> On Sun, 4 Sep 2016 10:37 pm, Ben Finney wrote:
>
> > Short anser: because nothing has removed the reference to the
> > instance.
>
> Hmmm. You're probably right, but not for the reason you think :-)

Thanks to those who corrected some details in my explanation.

> > This is a good example of why it helps to *never* call ‘__init__’
> > the “constructor”. It isn't, because ‘__init__’ acts on an
> > already-constructed instance.
>
> I don't believe I did call it the constructor :-)

You have advocated that in the past, though :-) I am presenting this as
a counter-example: ‘__init__’ does not act as the constructor, so it's
needlessly misleading to refer to it that way.

> > Right. The instance is constructed successfully (by ‘__new__’, the
> > constructor). It will be bound to ‘s’, creating a reference to the
> > instance.
>
> Bound to `s`? Did you mean `e`?

I did. And yes, that was incorrect: the assignment statement does not
complete because the exception interrupts it. So ‘e’ is not a reference
to the instance.

> So it looks like what may have been holding onto the reference to the
> Eggs instance was the exception or traceback, and once that got
> garbage-collected (by me causing a new exception and traceback) the
> finaliser ran.
>
> Which both Oscar and Chris suggested, thanks guys!

Indeed. Thanks for dissecting the right and wrong parts :-)

The larger point which remains true: Don't think of ‘__init__’ as a
constructor, all it does is work on an *already-constructed* instance.

The ‘__new__’ method is the constructor. The instance doesn't exist
before that method is called; if successful, the instance is constructed
and returned.

The ‘__init__’ method is the initialiser. It receives the
already-constructed instance, and returns ‘None’. That doesn't affect
existing references to the instance.

-- 
 \  “Shepherds … look after their sheep so they can, first, fleece |
  `\   them and second, turn them into meat. That's much more like the |
_o__)  priesthood as I know it.” —Christopher Hitchens, 2008-10-29 |
Ben Finney

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


Re: Why doesn't my finaliser run here?

2016-09-04 Thread Chris Angelico
On Mon, Sep 5, 2016 at 11:48 AM, Ben Finney  wrote:
> The larger point which remains true: Don't think of ‘__init__’ as a
> constructor, all it does is work on an *already-constructed* instance.
>
> The ‘__new__’ method is the constructor. The instance doesn't exist
> before that method is called; if successful, the instance is constructed
> and returned.
>
> The ‘__init__’ method is the initialiser. It receives the
> already-constructed instance, and returns ‘None’. That doesn't affect
> existing references to the instance.

It doesn't really matter, though. Here's the outside view of
constructing a class:

instance = Class()

Doesn't matter how it's implemented; you call something and you either
get an instance back, or catch an exception.

While it's technically true that __init__ raising an exception won't
affect existing references to that instance, it's almost immaterial.
You generally won't implement __new__ to retain refs, and you
generally won't call __init__ again after the instance has been fully
constructed. Generally, you can assume that an exception in __init__
means you can safely dispose of the object.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: manually sorting images?

2016-09-04 Thread Ulli Horlacher
Quivis  wrote:
> On Sun, 04 Sep 2016 21:32:47 +1000, Steve D'Aprano wrote:
> 
> >  What does it mean to sort images visually?
> 
> 1. A directory of images collected over say, five years.
> 
> 2. You want to sort them according to red houses, blue houses, green 
> trees, yellow trees (that's autumn leaves), cats, dogs, children, elderly 
> people, and so on, and rename them using some scheme you invented.
> 
> 3. AFAIK there are no algorithms to do that with any higher degree of 
> certainty, so you have to look through them and sort them manually. 
> Usually using thumbnails.

Exactly.
The purpose is to generate a list for llgal (a HTML gallery creating tool).
llgal makes a good job, but has no GUI for manually sorting.

Geeqie, you mentioned before, does nearly exactly what I want, but it does not
respect the locale when writing the filename collection. 
It always writes UTF8.

Ok, I can convert the filenames later by (python) script using the correct
locale.

The job is now:

call "geekie ."
user creates the collection and saves it
read the collection file (*)
convert the file names according to locale
prefix filenames with number (renaming)
call "llgal ..."

(*) Problem: how do I know which filename the user has choosen for the
 collection?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't my finaliser run here?

2016-09-04 Thread Gregory Ewing

Chris Angelico wrote:

There's a reference here somewhere, though. My suspicion is it's in
sys.exc_info / sys.last_traceback,


It's sys.last_traceback:

>>> e = Eggs()
instance created successfully
('self definitely exists:', <__main__.Eggs object at 0x2b6670>)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 8, in __init__
Exception
>>> sys.last_traceback = None
('deleting', '<__main__.Eggs object at 0x2b6670>')
>>>

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list