Is there anyway to check the number of I/O registered in poll?

2011-03-29 Thread crow
I'm using select.poll to do I/O polling. polling is placed in a
independent thread

from select import poll
_poller = poll()

def poll(timeout):
l = _poller.poll(timeout)
return l

In my code, in some context, the timeout value will be high ( like 1
hour ), but there is no I/O in _poller, then this poll action will be
blocked till timeout.

Is there anyway to find how many I/O in _poller? Thus I can avoid
polling.

Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: delete namespaces

2011-03-29 Thread Terry Reedy

On 3/29/2011 9:14 PM, monkeys paw wrote:

How do i delete a module namespace once it has been imported?

I use

import banner

Then i make a modification to banner.py. When i import it again,
the new changes are not reflected.


The best thing, if possible, is to restart the program.
If you develop banner.py with adequate tests, you will want to restart 
the test anyway, and you should not need to modify much thereafter.


--
Terry Jan Reedy

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


Re: Python3 Tkinter difficulty

2011-03-29 Thread harrismh777

Terry Reedy wrote:

[python] 3.2 (which you should definitely be starting with) should, I think, be
looking for [dev-tk] 8.5, which I believe is years old now and required, I also
believe, for the tkinter.ttk module.


Thanks everyone for your patience, and certainly for your help. I pulled 
down tk-dev 8.5 from the repository (I did not modify anything in the 
config setup.py manually), then this:


./configure --prefix=$HOME/local/python3
make
make install

This time the build process picked up the TclTk headers just fine and 
built the _tkinter module. IDLE is back on-line!--- yess.


Thanks again folks,
kind regards,

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


Re: multiprocessing Pool.imap broken?

2011-03-29 Thread Yang Zhang
On Tue, Mar 29, 2011 at 6:44 PM, Yang Zhang  wrote:
> I've tried both the multiprocessing included in the python2.6 Ubuntu
> package (__version__ says 0.70a1) and the latest from PyPI (2.6.2.1).
> In both cases I don't know how to use imap correctly - it causes the
> entire interpreter to stop responding to ctrl-C's.  Any hints?  Thanks
> in advance.
>
> $ python
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 import multiprocessing as mp
 mp.Pool(1).map(abs, range(3))
> [0, 1, 2]
 list(mp.Pool(1).imap(abs, range(3)))
> ^C^C^C^C^\Quit
>

In case anyone jumps on this, this isn't an issue with running from the console:

$ cat /tmp/go3.py
import multiprocessing as mp
print mp.Pool(1).map(abs, range(3))
print list(mp.Pool(1).imap(abs, range(3)))

$ python /tmp/go3.py
[0, 1, 2]
^C^C^C^C^C^\Quit

(I've actually never seen the behavior described in the corresponding
Note at the top of the multiprocessing documentation.)
-- 
http://mail.python.org/mailman/listinfo/python-list


multiprocessing Pool.imap broken?

2011-03-29 Thread Yang Zhang
I've tried both the multiprocessing included in the python2.6 Ubuntu
package (__version__ says 0.70a1) and the latest from PyPI (2.6.2.1).
In both cases I don't know how to use imap correctly - it causes the
entire interpreter to stop responding to ctrl-C's.  Any hints?  Thanks
in advance.

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing as mp
>>> mp.Pool(1).map(abs, range(3))
[0, 1, 2]
>>> list(mp.Pool(1).imap(abs, range(3)))
^C^C^C^C^\Quit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: delete namespaces

2011-03-29 Thread Tim Chase

On 03/29/2011 08:14 PM, monkeys paw wrote:

How do i delete a module namespace once it has been imported?

I use

import banner

Then i make a modification to banner.py. When i import it again,
the new changes are not reflected. Is there a global variable i can
modify?


Delete it from sys.modules:

>>> file('foo.py', 'w').write('x = 42\n')
>>> import foo
>>> foo.x
42
>>> del foo
>>> import sys
>>> del sys.modules['foo']
>>> file('foo.py', 'w').write('x = 999\n')
>>> import foo
>>> foo.x
999

Beware that if you still have old references to the module, they 
don't get refreshed.


-tkc


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


Re: delete namespaces

2011-03-29 Thread Raymond Hettinger
On Mar 29, 6:14 pm, monkeys paw  wrote:
> How do i delete a module namespace once it has been imported?
 . . .
> Then i make a modification to banner.py. When i import it again,
> the new changes are not reflected. Is there a global variable i can
> modify?

In Python2.x, you can use the reload() function:

Help on built-in function reload in module __builtin__:

reload(...)
reload(module) -> module

Reload the module.  The module must have been successfully
imported before.


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


delete namespaces

2011-03-29 Thread monkeys paw

How do i delete a module namespace once it has been imported?

I use

import banner

Then i make a modification to banner.py. When i import it again,
the new changes are not reflected. Is there a global variable i can
modify?
--
http://mail.python.org/mailman/listinfo/python-list


Re: send function keys to a legacy DOS program

2011-03-29 Thread Justin Ezequiel
On Tue, Mar 29, 2011 at 9:59 PM, Alexander Gattin  wrote:
> I'm not sure regarding the ASCII part. I think it
> might need to be set to 0x00 for all functional
> keys instead of 0x3F/0x3C/0x41, but probably no
> application actually cares.
>
> Another thing is that you may need to send key
> release after key press in order for the
> application to trigger the F5/F2/F7 event. I'm not
> sure what the scan codes for F5/F2/F7 releases
> are, but think that they may be:
>
> F5: 0xBF
> F2: 0xBC
> F7: 0xC1
>
> --
> With best regards,
> xrgtn
>

