Re: annonymous functions -- how to

2005-05-06 Thread Fredrik Lundh
Dave Benjamin wrote:

 In this case, having to name these callback functions is tiring and
 awkward, and (IMHO) disrupts the flow of my function:

so name them all func or next or something, so you don't have
to think.  once the object is bound, the name is irrlevant.

 def add_thingy():
  def next_thingy_id_func(thingy_id):
  print 'got thingy id:', thingy_id
  def next_doodad_id_func(doodad_id):
  print 'got doodad id:', doodad_id
  def new_thingy_doodad_func(thingy_doodad):
  print 'thingy doodad created, froobling...'
  frooble(thingy_doodad)
  print 'froobling complete'
  with_new_thingy_doodad(thingy_id, doodad_id,
 new_thingy_doodad_func)
  with_next_doodad_id(next_doodad_id_func)
  with_next_thingy_id(next_thingy_id_func)

there's also:

def add_thingy(self):

yield get_new_thingy_id; thingy_id = self.result

print 'got thingy id:', thingy_id

yield get_new_doodad_id; doodad_id = self.result

print 'got doodad id:', doodad_id

yield get_new_thingy_doodad; thingy_doodad = self.result

print 'thingy doodad created, froobling...'
frooble(thingy_doodad)
print 'froobling complete'

/F



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


Re: Hard times with packages and instances

2005-05-06 Thread Fredrik Lundh
Kay Schluehr wrote:

  if you manage to import the same thing multiple times, you'll have
  multiple class objects representing the same source code, and is-
  instance won't work properly.

 Importing a class/module multiple times does not cause the problem.
 Writing

   import ForeignPackage.B as B1
   import ForeignPackage.B as B2

that doesn't import it more than once; Python uses a cache to hold
modules, but the cache only works if Python can be sure that the
modules are the same thing, based on the information in the *import*
statement.  in this case, ForeignPackage.B is clearly the same thing
as ForeignPackage.B.

if you change the path around (in your case, by adding MyPackage to
the path, rather than relying on path-relative import), you'll introduce
multiple ways to import the same module, and the cache won't work
properly.  and when the cache doesn't work, isinstance breaks down
for the reason I stated.

 Flattening the package structure would solve the problem as well as
 destroying all file-system based packages and abandon them from Python.

well, packages for just fine for me.  if you cannot get them to work,
maybe you should stop doing things that don't work.

/F



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


Re: How to detect a double's significant digits

2005-05-06 Thread Fredrik Lundh
Jeremy Bowers wrote:

  A step which will require him to tell the printing routine how many digits
  he wants printed.

 Not necessarily; consider the str() of a float in Python, especially given
 the significant digits aspect (it may be ill-defined, but I can think of
 several well-defined ways to mean that, where str() embodies one of them).
 The easiest way to tell how long the number will be when str prints it out
 is to simply ask it.

and what language is str() implemented in?

 In C++, this may be harder, as your output software may insist on
 rendering everything directly, with no way to reach in and tell what it
 did. Imagine the standard IOStreams, without the ability to stream into a
 string.

but you can stream into a string buffer, and you can use sprintf() from C++,
so what's your point, besides stating that if things were harder, they would
be harder?

/F



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


Weird UserArray AttributeError (bug ?)

2005-05-06 Thread George Sakkis
I came across a strange error when trying to define a settable property
for a new-style subclass of UserArray (Numeric). Here's a shorter
example that reproduces the problem:


from UserArray import UserArray
from math import hypot

class Vector(UserArray,object):
def __init__(self,x,y):
super(Vector,self).__init__((x,y))

def _fget(self): return hypot(*self)
def _fset(self, m): self *= m/self.magnitude
magnitude = property(_fget, _fset)


v = Vector(3.,4.)
print v.magnitude
# the line below prints an infinite sequence of:
# Exception exceptions.AttributeError: can't delete attribute
# in  ignored
v.magnitude = 10


Any ideas on what's going on and if there's a workaround ?

George

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


RFC 2822 format date printing function in python

2005-05-06 Thread praba kar
Dear All,

   In Php we can print RFC 2822 formatted date by
date('r') with parameter r.  Then it will print the
below format date.
Thu,  7 Apr 2005 01:46:36 -0300.
I want to print same RFC 2822 format in python. Is it
possible in python? . If possible kindly mention the
function related to print RFC format date

regards,
Prabahar 


Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
-- 
http://mail.python.org/mailman/listinfo/python-list


hard memory limits

2005-05-06 Thread Maurice LING
Hi,

I think I've hit a system limit in python when I try to construct a list 
of 200,000 elements. My error is

malloc: vm_allocate (size = 2400256) failed..

Just wondering is this specific to my system or what? Will adding more 
RAM helps in this case?

Thanks and cheers
Maurice
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hard times with packages and instances

2005-05-06 Thread Kay Schluehr
Fredrik Lundh wrote:
 Kay Schluehr wrote:

   if you manage to import the same thing multiple times, you'll
have
   multiple class objects representing the same source code, and is-
   instance won't work properly.
 
  Importing a class/module multiple times does not cause the problem.
  Writing
 
import ForeignPackage.B as B1
import ForeignPackage.B as B2

 that doesn't import it more than once; Python uses a cache to hold
 modules, but the cache only works if Python can be sure that the
 modules are the same thing, based on the information in the *import*
 statement.  in this case, ForeignPackage.B is clearly the same
thing
 as ForeignPackage.B.

Yes, that's what I did expect.

 if you change the path around (in your case, by adding MyPackage to
 the path, rather than relying on path-relative import), you'll
introduce
 multiple ways to import the same module, and the cache won't work
 properly.  and when the cache doesn't work, isinstance breaks down
 for the reason I stated.

Exactly. ForeignPackage.B and MyPackage.ForeignPackage.B are two
paths pointing to the same module but it will be imported twice because
the cache does not lookup a strong name ( e.g. a hash of the module )
but the import path. This may also be the reason why it is not possible
to import a module in an interactive session, than edit it and finally
re-import it into the same running session. The hash value would have
been changed but the path remains the same.


  Flattening the package structure would solve the problem as well as
  destroying all file-system based packages and abandon them from
Python.

 well, packages for just fine for me.

In some cases they do, in other they don't. The __me__.py module comes
from working with ClearCase where the Python package is not installed
by an installation routine relative to an existing Python path. The
package has to recognize it's own position somewhere relative to the
virtual directory which can be arbitrary. Installing the package under
site-packages/ is a no go.

 if you cannot get them to work,
 maybe you should stop doing things that don't work.

For shure, but people tend to do workarounds. So I did.

Regards,
Kay

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


Re: RFC 2822 format date printing function in python

2005-05-06 Thread George Yoshida
praba kar wrote:

 In Php we can print RFC 2822 formatted date by
  date('r') with parameter r.  Then it will print the
  below format date.
  Thu,  7 Apr 2005 01:46:36 -0300.
  I want to print same RFC 2822 format in python. Is it
  possible in python? . If possible kindly mention the
  function related to print RFC format date
 

Not as simple as PHP, but of course it's possible :-)

  from email.Utils import formatdate
  formatdate(localtime=True)
'Fri, 06 May 2005 18:00:20 +0900'

  http://docs.python.org/lib/module-email.Utils.html

If you want to do the same thing with time module, you need a few
more lines to calcualate the timezone.

quote from footnote:

   Note that the sign of the timezone offset is the opposite of the
   sign of the time.timezone variable for the same timezone; the
   latter variable follows the POSIX standard while this module
   follows RFC 2822.


  http://docs.python.org/lib/module-time.html

-- 
george
http://www.dynkin.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python at MS Event!

2005-05-06 Thread Srijit Kumar Bhadra
Was it IronPython 0.7.x or standard Python 2.4.1?

Regards,
/Srijit

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


Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-06 Thread TZOTZIOY
On Fri, 29 Apr 2005 23:38:53 +0300, rumours say that pythonchallenge
[EMAIL PROTECTED] might have written:

For the riddles' lovers among you, you are most invited to take part
in the Python Challenge, the first python programming riddle on the net.

You are invited to take part in it at:
http://www.pythonchallenge.com

This is not only about riddle lovers, but a great way to advocate python
to other programmers...  I already had a session with a friend (he did
the thinking, I did the programming next to him) and he was enchanted :)

I'm already investing a little time to think some new riddles to suggest
(extending stdlib coverage).
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hard memory limits

2005-05-06 Thread Fredrik Lundh
Maurice LING wrote:

 I think I've hit a system limit in python when I try to construct a list
 of 200,000 elements.

there's no such limit in Python.

 My error is

 malloc: vm_allocate (size = 2400256) failed..

 Just wondering is this specific to my system or what?

that doesn't look like a Python error (Python usually raises
MemoryError exceptions when it runs out of memory), and
there's no sign of any vm_allocate function in the Python
sources, so yes, it's a system-specific problem.

 Will adding more RAM helps in this case?

probably.  more swap space might also help.  or you could use a
smarter malloc package.  posting more details on your platform,
toolchain, python version, and list building approach might also
help.

(are you perhaps building multiple lists piece by piece, interleaved
with other object allocations?  if so, it's probably a fragmentation
problem.  to check this, watch the process size.  if if grows at a
regular rate, and then explodes just before you get the above error,
you may need to reconsider the design a bit).

/F



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


Re: RFC 2822 format date printing function in python

2005-05-06 Thread Fredrik Lundh
praba kar wrote:

In Php we can print RFC 2822 formatted date by
 date('r') with parameter r.  Then it will print the
 below format date.
 Thu,  7 Apr 2005 01:46:36 -0300.
 I want to print same RFC 2822 format in python. Is it
 possible in python? . If possible kindly mention the
 function related to print RFC format date

here's what I replied the last time you asked about RFC 2822 dates:

the timestamp format you're using is also known as the RFC(2)822 format.
the email package contains several functions to deal with this format:

 x = 1112962934
 from email.Utils import formatdate
 formatdate(x) # default is utc 'Fri, 08 Apr 2005 12:22:14 -'
 formatdate(x, localtime=1)
'Fri, 08 Apr 2005 14:22:14 +0200'

 from email.Utils import parsedate_tz
 parsedate_tz(formatdate(x, localtime=1))
(2005, 4, 8, 14, 22, 14, 0, 1, 0, 7200)

for the full story, see:

http://docs.python.org/lib/module-email.Utils.html

you may want to save copies of questions you've already asked, and
the replies you got, so you can avoid asking the same questions over
and over again.  (yes, this also applies if you're a bot).

/F



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


Re: Setting the corner color in rotated PIL images

2005-05-06 Thread Anthra Norell
What do you mean 'is required'? I tend to think that getting ahead with a
job is what is required. I don't sneer at work-arounds if they save time.

Frederic

A somewhat craftier solution, if still pretty hackish, would be to go
through your image pixel by pixel, look what color each one is (color =
image.getpixel (here)) and change the ones with the wrong color (if color ==
wrong_color: putpixel (here, right_color)).
  If the color of  the corners does not occur inside your picture, you
can go throught the entire image. Else you'd have to stop changing colors at
the first occurrence of a pixel that does not have the wrong color, coming
inward from each of the lateral edges. (Code below (untested)).
  If you have elements in your picture that not only have the same color
as the corners, but also run into them, then you might have to refine your
code further in order for the inner loop not stray into the image.

# Left edge
for y in range (image.size [1]):
   for x in range (image.size [0]):
  color = image.getpixel ((x,y))
  if color != WRONG_COLOR:
 break
  image.putpixel ((x,y), RIGHT_COLOR)

# Right edge
for y in range (image.size [1]):
   for x in range (image.size [0]-1), -1,  -1):
  color = image.getpixel ((x,y))
  if color != WRONG_COLOR:
 break
  image.putpixel ((x,y), RIGHT_COLOR)


