pyvm - a portable python virtual machine

2005-03-06 Thread Antonio Cavallo
pyvm 1.4.9 
==
 
More batteries to your python

Introduction:

  pyvm is a relocatable python binary distribution containing
  several modules. Its main aim is to provide all this without 
  requiring root access.

Features:

  * pyqt (widget set)
  * pygtk (widget set)
  * nummarray (array and matematical)
  * pyqwt (plot widget in qt)
  * matplotlib (plot function similar tomatlab)
  * Imaging (a digital imaging library)
  * elementree (xml library)
  * and many many more.

Download:

  http://pyvm.sourceforge.net

Copyright:

  MIT for the building script,
  other licence terms apply to the singular package (see the docs) 

Author:

  Antonio Cavallo [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


convert gb18030 to utf16

2005-03-06 Thread Xah Lee
i have a bunch of files encoded in GB18030. Is there a way to convert
them to utf16 with python?

 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

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


function with a state

2005-03-06 Thread Xah Lee
is it possible in Python to create a function that maintains a variable
value?

something like this:

globe=0;
def myFun():
  globe=globe+1
  return globe

apparently it can't be done like that. I thought it can probably be
done by prefixing the variable with some package context...

the Python doc is quite stilted. Where in the python doc is a programer
supposed read about how the package/module system in Python works?
(besides the tutorial that touches it)

 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

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


Re: get textual content of a Xml element using 4DOM

2005-03-06 Thread and-google
Frank Abel Cancio Bello [EMAIL PROTECTED] wrote:

 PrettyPrint or Print return the value to the console, and i need
 keep this  value in a string variable to work with it, how can i
 do this?

The second parameter to either of these functions can be a stream
object, so you can use a StringIO to get string output:

  from StringIO import StringIO
  from xml.dom.ext import Print

  buf= StringIO()
  Print(doc, buf)
  xml= buf.getvalue()

-- 
Andrew Clover
http://www.doxdesk.com/
mailto:[EMAIL PROTECTED]

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


Re: convert gb18030 to utf16

2005-03-06 Thread and-google
Xah Lee [EMAIL PROTECTED] wrotE:

 i have a bunch of files encoded in GB18030. Is there a way to convert
 them to utf16 with python?

You will need CJKCodecs (http://cjkpython.i18n.org/), or Python 2.4,
which has them built in. Then just use them like any other codec. eg.

  f= open(path, 'rb')
  content= unicode(f.read(), 'gb18030')
  f.close()
  f= open(path, 'wb')
  f.write(content.encode('utf-16'))
  f.close()

-- 
Andrew Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

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


Re: function expression with 2 arguments

2005-03-06 Thread Leif K-Brooks
Xah Lee wrote:
if i understand correctly, forms such as
(lambda x,y:x+y)(a,b)
can only be gained thru experience? and not documented directly
anywhere in the official docs?
The official documentation can't list every possible permutation of the 
various syntactic constructs. It does explain parenthesis, the lambda 
expression, and calling syntax; the particular combination of the three 
that you're using can therefor be logically understood from the docs.
--
http://mail.python.org/mailman/listinfo/python-list


Re: function with a state

2005-03-06 Thread Patrick Useldinger
Xah Lee wrote:
globe=0;
def myFun():
  globe=globe+1
  return globe
The short answer is to use the global statement:
globe=0
def myFun():
  global globe
  globe=globe+1
  return globe
more elegant is:
globe=0
globe=myfun(globe)
def myFun(var):
  return var+1
and still more elegant is using classes and class attributes instead of 
global variables.

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


Re: function with a state

2005-03-06 Thread and-google
Xah Lee [EMAIL PROTECTED] wrote:

 is it possible in Python to create a function that maintains a
 variable value?

Yes. There's no concept of a 'static' function variable as such, but
there are many other ways to achieve the same thing.

 globe=0;
 def myFun():
   globe=globe+1
   return globe

This would work except that you have to tell it explicitly that you're
working with a global, otherwise Python sees the globe= and decides
you want 'globe' be a local variable.

  globe= 0
  def myFun():
global globe
globe= globe+1
return globe

Alternatively, wrap the value in a mutable type so you don't have to do
an assignment (and can use it in nested scopes):

  globe= [ 0 ]
  def myFun():
globe[0]+= 1
return globe[0]

A hack you can use to hide statics from code outside the function is to
abuse the fact that default parameters are calcuated at define-time:

  def myFun(globe= [ 0 ]):
globe[0]+= 1
return globe[0]

For more complicated cases, it might be better to be explicit and use
objects:

  class Counter:
def __init__(self):
  self.globe= 0
def count(self):
  self.globe+= 1
  return self.globe

  myFun= Counter().count

-- 
Andrew Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

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


Re: [ANN] WConio 1.5 Binary Installer for Python 2.4

2005-03-06 Thread Marek Kubica
Am Sat, 05 Mar 2005 20:33:22 -0600 schrieb Chris Gonnerman:

 http://newcenturycomputers.net/projects/wconio.html
I've done this before:
http://www.pythonwiki.de/PythonErweiterungen/WindowsBinaries

greets,
Marek

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


Re: using python to parse md5sum list

2005-03-06 Thread Michael Hoffman
Ben Rf wrote:
I'm new to programming and i'd like to write a program that will parse
a list produced by md5summer and give me a report in a text file on
which md5 sums appear more than once and where they are located.
This should do the trick:

import fileinput
md5s = {}
for line in fileinput.input():
md5, filename = line.rstrip().split()
md5s.setdefault(md5, []).append(filename)
for md5, filenames in md5s.iteritems():
if len(filenames)  1:
print \t.join(filenames)

Put this in md5dups.py and you can then use
md5dups.py [FILE]... to find duplicates in any of the files you
specify. They'll then be printed out as a tab-delimited list.
Key things you might want to look up to understand this:
* the dict datatype
* dict.setdefault()
* dict.iteritems()
* the fileinput module
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integer From A Float List?!?

2005-03-06 Thread Peter Otten
Michael Hoffman wrote:

 $ py24 -m timeit -s floats = map(float, range(1000)) -sfrom itertools
 import starmap, izip ints = list(starmap(int, izip(floats)))
 1000 loops, best of 3: 343 usec per loop
 
 Truly evil. Why is that faster than ints = list(imap(int, floats))?
 It is on my system.

A true performance anomaly. 

I can see how the lookup for int on every iteration may slow down [int(f)
for f in floats] with respect to map(int, floats) -- in fact the listcomp
approach becomes faster if you wrap it into a function:

def foo(int=int):
   return [int(f) for f in floats]

But where the advantage of the convoluted list(starmap(foo, izip(items))
could come from is a mystery to me. In particular, I would expect the
pre-tupling to slow down things -- which it sometimes does:

$ py24 -m timeit -st = (1,) -sdef f(a): pass f(*t)
100 loops, best of 3: 0.653 usec per loop
$ py24 -m timeit -st = 1 -sdef f(a): pass f(t)
100 loops, best of 3: 0.471 usec per loop

and sometimes doesn't:

$ py24 -m timeit -st = 1.2 int(t)
100 loops, best of 3: 0.654 usec per loop
$ py24 -m timeit -st = (1.2,) int(*t)
100 loops, best of 3: 0.657 usec per loop

Peter

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


Adding an option on the fly (Tkinter)

2005-03-06 Thread Harlin Seritt
I am making use of a Checkbutton widget. However, I would like to add
an option or method on the fly. For example I would like to bind a
filename (filename.txt) to a particular Checkbutton widget so that I
call it later as:

widget[filename]

Is this possible to do?

Thanks,

Harlin

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


Re: How do I import everything in a subdir?

2005-03-06 Thread John Roth
Dfenestr8 [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
Hi.
I have a program which I want a plugin directory for. I figured the way to
go about that would be to just add a plugin/ dir to sys.path, and import
everything in it. Then my program can just execute the main() method of
each imported plugin.
Is that a good way to go about it?
If so, how do I import everything in the plugins dir? The method raises an
error as you can see.
Read the directory and then use the __import__() method on each
entry that ends in .py, .pyc or .pyo. Filter for duplicates first or you
may be executing a single plugin more than once.
Don't bother with sys.path unless you want your plugins to be
able to import from that directory as well.
John Roth


import sys
import os
sys.path.append(plugins)
ls = os.popen(ls plugins).readlines()
for x in ls:
... plugs.append(x[0:x.rfind(.py)])
for x in plugs:
... import x
...
Traceback (most recent call last):
 File stdin, line 2, in ?
ImportError: No module named x
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can a method in one class change an object in another class?

2005-03-06 Thread Harlin Seritt
Here's what I came up with:

#objtest.py


class first:
def __init__(self):
a = 'a'
self.a = a
print self.a


def update(self):
print 'initially, a is', self.a
self.a = second(self.a)
print 'afterwards, a is', self.a.call(self.a)


class second:
def __init__(self, a):
pass


def call(self, a):
a = 'aa'
return a


if __name__ == '__main__':
app = first()
app.update() 

Not sure if this is what you are wanting though.

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


Re: Adding an option on the fly (Tkinter)

2005-03-06 Thread Diez B. Roggisch
Harlin Seritt wrote:

 I am making use of a Checkbutton widget. However, I would like to add
 an option or method on the fly. For example I would like to bind a
 filename (filename.txt) to a particular Checkbutton widget so that I
 call it later as:
 
 widget[filename]
 
 Is this possible to do?

Yes. Use dicts to store these buttons so that you can later refer to them.
-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can a method in one class change an object in another class?

2005-03-06 Thread Diez B. Roggisch
 I've got an app that creates an object in its main class (it also
 creates a GUI).  My problem is that I need to pass this object, a
 list, to a dialog that is implemented as a second class. I want to
 edit the contents of that list and then pass back the results to the
 first class.   So my question is, can a method in one class change an
 object in another class?


Sure it can. But your code shows that you suffer from a fundamental
misunderstanding on how variables and values work in python. Don't be to
worried about that, it happens to quite a few people. 

A variable in python is just a name refering to an object. So this

 a = 'a'
 b = a
 print a, b
a a


will make a and b both refer to the string 'a'. Now assigning a different
value to b will not affect the binding of a:

 b = 10
 print a, b
a 10

So that is the reason you obeserve the behaviour you've seen. Now the
question is how to accomplish your desired goal? The answer is simple:
don't rebind a value to a name - alter the value! In python, there is a
distinction between mutable objects and immutable ones. Strings and numbers
are of the latter kind, lists and dicts and objects of the former. So if we
changed our example slighly, things start working as you'd expect:

 a = ['a']
 b = a
 print a,b
['a'] ['a']
 b[0] = 10
 print a, b
[10] [10]

So if you pass the same _mutable_ object to two objects, and one of them
changes it, the other one will see the changes:

class A:
def __init__(self):
self.a_list = [0]

class B:
def __init__(self, l):
self.l = l

def foo(self):
self.l.append(100)

a = A()
b = B(a.a_list)
b.foo()
print a.a_list

- [0, 100]


There are some resources on the web that explain this in more thourough
detail - but curretntly I have trouble finding them. Search this newsgroup.
-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: locale support and 4.10

2005-03-06 Thread Michael Piotrowski
Timothy Smith [EMAIL PROTECTED] writes:

 something strange is happening, no matter what i try nothing is a 
 supported locale
 and yes it's freebsd 4.10

AFAIK, the locale support in FreeBSD 4.1 is incomplete.  Support for
LC_NUMERIC was only added in 4.6 - the release notes for 4.6 say:

  The locale support was synchronized with the code from FreeBSD
  -CURRENT. This change brings support for the LC_NUMERIC,
  LC_MONETARY, and LC_MESSAGES categories, as well as improvements to
  strftime(3), revised locale definitions, and improvement of the
  localization of many base system programs.

HTH

-- 
Michael Piotrowski, M.A.   [EMAIL PROTECTED]
Public key at http://www.dynalabs.de/mxp/pubkey.txt
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter credit card scan

2005-03-06 Thread phil
Problem, the focus is on a field which has contents
and I scan the credit card card, which is keyboard input.
The field is altered and a bunch of chars fly acroos the
field.  messy.
Ok, I can solve this in a very clumsy manner.
1. I see the first character of the scan, '%',
configure the field to show ' ' temporarily,
do a get() and after the scan is thru, restore
the contents. clumsy and messy, but ok.
The WORST PROBLEM, is if the previous contents
of the field had been selected, which it would be
if it is the first field in the payment window or
they had tabbed to the field.  The the ist char
of the scan, the '%' replaces the contents before I
can do a get().
Suggestions?
--
http://mail.python.org/mailman/listinfo/python-list


Re: function expression with 2 arguments

2005-03-06 Thread Simon Percivall
Actually, lambda forms are quite precisely documented at
http://docs.python.org/ref/lambdas.html if you feel than reading
the tutorial (specifically http://docs.python.org/tut/node6.html
section 4.7.5) is too base for you.

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


Using for... for multiple lists

2005-03-06 Thread Harlin Seritt
I am using the following code:

for i, f in filelist, self.checkbox:
   if f.get():
  print i

I am getting an error:

Exception in Tkinter callback
Traceback (most recent call last):
  File C:\Python23\lib\lib-tk\Tkinter.py, line 1345, in __call__
return self.func(*args)
  File install.py, line 123, in select_stage
for i, f in filelist, self.checkbox:
ValueError: unpack list of wrong size

Both filelist and self.checkbox are the same size (4 items btw). Is
there any way to get this done?

Thanks,

Harlin

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


Re: Adding an option on the fly (Tkinter)

2005-03-06 Thread Harlin Seritt
Would I do this like:

buttondict = {button1, name.txt}

??

Thanks,

Harlin

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


Re: Using for... for multiple lists

2005-03-06 Thread Diez B. Roggisch
 Both filelist and self.checkbox are the same size (4 items btw). Is
 there any way to get this done?

Use zip:

a, b = [1,2,3], ['a', 'b', 'c']
for i,j in zip(a,b):
print i,j

Or from itertools izip - which should be slightly more performant and less
memory consuming.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using for... for multiple lists

2005-03-06 Thread Heiko Wundram
On Sunday 06 March 2005 13:09, Harlin Seritt wrote:
 for i, f in filelist, self.checkbox:
if f.get():
   print i

Use:

for i, f in zip(filelist,self.checkbox):
bla

-- 
--- Heiko.


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

Re: Adding an option on the fly (Tkinter)

2005-03-06 Thread Diez B. Roggisch
Harlin Seritt wrote:

 Would I do this like:
 
 buttondict = {button1, name.txt}

If you want to but I guess the other way round makes more sense. And the
syntax is wrong, its supposed to be

{key : value, ...}

The point is that you can create buttons as much as you want - in a for loop
for example - but usually its important to keep _some_ reference to it so
you can alter it later - e.g. disable it. But you don't _have_ to, if you
don't want to touch it after creation. Something like this might give you
the idea:


cbs = {}
for name in filenames:
# I don't know the real expression for creating a button - but you
should, and this illustrates the idea
cb = check_button(parent, command=lambda name=name: do_something(name))
cbs[name] = cb

Later, in do_something(name), you could e.g. say:

def do_something(name):
cbs[name].config(enabled=False)

Of course this means that cbs has to be a global var. But there exist other
options of course - as part of a object or whatever. that depends on your
code.
-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can a method in one class change an object in another class?

2005-03-06 Thread Lee Harr
On 2005-03-06, Stewart Midwinter [EMAIL PROTECTED] wrote:
 I've got an app that creates an object in its main class (it also
 creates a GUI).  My problem is that I need to pass this object, a
 list, to a dialog that is implemented as a second class. I want to
 edit the contents of that list and then pass back the results to the
 first class.   So my question is, can a method in one class change an
 object in another class?

 If the answer is no, I suppose I could pass in the list as an argument
 when I create the second class, then return the contents of the list
 when I end the methods in that second class.

 alternatively, I could make the list a global variable, then it would
 be available to all classes.  I have a nagging feeling though that
 global variables are to be avoided on general principle. Is this
 correct?

 Here's a simple example app that tries to have one class change the
 object in another class.  It doesn't give the behaviour I want,
 though.


Depends a bit on who is updating who and which is
created first and which needs references to which.

Maybe like this...

 ---
 #objtest.py


class first:
def __init__(self, a):
self.a = a
print 'a initialized to', self.a
self.updater = second(self)

def update(self, a='aa'):
print 'initially, a is', self.a
self.updater.do_update(a)
print 'afterwards, a is', self.a

class second:
def __init__(self, lst):
self.lst = lst

def do_update(self, a):
self.lst.a = a


if __name__ == '__main__':
lst = first('a')
lst.update()

# or ...
dlg = second(lst)
lst.update('aaa')

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


Speeding up CGIHTTPServer

2005-03-06 Thread Johan Kohler
Hi,
I'm using CGIHTTPServer (via its test() method) to test some CGI on my
Windoze 98 box.  I find that the execution is very slow.  Is there
anything I can do to make sure I'm getting the best performance out of
CGIHTTPServer?

Thanks in advance,
Johan


Please find our disclaimer at http://www.ukzn.ac.za/disclaimer

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


Re: PEP 246 revision

2005-03-06 Thread S?bastien Boisg?rault
[EMAIL PROTECTED] (Magnus Lie Hetland) wrote in message news:[EMAIL 
PROTECTED]...
 In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:
 
 
 I had a look at the new reference implementation of PEP 246
 (Object Adaptation) and I feel uneasy with one specific point
 of this new version. I don't fully understand why it checks
 if *the type of* the protocol has a method __adapt__:
 
 ...
 # (c) then check if protocol.__adapt__ exists  likes obj
 adapt = getattr(type(protocol), '__adapt__', None)
 ...
 
 As a consequence of this change, you can't define a protocol
 as a class that implements __adapt__ anymore.
 
 How about an instance of such a class?
 
 class Protocol(object):
 def __adapt__(self, obj):
 ...
 
 If you instantiate this class, the object's type will have the
 __adapt__ attribute...
 
 This is the way it works with other special methods (i.e.
 __foo__-methods) in Python, too. Instead of looking in the object (or
 class) in question, Python checks the *type* of the object (or class).
 That's the general rule -- no reason to make an exception here. (In
 fact, there is every reason *not* to make an exception, IMO.)

Agreed. Consistency matters. But precisely because Python looks 
in the type of the object (and not the object itself), I don't 
need to explicitely check the type myself: the code 
adapt = getattr(protocol, '__adapt__') will find the method
type(protocol).__adapt__ anyway. If it doesn't exist, it will
use protocol.__adapt__ instead (right ?). Finally, the code 
adapt = getattr(protocol, '__adapt__') would work:
1. if protocol is the instance of a class that implements 
  __adapt__,
2. if protocol is a class that implements __adapt__.

 A good example of why this makes sense is the __call__ method. 
 [...]

Agreed.

 So: The scenario needn't be as complex as in your example, as long as
 you use instances instead of classes as protocols.
 
 (I guess the case could be made for using classes as protocols, but I
 suspect the case would be mainly syntactical...)

Agreed. But I'd like to use the classes directly :) ... and you're 
right it is mainly a matter of taste. I feel that a class *is* a 
kind of protocol ...

Have you read the BDFL's Python Optional Typechecking Redux ?
(http://www.artima.com/weblogs/viewpost.jsp?thread=89161)
It's usage of adapt assumes that a class is a protocol, so I
guess that it does not work with the new version of PEP 246.

Quote:

[...]
def foo(a: t1, b: t2) - t3:
your code here

This would be replaced by something like the following:

def foo__(a, b): # The original function
your code here

def foo(a, b): # Typechecking wrapper
a = __typecheck__(a, t1)
b = __typecheck__(b, t2)
r = foo__(a, b)
r = __typecheck__(r, t3)
return r
[...]

You can also implement duck typing as defined by adapt(), as follows:

from adaptation import adapt
def __typecheck__(x, T):
if adapt(x, T) is not x:
raise TypeError(...)
return x


Regards,

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


Re: GOTO (was Re: Appeal for python developers)

2005-03-06 Thread Anthra Norell



 Please 
include "goto" command in future python realeses know that proffesional 
programers doesn't like to use it,  but for me as newbie it's too hard 
to get used replacing it  with "while", "def" or other commands 
-- 
I believe the bad reputation of 'goto' goes back to 
the originators of structured programming and what they meant to say was: don't 
use goto as a quick fix for a poorly written tangle of looping constructs. It 
aggravates the tangle when the solution is to straighten it out. Had they deemed 
'goto' useless, they would have thrown it out there and then. They didn't, 
because a policy against misuse that prevents all use runs against the interests 
of those capable of avoiding the misuse on their own. Typically, elites revolt 
against dictatorial restrictions. Here, strangely, the elites afflict themselves 
voluntarily with a sort of gotophobia as a hallmark of 
professionalism. I had a period when I was 
into state machines and came up with a programming technique that started out 
with a state table in three columns. This example is a vending 
machine.

 Current 
state 
Transition 
event(s) 
Next state(s)

 WAITING FOR 
ACTION 
customer drops 
coin 
COIN HAS BEEN 
DROPPED 
customer selects beverage 
ORDER 
RECEIVED 
customer cancels 
order 
ACCOUNT CLOSURE IS 
DUE 
else 
WAITING FOR ACTION

 COIN HAS BEEN 
DROPPED 
identify 
coincredit 
account 
PAYMENT DUE IS UNKNOWN

 ORDER 
RECEIVED 
display 
selection 
PAYMENT DUE IS UNKNOWN

 PAYMENT DUE IS 
UNKNOWN 
no selection 
made 
NOTHING IS ORDERED 
payment is 
short 
PAYMENT IS 
SHORT 
else 
PAYMENT COVERS

 NOTHING IS 
ORDERED 
prompt for 
selection 
WAITING FOR ACTION

 PAYMENT IS 
SHORT 
display balance 
due 
prompt for 
payment 
WAITING FOR ACTION

 PAYMENT 
COVERS 
prompt for release action 
WAITING FOR RELEASE ACTION

 WAITING FOR RELEASE 
ACTION customer 
activates release DELIVERY IS 
DUE 
customer drops 
coin 
COIN HAS BEEN 
DROPPED 
customer selects beverage 
ORDER_RECEIVED 
customer cancels 
orderACCOUNT 
CLOSURE IS 
DUE 
else 
WAITING FOR RELEASE ACTION

 DELIVERY IS 
DUE 
release 
beverage 

debit 
account 
ACCOUNT CLOSURE IS DUE

 ACCOUNT CLOSURE IS 
DUE 
return account 
balance 
WAITING FOR ACTION
All of 
the next states reappear, no more than once each, in the first column as current 
states and so the table is consistent and exhaustive. Consistency is automatic 
regardless how big a table grows, if every new next state entered is copied 
right away into the first column where a bunch of them may accumulate, each one 
conspicuously unhandled as long as it stands alone on its line. Their order is 
irrelevant.  Converting the table into a 
program is trivial, because the table is a program. A few minor formal 
edits make it digestible for a C compiler:

 
WAITING_FOR_ACTION: 
if customer_drops_coin () 
goto 
COIN_HAS_BEEN_DROPPED; 
if customer_selects_beverage () goto 
ORDER_RECEIVED; 
if customer_cancels_order () goto 
ACCOUNT_CLOSURE_IS_DUE; 
goto WAITING_FOR_ACTION; 

 
COIN_HAS_BEEN_DROPPED: 
identify_coin 
(); 
credit_account 
(); 
goto PAYMENT_DUE_IS_UNKNOWN;

 
ORDER_RECEIVED: 
display_selection 
();goto 
PAYMENT_DUE_IS_UNKNOWN;

 
PAYMENT_DUE_IS_UNKNOWN: 
if no_selection_made 
() goto 
NOTHING_IS_ORDERED;
 
if payment_is_short 
() goto 
PAYMENT_IS_SHORT; 
goto PAYMENT_COVERS;

 
NOTHING_IS_ORDERED: 
prompt_for_selection 
();goto 
WAITING_FOR_ACTION;

 
PAYMENT_IS_SHORT: 
display_balance_due 
(); 
prompt_for_balance_due 
();goto 
WAITING_FOR_ACTION;

 
PAYMENT_COVERS: 
prompt_for_release_action ();// goto 
WAITING_FOR_RELEASE_ACTION;

 
WAITING_FOR_RELEASE_ACTION: 
if customer_activates_release () goto 
DELIVERY_IS_DUE; 
if customer_drops_coin () 
goto 
COIN_HAS_BEEN_DROPPED; 
if customer_selects_beverage () goto 
ORDER_RECEIVED; 
if customer_cancels_order () goto 
ACCOUNT_CLOSURE_IS_DUE; 
goto WAITING_FOR_RELEASE_ACTION; 


 
DELIVERY_IS_DUE: 
release_beverage ();
 
debit_account (); 
 // goto 
ACCOUNT_CLOSURE_IS_DUE;

 
ACCOUNT_CLOSURE_IS_DUE: 
return_account_balance 
();goto 
WAITING_FOR_ACTION;

An anachronism? So what? Isn't it simple, 
elegant, legible, easy to modify and expand and self-documenting on top of 
it?One advantage of this method is that legibility does not degrade as the 
complexitiy of the transition paths increases. Conditional loops do become 
increasingly difficult to follow as they nest and accumulate breaks and state 
flags, and somodifications become increasingly difficult to make. An 
upgrade simpler than the following one, on the other hand, is hard to 
imagine:

  
COIN_HAS_BEEN_DROPPED: 
identify_coin 
(); 
if coin_is_a_dud 
() 
goto HOLDING_UNWANTED_PROPERTY; // 
Newcredit_account 
(); 
goto 
PAYMENT_DUE_IS_UNKNOWN; 
 
HOLDING_UNWANTED_PROPERTY: 
reject_dud 
(); 
// 
New 
/* admonish_customer (); */ goto 
WAITING_FOR_ACTION; // 
New

I used 
this technique in C and found it useful on some occasions. I did not combine 
gotos and loops.Not all problems lend themselves to this solution, 

Re: Question of speed - Flat file DBMS

2005-03-06 Thread Ian Parker
In message [EMAIL PROTECTED], I.V. 
Aprameya Rao [EMAIL PROTECTED] writes
OK, i forgot to mention this.
The speed is a critical issue because there will be a competition and
whosever solution is faster wins the prize.
Hence will a python solution be as fast as a C++ solution??
aprameya
On 4 Mar 2005, John Machin wrote:
I.V. Aprameya Rao wrote:
 Hi

 I have to implement a flat file dbms. The basic condition is that
 relations will be given in files and i will have to run certain
select
 project join queries on those relations.

 Can someone tell me as to which language will be faster, python or
C++??
Faster to get a working app released: Python
Faster to drive you nuts: C++
Faster processing the files: My hunch is C++, but not by much. After
you've shipped your working app (in Python), you'll still have lots of
spare time to tweak up the speed -- IF it's slow, if anybody notices,
and if anybody cares -- and this newsgroup usually provides a lively
response to how do I make this faster questions.


The key to speed is disk caching.  Unless you're doing a profound amount 
of computation on your data, I doubt there'll be any significant 
difference between using Python or C++, except due to how much disk i/o 
is done by the different programs and language environments.

So cache as much as you can- read your entire database into memory if it 
will fit.  If not then try to ensure you can read your entire indices in 
memory.   Create an index for any field you'll be querying on to avoid 
having to read the entire record.  If you're dealing with massive data, 
think about indices of indices. Work on the data, or at least the 
indices. in memory.

Well, that's everything I ever learned about database design.
Regards
Ian
--
Ian Parker
--
http://mail.python.org/mailman/listinfo/python-list


How to script DOS app that doesn't use stdout

2005-03-06 Thread Gregor
There's a DOS console application I am trying to script (in Python), but it 
doesn't seem to use stdout or stderr... For example, if I redirect output 
to a file (cmd  file.txt), the output still appears on screen. 
Similarly, the output pipes returned by popen* don't catch the app's 
output. How might this app be generating its output? Any thoughts on how it 
could be captured (perhaps with something in the win32 extensions)?

Thanks,

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


Re: Can a method in one class change an object in another class?

2005-03-06 Thread Kent Johnson
Stewart Midwinter wrote:
I've got an app that creates an object in its main class (it also
creates a GUI).  My problem is that I need to pass this object, a
list, to a dialog that is implemented as a second class. I want to
edit the contents of that list and then pass back the results to the
first class.   So my question is, can a method in one class change an
object in another class?
Diez and Lee have shown you two ways to do this.
If the answer is no, I suppose I could pass in the list as an argument
when I create the second class, then return the contents of the list
when I end the methods in that second class.
This is almost what your example does, but you have made a small error. See 
below.
alternatively, I could make the list a global variable, then it would
be available to all classes.  I have a nagging feeling though that
global variables are to be avoided on general principle. Is this
correct?
Yes, it is correct.
Here's a simple example app that tries to have one class change the
object in another class.  It doesn't give the behaviour I want,
though.
---
#objtest.py
class first:
def __init__(self):
a = 'a'
self.a = a
print self.a
def update(self):
print 'initially, a is', self.a
self.a = second(self.a)
The line above is creating an instance of second and assigning it to self.a. What you want to do is 
create an instance of second, *call* it, and assign the result to self.a. So you should have
  self.a = second(self.a)(self.a)

The self.a parameter passed to second is never used. If you change 
second.__init__ to
  def __init__(self):
  pass
then the call in update() will be
  self.a = second()(self.a)
Kent
print 'afterwards, a is', self.a
class second:
def __init__(self, a):
pass
def __call__(self, a):
a = 'aa'
return a
if __name__ == '__main__':
app = first()
app.update()
thanks,
--
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tough Spawn Problem

2005-03-06 Thread Jeff Epler
By using os.spawn* and the os.P_NOWAIT, the spawn function will return
immediately, with the return value being the PID of the new process.
Later, you can use os.kill() to force the program to terminate,
os.waitpid() to retrieve the exit status if it has terminated, or you
could use the signal module to wait for SIGCHLD to be delivered at the
time the child terminates.

With os.spawn*, the child's open files (including stdin and stdout) are
the same as the parent's; using the popen2 module, you can send the
program input and capture its output too.

Here's the program I ran on Linux (Fedora Core 2 / Python 2.3) to show
that os.P_NOWAIT works fine:
import os
pid = os.spawnv(os.P_NOWAIT, /bin/sh,
[sh, -c, sleep 1; echo spawned program])
print child is pid, pid
print waitpid result is, os.waitpid(pid, 0)
and the output is
$ python /tmp/googlemike.py 
child is pid 13874
spawned program
waitpid result is (13874, 0)
the fact that spawned program is printed after child is pid N
shows that the python program continues executing while the child is
working (or, in this case, sleeping).

Jeff


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

Re: function with a state

2005-03-06 Thread Kent Johnson
Patrick Useldinger wrote:
The short answer is to use the global statement:
globe=0
def myFun():
  global globe
  globe=globe+1
  return globe
more elegant is:
globe=0
globe=myfun(globe)
def myFun(var):
  return var+1
This mystifies me. What is myfun()? What is var intended to be?
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: function with a state

2005-03-06 Thread gene . tani
and make it a singleton, viz:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52558
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531

http://www.python.org/2.2.3/descrintro.html
(scroll wayyy down)

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


Re: any Python equivalent of Math::Polynomial::Solve?

2005-03-06 Thread Cousin Stanley
| 
| Did you perhaps use a list (type(p) == type([])) for p?
| 
Alex 
  Using the coefficients in an  array  instead of a list
  was the key in the solution to my problems 
  Your other suggestions regarding floating p
  and the off-by-one error that I had with the
  polynomial degree were also included 
  The results agree with solutions from PyGSL
  as suggested by Pierre Schnizer, but seem
  to run just a bit slower on my machine 
  Thanks again for your assistance 
  The version that I tested with follows 
Stanley C. Kitching
# -
#!/usr/bin/env python
'''
NewsGroup  comp.lang.python
Date . 2005-02-27
Subject .. any Python equivalent of Math::Polynomial::Solver
Reply_By . Alex Renelt
Edited_By  Stanley c. Kitching
I'm writing a class for polynomial manipulation.
The generalization of the above code
for providing eigenvalues of a polynomial
is 
definitions 
1.) p = array( [ a_0 , a_i ,  , a_n ] )
P( x ) = \sum _{ i = 0 } ^n a_i x^i
2.) deg( p ) is its degree
3.) monic( p ) makes P monic
monic( p ) = p / p[ -1 ]
'''
import sys
import time
from numarray import *
import numarray.linear_algebra as LA
print '\n   ' , sys.argv[ 0 ] , '\n'
def report( n , this_data ) :
print 'Coefficients ..' , list_coeff[ n ]
print
print 'Roots .'
print
dt , roots = this_data
for this_item in roots :
print '%s' % this_item
print
print 'Elapsed Time  %.6f Seconds' % dt
print
print
def roots( p ) :
p = p / float( p[ -1 ] )  # monic( p )
n = len( p ) - 1  # degree of polynomial
z = zeros( ( n , n ) )
M = asarray( z , typecode = 'f8' )# typecode = c16, complex
M[ : -1 , 1 : ] = identity( n - 1 )
M[ -1 , : ] = -p[ : -1 ]
return LA.eigenvalues( M )
list_coeff = [ array( (  2. , 3. , 1. ) ) ,
   array( (  1. , 3. , 5. , 7. , 9. ) ) ,
   array( ( 10. , 8. , 6. , 4. , 2. , 1. , 2. , 4. , 6. ) ) ]
list_roots = [ ]
for these_coeff in list_coeff :
beg = time.time()
rs  = roots( these_coeff )
end = time.time()
dt  = end - beg
list_roots.append( [ dt , list( rs ) ] )
i = 0
for this_data in list_roots :
report( i , this_data )
i += 1
print
--
http://mail.python.org/mailman/listinfo/python-list


Re: function with a state

2005-03-06 Thread Reinhold Birkenfeld
Xah Lee wrote:
 is it possible in Python to create a function that maintains a variable
 value?
 
 something like this:
 
 globe=0;
 def myFun():
   globe=globe+1
   return globe

You could work with function attributes:


def myFun():
try:myFun.globe += 1
except: myFun.globe = 1

return myFun.globe

or with a default function argument:


class Dummy: pass

def myFun(globe=Dummy()):
try:globe.globe += 1
except: globe.globe = 1

return globe.globe

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


Hash of integers for use in Random module

2005-03-06 Thread Will McGugan
Hi,
If I retrieve the hash of an integer, will it always return the same 
value across platforms?

This reason I ask is that I want to produce a sequence of pseudo random 
numbers using the random module, that I can re-create later on. So I'll 
need to store the seed value, but Random.seed takes a hashable object 
rather than an integer directly.

Which brings another question to mind. Are hashes of builtin objects in 
general consistent across platforms, or are they an implementation 
detail that could change?

TIA,
Will McGugan
--
http://mail.python.org/mailman/listinfo/python-list


Re: function with a state

2005-03-06 Thread Andrew Koenig
Xah Lee [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 globe=0;
 def myFun():
  globe=globe+1
  return globe

 apparently it can't be done like that. I thought it can probably be
 done by prefixing the variable with some package context...

You can do this:

globe=0
def myFun():
global globe
globe=globe+1
return globe

The question you should ask yourself, however, is why you want to do this. 
Do you really want to tie your function to a single global variable?  Are 
you sure you will never need more than one?

For example, the function you've written represents a counter.  Are you sure 
you will never need more than one such counter?


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


Re: Hash of integers for use in Random module

2005-03-06 Thread Will McGugan
Will McGugan wrote:
Hi,
If I retrieve the hash of an integer, will it always return the same 
value across platforms?

This reason I ask is that I want to produce a sequence of pseudo random 
numbers using the random module, that I can re-create later on. So I'll 
need to store the seed value, but Random.seed takes a hashable object 
rather than an integer directly.

Which brings another question to mind. Are hashes of builtin objects in 
general consistent across platforms, or are they an implementation 
detail that could change?
*sigh* Didnt read the docs closely enough. It does say that ints and 
longs are used directly..

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


PyOpenGL issues (glutGetModifiers())

2005-03-06 Thread Timo Finnilä
Hi,
I'm having some weird issues with Python 2.4 and PyOpenGL 2.0.2.01 (and 
also with older versions).

When I call glutGetModifiers from event handler functions (set using 
glutMouseFunc, glutMotionFunc etc...), it just says:

GLUT: Warning in foo: glutCurrentModifiers: do not call outside core 
input callback.

And the return value is always zero.
This problem appeared once I installed PyOpenGL 2.0.2.01. Some older 
version did work fine otherwise, but crashed if CTRL was pressed during 
a mouse event. And oh, everything worked just fine with Python 2.3 and 
some older version of PyOpenGL.

I've already run out of ideas, so any help would be greatly appreciated.
Thanks.
--timof
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using for... for multiple lists

2005-03-06 Thread gene . tani
If sequences are not same length:

zip truncates to length of shortest input sequence

map(None, seq1, seq2) pads to length of longest seq.

(can't remember what itertools.izip() does)

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


Re: Another math problem...

2005-03-06 Thread qwweeeit
Sorry, in writing down the problem and the corresponding solution, I
made a mistake. It's evident, but anyway...

Wrong:
 #  ab *  cb = dab 35 *  26 = 936
 #   + + -  + + -   
 # ifd + chg = eaf179 + 258 = 437
 # ------
 # cih + cge = edd215 + 284 = 499


Correct:
  #  ab *  cb = dab 36 *  26 = 936
  #   + + -  + + -   
  # ifd + chg = eaf179 + 258 = 437
  # ------
  # cih + cge = edd215 + 284 = 499

(wrong 35 correct 36)

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


Re: function with a state

2005-03-06 Thread gene . tani
I believe python docs are quite *un*-stilted.  Modules and packages are
not complicated.  Read chapter 7 of the nutshell, it's only 10 pages
long.  2.3 and 2.4 didn't introduce any fundamental changes in how
modules work AFAIK

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


python -i (interactive environment)

2005-03-06 Thread Joe
When you run python -i scriptname.py after the script completes you left 
at the interactive command prompt.

Is there a way to have this occur from a running program?

In other words can I just run scriptname.py (NOT python -i scriptname.py) 
and inside of scriptname.py I decide that I want to fall back to the 
interactive prompt?

I've searched and so far the only thing I've come up with is to use pdb, but 
that is not exactly the same as the interactive prompt.

Is there any way to do it that I have missed?

Thanks. 


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


Error on xpath-ing a DOM with namespaces

2005-03-06 Thread Piet
Hello,
Via Xpath, I want to access nodes which have a namespace prefix. THe
document at hand is an Xsl-FO document. I tried the following:
from xml.dom import minidom
from xml.xpath import Evaluate
from xml import sax
parser = sax.make_parser()
parser.setFeature(sax.handler.feature_namespaces,1)
parser.setFeature(sax.handler.feature_namespace_prefixes,1)
doc = minidom.parse(fo-file.xml,parser)
#everything ok up to here
outlines = Evaluate(//fox:outline,doc.documentElement)

I get a RuntimeException in
[pythonpath]\Lib\site-packages\_xmlplus\xpath\ParsedNodeTest.py, line
168 because of an undefined namespace fox
In the xml document, the namespace fox is defined, e.g. it has been
assigned an URL via xmlns:fox. I have installed pyxml 0.83 and 4suite
1.0a3.
Since I never had to deal with namespaces before, I have no real idea
what to try next. I don't like to use the DOM functions like
getElementsByTagNameNS, because xpath is more flexible. Is this error
above caused by the employed xml tools, or have I missed something
basic about xpath and namespaces in general?
Many thanks in advance
Piet
-- 
http://mail.python.org/mailman/listinfo/python-list


Coding help...very basic

2005-03-06 Thread Igorati
I need some ideas of how to accomplish this task.
I was told that I just need to save the input in a file and make the file
searchable, nothing fancy like tying into SQL or Oracle. THis is a basic
program and help is greatly appreciated:


You've been given an assignment by your supervisor to program a small
application to monitor the current status of the cash account in the
firm's petty cash fund (the amount of cash kept on hand in the office for
incidental purchases).  The requirements for the program are to allow
users to input the amount of cash deposited, the amount of cash withdrawn
and to get a report of the balance at any given time. You will need to
also add the date of each deposit and the date of each withdrawal and
provide a date with the balance returned upon a given query. The program
should be able to provide a printed report and support a command line
query.

You are to use the object oriented properties of Python to accomplish this
task. 

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


Re: Question of speed - Flat file DBMS

2005-03-06 Thread William Park
I.V. Aprameya Rao [EMAIL PROTECTED] wrote:
 Hi
 
 I have to implement a flat file dbms. The basic condition is that 
 relations will be given in files and i will have to run certain select 
 project join queries on those relations. 
 
 Can someone tell me as to which language will be faster, python or C++??

GDBM.  It's already flat file.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
Slackware Linux -- because it works.

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


Re: how to execute Python in VIM

2005-03-06 Thread [EMAIL PROTECTED]
  map F12 Esc:!d:\python24\python.exe %CR
 
 
  but it comes with a new pop-up windowsdame~

 I'm no windows expert - but maybe pythonw.exe helps here?

I find that using pythonw.exe and the silent prefix in Vim works best
for me:

map F5 Esc:silent !pythonw.exe %CR

Regards,

Aaron

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


Re: Coding help...very basic

2005-03-06 Thread Diez B. Roggisch
Hi,

people here usually tend not to be too helpful when asked to do an obvious
homework task. So if you really want help, provide some code you've already
written and that has actual problems. Then we're glad to help. But don't
expect others to do your work.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error on xpath-ing a DOM with namespaces

2005-03-06 Thread Diez B. Roggisch
From  http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/basic-xpath


NSS = {u'wsdl': u'http://schemas.xmlsoap.org/wsdl/'}
#processorNss = namespace bindings to be used by the processor
ctx = Context(wsdl_doc, processorNss=NSS)
Evaluate(u'wsdl:description/wsdl:documentation', context=ctx)


Should give you a start.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function with a state

2005-03-06 Thread Patrick Useldinger
Kent Johnson wrote:
globe=0
globe=myfun(globe)
def myFun(var):
  return var+1

This mystifies me. What is myfun()? What is var intended to be?
myfun is an error ;-) should be myFun, of course.
var is parameter of function myFun. If you call myFun with variable 
globe, all references to var will be replaced by globe inside function 
myFun.

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


Re: python -i (interactive environment)

2005-03-06 Thread Pierre Barbier de Reuille
Very simple is you're on UNIX ...
You juste have to put at the beginnin of your file :
#!/usr/bin/python -i
And it juste does what you want :)
Pierre
Joe a écrit :
When you run python -i scriptname.py after the script completes you left 
at the interactive command prompt.

