Re: ImSim: Image Similarity

2011-03-05 Thread Grigory Javadyan
At least you could've tried to make the script more usable by adding
the possibility to supply command line arguments, instead of editing
the source every time you want to compare a couple of images.

On Sat, Mar 5, 2011 at 11:23 AM, n00m  wrote:
> Let me present my newborn project (in Python) ImSim:
>
> http://sourceforge.net/projects/imsim/
>
> Its README.txt:
> -
> ImSim is a python script for finding the most similar pic(s) to
> a given one among a set/list/db of your pics.
> The script is very short and very easy to follow and understand.
> Its sample output looks like this:
>
>  bears2.jpg
> 
>  bears2.jpg    0.00
>  bears3.jpg   55.33
>  bears1.jpg   68.87
>    sky1.jpg   83.84
>    sky2.jpg   84.41
>     ff1.jpg   91.35
>   lake1.jpg   95.14
>  water1.jpg   96.94
>     ff2.jpg  102.36
>  roses1.jpg  115.02
>  roses2.jpg  130.02
>
> Done!
>
> The *less* numeric value -- the *more similar* this pic is to the
> tested pic. If this value > 70 almost for sure these pictures are
> absolutely different (from totally different domains, so to speak).
>
> What is "similarity" and how can/could/should it be estimated this
> point I'm leaving for your consideration/contemplation/arguing etc.
>
> Several sample pics (*.jpg) are included into .zip.
> And of course the stuff requires PIL (Python Imaging Library), see:
> Home-page: http://www.pythonware.com/products/pil
> Download-URL: http://effbot.org/zone/pil-changes-116.htm
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fun with 'str' and 'bytes'

2011-03-05 Thread Frank Millman
On Mar 4, 6:40 pm, nn  wrote:
> On Mar 4, 7:32 am, "Frank Millman"  wrote:
>
> > Hi all
>
> > I want to create a cookie containing a session id. In python 2.6 I had the
> > following -
>
> > from __future__ import unicode_literals
> > session_id = b64encode(urandom(20))
> > response_headers.append(
> >     (b'Set-Cookie', b'sid="{0}"'.format(session_id)))
>
> > After upgrading to 3.2, the above lines generate this traceback -
> >     AttributeError: 'bytes' object has no attribute 'format'
>
> > The best workaround I can come up with is the following -
>
> > session_id = b64encode(urandom(20))
> > response_headers.append(
> >     (b'Set-Cookie', b'sid="' + session_id + b'"'))
>
> > It works, but it is not pretty. Is there a more elegant solution?
>
> > Thanks
>
> > Frank Millman
>
> As far as I know, that is pretty much it. Also see:
>
> http://bugs.python.org/issue3982http://mail.python.org/pipermail/python-dev/2010-July/102252.htmlhttp://lucumr.pocoo.org/2010/5/25/wsgi-on-python-3/

Thanks for the response, and for the links - interesting reading.

Frank
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: questions about multiprocessing

2011-03-05 Thread Vincent Ren
Got it.
After putting commas, it works (The 'o' was a mistake when I posted,
sorry about it ).

Thanks to all of you :)