- Original Message -
From: rzed [EMAIL PROTECTED]
Newsgroups: comp.lang.python
To: python-list@python.org
Sent: Tuesday, May 03, 2005 8:13 PM
Subject: Re: Setting the corner color in rotated PIL images


 Anthra Norell [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]:

 [in response to:
  I'm using PIL to generate some images which may be rotated at
  the user's option. When they are rotated, the original image is
  cropped in the new image (which is fine), and the corners are
  black (which is not, in this case). I can't find any documented
  way to change the default fill color (if that's what it is) for
  the corners, and PIL also doesn't seem to support a flood fill.
  I have created a flood fill in Python, which works but which
  markedly slows image generation.]

  I just had the same problem the other day. I solved it by
  starting out with an image large enough to retain enough white
  area following the rotation.

 Well, that's a workaround I could try, but I'm half-hearted about
 it. I don't like to think that it's *required*. Another possible
 solution is to make the outer portion black, so the rotation seems
 to do the right things, but in the cases I'm dealing with, that's
 either out or more trouble than it's worth. I can haul the rotated
 images into a paint program and manually touch up the corners, too,
 but I don't like to have to do that either.

 It seems strange that there wouldn't be some way to change the
 black to another color, or (maybe just as good) to transparent. PIL
 is so useful that it strikes me as an aberrant oversight. More
 likely, there *is* a better way, but I just don't know it and can't
 find it in the docs.

 --
 rzed

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

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


Re: properties vs. eval()

2005-05-06 Thread Steve Holden
Bob Rogers wrote:
 So you're saying you don't know the answer?  The question wasn't
 should I use setattr?
 
No, the *question* was (paraphrasing slightly) is [it] possible to 
dispense with the compile step and use eval() alone while setting a 
property the *answer* was you should use setattr.

If you don't see that this implies that using eval() is not a good idea 
until other resources have been exhausted, then you need to understand: 
using eval() is not a good idea until other resources have been exhausted.

regards
  Steve
-- 
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/

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


Re: win32: structured storage

2005-05-06 Thread Steve Holden
tlviewer wrote:
 hello,
 
 In honor of the chm exploit that I got hit by last week, I trying
 to code some ActivePython to list the directory inside a CHM.
 
Welcome to the world of the drive-by download. Now you know why people 
are recommending migrating away from IE.

  CHM is supposed to be structured storage (ITSF). If a given CHM
  file is infected it most likely has an embedded EXE file -- mine
  had one called [Open.exe].
 
Ironic, really, since Microsoft insist that the browser must be 
fully-integrated with the operating system I suppose that measn we had 
better all start using Linux.

regards
  Steve
-- 
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/

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


Re: New Python regex Doc

2005-05-06 Thread Steve Holden
Fredrik Lundh wrote:
 Xah Lee wrote:
 
 
I have now also started to rewrite the re-syntax page. At first i
thought that page needs not to be rewritten, since its about regex and
not really involved with Python. But after another look, that page is
as incompetent as every other page of Python documentation.

The rewritten page is here:
http://xahlee.org/perl-python/python_re-write/lib/re-syntax.html

It's not complete
 
 
 and it no longer describes how things work.  study the inner workings
 of the RE engine some more, and try again.
 

Though I realise I'm not one to gloat about other people's typos, I did 
find that When the LOCALE and UNICODE flags are apples as usual. 
really appealed to my imagination. And I thought it was all ones and 
zeroes ...

regards
  Steve
-- 
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/

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


Re: win32: structured storage

2005-05-06 Thread Robert Kern
tlviewer wrote:

 Is there another way to parse the central directory out of
 a CHM file?

google(chmlib python)

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die.
   -- Richard Harter

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


Re: Setting the corner color in rotated PIL images

2005-05-06 Thread rzed
[Following up]

 - Original Message -
 From: rzed [EMAIL PROTECTED]
 Newsgroups: comp.lang.python
 To: python-list@python.org
 Sent: Sunday, May 01, 2005 1:17 PM
 Subject: Setting the corner color in rotated PIL images
 
 
 I'm using PIL to generate some images which may be rotated at
 the user's option. When they are rotated, the original image is
 cropped in the new image (which is fine), and the corners are
 black (which is not, in this case). I can't find any documented
 way to change the default fill color (if that's what it is) for
 the corners, and PIL also doesn't seem to support a flood fill.
 I have created a flood fill in Python, which works but which
 markedly slows image generation.


Anthra Norell [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 I just had the same problem the other day. I solved it by
 starting out with an image large enough to retain enough white
 area following the rotation. 
 
 Frederic
 

I found another method that doesn't require the larger size and 
cropping :) but does require two copies of the original image :( 
(sort of).

I copy the image and rotate the copy, then I create an all-white 
image of the same size as the original and rotate it by the same 
amount. Then I use ImageChops composite() to combine the rotated 
copy, the original copy, and the black-and-white version 
(parameters in that order). The black corners of the b/w version 
serve as a mask to paste the original corners onto the copy. 

It still seems like a lot of trouble to go to, but I don't think 
there is a ready solution otherwise. I think there's a C-code 
memset of all zeroes that underlies the black corners thing, and 
that's not likely to change.

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


Re: py2exe + svn - the final drama

2005-05-06 Thread Timothy Smith
Timothy Smith wrote:

ok, i am updating my program from my svn - this works, however, i am 
getting the following error when i close the program. the zip file 
successfully updates, so i'm curious as to the meaning of this.

Traceback (most recent call last):
  File Main.pyo, line 820, in ValidateLogin
  File Main.pyo, line 863, in ShowMainFrameItems
  File glob.pyo, line 22, in glob
  File glob.pyo, line 50, in glob1
  File fnmatch.pyo, line 42, in filter
zipimport.ZipImportError: bad local file header in Z:\temp\library.zip

not that once i have finished client.update(''), it has successfully 
updated the zipfile, i open a dialoge box saying click ok and restart 
program AFTER i click on the above error pops up and my app shuts down 
as intended.

ideas?
  

ok i have done some digging and i cound this

/* Check to make sure the local file header is correct */
fseek(fp, file_offset, 0);
l = PyMarshal_ReadLongFromFile(fp);
if (l != 0x04034B50) {
/* Bad: Local File Header */
PyErr_Format(ZipImportError,
 bad local file header in %s,
 archive);
fclose(fp);


can anyone explain to me about zip file headers and why it would be 
different/incorrect and give me this error?
return NULL;


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


Re: Setting the corner color in rotated PIL images

2005-05-06 Thread Fredrik Lundh
rzed wrote:

 I'm using PIL to generate some images which may be rotated at the
 user's option. When they are rotated, the original image is cropped
 in the new image (which is fine), and the corners are black (which
 is not, in this case). I can't find any documented way to change
 the default fill color (if that's what it is) for the corners, and
 PIL also doesn't seem to support a flood fill. I have created a
 flood fill in Python, which works but which markedly slows image
 generation.

 Can anyone suggest a better way to set the color of the corners?

if you're doing this on RGB images, the quickest way to do this is:

def rotate(image, angle, color):
bg = Image.new(RGB, image.size, color)
im = image.convert(RGBA).rotate(angle)
bg.paste(im, im)
return bg

here's a more general solution:

def rotate(image, angle, color, filter=Image.NEAREST):
if image.mode == P or filter == Image.NEAREST:
matte = Image.new(1, image.size, 1) # mask
else:
matte = Image.new(L, image.size, 255) # true matte
bg = Image.new(image.mode, image.size, color)
bg.paste(
image.rotate(angle, filter),
matte.rotate(angle, filter)
)
return bg

/F 



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


Tkinter App to System Tray

2005-05-06 Thread
I write a program with Python 2.4 + TkinterExecute it, there will be a window show something.If I minimize it, it will be minimized to the taskbar. But I would like it to miniminze to the System Tray, this can make taskbar more clear. Would you please tell me how to modify my program.Thanks a lot !!Soure Code : # Display digits of pi in a window, calculating in a separate thread.# Compare with wpi.py in the Demo/threads/wpi.pyimport sysimport timeimport threadfrom Tkinter import *class ThreadExample:def __init__(self, master=None):self.ok= 1self.digits= []self.digits_calculated = 0self.digits_displayed  = 0self.master= masterthread.start_new_thread(self.worker_thread, ())self.frame = Frame(master, relief=RAISED, borderwidth=2)self.text = Text(self.frame, height=26, width=50)self.scroll = Scrollbar(self.frame, command=self.text.yview)self.text.configure(yscrollcommand=self.scroll.set)self.text.pack(side=LEFT)self.scroll.pack(side=RIGHT, fill=Y)self.frame.pack(padx=4, pady=4)Button(master, text='Close', command=self.shutdown).pack(side=TOP)self.master.after(100, self.check_digits)def worker_thread(self):while self.ok:self.digits.append(`9`)time.sleep(0.001)def shutdown(self):self.ok =0self.master.after(100, self.master.quit)def check_digits(self):self.digits_calculated = len(self.digits)diff = self.digits_calculated - self.digits_displayedix = self.digits_displayedfor i in range(diff):self.text.insert(END, self.digits[ix+i])self.digits_displayed =  self.digits_calculatedself.master.title('%d digits of pi' % self.digits_displayed)self.master.after(100, self.check_digits)root = Tk()root.option_readfile('optionDB')example = ThreadExample(root)root.mainloop()








 3




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

Re: How to detect a double's significant digits

2005-05-06 Thread John Roth
mrstephengross [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hi all... How can I find out the number of significant digits (to the
 right of the decimal place, that is) in a double? At least, I *think*
 that's what I'm asking for. For instance:

 0.103 -- 3
 0.0103 -- 4
 0.00103 -- 5
 0.000103 -- 6
 0.103 -- 7

 Thanks in advance!
 --Steve ([EMAIL PROTECTED])

As a lot of the responders have pointed out, it's effectively
impossible to do so in any meaningful fashion if all you
have is the binary representation of the number.

One way of doing it is the ScientificDouble class in
PyFit (and in all other versions of FIT, for that matter.)
That provides a class that saves the original string
representation so it can be used to determine precision
for compares. It's a niche approach: it works well for
FIT's purposes, but it's not a general purpose method
of estimating precision throughout a lengthy calculation.
That requires quite different techniques.

See:

fit.c2.com
www.fitnesse.org
FitNesse Yahoo mailing list (see the files section for PyFit.)

John Roth
 

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


Re: Python SQLite

2005-05-06 Thread dcrespo
 There are specific python modules for SQLite on Linux.

Which? I thought pysqlite works on Linux.

My important question is: If I develop an app using
Python-wxPython-PySQLite under Windows, and run it on Linux, it should
work, ¿right?

Daniel

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


[HELP] Tkinter Application Minimized to System Tray :)

2005-05-06 Thread
 I write a program with Python 2.4 + Tkinter
   Execute it, there will be a window show something.
   If I minimize it, it will be minimized to the taskbar. But I would like 
it to miniminze to the System Tray, this can make taskbar more clear. Would 
you please tell me how to modify my program.

   Thanks a lot !!
Soure Code : 

# Display digits of pi in a window, calculating in a separate thread.
# Compare with wpi.py in the Demo/threads/wpi.py
import sys
import time
import thread
from Tkinter import *
class ThreadExample:
   def __init__(self, master=None):
   self.ok= 1
   self.digits= []
   self.digits_calculated = 0
   self.digits_displayed  = 0
   self.master= master
   thread.start_new_thread(self.worker_thread, ())
   self.frame = Frame(master, relief=RAISED, borderwidth=2)
   self.text = Text(self.frame, height=26, width=50)
   self.scroll = Scrollbar(self.frame, command=self.text.yview)
   self.text.configure(yscrollcommand=self.scroll.set)
   self.text.pack(side=LEFT)
   self.scroll.pack(side=RIGHT, fill=Y)
   self.frame.pack(padx=4, pady=4)
   Button(master, text='Close', command=self.shutdown).pack(side=TOP)
   self.master.after(100, self.check_digits)
   def worker_thread(self):
   while self.ok:
   self.digits.append(`9`)
   time.sleep(0.001)
   def shutdown(self):
   self.ok =0
   self.master.after(100, self.master.quit)
   def check_digits(self):
   self.digits_calculated = len(self.digits)
   diff = self.digits_calculated - self.digits_displayed
   ix = self.digits_displayed
   for i in range(diff):
   self.text.insert(END, self.digits[ix+i])
   self.digits_displayed =  self.digits_calculated
   self.master.title('%d digits of pi' % self.digits_displayed)
   self.master.after(100, self.check_digits)
root = Tk()
root.option_readfile('optionDB')
example = ThreadExample(root)
root.mainloop()
_
 MSN Explorer:   http://explorer.msn.com/lccn/  

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

Re: Setting the corner color in rotated PIL images

2005-05-06 Thread rzed
Anthra Norell [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 What do you mean 'is required'? I tend to think that getting
 ahead with a job is what is required. I don't sneer at
 work-arounds if they save time. 
 
 Frederic
 
 A somewhat craftier solution, if still pretty hackish, would be
 to go through your image pixel by pixel, look what color each
 one is (color = image.getpixel (here)) and change the ones with
 the wrong color (if color == wrong_color: putpixel (here,
 right_color)). 
   If the color of  the corners does not occur inside your
   picture, you 
 can go throught the entire image. Else you'd have to stop
 changing colors at the first occurrence of a pixel that does not
 have the wrong color, coming inward from each of the lateral
 edges. (Code below (untested)). 
   If you have elements in your picture that not only have
   the same color 
 as the corners, but also run into them, then you might have to
 refine your code further in order for the inner loop not stray
 into the image. 
 

[Code snipped]

Yes, that is essentially similar to the slow flood-fill approach I 
used initially. I did in fact make use of your previous suggestion, 
which works but requires oversizing the image, calculating the crop 
rectangle and so on -- not overly difficult, just annoying -- and I 
also use another approach (outlined in another message) that 
involves pasting a rotated copy of the image back onto the original 
under control of a mask. It depends on what I want to see in the 
corners, essentially. And, having coded the workarounds, I get on 
with the process without worrying about it.

But ... it would be nice if I could specify a default solid color 
to replace the black in the corners, and have the rotation take 
place in one operation without resizing and recalculating and 
duplicating images and all. 

Somewhere down in the C code, the corner color is being set to 
black. I wouldn't think it would be terribly hard at that stage to 
set those bytes to other values instead, and exposing that color 
through PIL's interface. But I suppose it's more trouble than it's 
worth for Fredrik, or nobody else has been bothered by it, or by 
the lack of a flood-fill function. To me, these are 
uncharacteristically odd omissions from PIL.

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


Re: hard memory limits

2005-05-06 Thread Mike Meyer
Fredrik Lundh [EMAIL PROTECTED] writes:

 Maurice LING wrote:
 Will adding more RAM helps in this case?

 probably.  more swap space might also help.  or you could use a
 smarter malloc package.  posting more details on your platform,
 toolchain, python version, and list building approach might also
 help.

Without platform information, it's hard to say. On a modern Unix
system, you only run into system resource limits when the system is
heavily loaded. Otherwise, you're going to hit per-process limits. In
the latter case, adding RAM or swap won't help at all. Raising the
per-process limits is the solution.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ERP CRM in Python

2005-05-06 Thread Wolfgang Keller
Hello,

and thanks for your reply.

 We are writing a script to render a PDF from our doc. (using
 openreport.org)

Good to read.

  Why not mailing lists instead of online-forums.
 There is some mailing lists;
 http://tinyerp.org/lists.php
 ... but nobody uses it.
 
  The former was made for efficient human-to-human communication, the
  latter not.
 I agree.

Then why not create a gateway (-) for the forums into mailinglists
1:1?

Best regards

Wolfgang Keller

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


Re: hard memory limits

2005-05-06 Thread Bill Mill
On 5/6/05, Mike Meyer [EMAIL PROTECTED] wrote:
 Fredrik Lundh [EMAIL PROTECTED] writes:
 
  Maurice LING wrote:
  Will adding more RAM helps in this case?
 
  probably.  more swap space might also help.  or you could use a
  smarter malloc package.  posting more details on your platform,
  toolchain, python version, and list building approach might also
  help.
 
 Without platform information, it's hard to say. On a modern Unix
 system, you only run into system resource limits when the system is
 heavily loaded. Otherwise, you're going to hit per-process limits. In
 the latter case, adding RAM or swap won't help at all. Raising the
 per-process limits is the solution.
 

A quick google shows it to be mac os X, and a pretty frequent error message.

http://www.google.com/search?hl=enq=%22vm_allocate%20(size%20%3D%22btnG=Google+Search

Peace
Bill Mill
bill.mill at gmail.com

 mike
 --
 Mike Meyer [EMAIL PROTECTED]  
 http://www.mired.org/home/mwm/
 Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Python SQLite

2005-05-06 Thread Gerhard Häring
dcrespo wrote:
There are specific python modules for SQLite on Linux.
 
 Which? I thought pysqlite works on Linux.

Sure. What he probably meant was that there are binary installers for 
pysqlite from various Linux distributions (Debian, Gentoo, ...).

 My important question is: If I develop an app using
 Python-wxPython-PySQLite under Windows, and run it on Linux, it should
 work, ¿right?

Correct for Python and pysqlite. For wxPython you will often have to do 
fine-tuning because some bugs are only present on Windows, and some bugs 
are only present on *nix. And things sometimes look slightly different.

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


Re: Encryption with Python?

2005-05-06 Thread Ivan Voras
Blake T. Garretson wrote:
 I want to save some sensitive data (passwords, PIN numbers, etc.) to
 disk in a secure manner in one of my programs.  What is the
 easiest/best way to accomplish strong file encryption in Python?  Any
 modern block cipher will do: AES, Blowfish, etc.  I'm not looking for
 public key stuff; I just want to provide a pass-phrase.

There's a pure python Blowish implementation at:
http://bofh.concordia.ca/blowfish.py

(It looks like you'll have to divide your data in 8 byte blocks 
yourself, and pad the last block)
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting number of iteration

2005-05-06 Thread Florian Lindner
Hello,
when I'm iterating through a list with:

for x in list:

how can I get the number of the current iteration?

Thx,

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


Re: Getting number of iteration

2005-05-06 Thread Bill Mill
On 5/6/05, Florian Lindner [EMAIL PROTECTED] wrote:
 Hello,
 when I'm iterating through a list with:
 
 for x in list:
 
 how can I get the number of the current iteration?

Python 2.4 and greater:

for n, x in enumerate(lst):
print iteration %d on element %s % (n, x)

Earlier:

n = 0
for x in lst:
print iteration %d on element %s % (n, x)
n += 1

And you shouldn't use list as a variable name; list() is a built-in
function which you'll clobber if you do.

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting number of iteration

2005-05-06 Thread Bill Mill
On 5/6/05, Bill Mill [EMAIL PROTECTED] wrote:
 On 5/6/05, Florian Lindner [EMAIL PROTECTED] wrote:
  Hello,
  when I'm iterating through a list with:
 
  for x in list:
 
  how can I get the number of the current iteration?
 
 Python 2.4 and greater:

ummm, make that 2.3 and greater. I always think things are more recent
than they are.

 
 for n, x in enumerate(lst):
 print iteration %d on element %s % (n, x)
 
 Earlier:
 
 n = 0
 for x in lst:
 print iteration %d on element %s % (n, x)
 n += 1
 
 And you shouldn't use list as a variable name; list() is a built-in
 function which you'll clobber if you do.
 
 Peace
 Bill Mill
 bill.mill at gmail.com

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


Re: Getting number of iteration

2005-05-06 Thread George Sakkis
Florian Lindner wrote:

 Hello,
 when I'm iterating through a list with:

 for x in list:

 how can I get the number of the current iteration?

 Thx,

 Florianfor

in python 2.3+:

for i,x in enumerate(sequence):
print sequence[%d] = %s %(i,x)


George

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


Re: annonymous functions -- how to

2005-05-06 Thread Scott David Daniels
Fredrik Lundh wrote:
 
 so name them all func or next or something, so you don't have
 to think.  once the object is bound, the name is irrlevant.
 
Or, you could tell him about the reserved word anonymous which can be
used to created unnamed functions of values. A sample definition and
use of the anonymous keyword follows:

 def anonymous(text):
 return 'modified ' + text

 print 'Sample', anonymous('words')

--Scott David Daniels (with his tongue jammed firmly in his cheek)
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to convert a list into function call arguments?

2005-05-06 Thread bruno modulix
[EMAIL PROTECTED] wrote:
 I'm a newcomer to python - what is the best way to convert a list into
 a function call agruments?

Jeff Epler already answered to the question. Now a couple of advices:

 For example:
 
 list = (2005, 5, 5)

1/ this is not a list, it's a tuple. A list would be [2005, 5, 5]. (BTW, 
it's quite ok - and even better imho - to use a tuple here)

2/ using the word 'list' as identifier shadows the builtin function 
'list'. This is allowed, but you may prefer to avoid doing so.

3/ also, using the word 'list' as an identifier here is a poor choice 
from a semantic POV, since it convey useless (and in this case wrong) 
informations about an implementation detail (the data structure type) 
but says nothing about the intended use of the data. Something like 
'the_date' would have been better IMHO.

My 2 cents
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for 
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: min max of a list

2005-05-06 Thread querypk
Hi Steve!
I am not sure if I was clear with my previous post .Ok let me rephrase
it .

Assume the values list is the
content of a histogram. Then we see that
values = [  0,  72,   2,   4,   9,   2,   0,   0,  42,  26,   0, 282,
23,   0, 101, 0,   0,   0,   0,   0]

 1 is repeated 72 times, 3 - 4 times and so on. That is the index
would be the value repeated as many times as in the list.
Now If we find the max and look for the adjcent index.

That is if we plot the above list as a histogram. We will have crests
and troughs ie peaks and dips. if we find two dips then the region
between the two dips could be a range like [0,  72,   2] .So here we
are not looking for a zero. But if we find dips then we consider the
regions between it as a bin and group it.

|   /\
|  /\  /  \  /\
| /  \/\/  \
|/_
 ||-|---|
123

so pictorially. In the above plot. If y axis is the list above. then we
need to bin it this way.
If I use you previous approach using the groupby then all these three
regions will be considered as one.

Hope I am clear this time.

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


Re: How to detect a double's significant digits

2005-05-06 Thread Jeremy Bowers
On Fri, 06 May 2005 08:27:03 +0200, Fredrik Lundh wrote:

 Jeremy Bowers wrote:
 
  A step which will require him to tell the printing routine how many
  digits he wants printed.

 Not necessarily; consider the str() of a float in Python, especially
 given the significant digits aspect (it may be ill-defined, but I can
 think of several well-defined ways to mean that, where str() embodies
 one of them). The easiest way to tell how long the number will be when
 str prints it out is to simply ask it.
 
 and what language is str() implemented in?

Who cares? It demonstrates the existence of a print routine that prints a
variable number of characters.

 In C++, this may be harder, as your output software may insist on
 rendering everything directly, with no way to reach in and tell what it
 did. Imagine the standard IOStreams, without the ability to stream into
 a string.
 
 but you can stream into a string buffer, and you can use sprintf() from
 C++, so what's your point, besides stating that if things were harder,
 they would be harder?

Giving the original poster the benefit of the doubt, I assumed he was
dealing with some sort of screen library that would render something
without telling him the size, that didn't use streams at all. If that
library also implemented its own pretty print, string streams and
everything else don't help; you need *that* library's pretty print.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a cx_Oracle ORA-01036 problem

2005-05-06 Thread Miles
Damjan wrote:
 I'm using Python 2.4, cx_Oracle-4.1 on Linux with Oracle instant client
 10.1.0.3. This is the sql string:
 
 SQL = insert into D.D_NOTIFY values (:CARDREF, :BANKKEY, :OK1, :OK2 \
 :DEBTEUR, :DEBTDEN, to_date(:INVOICE_DATE,'DD.MM.YY'),
 to_date(:PAYMENT_DEADLINE,'DD.MM.YY'), :POINTS)
 
 And I'm trying to execute it as:
 c = db.cursor()
 c.execute(SQL, CARDREF=id, BANKKEY=dc_kluc, OK1=okd, OK2=okc, 
   
   DEBTEUR=iznos_eur, DEBTDEN=iznos_mkd, INVOICE_DATE=datum_g, 
   
   PAYMENT_DEADLINE=datum_d, POINTS=bodovi)
 
 And I get an ORA-01036 exception.

Try using a variable name other than id for the CARDREF variable... say
card_id.  id is a built in function name; I suspect your problem may be
that you are assiging that function to the variable rather than your intended
value...


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


Re: annonymous functions -- how to

2005-05-06 Thread Dave Benjamin
Fredrik Lundh wrote:
 Dave Benjamin wrote:
 
In this case, having to name these callback functions is tiring and
awkward, and (IMHO) disrupts the flow of my function:
 
 so name them all func or next or something, so you don't have
 to think.  once the object is bound, the name is irrlevant.

Sure, you could do this, but then you'd have multiple functions at 
different nesting levels with the same name, which would be confusing. 
You could call them func1, func2, func3, and so on, but at this 
point it becomes painfully obvious that you really don't care what the 
names are; you're only naming them because you have to. As Paul Graham 
would say, it's the human compiler at work.

 there's also:
 
 def add_thingy(self):

What object is self? Are we defining a method at this point?

 yield get_new_thingy_id; thingy_id = self.result

What is get_new_thingy_id? A function? To whom are we yielding here?

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


Re: Python at MS Event!

2005-05-06 Thread James
Standard. 2.4.x

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


Re: annonymous functions -- how to

2005-05-06 Thread Fredrik Lundh
Dave Benjamin wrote:

  so name them all func or next or something, so you don't have
  to think.  once the object is bound, the name is irrlevant.

 Sure, you could do this, but then you'd have multiple functions at
 different nesting levels with the same name, which would be confusing.

I don't wanna try that, you mean.

because if you had done so, you would have noticed that multiple
functions with the same name doesn't have to be any more confusing
than multiple print statements or multiple if statements (as long as
you're not using bad names on purpose, of course).

  there's also:
 
  def add_thingy(self):

 What object is self? Are we defining a method at this point?

if you have a problem with methods, you shouldn't use Python.


  yield get_new_thingy_id; thingy_id = self.result

 What is get_new_thingy_id? A function? To whom are we yielding here?

I could have sworn that you mentioned event-driven programming
in your original post.  if that's still what you're doing, the answers
are a token and the event source.

/F



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


Re: Weird UserArray AttributeError (bug ?)

2005-05-06 Thread George Sakkis
To answer my own question, the error is caused by the __setattr__
defined in UserArray:
def __setattr__(self,attr,value):
if attr=='shape':
self.array.shape=value
self.__dict__[attr]=value


I'm not sure though how to undefine __setattr__ in a subclass so that
property lookup works correctly. The furthest I got was to remove
__setattr__ from UserArray, but this is obviously unsafe if UserArray
is going to be used alone:

delattr(UserArray,'__setattr__')

class Vector(UserArray,object):
def __init__(self,x,y):
UserArray.__init__(self, (x,y))

shape = property(lambda self: self.array.shape,
 lambda self,v: setattr(self.array,'shape',v))

magnitude = property(lambda self: hypot(*self),
# setting scales the vector
lambda self,magnitude: self.__imul__(magnitude/self.magnitude))


Any alternatives to get the same effect without deleting an attribute
of the superclass ?

George

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


SC-Corporate-ID released

2005-05-06 Thread Philippe C. Martin
Dear all,

I am very pleased to announce the release of SC-Corporate-ID.

SC-Corporate-ID is a commercial Smart Card security system that can be
extended by the user using the Python language.

SC-Corporate-ID is written in Python and wxPython for the most part (except
for the PCSC wrapper, the GINA dll and the crypto) on the PC side, and
in  other languages on the Smart Card side. The PCSC driver (PYCSC) and
the crypto (PYCRYPTO) are public domain packages (PYCSC was slightly
modified by us)

SC-Corporate-ID is an off-the shelf package: you can use it as is; yet, as
it is based on a set of libraries (SCF), it can be modified and customized
by the company using it (the restriction being the capabilities of the code
in the Smart Card which would have to be modified by us).

SC-Corporate-ID can be used for PC Access, Data Security (file
encryption/signature), Company Electronic Purse and Corporate
Identification. Some of its possible extentions are Building Access and WEB
Security.

SC-Corporate-ID cards can be delivered pre-programmed (firwmare + data) or
simply with the firmware so the user may handle its own cards issuance.

Although it is a commercial product, SC-Corporate-ID intends to be a true
low cost security solution for Corporations.

SC-Corporate-ID will soon be followed by a School/University ID as well as
an Health Card ID.

You may find information on SC-Corporate-ID at www.snakecard.com.


Best regards,


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


Re: hard memory limits

2005-05-06 Thread Fredrik Lundh
Mike Meyer wrote:

 Without platform information, it's hard to say. On a modern Unix
 system, you only run into system resource limits when the system is
 heavily loaded. Otherwise, you're going to hit per-process limits. In
 the latter case, adding RAM or swap won't help at all. Raising the
 per-process limits is the solution.

does Mac OS X ship with memory limits set by default?  isn't that
a single-user system?

/F



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


Re: annonymous functions -- how to

2005-05-06 Thread Dave Benjamin
Fredrik Lundh wrote:
 Dave Benjamin wrote:
 
so name them all func or next or something, so you don't have
to think.  once the object is bound, the name is irrlevant.

Sure, you could do this, but then you'd have multiple functions at
different nesting levels with the same name, which would be confusing.
 
 I don't wanna try that, you mean.

No, I mean, I have an imagination. But for the sake of argument, here, 
I'll try that:

def add_thingy():
 def func(thingy_id):
 print 'got thingy id:', thingy_id
 def funnc(doodad_id):
 print 'got doodad id:', doodad_id
 def func(thingy_doodad):
 print 'thingy doodad created, froobling...'
 frooble(thingy_doodad)
 print 'froobling complete'
 with_new_thingy_doodad(thingy_id, doodad_id, func)
 with_next_doodad_id(func)
 with_next_thingy_id(func)

This function now has an infinite loop. Can you spot the reason?

 because if you had done so, you would have noticed that multiple
 functions with the same name doesn't have to be any more confusing
 than multiple print statements or multiple if statements (as long as
 you're not using bad names on purpose, of course).

I have noticed. It is more confusing. That's the whole point.

there's also:

def add_thingy(self):

What object is self? Are we defining a method at this point?
 
 if you have a problem with methods, you shouldn't use Python.

No, I was asking you to clarify, are we rewriting add_thingy to be a 
method, and if so, what class is it a method of, and what are its 
responsibilities? Because it seems like this example now shares data 
through an instance, but this data is not required for any other method, 
so it will add clutter to the instance namespace. If anything, it seems 
that add_thingy should be moved into another class at this point, in 
which case it follows that every method that needs to do this sort of 
asynchronous communication would likewise be moved to a new class. This 
is fine, I suppose, but it's a lot more verbose.

yield get_new_thingy_id; thingy_id = self.result

What is get_new_thingy_id? A function? To whom are we yielding here?
 
 I could have sworn that you mentioned event-driven programming
 in your original post.  if that's still what you're doing, the answers
 are a token and the event source.

I am just trying to make sense of your example. I am still talking about 
event-programming. Here are the events:

1. Program A sends program B a message, saying, I need a thingy ID.
2. B sends A a message, Here's a thingy ID: 42.
3. A sends B a message, I need a doodad ID.
4. B sends A a message, Here's a doodad ID: 43.
5. A sends B a message, Make a thingy doodad with IDs 42 and 43.
6. B sends A a message, Thingy doodad created.
7. A sends B a message, Now, frooble the thingy doodad.

I don't know what parts of this transcript you would consider tokens. 
And I'm also not sure how generators can provide an alternative solution 
to this problem. I am genuinely interested.

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


Re: hard memory limits

2005-05-06 Thread James Stroud
On Friday 06 May 2005 10:29 am, Fredrik Lundh wrote:
 Mike Meyer wrote:
  Without platform information, it's hard to say. On a modern Unix
  system, you only run into system resource limits when the system is
  heavily loaded. Otherwise, you're going to hit per-process limits. In
  the latter case, adding RAM or swap won't help at all. Raising the
  per-process limits is the solution.

 does Mac OS X ship with memory limits set by default?  isn't that
 a single-user system?

 /F

Dear original poster or whoever is interested in OS X:

OS X is not a single user system. It is BSD based unix. And its [EMAIL 
PROTECTED] 
sweet! (Though I'm using only Linux right now :o/

If configurable memory limits are a problem and if running python from the 
shell, do:

% unlimit

You can also change this in your .cshrc, .tcshrc, .bashrc, .k[whatever for 
korn], etc. if you run a custom shell.

Your shell settings for each user are in NetInfo Manager.

If you are completely clueless as to what the hell I'm talking about, then 
stop and try this:

1. start a Terminal
2. type this at the prompt:

% echo unlimit  .bashrc

3. Quit that terminal.
4. Start a new terminal.
5. Start python and make your list.

Hope it works.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


inheritance with new-style classes - help

2005-05-06 Thread Greg Copeland
Okay, I have:
class Base( object ):
def __init__( self ):
self._attrib = base
print Base


def real( self ):
print Base.real() is calling base.virtual()
self.virtual()


def virtual( self ):
print Base virtual()
pass



class Mother( Base ):
def __init__( self ):
print Mother
super( Mother, self ).__init__()


def virtual( self ):
print self._attrib
print virtual = Mother


class Father( Base ):
def __init__( self ):
print Father
super( Father, self ).__init__()

def virtual( self ):
print self._attrib
print virtual = Father



class Child( Mother, Father ):
def __init( self ):
print Child
super( Child, self ).__init__()

self._childAttrib = child


def virtual( self ):
print base attribute =  + self._attrib
print virtual = Child
print childAttrib =  + self._childAttrib



rename = Child


 x = rename()
Mother
Father
Base
 x.virtual()
base attribute = base
virtual = Child
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/tmp/python-8zAJdg.py, line 51, in virtual
AttributeError: 'Child' object has no attribute '_childAttrib'

Hmmm...interestingbut okay...let's look some more...

 x.__dict__
{'_attrib': 'base'}

What??!  Where the heck did self._childAttrib go?  And why?

Can someone please shine some light here?  Please?


Thanks in advance,

Greg

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


Re: min max of a list

2005-05-06 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
 If this is the list.
 
 values = [  0,  72,   0,   4,   9,   2,   0,   0,  42,  26,   0, 282,
 23,   0, 101, 0,   0,   0,   0,   0]
 
 as we can see there are peaks in the list.that is 0,72,0 is a
 group(triangle) with peak 72.then 0,   4,   9,   2,   0,   0 with peak
 9 and 0,  42,  26,   0 with 42 and so on...
 what I want is the left and right bound index of each bin(triangle).The
 list could as big as possible.So some heurestic algorithm which could
 first find max in the list and look for local maxima and minima and
 group its adjcent bounds.Then find next max and group the bins and so
 on.
 
 so that we can get
 
 [[0,2],[2,7],[7,10],[10,13]]
 ( indexes of the bounds in the values list). so first group [0,2]
 correspond to 0,72,0 in the values list and so on...
 Hope I am clear.

ISTM you just have to look for the valleys - places where the values change 
from descending to 
ascending. Here is a simple-minded way to do it:

def findPeaks(values):
 groups = []
 startIx = 0
 lastValue = values[0]
 ascending = True

 for i, value in enumerate(values[1:]):
 if value = lastValue:
 ascending = False
 else:
 if not ascending:
 # Switch from descending to ascending
 groups.append( [startIx, i] )
 startIx = i
 ascending = True

 lastValue = value

 # Get the last group if any
 if i  startIx:
 groups.append( [startIx, i] )

 return groups


values = [  0,  72,   2,   4,   9,   2,   0,   0,  42,  26,   0, 282,
23,   0, 101, 0,   0,   0,   0,   0]

print findPeaks(values)

## prints:
[[0, 2], [2, 7], [7, 10], [10, 13], [13, 18]]

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


Re: inheritance with new-style classes - help

2005-05-06 Thread Greg Copeland
BTW, this is on Python 2.3.4.

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


Re: Tons of stats/opens to non-existing files increases Python's startupon loaded NFS servers

2005-05-06 Thread Dieter Maurer
Fredrik Lundh [EMAIL PROTECTED] writes on Fri, 6 May 2005 00:08:36 +0200:
  ... lots of no such file or directory ...
  Whoa!! After looking at what is being stat'd or
  open'd, it looks like 'encodings' is new in 2.4 and,
  even worse, everything is looked for as a zip first.
 
 so why not build that ZIP?

We, too, saw this problem -- and we had the *.zip files already...

Python is a bit stupid in its import logic.
When, e.g., a package P defined in a zip archive zzz.zip
contains an import os, then Python checks whether
zzz.zip contains P.os (that is okay). *But*, usually
zzz.zip does not define P.os (as os is a builtin module)
and then Python checks in the file system
for zzz.zip/P/os{,.py,pyc,.so,} and zzz.zip/P/osmodule.so.
Of course, all of them fail as zzz.zip is a Zip archive
and zzz.zip/something is not meaningfull as a file system reference.

I improved on this by patching Python's import.c with the
attached patch. The patch implements that a path_hook
declaring itself to be responsible for a path is authoritative
for both negative as well as positive find_module responses.
Earlier, a negative find_module response caused Python to
try the default module lookup.


Furthermore, it is vital that your sys.path is as small as possible
because a single module lookup can cause file system lookups
in the order of 4 times the number of path elements. 

The standard extension of sys.path often contains far more
path elements than necessary (if you defined python24.zip, you
should remove all other python library directories that do not contain
shared objects).

Dieter

--- Python/import.c~	2004-10-07 08:46:25.0 +0200
+++ Python/import.c	2005-05-04 12:52:19.0 +0200
@@ -1211,6 +1211,9 @@
 return NULL;
 			/* Note: importer is a borrowed reference */
 			if (importer != Py_None) {
+			  	/* DM 2005-05-04: ATT: memory leak!
+   almost surely, we need
+   a Py_XDECREF(copy) */
 PyObject *loader;
 loader = PyObject_CallMethod(importer,
 			 find_module,
@@ -1223,7 +1226,12 @@
 	return importhookdescr;
 }
 Py_DECREF(loader);
-			}
+/* DM 2005-05-04: do not try the builtin import
+   when the responsible importer failed.
+   At least, for zipimport, trying builtin
+   import would be stupid. */
+continue;
+		}
 			/* no hook was successful, use builtin import */
 		}
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: hard memory limits

2005-05-06 Thread Fredrik Lundh
James Stroud wrote:

  does Mac OS X ship with memory limits set by default?  isn't that
  a single-user system?

 Dear original poster or whoever is interested in OS X:

 OS X is not a single user system. It is BSD based unix. And its [EMAIL 
 PROTECTED]
 sweet! (Though I'm using only Linux right now :o/

Well, Apple's marketing materials contain no signs whatsoever that the
systems Apple sells are designed for massive numbers of users, compared
to systems from RedHat, Sun, HP, etc.  (if you look at apple.com in this
very moment, it talks a lot about your mac and your desktop and your
computer, not the mac/desktop/computer you share with hundreds of
other users).

So why would Apple insist on setting unusably low process limits, when
the others don't?

/F



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


Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? GOOGLE·NEWSGROUP·POST·156

2005-05-06 Thread Please
Abuse reports to
[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL 
PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: inheritance with new-style classes - help

2005-05-06 Thread Terry Reedy

Greg Copeland [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Okay, I have:
[snip]
self._childAttrib = child
...
 AttributeError: 'Child' object has no attribute '_childAttrib'
 x.__dict__
 {'_attrib': 'base'}

 What??!  Where the heck did self._childAttrib go?  And why?

I don't immediately see the problem.  Failing that, I would rerun with
print 'setting '_childAttrib' # and
print self._childAttrib
bracketing the line where it should be set, and go one from there.

Terry J. Reedy




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


Re: min max of a list

2005-05-06 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
 Hi Steve!
 I am not sure if I was clear with my previous post .Ok let me rephrase
 it .
 
 Assume the values list is the
 content of a histogram. Then we see that
 values = [  0,  72,   2,   4,   9,   2,   0,   0,  42,  26,   0, 282,
 23,   0, 101, 0,   0,   0,   0,   0]
 
  1 is repeated 72 times, 3 - 4 times and so on. That is the index
 would be the value repeated as many times as in the list.
 Now If we find the max and look for the adjcent index.
 
 That is if we plot the above list as a histogram. We will have crests
 and troughs ie peaks and dips. if we find two dips then the region
 between the two dips could be a range like [0,  72,   2] .So here we
 are not looking for a zero. But if we find dips then we consider the
 regions between it as a bin and group it.
 
 |   /\
 |  /\  /  \  /\
 | /  \/\/  \
 |/_
  ||-|---|
 123
 
 so pictorially. In the above plot. If y axis is the list above. then we
 need to bin it this way.
 If I use you previous approach using the groupby then all these three
 regions will be considered as one.
 
 Hope I am clear this time.

So you want the peaks and valleys basically.  Well, using itools.window 
from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/299529, you 
could do something like:

py values = [0,72,2,4,9,2,0,0,42,26,0,282,23,0,101,0,0,0,0,0]
py peaks = [i
...  for i, (v1, v2, v3) in enumerate(itools.window(values))
...  if v1  v2 and v2  v3]
py peaks
[1, 4, 8, 11, 14]
py valleys = [i
...for i, (v1, v2, v3) in enumerate(itools.window(values))
...if v1 = v2 and v2 = v3]
py valleys
[2, 6, 7, 10, 13, 15, 16, 17, 18]
py [(min((abs(p - v), v) for v in valleys + [0] if v  p)[1],
...   p,
...   min((abs(p - v), v) for v in valleys if v  p)[1])
...  for p in peaks]
[(0, 1, 2), (2, 4, 6), (7, 8, 10), (10, 11, 13), (13, 14, 15)]

This is not likely the most efficient approach, but it's pretty simple:
  * identify the peaks and valleys
  * identify the valley on each side of a peak

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


Re: hard memory limits

2005-05-06 Thread James Stroud
On Friday 06 May 2005 11:27 am, Fredrik Lundh wrote:
 James Stroud wrote:
   does Mac OS X ship with memory limits set by default?  isn't that
   a single-user system?
 
  Dear original poster or whoever is interested in OS X:
 
  OS X is not a single user system. It is BSD based unix. And its [EMAIL 
  PROTECTED]
  sweet! (Though I'm using only Linux right now :o/

 Well, Apple's marketing materials contain no signs whatsoever that the
 systems Apple sells are designed for massive numbers of users, compared
 to systems from RedHat, Sun, HP, etc.  (if you look at apple.com in this
 very moment, it talks a lot about your mac and your desktop and your
 computer, not the mac/desktop/computer you share with hundreds of
 other users).

 So why would Apple insist on setting unusably low process limits, when
 the others don't?

 /F

I think that two different markets exist for this computer:

1. Joe user who has never seen a command line interface. These people need a 
nice, cozy little user environment that takes as little understanding as 
possible to use. They also buy the most computers and are probably most 
responsive to fluffy advertising campaigns. Hence the targeted advertising on 
apple.com In this case, my guess is that memory allocation, etc, is left to 
the application. For cocoa apps it is the objective c runtime handling this 
kind of thing and for carbon apps, it is probobably tacked on during the 
process of carbonizing. But I should say that I really don't know much about 
the low level workings of either.

2. Scientists/Engineers/Programmer types. These people configure their own 
limits instinctively and probably forgot that they ever put that unlimit in 
their rc files (like I did) and the dozens of other customizations they did 
to get their OS X boxes just so for unix use. When Joe User makes the 
crossover, such customizations don't seem very intuitive. Plus, I remember 
having to ulimit my IRIX account on SGIs I used back in the day--so other 
*nixes seem to have similar requirements.

To answer your question, my guess is that no one has complained yet.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: min max of a list

2005-05-06 Thread querypk
Hi Kent,
Thanks for that. But We are considering [..., 0, 101, 0, 0, 0, 0, 0] -
[13,18] .In fact if you look at the list, the histogram ends at 15 that
is [0,101,0] -- [13,15]. Dont you think so.

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


Running python cgi scripts that require external cvs under apache

2005-05-06 Thread chris . levis
All:

I have written a Python webapp under MS IIS 5.0 that does the
following:
-Does a CVS checkout of a particular bit of xml
-Gets a list of valid cvs tags for that xml file
-Based on user input via forms, modifies that xml
-CVS checkin's that file

To have correct permissions to run the cvs binaries and to write
out the xml to be modified into a temp dir, I ended up having to
have the app run as a valid user account on this Windows box
that was hosting the app (it's just my workstation, with IIS
running).  I.e., instead of IUSR_/IWAM_compname, it is running
as domain\someone.  This solution worked well enough for me
to develop the cvs transactions, the html, etc.

However, it has been requested that I move this app onto one of
the IS Dept's servers.  They insist that I put it on a solaris
box, which is running Apache.  I have no administrative control
over this box, and I know very little about it, besides the fact
that test scripts (e.g., /cgi-bin/test.py ) work as expected.

However, I'm have a not-unexpected problem with permissions.  When
folks use this page to modify the XML, it fails because:
1. the effective-user-id of the connecting person
   has insufficient rights to run the cvs binaries
   on the box
2. can't run cvs, so checkouts/rlogs/commits don't happen

I have heard of cgiwrap (http://cgiwrap.unixtools.com), and I'm
going to take a look at that.  I was hoping that others have a
similar experience - with a happy ending - that they can share.

Any help is greatly appreciated.

-cjl

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


Re: min max of a list

2005-05-06 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
 Hi Kent,
 Thanks for that. But We are considering [..., 0, 101, 0, 0, 0, 0, 0] -
 [13,18] .In fact if you look at the list, the histogram ends at 15 that
 is [0,101,0] -- [13,15]. Dont you think so.
 

Well you consider ..., 0,   4,   9,   2,   0,   0, ... as an interval [2, 7] in 
your example. How is 
that different from ..., 0, 101, 0, 0, 0, 0, 0 ?

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


Re: min max of a list

2005-05-06 Thread querypk
I get a syntax error in  :

 py [(min((abs(p - v), v) for v in valleys + [0] if v  p)[1],
...   p,
...   min((abs(p - v), v) for v in valleys if v  p)[1])
...  for p in peaks]

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


Re: win32: structured storage

2005-05-06 Thread Dave Benjamin
Steve Holden wrote:
 tlviewer wrote:
 
   CHM is supposed to be structured storage (ITSF). If a given CHM
   file is infected it most likely has an embedded EXE file -- mine
   had one called [Open.exe].
  
 Ironic, really, since Microsoft insist that the browser must be 
 fully-integrated with the operating system I suppose that measn we had 
 better all start using Linux.

Even more ironically, it would seem that in effort to kill Netscape they 
are killing Windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Python regex Doc (was: Python documentation moronicities)

2005-05-06 Thread Jeff Epler
To add to what others have said:

* Typos and lack of spell-checking, such as occurances vs occurrences

* Poor grammar, such as Other characters that has special meaning
  includes:

* You dropped version-related notes like New in version 2.4

* You seem to love the use of HRs, while docs.python.org uses them
  sparingly

* The category names you created, Wildcards, Repetition Qualifiers,
  and so forth, don't help me understand regular expressions any better
  than the original document

* Your document dropped some basic explanations of how regular
  expressions work, without a replacement text:
Regular expressions can be concatenated to form new regular
expressions; if A and B are both regular expressions, then AB is
also a regular expression. In general, if a string p matches A and
another string q matches B, the string pq will match AB. [...] Thus,
complex expressions can easily be constructed from simpler primitive
expressions like the ones described here.
  Instead, you start off with one unclear example (a+ matching
  hh!) and one misleading example (a regular expression that
  matches some tiny subset of valid e-mail addresses)

* You write
Characters that have special meanings in regex do not have special
meanings when used inside []. For example, '[b+]' does not mean one
or more b; It just matches 'b' or '+'.
  and then go on to explain that backslash still has special meaning; I
  see that the original documentation has a similar problem, but this
  just goes to show that you aren't improving the accuracy or clarity of
  the documentation in most cases, just rewriting it to suit your own
  style.  Or maybe just as an excuse to write offensive things like [a]
  fucking toy whose max use is as a simplest calculator

I can't see anything to make me recommend this documentation over the
existing documentation.

Jeff


pgp5Y4v6p63xE.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: min max of a list

2005-05-06 Thread querypk
oh yes its the same case. even  [0,4,9,2,0] as a set  [2,6] and may be
not [2,7]. Its not that you are wrong its jus that I was not clear.
Sorry about that.

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


Re: [HELP] Tkinter Application Minimized to System Tray :)

2005-05-06 Thread Jeff Epler
Tk, the library that Tkinter wraps, does not offer a way to minimize to
the taskbar.

Jeff


pgp3ATXnxg0dO.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Getting number of iteration

2005-05-06 Thread Mike Meyer
Bill Mill [EMAIL PROTECTED] writes:

 On 5/6/05, Florian Lindner [EMAIL PROTECTED] wrote:
 Hello,
 when I'm iterating through a list with:
 
 for x in list:
 
 how can I get the number of the current iteration?
 Earlier:

 n = 0
 for x in lst:
 print iteration %d on element %s % (n, x)
 n += 1

Just for the record, the old idiom was:

for n in xrange(len(lst)):
x = lst[n]
print iteration %d on element %s % (n, x)

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: annonymous functions -- how to

2005-05-06 Thread Peter Hansen
Dave Benjamin wrote:
 def add_thingy():
 def func(thingy_id):
 print 'got thingy id:', thingy_id
 def funnc(doodad_id):
 print 'got doodad id:', doodad_id
 def func(thingy_doodad):
 print 'thingy doodad created, froobling...'
 frooble(thingy_doodad)
 print 'froobling complete'
 with_new_thingy_doodad(thingy_id, doodad_id, func)
 with_next_doodad_id(func)
 with_next_thingy_id(func)
 
 This function now has an infinite loop. Can you spot the reason?

Not offhand, and to be completely honest, the original with the longer 
names was equally unreadable.  I doubt this is the best way to do 
whatever the heck it is that this is supposed to do.

Oh, and while I was typing my eyes fell on funnc misspelled above. 
Presumably that's your loop...

Spelling func as _ would tend to avoid this as well, unless you have 
a keyboard that repeats keys accidentally.

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


Re: min max of a list

2005-05-06 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
 I get a syntax error in  :
 
  py [(min((abs(p - v), v) for v in valleys + [0] if v  p)[1],
 ...   p,
 ...   min((abs(p - v), v) for v in valleys if v  p)[1])
 ...  for p in peaks]

I think we already covered the part where you were using an older 
version of Python.  In this case, the missing feature is generator 
expressions and they are inside the two min() calls.

You might want to consider upgrading...

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


Multiple Inheritence and data attributes

2005-05-06 Thread Derek Basch
Hello Everyone,

Given:

class A:
def __init__(self):
super(A, self).__init__()
self.dog = fluffy
def changeDog(self):
self.dog = spike

class B:
def __init__(self):
super(B, self).__init__()

class C(object, A, B):
def __init__(self):
super(C, self).__init__()
def printDog(self, cls):
print cls.dog

c = C()
c.printDog(c)

How can I access data attributes of superclasses? I can see the
function attributes of the superclasses:

['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__',
'changeDog', 'printDog']

but not the data attributes. Shouldn't the derived class have that data
attributes of superclasses? I guess I am not understanding the python
implementation.

Thanks,
Derek

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


Re: Running python cgi scripts that require external cvs under apache

2005-05-06 Thread Noah
How do you run the cvs binary from your script? If this is a simple CGI
that calls os.popen() or os.system() then the cvs binary is most likely
running as the same user as the Apache HTTP server (usually someone
like nobody, apache, or www).  http://cgiwrap.unixtools.org/ is
one solution.  Also consider suEXEC  which is part of the Apache
distribution; although, it is not installed by default. See
http://httpd.apache.org/docs/suexec.html . There are reasons why this
is dangerous and those reasons are discussed in the suEXEC
documentation. You can also see if the system administrator can allow
the web server user or group to run cvs. Again, this exposes your
server and so it's dangerous, but allowing cvs commit from a CGI is
dangerous, so I assume you know what you are doing. All of these
solutions will require the involvement of your UNIX system
administrator.

You may also want to look at the ViewCVS project
(http://viewcvs.sourceforge.net/ ) since that is written in Python and
implements a CGI-to-cvs interface. This may give you some
implementation hints.

Yours,
Noah

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


Re: win32: structured storage

2005-05-06 Thread Dave Benjamin
Dave Benjamin wrote:
 Steve Holden wrote:
 
 tlviewer wrote:

   CHM is supposed to be structured storage (ITSF). If a given CHM
   file is infected it most likely has an embedded EXE file -- mine
   had one called [Open.exe].
  
 Ironic, really, since Microsoft insist that the browser must be 
 fully-integrated with the operating system I suppose that measn we had 
 better all start using Linux.
 
 Even more ironically, it would seem that in effort to kill Netscape they 
 are killing Windows.

Or perhaps I'm just restating your point. ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hard memory limits

2005-05-06 Thread Mike Meyer
Fredrik Lundh [EMAIL PROTECTED] writes:

 James Stroud wrote:

  does Mac OS X ship with memory limits set by default?  isn't that
  a single-user system?

 Dear original poster or whoever is interested in OS X:

 OS X is not a single user system. It is BSD based unix. And its [EMAIL 
 PROTECTED]
 sweet! (Though I'm using only Linux right now :o/

 So why would Apple insist on setting unusably low process limits, when
 the others don't?

You're making an unwarranted assumption here - that the OP wasn't
creating a large process of some kind. IIRC, all we ever saw was the
size of the request that triggered the error, with no indication of
the total process size.

FWIW, OS X has a Mach kernel. The failing vm_malloc call listed in the
OP is a Mach call, not a Unix call. These days, the userland code is
largely FreeBSD. It used to include the best of OpenBSD, NetBSD and
FreeBSD at a relatively small level, but that headache was dropped in
favor of tracking one external system. The legacy of the mixed
heritage is utilities from NetBSD and OpenBSD that aren't in
FreeBSD. shlock comes to mind as an obvious example.

 mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe + svn - the final drama

2005-05-06 Thread David Bolen
Timothy Smith [EMAIL PROTECTED] writes:

 Timothy Smith wrote:
(...)
 zipimport.ZipImportError: bad local file header in Z:\temp\library.zip
 
  not that once i have finished client.update(''), it has successfully
  updated the zipfile, i open a dialoge box saying click ok and
  restart program AFTER i click on the above error pops up and my app
  shuts down as intended.
 
 ideas?
 
 ok i have done some digging and i cound this
 
 /* Check to make sure the local file header is correct */
   fseek(fp, file_offset, 0);
   l = PyMarshal_ReadLongFromFile(fp);
   if (l != 0x04034B50) {
   /* Bad: Local File Header */
   PyErr_Format(ZipImportError,
bad local file header in %s,
archive);
   fclose(fp);
 
 
 can anyone explain to me about zip file headers and why it would be
 different/incorrect and give me this error?

Are you perhaps trying to update the zip file in-place while it is still
being used by the application?  I'm not sure that's a safe operation.  A
quick peek at the same module where I think you found the above code shows
that when a zip importer instance is associated with a zip file, the
directory for that zip file is read in and cached.  So the importer is
holding onto offset information for each file based on the contents of the
zip directory at initialization time.

If you then change the file contents (such as updating it with svn), those
offsets will no longer be valid.  I then expect that during your process
exit, some bit of code is performing an extra import, which accesses the
wrong (based on the new file contents) portion of the zip file, and the
above safety check prevents it from loading an erroneous set of bytes
thinking its a valid module.

I expect you need to work on a mechanism to update the file
independently of the running copy, and then arrange to have it moved
into place for a subsequent execution.  Or find some way to have the
zip importer refresh its directory information or make a new importer
instance once the zip file is updated.

One (untested) thought ... before the update, make a copy of your
current library.zip as some other name, and adjust your sys.path to
reference that name (rather than the default pointer to the main
library.zip that py2exe initializes things with).  That should force
any future imports to access the old copy of the zip file and not the
one that svn will be updating.  Since you need to leave that zip file
copy in place through the exit (to satisfy any trailing imports),
arrange for your application to check for that copy on startup and
remove it if present.

Or, after looking through import.c handling for zip file imports,
there might be a simpler way.  ZIP imports are handled by a
zipimporter installed in sys.path_hooks, and once a specific path
element has a path hook instantiated for it (based on the sys.path
element name) it is cached in sys.path_hooks_cache.

So, simply clearing out the path_hooks_cache entry for your main
library.zip file should cause the next import attempt to re-create a
new zipimporter instance and thus re-open the file and re-load the
directory information.

I don't know if py2exe installs the library.zip into sys.path just as
library.zip or with some path information, but try checking out the
keys in sys.path_hooks_cache from your application when it is running.
You should find an entry (probably the only one unless you explicitly
augment sys.path yourself) for library.zip - clear out that key after
the update and see how it works.

Heck, since you're the efficiency hit is likely not an issue, just
flush all of sys.path_hooks_cache and don't even worry about the
actual key name for library.zip.  So a simple:
sys.path_importer_cache.clear()
call after your update completes may do the trick.

-- David

PS: In the same way that updating the library.zip under the running
application is tricky, you might run into issues if you end up trying
to update one of the extension modules.  svn might not be able to
update it (depending on how it deals with in use files).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32: structured storage

2005-05-06 Thread tlviewer

Robert Kern [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 tlviewer wrote:
 
  Is there another way to parse the central directory out of
  a CHM file?
 
 google(chmlib python)

Anyone know the calling syntax for the functions?

PythonWin 2.3.2 (#49, Nov 13 2003, 10:34:54) [MSC v.1200 32 bit (Intel)] on 
win32.
Portions Copyright 1994-2001 Mark Hammond 
([EMAIL PROTECTED]) - see 'Help/About PythonWin' for further copyright 
information.
 import os, sys
 import pychm._chmlib as chm
 obj=chm.chm_open('e:/batch/AdvCrypto')
 obj
 chm.chm_open('e:/batch/AdvCrypto')
 chm
module 'pychm._chmlib' from 'E:\Python23\Lib\site-packages\pychm\_chmlib.pyd'
 enm=chm.chm_enumerate()
Traceback (most recent call last):
  File interactive input, line 1, in ?
TypeError: chm_enumerate() takes exactly 4 arguments (0 given)
 chm.chm_enumerate(obj)

I doubt if the build is good ...

regards,
tlviewer

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


Re: hard memory limits

2005-05-06 Thread John Machin
On Fri, 06 May 2005 18:24:21 +1000, Maurice LING [EMAIL PROTECTED]
wrote:

Hi,

I think I've hit a system limit in python when I try to construct a list 
of 200,000 elements. My error is

malloc: vm_allocate (size = 2400256) failed..

Just wondering is this specific to my system or what? Will adding more 
RAM helps in this case?

Not if it's an OS limit (see other posts). Not if you are doing
something so weird or drastic that you will use up the extra RAM and
still get the same message.

If you were to reply to Fredrik's question (HOW are you creating your
list), and this one: WHAT is an element, we might be able to help
you avoid a trip to the Apple dealer.

As a bit of a reality check for you:
[numbers based on a 32-bit machine, CPython]

An extra list of 20 ints will take up 80 bytes (plus small
change) if the ints are all in range(-1, 101) and thus cached --
that's a 4-byte pointer (i.e. PyObject *) each.

If all the ints are outside that range, and are distinct, they'll take
(worst case) 16 bytes each (assuming you aren't using a debug build of
Python). The additional 12 bytes are for the int object: a reference
counter, a pointer to the type object, and the actual value. So you're
looking at approx 3.2MB.

In general, reckon on each element taking up 12+sizeof(element_value).

I'd suspect that your elements are not quite as elementary as ints,
and/or you are doing a whole lot of *other* memory allocation. Confess
all ...

Cheers,
John




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


handling more databases with ZEO

2005-05-06 Thread Almad
Hello, 

I'm using zodb with zeo and I want to connect to more databases from my
application. On server side, it's no problem, I just set up second
filestorage: 

filestorage 1
path /var/www/databases/zodb/almad-net.fs
/filestorage
filestorage 2
path /var/www/databases/zodb/azilla.fs
/filestorage

However, I dunno how to connect from app. Currently, I'm using

serverData = {
'shelf' : Shelf(('localhost', 11000), [Cat1, Cat2])
}

I dunno where to pass any argument to let ZEO knew where I'm connecting to.
Please let me knew any resource where this is described...

Thanks, 
-- 
Lukas Almad Linhart
[:: http://www.almad.net/ ::]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple Inheritence and data attributes

2005-05-06 Thread [EMAIL PROTECTED]
Two things:
- A call to super doesn't make senseif a class is not derived, and
class b seems superfuous.
- Code below is a working example of your code, the way you did it it
generates an error.

-#!/usr/bin/env python
-class A(object):
-def __init__(self):
-super(A, self).__init__()
-self.dog = fluffy
-def changeDog(self):
-self.dog = spike

-class B(object):
-def __init__(self):
-super(B, self).__init__()

-class C(A, B):
-def __init__(self):
-super(C, self).__init__()
-def printDog(self, cls):
-print cls.dog

-c = C()
-c.printDog(c)
-c.changeDog()
-c.printDog(c)

[EMAIL PROTECTED]:~$ ./test.py
fluffy
spike
[EMAIL PROTECTED]:~$

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


Re: hard memory limits

2005-05-06 Thread Maurice LING
Hi everyone,

thanks for your help.

Yes, I'm using Mac OSX 1.3 with 256MB Ram. Each element in the list is a 
float. The list is actually a retrieved results of document IDs from 
SOAP interface. And Mac OSX does not have 'unlimit' command as shown,

Maurice-Lings-Computer:~ mauriceling$ unlimit
-bash: unlimit: command not found
Maurice-Lings-Computer:~ mauriceling$ which unlimit
Maurice-Lings-Computer:~ mauriceling$ sh unlimit
unlimit: unlimit: No such file or directory
Maurice-Lings-Computer:~ mauriceling$


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


Re: min max of a list

2005-05-06 Thread Steven Bethard
Peter Hansen wrote:
 [EMAIL PROTECTED] wrote:
 
 I get a syntax error in  :

  py [(min((abs(p - v), v) for v in valleys + [0] if v  p)[1],
 ...   p,
 ...   min((abs(p - v), v) for v in valleys if v  p)[1])
 ...  for p in peaks]
 
 
 I think we already covered the part where you were using an older 
 version of Python.  In this case, the missing feature is generator 
 expressions and they are inside the two min() calls.
 
 You might want to consider upgrading...

But if you can't, you should write this as something like:

[(min([(abs(p - v), v) for v in valleys + [0] if v  p])[1],
   p,
   min([(abs(p - v), v) for v in valleys if v  p])[1])
  for p in peaks]

Note the extra brackets in the min calls.

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


Re: hard memory limits

2005-05-06 Thread Mike Meyer
Maurice LING [EMAIL PROTECTED] writes:

 Hi everyone,

 thanks for your help.

 Yes, I'm using Mac OSX 1.3 with 256MB Ram. Each element in the list is
 a float. The list is actually a retrieved results of document IDs from
 SOAP interface. And Mac OSX does not have 'unlimit' command as shown,

 Maurice-Lings-Computer:~ mauriceling$ unlimit
 -bash: unlimit: command not found
 Maurice-Lings-Computer:~ mauriceling$ which unlimit
 Maurice-Lings-Computer:~ mauriceling$ sh unlimit
 unlimit: unlimit: No such file or directory
 Maurice-Lings-Computer:~ mauriceling$

This is a shell builtin command, not an OS X command. For bash, the
command is ulimit, not unlimit. You'll need to read the bash man
page for exact details on how to raise your processes memory limits.

Note that the OS X may have a hard limit that you can't exceed except
as root. This can be raised, but it's a global system configuration,
and you'll have to get someone who knows more about  OS X than I do to
tell you how to do that.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe + svn - the final drama

2005-05-06 Thread Just
In article [EMAIL PROTECTED],
 David Bolen [EMAIL PROTECTED] wrote:

 Are you perhaps trying to update the zip file in-place while it is still
 being used by the application?  I'm not sure that's a safe operation. 

I'm sure it's not :)

[lots of useful help snipped]

the zipimport module has an attr called _zip_directory_cache, which is a 
dict you can .clear(). Still, reloading modules is hairy at best, its 
probably easiest to relaunch your app when the .zip file has changed.

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


Reference to self not passed to member function

2005-05-06 Thread James Stroud
Hello All,

I did this:

py class bob(object):
...   def __init__(self,**kwargs):
... for fname,func in kwargs.items():
...   setattr(self, fname, lambda *args : func(*args))
...
py def doit():
...   print wuzzup?
...
py abob = bob(doit=doit)
py
py abob.doit()
wuzzup?


Much to my surprise, this works fine. 

My questions:

1. What exactly is going on?
2. How can I get ref to self passed to doit() if I want it to? This:

abob.doit(abob)

   seems like the hard way

Any ideas?

James


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hard memory limits

2005-05-06 Thread Fredrik Lundh
Mike Meyer wrote:

  So why would Apple insist on setting unusably low process limits, when
  the others don't?

 You're making an unwarranted assumption here - that the OP wasn't
 creating a large process of some kind.

You need a special license to create large processes on a Mac?

I clicked on the google link that Bill posted, and noted that it wasn't
exactly something that only affected a single Python user.  If some-
thing causes problems for many different applications that run fine
on other Unix systems, it's pretty obvious that the default OS X con-
figuration isn't quite as Unixy as one would expect.

 FWIW, OS X has a Mach kernel. The failing vm_malloc call listed in the
 OP is a Mach call, not a Unix call.

So has tru64.  I've done some serious Python stuff on that platform
(stuff that included some really large processes ;-), and I never had
any allocation problems.  But of course, that system was designed
by DEC people...

/F



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


Re: hard memory limits

2005-05-06 Thread James Stroud
Sorry Maurice, apparently in bash its ulimit (no n). I don't use bash, so I 
don't know all of the differences offhand. Try that.

James

On Friday 06 May 2005 03:02 pm, Maurice LING wrote:
 Hi everyone,

 thanks for your help.

 Yes, I'm using Mac OSX 1.3 with 256MB Ram. Each element in the list is a
 float. The list is actually a retrieved results of document IDs from
 SOAP interface. And Mac OSX does not have 'unlimit' command as shown,

 Maurice-Lings-Computer:~ mauriceling$ unlimit
 -bash: unlimit: command not found
 Maurice-Lings-Computer:~ mauriceling$ which unlimit
 Maurice-Lings-Computer:~ mauriceling$ sh unlimit
 unlimit: unlimit: No such file or directory
 Maurice-Lings-Computer:~ mauriceling$


 Cheers
 Maurice

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reference to self not passed to member function

2005-05-06 Thread [EMAIL PROTECTED]
I think it is more clear to rephrase your code as:
-#!/usr/bin/env python
-class bob(object):
-def __init__(self,**kwargs):
-print kwargs
-for fname,func in kwargs.items():
-setattr(self, fname, lambda *args : func(*args))
-
-def doit():
-print wuzzup?
-
-
-abob = bob(sayyoudo=doit)
-
-abob.sayyoudo()
outpu is now:
[EMAIL PROTECTED]:~$ ./test.py
{'sayyoudo': function doit at 0xb7dfcdf4}
wuzzup?
[EMAIL PROTECTED]:~$

so property sayyoudo points to method doit

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


Re: Getting number of iteration

2005-05-06 Thread Fredrik Lundh
Mike Meyer wrote:

  n = 0
  for x in lst:
  print iteration %d on element %s % (n, x)
  n += 1

 Just for the record, the old idiom was:

 for n in xrange(len(lst)):
 x = lst[n]
 print iteration %d on element %s % (n, x)

it was?  of the following four solutions,

for n in xrange(len(lst)):
x = lst[n]
...

for n in range(len(lst)):
x = lst[n]
...

n = 0
for x in lst:
...
n += 1

for x, n in enumerate(lst):
...

the xrange solution tends to be the slowest, especially for
relatively short lists (up to a 1000 elements, or so).

the exact details vary somewhat between Python versions,
but the += solution is always a good choice, and the xrange
solution is almost always a bad choice.

/F



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


ANN: RUR-PLE version 0.8

2005-05-06 Thread André Roberge
RUR-PLE is a Python Learning Environment.

It contains four main elements:
1. Lessons viewable within an incorporated browser. Version 0.8 includes 
25 lessons introducing Python.
2. A robot world with a robot that can accomplish tasks through Python 
programs.
3. A built-in interpreter which can be used to play with Python
4. A built-in file editor which can be used for futher Python explorations.

Version 0.8 includes a bilingual (English or French) interface.
Only English lessons are included.

RUR-PLE requires wxPython.  It can be found on sourceforge:

https://sourceforge.net/project/showfiles.php?group_id=125834

RUR-PLE has been inspired from GvR (Guido van Robot), also available on 
sourceforge.  RUR-PLE can be though of as GvR++.

The relatively large size of the download is due to the many graphical 
elements included with the lessons.

André Roberge

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


Re: py2exe + svn - the final drama

2005-05-06 Thread Timothy Smith
Just wrote:

In article [EMAIL PROTECTED],
 David Bolen [EMAIL PROTECTED] wrote:

  

Are you perhaps trying to update the zip file in-place while it is still
being used by the application?  I'm not sure that's a safe operation. 



I'm sure it's not :)

[lots of useful help snipped]

the zipimport module has an attr called _zip_directory_cache, which is a 
dict you can .clear(). Still, reloading modules is hairy at best, its 
probably easiest to relaunch your app when the .zip file has changed.

Just
  

what i do is as soon as the update is complete i close the app, but it 
still gives the error, i tried clear() after update and before it, it 
still got the same error. it's be nice to not have to fiddle around with 
the zip file, i really think making py2exe create a dir instead of a zip 
will be much better
here what i do anyway

if (os.name == 'nt') or (os.name == 'win32'):
   
client = pysvn.Client()
#get current revision number
CurrentRev = client.info('').revision.number
   
Check = client.update('')
sys.path_importer_cache.clear()
   
if Check.number  CurrentRev:
self.Popup('Update installed, click ok and restart 
','Update installed')
self.Destroy()
   
else:
InfoMsg.Update(3,'No Updates needed')   

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


Re: py2exe + svn - the final drama

2005-05-06 Thread David Bolen
Just [EMAIL PROTECTED] writes:

 the zipimport module has an attr called _zip_directory_cache, which is a 
 dict you can .clear(). Still, reloading modules is hairy at best, its 
 probably easiest to relaunch your app when the .zip file has changed.

Except that he's getting an error during the process exit of the
current execution, which is needed to restart.  And if he updates to a
different copy, there's the bootstrap problem of how to get it back
into the standard location for the next restart since his application
will need to have it to restart in the first place.

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


Re: Reference to self not passed to member function

2005-05-06 Thread Scott David Daniels
James Stroud wrote:
 Hello All,
 
 I did this:
 
 py class bob(object):
 ...   def __init__(self,**kwargs):
 ... for fname,func in kwargs.items():
 ...   setattr(self, fname, lambda *args : func(*args))
 ...
 py def doit():
 ...   print wuzzup?
 ...
 py abob = bob(doit=doit)
 py
 py abob.doit()
 wuzzup?

 Much to my surprise, this works fine. 
  1. What exactly is going on?

This behavior shouldn't surprise you.  You stored a function as
an attribute.  In fact you could have simply done:
py class bob(object):
...   def __init__(self,**kwargs):
...   for fname, function in kwargs.items():
...   setattr(self, fname, function)

 2. How can I get ref to self passed to doit() if I want it to? This:
 abob.doit(abob)

py import new
py class carol(object):
...def __init__(self, **kwargs):
...for name, method in kwargs.items():
...setattr(self, name,
...new.instancemethod(method, self, carol))

This should behave as you prefer.


--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe + svn - the final drama

2005-05-06 Thread David Bolen
Timothy Smith [EMAIL PROTECTED] writes:

 what i do is as soon as the update is complete i close the app, but it
 still gives the error, i tried clear() after update and before it, it
 still got the same error. it's be nice to not have to fiddle around
 with the zip file, i really think making py2exe create a dir instead
 of a zip will be much better

Well, you'd still potentially have a problem if the update changed a
file in that directory that hadn't been imported yet, but now depended
on other updated files that your application had already loaded old
versions for.  That's a general problem of updating modules beneath
the executing application, and not really specific to the zip file,
although you're getting a zip importer specific error related to that
in this case.

 here what i do anyway
 
 if (os.name == 'nt') or (os.name == 'win32'):
  client = pysvn.Client()
 #get current revision number
 CurrentRev = client.info('').revision.number
  Check = client.update('')
 sys.path_importer_cache.clear()
  if Check.number  CurrentRev:
 self.Popup('Update installed, click ok and restart
 ','Update installed')
 self.Destroy()
  else:
 InfoMsg.Update(3,'No Updates needed')

Ah, it's more devious than I thought.  Just pointed out the other
missing piece in his response.

Apparently there are two levels of caching that you've got to defeat
if you change the underlying zip:

1. A global file set of file directory cache information for any opened
   zip file (for all files in the zip).  This is held in the zipimport
   module global _zip_directory_cache.
2. Individual file cached information within the zipimporter instance
   that is kept in the path importer cache (sys.path_importer_cache).
   Technically these are just references to the same individual entries
   being held in the dictionary from (1).

So when you cleared out (2), it still found the cached directory at
the zipimport module level and re-used that information.  But if you only
clear out (1), then the reference in (2) to the directory entries for
currently imported modules remains and still gets used.

I tried testing this with a small zip file that I first built with normal
compression on the entries, then imported one from a running interpreter,
and then rebuilt the zip without compression.  I couldn't seem to get the
precise error you were getting, but doing this gave me a decompression
error upon an attempted reload of an imported module, since the cached
information still thought it was compressed.

After clearing both sys.path_importer_cache and
zipimport._zip_directory_cache, the reload went fine.

It's sort of unfortunate that you have to cheat with the private
cache clearing in this case.  It might be worth an enhancement request
to see if zipimport could know to update itself if the timestamp on
the zip file changes, but this is sort of a very specialized scenario.
Although maybe just a public way to cleanly flush import cache
information would be useful.

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


Re: hard memory limits

2005-05-06 Thread James Tanis
James Stroud wrote:

Sorry Maurice, apparently in bash its ulimit (no n). I don't use bash, so I 
don't know all of the differences offhand. Try that.
  


The only shells I know of that uses unlimit is csh  tcsh.. bleh.. :) 
FWIW, I've had the same problem in openbsd, while ulimit will fix your 
problem temporarily you'll probably want to edit your default user class 
/etc/login.conf. In response to someone earlier, I think it's Linux here 
that is un-unix like, I do not think that characteristally a (non-admin) 
user is allowed unlimited access to ram in most varieties of unix, among 
other things and for good reason.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Python regex Doc (was: Python documentation moronicities)

2005-05-06 Thread Xah Lee
HTML Problems in Python Doc

I don't know what kind of system is used to generate the Python docs,
but it is quite unpleasant to work with manually, as there are
egregious errors and inconsistencies.

For example, on the Module Contents page (
http://python.org/doc/2.4.1/lib/node111.html ), the closing tags for
dd are never used, and all the tags are in lower case. However, on
the regex syntax page ( http://python.org/doc/2.4.1/lib/re-syntax.html
), the closing tages for dd are given, and all tages are in caps.

The doc's first lines declare a type of:
!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN

yet in the files they uses / to close image tags, which is a XHTML
syntax.

the doc litters p and never closes them, making it a illegal
XML/XHTML by breaking the minimal requirement of well-formedness.

Asides from correctness, the code is quite bloated as in generally true
of generated HTML. For example, it is littered with: tt id='l2h-853'
xml:id='l2h-853' which isn't used in the style sheet, and i don't
think those ids can serve any purpose other than in style sheet.

Although the doc uses a huge style sheet and almost every tag comes
with a class or id attribute, but it also profusively uses hard-coded
style tags like b, big and Netcsape's nobr.

It also abuse tables that effectively does nothing. Here's a typical
line:
table cellpadding=0 cellspacing=0tr valign=baseline
  tdnobrbtt id='l2h-851' xml:id='l2h-851'
class=functioncompile/tt/b(/nobr/td
  tdvarpattern/varbig[/bigvar,
flags/varbig]/bigvar/var)/td/tr/table


If Python is supposed to be a quality language, then its
documentation's content and code seems indicate otherwise.
---

This email is archived at:
http://xahlee.org/perl-python/re-write_notes.html

 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/




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

Re: annonymous functions -- how to

2005-05-06 Thread Dave Benjamin
Peter Hansen wrote:
 Dave Benjamin wrote:
 
 def add_thingy():
 def func(thingy_id):
 print 'got thingy id:', thingy_id
 def funnc(doodad_id):
 print 'got doodad id:', doodad_id
 def func(thingy_doodad):
 print 'thingy doodad created, froobling...'
 frooble(thingy_doodad)
 print 'froobling complete'
 with_new_thingy_doodad(thingy_id, doodad_id, func)
 with_next_doodad_id(func)
 with_next_thingy_id(func)

 This function now has an infinite loop. Can you spot the reason?
 
 Not offhand, and to be completely honest, the original with the longer 
 names was equally unreadable.  I doubt this is the best way to do 
 whatever the heck it is that this is supposed to do.

I agree. I think both are difficult to read. I find the first version 
that I originally posted (using an imaginary anonymous function syntax) 
much easier to understand.

I think I've made it pretty clear what this is supposed to do in my 
earlier post to Fredrik, delineating each step of the communication 
process. If you have a better way to do this, I'd certainly like to see it.

 Oh, and while I was typing my eyes fell on funnc misspelled above. 
 Presumably that's your loop...

Yes, precisely. And because of a typo, the wrong callback gets passed, 
causing it to use the same callback over and over. With anonymous 
functions, there would be nothing to name, and therefore, nothing to 
misspell.

 Spelling func as _ would tend to avoid this as well, unless you have 
 a keyboard that repeats keys accidentally.

Hrmmm. Well, it is less to type.

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


Re: py2exe + svn - the final drama

2005-05-06 Thread Timothy Smith
David Bolen wrote:

Timothy Smith [EMAIL PROTECTED] writes:

  

what i do is as soon as the update is complete i close the app, but it
still gives the error, i tried clear() after update and before it, it
still got the same error. it's be nice to not have to fiddle around
with the zip file, i really think making py2exe create a dir instead
of a zip will be much better



Well, you'd still potentially have a problem if the update changed a
file in that directory that hadn't been imported yet, but now depended
on other updated files that your application had already loaded old
versions for.  That's a general problem of updating modules beneath
the executing application, and not really specific to the zip file,
although you're getting a zip importer specific error related to that
in this case.

  

here what i do anyway

if (os.name == 'nt') or (os.name == 'win32'):
 client = pysvn.Client()
#get current revision number
CurrentRev = client.info('').revision.number
 Check = client.update('')
sys.path_importer_cache.clear()
 if Check.number  CurrentRev:
self.Popup('Update installed, click ok and restart
','Update installed')
self.Destroy()
 else:
InfoMsg.Update(3,'No Updates needed')



Ah, it's more devious than I thought.  Just pointed out the other
missing piece in his response.

Apparently there are two levels of caching that you've got to defeat
if you change the underlying zip:

1. A global file set of file directory cache information for any opened
   zip file (for all files in the zip).  This is held in the zipimport
   module global _zip_directory_cache.
2. Individual file cached information within the zipimporter instance
   that is kept in the path importer cache (sys.path_importer_cache).
   Technically these are just references to the same individual entries
   being held in the dictionary from (1).

So when you cleared out (2), it still found the cached directory at
the zipimport module level and re-used that information.  But if you only
clear out (1), then the reference in (2) to the directory entries for
currently imported modules remains and still gets used.

I tried testing this with a small zip file that I first built with normal
compression on the entries, then imported one from a running interpreter,
and then rebuilt the zip without compression.  I couldn't seem to get the
precise error you were getting, but doing this gave me a decompression
error upon an attempted reload of an imported module, since the cached
information still thought it was compressed.

After clearing both sys.path_importer_cache and
zipimport._zip_directory_cache, the reload went fine.

It's sort of unfortunate that you have to cheat with the private
cache clearing in this case.  It might be worth an enhancement request
to see if zipimport could know to update itself if the timestamp on
the zip file changes, but this is sort of a very specialized scenario.
Although maybe just a public way to cleanly flush import cache
information would be useful.

-- David
  

awesome it looks like it's working now!
it's a very convenient why of keeping them all up today, now instead of 
stuffing around making setup packages i can just run my makeexe.bat file 
to create the py2exe files, svn commit -m new package and i'm done.
also there's no way for the staff to bugger it up ( well, it's fairly safe)

thanks very very much to everyone who made suggestions, this is what 
makes OSS so good - the community input and support.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hard memory limits

2005-05-06 Thread Maurice LING
James Stroud wrote:

 Sorry Maurice, apparently in bash its ulimit (no n). I don't use bash, so I 
 don't know all of the differences offhand. Try that.
 
 James

Thanks guys,

It doesn't seems to help. I'm thinking that it might be a SOAPpy 
problem. The allocation fails when I grab a list of more than 150k 
elements through SOAP but allocating a 1 million element list is fine in 
python.

Now I have a performance problem...

Say I have 3 lists (20K elements, 1G elements, and 0 elements), call 
them 'a', 'b', and 'c'. I want to filter all that is in 'b' but not in 
'a' into 'c'...

  a = range(1, 10, 5)
  b = range(0, 100)
  c = []
  for i in b:
... if i not in a: c.append(i)
...

This takes forever to complete. Is there anyway to optimize this?

Thanks in advance

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


how to make a LAN game using python?

2005-05-06 Thread flyaflya
I want make a desktop game suports LAN connect, but pygame has nothing 
about network.How to let pygame suport LAN connect? have you some 
examples or articles about LAN connect?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hard memory limits

2005-05-06 Thread Mike Meyer
Fredrik Lundh [EMAIL PROTECTED] writes:

 Mike Meyer wrote:

  So why would Apple insist on setting unusably low process limits, when
  the others don't?

 You're making an unwarranted assumption here - that the OP wasn't
 creating a large process of some kind.

 You need a special license to create large processes on a Mac?

No more so than on any other OS. What does that have to do with my
pointing out that the OP may have been creating a process that
exceeded the size normally allowed for non-administrator processes?
Any modern OS should have different groups of users with different
sets of possible maximum resource allocation - which only an
administrator should be allowed to change.

 I clicked on the google link that Bill posted, and noted that it wasn't
 exactly something that only affected a single Python user.  If some-
 thing causes problems for many different applications that run fine
 on other Unix systems, it's pretty obvious that the default OS X con-
 figuration isn't quite as Unixy as one would expect.

I didn't follow that link - I formulated my own google queery. While I
saw lots of things about vm_malloc, trying vm_malloc python turns up
nothing. Which seems to indicate that this is a relatively rare thing
for python users.

 FWIW, OS X has a Mach kernel. The failing vm_malloc call listed in the
 OP is a Mach call, not a Unix call.
 So has tru64.  I've done some serious Python stuff on that platform
 (stuff that included some really large processes ;-), and I never had
 any allocation problems.  But of course, that system was designed
 by DEC people...

Oddly enough, google just turned up a vm_malloc for VMS as well. I
wonder if that's where tru64 got it from - and if so how it got into
Mach?

There is something very non-unixy going on here, though. Why is
vm_malloc exiting with an error message, instead of returning a
failure to the calling application? I've seen other applications
include a FOSS malloc implementation to work around bugs in the
system's malloc. Maybe Python should do that on the Mac?

 mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to make a LAN game using python?

2005-05-06 Thread Peter Hansen
flyaflya wrote:
 I want make a desktop game suports LAN connect, but pygame has nothing 
 about network.How to let pygame suport LAN connect? have you some 
 examples or articles about LAN connect?

Pygame wouldn't bother supporting that, since it's already fully 
supported by standard Python, and any number of add-on frameworks.

Your options include, but aren't limited to:

- the socket module in Python's standard library
- asyncore and friends in the standard library
- Twisted (this might be beyond your level, but it was *designed* for 
doing online games so it can certainly handle whatever you want to throw 
at it... think of it as something you can grow into)
- Pyro (this might be the easiest for you to get working, if you already 
know Python and are using it for all software involved)

Many books and web sites on Python will cover networking issues as well. 
  The Python in a Nutshell book certainly talks about it, and I suspect 
the Cookbook has some useful recipes as well.

Finally, search terms to help you use Google, which could certainly have 
told you much of this if you'd tried, include sockets, RPC, 
distributed systems, networking, and of course Python in 
combination with any of them...

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


Re: hard memory limits

2005-05-06 Thread Bengt Richter
On Sat, 07 May 2005 11:08:31 +1000, Maurice LING [EMAIL PROTECTED] wrote:

James Stroud wrote:

 Sorry Maurice, apparently in bash its ulimit (no n). I don't use bash, so 
 I 
 don't know all of the differences offhand. Try that.
 
 James

Thanks guys,

It doesn't seems to help. I'm thinking that it might be a SOAPpy 
problem. The allocation fails when I grab a list of more than 150k 
elements through SOAP but allocating a 1 million element list is fine in 
python.

Now I have a performance problem...

Say I have 3 lists (20K elements, 1G elements, and 0 elements), call 
them 'a', 'b', and 'c'. I want to filter all that is in 'b' but not in 
'a' into 'c'...

  a = range(1, 10, 5)
  b = range(0, 100)
  c = []
  for i in b:
... if i not in a: c.append(i)
...

This takes forever to complete. Is there anyway to optimize this?

Checking whether something is in a list may average checking equality with
each element in half the list. Checking for membership in a set should
be much faster for any significant size set/list. I.e., just changing to

  a = set(range(1, 10, 5))

should help. I assume those aren't examples of your real data ;-)
You must have a lot of memory if you are keeping 1G elements there and
copying a significant portion of them. Do you need to do this file-to-file,
keeping a in memory? Perhaps page-file thrashing is part of the time problem?

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to make a LAN game using python?

2005-05-06 Thread Terry Reedy

flyaflya [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
I want make a desktop game suports LAN connect, but pygame has nothing
 about network.How to let pygame suport LAN connect? have you some
 examples or articles about LAN connect?

The discussions on the pygame mailing list (gatewayed to 
gmane.comp.python.games) include networking with pygame issues.  There were 
recent threads about pygame and twisted.  See if you can explore the 
archives a bit.

Terry J. Reedy





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


  1   2   >