Is there a way to have this occur from a running program?
In other words can I just run scriptname.py (NOT python -i scriptname.py) 
and inside of scriptname.py I decide that I want to fall back to the 
interactive prompt?

I've searched and so far the only thing I've come up with is to use pdb, but 
that is not exactly the same as the interactive prompt.

Is there any way to do it that I have missed?
Thanks. 


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


Re: function with a state

2005-03-06 Thread Kent Johnson
Patrick Useldinger wrote:
Kent Johnson wrote:
globe=0
globe=myfun(globe)
def myFun(var):
  return var+1

This mystifies me. What is myfun()? What is var intended to be?

myfun is an error ;-) should be myFun, of course.
var is parameter of function myFun. If you call myFun with variable 
globe, all references to var will be replaced by globe inside function 
myFun.
Oh. I thought there was some deep magic here that I was missing :-)
You also have to define myFun before you call it...
def myFun(var):
  return var+1
globe = 0
...
globe = myFun(globe)
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-06 Thread Joe
Hi Pierre,

Thanks for the reply, but  I am not on Unix and it even if I was that 
solution it does not achieve the desired results.

I want the script to decide whether to fall back to the interactive prompt. 
You solution makes it ALWAYS fall back to the interactive prompt.

I want to do something like:

try:
# execute code
except MyExceptionOccurred, except_msg:
# fall to interactive prompt.

