Re: safest way to kill a thread

2005-01-18 Thread limodou
I think only those threads which invoked with setDaemon() method will 
exit, and others will not,  as the main program exit.

[EMAIL PROTECTED] wrote:
limodou wrote:
Using Thread's method setDaemon() before you call the start() method.
Just like :
t.setDaemon(True)
t.start()
thank for fast reply.
from python.org doc, said that setDaemon() function as
"The entire Python program exits when no active non-daemon threads
are left."
is it mean that when the main program exit (normally/abnormally), all
threads created will also exit?
  Thank again.
--
I love python!
My Blog: http://www.donews.net/limodou
--
http://mail.python.org/mailman/listinfo/python-list


Re: Solutions for data storage?

2005-01-18 Thread Jan Dries
Leif K-Brooks <[EMAIL PROTECTED]> schreef:
> 
> I've looked at SQLObject, and it's very nice, but it doesn't 
> provide certain features I really want, like the ability to store
> lists of strings or integers directly in the database (using commas
> in a varchar column or something).

What exactly in SQLObject prevents you from doing this? You may have to
pack/unpack the list into a comma separated string yourself, but surely the 2
line code function that requires can't be the problem.
And SQLObject's support for properties makes this very clean.
See:
http://www.sqlobject.org/docs/SQLObject.html#adding-magic-attributes-properties
Or am I missing something here?

Regards,
Jan


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


Re: safest way to kill a thread

2005-01-18 Thread martinnitram
limodou wrote:
>Using Thread's method setDaemon() before you call the start() method.
>Just like :
>t.setDaemon(True)
>t.start()
thank for fast reply.
from python.org doc, said that setDaemon() function as
"The entire Python program exits when no active non-daemon threads
are left."
is it mean that when the main program exit (normally/abnormally), all
threads created will also exit?
  Thank again.

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


Solutions for data storage?

2005-01-18 Thread Leif K-Brooks
I'm writing a relatively simple multi-user public Web application with 
Python. It's a rewrite of a similar application which used PHP+MySQL 
(not particularly clean code, either). My opinions on various Web 
frameworks tends to vary with the phase of the moon, but currently, I'm 
planning to use Quixote.

Needless to say, my application will need some kind of persistent data 
storage. The previous PHP+MySQL application uses around 1.1GB of 
storage, so something like PyPerSyst where everything is kept in memory 
is out.

I've looked at SQLObject, and it's very nice, but it doesn't provide 
certain features I really want, like the ability to store lists of 
strings or integers directly in the database (using commas in a varchar 
column or something).

ZODB is very nice, but IndexedCatalog doesn't seem to provide any 
automatic mechanisms for things like ensuring attribute uniqueness (for 
e.g. usernames). I suppose I could implement manual checking in every 
class that needs it, but it really seems like very error-prone code to 
be implementing at the application level.

My ideal solution would be an object database (or object-relational 
mapper, I guess) which provided total transparency in all but a few 
places, built-in indexing, built-in features for handling schema 
changes, the ability to create attributes which are required to be 
unique among other instances, and built-in querying with pretty syntax. 
Atop seems to come pretty close, but since it's meant to be used in the 
asynchronous Twisted environment, it doesn't provide any thread safety.

So basically, I'm wondering if there are any Python data storage 
solutions I haven't noticed that come a bit closer to what I'm looking 
for. I could live without built-in schema evolution; the querying is 
really the most important feature I want.
--
http://mail.python.org/mailman/listinfo/python-list


Re: File objects? - under the hood question

2005-01-18 Thread Stephen Thorne
On Tue, 18 Jan 2005 22:53:10 -0800, Eric Pederson <[EMAIL PROTECTED]> wrote:
> 
> I didn't come across any illuminating discussion via Google, thus my question 
> here (though it may be a neophyte question.) I am interested in the workings 
> under the hood of Python's access of "files".
> 
> What is actually happening at the various stages when I create a file object 
> and "read" it?
> 
> (1)>>> f = file("C:/GuidosParrot.txt","r")
You've just opened a file for reading. You haven't read any data, but
at this point if the file wasn't there, the OS would have throw you an
error.

> (2)>>> hesjustsleeping = f.read()
The entire file is read directly into a single python str.

Regards,
Stephen Thorne.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: generator expressions: performance anomaly?

2005-01-18 Thread Stephen Thorne
On Tue, 18 Jan 2005 23:09:57 -0700, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> @with_consts(i=1, deftime=time.ctime())
> def foo(x, y=123, *args, **kw):
>  return x*y, kw.get('which_time')=='now' and time.ctime() or deftime
> 
> Then you don't have to mix parameter declarations with locals definitions.
> 
> [1] I have no idea how implementable such a decorator would be.  I'd
> just like to see function constants declared separate from arguments
> since they mean such different things.

(untested)

def with_constant(**constants_kwargs):  
  def decorator(f)
def closure(*arg, **kwargs):
  kwargs.update(constants_kwargs)
  return f(*arg, **kwargs)
return closure
  return decorator
   
Regards,
Stephen Thorne
-- 
http://mail.python.org/mailman/listinfo/python-list


File objects? - under the hood question

2005-01-18 Thread Eric Pederson

I didn't come across any illuminating discussion via Google, thus my question 
here (though it may be a neophyte question.) I am interested in the workings 
under the hood of Python's access of "files".

What is actually happening at the various stages when I create a file object 
and "read" it?

(1)>>> f = file("C:/GuidosParrot.txt","r")

(2)>>> hesjustsleeping = f.read()

At (1) have I loaded the file from hard drive into RAM when I create the file 
object?  What does this object know and how did it find it out?

At (2) am I loading the file contents into RAM, or just assigning what is 
already in RAM to a variable? 

Where is the work split between the OS and Python?  I assume the OS is 
responsible for "presenting" the file to Python, so perhaps the OS assembles 
this file from the blocks on disk and loads it into RAM at the time the file 
object is created?  Or would the OS simply have pointers that can assemble the 
file, and pass those pointers to Python?

Perhaps I've answered my question and the under-the-hood mechanics are handled 
on the OS side, and Python is just making requests of the OS...


My brain-teaser:  What I'd like to do is read the last ~2K of a large number of 
large files on arbitrary servers across the net, without having to read each 
file from the beginning (which would be slow and resource inefficient)...




Eric Pederson
http://www.songzilla.blogspot.com
:::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:

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


Re: makepy crashing

2005-01-18 Thread Roger Upole
Looks like the makepy step creates the generated file successfully,
but python is choking with an assertion failure on lines longer than
512 when it tries to import it.

This is the line it was processing when it died:
def GetSpellingSuggestions(self, Word=defaultNamedNotOptArg,
CustomDictionary=defaultNamedOptArg, IgnoreUppercase=defaultNamedOptArg,
MainDictionary=defaultNamedOptArg, SuggestionMode=defaultNamedOptArg,
CustomDictionary2=defaultNamedOptArg, CustomDictionary3=defaultNamedOptArg,
CustomDictionary4=defaultNamedOptArg, CustomDictionary5=defaultNamedOptArg,
CustomDictionary6=defaultNamedOptArg, CustomDictionary7=defaultNamedOptArg,
CustomDictionary8=defaultNamedOptArg, CustomDictionary9=defaultNamedOptArg,
CustomDictionary10=defaultNamedOptArg):

You might be able to do a workaround by hacking genpy.py and replacing the
defaultArg names with something shorter.
...Nope, there are a few other lines that exceed 512.

I think it's a problem with the encoding.  If you remove the mbcs tag
(# -*- coding: mbcs -*-) from the top of the generated file, the import 
succeeds.

   Roger


<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Has anyone sucessfully run makepy and Microsoft Word Object Library
> (9.0)?  Mine crashes under XP Pro and Python 2.4.
>
> It only seems to be word that has the problem, though.
>
> I get a dialog that says that pythonwin.exe has crashed:
> AppName: pythonwin.exe AppVer: 0.0.0.0 ModName: ntdll.dll
> ModVer: 5.1.2600.1217 Offset: 96f9
>





== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: generator expressions: performance anomaly?

2005-01-18 Thread Steven Bethard
Bengt Richter wrote:
On Tue, 18 Jan 2005 17:38:20 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:

Bengt Richter wrote:
Which make me wonder what plans there are for providing a better
mechanism than default arguments as a way of initializing local function
variables. Nested def's to create a closure with initialized values is
pretty crufty for that, IMO.
What about using a class?  Associating functions with data is pretty 
much what they're for...


Maybe extending the default argument space
with whatever comes after e.g. a triple star delimiter in the argument list,
but which wouldn't be counted as part of the normal arguments? E.g.,
   def foo(x, y=123, *args, **kw, *** i=1, deftime=time.ctime()):
   return x*y, kw.get('which_time')=='now' and time.ctime() or deftime
If what you want is to have i=1 and deftime=time.ctime() available 
within foo, you could do something like (untested):

class foo(object):
   def __init__(self):
   self.i = 1
   self.deftime = time.ctime()
   def __call__(self, x, y=123, *args, **kwds):
   return x*y, (kw.get('which_time') == 'now'
and time.ctime() or self.deftime)
foo = foo()
Total: 8 lines, much irrelevant cruft.

Or if you don't like 'foo = foo()', you could probably abuse the __new__ 
method (also untested):

class foo(object):
   i = 1
   deftime = time.ctime()
   def __new__(cls, x, y=123, *args, **kwds):
   return x*y, (kw.get('which_time') == 'now'
and time.ctime() or self.deftime)
Total: 6 lines, newbie-unfriendly abuse of __new__ ;-)

I guess my point is that if you want attribute associated with the 
function, it's often easy enough to write a class instead...
vs. 2 easy lines with minimal irrelevant cruft ;-)
If you're really counting lines, you might compare with the more compact:
class foo(object):
def __init__(self):
self.i, self.deftime = 1, time.ctime()
def __call__(self):
return x*y, kw.get('which_time') == 'now' and time.ctime() or 
self.deftime
foo = foo()

and
class foo(object):
i, deftime = 1, time.ctime()
def __new__(cls, x, y=123, *args, **kwds):
return x*y, kw.get('which_time') == 'now' and time.ctime() or 
self.deftime

And probably what you want to compare is N lines (function only) versus 
N + 2 lines (using __new__) and N + 4 lines (using __call__).  If N is 
more than 2 lines (which is probably true in most cases), the difference 
isn't so dramatic.

Using a class also has the advantage that, assuming one already knows 
how classes work (which any Python programmer who wants the kind of 
scoping you're talking about should) you don't have to learn how 
something new to be able to use it -- that is, *** -> bound locals that 
don't contribute to arguments but are listed in the same place as arguments.

If you really want locals that don't contribute to arguments, I'd be 
much happier with something like a decorator, e.g.[1]:

@with_consts(i=1, deftime=time.ctime())
def foo(x, y=123, *args, **kw):
return x*y, kw.get('which_time')=='now' and time.ctime() or deftime
Then you don't have to mix parameter declarations with locals definitions.
Steve
[1] I have no idea how implementable such a decorator would be.  I'd 
just like to see function constants declared separate from arguments 
since they mean such different things.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Window capture using WM_PRINT and Python

2005-01-18 Thread Roger Upole
Do you get any kind of traceback when you start a process that way?
There's not much info to go on.

Sys.argv parameters are passed as strings.  You'll need to do an int() on 
them
before you can use them as handles.  Also, not all handles are portable
between processes.  Your device context handle might not be valid
even if you make it an int.

   hth
Roger


"arN" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi !
>
> I'm a Java developper and I wish to make a capture of an offscreen window 
> (on WinXP). It's not possible in Java, so I use a python script and 
> WM_PRINT, but it doesn't seem to work.
>
> Could someone have a look at my script and give me any advise ?
>
> TIA
>
> --
> Arnaud
> my python script : python snap.py GraphicalContext_handle image_handle
> --
> snap.py :
> "
> import win32api, win32con, sys
>
> win32api.SendMessage(sys.argv[2], win32con.WM_PAINT, sys.argv[3], 0)
> win32api.SendMessage(sys.argv[2], win32con.WM_PRINT, sys.argv[3], 
> win32con.PRF_CHILDREN | win32con.PRF_CLIENT | win32con.PRF_OWNED)
> "
>
> 
> snippet from Snapshot.java :
> "
> public static Image snapshot(Composite bean) {
> GC gc = new GC(bean);
> final Image image = new Image (null, bean.getBounds().width, 
> bean.getBounds().height);
> String commmand = "python snap.py " + gc.handle + " " + image.handle;
>
> Runtime rt = Runtime.getRuntime();
> try {
> Process p = rt.exec(command);
> } catch (.)
>
> gc.dispose();
> return image;
> }
> " 




== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python/cgi/html bug

2005-01-18 Thread Dan Bishop

Dfenestr8 wrote:
> Hi.
>
> I've written a cgi messageboard script in python, for an irc chan I
happen
> to frequent.
>
> Bear with me, it's hard for me to describe what the bug is. So I've
> divided this post into two sections: HOW MY SCRIPTS WORKS, and WHAT
THE
> BUG IS.
> ...
> The problem is when someone posts a new topic, and that topic happens
to
> have "" double quotes, or any other strange character, some strange
> glitches occur.

Use cgi.escape(topic, True) to convert HTML special characters to the
equivalent ampersand escape sequences.

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


Error in Plex 1.1.4.1

2005-01-18 Thread srijit
Hello,
I got the following error while using Plex 1.1.4.1

D:\Python24\myfiles>python plex1.py
Traceback (most recent call last):
  File "plex1.py", line 1, in ?
from Plex import *
  File "D:\python24\lib\site-packages\Plex\__init__.py", line 34, in ?
from Lexicons import Lexicon, State
  File "D:\python24\lib\site-packages\Plex\Lexicons.py", line 12, in ?
import DFA
  File "D:\python24\lib\site-packages\Plex\DFA.py", line 9, in ?
import Machines
  File "D:\python24\lib\site-packages\Plex\Machines.py", line 14, in ?
from Transitions import TransitionMap
  File "D:\python24\lib\site-packages\Plex\Transitions.py", line 85
def get_epsilon(self,
SyntaxError: Invalid syntax.  Assignment to None.

The corresponding source code :

#file plex1.py

from Plex import *

lexicon = Lexicon([
(Str("Python"),  "my_favourite_language"),
(Str("Perl"),"the_other_language"),
(Str("rocks"),   "is_excellent"),
(Str("sucks"),   "is_differently_good"),
(Rep1(Any(" \t\n")), IGNORE)
])

filename = "plex1.txt"
f = open(filename, "r")
scanner = Scanner(lexicon, f, filename)
while 1:
token = scanner.read()
print token
if token[0] is None:
break

The error was removed when I used the following code in Transitions.py

def get_epsilon(self,
none = None):
"""
Return the mapping for epsilon, or None.
"""
return self.special.get('', None)


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


[perl-python] 20050119 writing modules

2005-01-18 Thread Xah Lee
© # -*- coding: utf-8 -*-
© # Python
©
© # one can write functions,
© # save it in a file
© # and later on load the file
© # and use these functions.
©
© # For example, save the following line in
© # a file and name it module1.py
© # def f1(n): returns range(n)
©
© # to load the file, use import
© import mymodule
©
© # to use the function, use
© # fileName.functionName.
© print mymodule.f1(5)
©
© # the file name without the .py suffix
© # is the module's name, and is available
© # as the variable fileName.__name__
© print mymodule.__name__
©
© # for more on modules, see
© # http://python.org/doc/2.3.4/tut/node8.html
©
© 
© # the perl analogue is like this:
© # save the following 3 lines in a file
© # and name it mymodule.pm
©
© # package mymodule;
© # sub f1($){(1..$_[0])}
© # 1
©
© # then, call it like the following way
© use mymodule;
© use Data::Dumper;
© print Dumper [&mymodule::f1(7)];
©
© # this is about the simplest way
© # to write a modlue in perl and
© # calling its function.
© # for an inscrutable treatment,
© # see "perldoc perlmod"
©
©   Xah
©   [EMAIL PROTECTED]
©   http://xahlee.org/PageTwo_dir/more.html

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


Re: rotor replacement

2005-01-18 Thread Paul Rubin
"Reed L. O'Brien" <[EMAIL PROTECTED]> writes:
> I see rotor was removed for 2.4 and the docs say use an AES module
> provided separately...  Is there a standard module that works alike or
> an AES module that works alike but with better encryption?

If you mean a module in the distribution, the answer is no, for
political reasons.

There are a number of AES modules available on the net.  Most are C
extension modules which means you need to compile them, and if you
want to deploy them widely, you need binaries for every target platform.
There's a few pure-Python AES implementations but they are verrry slow.

Here's something written in Python that uses the built-in sha1 module
as a crypto primitive.  Its security should be better than rotor and
performance is reasonable for most applications:

  http://www.nightsong.com/phr/crypto/p3.py

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


Re: Has apparent 2.4b1 bug been fixed? flatten in Lib\compiler\ast.py overloads 'list' name

2005-01-18 Thread Bengt Richter
On Wed, 19 Jan 2005 04:55:53 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:

>What am I missing? (this is from 2.4b1, so probably it has been fixed?)
>
I googled and found a bug report, but initial report kind of passes on it
saying nested sequences will probably be tuples, so no panic (my paraphrased 
description).
So I guess it's in the mill. So never mind. I should have googled first ;-/

>
>def flatten(list):
>l = []
>for elt in list:
>   --must be expecting list instance or other sequence
>t = type(elt)
>if t is tuple or t is list:
>  --looks like it expects to refer to the 
> type, not the arg
>for elt2 in flatten(elt):
>l.append(elt2)
>else:
>l.append(elt)
>return l
>

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


Has apparent 2.4b1 bug been fixed? flatten in Lib\compiler\ast.py overloads 'list' name

2005-01-18 Thread Bengt Richter
What am I missing? (this is from 2.4b1, so probably it has been fixed?)


def flatten(list):
l = []
for elt in list:
   --must be expecting list instance or other sequence
t = type(elt)
if t is tuple or t is list:
  --looks like it expects to refer to the type, 
not the arg
for elt2 in flatten(elt):
l.append(elt2)
else:
l.append(elt)
return l


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


Re: Employablity of python programmers

2005-01-18 Thread Benji York
Mir Nazim <[EMAIL PROTECTED]> wrote:
I am in a fix what skill set I must choose to be safe as
far as job openings are concerned.
> 1) C/C++ and Python.
> 2) Java and Python.
> 3) Pure Python.
As for pure employability, I'd choose option 2, but as a person that 
wants something more than employment from my work life, I'd like to 
share something with you:

A while ago I decided that to be happy I had to decide what I wanted, 
*really* go after those things, and believe that the rewards would 
follow.  For me Python had a big part to play in that, so I recently 
started looking for a new job, even though I already had one that was 
promising and secure.  It also meant being willing to move myself and my 
family far from or home, friends, and other family members to take that 
new job.

If we were willing to make big changes (and the accompanying 
sacrifices), we were going to make the most of it: I wouldn't accept 
anything but the right job, at the right company, with the right 
environment where they really needed *me*.  I spent hours researching 
openings and companies and sent out many resumes with the hopes of 
finding that *one* job.  Two weeks later, I was fortunate enough to 
begin talks with *two* very interested (and more importantly, 
interesting) companies.

I've been at my new job (in a new house, in a new city) for about six 
weeks now.  It's not perfect (nothing is), but I'm enjoying the job, 
like the people I work with, and the area we live in.  We made the right 
choice.  Go after what you really want, and you will too.
--
Benji York
Sr. Software Engineer
Zope Corporation
--
http://mail.python.org/mailman/listinfo/python-list


rotor replacement

2005-01-18 Thread Reed L. O'Brien
I see rotor was removed for 2.4 and the docs say use an AES module 
provided separately...  Is there a standard module that works alike or 
an AES module that works alike but with better encryption?

cheers,
reed
--
http://mail.python.org/mailman/listinfo/python-list


Re: safest way to kill a thread

2005-01-18 Thread limodou
Using Thread's method setDaemon() before you call the start() method. 
Just like :

t.setDaemon(True)
t.start()
[EMAIL PROTECTED] wrote:
Dear all,
in python, a thread can be created by t = threading.Thread. But i
found that when the main (and the thread) program is running and user
use Crtl+C/Crtl+Z to break the program abnormally, the thread is still
running and needed to kill manually (by the pid). Is there had any
safest way to kill/exit the thread program under python (when the
thread program part is a forever loop)?
Thank a lot
--
I love python!
My Blog: http://www.donews.net/limodou
--
http://mail.python.org/mailman/listinfo/python-list


safest way to kill a thread

2005-01-18 Thread martinnitram
Dear all,
in python, a thread can be created by t = threading.Thread. But i
found that when the main (and the thread) program is running and user
use Crtl+C/Crtl+Z to break the program abnormally, the thread is still
running and needed to kill manually (by the pid). Is there had any
safest way to kill/exit the thread program under python (when the
thread program part is a forever loop)?

Thank a lot

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


DDE client help

2005-01-18 Thread bogdan romocea
Dear Python experts,

I'm facing a simple problem which however I'm having a hard time
solving. I have a DDE server with data that changes from time to time.
I need to put together a DDE client that would 'notice' updated values
on the server and append them as a new row in a text file. 

1. How do I connect to the DDE server, and ask for data?
In OpenOffice.org it looks very simple:
=DDE("FPS";"TIME";"PRC")
I also have some VB code which does the same thing:
Private Sub Command1_Click()
Text1.LinkTopic = "FPS|TIME"
Text1.LinkItem = Text4.Text
Text1.LinkMode = vbLinkAutomatic
I checked the DDE client sample code from
C:\Python24\Lib\site-packages\win32\Demos\dde, 
however I got stuck here:
conversation.ConnectTo("FPS","PRC")
Traceback (most recent call last):
  File "", line 1, in ?
conversation.ConnectTo("FPS","PRC")
error: ConnectTo failed

2. Once I manage to connect to the DDE server, how do I append the new
data values in a text file?

Suggestions and sample code will be highly appreciated.

Thank you,
b.






__ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050118 keyed list

2005-01-18 Thread Jürgen Exner
Tassilo v. Parseval wrote:
> Also sprach Jürgen Exner:
>
>> Xah Lee wrote:
>
>>> © %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
>>> © use Data::Dumper qw(Dumper);
>>> © print Dumper \%a;
>>
>> Wow, my compliments. The very first time that using Data::Dumper
>> actually may do something useful (formats the data more nicely).
>> Still, why you are passing a reference is beyond me.
>
> How else would you use 'Dumper' on a hash?

Well, fair enough. If you do a plain
print Dumper(%a);
you do loose a lot of the nifty pretty printing that is provided by Dumper 
otherwise.

jue 


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


Re: generator expressions: performance anomaly?

2005-01-18 Thread Paul Rubin
Steve Holden <[EMAIL PROTECTED]> writes:
> You probably already know that sensible compiled language systems have
> used constant folding since time immemorial, but Python has always
> eschewed it. That's what comes of being a pragmatist's language: if
> such optimizations really are required the programmer is expected to
> perform them.

You mean the lack is deliberate?  I just figured it was an artifact of
the implementation and that PyPy had some reasonable chance of fixing it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: generator expressions: performance anomaly?

2005-01-18 Thread Bengt Richter
On Tue, 18 Jan 2005 17:38:20 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:

>Bengt Richter wrote:
>> Which make me wonder what plans there are for providing a better
>> mechanism than default arguments as a way of initializing local function
>> variables. Nested def's to create a closure with initialized values is
>> pretty crufty for that, IMO.
>
>What about using a class?  Associating functions with data is pretty 
>much what they're for...
>
>> Maybe extending the default argument space
>> with whatever comes after e.g. a triple star delimiter in the argument list,
>> but which wouldn't be counted as part of the normal arguments? E.g.,
>> 
>> def foo(x, y=123, *args, **kw, *** i=1, deftime=time.ctime()):
>> return x*y, kw.get('which_time')=='now' and time.ctime() or deftime
>
>If what you want is to have i=1 and deftime=time.ctime() available 
>within foo, you could do something like (untested):
>
>class foo(object):
> def __init__(self):
> self.i = 1
> self.deftime = time.ctime()
> def __call__(self, x, y=123, *args, **kwds):
> return x*y, (kw.get('which_time') == 'now'
>  and time.ctime() or self.deftime)
>foo = foo()
Total: 8 lines, much irrelevant cruft.

>
>Or if you don't like 'foo = foo()', you could probably abuse the __new__ 
>method (also untested):
>
>class foo(object):
> i = 1
> deftime = time.ctime()
> def __new__(cls, x, y=123, *args, **kwds):
> return x*y, (kw.get('which_time') == 'now'
>  and time.ctime() or self.deftime)
Total: 6 lines, newbie-unfriendly abuse of __new__ ;-)

>
>I guess my point is that if you want attribute associated with the 
>function, it's often easy enough to write a class instead...
vs. 2 easy lines with minimal irrelevant cruft ;-)

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


Re: Integration with java (Jpype vs. JPE)

2005-01-18 Thread Steve Menard
Istvan Albert wrote:
Steve Menard wrote:
To asnwer your question more fully, the jpype-specific cide is only 
for looking up the Classes and startting/stopping the environment. For 
everything else, Java objects and classes are used as regular Python 
objects.

Thanks for the response. Currently I don't need to use java but
in the past when I explored such a possibility I looked at jpype
and I was unable to understand from the documentation what it
actually does.
There is a lot of text there, but it is all concerning catching
errors or other subtleties. For a new visitor the most important
question is about how it works, what does it do, and how can it be
applied for the given problem.
 > everything else, Java objects and classes are used as regular Python
 > objects.
This is too generic. My question was a little more specific,
how would I pass a python list as an argument of a java class/method or
transform a java list into a python one? You don't have to
answer it here, I'm just pointing out the kind of
questions that I was unable to get an answer for on the jpype
website.
best,
Istvan.
I see what you mean. And I agree fully. I guess that's one more thing to 
put on the TODO list hehe.

Thanks for the input.
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem parsing namespaces with xml.dom.minidom

2005-01-18 Thread Mike McGavin
Hi Fredrik.
Fredrik Lundh wrote:
It wouldn't need to conform to the official specifications of the DOM API, but I guess I'm after 
some comparable functionality. [--snip--]

sounds like this might be exactly what you need:
http://effbot.org/zone/element-index.htm
(it's also the fastest and most memory-efficient Python-only parser you
can get, but I suppose that's not a problem ;-)
Thanks.  The original problem I was having turned out to the be 
reversing a couple of parameters in a method call, as Paul pointed out, 
and I now feel pretty silly as a result.  But I'll take a look at this, too.

Much appreciated.
Mike.
--
http://mail.python.org/mailman/listinfo/python-list


Re: file copy portability

2005-01-18 Thread Bob Smith
John Machin wrote:
Bob Smith wrote:
Is shutil.copyfile(src,dst) the *most* portable way to copy files
with
Python? I'm dealing with plain text files on Windows, Linux and Mac
OSX.
Thanks!

Portable what? Way of copying??
Do you want your files transferred (a) so that they look like native
text files on the destination system, or (b) so that they are exact
byte-wise copies?
A 5-second squint at the source (Lib/shutil.py) indicates that it
provides, reliably and portably, option b:
fsrc = open(src, 'rb')
fdst = open(dst, 'wb')
One way of doing option (a): you would need to be running Python on the
destination system, open the src file with 'rU', open the dst file with
'w'.
The files are not copied from one platform to the other. The app must 
run on all platforms. I want to make the app as portable as possible to 
reduce platform specific code.
--
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous multiple requests to very simple database

2005-01-18 Thread Eric S. Johansson
Thomas Bartkus wrote:
When you write that "super dictionary", be sure to post code!
I could use one of those myself.
hmmm it looks like you have just flung down the gauntlet of "put up or 
quityerwhinging".  I need to get the crude implementation done first but 
I think I can do it if I can find a good XMLRPC multithreading framework.

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


Re: file copy portability

2005-01-18 Thread Steve Holden
Bob Smith wrote:
Is shutil.copyfile(src,dst) the *most* portable way to copy files with 
Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.

Thanks!
Yes.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: file copy portability

2005-01-18 Thread John Machin

Bob Smith wrote:
> Is shutil.copyfile(src,dst) the *most* portable way to copy files
with
> Python? I'm dealing with plain text files on Windows, Linux and Mac
OSX.
>
> Thanks!

Portable what? Way of copying??

Do you want your files transferred (a) so that they look like native
text files on the destination system, or (b) so that they are exact
byte-wise copies?

A 5-second squint at the source (Lib/shutil.py) indicates that it
provides, reliably and portably, option b:
fsrc = open(src, 'rb')
fdst = open(dst, 'wb')

One way of doing option (a): you would need to be running Python on the
destination system, open the src file with 'rU', open the dst file with
'w'.

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


Re: file copy portability

2005-01-18 Thread Peter Hansen
Bob Smith wrote:
Is shutil.copyfile(src,dst) the *most* portable way to copy files with 
Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.
Yes, provided you don't need any of the features provided by the
other shutil.copy functions, and assuming you can live with the
Caveat listed in the docs for the MacOS system...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: generator expressions: performance anomaly?

2005-01-18 Thread Bengt Richter
On Tue, 18 Jan 2005 15:29:06 +0100, "Diez B. Roggisch" <[EMAIL PROTECTED]> 
wrote:

>> I don't see how generating byte code for a = 9; when seeing the
>> expression a = 3 + 6, would be a problem for non-functional
>> languages.
>
>Most probably. But I don't see much code of that type that it would be worth
>optimizing for, either. The cost for re-evaluation such an expression
>doesn't really account for any performance problems you hit - in python, of
>course.
>See this:
>
>[EMAIL PROTECTED]:/usr/lib/python2.3$ python timeit.py -c "[4*5 for i in
>xrange(1)]"
>100 loops, best of 3: 5.5e+03 usec per loop
>[EMAIL PROTECTED]:/usr/lib/python2.3$ python timeit.py -c "[20 for i in
>xrange(1)]"
>100 loops, best of 3: 4.3e+03 usec per loop
>
>
>Now of course the longer the expressions get, the more time it costs - but
>how many long arithmetical expression of constant evaluation value do you
>have?
>
>> 
>> I agree that things like [time.time() for i in xrange(10)] shouldn't
>> be pregenerated and that the problem is more complicated as I thought.
>> 
>> But during compilation the compilor could do an anlysis of the code
>> do determine whether there are side effects or not. If the compilor
>> then would store a code in the byte code for functions that are
>> guaranteed side-effect free and only pregenerated objects generated
>> by expressions with no side-effect, some common subexpression
>> elimination could be done even in a non-functional language.
>
>This analysis would only be possible for the most primitive of examples, 
>the reason beeing that due to the dynamic features syntactically equivalent
>expressions can have totally different semantics. So its not really worth
>the effort.

IOM that doesn't mean there might not be an alternative interesting angle. E.g.,
what if we had a yield_constant (instant bf here ;-) as well as a yield.
IOW an explicit promise that the generator would always yield the same thing
for the same input args. This could potentially allow tuple(x for x in 
foo(1234))
to be pre-calculated, or marked for sticky internal caching or such, if repeat
use benefit could not be determined.  I guess we can write memoizing decorators 
now,
so how would you e.g., spell memoizing a generator expression? No end to 
probably
impractical ideas ;-)

IMO it's more a matter of RO[D]I (return on [development] investment) and
restraints on bloat than whether optimizations and other ideas are feasible.

I think practicality vs purity drives actual implementation, but purity issues
drive a lot of interesting, if not too practical, discussions. Of course, if 
someone
has the energy to become champions of their ideas, and actually implement them
for testing and evaluation, more power to them. I don't think we should beat up
on Antoon for his interest in exploring theoretical possibilities. Sometimes
a spark may fly off and provide some useful illumination. OTOH, interesting is
in the eye of the beholder ;-)

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


Re: generator expressions: performance anomaly?

2005-01-18 Thread Steven Bethard
Bengt Richter wrote:
Which make me wonder what plans there are for providing a better
mechanism than default arguments as a way of initializing local function
variables. Nested def's to create a closure with initialized values is
pretty crufty for that, IMO.
What about using a class?  Associating functions with data is pretty 
much what they're for...

Maybe extending the default argument space
with whatever comes after e.g. a triple star delimiter in the argument list,
but which wouldn't be counted as part of the normal arguments? E.g.,
def foo(x, y=123, *args, **kw, *** i=1, deftime=time.ctime()):
return x*y, kw.get('which_time')=='now' and time.ctime() or deftime
If what you want is to have i=1 and deftime=time.ctime() available 
within foo, you could do something like (untested):

class foo(object):
def __init__(self):
self.i = 1
self.deftime = time.ctime()
def __call__(self, x, y=123, *args, **kwds):
return x*y, (kw.get('which_time') == 'now'
 and time.ctime() or self.deftime)
foo = foo()
Or if you don't like 'foo = foo()', you could probably abuse the __new__ 
method (also untested):

class foo(object):
i = 1
deftime = time.ctime()
def __new__(cls, x, y=123, *args, **kwds):
return x*y, (kw.get('which_time') == 'now'
 and time.ctime() or self.deftime)
I guess my point is that if you want attribute associated with the 
function, it's often easy enough to write a class instead...

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


file copy portability

2005-01-18 Thread Bob Smith
Is shutil.copyfile(src,dst) the *most* portable way to copy files with 
Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.

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


Re: inbuilt function buffer()

2005-01-18 Thread Aldo Cortesi
Thus spake km ([EMAIL PROTECTED]):

> I which context is the inbuilt function buffer() used ? 

It's an efficiency measure. Say you have a string x. Taking
a slice of the string - x[a:a+10] - will implicitly create a
new string containing the specified data. Doing the same
using buffer - buffer(x, a, 10) - will not. Essentially,
buffer() gives you a window into a piece of contiguous data,
without the cost of making a copy of the data you want to
extract. 

To see how this might be useful, consider writing a simple
web server. The web server reads a local file into memory,
and then feeds it bit by bit to a socket until the data is
exhausted. Without using buffer, the server would have to
create a copy of each snippet of data fed to the socket.
Using buffer, however, the copies are avoided, and the data
can be consumed more efficently. The code below demonstrates
this idea in an elementary fashion  - on my system,
"takebuf" runs about twice as fast as "take".


--

#!/usr/bin/env python2.3
import time

SIZE = 1024*1024*50
data = "O"*SIZE

def take(data):
for i in range(0, SIZE, 1024):
yield data[i:i+1024]

def takebuf(data):
for i in range(0, SIZE, 1024):
yield buffer(data, i, 1024)

def main():
start = time.time()
for i in take(data):
pass
print "Plain:\t", time.time()-start

start = time.time()
for i in takebuf(data):
pass
print "Buffer:\t", time.time()-start

if __name__ == "__main__":
main()






Cheers,



Aldo



-- 
Aldo Cortesi
[EMAIL PROTECTED]
http://www.nullcube.com
Off: (02) 9283 1131
Mob: 0419 492 863
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter in thread hangs on windows but not on Linux

2005-01-18 Thread Philippe C. Martin
Actually, the following link:
http://www.astro.washington.edu/owen/TkinterSummary.html
seems to say my code is illegal - so I'm now just launching a modless
window from the main thread - _seems_ to work




On Tue, 18 Jan 2005 11:45:28 +0100, Philippe C. Martin wrote:

> Hi,
> 
> I need to pop-up in a "modless" manner some windows from an existing
> Tkinter loop. The following code works OK under Linux: the second window
> opens, shows the information, and quits cleanly when destroyed. However,
> under windows, I get the second window without the content (so I hang in
> run I guess), and both the thread and the calling process hang.
> 
> Any clue ?
> 
> Thanks
> Philippe
> 
> 
> 
> 
> 
> #***
> class SC_DOCS(threading.Thread):
>   __m_smg = None
>   __m_title = None
>   def __init__(self,p_msg,p_title):
> threading.Thread.__init__(self)
> self.__m_msg = p_msg
> self.__m_title = p_title
> 
> #***
>   def run (self):
> l_r = Tk()
> l_r.title(self.__m_title)
> l_f = Frame(l_r)
> l_f.pack(side=TOP, expand=YES, fill=BOTH)
> l_st = ScrolledText(l_f)
> l_st.pack(side=TOP, expand=YES, fill=BOTH)
> l_st.insert(END,self.__m_msg)
> 
> l_r.mainloop()
> 
> 
> .
> .
> .
> 
> l_d = SC_DOCS('A MESSAGE', 'A TITLE')
> l_d.start()
> 
> 
> .
> .
> .

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


Re: script to automate GUI application (newbie)

2005-01-18 Thread McBooCzech
Try following scripting language to automating Windows GUI, it
simulates keystrokes (supports most keyboard layouts), simulates mouse
movements and clicks  and does tons of other stuff:
http://www.hiddensoft.com/autoit3/

It works nicely for me.

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


Re: generator expressions: performance anomaly?

2005-01-18 Thread Bengt Richter
On Tue, 18 Jan 2005 09:24:15 -0500, Steve Holden <[EMAIL PROTECTED]> wrote:
[...]
>You probably already know that sensible compiled language systems have 
>used constant folding since time immemorial, but Python has always 
>eschewed it. That's what comes of being a pragmatist's language: if such 
>optimizations really are required the programmer is expected to perform 
>them.
Which make me wonder what plans there are for providing a better
mechanism than default arguments as a way of initializing local function
variables. Nested def's to create a closure with initialized values is
pretty crufty for that, IMO. Maybe extending the default argument space
with whatever comes after e.g. a triple star delimiter in the argument list,
but which wouldn't be counted as part of the normal arguments? E.g.,

def foo(x, y=123, *args, **kw, *** i=1, deftime=time.ctime()):
return x*y, kw.get('which_time')=='now' and time.ctime() or deftime

Seem like a minor extension of the default-arg hack.

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


Re: Re: Fuzzy matching of postal addresses

2005-01-18 Thread Tim Churches
Andrew McLean <[EMAIL PROTECTED]> wrote:
> 
> Thanks for all the suggestions. There were some really useful pointers.
> 
> A few random points:
> 
> 1. Spending money is not an option, this is a 'volunteer' project. I'll 
> try out some of the ideas over the weekend.
> ...
> I am tempted to try an approach based on splitting the address into a 
> sequence of normalised tokens. Then work with a metric based on the 
> differences between the sequences. The simple case would look at 
> deleting tokens and perhaps concatenating tokens to make a match.

Do please have a look at the Febrl project at http://febrl.sf.net

We would be most interested to learn how well its HMM address parser works well 
for 
all those "quaint" English addresses, and its Fellegi-Sunter probabilistic 
matching 
engine should give good results on your data (or use the simpler deterministic 
engine if 
you like). Provided that your data are not too large (eg more than a few 
hundred 
thousand records), Febrl should work fairly well. We'd be pleased to get any 
feedback 
you may have.

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


Re: lambda

2005-01-18 Thread Bengt Richter
On 18 Jan 2005 13:28:00 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:

>Op 2005-01-18, Nick Coghlan schreef <[EMAIL PROTECTED]>:
>> Antoon Pardon wrote:
>>> More specific the Decimal class is mutable and usable as dict key.
>>
>> It's *meant* to be immutable though. The fact that we used __slots__ instead 
>> of 
>> __setattr__ to implement the immutability, so you *can* overwrite the slot 
>> variables if you really want to is merely an artifact of the current Python 
>> implementation.
>>
>> The limited mutability bug will disappear in Python 2.5, so it's not a good 
>> example of a 'mutable' dict key (especially given that the only way to 
>> mutate it 
>> is to modify private variables directly).
>>
>> And, as I've stated previously, if the issue of sane mutable keys in 
>> dictionaries and sets really bugs you so much - implement identity_dict and 
>> identity_set in C and lobby for their inclusion in the collections module.
>
>I'm not bugged by its absence in Python. I'm bugged by the attitude
>about them. But anyway I'm thinking about implementing a safe dictionary
>that will copy whenever it would otherwise allow the risk of mutating a
>key.
I encourage you to do it. It should be a rich learning experience.
My bet is you will discover something about the real requirements of
what you are "thinking about implementing" ;-)

IANAP, but ISTM that after a certain point, trying to get made-my-point 
satisfaction
in a thread like this is more like OCD symptomatology than n.g. dialog ;-)

>
>> On the more general point of "don't use mutable objects with non-identity 
>> based 
>> comparisons as dictionary keys", try teaching students for a while (or 
>> listen to 
>> those who have):
>
>What kind of students?
>
>I have implemented a hash table when I was a student and its
>implementation allowed the use of 'mutable' objects as a key
>without a problem. It simply always made copies when appropiate
>and didn't allow external access to the keys. So although the
>key objects were 'mutable' there was no way a user could accidently
>mutate a key.
This is word play IMO. What you describe is effectively using the mutables
to construct immutable keys for actual use, not using immutable keys. Having
the immutable (because of access restriction) constructed keys allows
you to check on their consistency with their source any time you want,
but that doesn't change the fact that you have created an alternative dictionary
implementation with immutable keys made immutable by copying and access 
restriction.
If you update your dictionary when a key no longer matches its source data, you
are just deleting an immutable-by-special-means key and entering the associated
value in association with a new immutable-by-special-means key.

I can produce OCD symptoms too ;-)

>
>So don't use a mutable as a dictionary key isn't so much a dictionary
>limitation in general but a specific limitation of the python implementation.
>
>And yes I understand, the current implenatation is the result of the
>fact that the same dictionaries are used internally for variables in
>scopes and attributes in objects and the fact that no copies are
>involved gives a boost to performance. But it could be argued that
>providing these same dictionaries with those semantics to the users
>was a premature optimisation.

If you see a sign like

   +->
   | WILD GOOSE CHASE THIS WAY->
   +->
   ||
   ||\|/
   ||=o=
   ||/|\