appreciate all the help.
unfortunately, my hard drive crashed and badly.
thus was unable to investigate this further.
as I was running out of time, we're now going for a reimplementation
of the legacy barcode program.
was fortunate to find an implementation that gives the same output
(we're testing thoroughly and we may have found a winner)

oh btw, it was a seagate  250GB drive for my dell laptop
may need to pay somebody to try to recover my personal files.
all work files are in version control so they're ok
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Paul Rubin
Ian Kelly  writes:
> cmp_to_key(lambda x, y: -cmp(x, y))

cmp_to_key(lambda x, y: cmp(y, x))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to create a virtual printer

2011-03-29 Thread eryksun ()
On Monday, March 28, 2011 7:12:23 AM UTC-4, kalo...@gmail.com wrote:
> 
> Does anybody know how to create a virtual
> printer with python (on both windows and linux)?

Here's some code I just put together showing how to use Python to create a 
PostScript file printer on Windows, output raw text to a file, and also output 
text with fonts and simple line graphics. You'll need the pywin32 extensions. 

This code is only minimally tested, and it does little if any error checking. 
However, this is just to demonstrate the gist of using pywin32 for printing 
PostScript to a file. If you get an error about finding the driver for "MS 
Publisher Imagesetter', you may need to add the printer manually to make the 
driver available (it's under the 'generic' manufacturer). No doubt there's a 
way to install this driver automatically using the Win32 API, but I haven't 
looked into it.

The generated PostScript file can be viewed on Windows using the evince viewer:

http://live.gnome.org/Evince/Downloads

#

import win32print, win32ui, win32gui
import win32con, pywintypes

def create_printer(printer_name='MyPSPrinter'):
printer_info = {
'pPrinterName': printer_name,
'pDevMode': pywintypes.DEVMODEType(),
'pDriverName': 'MS Publisher Imagesetter',
'pPortName': 'FILE:',
'pPrintProcessor': 'WinPrint',
'Attributes': 0,
'AveragePPM': 0,
'cJobs': 0,
'DefaultPriority': 0,
'Priority': 0,
'StartTime': 0,
'Status': 0,
'UntilTime': 0,
'pComment': '',
'pLocation': '',
'pDatatype': None,
'pParameters': None,
'pSecurityDescriptor': None,
'pSepFile': None,
'pServerName': None,
'pShareName': None}

h_printer = win32print.AddPrinter(None, 2, printer_info)
return h_printer


def test_raw(printer='MyPSPrinter',
 filename=r'D:\test.txt',
 text=None):
'''send plain text to a file'''
if text is None:
text_data = "This is a test. This is only a test."
else:
text_data = text
job_info = ("Raw File Print", filename, 'RAW')
h_printer = win32print.OpenPrinter(printer)
try:
h_job = win32print.StartDocPrinter(h_printer, 1, job_info)
try:
win32print.StartPagePrinter(h_printer)
win32print.WritePrinter(h_printer, text_data)
win32print.EndPagePrinter(h_printer)
finally:
win32print.EndDocPrinter(h_printer)
finally:
win32print.ClosePrinter(h_printer)


def test_ps(printer='MyPSPrinter',
filename=r'D:\test.ps',
margin=(0.25,1.5,0.25,1.0),
font_size=24,
text=None):
'''render postscript text and graphics to a file'''
if text is None:
text_data = "This is a test.\nThis is only a test."
else:
text_data = str(text)

# Get the printer's DEVMODE structure
h_printer = win32print.OpenPrinter(printer)
devmode = win32print.GetPrinter(h_printer, 2)['pDevMode']
win32print.ClosePrinter(h_printer)

# set up the device context
# see MSDN: ff552837, aa452943, dd319099, dd145045
devmode.FormName = 'Letter'  # or 'A4'
devmode.PaperSize = win32con.DMPAPER_LETTER  # or DMPAPER_A4
devmode.Orientation = win32con.DMORIENT_PORTRAIT 
devmode.PrintQuality = win32con.DMRES_HIGH
devmode.Color = win32con.DMCOLOR_MONOCHROME
devmode.TTOption = win32con.DMTT_SUBDEV
devmode.Scale = 100
devmode.Fields |= (win32con.DM_FORMNAME | 
   win32con.DM_PAPERSIZE | 
   win32con.DM_ORIENTATION | 
   win32con.DM_PRINTQUALITY | 
   win32con.DM_COLOR | 
   win32con.DM_TTOPTION | 
   win32con.DM_SCALE)
h_dc = win32gui.CreateDC('WINSPOOL', printer, devmode)
dc = win32ui.CreateDCFromHandle(h_dc)
dc.SetMapMode(win32con.MM_TWIPS) # or MM_HIMETRIC (0.01 mm)

# begin writing the document
dc.StartDoc('Postscript File Print', filename)
dc.StartPage()

# we need a pen and a font
scale = 20  # 72 pt/inch * 20 twip/pt = 1440
inch = 72*scale
pen = win32ui.CreatePen(win32con.PS_SOLID,
scale, # 1 pt
0) # black
dc.SelectObject(pen)
font = win32ui.CreateFont({
'name': 'Times New Roman',
'height': font_size * scale,
'weight': win32con.FW_NORMAL})
dc.SelectObject(font)

# output the text
x = int(margin[0] * inch)
y = -int(margin[1] * inch)
width = int((8.5 - margin[0] - margin[2]) * inch)
height = int((11.0 - margin[1] - margin[3]) * inch)
rect = (x, y, x + width, y - height)
dc.DrawText(text_data, rect, win32con.DT_LEFT)

if text is None:
# draw 8 steps starting at x = 0.25", y = 3"
width = inch
height = inch
for n in range(8):
x 

Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Ian Kelly
On Tue, Mar 29, 2011 at 5:06 PM, MRAB  wrote:
> I think I've found a solution:
>
>    class NegStr:
>        def __init__(self, value):
>            self._value = value
>        def __lt__(self, other):
>            return self._value > other._value

IOW:

cmp_to_key(lambda x, y: -cmp(x, y))

This is still just taking a cmp function and dressing it up as a key.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread MRAB

On 29/03/2011 21:32, Dan Stromberg wrote:


On Tue, Mar 29, 2011 at 12:48 PM, Ian Kelly mailto:ian.g.ke...@gmail.com>> wrote:

On Tue, Mar 29, 2011 at 1:08 PM, Chris Angelico mailto:ros...@gmail.com>> wrote:
 > On Wed, Mar 30, 2011 at 5:57 AM, MRAB mailto:pyt...@mrabarnett.plus.com>> wrote:
 >> You would have to do more than that.
 >>
 >> For example, "" < "A", but if you "negate" both strings you get "" <
 >> "\xBE", not "" > "\xBE".
 >
 > Strings effectively have an implicit character at the end that's less
 > than any other character. Easy fix: Append a character that's greater
 > than any other. So "" < "A" becomes "\xFF" > "\xBE\xFF".
 >
 > Still not going to be particularly efficient.

Not to mention that it still has bugs:

"" < "\0"
"\xff" < "\xff\xff"
--
http://mail.python.org/mailman/listinfo/python-list


It probably could be a list of tuples:

'abc' -> [ (1, chr(255 - ord('a')), (1, chr(255 - ord('b')), (1, chr(255
- ord('c')), (0, '') ]

...where the (0, '') is an "end of string" marker, but it's getting
still slower, and quite a lot bigger, and getting so reductionistic
isn't a good thing when one class wraps another wraps another - when
their comparison methods are interrelated.


I think I've found a solution:

class NegStr:
def __init__(self, value):
self._value = value
def __lt__(self, other):
return self._value > other._value

so when sorting a list of tuples:

def make_key(t):
return NegStr(t[0]), t[1]

items = [("one", 1), ("two", 2), ("three", 3), ("four", 4), 
("five", 5)]

items.sort(key=make_key)
--
http://mail.python.org/mailman/listinfo/python-list


Only 7 Years

2011-03-29 Thread Cousin Stanley

  On May 8, 2004 I posted a note[1] here in comp.lang.python
  with a subject line of  Lost : Plot_Demo  looking for
  a small 2d plot program that I had seen, misplaced,
  and which I thought came along as a demo with a PYTHON 
  installation 

  This morning after rooting about in an old JYTHON demo dir
  I found the program in  Demo/awt/Graph.py  along with
  a comment that I had edited the file about 7 months
  before posting here looking for it ! 

  It's a very nice demo with a single text box
  to enter simple functions to be parsed and plotted 

  At least it's good to know that I'm only forgetful
  and not totally daft  :-)

  [1]
  http://groups.google.com/group/comp.lang.python  
/browse_thread/thread/54d4b716bfbdcb9c/f3e48b33fcf4e1d3

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Free Software University - Python Certificate - In reply to Noah Hall

2011-03-29 Thread Lloyd Hardy

Hi 'News123',

The message which you seem to think was a reply to you, wasn't. It was 
sent 2 days ago in reply to another message, not yours.


_03/27/2011_ 01:15 PM


Well, that is - as far as I know - I'm not sure if you're 'Noah Hall' or not.. 
maybe you are? That's the problem with having an alias I guess, lol.. maybe all 
three of us are the same person and this is a big conspiracy by a proprietary 
software company to make free software proponents look stupid? Lol... :D



(I mean, free education is always good),


> Not if you even don't know if this education really exists before
registering.


I didn't write that, lol...

..but I do think it's unusual that you're concerned about email 
harvesting.. yet post your email address on a mailing list.. That 
doesn't make any sense at all? I think each project owner decides the 
terms of their project. I feel academic pursuits require integrity - as 
all learning institutions do.. and accountability. Certificates cannot 
be awarded to aliases and teacher credentials cannot be verified. So, 
there will be no aliases in the FSU. I'm sorry if you do not agree with 
this, but it will not change - identity is important in any examination 
/ certification.


Please feel free to register for the FSU under your real name, not an alias. 
Please feel free to post reviews of the FSU after you have taken a course :)

It's very kind of you to make suggestions, thank you - although there has so 
far been no problem with attracting people - you appear to be misinformed :) 
I'm sure the community themselves will select a design / change of design of 
the FSU resources. If you'd like to join the FSU community then your views 
would certainly be considered :)

Thanks again!


Lloyd



On 29/03/11 22:01, News123 wrote:

Hi Loyd,


It wasn't me sending you the private email.

I'm just a little surprised about this: "if you don't post under your
real name you must be a bad person" - attitude.

On 03/27/2011 01:15 PM, Lloyd Hardy wrote:

Secondly, if you do use various names and email addresses and play
'maybe this is my identity' games, we really don't want you in the FSU -
as you are not an honest person - our work is based on the integrity of
the faculty and students.

Some people are just scared of data mining.

Having internet aliases has absolutely nothing with honesty, but just
about not wanting to be easily profiled by persons whom you don't even know.


To be a good member of whatever an identity is not important.
What counts are the contributions and the quality of the feed back




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


Re: Free Software University - Python Certificate - In reply to Noah Hall

2011-03-29 Thread News123
Hi Loyd,


It wasn't me sending you the private email.

I'm just a little surprised about this: "if you don't post under your
real name you must be a bad person" - attitude.

On 03/27/2011 01:15 PM, Lloyd Hardy wrote:
> Secondly, if you do use various names and email addresses and play
> 'maybe this is my identity' games, we really don't want you in the FSU -
> as you are not an honest person - our work is based on the integrity of
> the faculty and students.

Some people are just scared of data mining.

Having internet aliases has absolutely nothing with honesty, but just
about not wanting to be easily profiled by persons whom you don't even know.


To be a good member of whatever an identity is not important.
What counts are the contributions and the quality of the feed back


> 
>> (I mean, free education is always good),

Not if you even don't know if this education really exists before
registering.


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


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Dan Stromberg
On Tue, Mar 29, 2011 at 12:48 PM, Ian Kelly  wrote:

> On Tue, Mar 29, 2011 at 1:08 PM, Chris Angelico  wrote:
> > On Wed, Mar 30, 2011 at 5:57 AM, MRAB 
> wrote:
> >> You would have to do more than that.
> >>
> >> For example, "" < "A", but if you "negate" both strings you get "" <
> >> "\xBE", not "" > "\xBE".
> >
> > Strings effectively have an implicit character at the end that's less
> > than any other character. Easy fix: Append a character that's greater
> > than any other. So "" < "A" becomes "\xFF" > "\xBE\xFF".
> >
> > Still not going to be particularly efficient.
>
> Not to mention that it still has bugs:
>
> "" < "\0"
> "\xff" < "\xff\xff"
> --
> http://mail.python.org/mailman/listinfo/python-list
>

It probably could be a list of tuples:

'abc' -> [ (1, chr(255 - ord('a')), (1, chr(255 - ord('b')), (1, chr(255 -
ord('c')), (0, '') ]

...where the (0, '') is an "end of string" marker, but it's getting still
slower, and quite a lot bigger, and getting so reductionistic isn't a good
thing when one class wraps another wraps another - when their comparison
methods are interrelated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Chris Angelico
On Wed, Mar 30, 2011 at 6:48 AM, Ian Kelly  wrote:
> Not to mention that it still has bugs:
>
> "" < "\0"
> "\xff" < "\xff\xff"

That's because \0 isn't less than any character, nor is \xff greater
than any. However, the latter is true if (for instance) your string is
in UTF-8; it may be possible to use some construct that suits your own
data.

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


Re: Free Software University - Python Certificate - In reply to Noah Hall

2011-03-29 Thread News123
Hi Loyd,


Having a decent front page might help to attract people:

Go to http://www.freesoftwareuni.com/

and try to get any useful information except (free / GPL / not
accredited  / your email address)


With out signing in / without registering you don't even see what FSU
has to offer  / plans to offer

Probably you lost already many potential students, potential creators of
training material just by this choice of design.


If you force people to register before they see existing (or planned)
courses, then it easy to think, that this web site is just another way
of collecting email addresses.





On 03/26/2011 12:39 PM, Lloyd Hardy wrote:
> Noah Hall enalicho at gmail.com
> Tue Mar 22 17:38:48 CET 2011
> 
>>I've been following this project for a while, since it was annouced on
> the Ubuntu forums. I can't say that I've been at all impressed by
> anything they have to offer.
> 
> Hi Noah,
> 
> I'm interested in your post for a few reasons:
> 
> 1. There is no Noah Hall registered in the FSU
> 2. Your email address is not registered in the FSU
> 3. The FSU is really about what _you_ have to offer
> 4. As has already been noted, we are currently making courses
> 5. The first course (Free Software Certificate) starts 2nd May 2011
> 
> ..so, maybe you can help me to understand your post? It seems a strange
> post, based on these facts...
> 
> Maybe you'd like to come along and actually get involved? You would be
> most welcome.. our other 800 members will be happy to see you, I'm
> sure... come and contribute! :)
> 
> Lloyd
> FSU Founder

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


Re: Fun python 3.2 one-liner

2011-03-29 Thread Terry Reedy

On 3/29/2011 5:50 AM, Raymond Hettinger wrote:

from collections import Counter
from itertools import product

print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum,
product(range(6), repeat=8))).items(


The line break makes that hard to read; the axis is not labeled (and 
labels help understand the code). So my suggested revision is:


from collections import Counter
from itertools import product

print('\n'.join('{:2d}: {}'.format(i, '*'*(c//2000)) for i,c in sorted(
Counter(map(sum,product(range(6), repeat=8))).items() )))

 0:
 1:
 2:
 3:
 4:
 5:
 6:
 7: *
 8: ***
 9: *
10: 
11: 
12: **
13: *
14: 
15: *
16: *
17: 
18: **
19: **
20: ***
21: **
22: **
23: 
24: *
25: *
26: 
27: *
28: **
29: 
30: 
31: *
32: ***
33: *
34:
35:
36:
37:
38:
39:
40:

--
Terry Jan Reedy

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


Re: Non-deterministic output

2011-03-29 Thread John Nagle

On 3/28/2011 3:42 AM, Esben Nielsen wrote:

Hi,

We are making a prototype program in Python. I discovered the output was
non-deterministic, i.e. I rerun the program on the same input files and
get different output files. We do not use any random calls, nor
threading.

One of us thought it could be set and dictionaries not always yielding
the same results. I, however, would think that given the exact same
operations, a set/dictionary would always yield the same results. Am I
correct? Or could different runs of the same program yield different
results due to, say, different memory locations?

Are there any other sources of randomness we ought to look out for?

Esben


That's worth chasing down.  It's hard to accidentally get
nondeterminism in a single-thread batch Python program.
Core Python doesn't have uninitialized variables, the usual
source of trouble, because Python variables are created by
initialization, not declaration.

numpy, though, does have uninitialized variables. Try:

import numpy
a = numpy.empty(10)
print(a)

creates an array of 10 junk floating point numbers.  Look for that.
Also look at any other C packages you're using.  If you're stil
stuck, give us the list of non-Python modules you're importing,
directly or indirectly.

John Nagle

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


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Ian Kelly
On Tue, Mar 29, 2011 at 1:08 PM, Chris Angelico  wrote:
> On Wed, Mar 30, 2011 at 5:57 AM, MRAB  wrote:
>> You would have to do more than that.
>>
>> For example, "" < "A", but if you "negate" both strings you get "" <
>> "\xBE", not "" > "\xBE".
>
> Strings effectively have an implicit character at the end that's less
> than any other character. Easy fix: Append a character that's greater
> than any other. So "" < "A" becomes "\xFF" > "\xBE\xFF".
>
> Still not going to be particularly efficient.

Not to mention that it still has bugs:

"" < "\0"
"\xff" < "\xff\xff"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3 Tkinter difficulty

2011-03-29 Thread Terry Reedy

On 3/29/2011 1:52 PM, harrismh777 wrote:


Thanks. You're right... I don't have tk-dev installed. duh. And I have
choices to make... it looks like setup.py is looking for 8.4 headers; I


3.2 (which you should definitely be starting with) should, I think, be 
looking for 8.5, which I believe is years old now and required, I also 
believe, for the tkinter.ttk module.



have TclTk 8.5x installed. From the standard repository it looks like I
can download and install tk-dev (dependency package) and|or tk-dev 8.3,
or 8.4, or 8.5... and I am not sure which of these is what is needed
without causing other problems. Can 8.4 and 8.5 be installed together
without problem? Does it really matter which of these I use for the
purpose of python build? If I have TclTk 8.5 installed should I only
download the 8.5 tk-dev package?


I would start with that and then make that work.

--
Terry Jan Reedy

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


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Terry Reedy

For anyone interested, the tracker discussion on removing cmp is at
http://bugs.python.org/issue1771
There may have been more on the old py3k list and pydev list.

One point made there is that removing cmp= made list.sort consistent 
with all the other comparision functions, 
min/max/nsmallest/nlargest/groupby that only have a key arg. How many 
would really want cmp= added everywhere?


A minor problem problem with cmp is that the mapping between return 
values and input comparisons is somewhat arbitrary. Does -1 mean abforget without constant use).


A bigger problem is that it conflicts with key=. What is the result of
l=[1,3,2]
l.sort(cmp=lambda x,y:y-x, key=lambda x: x)
print l
? (for answer, see http://bugs.python.org/issue11712 )

While that can also be learned, I consider conflicting parameters 
undesireable and better avoided when reasonably possible. So I see this 
thread as a discussion of the meaning of 'reasonably' in this particular 
case.


--
Terry Jan Reedy

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


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Chris Angelico
On Wed, Mar 30, 2011 at 5:57 AM, MRAB  wrote:
> You would have to do more than that.
>
> For example, "" < "A", but if you "negate" both strings you get "" <
> "\xBE", not "" > "\xBE".

Strings effectively have an implicit character at the end that's less
than any other character. Easy fix: Append a character that's greater
than any other. So "" < "A" becomes "\xFF" > "\xBE\xFF".

Still not going to be particularly efficient.

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


Re: Fun python 3.2 one-liner

2011-03-29 Thread harrismh777

Raymond Hettinger wrote:

almost-normally-yours,

Raymond


thanks ... interesting

Seriously, these little one liners teach me more about the python 
language in less time than *all* of the books I'm trying to digest right 
now.  The toughest part of learning python is learning about what's 
available so as not to reinvent the proverbial wheel...


thanks again... fun.



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


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread MRAB

On 29/03/2011 18:01, Dan Stromberg wrote:


On Tue, Mar 29, 2011 at 1:46 AM, Antoon Pardon
mailto:antoon.par...@rece.vub.ac.be>> wrote:

The double sort is useless if the actual sorting is done in a different
module/function/method than the module/function/method where the order
is implemented. It is even possible you didn't write the module
where the sorting actually occurs.


There's a good point in the above.

Usually the order in which a class needs to be sorted, is a detail that
should be hidden by the class (or auxiliary comparison function).

Doing more than one sort in order to get one key forward and another in
reverse, seems to require a client of the class to know class detail (or
auxiliary comparison function detail).

In fact, if something inside the class (or auxiliary comparison
function) needs to change s.t. you must change how you sort its
instances, then you might have to change a bunch of single-sorts to
multiple-sorts in client code.  EG if you were sorting a number in
reverse followed by a string forward, to a number in reverse followed by
a string forward and another string in reverse.

In principle, you could come up with a "negate string" operation
though.  EG for Latin-1, each ch would become chr(255-ord(ch)).  That's
probably going to be rather expensive, albeit linear.  It should at
least avoid the need for multi-sorting and exposing implementation
detail.  I want to say you could do something similar for Unicode
strings, but I don't have enough experience with Unicode to be sure yet.


You would have to do more than that.

For example, "" < "A", but if you "negate" both strings you get "" <
"\xBE", not "" > "\xBE".
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fun python 3.2 one-liner

2011-03-29 Thread geremy condra
On Tue, Mar 29, 2011 at 11:24 AM, Raymond Hettinger  wrote:
 print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum, 
 product(range(6), repeat=8))).items(
>
>
>
>
>
>
>
>
> *
> ***
> *
> 
> 
> **
> *
> 
> *
> *
> 
> **
> **
> ***
> **
> **
> 
> *
> *
> 
> *
> **
> 
> 
> *
> ***
> *
>
>
>
> Re-posting (forgot to attach the output).
> Besides the interesting output, other
> interesting virtues include very low
> memory usage and that the inner-loop
> pipeline runs entirely in C.

Another (related) 3.2 one liner:

from math import erf, sqrt

def normal_cdf(x, mu=0, sigma=1): return (1/2) * (1 +
erf((x-mu)/(sigma*sqrt(2

approximates the cumulative distribution function of the normal distribution.

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


Re: Fun python 3.2 one-liner

2011-03-29 Thread Raymond Hettinger
>>> print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum, 
>>> product(range(6), repeat=8))).items(








*
***
*


**
*

*
*

**
**
***
**
**

*
*

*
**


*
***
*



Re-posting (forgot to attach the output).
Besides the interesting output, other
interesting virtues include very low
memory usage and that the inner-loop
pipeline runs entirely in C.


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


Re: Python3 Tkinter difficulty

2011-03-29 Thread harrismh777

Peter Otten wrote:

We don't eat children above the age of three;)


   geez... that's good news   :)


>  work... but, I'm at a bit of a loss to know exactly what its looking
>  for... libs, or libs and devel headers?   or other?



Most likely the development headers. Try installing tk-dev.

   Thanks. You're right... I don't have tk-dev installed. duh.  And I 
have choices to make...  it looks like setup.py is looking for 8.4 
headers; I have TclTk 8.5x installed.  From the standard repository it 
looks like I can download and install tk-dev (dependency package) and|or 
tk-dev 8.3, or 8.4, or 8.5...   and I am not sure which of these is what 
is needed without causing other problems.  Can 8.4 and 8.5 be installed 
together without problem?  Does it really matter which of these I use 
for the purpose of python build?  If I have TclTk 8.5 installed should I 
only download the 8.5 tk-dev package?


   sorry for being so dense... and I'm definitely over three... way too 
tough for eating or anything like that  :}




kind regards,




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


Re: Python-related Animation Packages?

2011-03-29 Thread Corey Richardson
On 03/29/2011 01:17 PM, Benjamin J. Racine wrote:
> Hello all,
> 
> Does anyone know of software that might be of use in an attempt to animate an 
> object undergoing 6-DOF rigid body motions: surge, sway, heave, roll, pitch 
> and yaw?
> 
> Thanks so much,
> Ben Racine
> 

Blender.

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


Python-related Animation Packages?

2011-03-29 Thread Benjamin J. Racine
Hello all,

Does anyone know of software that might be of use in an attempt to animate an 
object undergoing 6-DOF rigid body motions: surge, sway, heave, roll, pitch and 
yaw?

Thanks so much,
Ben Racine

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


Re: Directly Executable Files in Python

2011-03-29 Thread CM
On Mar 29, 12:16 am, harrismh777  wrote:
> Chris Rebert wrote:
> > Yes. py2exe is a tool which generates such Windows executables:
> >http://www.py2exe.org/
>
> Interesting... but it can't possibly be creating .exe files
> (compiling)... I don't buy it... it has to be reproducing the byte code
> interpreter in the code segment and the byte code in the data segment...
> so that each .exe file created by said process is actually loading an
> entire copy of at least the byte code interpreter with each program
> "compiled" ...  

Yes, if you think of it as a handy packager and not a compiler, it
makes sense.

> can't be very efficient??

How do you define efficient?  All I know is that it works well.  You
click on the .exe and a moment later you are running the application
despite not having Python or any of the third party libraries you've
used installed on your computer.  I'm grateful for its existence.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Directly Executable Files in Python

2011-03-29 Thread CM

> it has to be reproducing the byte code
> interpreter in the code segment and the byte code in the data segment...
> so that each .exe file created by said process is actually loading an
> entire copy of at least the byte code interpreter with each program
> "compiled" ...

Yes, if you think of it as a handy packager and not a compiler, it
makes sense.

> can't be very efficient??

How do you define efficient?  All I know is that it works well.  You
click on
the .exe and a moment later you are running the application despite
not having
Python installed on your computer.  I'm grateful for its existence.

Che

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


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Dan Stromberg
On Tue, Mar 29, 2011 at 1:46 AM, Antoon Pardon  wrote:

> The double sort is useless if the actual sorting is done in a different
> module/function/method than the module/function/method where the order
> is implemented. It is even possible you didn't write the module
> where the sorting actually occurs.
>

There's a good point in the above.

Usually the order in which a class needs to be sorted, is a detail that
should be hidden by the class (or auxiliary comparison function).

Doing more than one sort in order to get one key forward and another in
reverse, seems to require a client of the class to know class detail (or
auxiliary comparison function detail).

In fact, if something inside the class (or auxiliary comparison function)
needs to change s.t. you must change how you sort its instances, then you
might have to change a bunch of single-sorts to multiple-sorts in client
code.  EG if you were sorting a number in reverse followed by a string
forward, to a number in reverse followed by a string forward and another
string in reverse.

In principle, you could come up with a "negate string" operation though.  EG
for Latin-1, each ch would become chr(255-ord(ch)).  That's probably going
to be rather expensive, albeit linear.  It should at least avoid the need
for multi-sorting and exposing implementation detail.  I want to say you
could do something similar for Unicode strings, but I don't have enough
experience with Unicode to be sure yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Jean-Michel Pichavant

Steven D'Aprano wrote:

On Fri, 25 Mar 2011 10:21:35 +0100, Antoon Pardon wrote:

  

On Thu, Mar 24, 2011 at 11:49:53PM +, Steven D'Aprano wrote:


On Thu, 24 Mar 2011 17:47:05 +0100, Antoon Pardon wrote:

  

However since that seems to be a problem for you I will be more
detailed. The original poster didn't ask for cases in which cmp was
necessary, he asked for cases in which not using cmp was cumbersome.


I'm the original poster, and that's not what I said. I said:

"If anyone has any use-cases for sorting with a comparison function
that either can't be written using a key function, or that perform
really badly when done so, this would be a good time to speak up."

You'll notice that I said nothing about whether writing the code was
easy or cumbersome, and nothing about readability.
  

Well fine. I should have realised the question was just a pretense and
that there really never was any intention to consider the reactions,
because the answer is already fixed. Of course a key function can always
be written, it may just need a specific class to implement the specific
order. Likewise there is no reason to expect the order-functions to
preform worse when implemented in a class, rather than in a function.



The reason Guido is considering re-introducing cmp is that somebody at 
Google approached him with a use-case where a key-based sort did not 
work. The use-case was that the user had masses of data, too much data 
for the added overhead of Decorate-Sort-Undecorate (which is what key 
does), but didn't care if it took a day or two to sort.


So there is at least one use-case for preferring slowly sorting with a 
comparison function over key-based sorting. I asked if there any others. 
It seems not.



  
That was known from the begining, was it ? Since key sort trades memory 
for CPU, you could expect that "masses of data" use cases may fail 
because of memory shortage.


JM

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


Re: send function keys to a legacy DOS program

2011-03-29 Thread Mel
Alexander Gattin wrote:
> Another thing is that you may need to send key
> release after key press in order for the
> application to trigger the F5/F2/F7 event. I'm not
> sure what the scan codes for F5/F2/F7 releases
> are, but think that they may be:
>
> F5: 0xBF
> F2: 0xBC
> F7: 0xC1

True.  The key-release codes are the key-press codes (the "key numbers")
but with the high-order bit set.

Mel.

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


your web page details

2011-03-29 Thread radha krishnan
 http://123maza.com/65/agent409/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popular programs made in python?

2011-03-29 Thread Corey Richardson
On 03/29/2011 10:32 AM, Neil Alt wrote:
> i mean made with python only, not just a small part of python.

Civilisation 4 (the game) used Python for all of its scripting. As far
as I know almost all the game logic was in Python, and you could access
most parts of the game.

Blender also has a rather extensive Python API that allows you to make
scripts that can access any part of the software, or almost any part of it.

Just look at http://en.wikipedia.org/wiki/List_of_Python_software
It's not a complete list either.
-- 
Corey Richardson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popular programs made in python?

2011-03-29 Thread Neil Alt
yeah nice example :) impressive.

On 3/29/11, Chris Angelico  wrote:
> On Wed, Mar 30, 2011 at 1:32 AM, Neil Alt  wrote:
>> i mean made with python only, not just a small part of python.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
> You're using one right now. Mailman is written in Python, and it
> manages countless mailing lists the world over. I have it running all
> the lists on my mail server, it's powerful and easy to set up.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popular programs made in python?

2011-03-29 Thread Chris Angelico
On Wed, Mar 30, 2011 at 1:32 AM, Neil Alt  wrote:
> i mean made with python only, not just a small part of python.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

You're using one right now. Mailman is written in Python, and it
manages countless mailing lists the world over. I have it running all
the lists on my mail server, it's powerful and easy to set up.

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


popular programs made in python?

2011-03-29 Thread Neil Alt
i mean made with python only, not just a small part of python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Directly Executable Files in Python

2011-03-29 Thread Grant Edwards
On 2011-03-29, harrismh777  wrote:
> Chris Rebert wrote:
>> Yes. py2exe is a tool which generates such Windows executables:
>> http://www.py2exe.org/
>
> Interesting... but it can't possibly be creating .exe files

It is.

> (compiling)...

It isn't.

> I don't buy it...

Then don't.

> it has to be reproducing the byte code interpreter in the code
> segment and the byte code in the data segment...

Something like that.

-- 
Grant Edwards   grant.b.edwardsYow! Either CONFESS now or
  at   we go to "PEOPLE'S COURT"!!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: send function keys to a legacy DOS program

2011-03-29 Thread Alexander Gattin
Hello,

On Sun, Mar 20, 2011 at 06:59:46PM -0700, Justin
Ezequiel wrote:
> On Mar 20, 7:30 am, Alexander Gattin
>  wrote:
> > You need to place 2 bytes into the circular buffer
> > to simulate key press. Lower byte is ASCII code,
> > higher byte is scan code (they are the same for
> > functional keys, whe using default keycode set#1):
> >
> > F5: 0x3F 0x3F
> > F2: 0x3C 0x3C
> > F7: 0x41 0x41

I'm not sure regarding the ASCII part. I think it
might need to be set to 0x00 for all functional
keys instead of 0x3F/0x3C/0x41, but probably no
application actually cares.

Another thing is that you may need to send key
release after key press in order for the
application to trigger the F5/F2/F7 event. I'm not
sure what the scan codes for F5/F2/F7 releases
are, but think that they may be:

F5: 0xBF
F2: 0xBC
F7: 0xC1

-- 
With best regards,
xrgtn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Linux drives me crazy... Rights, listdir...

2011-03-29 Thread durumdara
Hi!

Sorry. The path was wrong! "backup_redmine <> redmine_backup"... :-(

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


Re: Directly Executable Files in Python

2011-03-29 Thread Ethan Furman

harrismh777 wrote:

Chris Rebert wrote:

Yes. py2exe is a tool which generates such Windows executables:
http://www.py2exe.org/


Interesting... but it can't possibly be creating .exe files 
(compiling)...


Yes and no.  The python program is not being compiled.  The Python 
system, along with all the necessary libraries and support .py files, 
are combined into a .exe loader.  When the .exe is run it extracts the 
Python interpreter, makes all the other files available, and then starts 
it running.*


~Ethan~

*The details are not exact, but this is the general idea.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fun python 3.2 one-liner

2011-03-29 Thread Xavier Ho
http://www.ideone.com/infch
^ Result of the below code

On 29 March 2011 19:50, Raymond Hettinger  wrote:

> from collections import Counter
> from itertools import product
>
> print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum,
> product(range(6), repeat=8))).items(
>
>
> almost-normally-yours,
>
> Raymond
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Fun python 3.2 one-liner

2011-03-29 Thread Raymond Hettinger
from collections import Counter
from itertools import product

print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum,
product(range(6), repeat=8))).items(


almost-normally-yours,

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


Linux drives me crazy... Rights, listdir...

2011-03-29 Thread durumdara
Dear Everybody!

We have a redmine server with linux.
I wrote some pythonic tool that backup the redmine (files and
database) and put to ftp server.

This was working fine.

But today I checked, and I saw this failed in the prior week.
As I checked more, I saw that part. is out of space.
I stored the files, logs, dumps in the /home, and this dev. is out of
space.

Then I tried to move to /var/www/redmine_backup folder.

And then I got result what I don't understand.

In root mode I set the user on every file and directory, and set the
mode to 777, and set sticky bit, and user/group on execution.
Everything is same, but when I check os.listdir() on this dir, I see
only two folders.

5 elements are here:
Files_Zipped (dir)
MySQL_Dump (dir)
Log (dir)
Log2 (dir)
BackupRedmine.py (the script)

The listdir show only:
Files_Zipped
MySQL_Dump

(It don't see itself!)

Because it don't see the Log dir, try to make it, and it have been
failed...

I checked all things in MC too, but I cannot find the differents...
May this is Python bug?

xuser@h2182:~$ /var/www/backup_redmine/BackupRedMine.py /log
RedMine Backup V1.0
Log mode
Make and get backup path
Try to make /var/www/redmine_backup/Log
Traceback (most recent call last):
File "/var/www/backup_redmine/BackupRedMine.py", line 239, in 
logfilename = MakeBackupPath(_SubPath_Log) + '/log_' + NowStr
File "/var/www/backup_redmine/BackupRedMine.py", line 78, in
MakeBackupPath
os.makedirs(path)
File "/usr/lib/python2.5/os.py", line 171, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/var/www/redmine_backup/Log'

xuser@h2182:/var/www/backup_redmine$ ./BackupRedMine.py /log
RedMine Backup V1.0
Log mode
Make and get backup path (os.listdir)
['Files_Zipped', 'MySQL_Dump']
xuser@h2182:/var/www/backup_redmine$ ls -l
total 24
-rwxrwxrwt 1 xuser xuser 7350 2011-03-29 10:47 BackupRedMine.py
drwsrwsrwt 2 xuser xuser 4096 2011-03-29 09:46 Files_Zipped
drwsrwsrwt 2 xuser xuser 4096 2011-03-29 10:36 Log
drwsrwsrwt 2 xuser xuser 4096 2011-03-29 10:42 Log2
drwsrwsrwt 2 xuser xuser 4096 2011-03-29 09:46 MySQL_Dump

But interesting thing is that everything is working good on /home.

So it is seems to be right problem, but what is the different?

What can I do?

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


Great chance for Management work.

2011-03-29 Thread gaurav
Railroad employers, opportunities in only on the site for government,
banking and data entry.
http://rojgars.webs.com/Railwayjobs.htm  http://rojgars1.webs.com/gov.htm

Cash income in Management careers.
Globalize Management careers.
http://managementjobs.webs.com/mm.htm 
http://jobshunter.webs.com/industrialmanagement.htm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3 Tkinter difficulty

2011-03-29 Thread Peter Otten
harrismh777 wrote:

> Greetings folks,
> I am very new to this usenet forum, and I am brand new to Python3...

Welcome.

> so be gentle 

We don't eat children above the age of three ;)

> The source tarball for Python3 compiled and installed (local install
> for first experiments $HOME/local/) and runs very well in my terminal.
> I am not able to run IDLE because the compile build process could
> not build the _tkinter module, I think because TclTk is not installed on
> this system in the standard places... Ubuntu 9.04 Jaunty.  I have TclTk
> installed version 8.5x and tclsh and wish work fine... also IDLE on
> python 2.62 works fine too.
> I am noticing that setup.py has the path to the TclTk libs hardcoded
> for /usr/X11R6/...  and my TclTk is not there... so I'm thinking that I
> need to direct the setup.py path to the right place and thinngs should
> work... but, I'm at a bit of a loss to know exactly what its looking
> for... libs, or libs and devel headers?   or other?

Most likely the development headers. Try installing tk-dev.

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


Re: New blog from python-dev

2011-03-29 Thread Ivan Vilata i Balaguer
Doug Hellmann (2011-03-24 14:58:30 +0100) wrote:

> Python Insider (http://blog.python.org/) is a new blog from the Python
> core development team. [...] There are a variety of ways to subscribe,
> including email and Twitter. [...]

Hi Doug, this is great news, thank you!

I've tried to subscribe to the RSS feed (my reader doesn't support Atom)
but although I'm following the link labeled as RSS, I'm still getting an
Atom feed via FeedBurner.  May this be a problem with FeedBurner
configuration, or I'd better use another subscription mechanism?

Thank you very much!

-- 
Ivan Vilata i Balaguer -- http://ivan.lovesgazpacho.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


hi joining me

2011-03-29 Thread kalpana N
ms.kalpana2...@rediffmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Antoon Pardon
On Mon, Mar 28, 2011 at 03:43:03PM +, Steven D'Aprano wrote:
> On Mon, 28 Mar 2011 14:39:04 +0200, Antoon Pardon wrote:
> 
> > I tried to sort lists of 1 elemens. Each element a tuple two items
> > that was to be sorted first according to the first item in ascending
> > order, then according to the second item in descending order. This was
> > done on python 2.6 so I had to write my own cmp_to_key function.
> > 
> > I then sorted these lists of 1 elements a 1000 times with the
> > following methods.
> 
> Thank you for spending the time to get some hard data, but I can't 
> replicate your results since you haven't shown your code. Rather than 
> attempt to guess what you did and duplicate it, I instead came up with my 
> own timing measurements. Results are shown here, my code follows below:

But why expect me to come up with such data? Shouldn't the dev team have
come up with such data before they decided to remove the cmp-argument,
instead of afterwards expecting the python users to come up with data
to support the reversing of that decision?

> [steve@sylar ~]$ python2.7 sort_test.py
> Comparison function: 12.1256039143
> Key function: 3.51603388786
> Double sort: 2.33165812492
> cmp_to_key: 28.1129128933
> 
> 
> By far the best result comes from two calls to sort. Not far off is the 
> key function solution. (Admittedly, coming up with a key function for non-
> numeric data would be challenging.) The comparison function, and the 
> cmp_to_key solution, are clearly *much* slower.

So, that means that the fastest solutions don't generalize.

The double sort is useless if the actual sorting is done in a different
module/function/method than the module/function/method where the order
is implemented. It is even possible you didn't write the module 
where the sorting actually occurs.

Your key-function only works with numeric data, strings already pose
a problem here. 

The cmp function can be externally provided, without you having the
source.

So sooner or later there will be a user who just doesn't have a
choice but to use cmp_to_key or something similar. and who will
have to suffer this kind of speed loss.

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


Re: Directly Executable Files in Python

2011-03-29 Thread Paul Rudin
Benjamin Kaplan  writes:


> If you can figure out a good way to compile a language like Python,
> you'll be very rich. Yes, it is running the interpreter and then
> running the bytecode on the interpreter. It's the same way Java and
> .NET work.

Not exactly AIUI. .NET bytecodes do actually get compiled to executable code
before being executed (unless things have changed recently - I haven't
really done anything significant with .NET in the last couple of years).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Antoon Pardon
On Mon, Mar 28, 2011 at 11:35:09AM +, Steven D'Aprano wrote:

> [...]
> > Forcing people to use a key-function, will produce cases where python
> > will ask for more memory and take longer to sort, than allowing to
> > provide a cmp function.
> 
> More memory yes; take longer to sort, almost certainly not (except, 
> perhaps, for a very narrow window where the addition of a key causes the 
> application to page out to virtual memory, but a comparison function 
> wouldn't -- and even then, the key function might still be faster).
> 
> But we've already covered the "more memory" angle to death. We already 
> understand that. This is why I have asked if there are any *other* use-
> cases for a comparison function.
> 
> Dan Stromberg has suggested that another use-case would be lazy-
> comparisons, where you might not be able to generate a single key 
> cheaply, but you can perform a comparison lazily.
> 
> 
> > This for the simple reason that for some
> > order-functions, the only way to write a key-function will be to write a
> > specific class, that will implement the order with the same kind of code
> > that otherwise would have been put in the cmp function, 
> 
> There is a recipe for that on ActiveState's website, google for 
> cmp_to_key. That recipe has been added to Python's standard library for 
> version 3.2. Please stop flogging that dead horse.

This doesn't make any sense. As far as I can see there is nothing in Dan's
code that would make it more troublesome to use with cmp_to_key than Carl
Bank's examples or that would make it loose more speed than the overhead
I was describing.

Whatever is meant by lazily, the cmp_to_key function will generate a key
function that during the sorting will finally defer to this cmp-function
to do the comparisons. If the cmp is lazy when it does its work as a
cmp-argument, it will be lazy when it does its work when a key is wrapped
around it.

This argument works for whatever property, the cmp-function should posses.
If your cmp argument has property foo when comparing during a sort then
using cmp_to_key will preserve than property when comparing during a sort.
This for the simple reason that with a cmp_to_key function when the
sort comapares two keys, it will after some overhead just call the cmp
function with the undecorated data.

That means that asking for use cases that fall outside the overhead in
memory or speed of the cmp_to_key function and are not about the cumbersome
work in writing your own key-function in order to reduce that overhead,
that asking for such use cases is like asking for a real number that squares
to a negative. We can conclude a priori that there won't be any.

That is why I don't consider a request for such use cases a serious request.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-deterministic output

2011-03-29 Thread Esben Nielsen

On Mon, 2011-03-28 at 12:58 +0100, Tim Wintle wrote:
> On Mon, 2011-03-28 at 12:42 +0200, Esben Nielsen wrote:
> > We are making a prototype program in Python. I discovered the output was
> > non-deterministic, i.e. I rerun the program on the same input files and
> > get different output files. We do not use any random calls, nor
> > threading.
> > 
> > One of us thought it could be set and dictionaries not always yielding
> > the same results. I, however, would think that given the exact same
> > operations, a set/dictionary would always yield the same results. Am I
> > correct? Or could different runs of the same program yield different
> > results due to, say, different memory locations?
> 
> If you're using id() at any point (e.g. in __hash__ ) then that would
> lead to non-deterministic behaviour.
> 
I changed my code to use other kinds of hash. That helped! :-) Thanks!

> obviously so would time.time() etc.

I didn't use those :-)
> 
> 

Esben



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


Python3 Tkinter difficulty

2011-03-29 Thread harrismh777

Greetings folks,
   I am very new to this usenet forum, and I am brand new to Python3... 
so be gentle 
   The source tarball for Python3 compiled and installed (local install 
for first experiments $HOME/local/) and runs very well in my terminal.
   I am not able to run IDLE because the compile build process could 
not build the _tkinter module, I think because TclTk is not installed on 
this system in the standard places... Ubuntu 9.04 Jaunty.  I have TclTk 
installed version 8.5x and tclsh and wish work fine... also IDLE on 
python 2.62 works fine too.
   I am noticing that setup.py has the path to the TclTk libs hardcoded 
for /usr/X11R6/...  and my TclTk is not there... so I'm thinking that I 
need to direct the setup.py path to the right place and thinngs should 
work... but, I'm at a bit of a loss to know exactly what its looking 
for... libs, or libs and devel headers?   or other?

   Help/Hints would be appreciated from the initiated... humbly greatful...

kind regards,
m harris
--
http://mail.python.org/mailman/listinfo/python-list