In other words I want to have my program to determine whether the 
interactive prompt to be displayed or not.

Thanks!


Pierre Barbier de Reuille [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Very simple is you're on UNIX ...

 You juste have to put at the beginnin of your file :

 #!/usr/bin/python -i

 And it juste does what you want :)

 Pierre

 Joe a écrit :
 When you run python -i scriptname.py after the script completes you 
 left at the interactive command prompt.

 Is there a way to have this occur from a running program?

 In other words can I just run scriptname.py (NOT python -i scriptname.py) 
 and inside of scriptname.py I decide that I want to fall back to the 
 interactive prompt?

 I've searched and so far the only thing I've come up with is to use pdb, 
 but that is not exactly the same as the interactive prompt.

 Is there any way to do it that I have missed?

 Thanks. 


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


Re: multiple inheritance with builtins

2005-03-06 Thread Steve Holden
Giovanni Bajo wrote:
Hello,
I noticed that bultin types like list, set, dict, tuple don't seem to adhere to
the convention of using super() in constructor to correctly allow
diamond-shaped inheritance (through MRO). For instance:

class A(object):
... def __init__(self):
... print A.__init__
... super(A, self).__init__()
...
class B(A, list):
... def __init__(self):
... print B.__init__
... super(B, self).__init__()
...
B.__mro__
(class '__main__.B', class '__main__.A', type 'list', type 'object')
B()
B.__init__
A.__init__
[]
class C(list, A):
... def __init__(self):
... print C.__init__
... super(C, self).__init__()
...
C.__mro__
(class '__main__.C', type 'list', class '__main__.A', type 'object')
C()
C.__init__
[]