.`.||,..__|_,.

Do you feel that you must make sure?
The sign painter may only be indicating what his own experience was, after all.
But if it was a core developer's experience, it may be prudent to bet on 
another trail
-- unless you have an extremely interesting hunch. Then you should follow your 
passion
and have your own experience, and you may wind up being able to contribute 
something
(even if only an exclamation point on the sign ;-)

>  
>> When stating useful general principles, it is never, ever worth it to get 
>> into 
>> the quibbly little details about exceptions to the principle. If students 
>> ask, 
>> admit that they exist, but point out that the exceptions are rare, and not 
>> worth 
>> worrying about at that point in their learning.
>
>But don't use mutable keys is not a general principle. It is a principle
>introduced by the limitations of the python implementations.
That is so in your mind, and it is so given certain interpretations of the words
you are using, but to others "mutable keys" may be a contradiction in terms, 
because
they do not use the words in the same sense as you. If you can't see 
alternative conceptual
constructs you are stuck, and if we can't agree on the meaning of words for a 
given dialog,
we won't be communicating very well. The difficulty is getting people to 
recognize their
implicit assumptions and definitions ;-)

>
>I don't like it when a good rule of thumb because of implementation
>limitations is sold as a general

Re: Assigning to self

2005-01-18 Thread Jeff Shannon
Marc 'BlackJack' Rintsch wrote:
Frans Englich wrote:
Then I have some vague, general questions which perhaps someone can reason 
from: what is then the preferred methods for solving problems which requires 
Singletons?
As already mentioned it's similar to a global variable.  If I need a
"Singleton" I just put it as global into a module.  Either initialize it
at module level or define a function with the content of your __init__().
If one is determined to both use a Singleton and avoid having a plain 
module-global variable, one could (ab)use function default parameters:

class __Foo:
"I am a singleton!"
pass
def Foo(foo_obj = __Foo()):
assert isinstance(foo_obj, __Foo
return foo_obj
Of course, this suffers from the weakness that one might pass an 
object as an argument to the factory function and thus temporarily 
override the Singleton-ness of __Foo... but a determined programmer 
will work around any sort of protection scheme anyhow. ;)

In general, ISTM that if one wants a Singleton, it's best to create it 
via a factory function (even if that function then masquerades as a 
class).  This gives you pretty good control over the circumstances in 
which your Singleton will be created and/or retrieved, and it also 
makes it trivial to replace the Singleton with some other pattern 
(such as, e.g., a Flyweight or Borg object) should the need to 
refactor arise.

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fuzzy matching of postal addresses

2005-01-18 Thread John Roth
"Andrew McLean" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
Thanks for all the suggestions. There were some really useful pointers.
A few random points:
1. Spending money is not an option, this is a 'volunteer' project. I'll 
try out some of the ideas over the weekend.

2. Someone commented that the data was suspiciously good quality. The data 
sources are both ones that you might expect to be authoritative. If you 
use as a metric, having a correctly formatted and valid postcode, in one 
database 100% the records do in the other 99.96% do.

3. I've already noticed duplicate addresses in one of the databases.
4. You need to be careful doing an endswith search. It was actually my 
first approach to the house name issue. The problem is you end up matching 
"12 Acacia Avenue, ..." with "2 Acacia Avenue, ...".

I am tempted to try an approach based on splitting the address into a 
sequence of normalised tokens. Then work with a metric based on the 
differences between the sequences. The simple case would look at deleting 
tokens and perhaps concatenating tokens to make a match.
It's been a while since I did this stuff. The trick in dealing
with address normalization is to parse the string backwards,
and try to slot the pieces into the general pattern.
In your case, the postal code,  district (is that what it's called
in the UK?) and city seem to be fine, it's when you get to the
street (with or without house number), building name and flat
or room number that there's a difficulty.
We always had a list of keywords that could be trusted
to be delimiters. In your examples, "the" should be pretty
reliable in indicating a building name. Of course, that might
have some trouble with Tottering on the Brink.
John Roth
--
Andrew McLean 
--
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous multiple requests to very simple database

2005-01-18 Thread Thomas Bartkus
"Eric S. Johansson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> 99.9 percent of what I do (and I suspect this could be true for others)
> could be satisfied by a slightly enhanced super dictionary with a record
> level locking.

BUT - Did you not mention! :
> Estimated number of records will be in the ballpark of 50,000 to
100,000 in his
> early phase and 10 times that in the future.  Each record will run
about
> 100 to 150 bytes.
.
And
> The very large dictionary must be accessed from
> multiple processes simultaneously

And
   > I need to be able to lock records
   > within the very large dictionary when records are written to

And
   > although I must complete processing in less than 90 seconds.

And - the hole in the bottom of the hull -
   all of the above using "a slightly enhanced super dictionary".

*Super* dictionary??? *Slightly* enhanced???
Have you attempted any feasability tests?  Are you running a Cray?

There are many database systems available, and Python (probably) has free
bindings to every one of them.  Whichever one might choose, it would add
simplicity, not complexity to what you are attempting.  The problems you
mention are precisely those that databases are meant to solve. The only
tough (impossible?) requirement you have is that you don't want to use one.

When you write that "super dictionary", be sure to post code!
I could use one of those myself.
Thomas Bartkus


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


Re: simultaneous multiple requests to very simple database

2005-01-18 Thread Eric S. Johansson
Ricardo Bugalho wrote:
On Tue, 18 Jan 2005 17:33:26 -0500, Eric S. Johansson wrote:

When I look at databases, I see a bunch of very good solutions that are
either overly complex or heavyweight on one hand and very nice and simple
but unable to deal with concurrency on the other.  two sets of point
solutions that try to stretch themselves and the developers to fit other
application contexts.

Have you considerded SQLite/pySQLite ?
yep and apparently it won't work
http://www.sqlite.org/faq.html#q7
if I had record level locking, the code would do a very common pattern like:
if record present:
 Lock record
 modify record
 release lock
else:
 create record atomically (actual method TBB)
if I read their opinion correctly, the SQL lite folks are wrong in that 
only the applications need massive concurrency.  Small applications need 
significant to massive concurrency for very tiny windows on very little 
data.

but I do appreciate the pointer.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Assigning to self

2005-01-18 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Frans Englich
wrote:

> Then I have some vague, general questions which perhaps someone can reason 
> from: what is then the preferred methods for solving problems which requires 
> Singletons?

As already mentioned it's similar to a global variable.  If I need a
"Singleton" I just put it as global into a module.  Either initialize it
at module level or define a function with the content of your __init__().

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: macros

2005-01-18 Thread Jeremy Bowers
On Tue, 18 Jan 2005 14:36:08 -0800, Jeff Shannon wrote:
> I think that this sort of thing is better to have as an explicitly 
> risky hack, than as an endorsed part of the language.  The mere fact 
> that this *is* something that one can clearly tell is working around 
> certain deliberate limitations is a big warning sign, and it makes it 
> much less likely to be used extensively.  Relatively few people are 
> going to want to use something called "bytecodehacks" in a 
> mission-critical piece of software, compared to the number who'd be 
> perfectly happy to use a language's built-in macro facilities, so at 
> least it keeps the actual usage down to a somewhat more manageable level.
> 
> To rephrase this a bit more succinctly ;) there's a big difference 
> between having no practical way to prevent something, and actually 
> encouraging it.

Hey, argument, there you are. I figured you'd work your way out somehow
without me having to type you.

:-)

The counterargument that leaps to mind is that if enough people do it,
there's a need, and that need should be met explicitly rather than with
"hacks", for the benefit of all.

Again, I emphasize my ambivalence. Are there "enough"? (It's hard to tell,
maybe if it weren't so hard more would do it.) Is the benefit big enough?
Is "the need" the need to tell people "stop juggling chainsaws!"? (In
which case I guess "the need" has been met.)

Basically, I'm willing to trust Guido overall on the grounds that he has
earned it. But I still can't help but wonder if outright dismissal isn't
missing something that could be useful and positive if Guido et al turned
their minds to it. But then, I have no idea what it may be and it may be
impossible.

Like I said, I'm torn on this one :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: macros

2005-01-18 Thread Evan Simpson
Jeremy Bowers wrote:
You know, Guido might as well give in now on the Macro issue. If he
doesn't come up with something himself, apparently we'll just hack
bytecode.
Ah, hacking bytecode isn't where it's at anymore.  These days, you use 
the compiler package and munge the AST.  Hygenic!

That said, the big brake on macros implemented either of these ways is 
the fact that the source still has to be syntactically valid python. 
You can make a macro FOOBAR that works in these ways:

  x = FOOBAR(some, arguments) # Pseudo-function
  if FOOBAR:
  a.suite # Pseudo-'if' statement
  { FOOBAR: expr } # Pseudo-throwaway dict
...but not these:
  FOOBAR:
 a.suite # Suite that explicity depends on FOOBAR for meaning
  x = a FOOBAR b # expression with pseudo-keyword
What we need is a generic suite statement, something like:
gensuite ::= [decorators] "do:" suite
...where the suite is treated like the body of an anonymous function 
that is called and discarded immediately after it is defined.  In other 
words, the code

  @f2
  do: pass
...is roughly equivalent to:
  @f2
  def (): pass
  ()
  del 
Then we could abuse the heck out of it by perverting the AST of
  @FOOBAR
  do:
stuff
That's never going to happen, tho.
Cheers,
Evan @ 4-am
--
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous multiple requests to very simple database

2005-01-18 Thread Ricardo Bugalho
On Tue, 18 Jan 2005 17:33:26 -0500, Eric S. Johansson wrote:

> When I look at databases, I see a bunch of very good solutions that are
> either overly complex or heavyweight on one hand and very nice and simple
> but unable to deal with concurrency on the other.  two sets of point
> solutions that try to stretch themselves and the developers to fit other
> application contexts.
> 

Have you considerded SQLite/pySQLite ?

-- 
Ricardo

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


python/cgi/html bug

2005-01-18 Thread Dfenestr8
Hi.

I've written a cgi messageboard script in python, for an irc chan I happen
to frequent.

Bear with me, it's hard for me to describe what the bug is. So I've
divided this post into two sections: HOW MY SCRIPTS WORKS, and WHAT THE
BUG IS.



HOW MY SCRIPT WORKS 

Basically, it's divided into two executable scripts..

One is the thread viewer, ppthread.py, which views threads. When someone
posts a new topic, for instance called "Generic new topic", it creates
a file called "Generic new topic.thread". It stores the post, and any
subsequent posts under in the thread in that file. Nice and simple I
figured.

The other executable script is the topic viewer, pptopic.py. All that does
is display the topics, by doing a "tops = os.popen('ls -c *.thread')" The
"ls -c" part reads the threads in the order in which they've been
modified, so the first item in the list is always the thread most recently
posted in. 

It then creates an html link to each of the threads ... on the page the
html looks like

foo

WHAT THE BUG IS 

The problem is when someone posts a new topic, and that topic happens to
have "" double quotes, or any other strange character, some strange
glitches occur. 

Best way to describe is to demonstrate it is go to the forum and try
it yourself. Try entering a topic with straight, ordindary characters, not
that you can re enter the thread any time you want and make new posts
under it. Then try entering a thread with new or whacky characters and see
how far you get.

http://funkmunch.net/~pirch/cgi-bin/alphaforum/pptopic.py

BTW, if you want to download the script, here it is in gzipped form
http://funkmunch.net/~pirch/pepperpot.tgz





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


Re: simultaneous multiple requests to very simple database

2005-01-18 Thread Stephen Thorne
On Tue, 18 Jan 2005 17:33:26 -0500, Eric S. Johansson <[EMAIL PROTECTED]> wrote:
> so in conclusion, my only reason for querying was to see if I was
> missing a solution.  So far, I have not found any work using because
> they add orders of magnitude more complexity than simple dbm with file
> locking.  Obviously, the simple solution has horrible performance right
> now I need simplicity implementation.
> 
> thanks for your commentary.

Maybe you can just get the best of both worlds.

Have a look at SQLObject. You can ignore the fact that underneath the
SQLObject there's a postgres (or mysql, or whatever) database, and get
OO based persistance.

SQLObject is crippled in that there are degrees of freedom that SQL
gives you that SQLObject takes away/makes hard to use, but what you're
trying to do, and what most people actually do with databases, can be
easily wrapped around with a simple, pythonic wrapper.

It even has a .createTable() function for those times when you don't
even want to log into the database.

Regards,
Stephen Thorne.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-18 Thread David Bolen
Antoon Pardon <[EMAIL PROTECTED]> writes:

> Op 2005-01-18, Simon Brunning schreef <[EMAIL PROTECTED]>:
> > On 18 Jan 2005 07:51:00 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> >> 3 mutating an item in a sorted list *does* *always* cause problems
> >
> > No, it doesn't. It might cause the list no longer to be sorted, but
> > that might or might no be a problem.
> 
> Than in the same vain I can say that mutating a key in a dictionary
> doesn't always cause problems either. Sure it may probably make a
> key unaccessible directly, but that might or might not be a problem.

Well, I'd definitely consider an inaccessible key as constituting a
problem, but I don't think that's a good analogy to the list case.

With the dictionary, the change can (though I do agree it does not
have to) interfere with proper operation of the dictionary, while a
list that is no longer sorted still functions perfectly well as a
list.  That is, I feel "problems" are more guaranteed with a
dictionary since we have affected base object behavior, whereas sorted
is not an inherent attribute of the base list type but something the
application is imposing at a higher level.

For example, I may choose to have an object type that is mutable (and
not worthy for use as a dictionary key) but maintains a logical
ordering so is sortable.  I see no problem with sorting a list of such
objects, and then walking that list to perform some mutation to each
of the objects, even if along the way the mutation I am doing results
in the items so touched no longer being in sorted order.  The act of
sorting was to provide me with a particular sequence of objects, but
aside from that fact, the list continues to perform perfectly well as
a list even after the mutations - just no longer delivering objects in
sorted order.

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


Re: Fuzzy matching of postal addresses

2005-01-18 Thread Andrew McLean
Thanks for all the suggestions. There were some really useful pointers.
A few random points:
1. Spending money is not an option, this is a 'volunteer' project. I'll 
try out some of the ideas over the weekend.

2. Someone commented that the data was suspiciously good quality. The 
data sources are both ones that you might expect to be authoritative. If 
you use as a metric, having a correctly formatted and valid postcode, in 
one database 100% the records do in the other 99.96% do.

3. I've already noticed duplicate addresses in one of the databases.
4. You need to be careful doing an endswith search. It was actually my 
first approach to the house name issue. The problem is you end up 
matching "12 Acacia Avenue, ..." with "2 Acacia Avenue, ...".

I am tempted to try an approach based on splitting the address into a 
sequence of normalised tokens. Then work with a metric based on the 
differences between the sequences. The simple case would look at 
deleting tokens and perhaps concatenating tokens to make a match.

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


Re: macros

2005-01-18 Thread Jeff Shannon
Jeremy Bowers wrote:
On Tue, 18 Jan 2005 12:59:07 -0800, Robert Brewer wrote:
You know, Guido might as well give in now on the Macro issue. If he
doesn't come up with something himself, apparently we'll just hack
bytecode. I'm not sure that's a gain. 
I think that this sort of thing is better to have as an explicitly 
risky hack, than as an endorsed part of the language.  The mere fact 
that this *is* something that one can clearly tell is working around 
certain deliberate limitations is a big warning sign, and it makes it 
much less likely to be used extensively.  Relatively few people are 
going to want to use something called "bytecodehacks" in a 
mission-critical piece of software, compared to the number who'd be 
perfectly happy to use a language's built-in macro facilities, so at 
least it keeps the actual usage down to a somewhat more manageable level.

To rephrase this a bit more succinctly ;) there's a big difference 
between having no practical way to prevent something, and actually 
encouraging it.

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


How to fill available screen size then scroll

2005-01-18 Thread Mudcat
Hi all,

I am writing a gui that expands depending on the number of interefaces
a user decides to use with Win 2k, Tkinter, and Pmw.

So with normal use the gui window will expand to the screen size and
then clip without scrolling. If I use Pmw.ScrolledFrame, the clipping
frame is set based on the size of the first child frame and never
expands to fill the screen. It just expands the size of the inside
frame inside the clipping frame.

I need a tweener solution. I need the gui to expand until it reaches
the width of the available viewing screen. THEN the scroll bar kicks in
with a clipping frame the width of the screen to allow the user to see
as many interfaces as possible.
Does anyone know how to do this?

Thanks ahead of time,
Marc

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


Re: simultaneous multiple requests to very simple database

2005-01-18 Thread Eric S. Johansson
Thomas Bartkus wrote:
"Eric S. Johansson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

at this point, I know they will be some kind souls suggesting various
SQL solutions.  While I appreciate the idea, unfortunately I do not have
time to puzzle out yet another component.  Someday I will figure it out
because I really liked what I see with SQL lite but unfortunately, today
is not that day (unless they will give me their work, home and cell
phone numbers so I can call when I am stuck. ;-)

Forgive me if this reply sounds a bit glib. But I do mean it without malice.
understood and taken in that spirit.
Do you seriously expect to write your own (database) solution and that this
will save you time and effort over learning an existing (SQL) solution?
Because -
If you are seeking to "save time" on "puzzles", you are certainly going
about it the wrong way.
one thing I learned a long time ago was to respect the nagging voice in 
the back of my head that says "there is something wrong".  Right now 
with databases, that voice is not nagging but screaming.  So I made my 
query to try and prove that intuition wrong.  So far, that has not happened.

When I look at databases, I see a bunch of very good solutions that are 
either overly complex or heavyweight on one hand and very nice and 
simple but unable to deal with concurrency on the other.  two sets of 
point solutions that try to stretch themselves and the developers to fit 
other application contexts.

99.9 percent of what I do (and I suspect this could be true for others) 
could be satisfied by a slightly enhanced super dictionary with a record 
level locking.  but, the database world does not fit this model.  It has 
a great deal more complication then what is frequently necessary.

If I ever find the time, I will try to build such a beast probably 
around Metakit.  The only reason for reluctance is that I have spent too 
many hours tracking down concurrency problems at the OS level way to 
many years ago and so I do not create multithreaded applications lightly.

so in conclusion, my only reason for querying was to see if I was 
missing a solution.  So far, I have not found any work using because 
they add orders of magnitude more complexity than simple dbm with file 
locking.  Obviously, the simple solution has horrible performance right 
now I need simplicity implementation.

thanks for your commentary.
---eric

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


Re: extension module, thread safety?

2005-01-18 Thread David Bolen
Nick Coghlan <[EMAIL PROTECTED]> writes:

> Pierre Barbier de Reuille wrote:
> > Ok, I wondered why I didn't know these functions, but they are new
> > to Python 2.4 ( and I didn't take the time to look closely at Python
> > 2.4 as some modules I'm working with are still not available for
> > Python 2.4). But if it really allows to call Python code outside a
> > Python thread ... then I'll surely use that as soon as I can use
> > Python 2.4 :) Thanks for the hint :)
> 
> The Python 2.4 docs claim the functions were added in Python 2.3, even
> though they aren't documented in the 2.3.4 docs.
> 
> The 2.3 release PEP (PEP 283) confirms that PEP 311 (which added these
> functions) went in.

And even before that it was certainly possible to call into the Python
interpreter from a native thread using existing functions, albeit the
newer functions are more convenient (and perhaps more robust, I don't
know).

My earliest interaction with Python (~1999, while writing a module
that extended and embedded Python 1.5.2) used PyEval_AcquireThread()
and PyEval_ReleaseThread() to get access to a thread state from a
native C application thread (not initiated by the Python interpreter)
to allow me to call safely into an executing Python script upon
asynchronous data reception by the C code.

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


Re: simultaneous multiple requests to very simple database

2005-01-18 Thread Thomas Bartkus
"Eric S. Johansson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> at this point, I know they will be some kind souls suggesting various
> SQL solutions.  While I appreciate the idea, unfortunately I do not have
> time to puzzle out yet another component.  Someday I will figure it out
> because I really liked what I see with SQL lite but unfortunately, today
> is not that day (unless they will give me their work, home and cell
> phone numbers so I can call when I am stuck. ;-)


Forgive me if this reply sounds a bit glib. But I do mean it without malice.

Do you seriously expect to write your own (database) solution and that this
will save you time and effort over learning an existing (SQL) solution?

Because -
If you are seeking to "save time" on "puzzles", you are certainly going
about it the wrong way.

Best of luck
Thomas Bartkus


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


Re: Fuzzy matching of postal addresses

2005-01-18 Thread John Machin

John Machin wrote:
> Ermmm ... only remove "the" when you are sure it is a whole word.
Even
> then it's a dodgy idea. In the first 1000 lines of the nearest
address
> file I had to hand, I found these: Catherine, Matthew, Rotherwood,
> Weatherall, and "The Avenue".
>

Partial apologies: I wasn't reading Skip's snippet correctly -- he had
"THE ", I read "THE". Only "The Avenue" is a problem in the above list.
However Skip's snippet _does_ do damage in cases where the word ends in
"the". Grepping lists of placenames found 25 distinct names in UK,
including "The Mythe" and "The Wrythe".

Addendum: Given examples in the UK like "Barton in the Beans" (no
kiddin') and "Barton-on-the-Heath", replacing "-" by space seems
indicated.

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


anydbm biasing

2005-01-18 Thread Eric S. Johansson
I have a preference for gdbm when building DBM based dictionaries but 
have found I cannot count on it being there all the time.  Therefore, I 
have created this little tidbit which you call before opening your 
anydbm database to bias the preference towards gdbm instead of dbhash:

# bias DBM towards gdbm if at all possible.
def bias_anydbm():
"""bias anydbm to gdbm"""
try:
_mod = __import__("gdbm")
except ImportError:
pass
else:
# and other words, if you can import gdbm, make it the default
anydbm._defaultmod = _mod
usage:
bias_anydbm()
open_DBM = anydbm.open(DBM_path, 'c')
if you have gdbm enabled, it will use that otherwise it will default to 
the search list in anydbm.  obviously, this can be used to bias anydbm 
to meet your own preferences

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


Re: Contributor's List

2005-01-18 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> Is this mean't to only cover additional entries which were added in
> the 2nd edition, or is it also mean't to encompass entries which were
> carried over from the 1st edition as well.

The latter: it covers all entries.

> If it is both, then the editing must have been quite cut throat as I

It was indeed.  Fewer than half of the recipes in the 2nd edition are
"carried over" (with heavy edits in all cases) from the first.

> dropped from 3 entries in the 1st edition to 0 in the 2nd edition.

True, alas: your three recipes in the Distributed Processing chapter
were dropped.  Not light-heartedly, believe me.


> I can sort of understand if the intent was to get rid of entries which

It was of course not my intent to *GET RID* of anything whatsoever: I
selected all the recipes for the 1st edition, just as for the 2nd one,
and would dearly have loved to keep each and every one of them (I
wouldn't have selected them in the first place if I didn't like them).

The INTENT was to add over a couple hundred new and (I do believe)
wonderful recipes; the CONSTRAINT was that I couldn't just blithely
double the book's size.  So, the only way to make space for the new was
to ruthlessly cut much of the old, in order to limit the book's size
within reasonable boundaries.

> referenced packages which weren't regarded as mainstream. I guess
> it is only 14 years of work down the drain. ;-(

I wish you wouldn't look on it that way.  The Python Cookbook is not
intended as a validation or invalidation of any particular piece of
software -- just, if you will, as a reflection of how widespread the
current interest on it is.  Consider: _my_ own lovechild
"non-mainstream" package is gmpy, OK?  Well, I didn't put even ONE
recipe about it in either edition nor on the online Cookbook -- nor did
anybody else post recipes using it to the Cookbook, validating my belief
that it's too specialized to cover in the book.  I don't consider this
means "years of work down the drain": gmpy scratches the itch I made it
for, and occasional references to others using it are just a little
extra bonus, even if they do make my heart give a little jump of joy
each time I see one.

I think that's the spirit in which to do open-source development...


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


Re: pickling extension class

2005-01-18 Thread David M. Cooke
harold fellermann <[EMAIL PROTECTED]> writes:

> Hi all,
>
> I have a problem pickling an extension class. As written in the
> Extending/Embedding Manual, I
> provided a function __reduce__ that returns the appropreate tuple.
> This seams to work fine,
> but I still cannot pickle because of the following error:
>
>  >>> from model import hyper
>  >>> g = hyper.PeriodicGrid(4,4,1)
>  >>> g.__reduce__()
> (,(4.,4.,1.))
>  >>> import pickle
>  >>> pickle.dump(g,file("test","w"))
> Traceback (most recent call last):
>File "pickle_test.py", line 5, in ?
>  pickle.dump(g,file("test","w"))
>File "/sw/lib/python2.4/pickle.py", line 1382, in dump
>  Pickler(file, protocol, bin).dump(obj)
>File "/sw/lib/python2.4/pickle.py", line 231, in dump
>  self.save(obj)
>File "/sw/lib/python2.4/pickle.py", line 338, in save
>  self.save_reduce(obj=obj, *rv)
>File "/sw/lib/python2.4/pickle.py", line 414, in save_reduce
>  save(func)
>File "/sw/lib/python2.4/pickle.py", line 293, in save
>  f(self, obj) # Call unbound method with explicit self
>File "/sw/lib/python2.4/pickle.py", line 760, in save_global
>  raise PicklingError(
> pickle.PicklingError: Can't pickle : it's
> not found as hyper.PeriodicGrid
>  >>> dir(hyper)
> ['Dir', 'Neighbors', 'PeriodicGrid', 'PeriodicPos', '__doc__',
> '__file__', '__name__', 'refcount']
>  >>> hyper.PeriodicGrid
> 
 ^

I think that's your error. The extension type is declared to be
hyper.PeriodicGrid, where it actually is model.hyper.PeriodicGrid
(because hyper is in the model package).

Pickle stores g.__class__.__module__ (which is "hyper") and
g.__class__.__name__ (="PeriodicGrid") to find the class object for
reimporting, and on unpickling, tries to do __import__("hyper"), which
fails.

The tp_name slot of your extension type should be "model.hyper.PeriodicGrid".

-- 
|>|\/|<
/--\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list


macros (was: RE: generator expressions: performance anomaly?)

2005-01-18 Thread Jeremy Bowers
On Tue, 18 Jan 2005 12:59:07 -0800, Robert Brewer wrote:
> Especially since you can already do it explicitly with Raymond
> Hettinger's cookbook recipe:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940

You know, Guido might as well give in now on the Macro issue. If he
doesn't come up with something himself, apparently we'll just hack
bytecode. I'm not sure that's a gain. (To be fair, I can see some
arguments that it is, so that "I'm not sure" isn't a
passive-aggressive/sarcastic snipe like most people use it in this
context; I mean it literally.)

(I expect if we ever do see them, this will be the basic argument used. I
guess you could call it Historic Inevitably. :-) )

I'm not just basing it on this one thing, I'm basing this on all the
bytecode hacks I've seen.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what would you like to see in a 2nd edition Nutshell?

2005-01-18 Thread Alex Martelli
Steven Chan <[EMAIL PROTECTED]> wrote:

> I completely agree. I'm also waiting for an advanced Python/project
> management book that helps folks out with large-scale projects.

I won't schedule that project until the Nutshell 2nd ed is substantially
done... and I'm not _promising_ I'll schedule it right afterwards;-).

> And, for the 2nd edition, may I suggest:
> - coverage of OptionParser module, which is more advanced than the
> getopt module that you discuss on page 141.

I assume you mean optparse -- that's the module; OptionParser is a class
within that module.  Yep, covering that is in the plan.

> - better Mac OS X application building coverage. Tell us how to build
> double-clickable applications.

Python in a Nutshell is a book about *cross-platform* Python.  There is
practically no *WINDOWS*-specific coverage -- 80% of the market or
whatever -- it would be absurd if there was platform-specific coverage
for a (wonderful) system that has less than 1/10th as much volume (and
much as I may be rooting for the mac mini to revolutionize the market, I
suspect it will only make a relatively small, incremental difference).

I *WISH* I could write a book about Python on the Mac -- ever since I
got my iBook, over a year ago, it's been my love and joy, and as soon as
I had to change a desktop machine I got myself a dual processor G5
PowerMac too.  However, when I proposed that idea to O'Reilly, their
reaction was a firm no -- it's too narrow a market, they think (and,
being the premier publisher for both the Mac AND Python, they should
know, if anybody does).

I don't know if this perception of O'Reilly can be changed.  If it ever
does change, I sure hope they'll call me first, to do that book...!!!


> I wish I could ask for wxPython coverage (the whole chapter on tkinter
> is useless to me), but I won't start a flame war here.

As long as Tkinter is distributed with standard Python and not
deprecated, it's unlikely that a reference work about Python can just
quietly ignore it.  If standard Python changed in this respect, I would
of course take that into account in the next following edition!-)


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


Re: Tkinter in thread hangs on windows but not on Linux

2005-01-18 Thread Philippe C. Martin
Well this is what is on the top of my script:
from Tkinter import *
import threading
from ScrolledText import *

I still hang under XP  wish I had 2K to test.

I almost sounds like tkinter does not get refresh events anymore.

I'll keep at it







On Tue, 18 Jan 2005 12:42:21 -0800, Kamilche wrote:

> This example worked for me on Windows 2000, after inserting
> 
> import threading
> from Tkinter import *
> import ScrolledText
> 
> 
> at the top.

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


Re: what would you like to see in a 2nd edition Nutshell?

2005-01-18 Thread Alex Martelli
kery <[EMAIL PROTECTED]> wrote:
   ...
> Any schedule for publication of 2nd Ed? I just bought 1st Ed.

The 2nd edition Python Cookbook appears to be on-track for PyCon (late
March) for the very first ink-on-paper -- probably April in bookstores.

The 2nd edition Python in a Nutshell is more doubtful, being just
started and all that -- OSCON is a possible target, but it's way too
early to say if I'll manage to hit it.

In both cases, the 2nd ed is meant to focus on versions 2.3 and 2.4 of
Python, while the 1st ed covered all versions up to 2.2 included.  So,
if you're still interested in using Python 2.2 or older versions, you
may want to stock up on 1st editions of Cookbook and Nutshell; if you're
only interested in 2.3 and following versions, in the case of the
Cookbook waiting 2-3 months for the 2nd ed may be worth it, while, in
the case of the Nutshell, I would definitely not recommend a far longer
and more uncertain waiting period of 7 months or more.  Moreover, the
changes in the Nutshell will be less than those in the Cookbook were:
the Cookbook has changed way more than 50% of its contents, the Nutshell
will change substantially less (according to current plans: I'll be able
to give more precise information later this year).


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


Re: script to automate GUI application (newbie)

2005-01-18 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Jim <[EMAIL PROTECTED]> wrote:
>
>It sounds like a case for the Expect program, to me.  Try Google-ing
>for "Expect".  If you are looking for a Python approach, then try
>googling for "Expect Python".
>
>Jim
>

No--that is, I find his description unambiguous in NOT allowing
for "keyboard control", which is Expect's domain.  Expect, of
any flavor, will not help.

Along with the Java-savvy solutions already mentioned, several
general-purpose record-playback tools are available for Windows.
http://wiki.tcl.tk/8813 > mentions several.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Excel module for Python

2005-01-18 Thread jean-paul
I generate a lot pseudo excel file. Just write row by row on file and
separate every cell of a row by a tab and put an .xls extension on the
file name. When you double click. It opens directly EXCEL and you have
directly the column and the row. It is easier than the CSV or SYLK
files. If you want to format it automatically you can either define a
VBA macro or use python com. 

Cheers,

Jean-Paul

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


RE: generator expressions: performance anomaly?

2005-01-18 Thread Robert Brewer
Jeremy Bowers wrote:
> On Tue, 18 Jan 2005 14:05:15 +, Antoon Pardon wrote:
> > I don't see how generating byte code for a = 9; when seeing the
> > expression a = 3 + 6, would be a problem for non-functional
> > languages.
> 
> Ultimately, the use is fairly limited; I can't imagine the 
> execution time saved would reach the time of implementation
> for weeks after a release, even aggregating across all Python
> use in the world, and "real time gained" (i.e., time useful
> to a human) would probably never add up to the
> implementation time. So why bother? That's a horrid trade off 
> when there are so many other real gains to be had.

Especially since you can already do it explicitly with Raymond
Hettinger's cookbook recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: pickling extension class

2005-01-18 Thread Alex Martelli
harold fellermann <[EMAIL PROTECTED]> wrote:
   ...
> Here it goes...:
>   OOPS, error (exceptions.ImportError): No module named hyper

So, the __import__ in pickle fails -- indeed, __import__('foo') when
'foo' ``is imported from a subpackage'' is _supposed_ to fail, as
'hyper' is not the name you SHOULD be importing.  For example,

__import__('email.Encoders')

is fine, but just

__import__('Encoders')

fails with ImportError -- there IS no toplevel module by that name!


> I have noticed that the error does not occur, when the imported module
> ('hyper') is in the same directory as the script that pickles. When it
> is imported from a subpackage (like in the code
> I sent you) it goes wrong.

If you can't fix the modulename given by your type, you can perhaps
kludge things up by (e.g.)

import the.real.hyper
sys.modules['hyper']=the.real.hyper

before you pickle; but I suspect UNpickling would fail in that case.

Using the standard library copy_reg module to register your way to
pickle and recover instances of your type might work better.


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


Re: Tkinter in thread hangs on windows but not on Linux

2005-01-18 Thread Kamilche
This example worked for me on Windows 2000, after inserting

import threading
from Tkinter import *
import ScrolledText


at the top.

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


Window capture using WM_PRINT and Python

2005-01-18 Thread arN
Hi !
I'm a Java developper and I wish to make a capture of an offscreen 
window (on WinXP). It's not possible in Java, so I use a python script 
and WM_PRINT, but it doesn't seem to work.

Could someone have a look at my script and give me any advise ?
TIA
--
Arnaud
my python script : python snap.py GraphicalContext_handle image_handle
--
snap.py :
"
import win32api, win32con, sys
win32api.SendMessage(sys.argv[2], win32con.WM_PAINT, sys.argv[3], 0)
win32api.SendMessage(sys.argv[2], win32con.WM_PRINT, sys.argv[3], 
win32con.PRF_CHILDREN | win32con.PRF_CLIENT | win32con.PRF_OWNED)
"


snippet from Snapshot.java :
"
public static Image snapshot(Composite bean) {
GC gc = new GC(bean);
final Image image = new Image (null, bean.getBounds().width, 
bean.getBounds().height);
String commmand = "python snap.py " + gc.handle + " " + image.handle;

Runtime rt = Runtime.getRuntime();
try {
Process p = rt.exec(command);
} catch (.)
gc.dispose();
return image;
}
"
--
http://mail.python.org/mailman/listinfo/python-list


Re: hex notation funtion

2005-01-18 Thread tertius
tertius wrote:
Hi,
Is there a builtin function that will enable me to display the hex 
notation of a given binary string? (example below)

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


Re: One-Shot Property?

2005-01-18 Thread Scott David Daniels
Leif K-Brooks wrote:
class CachingProperty(object):
def __init__(self, attr_name, calculate_function):
self._name = attr_name
self._calculate = calculate_function
def __get__(self, obj, type=None):
if obj is None:
return self
else:
value = self._calculate(obj)
setattr(obj, self._name, value)
return value
And example code:
 >>> class Foo(object):
... def calculate_value(self):
... print 'Calculating...'
... return 42
... foo = CachingProperty('foo', calculate_value)
...
 >>> bar = Foo()
 >>> bar.__dict__
{}
 >>> bar.foo
Calculating...
42
 >>> bar.foo # Notice that the print statement doesn't run this time
42
 >>> bar.__dict__
{'foo': 42}

To build on this for Python 2.4:
class Caches(object):
def __init__(self, calculate_function):
self._calculate = calculate_function
def __get__(self, obj, _=None):
if obj is None:
return self
value = self._calculate(obj)
setattr(obj, self._calculate.func_name, value)
return value
class Foo(object):
@Caches
def foo(self):
print 'Calculating...'
return 42
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: hex notation funtion

2005-01-18 Thread Peter Hansen
Grant Edwards wrote:
On 2005-01-18, Grant Edwards <[EMAIL PROTECTED]> wrote:
On 2005-01-18, tertius <[EMAIL PROTECTED]> wrote:

Is there a builtin function that will enable me to display the hex 
notation of a given binary string? (example below)
' '.join('%02x' % ord(b) for b in s)

Oops.  Should be:
' '.join(['%02x' % ord(b) for b in s])
The first works fine under Python 2.4, actually... you
need the list comprehension only on previous versions.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fuzzy matching of postal addresses

2005-01-18 Thread [EMAIL PROTECTED]
I think you guys are missing the point. All you would need to add to
get a 'probable match' is add another search that goes through the 10%
that didnt get matched and do a "endswith" search on the data. From the
example data you showed me, that would match a good 90% of the 10%,
leaving you with a 1% that must be hand matched. You would have to
combine this idea with Jeff Shannon's idea to make it work more
efficiently.

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


Re: hex notation funtion

2005-01-18 Thread Grant Edwards
On 2005-01-18, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2005-01-18, tertius <[EMAIL PROTECTED]> wrote:
>
>> Is there a builtin function that will enable me to display the hex 
>> notation of a given binary string? (example below)
>
> ' '.join('%02x' % ord(b) for b in s)

Oops.  Should be:

' '.join(['%02x' % ord(b) for b in s])

-- 
Grant Edwards   grante Yow!  .. Am I in a SOAP
  at   OPERA??
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pickling extension class

2005-01-18 Thread harold fellermann
On 18.01.2005, at 20:31, Alex Martelli wrote:
harold fellermann <[EMAIL PROTECTED]> wrote:
   File "/sw/lib/python2.4/pickle.py", line 760, in save_global
 raise PicklingError(
pickle.PicklingError: Can't pickle : it's
not found as hyper.PeriodicGrid
dir(hyper)
['Dir', 'Neighbors', 'PeriodicGrid', 'PeriodicPos', '__doc__',
'__file__', '__name__', 'refcount']
hyper.PeriodicGrid

So pickle complains about the class PeriodicGrid not being found in 
the
module hyper, but a dir()
proves that python can find it. Has anyone an idea what's going wrong
here?
These symptomps are pretty weird -- let's try to pin things down a bit
more.  The relevant few lines of pickle.py are:
try:
__import__(module)
mod = sys.modules[module]
klass = getattr(mod, name)
except (ImportError, KeyError, AttributeError):
raise PicklingError(
so, could you please edit your pickle.py to provide VASTLY more info,
[...]
and let us know exactly what his modified pickle.py outputs...?

Here it goes...:
 OOPS, error (exceptions.ImportError): No module named hyper
Traceback (most recent call last):
  File "pickle_test.py", line 5, in ?
pickle.dump(g,file("test","w"))
  File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 1387, 
in dump
Pickler(file, protocol, bin).dump(obj)
  File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 231, 
in dump
self.save(obj)
  File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 338, 
in save
self.save_reduce(obj=obj, *rv)
  File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 414, 
in save_reduce
save(func)
  File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 293, 
in save
f(self, obj) # Call unbound method with explicit self
  File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 765, 
in save_global
raise PicklingError(
pickle.PicklingError: Can't pickle : it's 
not found as hyper.PeriodicGrid

I have noticed that the error does not occur, when the imported module 
('hyper') is in the same directory as the script that pickles. When it 
is imported from a subpackage (like in the code
I sent you) it goes wrong.

- harold -
--
Reality is for people who lack imagination.
--
http://mail.python.org/mailman/listinfo/python-list


Re: pickling extension class

2005-01-18 Thread Alex Martelli
harold fellermann <[EMAIL PROTECTED]> wrote:

>File "/sw/lib/python2.4/pickle.py", line 760, in save_global
>  raise PicklingError(
> pickle.PicklingError: Can't pickle : it's 
> not found as hyper.PeriodicGrid
>  >>> dir(hyper)
> ['Dir', 'Neighbors', 'PeriodicGrid', 'PeriodicPos', '__doc__', 
> '__file__', '__name__', 'refcount']
>  >>> hyper.PeriodicGrid
> 
> 
> So pickle complains about the class PeriodicGrid not being found in the
> module hyper, but a dir()
> proves that python can find it. Has anyone an idea what's going wrong
> here?

These symptomps are pretty weird -- let's try to pin things down a bit
more.  The relevant few lines of pickle.py are:

try:
__import__(module)
mod = sys.modules[module]
klass = getattr(mod, name)
except (ImportError, KeyError, AttributeError):
raise PicklingError(

so, could you please edit your pickle.py to provide VASTLY more info,
say:

try:
print 'Here it goes...:'
_xx = __import__(module)
print '  __import__ says: %r' % (_xx,)
mod = sys.modules[module]
print '  in sys.modules: %r' % (mod,)
klass = getattr(mod, name)
print '  klass is: %r' % (klass,)
except (ImportError, KeyError, AttributeError), _xx:
print '  OOPS, error (%s): %s' % (_xx.__class__, _xx)
raise PicklingError(

and let us know exactly what his modified pickle.py outputs...?


Thanks,

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


Re: hex notation funtion

2005-01-18 Thread Grant Edwards
On 2005-01-18, tertius <[EMAIL PROTECTED]> wrote:

> Is there a builtin function that will enable me to display the hex 
> notation of a given binary string? (example below)

' '.join('%02x' % ord(b) for b in s)

-- 
Grant Edwards   grante Yow!  This is a NO-FRILLS
  at   flight -- hold th' CANADIAN
   visi.comBACON!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hex notation funtion

2005-01-18 Thread [EMAIL PROTECTED]
This will do it:
>>> int('1000', 2)
128
>>> hex(int('1000', 2))
'0x80'
>>>

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


Re: How to prevent the script from stopping before it should

2005-01-18 Thread python

Fredrik Lundh wrote:
> Steve Holden wrote:
>
> > You will need to import the socket module and then call
socket.setdefaulttimeout() to ensure that
> > communication with non-responsive servers results in a socket
exception that you can trap.
>
> or you can use asynchronous sockets, so your program can keep
processing
> the sites that do respond at once while it's waiting for the ones
that don't.  for
> one way to do that, see "Using HTTP to Download Files" here:
>
> http://effbot.org/zone/effnews-1.htm
>
> (make sure you read the second and third article as well)
>
Dear Fredrik Lundh,
Thank you for the link. I checked it. But I have not found an answer to
my question.
My problem is that I can not finish( sometimes) to download all pages.
Sometimes my script freezes and I can not do nothing but restart the
script from the last successfully downloaded web page. There is no
error saying that was an error. I do not know why; maybe the server is
programed to reduce the numbers of connection or there maybe  different
reasons.So, my idea was two threads. One master ,suprevising the slave
thread that would do downloading and if the slave thread stopped,
master thread would start another slave. Is it a good solution? Or is
there a better solution?
Thanks for help
Lad

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


Re: how to find site-packages path (Michael Hoffman) - use distutils

2005-01-18 Thread Philippe C. Martin
I actually target Unix and windows so pyexe won't cut it I'm afraid -
same issue with Inno.

As far as the site-package target, I don't fully understand your
relunctancy. Just as my potential users might not own a compiler, they
might not be computer proficient enough to easily understand how to
change the sys.path. So until I have found a clean cross platform
solution I'm going to have to stick to site-packages.

Best regards,

Philippe




-- 
***
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***

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


Re: how to find site-packages path (Michael Hoffman) - use distutils

2005-01-18 Thread vincent wehren
Philippe C. Martin wrote:
Why would you want to copy any *.pyc instead of compiling them on
site?

I know that sounds terrible to the open source community, 

but I do not
intend to release the source code for my product 
That's not why I asked. I'll leave the politics up to you. The thing is, 
that the path info gets cached in the *.pyc file. This may lead to 
confusing tracebacks - might they occur - when the user does not install 
to the exact same drive/path as you did.

Additionally: if you *do* want to distribute *.pyc only, I personally 
wouldn't find it terribly neat if you stuck those into the site-packages 
directory of my Python installation. I - for one - would want to know 
what kind of source code you place along *my* sys.path.

Maybe you should consider using py2exe to distribute - keeping your 
*.pyc out of the user's Python directory tree, if any, entirely. Also, 
you may want to consider using Inno Setup as deployment tool (if Windows 
is your target platform). Using distutils for a *.py-less installer 
seems pretty pointless.


Regards,
--
Vincent Wehren
- pls go to
philippecmartin.com/applications.html for my _small_ contributions :-))

Regards,
Philippe

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


Re: Print to Windows default Printer

2005-01-18 Thread Samantha
Thanks for he quick response. This is small sample code from a PSP script to 
get Exit Info of a digital image. I want to print to the printer rather than 
the screen.
---
Info = App.Do( Environment, 'ReturnImageInfo' )

print
print 'Input Device Information'
for key in InputDeviceKeys:
if OnlyExistingData == 0 or Info[key] != '':
print key, ': ', Info[key]
print

print 'Artist Information'
for key in ArtistKeys:
if OnlyExistingData == 0 or Info[key] != '':
print key, ': ', Info[key]
print
--
Is there an easy way to do it. Right now I  copy and paste to a txt file 
then print the file?
S

"Peter Hansen" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Samantha wrote:
>> I am new to Python and I am having considerable trouble trying to print 
>> (using a simple script) to the default printer rather than the screen.
>> Thanks for any help.
>
> Please show some example code, and explain in more detail
> what you are trying to do.  There are perhaps *dozens*
> of different ways to do printing under Windows, and we
> can't guess which approach you are trying, nor which
> might be suitable for your needs.
>
> -Peter 


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


Re: hex notation funtion

2005-01-18 Thread Philippe C. Martin
Would that do it?

for i in my_byte_string:
   = atoi(binascii.hexlify(i),16)

Regards,

Philippe





On Tue, 18 Jan 2005 20:43:44 +0200, tertius wrote:

> Hi,
> 
> Is there a builtin function that will enable me to display the hex 
> notation of a given binary string? (example below)
> 
> many thanks
> Tertius
> 
> 
> 
> ()  02 11 00 00 46 5A 1A 82  02 11 00 39 36 39 33 39 
> FZ.96939
> 
> 0016(0010)  36 39 33 00 0A 30 33 37  34 34 39 35 38 25 DD 01 
> 693..03744958%..

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


Re: hex notation funtion

2005-01-18 Thread Irmen de Jong
tertius wrote:
Hi,
Is there a builtin function that will enable me to display the hex 
notation of a given binary string? (example below)
Does this help:
>>> "hello".encode("hex")
'68656c6c6f'
>>> "deadbeef".decode("hex")
'\xde\xad\xbe\xef'
?
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


pickling extension class

2005-01-18 Thread harold fellermann
Hi all,
I have a problem pickling an extension class. As written in the 
Extending/Embedding Manual, I
provided a function __reduce__ that returns the appropreate tuple. This 
seams to work fine,
but I still cannot pickle because of the following error:

>>> from model import hyper
>>> g = hyper.PeriodicGrid(4,4,1)
>>> g.__reduce__()
(,(4.,4.,1.))
>>> import pickle
>>> pickle.dump(g,file("test","w"))
Traceback (most recent call last):
  File "pickle_test.py", line 5, in ?
pickle.dump(g,file("test","w"))
  File "/sw/lib/python2.4/pickle.py", line 1382, in dump
Pickler(file, protocol, bin).dump(obj)
  File "/sw/lib/python2.4/pickle.py", line 231, in dump
self.save(obj)
  File "/sw/lib/python2.4/pickle.py", line 338, in save
self.save_reduce(obj=obj, *rv)
  File "/sw/lib/python2.4/pickle.py", line 414, in save_reduce
save(func)
  File "/sw/lib/python2.4/pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
  File "/sw/lib/python2.4/pickle.py", line 760, in save_global
raise PicklingError(
pickle.PicklingError: Can't pickle : it's 
not found as hyper.PeriodicGrid
>>> dir(hyper)
['Dir', 'Neighbors', 'PeriodicGrid', 'PeriodicPos', '__doc__', 
'__file__', '__name__', 'refcount']
>>> hyper.PeriodicGrid


So pickle complains about the class PeriodicGrid not being found in the 
module hyper, but a dir()
proves that python can find it. Has anyone an idea what's going wrong 
here?

Any help appreceated,
- harold -
--
What is mind? -- Doesn't matter.
What is matter? -- Never mind!
--
--
http://mail.python.org/mailman/listinfo/python-list


hex notation funtion

2005-01-18 Thread tertius
Hi,
Is there a builtin function that will enable me to display the hex 
notation of a given binary string? (example below)

many thanks
Tertius

()  02 11 00 00 46 5A 1A 82  02 11 00 39 36 39 33 39 
FZ.96939

0016(0010)  36 39 33 00 0A 30 33 37  34 34 39 35 38 25 DD 01 
693..03744958%..
--
http://mail.python.org/mailman/listinfo/python-list


Re: Print to Windows default Printer

2005-01-18 Thread Peter Hansen
Samantha wrote:
I am new to Python and I am having considerable trouble trying to print 
(using a simple script) to the default printer rather than the screen.
Thanks for any help.
Please show some example code, and explain in more detail
what you are trying to do.  There are perhaps *dozens*
of different ways to do printing under Windows, and we
can't guess which approach you are trying, nor which
might be suitable for your needs.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Print to Windows default Printer

2005-01-18 Thread Samantha
I am new to Python and I am having considerable trouble trying to print 
(using a simple script) to the default printer rather than the screen.
Thanks for any help.
S 


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


Re: One-Shot Property?

2005-01-18 Thread John Lenton
On Tue, Jan 18, 2005 at 04:54:56PM +, Kevin Smith wrote:
> 
> I have many cases in my code where I use a property for calculating a 
> value on-demand.  Quite a few of these only need to be called once.  
> After that the value is always the same.  In these properties, I set a 
> variable in the instance as a cached value and return that value on 
> subsequent calls.  It would be nice if there was a descriptor that would 
> do this automatically.  Actually, what would be really nice is if I 
> could replace the property altogether and put the calculated value in 
> its place after the first call, but the property itself prevents me from 
> doing that.  Is this possible?

consider this:

   1 >>> class C:
   2 ... x = property(str)
   3 ... 
   4 >>> c = C()
   5 >>> c.x
   6 '<__main__.C instance at 0x4008d92c>'
   7 >>> setattr(c, 'x', c.x)
   8 >>> c.x
   9 '<__main__.C instance at 0x4008d92c>'
  10 >>> C.x
  11 
  12 >>> c.x = 2
  13 >>> 

in line 5 you see that the x property so defined works. In line 7 you
remove it, replacing it with the computed value of the property. Line
9 shows that it worked, line 11 shows that it didn't break the class,
and line 13 (through the absence of an exception) shows that it no
longer is 'special' (as it shouldn't be).

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
You can tune a piano, but you can't tuna fish.

You can tune a filesystem, but you can't tuna fish.
-- from the tunefs(8) man page


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Integration with java (Jpype vs. JPE)

2005-01-18 Thread Irmen de Jong
Joachim Boomberschloss wrote:
Option iii would also enable writing independent
packages in Python and Java, but its glue layer will
be distributed between Python and Java using Jython
and Pyro (I chose Pyro because it works in both
CPython and Jython, and can be used to communicate
between them).
Please note that currently it is not possible to use Pyro
as a server in Jython. Only as a client.
Also; last time I checked there were some bugs in the Jython
compiler that were triggered by Pyro's code (parts of it
would give a compile error).
See http://www.razorvine.net/python/PyroAndJython
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: One-Shot Property?

2005-01-18 Thread Leif K-Brooks
Kevin Smith wrote:
I have many cases in my code where I use a property for calculating a 
value on-demand.  Quite a few of these only need to be called once.  
After that the value is always the same.  In these properties, I set a 
variable in the instance as a cached value and return that value on 
subsequent calls.  It would be nice if there was a descriptor that would 
do this automatically.  Actually, what would be really nice is if I 
could replace the property altogether and put the calculated value in 
its place after the first call, but the property itself prevents me from 
doing that.
This should do it:
class CachingProperty(object):
def __init__(self, attr_name, calculate_function):
self._name = attr_name
self._calculate = calculate_function
def __get__(self, obj, type=None):
if obj is None:
return self
else:
value = self._calculate(obj)
setattr(obj, self._name, value)
return value
And example code:
>>> class Foo(object):
... def calculate_value(self):
... print 'Calculating...'
... return 42
... foo = CachingProperty('foo', calculate_value)
...
>>> bar = Foo()
>>> bar.__dict__
{}
>>> bar.foo
Calculating...
42
>>> bar.foo # Notice that the print statement doesn't run this time
42
>>> bar.__dict__
{'foo': 42}
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: Altova ... blah blah blah

2005-01-18 Thread Irmen de Jong
Altova Announcements wrote:
Altova Unveils .
[spam]
Well now, I didn't like their products very much already,
but this spam has certainly made them drop another few
steps down on my scale. Hmpf.
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: generator expressions: performance anomaly?

2005-01-18 Thread Jeremy Bowers
On Tue, 18 Jan 2005 14:05:15 +, Antoon Pardon wrote:
> I don't see how generating byte code for a = 9; when seeing the
> expression a = 3 + 6, would be a problem for non-functional
> languages.

To answer nearly every post you've made to this thread, "because Python
doesn't have the resources to program to special cases".

And as is often the case in this sort of discussion, sure, adding this
might be only a little work, but there's thousands of enhancements of the
same general work level and performance gain. So remember you're not just
espousing this particular enhancement, you're implicitly arguing for the
entire class (because there is nothing to discriminate in the argument
"this is fairly easy" between this particular feature on your mind today
and the other thousands of such features).

To address your point more specifically, you can do this subexpression
elimination to the extent that your expression is a purely functional one.
"a = 3 + 6", while written in an imperative language and setting a
variable in an imperative manner, has a "functional subexpression" "3 +
6", that has no side-effects, etc., so the compiler could reduce it if it
knew how. (In Python, that's a function call, but since you can't change
__add__ on ints, you could do this, although there's still some special
casing you're doing that will ripple unpleasantly through the code.) But
as soon as you call any sort of method or function, you're done.

Ultimately, the use is fairly limited; I can't imagine the execution time
saved would reach the time of implementation for weeks after a release,
even aggregating across all Python use in the world, and "real time
gained" (i.e., time useful to a human) would probably never add up to the
implementation time. So why bother? That's a horrid trade off when there
are so many other real gains to be had.

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


Re: One-Shot Property?

2005-01-18 Thread Daniel Dittmar
Kevin Smith wrote:
I have many cases in my code where I use a property for calculating a 
value on-demand.  Quite a few of these only need to be called once.  
After that the value is always the same.  In these properties, I set a 
variable in the instance as a cached value and return that value on 
subsequent calls.  It would be nice if there was a descriptor that would 
do this automatically.  Actually, what would be really nice is if I 
could replace the property altogether and put the calculated value in 
its place after the first call, but the property itself prevents me from 
doing that.  Is this possible?
If you use the old-fashioned __getattr__ method instead of properties. 
__getattr__ gets called only if the value can't be found in the instance 
dictionary.

def __getattr__ (self, attrname):
try:
method = getattr (self, 'calculate_' + attrname)
except AttributeError:
raise AttributeError, attrname
value = method ()
setattr (self, attrname, value)
return value
And probably also through metaclasses. And decorators.
Daniel
--
http://mail.python.org/mailman/listinfo/python-list


Re: script to automate GUI application (newbie)

2005-01-18 Thread Jim

It sounds like a case for the Expect program, to me.  Try Google-ing
for "Expect".  If you are looking for a Python approach, then try
googling for "Expect Python".

Jim

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


Re: One-Shot Property?

2005-01-18 Thread Dave Benjamin
Kevin Smith wrote:
I have many cases in my code where I use a property for calculating a 
value on-demand.  Quite a few of these only need to be called once.  
After that the value is always the same.  In these properties, I set a 
variable in the instance as a cached value and return that value on 
subsequent calls.  It would be nice if there was a descriptor that would 
do this automatically.  Actually, what would be really nice is if I 
could replace the property altogether and put the calculated value in 
its place after the first call, but the property itself prevents me from 
doing that.  Is this possible?
I was going to recommend taking a look at the "memoize" example on the 
Python wiki, but it seems to be missing at the moment. In any case, 
here's the URL:

http://www.python.org/moin/PythonDecoratorLibrary
There are also a few examples on the Cookbook, like this one:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325205
It shouldn't be too difficult to adapt this technique so that it can be 
used to create properties. I wouldn't bother replacing the property with 
an attribute unless you have a specific reason to do so (performance, 
perhaps).

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


Re: simultaneous multiple requests to very simple database

2005-01-18 Thread Eric S. Johansson
Robert Brewer wrote:
Eric S. Johansson wrote:
I have an application where I need a very simple database, 
effectively a very large dictionary.  The very large
dictionary must be accessed from multiple processes
simultaneously.  I need to be able to lock records within
the very large dictionary when records are written to.

Just to clarify, you want shared-read until a write, at which point you
want to lock just the item being written? Or would page or table locking
be acceptable at that point?
just the item/record.  I'm doing arrival rate calculations.  each record 
contains a set of arrival times and I am rewriting the record every time 
a new entry arrives.  complete page or table locking will work in the 
sense that it will prevent collisions but it will have an increasing 
impact as load and simultaneous table but not record accesses increase.

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


Re: [perl-python] 20050118 keyed list

2005-01-18 Thread Reinhold Birkenfeld
Jürgen Exner wrote:

>> © # see "perldoc perldata" for an unix-styled course.
> 
> Excuse me? Do you mind explaining where exactly perldata is "Unix-styled"?

Remember: Perl == Unix == Satan.

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


  1   2   >