On Mar 5, 5:12 pm, Dennis Lee Bieber  wrote:
> On Fri, 4 Mar 2011 20:08:21 -0800 (PST), Vincent Ren
>  declaimed the following in
> gmane.comp.python.general:
>
> > Hello, everyone, recently I am trying to learn python's
> > multiprocessing, but
> > I got confused as a beginner.
>
> > If I run the code below:
>
> > from multiprocessing import Pool
> > import urllib2
> > otasks = [
> >      'http://www.php.net'
> >      'http://www.python.org'
> >      'http://www.perl.org'
> >      'http://www.gnu.org'
> >      ]
>
>         You've just defined a list with ONE element -- a string of:
>
> "http://www.php.nethttp://www.python.orghttp://www.perl.orghttp://http...";
>
>         Python concatenates adjacent strings -- which includes those on
> multiple lines when inside an open ( [ { structure.
>
>         You need to put commas after the closing quotes on those lines.
>
> > def f(url):
> >      return urllib2.urlopen(url).read()
>
> > pool = Pool(processes = 2)
> > print pool.map(f, tasks)
>
>         And I'm presuming the others are correct -- and that should be
>
> (f, otasks)
>
> > httplib.InvalidURL: nonnumeric port: ''
>
>         No surprise... URL nomenclature expects a port number after the
> second : in URL, and with concatenation you've got four : in a single
> URL.
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfr...@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Re: Problems of Symbol Congestion in Computer Languages

2011-03-05 Thread Xah Lee
On Mar 1, 3:40 pm, Chris Jones  wrote:

> At first it looks like something MS (Morgan Stanley..) dumped into the
> OSS lap fifteen years ago and nobody ever used it or maintained it.. so
> it takes a bit of digging to make it.. sort of work in current GNU/linux
> distributions.. especially since it knows nothing about Unicode.
>
> Here's the X/A+ map I came up with:
>
> // A+ keyboard layout: /usr/share/X11/xkb/symbols/apl
> // Chris Jones - 18/12/2010
>
> // Enable via:
> //      $ setxkbmap -v 10 apl
>
> default
> partial alphanumeric_keys modifier_keys
> xkb_symbols "APL" {
>
>     name[Group1]= "APL";
>
>     // Alphanumeric section
>     key  {  [     grave,    asciitilde,     0x01fe,     0x017e  
>     ]       };
>     key  {  [         1,    exclam,         0x01a1,     0x01e0  
>     ]       };
>     key  {  [         2,    at,             0x01a2,     0x01e6  
>     ]       };
>     key  {  [         3,    numbersign,     0x013c,     0x01e7  
>     ]       };
>     key  {  [         4,    dollar,         0x01a4,     0x01e8  
>     ]       };
>     key  {  [         5,    percent,        0x013d,     0x01f7  
>     ]       };
>     key  {  [         6,    asciicircum,    0x01a6,     0x01f4  
>     ]       };
>     key  {  [         7,    ampersand,      0x013e,     0x01e1  
>     ]       };
>     key  {  [         8,    asterisk,       0x01a8,     0x01f0  
>     ]       };
>     key  {  [         9,    parenleft,      0x01a9,     0x01b9  
>     ]       };
>     key  {  [         0,    parenright,     0x015e,     0x01b0  
>     ]       };
>     key  {  [     minus,    underscore,     0x01ab,     0x0121  
>     ]       };
>     key  {  [     equal,    plus,           0x01df,     0x01ad  
>     ]       };
>
>     key  {  [         q,    Q,              0x013f,     0x01bf  
>     ]       };
>     key  {  [         w,    W,              0x01d7,     Nosymbol    
>     ]       };
>     key  {  [         e,    E,              0x01c5,     0x01e5  
>     ]       };
>     key  {  [         r,    R,              0x01d2,     Nosymbol    
>     ]       };
>     key  {  [         t,    T,              0x017e,     Nosymbol    
>     ]       };
>     key  {  [         y,    Y,              0x01d9,     0x01b4  
>     ]       };
>     key  {  [         u,    U,              0x01d5,     Nosymbol    
>     ]       };
>     key  {  [         i,    I,              0x01c9,     0x01e9  
>     ]       };
>     key  {  [         o,    O,              0x01cf,     0x01ef  
>     ]       };
>     key  {  [         p,    P,              0x012a,     0x01b3  
>     ]       };
>     key  {  [ bracketleft,  braceleft,      0x01fb,     0x01dd  
>     ]       };
>     key  {  [ bracketright, braceright,     0x01fd,     0x01db  
>     ]       };
>
>     key  {  [         a,    A,              0x01c1,     Nosymbol    
>     ]       };
>     key  {  [         s,    S,              0x01d3,     0x01be  
>     ]       };
>     key  {  [         d,    D,              0x01c4,     Nosymbol    
>     ]       };
>     key  {  [         f,    F,              0x015f,     0x01bd  
>     ]       };
>     key  {  [         g,    G,              0x01c7,     0x01e7  
>     ]       };
>     key  {  [         h,    H,              0x01c8,     0x01e8  
>     ]       };
>     key  {  [         j,    J,              0x01ca,     0x01ea  
>     ]       };
>     key  {  [         k,    K,              0x0127,     Nosymbol    
>     ]       };
>     key  {  [         l,    L,              0x01cc,     0x01ec  
>     ]       };
>     key  {  [ semicolon,    colon,          0x01db,     0x01bc  
>     ]       };
>     key  {  [ apostrophe,   quotedbl,       0x01dd,     0x01bb  
>     ]       };
>
>     key  {  [         z,    Z,              0x01da,     0x01fa  
>     ]       };
>     key  {  [         x,    X,              0x01d8,     Nosymbol    
>     ]       };
>     key  {  [         c,    C,              0x01c3,     0x01e3  
>     ]       };
>     key  {  [         v,    V,              0x01d6,     Nosymbol    
>     ]       };
>     key  {  [         b,    B,              0x01c2,     0x01e2  
>     ]       };
>     key  {  [         n,    N,              0x01ce,     0x01ee  
>     ]       };
>     key  {  [         m,    M,              0x017c,     0x01cd  
>     ]       };
>     key  {  [     comma,    less,           0x01ac,     0x013c  
>     ]       };
>     key  {  [    period,    greater,        0x01dc,     0x01ae  
>     ]       };
>     key  {  [     slash,    question,       0x01af,     0x013f  
>     ]       };
>
>     key  {  [ backslash,         bar,       0x01dc,     0x01fc  
>     ]       };
>     key  {  [ Caps_L

Re: getting text out of an xml string

2011-03-05 Thread John Machin
On Mar 5, 8:57 am, JT  wrote:
> On Mar 4, 9:30 pm, John Machin  wrote:
>
> > Your data has been FUABARred (the first A being for Almost) -- the
> > "\u3c00" and "\u3e00" were once "<" and ">" respectively. You will
>
> Hi John,
>
>    I realized that a few minutes after posting.  I then realized that
> I could just extract the text between the stuff with \u3c00 xml
> preserve etc, which I did; it was good enough since it was a one-off
> affair, I had to convert a to-do list from one program to another.
> Thanks for replying and sorry for the noise :-)

Next time you need to extract some data from an xml file, please (for
your own good) don't do whatever you did in that code -- note that the
unicode equivalent of "<" is u"\u003c", NOT u"\u3c00"; I wasn't joking
when I said it had been FU.

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


Re: What do I need to know in order to write a web application in python?

2011-03-05 Thread ErichCart ErichCart
Visual Python seems to be exactly what I want. But it doesn't seem
very popular. Perhaps it means that there are not many people who will
be able to help if I have problems with it. Also judging by the amount
of ads at visualpython.org, it also doesn't seem very serious.

I looked into pyGTK, and I found something called "Glade", which seems
to be something similar to visual python. The latest version of Glade
was released just this month, so it seems to be actively developed.

Regarding Boa constructor, it is very old, isn't it? The latest news
from this project date to the end of 2006. I don't expect it to
support python 3 any time soon.

So, "Glade", is this what everybody uses? I mean programmers don't
just use text editors to make GUI applications, do they?



> That site appears to require a monthly fee, so it may not be a good
> vehicle for demonstrating requirements to a broad audience.

Actually you can play 10 games per day for free, or at least it was
like that when I used it last time. Just enter some random name and
press "start game".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generate PDF with Tamil font problem

2011-03-05 Thread Tom Zych
sathe...@e-ndicus.com wrote:
>I am using python's reportlab to print some unicode Tamil characters
> 'பே'. I added necessary unicode font to reportlab. But It
> prints the output as 'ேப' (in reverse order). This issue
> happens for multi-byte characters, whereas for character 'ப' is
> printed as it is.
> I am struggling to figure out the issue. Any help would see me on track.

Something similar came up on stackoverflow recently, though that was
with tkinter. Might shed some light.

http://stackoverflow.com/questions/5166488/

-- 
Tom Zych / freethin...@pobox.com
"Would you like a lovely fluffy little white rabbit, little girl,
or a cutesy wootesly little brown rabbit?"
"Actually, I don't think my python would notice."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems of Symbol Congestion in Computer Languages

2011-03-05 Thread Albert van der Horst
In article ,
Dotan Cohen   wrote:
>You miss the canonical bad character reuse case: = vs ==.
>
>Had there been more meta keys, it might be nice to have a symbol for
>each key on the keyboard. I personally have experimented with putting
>the symbols as regular keys and the numbers as the Shifted versions.
>It's great for programming.

People might be interested in the colorforth solution:

This goes the other way: characters are limited (lowercase
and few special chars) to what is needed for programming.
So the fingers never need to leave the home position,
reaching about 30 chars at most.
Different uses (defining a function versus using a function)
are indicated by color, so don't use up char's.

http://www.colorforth.com

I was forced to use it (a development environment required it)
and it is not as bad as it sounds.

>--
>Dotan Cohen

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Problem with python 3.2 and circular imports

2011-03-05 Thread Rafael Durán Castañeda
Thank you for your answer Frank, I think I've found the problem. I was
calling modules from inside subpackages, and I need to use them from
outside, so I have package in PYTHONPATH. is that correct? But now I have
another question: Can I execute an script inside subpackage1 importig
modules from subpackage2?

2011/3/4 Frank Millman 

>
> On February 28 2011 Rafael Durán Castañeda wrote
>
>  I'm stil totally stuck with relative imports, i' ve tried the example tree
>> from PEP 328 without any result:
>>
>> package/
>>   __init__.py
>>   subpackage1/
>>   __init__.py
>>   moduleX.py
>>   moduleY.py
>>   subpackage2/
>>   __init__.py
>>   moduleZ.py
>>   moduleA.py
>>
>> Assuming that the current file is either moduleX.py or
>> subpackage1/__init__.py, following are correct usages of the new
>> syntax:
>>
>> from .moduleY import spam
>> from .moduleY import spam as ham
>> from . import moduleY
>> from ..subpackage1 import moduleY
>> from ..subpackage2.moduleZ import eggs
>> from ..moduleA import foo
>> from ...package import bar
>> from ...sys import path
>>
>> I always get:
>>
>> Traceback (most recent call last):
>>  File "moduleY.py", line 1, in 
>>   from ..moduleA import a
>> ValueError: Attempted relative import in non-package
>>
>>
>>
> Hi Rafael
>
> I only just noticed your message now. For some reason it did not appear on
> google.groups.
>
> I just tried it and it worked for me. This is what I did.
>
> I set up the above structure. I added a 'def spam()' to moduleY, 'def
> eggs()' to moduleZ, and 'def foo()' to moduleA.
>
> I pasted all of the 'from ... import ...' lines above into moduleX.
>
> In the same directory that contains the subdirectory 'package' I create a
> test script containing the following line -
>   import package.subpackage1.moduleX
>
> To begin with it failed on the last two lines starting with 'from ...' [how
> do you indicate three dots followed by etc etc, which would normally be
> indicated by three dots!]. The traceback said 'Attempted relative import
> beyond toplevel package'.
>
> I did not want to investigate too deeply so I just commented those lines
> out, and now it runs with no errors. I even put a couple of print statements
> (or must I call them print functions now) into the modules being imported,
> and the messages do appear, so the modules are being imported.
>
> HTH
>
> Frank Millman
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What do I need to know in order to write a web application in python?

2011-03-05 Thread Corey Richardson
On 03/05/2011 06:49 AM, ErichCart ErichCart wrote:
> So, "Glade", is this what everybody uses? I mean programmers don't
> just use text editors to make GUI applications, do they?

I usually see people using Qt and QtDesigner over Gtk and Glade. And
actually, yes, I'm sure lots of people besides me actually make their
GUI apps in a text editor. Then again, I usually don't do anything big.
If you want to learn your GUI toolkit well, do it by hand and not by
tool. As someone said to me once, "QtDesigner is meant for people who
already know how to use Qt". I'm sure the same applies for Glade.

-- 
Corey Richardson
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: python xmp toolkit question

2011-03-05 Thread jyoung79
>In article <20110304161955.LI5T1.94538.root at cdptpa-web16-z02>,
>  wrote:

>> Is anyone here using the Python XMP Toolkit?  I'm trying to install 
>> this and having problems.
>> 

> I have no experience with either but I would guess that the two 
> configure options are for building with Boost installed from MacPorts 
> (the newer name for DarwinPorts) or from Fink.  MacPorts and Fink are 
> two open-source projects that port and distribute many third-party 
> packages to Mac OS X.  My personal preference is for MacPorts.  If you 
 >don't already have the necessary current MacPorts base files installed, 
> follow the instructions here: http://www.macports.org/install.php
> MacPorts installs everything under /opt/local so you will need to add 
> /opt/local/bin to the front of your shell search PATH.  Then you can 
> pick a Python version (MacPorts will install its own version) and the 
> Boost variant to go with it:

> $ sudo port selfupdate
> $ sudo port install python27
> $ sudo port install python_select
> $ sudo /opt/local/bin/python_select python27
> $ sudo port install boost +python27

> In fact, MacPorts has a port file for Exempi itself 
> (http://www.macports.org/ports.php?by=name&substr=exempi)

> $ sudo port install exempi

> Then, using the MacPorts python you installed, you should be able to 
> easily install the toolkit.  Good luck!

> -- 
>  Ned Deily,
>  nad at acm.org


Hi Ned,

Thank you very much for your reply.  When I get back to work Monday I 
will give this a try… this looks to be exactly what I needed!

Thanks.

Jay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What do I need to know in order to write a web application in python?

2011-03-05 Thread CM
On Mar 5, 6:49 am, ErichCart ErichCart  wrote:

> Regarding Boa constructor, it is very old, isn't it? The latest news
> from this project date to the end of 2006. I don't expect it to
> support python 3 any time soon.

The website is incredibly out of date, but the last major update was
July 2007.  So, yes.  Like any snake, it could suddenly rear up and
spring to life with a new version, but there is no way to know when or
if that will happen.  Even wxPython itself doesn't support Python 3
yet, so I'm not sure I'd let that deter you.  It seems like many third
party libraries haven't updated to Python 3 yet and may not for some
time to come.

All this said, one can build a toy GUI application using Boa, Python
2.5 or 2.6 and wxPython 2.8.x.x. in 5 minutes if you know what you're
doing.  And you can build a larger and real application that way, too.

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


Re: ImSim: Image Similarity

2011-03-05 Thread n00m

I uploaded a new version of the subject with a
VERY MINOR correction in it. Namely, in line #55:

print '%12s %7.2f' % (db[k][1], db[k][0] / 3600.0,)

instead of

print '%12s %7.2f' % (db[k][1], db[k][0] * 0.001,)

I.e. I normalized it to base = 100.
Now the values of similarity can't be greater than 100
and can be treated as some "regular" percents (%%).

Also, due to this change, the *empirical* threshold of
"system alarmity" moved down from "number 70" to "20%".

  bears2.jpg

  bears2.jpg0.00
  bears3.jpg   15.37
  bears1.jpg   19.13
sky1.jpg   23.29
sky2.jpg   23.45
 ff1.jpg   25.37
   lake1.jpg   26.43
  water1.jpg   26.93
 ff2.jpg   28.43
  roses1.jpg   31.95
  roses2.jpg   36.12

Done!

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


Re: ImSim: Image Similarity

2011-03-05 Thread Mel
n00m wrote:

> 
> I uploaded a new version of the subject with a
> VERY MINOR correction in it. Namely, in line #55:
> 
> print '%12s %7.2f' % (db[k][1], db[k][0] / 3600.0,)
> 
> instead of
> 
> print '%12s %7.2f' % (db[k][1], db[k][0] * 0.001,)
> 
> I.e. I normalized it to base = 100.
> Now the values of similarity can't be greater than 100
> and can be treated as some "regular" percents (%%).
> 
> Also, due to this change, the *empirical* threshold of
> "system alarmity" moved down from "number 70" to "20%".
> 
>   bears2.jpg
> 
>   bears2.jpg0.00
>   bears3.jpg   15.37
>   bears1.jpg   19.13
> sky1.jpg   23.29
> sky2.jpg   23.45
>  ff1.jpg   25.37
>lake1.jpg   26.43
>   water1.jpg   26.93
>  ff2.jpg   28.43
>   roses1.jpg   31.95
>   roses2.jpg   36.12

I'd like to see a *lot* more structure in there, with modularization, so the 
internal functions could be used from another program.  Once I'd figured out 
what it was doing, I had this:


from PIL import Image
from PIL import ImageStat

def row_column_histograms (file_name):
'''Reduce the image to a 5x5 square of b/w brightness levels 0..3
Return two brightness histograms across Y and X
packed into a 10-item list of 4-item histograms.'''
im = Image.open (file_name)
im = im.convert ('L')   # convert to 8-bit b/w
w, h = 300, 300
im = im.resize ((w, h))
imst = ImageStat.Stat (im)
sr = imst.mean[0]   # average pixel level in layer 0
sr_low, sr_mid, sr_high = (sr*2)/3, sr, (sr*4)/3
def foo (t):
if t < sr_low: return 0
if t < sr_mid: return 1
if t < sr_high: return 2
return 3
im = im.point (foo) # reduce to brightness levels 0..3
yhist = [[0]*4 for i in xrange(5)]
xhist = [[0]*4 for i in xrange(5)]
for y in xrange (h):
for x in xrange (w):
k = im.getpixel ((x, y))
yhist[y / 60][k] += 1
xhist[x / 60][k] += 1
return yhist + xhist


def difference_ranks (test_histogram, sample_histograms):
'''Return a list of difference ranks between the test histograms and 
each of the samples.'''
result = [0]*len (sample_histograms)
for k, s in enumerate (sample_histograms):  # for each image
for i in xrange(10):# for each histogram slot
for j in xrange(4): # for each brightness level
result[k] += abs (s[i][j] - test_histogram[i][j])   
return result


if __name__ == '__main__':
import getopt, sys
opts, args = getopt.getopt (sys.argv[1:], '', [])
if not args:
args = [
'bears1.jpg',
'bears2.jpg',
'bears3.jpg',
'roses1.jpg',
'roses2.jpg',
'ff1.jpg',
'ff2.jpg',
'sky1.jpg',
'sky2.jpg',
'water1.jpg',
'lake1.jpg',
]
test_pic = 'bears2.jpg' 
else:
test_pic, args = args[0], args[1:]

z = [row_column_histograms (a) for a in args]
test_z = row_column_histograms (test_pic)

file_ranks = zip (difference_ranks (test_z, z), args)   
file_ranks.sort()

print '%12s' % (test_pic,)
print ''
for r in file_ranks:
print '%12s %7.2f' % (r[1], r[0] / 3600.0,)



(omitting a few comments that wrapped around.)  The test-case still agrees 
with your archived version:

mwilson@tecumseth:~/sandbox/im_sim$ python image_rank.py bears2.jpg *.jpg
  bears2.jpg

  bears2.jpg0.00
  bears3.jpg   15.37
  bears1.jpg   19.20
sky1.jpg   23.20
sky2.jpg   23.37
 ff1.jpg   25.30
   lake1.jpg   26.38
  water1.jpg   26.98
 ff2.jpg   28.43
  roses1.jpg   32.01


I'd vaguely wanted to do something like this for a while, but I never dug 
far enough into PIL to even get started.  An additional kind of ranking that 
takes colour into account would also be good -- that's the first one I never 
did.

Cheers, Mel.

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


Re: ImSim: Image Similarity

2011-03-05 Thread n00m
On Mar 5, 7:10 pm, Mel  wrote:
> n00m wrote:
>
> > I uploaded a new version of the subject with a
> > VERY MINOR correction in it. Namely, in line #55:
>
> >     print '%12s %7.2f' % (db[k][1], db[k][0] / 3600.0,)
>
> > instead of
>
> >     print '%12s %7.2f' % (db[k][1], db[k][0] * 0.001,)
>
> > I.e. I normalized it to base = 100.
> > Now the values of similarity can't be greater than 100
> > and can be treated as some "regular" percents (%%).
>
> > Also, due to this change, the *empirical* threshold of
> > "system alarmity" moved down from "number 70" to "20%".
>
> >   bears2.jpg
> > 
> >   bears2.jpg    0.00
> >   bears3.jpg   15.37
> >   bears1.jpg   19.13
> >     sky1.jpg   23.29
> >     sky2.jpg   23.45
> >      ff1.jpg   25.37
> >    lake1.jpg   26.43
> >   water1.jpg   26.93
> >      ff2.jpg   28.43
> >   roses1.jpg   31.95
> >   roses2.jpg   36.12
>
> I'd like to see a *lot* more structure in there, with modularization, so the
> internal functions could be used from another program.  Once I'd figured out
> what it was doing, I had this:
>
> from PIL import Image
> from PIL import ImageStat
>
> def row_column_histograms (file_name):
>     '''Reduce the image to a 5x5 square of b/w brightness levels 0..3
>     Return two brightness histograms across Y and X
>     packed into a 10-item list of 4-item histograms.'''
>     im = Image.open (file_name)
>     im = im.convert ('L')       # convert to 8-bit b/w
>     w, h = 300, 300
>     im = im.resize ((w, h))
>     imst = ImageStat.Stat (im)
>     sr = imst.mean[0]   # average pixel level in layer 0
>     sr_low, sr_mid, sr_high = (sr*2)/3, sr, (sr*4)/3
>     def foo (t):
>         if t < sr_low: return 0
>         if t < sr_mid: return 1
>         if t < sr_high: return 2
>         return 3
>     im = im.point (foo) # reduce to brightness levels 0..3
>     yhist = [[0]*4 for i in xrange(5)]
>     xhist = [[0]*4 for i in xrange(5)]
>     for y in xrange (h):
>         for x in xrange (w):
>             k = im.getpixel ((x, y))
>             yhist[y / 60][k] += 1
>             xhist[x / 60][k] += 1
>     return yhist + xhist
>
> def difference_ranks (test_histogram, sample_histograms):
>     '''Return a list of difference ranks between the test histograms and
> each of the samples.'''
>     result = [0]*len (sample_histograms)
>     for k, s in enumerate (sample_histograms):  # for each image
>         for i in xrange(10):    # for each histogram slot
>             for j in xrange(4): # for each brightness level
>                 result[k] += abs (s[i][j] - test_histogram[i][j])      
>     return result
>
> if __name__ == '__main__':
>     import getopt, sys
>     opts, args = getopt.getopt (sys.argv[1:], '', [])
>     if not args:
>         args = [
>             'bears1.jpg',
>             'bears2.jpg',
>             'bears3.jpg',
>             'roses1.jpg',
>             'roses2.jpg',
>             'ff1.jpg',
>             'ff2.jpg',
>             'sky1.jpg',
>             'sky2.jpg',
>             'water1.jpg',
>             'lake1.jpg',
>         ]
>         test_pic = 'bears2.jpg'
>     else:
>         test_pic, args = args[0], args[1:]
>
>     z = [row_column_histograms (a) for a in args]
>     test_z = row_column_histograms (test_pic)
>
>     file_ranks = zip (difference_ranks (test_z, z), args)      
>     file_ranks.sort()
>
>     print '%12s' % (test_pic,)
>     print ''
>     for r in file_ranks:
>         print '%12s %7.2f' % (r[1], r[0] / 3600.0,)
>
> (omitting a few comments that wrapped around.)  The test-case still agrees
> with your archived version:
>
> mwilson@tecumseth:~/sandbox/im_sim$ python image_rank.py bears2.jpg *.jpg
>   bears2.jpg
> 
>   bears2.jpg    0.00
>   bears3.jpg   15.37
>   bears1.jpg   19.20
>     sky1.jpg   23.20
>     sky2.jpg   23.37
>      ff1.jpg   25.30
>    lake1.jpg   26.38
>   water1.jpg   26.98
>      ff2.jpg   28.43
>   roses1.jpg   32.01
>
> I'd vaguely wanted to do something like this for a while, but I never dug
> far enough into PIL to even get started.  An additional kind of ranking that
> takes colour into account would also be good -- that's the first one I never
> did.
>
>         Cheers,         Mel.


Very nice, Mel.

As for using color info...
my current strong opinion is: the colors must be forgot for good.
Paradoxically but "profound" elaboration and detailization can/will
spoil/undermine the whole thing. Just my current imo.


===
Vitali

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


Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Ravi
I can extend dictionary to allow for the my own special look-up tables. However 
now I want to be able to define multidimensional dictionary which supports 
look-up like this:

d[1]['abc'][40] = 'dummy'

and if d[1] and d[1][abc] raise KeyError just create them.

for d[1] I can override __getitem__() but how to do the same for the d[1][abc]?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Ravi
I found a solution here:

http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional-dictionaries-in-python/

Please tell how good is it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Peter Otten
Ravi wrote:

> I found a solution here:
> 
> http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional-
dictionaries-in-python/
> 
> Please tell how good is it?

Follow the link to the cookbook and read Andrew Dalke's comment ;) 
To spell it out:

>>> class D(dict):
... def __missing__(self, key):
... result = self[key] = D()
... return result
...
>>> d = D()
>>> d["a"]["b"]["c"] = 42
>>> d
{'a': {'b': {'c': 42}}}

This is not only simpler, it should also give you faster lookup when the key 
already exists.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-05 Thread Jorgen Grahn
On Sat, 2011-03-05, Grigory Javadyan wrote:
> At least you could've tried to make the script more usable by adding
> the possibility to supply command line arguments, instead of editing
> the source every time you want to compare a couple of images.
>
> On Sat, Mar 5, 2011 at 11:23 AM, n00m  wrote:
>> Let me present my newborn project (in Python) ImSim:
>>
>> http://sourceforge.net/projects/imsim/
>>
>> Its README.txt:
>> -
>> ImSim is a python script for finding the most similar pic(s) to
>> a given one among a set/list/db of your pics.
>> The script is very short and very easy to follow and understand.
>> Its sample output looks like this:
...
>> The *less* numeric value -- the *more similar* this pic is to the
>> tested pic. If this value > 70 almost for sure these pictures are
>> absolutely different (from totally different domains, so to speak).
>>
>> What is "similarity" and how can/could/should it be estimated this
>> point I'm leaving for your consideration/contemplation/arguing etc.

So basically you're saying you won't tell the users what the program
*does*. I don't get that.

Is it better than this?
- scale each image to 100x100
- go black&white in such a way that half the pixels are black
- XOR the images and count the mismatches

That takes care of JPEG quality, scaling and possibly gamma
correction, but not cropping or rotation. I'm sure there are better,
well-known algorithms.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to read the last line of a huge file???

2011-03-05 Thread tkp...@hotmail.com
Thanks for the pointer. Yes, it is a text file, but the mystery runs
deeper: I later found that it works perfectly as written when I run it
from IDLE or the Python shell, but it fails reliably when I run it
from PyScripter 2.4.1 (an open source Python IDE)! So I suspect
there's a PyScripter issue lurking in here. I'm next going to try the
solution you propose - use only for legal offsets - and then retry it
under both IDLE and PyScripter. Question: how do I use f.tell() to
identify if an offset is legal or illegal?

Thanks in advance


Thomas Philips
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-05 Thread n00m
>
> Is it better than this?
> - scale each image to 100x100
> - go black&white in such a way that half the pixels are black
> - XOR the images and count the mismatches


It's *much* better but I'm not *much* about to prove it.



> I'm sure there are better,
> well-known algorithms.


The best well-known algorithm is to hire a man with good eyesight
for to do the job of comparing, ranking and selecting the pictures.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-05 Thread n00m

PS

For some reason they don't update the link to the last version.

It's _20110306, here: http://sourceforge.net/projects/imsim/files/

I use Python 2.5 & PIL for Python 2.5

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


Re: What do I need to know in order to write a web application in python?

2011-03-05 Thread OKB (not okblacke)
Grumman wrote:

> On 3/4/2011 16:48, ErichCart ErichCart wrote:
>>
>> In fact this doesn't necessary need to be web application. For
>> example I have a friend who uses Delphi, and he can create all
>> sorts of windows applications easily, like he can see the window
>> on the screen and he can place buttons, text fields, radio buttons
>> etc. wherever he wants and then program the actions of each
>> element. I was able to do the same with visual basic in one of my
>> university classes. 
>>
>> What do I need to know in order to be able to do the same with
>> python? Which python modules/python development environments do I
>> need to use? 
> 
> You might want to look at: http://visualpython.org/

Also www.dabodev.com

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What do I need to know in order to write a web application in python?

2011-03-05 Thread geremy condra
On Sat, Mar 5, 2011 at 3:49 AM, ErichCart ErichCart  wrote:
> Visual Python seems to be exactly what I want. But it doesn't seem
> very popular. Perhaps it means that there are not many people who will
> be able to help if I have problems with it. Also judging by the amount
> of ads at visualpython.org, it also doesn't seem very serious.
>
> I looked into pyGTK, and I found something called "Glade", which seems
> to be something similar to visual python. The latest version of Glade
> was released just this month, so it seems to be actively developed.
>
> Regarding Boa constructor, it is very old, isn't it? The latest news
> from this project date to the end of 2006. I don't expect it to
> support python 3 any time soon.
>
> So, "Glade", is this what everybody uses? I mean programmers don't
> just use text editors to make GUI applications, do they?

Yes, they do. It isn't that bad once you get used to it, and it beats
the snot out of trying to maintain the insensible gibberish that some
of the autogen tools put out.

On a side note, you should check out pygui[0]- very, very nice GUI toolkit.

Geremy Condra

[0]: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Paul Rubin
Ravi  writes:
> I can extend dictionary to allow for the my own special look-up
> tables. However now I want to be able to define multidimensional
> dictionary which supports look-up like this:
>
> d[1]['abc'][40] = 'dummy'

Why do that anyway?  You can use a tuple as a subscript:

   d[1,'abc',40] = 'dummy'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to read the last line of a huge file???

2011-03-05 Thread John Nagle

On 3/5/2011 10:21 AM, tkp...@hotmail.com wrote:

Question: how do I use f.tell() to
identify if an offset is legal or illegal?


   Read backwards in binary mode, byte by byte,
until you reach a byte which is, in binary, either

0xxx
11xx

You are then at the beginning of an ASCII or UTF-8
character.  You can copy the bytes forward from there
into an array of bytes, then apply the appropriate
codec.  This is also what you do if skipping ahead
in a UTF-8 file, to get in sync.

   Reading the last line or lines is easier.  Read backwards
in binary until you hit an LF or CR, both of which
are the same in ASCII and UTF-8.  Copy the bytes
forward from that point into an array of bytes, then
apply the appropriate codec.

John Nagle

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


Re: how to read the last line of a huge file???

2011-03-05 Thread Terry Reedy

On 3/5/2011 1:21 PM, tkp...@hotmail.com wrote:

Thanks for the pointer. Yes, it is a text file, but the mystery runs
deeper: I later found that it works perfectly as written when I run it
from IDLE or the Python shell, but it fails reliably when I run it
from PyScripter 2.4.1 (an open source Python IDE)! So I suspect
there's a PyScripter issue lurking in here. I'm next going to try the
solution you propose - use only for legal offsets - and then retry it
under both IDLE and PyScripter. Question: how do I use f.tell() to
identify if an offset is legal or illegal?


I do not believe you can. You have to be at a position and f.tell() will 
report it.


Note: if a file is utf-8 encoded, and you seek to an arbitrary position 
in binary mode, it is easy to synchronize by discarding the remainder 
(if any)of a multibyte char and finding the start of the next char.


--
Terry Jan Reedy

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


Re: getting text out of an xml string

2011-03-05 Thread björn lundin

> Next time you need to extract some data from an xml file, please (for
> your own good) don't do whatever you did in that code -- note that the
> unicode equivalent of "<" is u"\u003c", NOT u"\u3c00"; I wasn't joking
> when I said it had been FU.

Is that perhaps the doing of going from littleEndian to bigEndian
(or vice versa) machines with that file, in some kind of strange
binary mode?
/björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread John Nagle

On 3/5/2011 12:05 PM, Paul Rubin wrote:

Ravi  writes:

I can extend dictionary to allow for the my own special look-up
tables. However now I want to be able to define multidimensional
dictionary which supports look-up like this:

d[1]['abc'][40] = 'dummy'


Why do that anyway?  You can use a tuple as a subscript:

d[1,'abc',40] = 'dummy'


   Also, at some point, it's time to use a database.
If you find yourself writing those "dictionaries" to
files, or trying to look up everything with "abc"
in the second subscript, a database is appropriate.

John Nagle

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


Re: 2to3 and maketrans

2011-03-05 Thread Gregory Ewing

Martin v. Löwis wrote:


Whether a GUI library is application programming or systems programming,
I don't know.


Neither do I, but it doesn't really matter. In my case the
string is definitely text (although it will always be ascii)
and therefore unicode is the right representation to use
in 3.x.

I just wondered whether there was a recommended idiom for
using maketrans() on text in 2.7 that 2to3 would translate
into str.maketrans(), but it seems not. Instead the
solution seems to be to convert to unicode and use its
translation method instead.

I've since adopted a different solution, but I'll keep
this in mind for the future. Thanks, everyone.

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


Re: having both dynamic and static variables

2011-03-05 Thread Gregory Ewing

BartC wrote:

I got the impression the OP was talking about simply pinning down 
certain variables, so that a runtime name lookup (if that's in fact what 
Python does) was not necessary.


A problem with this is that lexical name lookups are a
relatively small proportion of the looking up that goes
on in a typical Python program. Much more often you're
looking up attributes of objects, which is much harder
to turn into an indexed access, because the compiler
has next to no knowledge of what type the object will
be at run time.

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


Absolutely Insane Problem with Gmail

2011-03-05 Thread Victor Subervi
Hi;
I have this code:

#!/usr/bin/python

import sys, os, string
import cgitb; cgitb.enable()
import cgi
cwd = os.getcwd()
dirs = string.split(cwd, '/')
dirs = dirs[1:-1]
backLevel = '/' + string.join(dirs, '/')
sys.path.append(cwd)
sys.path.append(backLevel)
import string
form = cgi.FieldStorage()
// all the fields here
subject = 'Order For Maya 2012'
msg = 'First Name: %s\nLast Name: %s\nEmail Address: %s\nAddress2: %s, City:
%s\nState: %s\nCountry: %s\nZip: %s\nPhone: %s\nFax: %s\nMessage: %s\n' %
(firstNameText, lastNameText, emailText, addrText, addr2Te
xt, cityText, stateText, countryText, zipText, faxText, messageText)
### LOOK AT THESE TWO LINES
ourEmail = 'myemaila...@gmail.com'
ourEmail = 'q...@xxx.com'

def my_mail():
  emailOne()
  emailTwo()

def emailOne():
  from simplemail import Email
  Email(
  from_address = ourEmail,
  to_address = emailText,
  subject = 'Thank you for your order!',
  message = msg
  ).send()

def emailTwo():
  from simplemail import Email
  Email(
  from simplemail import Email
  Email(
#  from_address = emailText,
#  to_address = ourEmail,
  from_address = ourEmail,
  to_address = emailText,
  subject = 'Order for Maya 2012',
  message = msg
  ).send()

print '''Content-type: text/html







'''
my_mail()
print '''


'''

Now what's absolutely crazy about this is that if I use my online form and
enter my gmail address I get the email confirmations. However, if I get rid
of that garbage value for ourEmail and use the other one which is the
_very_same_gmail_address I get nothing!! No email. Ditto if I uncomment
those lines in emailTwo and delete the next two lines. What on earth could
be doing this???
TIA,
Beno
-- 
http://mail.python.org/mailman/listinfo/python-list


One popular idea, for the christian louboutin salesfood family style. In t

2011-03-05 Thread shoesbuy
One popular idea, for the christian louboutin salesfood family style.
In this type of party, all of the food is put on the table, in large
record transfer, rather than focusing on a waiter to all guest
personal plate of food. Family style service cannot be frowsty than
traditional plating dinners, and more elegant stage. Here are some
ideas of how to arrange a family style wedding, your guests to love.  Nokia N97 can support up to 48 GB of music, pictures, data file
and video content, using 32 GB vehicle-mounted ability or 16 GB
expansion can be accomplished by using micro – SD card. This means http://www.heelshoes08.com/";>christian louboutin shoes
replay, equipment performance, including multimedia megapixel camera
with a five – Karl Zeiss optical – might be used to the fullest and
can be Shared use Ovi share services etc. Jonas Geust nokia deputy
dean said, have Nseries N97 is “the most powerful, mobile computer
more survival” or a may attract those that wish to leading technology
curve. “N97 nokia mobile computers adjusts to the world around us and
help people and keep in touch something really important.” Consumers
want to restore health, and also may be christian louboutin designer of the other
options, and was later released by the manufacturer. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: having both dynamic and static variables

2011-03-05 Thread John Nagle

On 3/2/2011 9:27 PM, Steven D'Aprano wrote:

On Wed, 02 Mar 2011 19:45:16 -0800, Yingjie Lan wrote:


Hi everyone,

Variables in Python are resolved dynamically at runtime, which comes at
a performance cost. However, a lot of times we don't need that feature.
Variables can be determined at compile time, which should boost up
speed.

[...]

This is a very promising approach taken by a number of projects.


   It's worth having some syntax for constants.  I'd suggest
using "let":

let PI = 3.1415926535897932384626433832795028841971693993751

I'd propose the following semantics:

1.  "let" creates an object whose binding is unchangeable.  This
is effectively a constant, provided that the value is immutable.
A compiler may treat such variables as constants for optimization
purposes.

2.  Assignment to a a variable created with "let" produces an error
at compile time or run time.

3.  Names bound with "let" have the same scope as any other name
created in the same context.  Function-local "let" variables
are permitted.

4.  It is an error to use "let" on a name explicitly made "global",
because that would allow access to the variable before it was
initialized.

This is close to the semantics of "const" in C/C++, except that
there's no notion of a const parameter.

"let" allows the usual optimizations - constant folding, hoisting
out of loops, compile time arithmetic, unboxing, etc.  Ordinarily,
Python compilers have to assume that any variable can be changed
at any time from another thread, requiring worst-case code for
everything.

John Nagle  
--
http://mail.python.org/mailman/listinfo/python-list


Re: Absolutely Insane Problem with Gmail

2011-03-05 Thread Littlefield, Tyler

>ourEmail = '
myemaila...@gmail.com'

>ourEmail = '
q...@xxx.com'

You redefine this twice. You also don't define a variable down lower.
>#  to_address = ourEmail,
>  from_address = ourEmail,
>  to_address = emailText,
I could be wrong, but emailText isn't defined. Perhaps a better variable 
naming setup would help you some. so: in short, set up a to_address and 
from_address,

populate those however you need to, then change the variable names.
--
http://mail.python.org/mailman/listinfo/python-list


Re: having both dynamic and static variables

2011-03-05 Thread Littlefield, Tyler

>   It's worth having some syntax for constants.  I'd suggest
>using "let":
>let PI = 3.1415926535897932384626433832795028841971693993751
in to many languages, let is just a setter. why not just const pye = 3.14...

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


Re: having both dynamic and static variables

2011-03-05 Thread MRAB

On 06/03/2011 02:37, John Nagle wrote:

On 3/2/2011 9:27 PM, Steven D'Aprano wrote:

On Wed, 02 Mar 2011 19:45:16 -0800, Yingjie Lan wrote:


Hi everyone,

Variables in Python are resolved dynamically at runtime, which comes at
a performance cost. However, a lot of times we don't need that feature.
Variables can be determined at compile time, which should boost up
speed.

[...]

This is a very promising approach taken by a number of projects.


It's worth having some syntax for constants. I'd suggest
using "let":

let PI = 3.1415926535897932384626433832795028841971693993751

I'd propose the following semantics:

1. "let" creates an object whose binding is unchangeable. This
is effectively a constant, provided that the value is immutable.
A compiler may treat such variables as constants for optimization
purposes.

2. Assignment to a a variable created with "let" produces an error
at compile time or run time.

3. Names bound with "let" have the same scope as any other name
created in the same context. Function-local "let" variables
are permitted.

4. It is an error to use "let" on a name explicitly made "global",
because that would allow access to the variable before it was
initialized.

This is close to the semantics of "const" in C/C++, except that
there's no notion of a const parameter.

"let" allows the usual optimizations - constant folding, hoisting
out of loops, compile time arithmetic, unboxing, etc. Ordinarily,
Python compilers have to assume that any variable can be changed
at any time from another thread, requiring worst-case code for
everything.


Having a fixed binding could be useful elsewhere, for example, with
function definitions:

const PI = 3.1415926535897932384626433832795028841971693993751

const def squared(x):
return x * x

or:

fixed PI = 3.1415926535897932384626433832795028841971693993751

fixed def squared(x):
return x * x
--
http://mail.python.org/mailman/listinfo/python-list


Re: having both dynamic and static variables

2011-03-05 Thread Corey Richardson
On 03/05/2011 10:23 PM, MRAB wrote:
> Having a fixed binding could be useful elsewhere, for example, with
> function definitions:
> [..]
>  fixed PI = 3.1415926535897932384626433832795028841971693993751
> 
>  fixed def squared(x):
>  return x * x

This question spawns from my ignorance: When would a functions
definition change? What is the difference between a dynamic function and
a fixed function?

-- 
Corey Richardson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: having both dynamic and static variables

2011-03-05 Thread Santoso Wijaya
A function object can get bound to a name, too:

def foo(x):
return x + 1

foo = lambda x: x - 1
assert foo(1) == 0

~/santa


On Sat, Mar 5, 2011 at 7:46 PM, Corey Richardson  wrote:

> On 03/05/2011 10:23 PM, MRAB wrote:
> > Having a fixed binding could be useful elsewhere, for example, with
> > function definitions:
> > [..]
> >  fixed PI = 3.1415926535897932384626433832795028841971693993751
> >
> >  fixed def squared(x):
> >  return x * x
>
> This question spawns from my ignorance: When would a functions
> definition change? What is the difference between a dynamic function and
> a fixed function?
>
> --
> Corey Richardson
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-05 Thread Mel
n00m wrote:

> As for using color info...
> my current strong opinion is: the colors must be forgot for good.
> Paradoxically but "profound" elaboration and detailization can/will
> spoil/undermine the whole thing. Just my current imo.

Yeah.  I guess including color info cubes the complexity of the answer.  
Might be too complicated to know what to do with an answer like that.

Mel.

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


Re: having both dynamic and static variables

2011-03-05 Thread Westley Martínez
On Sat, 2011-03-05 at 18:37 -0800, John Nagle wrote:
> On 3/2/2011 9:27 PM, Steven D'Aprano wrote:
> > On Wed, 02 Mar 2011 19:45:16 -0800, Yingjie Lan wrote:
> >
> >> Hi everyone,
> >>
> >> Variables in Python are resolved dynamically at runtime, which comes at
> >> a performance cost. However, a lot of times we don't need that feature.
> >> Variables can be determined at compile time, which should boost up
> >> speed.
> > [...]
> >
> > This is a very promising approach taken by a number of projects.
> 
> It's worth having some syntax for constants.  I'd suggest
> using "let":
> 
>   let PI = 3.1415926535897932384626433832795028841971693993751
> 
> I'd propose the following semantics:
> 
> 1.  "let" creates an object whose binding is unchangeable.  This
>  is effectively a constant, provided that the value is immutable.
>  A compiler may treat such variables as constants for optimization
>  purposes.
> 
> 2.  Assignment to a a variable created with "let" produces an error
>  at compile time or run time.
> 
> 3.  Names bound with "let" have the same scope as any other name
>  created in the same context.  Function-local "let" variables
>  are permitted.
> 
> 4.  It is an error to use "let" on a name explicitly made "global",
>  because that would allow access to the variable before it was
>  initialized.
> 
> This is close to the semantics of "const" in C/C++, except that
> there's no notion of a const parameter.
> 
> "let" allows the usual optimizations - constant folding, hoisting
> out of loops, compile time arithmetic, unboxing, etc.  Ordinarily,
> Python compilers have to assume that any variable can be changed
> at any time from another thread, requiring worst-case code for
> everything.
> 
>   John Nagle  
I'm against constants, for the purpose of "programmers should be smart
enough to not set a variable to another value that should be static",
but if Python were to have constants I think it would be better to use
something more descriptive than 'let'. Also, because the defined
constant is static, I think it would be better to use 'is' instead of
'='. Example:

constant x is 5

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


Re: having both dynamic and static variables

2011-03-05 Thread John Nagle

On 3/5/2011 7:46 PM, Corey Richardson wrote:

On 03/05/2011 10:23 PM, MRAB wrote:

Having a fixed binding could be useful elsewhere, for example, with
function definitions:
[..]
  fixed PI = 3.1415926535897932384626433832795028841971693993751

  fixed def squared(x):
  return x * x


This question spawns from my ignorance: When would a functions
definition change? What is the difference between a dynamic function and
a fixed function?


   All functions in Python can be replaced dynamically. While they're
running. From another thread.  Really.

   Implementing this is either inefficient, with a lookup for every
use (CPython) or really, really complicated, involving just-in-time
compilers, invalidation, recompilation, and a backup interpreter
for when things get ugly (PyPy).

John Nagle

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


Re: having both dynamic and static variables

2011-03-05 Thread Santoso Wijaya
Shouldn't this go to python-ideas?
Anyway, I'm partial to "static".


~/santa


On Sat, Mar 5, 2011 at 8:33 PM, Westley Martínez  wrote:

> On Sat, 2011-03-05 at 18:37 -0800, John Nagle wrote:
> > On 3/2/2011 9:27 PM, Steven D'Aprano wrote:
> > > On Wed, 02 Mar 2011 19:45:16 -0800, Yingjie Lan wrote:
> > >
> > >> Hi everyone,
> > >>
> > >> Variables in Python are resolved dynamically at runtime, which comes
> at
> > >> a performance cost. However, a lot of times we don't need that
> feature.
> > >> Variables can be determined at compile time, which should boost up
> > >> speed.
> > > [...]
> > >
> > > This is a very promising approach taken by a number of projects.
> >
> > It's worth having some syntax for constants.  I'd suggest
> > using "let":
> >
> >   let PI = 3.1415926535897932384626433832795028841971693993751
> >
> > I'd propose the following semantics:
> >
> > 1.  "let" creates an object whose binding is unchangeable.  This
> >  is effectively a constant, provided that the value is immutable.
> >  A compiler may treat such variables as constants for optimization
> >  purposes.
> >
> > 2.  Assignment to a a variable created with "let" produces an error
> >  at compile time or run time.
> >
> > 3.  Names bound with "let" have the same scope as any other name
> >  created in the same context.  Function-local "let" variables
> >  are permitted.
> >
> > 4.  It is an error to use "let" on a name explicitly made "global",
> >  because that would allow access to the variable before it was
> >  initialized.
> >
> > This is close to the semantics of "const" in C/C++, except that
> > there's no notion of a const parameter.
> >
> > "let" allows the usual optimizations - constant folding, hoisting
> > out of loops, compile time arithmetic, unboxing, etc.  Ordinarily,
> > Python compilers have to assume that any variable can be changed
> > at any time from another thread, requiring worst-case code for
> > everything.
> >
> >   John Nagle
> I'm against constants, for the purpose of "programmers should be smart
> enough to not set a variable to another value that should be static",
> but if Python were to have constants I think it would be better to use
> something more descriptive than 'let'. Also, because the defined
> constant is static, I think it would be better to use 'is' instead of
> '='. Example:
>
> constant x is 5
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-05 Thread n00m
On Mar 6, 6:10 am, Mel  wrote:
> n00m wrote:
> > As for using color info...
> > my current strong opinion is: the colors must be forgot for good.
> > Paradoxically but "profound" elaboration and detailization can/will
> > spoil/undermine the whole thing. Just my current imo.
>
> Yeah.  I guess including color info cubes the complexity of the answer.  
> Might be too complicated to know what to do with an answer like that.
>
>         Mel.

Uhmm, Mel. Totally agree with you.
+
I included "roses1.jpg" & "roses2.jpg" on purpose:
the 1st one is a painting by Abbott Handerson Thayer,
the 2nd is its copy by some obscure Russian painter.
But it's of course a creative & revamped copy.

In strict sense they are 2 different images (look at their colors etc)
, on the other hand they are closely related to each other.
Plus, we can't tell *in principle* what is original and what is copy
what colors are "right/good" and what colors are "wrong/bad"

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


Re: having both dynamic and static variables

2011-03-05 Thread Carl Banks
On Mar 5, 7:46 pm, Corey Richardson  wrote:
> On 03/05/2011 10:23 PM, MRAB wrote:
>
> > Having a fixed binding could be useful elsewhere, for example, with
> > function definitions:
> > [..]
> >      fixed PI = 3.1415926535897932384626433832795028841971693993751
>
> >      fixed def squared(x):
> >          return x * x
>
> This question spawns from my ignorance: When would a functions
> definition change? What is the difference between a dynamic function and
> a fixed function?

There's a bit of ambiguity here.  We have to differentiate between
"fixed binding" (which is what John Nagle and MRAB were talking about)
and "immutable object" (which, apparently, is how you took it).  I
don't like speaking of "constants" in Python because it's not always
clear which is meant, and IMO it's not a constant unless it's both.

An immutable object like a number or tuple can't be modified, but the
name refering to it can be rebound to a different object.

a = (1,2,3)
a.append(4) # illegal, can't modify a tuple
a = (1,2,3,4) # but this is legal, can set a to a new tuple

If a hypothetical fixed binding were added to Python, you wouldn't be
able to rebind a after it was set:

fixed a = (1,2,3)
a = (1,2,3,4) # now illegal

If you could define functions with fixed bindings like this, then a
compiler that's a lot smarter than CPython's would be able to inline
functions for potentially big speed increases.  It can't do that now
because the name of the function can always be rebound to something
else.

BTW, a function object is definitely mutable.

def squared(x):
return x*x

squared.foo = 'bar'


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-05 Thread n00m
http://www.nga.gov/search/index.shtm
http://deyoung.famsf.org/search-collections
etc
Seems they all offer search only by keywords and this kind.
What about to submit e.g. roses2.jpg (copy) and to find its
original? Assume we don't know its author neither its title
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: having both dynamic and static variables

2011-03-05 Thread Steven D'Aprano
On Thu, 03 Mar 2011 08:52:16 -0800, Rafe Kettler wrote:

>> Finally, Python 3 introduced type annotations, which are currently a
>> feature looking for a reason.
> 
> By type annotations, do you mean function annotations (see PEP 3107,
> http://www.python.org/dev/peps/pep-3107/)? Or is this some other feature
> that I'm unaware of?

Sorry, yes, I meant function annotations. Of course you can use function 
annotations for more than just types.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: having both dynamic and static variables

2011-03-05 Thread Steven D'Aprano
On Thu, 03 Mar 2011 06:19:41 -0800, Westley Martínez wrote:

> On Wed, 2011-03-02 at 19:45 -0800, Yingjie Lan wrote:
>> Hi everyone,
>> 
>> Variables in Python are resolved dynamically at runtime, which comes at
>> a performance cost. However, a lot of times we don't need that feature.
>> Variables can be determined at compile time, which should boost up
>> speed.
[...]
> I once used this obscure language called "C"; it did kind of what you're
> talking about.

I'm told that there might be a couple of programming languages other than 
Python and C. Personally, I find that hard to believe. Why would the 
world need _three_ programming languages?



*wink*

-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list