It seems weird to me that I have to swap the order of bases to get the expected
behaviour. Is there a reason for this, or is it simply a bug that should be
fixed?
The documentation explicitly states that only one of the built-in types 
can be used as a base class: they aren't desinged to be mixed with each 
other.

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


IndexedCatalog and ZEO

2005-03-06 Thread Almad
Hello, 

I'm trying to use IndexedCatalog
[http://www.async.com.br/projects/IndexedCatalog/] in my CherryPy
[http://www.cherrypy.org] application. 
As Zodb support access just from one Python thread, I must either use just
one CherryPy thread (slow), or use ZEO. However, if I understand it good,
when I use 
from ZEO import ClientStorage

then ZEO is internally using FileStorage, so no IndexedCatalog is used. 

Anyone knews, how to use IndexedCatalog with ZEO, or do I have to patch
ZEO for myself (or run this one thread)? 

Thanks, 
-- 
Lukas Almad Linhart

[:: http://www.almad.net/ ::]
[:: Humans are too complicated to be described with words. ::]
[:: PGP/GNUPg key: http://www.almad.net/download/pubkey.asc ::]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: site-packages versus site-python

2005-03-06 Thread Steve Holden
msoulier wrote:
Well, broadly, the reason is that it allows version-specific code to
be
included in libraries.

I've actually found this to be a bit of a pain. I build packages
against say, python2.2, and if you upgrade python to 2.3 the package
breaks. The code works fine so saying it requires python = 2.2 should
be valid, but the version-specific path prevents that. 

Mike
Well, if you can invent a reliable mechanism for managing 
version-independent extensions I'm sure the developers will be happy to 
hear about it :-)

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-06 Thread Michael Hoffman
Joe wrote:
I want the script to decide whether to fall back to the interactive prompt. 
You solution makes it ALWAYS fall back to the interactive prompt.
Actually, using sys.exit() means the program can exit even if python -i
is used.
You can use:
import code
code.interact()
which emulates the interactive prompt.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


parsing a date string

2005-03-06 Thread MikeyG
Hi,
I have a date string in the ctime() format ('Sat Mar  5 10:38:07 2005') 
and I want to know how long ago that was in whole days.

So far I have:
import time
import datetime
age = 
(datetime.date.fromtimestamp(time.mktime(time.strptime(date.strip( - 
datetime.date.today()).days

Which is an absurd number of function calls and is possibly not even 
correct (something in the docs about mktime() taking localtime whereas 
my string is in UTC)

Any suggestions?
Thanks
MikeG
--
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-06 Thread Raymond L. Buvel
I posted the following a while back.  I think this is what you are 
looking for.

This can be done fairly easily by creating a module (lets call it
interactive) with the following code in it.
---
import sys,os
def debug_exception(type, value, traceback):
 # Restore redirected standard I/O
 sys.stdin = sys.__stdin__
 sys.stdout = sys.__stdout__
 sys.stderr = sys.__stderr__
 # Kick the interpreter into interactive mode and call the original
 # exception handler.
 os.environ['PYTHONINSPECT'] = '1'
 sys.__excepthook__(type, value, traceback)
sys.excepthook = debug_exception
---
Now if you import this module and raise an unhandled exception, you will
be in interactive mode.  In other words, I think the following script
does what you are asking for.
---
import interactive
raise RuntimeError('Interactive Mode')
---
This also has the advantage that if there are no unhandled exceptions in
your script, the script runs and terminates normally.
Enjoy,
Ray Buvel
Joe wrote:
Hi Pierre,
Thanks for the reply, but  I am not on Unix and it even if I was that 
solution it does not achieve the desired results.

I want the script to decide whether to fall back to the interactive prompt. 
You solution makes it ALWAYS fall back to the interactive prompt.

I want to do something like:
try:
# execute code
except MyExceptionOccurred, except_msg:
# fall to interactive prompt.
In other words I want to have my program to determine whether the 
interactive prompt to be displayed or not.

Thanks!
Pierre Barbier de Reuille [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

Very simple is you're on UNIX ...
You juste have to put at the beginnin of your file :
#!/usr/bin/python -i
And it juste does what you want :)
Pierre
Joe a écrit :
When you run python -i scriptname.py after the script completes you 
left at the interactive command prompt.

Is there a way to have this occur from a running program?
In other words can I just run scriptname.py (NOT python -i scriptname.py) 
and inside of scriptname.py I decide that I want to fall back to the 
interactive prompt?

I've searched and so far the only thing I've come up with is to use pdb, 
but that is not exactly the same as the interactive prompt.

Is there any way to do it that I have missed?
Thanks. 


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


Re: python -i (interactive environment)

2005-03-06 Thread MikeyG
Joe wrote:
When you run python -i scriptname.py after the script completes you left 
at the interactive command prompt.

Is there a way to have this occur from a running program?
In other words can I just run scriptname.py (NOT python -i scriptname.py) 
and inside of scriptname.py I decide that I want to fall back to the 
interactive prompt?

I've searched and so far the only thing I've come up with is to use pdb, but 
that is not exactly the same as the interactive prompt.

Is there any way to do it that I have missed?
Thanks. 


Yes you can set the PYTHONINSPECT environment variable to something 
other than an empty string from within your program.

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


A few SWIG/Python questions

2005-03-06 Thread Derek Allen
I'm using SWIG to generate glue code for my embedded/extended python app. 
There are a couple of very frustrating issues that I would like to see if 
anyone else has solutions for:

- Once I have created and initialized a module with SWIG I can call it by 
executing a python file with no problems. However I would like to be able to 
type in a single-line python function and have it execute from my module. 
One line cannot contain both import _mypackage and 
_mypackage.DoFunction(hello) (and even if it could it would be 
cumbersome). I cannot find a way to manually import (in code) the methods 
from my package prior to executing the single-line instruction. I can get 
the dictionary but that doesn't give me the methods. How do I do this?

- For some reason whatever name I give the module (via %module name) ends up 
with an underscore at its beginning - e.g., _name. I don't know why this is, 
and it was the source of some serious hair-pulling. Is there a way to turn 
this off (without recompiling the swig executable)?

- SWIG in general generates a TON of code for the glue module. Is there a 
way to reduce this?

- SWIG wraps everything with extern C, which is unnecessary for my code 
and requires me to decorate functions unnecessarily. Is there a way to turn 
this off?

Thanks. 


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


seeking tree-browser widget for use with Tkinter

2005-03-06 Thread Sean McIlroy
I'm looking for a widget, to be used with Tkinter, that displays a
tree whose leaves are strings. I thought there was something like that
in the Python Megawidgets, but when I look at the documentation
(http://pmw.sourceforge.net/doc/refindex.html), it doesn't seem to be
there. Any advice will be much appreciated.

Peace,
STM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: seeking tree-browser widget for use with Tkinter

2005-03-06 Thread Stefan Eischet
Hi Sean,
I downloaded a file called tree.py recently which has this at the top:
# Highly optimized Tkinter tree control
# by Charles E. Gene Cash email gcash at cfl.rr.com
#
# This is documented more fully on my homepage at
# http://home.cfl.rr.com/genecash/ and if it's not there, look in the 
Vaults
# of Parnassus at http://www.vex.net/parnassus/ which I promise to keep
# updated.

If you can't find it there I can mail it to you.
  Stefan
On 06.03.2005, at 21:02, Sean McIlroy wrote:
I'm looking for a widget, to be used with Tkinter, that displays a
tree whose leaves are strings. I thought there was something like that
in the Python Megawidgets, but when I look at the documentation
(http://pmw.sourceforge.net/doc/refindex.html), it doesn't seem to be
there. Any advice will be much appreciated.
Peace,
STM
--
http://mail.python.org/mailman/listinfo/python-list

-
Two of the most famous products of Berkeley are LSD and Unix.
 I dont think that this is a coincidence.
 Anonymous
--
http://mail.python.org/mailman/listinfo/python-list


Re: IndexedCatalog and ZEO

2005-03-06 Thread Leif K-Brooks
Almad wrote:
Hello, 

I'm trying to use IndexedCatalog
[http://www.async.com.br/projects/IndexedCatalog/] in my CherryPy
[http://www.cherrypy.org] application. 
As Zodb support access just from one Python thread, I must either use just
one CherryPy thread (slow), or use ZEO. However, if I understand it good,
when I use 
from ZEO import ClientStorage

then ZEO is internally using FileStorage, so no IndexedCatalog is used. 
If you're using IndexedCatalog's Shelf class, just pass it a host/port 
tuple instead of a path:

from IndexedCatalog.Shelf import Shelf
shelf = Shelf(('localhost', 1234), [Class1, Class2])
--
http://mail.python.org/mailman/listinfo/python-list


Re: yum install python2.4

2005-03-06 Thread John J. Lee
[EMAIL PROTECTED] writes:

 My goal is to install python2.4 using yum (wouldn't you know it, it's a
 dependency for something else).
[...]

You're probably better off asking on a yum or Fedora list or
newsgroup.


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


Re: Modifying Call Tips and Intellisense Behavior

2005-03-06 Thread John J. Lee
[EMAIL PROTECTED] writes:

 I like the way call tips displays argument variables for functions when
 you type the ( after the function name.  However, if one of the
 arguments to the function is something like SomeMod.attribute, the
 intellisense will display all the exposed methods and attributes when
 SomeMod. is typed.  This is fine but once I have selected the desired
 attribute and continue with entering the next argument, the original
 call tip for the function I'm working on is lost.  I think it would be
 nice if one could hit a key sequence or something to recall the last
 call tip.
 
 Are there some other python editors that have this type of behavior?
 
 If not, where should I start looking to tweak.

You haven't said what editor/IDE you're using now.


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


Re: python -i (interactive environment)

2005-03-06 Thread Joe
Thanks Michael, that's what I was looking for.

Are there any differences between that and the actual interactve prompt that 
I should be aware of?

Would you consider that a better method than using (thanks to those who 
suggested this other option):

import os
os.environ['PYTHONINSPECT'] = '1'


Michael Hoffman [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Joe wrote:

 I want the script to decide whether to fall back to the interactive 
 prompt. You solution makes it ALWAYS fall back to the interactive prompt.

 Actually, using sys.exit() means the program can exit even if python -i
 is used.

 You can use:

 import code
 code.interact()

 which emulates the interactive prompt.
 -- 
 Michael Hoffman 


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


Re: Using for... for multiple lists

2005-03-06 Thread Harlin Seritt
Actually the sequences are of the same length. Forgot to mention that.

thanks,

Harlin

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


Re: seeking tree-browser widget for use with Tkinter

2005-03-06 Thread Harlin Seritt
Actually it should be here:

http://py.vaults.ca/apyllo.py/808292924.247038364.90387689.96972321

Cheers,

Harlin

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


Re: IndexedCatalog and ZEO

2005-03-06 Thread Diez B. Roggisch
 I'm trying to use IndexedCatalog
 [http://www.async.com.br/projects/IndexedCatalog/] in my CherryPy
 [http://www.cherrypy.org] application.
 As Zodb support access just from one Python thread, I must either use just
 one CherryPy thread (slow), or use ZEO. However, if I understand it good,
 when I use
 from ZEO import ClientStorage
 
 then ZEO is internally using FileStorage, so no IndexedCatalog is used.
 
 Anyone knews, how to use IndexedCatalog with ZEO, or do I have to patch
 ZEO for myself (or run this one thread)?

I'm not sure that I fully understand your problem - the usage of
IndexedCatalog is IMHO unrelated to threading issues of zodb. And it's not
true that zodb supports only one thread. I use it in a multi-threaded
environment - as does zope. 

But it is necessary to use a separate connection object per thread. I've
written myself a transaction service alike to the java transaction api that
creates a connection for every call made to my server. In conjunction with
proxy-objects that keep a unique key for each object, I can happily access
zodb concurrently.

The basic idea is like this:

# open a zodb file storage and store a global reference
db = 

def get_root():
# the module threadlocal is from the cookbook
conn = threadlocal.get(connection, None)
if conn is None:
conn = db.open()
threadlocal[connection] = conn
return conn.root()

class Data(PersistenObject):
 my data-object. It has a property id that identifies it uniquely 
...
 
class DataProxy(object):
def __init__(self, id):
 self.id = id

def _g_data(self):
return get_root()[self.id]

data = property(_g_data)

def __getattr__(self, name):
return getattr(self.data, name)

The magic is in the get_root()-function that fetches a thread-local
connection and returns the root-object in my zodb. In my real application,
the data-object is cached as long as I'm in one transaction, so multiple
attribute accesses are faster.

I have to add that I have no expirience with zeo - so maybe that can also
solve your problems, but that will result in a local loop network access
that also slows down your application.

Regarding the usage of IndexedCatalog: It seems you can use it in
conjunction with zeo as it has no idea of whatever storage is needed - all
it does is indexing zodb objects - which you get from zeo as well. Of
course that means that you have to keep a catalog for every thread/process
that accesses the objects. Alternatively, you maybe can make the
IndexedCatalog a  zodb-stored object itself, but I'm not sure about that.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GOTO (was Re: Appeal for python developers)

2005-03-06 Thread Andrew Dalke
Paul McGuire wrote:
 At the risk of beating this into the Pythonic ground, here is a
 generator version which collapses the original nested loop into a
 single loop, so that break works just fine:

Indeed.  For some things I'm still in the pre-generator days of
Python.  If I worked at it I think I could come up with an example
that wouldn't be so easy to turn into an iterator, but that would
be not only be beating it into the ground but doing a clog dance
on top.

Andrew
[EMAIL PROTECTED]

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


Re: python -i (interactive environment)

2005-03-06 Thread Michael Hoffman
Joe wrote:
Are there any differences between that and the actual interactve prompt that 
I should be aware of?
I don't know, unfortunately.
Would you consider that a better method than using (thanks to those who 
suggested this other option):

import os
os.environ['PYTHONINSPECT'] = '1'
Actually I would do that everyone else suggested for your use case. I 
thought
about trying this method but couldn't imagine that it would actually work!
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Call Tips and Intellisense Behavior

2005-03-06 Thread pytopo

John J. Lee wrote:
 [EMAIL PROTECTED] writes:

  I like the way call tips displays argument variables for functions
when
  you type the ( after the function name.  However, if one of the
  arguments to the function is something like SomeMod.attribute,
the
  intellisense will display all the exposed methods and attributes
when
  SomeMod. is typed.  This is fine but once I have selected the
desired
  attribute and continue with entering the next argument, the
original
  call tip for the function I'm working on is lost.  I think it would
be
  nice if one could hit a key sequence or something to recall the
last
  call tip.
 
  Are there some other python editors that have this type of
behavior?
 
  If not, where should I start looking to tweak.

 You haven't said what editor/IDE you're using now.


 John

I'm using Pythonwin editor now but I have also looked at SPE (Stani),
PyAlaCarte.  I tried to get Eric3 but never could get the Qt stuff to
work.

All seem to handle calltips and intellisense slightly different but all
seem forget the base funcion call tip once another call tip or
intellisense is displayed while filling in the arguments.

I guess I would like to use the Pythonwin editor but I'm not against
other editors if they can be made to work the way I described.

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


Re: seeking tree-browser widget for use with Tkinter

2005-03-06 Thread TZOTZIOY
On 6 Mar 2005 12:02:42 -0800, rumours say that [EMAIL PROTECTED] (Sean
McIlroy) might have written:

I'm looking for a widget, to be used with Tkinter, that displays a
tree whose leaves are strings. I thought there was something like that
in the Python Megawidgets, but when I look at the documentation
(http://pmw.sourceforge.net/doc/refindex.html), it doesn't seem to be
there. Any advice will be much appreciated.

Have you got Idle on your computer?  Search the idlelib directory for the
TreeWidget.py file.
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using python to parse md5sum list

2005-03-06 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], James Stroud
wrote:

 If you are using md5sum, tou can grab the md5 and the filename like such:
 
 myfile = open(filename)
 md5sums = []
 for aline in myfile.readlines():
   md5sums.append(aline[:-1].split(  ,1))

  md5sums.append(aline[:-1].split(None, 1))

That works too if md5sum opened the files in binary mode which is the
default on Windows.  The filename is prefixed with a '*' then, leaving
just one space between checksum and filename.

 myfile.close()

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


Re: python -i (interactive environment)

2005-03-06 Thread Reinhold Birkenfeld
Michael Hoffman wrote:
 Joe wrote:
 
 Are there any differences between that and the actual interactve prompt that 
 I should be aware of?
 
 I don't know, unfortunately.
 
 Would you consider that a better method than using (thanks to those who 
 suggested this other option):
 
 import os
 os.environ['PYTHONINSPECT'] = '1'
 
 Actually I would do that everyone else suggested for your use case. I thought
 about trying this method but couldn't imagine that it would actually work!

Actually, using this behavior is encouraged by the developers. See this
comment in Modules/main.c:

   /* Check this environment variable at the end, to give programs the
* opportunity to set it from Python.
*/

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


Re: python -i (interactive environment)

2005-03-06 Thread Joe
Reinhold,

Interesting.

A key difference between the two is that PYTHONINSPECT will allow you access 
to the prompt at the end of your program (assuming no sys.exit or raise 
SystemExit) but code.interact() allows you to jump into the program at any 
point.


Reinhold Birkenfeld [EMAIL PROTECTED] wrote in 
message news:[EMAIL PROTECTED]

   /* Check this environment variable at the end, to give programs the
* opportunity to set it from Python.
*/

 Reinhold 


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


Re: Appeal for python developers

2005-03-06 Thread Michael Hoffman
Christos TZOTZIOY Georgiou wrote:
Argument against your only in you can only use goto:
http://www.entrian.com/goto/
That is sick.
I'm clearly an amateur at obfuscating Python. Although my
implementation is much simpler. ;)
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Appeal for python developers

2005-03-06 Thread EP
Grant Edwards [EMAIL PROTECTED] diagnosed

 
 Troll.
 


I first checked my calendar to make sure it wasn't April 1, but some folks just 
can't wait, can they.

And another thought:  all this use of alphanumeric characters --- aren't we 
obfuscating the pure binariness we should all know and love if we want to be 
one with the CPU?

010010100111010101110011011101100110101001100110101101101001011011100110011100100110011001100110110001101011011100110011



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


Re: python -i (interactive environment)

2005-03-06 Thread Joe
Funny you said that, because I didn't even bother trying it because I didn't 
think it would work either.  I figured that python did something internally 
when it saw the -i switch.  Looks like it just checks for it when it's done 
with your code.

One difference between the two methods that I see is that when you set 
PYTHONINSPECT you don't really have to do anything else and unless 
sys.exit() or raise SystemExit is used you will get the interactive prompt.

Using code.interact you would need to wrap everything in a try/except block 
and call code.interact from there, or you could invoke it whenever you 
wanted too.  This has the advantage that you can even trap SystemExit if you 
want too.

Thanks again to everyone!


Michael Hoffman [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Joe wrote:

 Actually I would do that everyone else suggested for your use case. I 
 thought
 about trying this method but couldn't imagine that it would actually work!
 -- 
 Michael Hoffman 


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


Re: function with a state

2005-03-06 Thread Mike Meyer
Xah Lee [EMAIL PROTECTED] writes:

 the Python doc is quite stilted. Where in the python doc is a programer
 supposed read about how the package/module system in Python works?
 (besides the tutorial that touches it)

The python docs at URL: http://docs.python.org/ref/naming.html  are
perfectly clear. It explains the namespaces used when resolving
variable names, and how to subvert the standard resolution to solve
your problem.

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


Re: Appeal for python developers

2005-03-06 Thread TZOTZIOY
On Sat, 05 Mar 2005 14:32:27 +, rumours say that Michael Hoffman
[EMAIL PROTECTED] might have written:

BOOGIEMAN wrote:
 Please include goto command in future python realeses

As has been said before, you can only use goto in Python if
you are using Python with line numbers:

http://groups-beta.google.com/group/comp.lang.python/msg/98264a0daa007c46

Argument against your only in you can only use goto:

http://www.entrian.com/goto/

The relevant post was (long url):

http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/efe172a98d165a1d/4c504caf72a622a7
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


(no subject)

2005-03-06 Thread Mário Gamito
--
http://mail.python.org/mailman/listinfo/python-list


Re: Appeal for python developers

2005-03-06 Thread TZOTZIOY
On Sun, 06 Mar 2005 22:52:10 +, rumours say that Michael Hoffman
[EMAIL PROTECTED] might have written:

Christos TZOTZIOY Georgiou wrote:

 Argument against your only in you can only use goto:
 
 http://www.entrian.com/goto/

That is sick.

I'm clearly an amateur at obfuscating Python. Although my
implementation is much simpler. ;)

Your implementation was a fine hack.

Since it seems you didn't know about that joke, please read the whole thread;
after the first ha ha nice joke responses, you will notice the surprise of
people when we found out that the module was *actually working* :)
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding help...very basic

2005-03-06 Thread Igorati
Thank both for the help. I understand that I should provide code, I am
still trying to understand what to do, I don't want the work done, just
some ideas of where to go, a general layout perhaps. Thank you.

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


Re: Coding help...very basic

2005-03-06 Thread Igorati
This is just a basic of what I have so far. The time , a class I will need
and the print function.

 class Account:
 def __init__(self, initial):
 self.balance = initial
 def deposit(self, amt):
 self.balance = self.balance + amt
 def withdraw(self,amt):
 self.balance = self.balance - amt
 def getbalance(self):
 return self.balance 

import time
time.asctime()

import win32api
source_filename = log.txt 
win32api.ShellExecute (
0
print
source_filename
None
.
0)


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


[ANNOUNCE] PyKota v1.21 Final is out

2005-03-06 Thread Jerome Alet
Hi there,

I'm pleased to announce the availability of PyKota v1.21 Final.

PyKota is a Print Quota and Accounting solution for CUPS and LPRng,
available from :

  http://www.librelogiciel.com/software/PyKota/action_Presentation

PyKota's original distribution method consists in providing Official 
tarballs, DEB and RPM packages for a yearly fee of 20 US$ (minimum), 
while letting everyone download Unofficial versions of this software 
free of charge by using Subversion (aka svn)

PyKota is written in the Python language and published under the terms
of the GNU General Public License of the Free Software Foundation.

List of changes since 1.20 :



  - Support Contracts are now available from :
  
  http://www.librelogiciel.com/techsupport/
  
  - Third party administration tools like phpPykotaAdmin appeared and
begin to be useable.
  
  - Simplified installation script. Independant script to check for 
dependencies.
  
  - Integrated pre/post banners (CUPS only).
Banners can be either static files, executables, or pipes. PyKota 
includes a default tool to generate customizable banners on the 
fly with accounting information. Banners can be accounted for or
not, depending on a runtime configuration directive which can be
set on a per printer basis if needed.
  
  - The data dumper is now also available as a CGI script, and
can dump the job history into CUPS' page_log format (even when
using LPRng instead of CUPS). This allows real time integration
of other tools like phpPrintAnalyzer and the like.

  - The output of the data dumper is now independant of the database  
backend being used. This allows third party tools like phpPykotaAdmin
to integrate it easily.

  - Each user can now have an overcharging (or underchaging) factor,  
used when computing the cost of a print job.

  - Duplicate jobs can be denied automatically on a per printer basis.
  
  - Added an email gateway to allow end users to query their
quota information by mail.

  - The location of the configuration files is now configurable.  
  
  - Improved security and documentation.
  
  - Automated disconnect/reconnect in case of LDAP timeouts.
  
  - Added TLS support for LDAP.
  
  - Several new configuration directives added, see the sample configuration
file for details.
  
  - Improved --prototype command line option to edpykota : it can now
use most user/group attributes as the prototype for new users/groups.
 
  - Improved the internal Page Description Languages parsers.   

  - Turkish and Traditional Chinese translations were added.
  
  - Many bug fixes and improvements.

  - Development moved from CVS to Subversion.

  - For the first time, three people were given a developer access.
  
NB : The database's structure changed, so don't forget to run the upgrade
script if you use PostgreSQL, or to copy the new LDAP schema into your
LDAP server's schemas directory if you use LDAP.

Many Many thanks to the numerous sponsors of the project, as well
as to the following contributors :

- Matt Hyclak
- Stefan Wold
- Baris Cicek
- Tsang Yu Pong
- Marcus Flávio de Lima
- Kanakorn Horsiritham
- Wilson Roberto Afonso
- Klaus Ade Johnstad
- Jurandy Martins
- Sergio González González

The full list of features is available from :

  http://www.librelogiciel.com/software/PyKota/action_Features

Thank you for reading !

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


Re: How do I import everything in a subdir?

2005-03-06 Thread YL
Try something like this:
for x in plugs:
cmd = import %s % x
exec (cmd)


Dfenestr8 [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi.

 I have a program which I want a plugin directory for. I figured the way to
 go about that would be to just add a plugin/ dir to sys.path, and import
 everything in it. Then my program can just execute the main() method of
 each imported plugin.

 Is that a good way to go about it?

 If so, how do I import everything in the plugins dir? The method raises an
 error as you can see.

  import sys
  import os
  sys.path.append(plugins)
  ls = os.popen(ls plugins).readlines()
  for x in ls:
 ... plugs.append(x[0:x.rfind(.py)])
  for x in plugs:
 ... import x
 ...
 Traceback (most recent call last):
   File stdin, line 2, in ?
 ImportError: No module named x



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


python-dev Summary for 2005-02-01 through 2005-02-14

2005-03-06 Thread Brett C.
[The HTML version of this Summary is available at
http://www.python.org/dev/summary/2005-02-01_2005-02-14.html]

=
Summary Announcements
=
--
Giving myself a gold watch
--
As some of you may have already heard or read, I am retiring from writing the 
python-dev Summaries after sending out the March 16 - 31 summary.  It has been 
a long time coming and it required a kick in the ass (graciously supplied by 
Steve Holden) to finally make me let go of doing this and let someone else take 
over.

The joy of the Summaries has dwindled over the 2.5 years I have been doing 
this.  I was only doing them to be helpful.  But now I would rather put my time 
and effort I have for Python into coding work rather than the Summaries.  I 
would like to think I can be more productive and helpful as a programmer than a 
writer.  And so there will only be three more regular Summaries after this 
written by yours truly.

But do not worry about the Summaries dying!  When I announced this (see 
http://mail.python.org/pipermail/python-dev/2005-March/051823.html for the 
thread that led to this), three individuals stepped forward to pick up the work 
once I step down.  Steven Bethard, Tony Meyer, and Tim Lesher are being 
considered for picking up where I left off.  There is the possibility that they 
will actually write the Summaries together as a team.

As for my last Summary, expect a more expository one with my random thoughts on 
PyCon, Python, and anything else that comes to mind that I feel like using this 
space to abuse.  You have Scott David Daniels to thank for that format idea for 
my final hurrah.


Go to PyCon!

I just booked my hotel room for PyCon_.  You going to be there so I can shake 
your hand, thanking you for supporting Python?

.. _PyCon: http://www.pycon.org/
=
Summaries
=
-
Python Security Response Team founded
-
For those of you who don't know, a security hole was found in XML-RPC servers 
in the stdlib that use register_instance; details at 
http://www.python.org/security/PSF-2005-001/ .

In response to this, Guido has now formed the 'Python Security Response Team`_. 
 This group's job is to respond to any and all security issues that come up as 
quickly as possible and to issue a patch in a timely fashion.

.. _Python Security Response Team: http://www.python.org/security/
Contributing threads:
  - `Wanted: members for Python Security Response Team 
http://mail.python.org/pipermail/python-dev/2005-February/051414.html`__

--
Licensing issues in the stdlib
--
It was reported to python-dev that 'profiler' and 'md5 do not conform to the 
Debian Free Software Guidelines.  The specific issue was derived works using 
Python.  This is obviously not a good thing.

Things are in the works, though.  The hope is to get the copyrights signed over 
and all of this cleared up.  At worst the modules will be replaced with code 
licensed to the Python Software Foundation.  If you care to accelerate this by 
writing replacements please do so.

Contributing threads:
  - `license issues with profiler.py and md5.h/md5c.c 
http://mail.python.org/pipermail/python-dev/2005-February/051450.html`__

---
Replacing list of constants with tuple of constants
---
note: written by Tim Lesher
Skip Montanaro noticed that Raymond Hettinger had made a number of
library checkins replacing lists with tuples in constructs like ``for
a in [1, 2, 3]:`` and ``if a in [1, 2, 3]:``.  He agreed with the
motivation (the peephole optimizer can convert a tuple of constants
into a single constant, eliminating construction time), but questioned
hardcoding the optimization.  Instead, he suggested teaching the
optimizer about throwaway lists in ``for`` and ``if`` statements.
Guido agreed with the sentiment.  Raymond accepted the suggestion, and
checked in code to implement it.  There were some issues, though, but those 
will be covered in the next Summary.

Contributing threads:
  - `list of constants - tuple of constants 
http://mail.python.org/pipermail/python-dev/2005-February/051442.html`__

---
Complex I/O problem
---
note: written by Tim Lesher
Neal Becker asked why the result of printing a complex number is not an
acceptable input to constructing a complex.  For example, ``print
complex(2,2)`` yields ``'(2+2j)'``; but ``complex('(2+2j)')`` throws a
ValueError.
A. M. Kuchling responded that many types, including 'str' and
'file' share this behavior, and that in any event, parsing string
representations is a job more suited to 'eval' than to classes
themselves.
Guido `reiterated the rules`_ for str() (used by 'print') and
repr(). Since both complex.__str__ and 

Fork on windows

2005-03-06 Thread Dave Lajoie



Hello Guys,
 I am new to the list and to 
Python.
 I have been reading Oreilly's 
Python book and some web page on child process creation
 using Python.

Basically, on windows, I want to start a process 
and monitor its stdout and stderror.
I have looked at os.py from python lib directory, 
and it explicitly requires fork to be present
to "publish" os.open3

e.g.: AttributeError: 'module' object has no 
attribute 'open3'

if I can't use os.open methods, is there another 
solution to trigger an exec file and monitor its 
stdout/stderr?
Sorry if the question was asked. I have done 
several unsuccessful web search to have a 
definitive answer.

Obviously I would like the same code to run on both 
windows and linux, whenever possible
I try to stay away from window specific code, but I 
fear I might have to do it... ;)

Any help is welcome,
Tx in advance
Dave Lajoie

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

Re: How to script DOS app that doesn't use stdout

2005-03-06 Thread Paul Watson
Gregor [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 There's a DOS console application I am trying to script (in Python), but 
 it
 doesn't seem to use stdout or stderr... For example, if I redirect output
 to a file (cmd  file.txt), the output still appears on screen.
 Similarly, the output pipes returned by popen* don't catch the app's
 output. How might this app be generating its output? Any thoughts on how 
 it
 could be captured (perhaps with something in the win32 extensions)?

The good-ole DOS app could be doing many things.  It could be making BIOS 
calls or writing directly to the video display memory at segment 0xB800. 
One would think that if it did a DUP of stdout that it might get captured, 
but apparently you have tried the popen* family.

Any hints as to what the DOS app is?  If it is known by anyone, perhaps a 
workaround is also known. 


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


Re: Fork on windows

2005-03-06 Thread Dave Lajoie



pls ignore, I got open3 to work, silly mistake on 
my part...
dave.

  - Original Message - 
  From: 
  Dave 
  Lajoie 
  To: Python-list@python.org 
  Sent: Sunday, March 06, 2005 10:32 
  PM
  Subject: Fork on windows
  
  Hello Guys,
   I am new to the list and to 
  Python.
   I have been reading Oreilly's 
  Python book and some web page on child process creation
   using Python.
  
  Basically, on windows, I want to start a process 
  and monitor its stdout and stderror.
  I have looked at os.py from python lib directory, 
  and it explicitly requires fork to be present
  to "publish" os.open3
  
  e.g.: AttributeError: 'module' object has no 
  attribute 'open3'
  
  if I can't use os.open methods, is there another 
  solution to trigger an exec file and monitor 
  its stdout/stderr?
  Sorry if the question was asked. I have done 
  several unsuccessful web search to have a 
  definitive answer.
  
  Obviously I would like the same code to run on 
  both windows and linux, whenever possible
  I try to stay away from window specific code, but 
  I fear I might have to do it... ;)
  
  Any help is welcome,
  Tx in advance
  Dave Lajoie
  
  
  

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

Re: io.h include file in pyconfig.h

2005-03-06 Thread pythonnewbie
Thanks. How do I verify what RPMs I need? I checked with rpm -qa |
python, it only showed the python package. After I included the
/usr/include/sys/io.h in the source package INCLUDE path, it seemed
like the compilation went into a include loop.
(/usr/include/sys/unisted.h:1:10 #include nested too deeply)

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


Re: locale support and 4.10

2005-03-06 Thread Hye-Shik Chang
On Sat, 05 Mar 2005 15:42:23 +1000, Timothy Smith
[EMAIL PROTECTED] wrote:
 i'm trying to setlocale() on 4.10, and it appears the python package
 doesn't support this under 4.10.
 
 Python 2.3.3 (#2, Apr 28 2004, 22:48:37)
 [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
 Type help, copyright, credits or license for more information.
   import locale
   locale.setlocale(locale.LC_NUMERIC, 'us')
 Traceback (most recent call last):
   File stdin, line 1, in ?
   File /usr/local/lib/python2.3/locale.py, line 381, in setlocale
 return _setlocale(category, locale)
 locale.Error: unsupported locale setting
  
 
 the exact same thing works under windows xp.
 
 do i have to compile it with locale support?
 

 import locale
 locale.setlocale(locale.LC_NUMERIC, 'us')
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/local/lib/python2.2/locale.py, line 372, in setlocale
return _setlocale(category, locale)
locale.Error: locale setting not supported
 locale.setlocale(locale.LC_NUMERIC, 'en_US.ISO8859-1')
'en_US.ISO8859-1'
 locale.format('%g', 12.34)
'12.34'
 locale.setlocale(locale.LC_NUMERIC, 'fr_FR.ISO8859-1')
'fr_FR.ISO8859-1'
 locale.format('%g', 12.34)
'12,34'


You must specify exact locale name in FreeBSD.
eg) en_US.ISO8859-1 en_US.ISO8859-15 or etc.

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


Possible to import a module whose name is contained in a variable?

2005-03-06 Thread Steven Reddie
Hi,

I want to do something like the following, which doesn't work:

modulename = 'module'
import modulename

The error is that there is no module named 'modulename'.  Is there a
way to get that variable expanded?

Regards,

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


Re: Possible to import a module whose name is contained in a variable?

2005-03-06 Thread Hye-Shik Chang
On 6 Mar 2005 21:34:08 -0800, Steven Reddie [EMAIL PROTECTED] wrote:
 Hi,
 
 I want to do something like the following, which doesn't work:
 
 modulename = 'module'
 import modulename
 
 The error is that there is no module named 'modulename'.  Is there a
 way to get that variable expanded?
 

modulename = 'module'
module = __import__(modulename)


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


RE: Possible to import a module whose name is contained in a variable?

2005-03-06 Thread Steven Reddie
Hi,

Thanks, that seems to be what I was missing.  I'm having some further
related trouble though.  I want to do something like this:

MODULES = [ 'module1', 'module2' ]

def libinfo():
for m in MODULES:
__import__('libinfo.'+m)
m.libinfo()
CFLAGS+=m.CFLAGS

That is, effectively expanding out to:

def libinfo():
__import__('libinfo.module1')
module1.libinfo()
CFLAGS+=module1.CFLAGS  

I think the m in m.libinfo() is a string and so there is a failure to find
a libinfo member of a string object (which makes sense).  Is there some way
to call the libinfo member of the object named by m?  Am I heading into
reflection territory?

Regards,

Steven

-Original Message-
From: Hye-Shik Chang [mailto:[EMAIL PROTECTED] 
Sent: Monday, 7 March 2005 4:48 PM
To: Steven Reddie
Cc: python-list@python.org
Subject: Re: Possible to import a module whose name is contained in a
variable?

On 6 Mar 2005 21:34:08 -0800, Steven Reddie [EMAIL PROTECTED] wrote:
 Hi,
 
 I want to do something like the following, which doesn't work:
 
 modulename = 'module'
 import modulename
 
 The error is that there is no module named 'modulename'.  Is there a 
 way to get that variable expanded?
 

modulename = 'module'
module = __import__(modulename)


Hye-Shik

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


Re: How do I import everything in a subdir?

2005-03-06 Thread Steven Bethard
YL wrote:
Try something like this:
for x in plugs:
cmd = import %s % x
exec (cmd)
For the sake of others who might have missed the rest of this thread, 
I'll point out that this is definitely not the way to go.  No need to 
use exec when the builtin __import__ function is already defined for 
exactly this sort of use.

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


Re: function with a state

2005-03-06 Thread Stephen Thorne
On Sun, 06 Mar 2005 09:44:41 +0100, Patrick Useldinger
[EMAIL PROTECTED] wrote:
 Xah Lee wrote:
 
  globe=0;
  def myFun():
globe=globe+1
return globe
 
 The short answer is to use the global statement:
 
 globe=0
 def myFun():
global globe
globe=globe+1
return globe
 
 more elegant is:
 
 globe=0
 globe=myfun(globe)
 def myFun(var):
return var+1
 
 and still more elegant is using classes and class attributes instead of
 global variables.

Or what about just using the function object directly?

def myFun():
  myFun.x += 1
  return myFun.x
myFun.x = 0

for test in range(10):
 assert myFun()+1 == myFun()
 assert myFun()*2+3 == myFun()+myFun()
 assert range(myFun(), myFun()+9) == [myFun() for x in range(10)]
 assert range(myFun()+2, myFun()+11) == [myFun() for x in range(10)]

:))

couldn't-help-feeding-the-troll-ly-y'rs.
Stephen Thorne.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >