Re: state of SOAP and python?

2006-08-16 Thread Andre Meyer
I had success with ZSI: http://pywebsvcs.sourceforge.net/It worked very nicely for publishing a SOAP we service and accessing it from a client writtenusing the same library. What I didn't manage to achieve was to write the client in AJAX (tried 
http://www-128.ibm.com/developerworks/webservices/library/ws-wsajax/).regardsAndreOn 8/16/06, 
Mark Harrison <[EMAIL PROTECTED]> wrote:
Gabriel Genellina <[EMAIL PROTECTED]> wrote:> At Thursday 10/8/2006 03:38, Mark Harrison wrote:>> >So I'm investigating doing some SOAP work... Any concensus on
> >what the best python libraries are for doing this?> >> >Too bad, xmlrpc is choking on our long longs. :-(>> Just thinking, if you have control over the two ends, and dont need
> real interoperability, maybe just extending  to support long> integers could be easier...> I remember extending  once to support NaN's, moving to SOAP> was too much effort for that application.
Good thinking!  It turns out all you have to do is commentout the range check:def dump_int(self, value, write):# in case ints are > 32 bits##if value > MAXINT or value < MININT:
##raise OverflowError, "int exceeds XML-RPC limits"write("")write(str(value))write("\n")
Thanks,Mark--Mark HarrisonPixar Animation Studios--http://mail.python.org/mailman/listinfo/python-list
-- Dr. Andre P. Meyerhttp://python.openspace.nl/meyerTNO Defence, Security and Safety  
http://www.tno.nl/Delft Cooperation on Intelligent Systems  http://www.decis.nl/Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Very weird behavior that's driving me crazy

2006-08-16 Thread Pupeno
Hello,
I am experiencing a weird behavior that is driving me crazy. I have module
called Sensors containing, among other things:

class Manager:
def getStatus(self):
print "getStatus(self=%s)" % self
return {"a": "b", "c": "d"}

and then I have another module called SensorSingleton that emulates the
hard-to-code-on-python singleton in this way:

manager = Manager()
print "manager=%s" % manager
def getStatus():
print "getStatus()"
return manager.getStatus()

and then in some other module, I import SensorSingleton and I do, among
other things:

print SensorSingleton.getStatus()

and the output is more or less like this. First, the manager:

manager: 

ok, then 

Manager.getStatus(self=) =>
{"a": "b", "c": "d"}
None

None is the return of SensorSingleton.getStatus(), now, my questions are:

- Shouldn't the manager be the same in the first print and the second, that
is, the id is different, shouldn't it be the same ?
- What happened with all the output of SensorSingleton.getStatus() ? there's
no trace of it (but there's output of the method it calls).
- Why doesn't the SensorSingleton.getStatus() return the return value of
manager.getStatus(), it's a very straight forward call to it and return it.

Thank you.
-- 
Pupeno <[EMAIL PROTECTED]> (http://pupeno.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Python form Unix to Windows

2006-08-16 Thread Pradeep
Hi friends,

We are changing the python application from Unix to Windows. The source
code of Python application should work well in windows. How to make
changed to windows environment.
In Python code we have login module, ftp, socket programming.

Please help in changing the code from Unix envirnment to Windows
Environment.

Thanks in Advance.

Regards,
Pradeep

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


Weekly Python Patch/Bug Summary

2006-08-16 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  404 open ( +2) /  3376 closed (+16) /  3780 total (+18)
Bugs:  860 open ( -1) /  6131 closed (+17) /  6991 total (+16)
RFE :  229 open ( +1) /   235 closed ( +1) /   464 total ( +2)

New / Reopened Patches
__

option to leave tempfile.NamedTemporaryFile around on close  (2006-08-10)
   http://python.org/sf/1537850  opened by  djmdjm

Patch to fix __index__() clipping  (2006-08-11)
CLOSED http://python.org/sf/1538606  opened by  Travis Oliphant

Patch cElementTree to export CurrentLineNumber  (2006-08-11)
   http://python.org/sf/1538691  opened by  Robin Bryce

Replace unicode.__eq__ exceptions with a warning  (2006-08-11)
CLOSED http://python.org/sf/1538956  opened by  M.-A. Lemburg

Add readinto method to StringIO and cStringIO  (2006-08-12)
   http://python.org/sf/1539381  opened by  Alexander Belopolsky

Backports from trunk to release24-maint  (2006-08-15)
   http://python.org/sf/1540329  opened by  flub

tarfile __slots__ addition  (2006-08-14)
   http://python.org/sf/1540385  opened by  Brian Harring

Patches for OpenBSD 4.0  (2006-08-15)
   http://python.org/sf/1540470  opened by  djmdjm

Use Py_ssize_t for rangeobject members  (2006-08-15)
   http://python.org/sf/1540617  opened by  Alexander Belopolsky

except too broad  (2006-08-15)
   http://python.org/sf/1540849  opened by  Jim Jewett

with is now a blockopener  (2006-08-15)
CLOSED http://python.org/sf/1540851  opened by  Jim Jewett

IOBinding overly broad except (2nd try)  (2006-08-15)
CLOSED http://python.org/sf/1540856  opened by  Jim Jewett

except too broad  (2006-08-15)
CLOSED http://python.org/sf/1540857  opened by  Jim Jewett

IOBinding broad except - try 3  (2006-08-15)
CLOSED http://python.org/sf/1540859  opened by  Jim Jewett

CodeContext visibility   (2006-08-15)
   http://python.org/sf/1540869  opened by  Jim Jewett

broken shortcut keys  (2006-08-15)
   http://python.org/sf/1540874  opened by  Jim Jewett

make IDLE honor the quit() builtin  (2006-08-15)
CLOSED http://python.org/sf/1540892  opened by  Jim Jewett

Patches Closed
__

Add notes on locale module changes to whatsnew25.tex  (2006-08-03)
   http://python.org/sf/1534027  closed by  akuchling

Build ctypes on OpenBSD x86_64  (2006-08-08)
   http://python.org/sf/1536908  closed by  theller

Fix __index__() clipping really big numbers  (2006-07-29)
   http://python.org/sf/1530738  closed by  ncoghlan

PyShell.recall - fix indentation logic  (2006-07-25)
   http://python.org/sf/1528468  closed by  kbk

Patch to fix __index__() clipping  (2006-08-11)
   http://python.org/sf/1538606  closed by  nnorwitz

Replace unicode.__eq__ exceptions with a warning  (2006-08-11)
   http://python.org/sf/1538956  closed by  lemburg

Replace the ctypes internal '_as_parameter_' mechanism  (2006-08-02)
   http://python.org/sf/1532975  closed by  theller

writelines() in bz2 module does not raise check for errors  (2006-08-06)
   http://python.org/sf/1535500  closed by  gbrandl

trace.py on win32 has problems with lowercase drive names  (2006-08-07)
   http://python.org/sf/1536071  closed by  gbrandl

Give Cookie.py its own _idmap  (2006-07-13)
   http://python.org/sf/1521882  closed by  gbrandl

socket.gethostbyaddr fix for machines with incomplete DNS  (2006-06-23)
   http://python.org/sf/1511317  closed by  gbrandl

with is now a blockopener  (2006-08-15)
   http://python.org/sf/1540851  closed by  kbk

IOBinding overly broad except (2nd try)  (2006-08-15)
   http://python.org/sf/1540856  closed by  jimjjewett

except too broad  (2006-08-15)
   http://python.org/sf/1540857  closed by  jimjjewett

IOBinding broad except - try 3  (2006-08-15)
   http://python.org/sf/1540859  closed by  jimjjewett

make IDLE honor the quit() builtin  (2006-08-15)
   http://python.org/sf/1540892  closed by  kbk

New / Reopened Bugs
___

2nd issue with need for speed patch  (2006-08-09)
   http://python.org/sf/1537167  opened by  Robin Bryce

Missing platform information in subprocess documentation  (2006-08-09)
CLOSED http://python.org/sf/1537195  opened by  Aaron Bingham

urllib2 httplib _read_chunked timeout  (2006-08-09)
   http://python.org/sf/1537445  opened by  devloop

Installation on Windows Longhorn  (2006-08-10)
   http://python.org/sf/1537601  opened by  O.R.Senthil Kumaran

import on cElementTree on Windows  (2006-08-09)
   http://python.org/sf/1537685  reopened by  thomasbhickey

import on cElementTree on Windows  (2006-08-09)
   http://python.org/sf/1537685  opened by  Thomas B Hickey

indent changes when copying command  (2006-08-10)
CLOSED http://python.org/sf/1538445  opened by  mjd__

PyThreadState_SetAsyncExc bug  (2006-08-11)
   http://python.org/sf/1538556  opened by  ganges master

pyo's are not overwritten by different optimization levels  (2006-08-11)
   

round not rounding to 0 places

2006-08-16 Thread Fuzzydave
I have been using a round command in a few places to round
a value to zero decimal places using the following format,

round('+value+', 0)

but this consistantly returns the rounded result of the value
to one decimal place with a zero

EG:

4.97 is returned as 5.0 when i want it returned as 5, does
anyone know why this is and if i can get the round to make
the value 5?

David P

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


Re: what is the keyword "is" for?

2006-08-16 Thread Hendrik van Rooyen

 "Dan Bishop" <[EMAIL PROTECTED]> wrote:


| Sybren Stuvel wrote [on the difference between is and ==]:
| > Obviously "a is b" implies "a == b",
|
| Not necessarily.
|
| >>> a = b = 1e1000 / 1e1000
| >>> a is b
| True
| >>> a == b
| False

Huh? - wtf is this - I find this deeply disturbing - Sybren's explanation kind
of was congruent with my own understanding, and this is just weird - Hendrik

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


Re: Python form Unix to Windows

2006-08-16 Thread neokosmos

Pradeep wrote:
> We are changing the python application from Unix to Windows. The source
> code of Python application should work well in windows. How to make
> changed to windows environment.
> In Python code we have login module, ftp, socket programming.
>
> Please help in changing the code from Unix envirnment to Windows
> Environment.

You ask a good question.  However, the question is too large to be
answered in a newsgroup post.  The appropriate thing for you to do is
to go through the Python documentation and see which modules your
application depends on that are not available on Windows.  Then, you
need to decide how you'll either provide the missing functionality or
recode your app to better fit with the Windows environment.

Also, I'd like to note that if this is an app of any size, the work
involved might be fairly sizeable.  In that case, your best bet is to
either slog through the process i outlined above (returning to the
newsgroup when you're stuck on how to proceed), or pay someone to do
it.  I don't think you'll find anyone here willing to do that amount
and that kind of work for free. O:-)

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


Re: round not rounding to 0 places

2006-08-16 Thread Simon Forman
Fuzzydave wrote:
> I have been using a round command in a few places to round
> a value to zero decimal places using the following format,
>
> round('+value+', 0)
>
> but this consistantly returns the rounded result of the value
> to one decimal place with a zero
>
> EG:
>
> 4.97 is returned as 5.0 when i want it returned as 5, does
> anyone know why this is and if i can get the round to make
> the value 5?
>
> David P

|>> n = 4.97
|>> round(n)
5.0
|>> int(round(n))
5
|>> help(round)
Help on built-in function round in module __builtin__:

round(...)
round(number[, ndigits]) -> floating point number

Round a number to a given precision in decimal digits (default 0
digits).
This always returns a floating point number.  Precision may be
negative.


HTH,
~Simon


BTW, '+value+' ..?  Huh?

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


Re: how to deepcopy a slice object?

2006-08-16 Thread Alexandre Guimond
thx for all the help simon. good ideas i can work with.

thx again.

alex.

Simon Forman wrote:
> Alexandre Guimond wrote:
> > Here is my reason:
> >
> > I have an object that contrains a 2D regular grid (matrix). In this
> > regular grid, I place points at regular intervals. In essence, i have
> > something like (my code is obviously more complex, this is just to show
> > what I want to do)
> >
> > obj.grid = numpy.zeros( ( 100, 100 ) )
> > obj.grid[ obj.y1: obj.y2 : obj.ys, obj.x1 : obj.x2 : obj.xs ] =
> > embedded_parameters
> > result = somefunc( obj.grid )
> >
> > My goal was to reduce the number of elements in my obj object by
> > replacing y1, y2, ys, and x1, x2, xs by 2 slice objects, and then do:
> >
> > obj.grid[ obj.slicey, obj.slicex ] = embedded_parameters
> >
> > But when I do this and then try to deepcopy my object, it doesn't work,
> > as in the example below.
> >
> > Its not a big thing. I just liked the idea of having less elements in
> > my obj class and actually modeling my slice concept by a slice object,
> > specially since i'm going to 3D and 4D grid, and its somewhat annoying
> > to carry so many indices in my class definition.
> >
> > Simon Forman wrote:
> > > Alexandre Guimond wrote:
> > > > Hi all,
> > > >
> > > > i'm trying to deepcopy a slice object but i get the following error.
> > > > Does anyone know a workaround?
> > > >
> > > > ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
> > > > Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
> > > > on win32
> > > > Type "help", "copyright", "credits" or "license" for more information.
> > > > >>> import copy
> > > > >>> copy.deepcopy( slice( 1, 10, 2 ) )
> > > > Traceback (most recent call last):
> > > >   File "", line 1, in ?
> > > >   File "C:\Program Files\Python\lib\copy.py", line 204, in deepcopy
> > > > y = _reconstruct(x, rv, 1, memo)
> > > >   File "C:\Program Files\Python\lib\copy.py", line 336, in _reconstruct
> > > > y = callable(*args)
> > > >   File "C:\Program Files\Python\lib\copy_reg.py", line 92, in
> > > > __newobj__
> > > > return cls.__new__(cls, *args)
> > > > TypeError: slice expected at least 1 arguments, got 0
> > > >
> > > > thx for any help.
> > >
> > > Why would you want to [deep]copy a slice object?
> > >
> > > Anyway,  I don't know much about them, other than that they are
> > > slightly unusual objects that play a very restricted role in python,
> > > rather like the Ellipsis.
> > >
> > > Workarounds are possible, I think, but really you almost certainly
> > > don't need to do this.
> > >
> > > Peace,
> > > ~Simon
>
> Ah, so you *do* want to deepcopy slice objects..  Neat. :-)
>
> I can't do that, but I can show you a couple of ways to deepcopy
> objects that have slices as attributes.
>
> First, if the __init__() method and its args are sufficient to recreate
> your objects then you could do something like this:
>
> class DeepCopyable0:
>
> def __init__(self, x, y, z, a, b, c):
> self.slicex = slice(x, y, z)
> self.slicey = slice(a, b, c)
>
> def __deepcopy__(self, memo):
>
> # Create local vars for brevity.
> sx, sy = self.slicex, self.slicey
>
> # Create a new DeepCopyable0 instance.
> return DeepCopyable0(
> sx.start, sx.stop, sx.step,
> sy.start, sy.stop, sy.step
> )
>
> |>> d0 = DeepCopyable0(1, 2, 3, 4, 5, 6)
> |>> d0.slicex, d0.slicey
> (slice(1, 2, 3), slice(4, 5, 6))
> |>> d1 = deepcopy(d0)
> |>> d1.slicex, d1.slicey
> (slice(1, 2, 3), slice(4, 5, 6))
>
> Otherwise, another way to do it would be to provide the pickling
> protocol:
>
> class DeepCopyable1:
>
> def __init__(self, x, y, z, a, b, c):
> # Pretend this was something more complicated.
> self.slicex = slice(x, y, z)
> self.slicey = slice(a, b, c)
>
> def __getstate__(self):
>
> state = self.__dict__.copy()
>
> # Create local vars for brevity.
> sx, sy = self.slicex, self.slicey
>
> # Save the indices rather than the slices.
> state['slicex'] = sx.start, sx.stop, sx.step
> state['slicey'] = sy.start, sy.stop, sy.step
>
> return state
>
> def __setstate__(self, state):
>
> # Recreate the slice objects.
> state['slicex'] = slice(*state['slicex'])
> state['slicey'] = slice(*state['slicey'])
>
> self.__dict__.update(state)
>
>
> |>> d0 = DeepCopyable1(1, 2, 3, 4, 5, 6)
> |>> d0.slicex, d0.slicey
> (slice(1, 2, 3), slice(4, 5, 6))
> |>> d1 = deepcopy(d0)
> |>> d1.slicex, d1.slicey
> (slice(1, 2, 3), slice(4, 5, 6))
>
> Circular references seem work fine here too.  Observe:
>
> |>> d0 = DeepCopyable1(1, 2, 3, 4, 5, 6)
> |>> d0.rec = d0
> |>> d0
> 
> |>> d0.rec.rec  #etc...
> 
> |>> d1 = deepcopy(d0)
> |>> d1
> 
> |>> d1.rec
> 
>
> Since you're going to be using more dimensions, you could make python
> do the work for you rather than cutting and pasting:
>
> class DeepCopyable2:

Re: round not rounding to 0 places

2006-08-16 Thread Tim Leslie
On 16 Aug 2006 00:19:24 -0700, Fuzzydave <[EMAIL PROTECTED]> wrote:
> I have been using a round command in a few places to round
> a value to zero decimal places using the following format,
>
> round('+value+', 0)
>
> but this consistantly returns the rounded result of the value
> to one decimal place with a zero
>
> EG:
>
> 4.97 is returned as 5.0 when i want it returned as 5, does
> anyone know why this is and if i can get the round to make
> the value 5?

round returns a float. You probably want to convert it to an int.

>>> int(round(4.97))
5

Cheers,

Tim

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


Re: Python form Unix to Windows

2006-08-16 Thread Simon Forman
Pradeep wrote:
> Hi friends,
>
> We are changing the python application from Unix to Windows. The source
> code of Python application should work well in windows. How to make
> changed to windows environment.
> In Python code we have login module, ftp, socket programming.
>
> Please help in changing the code from Unix envirnment to Windows
> Environment.
>
> Thanks in Advance.
>
> Regards,
> Pradeep

Simplest way: Run the app in windows, see what breaks (probably less
than you might think), fix it.

I have written large apps that required less than a dozen, or no,
changes to move between windows and *nix.  YMMV

Peace,
~Simon

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


Re: Very weird behavior that's driving me crazy

2006-08-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Pupeno wrote:

> - Shouldn't the manager be the same in the first print and the second, that
> is, the id is different, shouldn't it be the same ?
> - What happened with all the output of SensorSingleton.getStatus() ? there's
> no trace of it (but there's output of the method it calls).
> - Why doesn't the SensorSingleton.getStatus() return the return value of
> manager.getStatus(), it's a very straight forward call to it and return it.

How have you tested this?  Is there any chance it was an interactive
session and you forgot to reload the module after making changes to it?

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


Re: round not rounding to 0 places

2006-08-16 Thread Fuzzydave
> Sybren Stuvel wrote:
> round returns a float. Use
> int(round('+value+', 0))
> to get an integer.
> Sybren

ahh of course it does, slaps own forehead sorted 
thanks :)

David P

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


Re: Very weird behavior that's driving me crazy

2006-08-16 Thread Simon Forman
Pupeno wrote:
> Hello,
> I am experiencing a weird behavior that is driving me crazy. I have module
> called Sensors containing, among other things:
>
> class Manager:
> def getStatus(self):
> print "getStatus(self=%s)" % self
> return {"a": "b", "c": "d"}
>
> and then I have another module called SensorSingleton that emulates the
> hard-to-code-on-python singleton in this way:
>
> manager = Manager()
> print "manager=%s" % manager
> def getStatus():
> print "getStatus()"
> return manager.getStatus()
>
> and then in some other module, I import SensorSingleton and I do, among
> other things:
>
> print SensorSingleton.getStatus()
>
> and the output is more or less like this. First, the manager:
>
> manager: 
>
> ok, then
>
> Manager.getStatus(self=) =>
> {"a": "b", "c": "d"}
> None
>
> None is the return of SensorSingleton.getStatus(), now, my questions are:
>
> - Shouldn't the manager be the same in the first print and the second, that
> is, the id is different, shouldn't it be the same ?
> - What happened with all the output of SensorSingleton.getStatus() ? there's
> no trace of it (but there's output of the method it calls).
> - Why doesn't the SensorSingleton.getStatus() return the return value of
> manager.getStatus(), it's a very straight forward call to it and return it.
>
> Thank you.
> --
> Pupeno <[EMAIL PROTECTED]> (http://pupeno.com)

The code you posted doesn't match the output you posted.  Try coding
the smallest version of what you're trying to do and post its output.

Peace,
~Simon

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


Re: what is the keyword "is" for?

2006-08-16 Thread [EMAIL PROTECTED]
Sybren Stuvel wrote:
> Dan Bishop enlightened us with:
>  a = b = 1e1000 / 1e1000
>  a is b
> > True
>  a == b
> > False
>
> If "a is b" then they refer to the same object, hence a == b. It
> cannot be otherwise, unless Python starts to defy logic. I copied your
> code and got the expected result:
>
> >>> a = b = 1e1000 / 1e1000
> >>> a is b
> True
> >>> a == b
> True

Probably depends on the implementation.  1e1000/1e1000 yields a NaN
here, and I get True for "a is b" but False for "a==b".  Presumably
comparing a NaN for equality (any comparison?) always yields False.

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


Re: Very weird behavior that's driving me crazy

2006-08-16 Thread Pupeno
Nevermind, it was fixed. Thanks.

Pupeno wrote:

> Hello,
> I am experiencing a weird behavior that is driving me crazy. I have module
> called Sensors containing, among other things:
> 
> class Manager:
> def getStatus(self):
> print "getStatus(self=%s)" % self
> return {"a": "b", "c": "d"}
> 
> and then I have another module called SensorSingleton that emulates the
> hard-to-code-on-python singleton in this way:
> 
> manager = Manager()
> print "manager=%s" % manager
> def getStatus():
> print "getStatus()"
> return manager.getStatus()
> 
> and then in some other module, I import SensorSingleton and I do, among
> other things:
> 
> print SensorSingleton.getStatus()
> 
> and the output is more or less like this. First, the manager:
> 
> manager: 
> 
> ok, then
> 
> Manager.getStatus(self=) =>
> {"a": "b", "c": "d"}
> None
> 
> None is the return of SensorSingleton.getStatus(), now, my questions are:
> 
> - Shouldn't the manager be the same in the first print and the second,
> that is, the id is different, shouldn't it be the same ?
> - What happened with all the output of SensorSingleton.getStatus() ?
> there's no trace of it (but there's output of the method it calls).
> - Why doesn't the SensorSingleton.getStatus() return the return value of
> manager.getStatus(), it's a very straight forward call to it and return
> it.
> 
> Thank you.

-- 
Pupeno <[EMAIL PROTECTED]> (http://pupeno.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is the keyword "is" for?

2006-08-16 Thread Simon Forman
Sybren Stuvel wrote:
> Dan Bishop enlightened us with:
>  a = b = 1e1000 / 1e1000
>  a is b
> > True
>  a == b
> > False
>
> If "a is b" then they refer to the same object, hence a == b. It
> cannot be otherwise, unless Python starts to defy logic. I copied your
> code and got the expected result:
>
> >>> a = b = 1e1000 / 1e1000
> >>> a is b
> True
> >>> a == b
> True
>
> Sybren

Python 2.4.3 (#2, Apr 27 2006, 14:43:58)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

|>> a = b = 1e1000 / 1e1000
|>> a is b
True
|>> a == b
False

Huh.  Weird.  I copied it too and got the "wrong" result.

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


Re: what is the keyword "is" for?

2006-08-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Sybren Stuvel wrote:

> Dan Bishop enlightened us with:
> a = b = 1e1000 / 1e1000
> a is b
>> True
> a == b
>> False
> 
> If "a is b" then they refer to the same object, hence a == b. It
> cannot be otherwise, unless Python starts to defy logic. I copied your
> code and got the expected result:
> 
 a = b = 1e1000 / 1e1000
 a is b
> True
 a == b
> True

I get the same as Dan:

In [13]: a = b = 1e1000 / 1e1000

In [14]: a is b
Out[14]: True

In [15]: a == b
Out[15]: False

In [16]: a
Out[16]: nan

On my platform the division results in "Not A Number".  Two NaNs compared
are always `False`.  You could argue that this is the very same NaN but to
get this effect the interpreter has to take care that every NaN produced
while a program is running is unique.  Quite huge overhead for such a
corner case IMHO.

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


RE: What would be the best way to run python client in the background

2006-08-16 Thread Tim Golden
| Tim Golden wrote:
| 
| > [gel]
| >
| > | I have written a python client server app [...]
| > | I want to run the client end of the app more or less invisibly
| > | (no console) on the XP clients when ever a users logs on.

[Tim G]
| > The normal way is to run a Win32 service. There are several
| > posts on the subject around the Python and Python-Win32
| > mailing lists / newsgroups. The alternative is to set something
| > to run when any user logs in to run without a window. Again,
| > there are posts on the subject, including one I seem to remember
| > from Robin Becker, which tell how to do this kind of thing.

[gel]
| Yes running the client as a service seems to be the way to go.  I have
| had a bit of a look at the py2exe way of doing it, but have not got my
| head around it yet.  What would be your preferred way of creating a
| service for an XP client?

I've always coded pretty much from scratch, reusing a tried-and-trusted
skeleton and fitting things in. That said, I've never had to put
together
a service that was anything more than lightweight. The attached template
I
culled from someone's webpage, can't remember where I'm afraid. I
believe
people have had success in using py2exe to create a service but I
haven't
tried it myself.

Hopefully more experienced service-writers will chime in with coherent
advice. You might also try the python-win32 mailing list, since not
everyone who reads that reads this I imagine.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk


service_template.py
Description: service_template.py
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: using python at the bash shell?

2006-08-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, cga2000 wrote:

> and also some bash built-ins such as "cd" do not do anything .. maybe
> ipython starts a subprocess that switches and then immediately exits ..
> so when I get the prompt back I'm back where I started.

If you put a ``!`` in front of ``cd`` this is what happens.  Just leave
out the ``!``.  IPython has it's own built-in ``cd`` command.

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


Re: how to deepcopy a slice object?

2006-08-16 Thread Simon Forman
Alexandre Guimond wrote:
> thx for all the help simon. good ideas i can work with.
>
> thx again.
> 
> alex.
> 

You're very welcome, a pleasure. ;-)

~Simon

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


Re: Memory usage of an 'empty' python interpreter

2006-08-16 Thread Ant

[EMAIL PROTECTED] wrote:
> I was wondering what the approximate amount of memory needed to load a
> Python interpreter (only, no objects, no scripts, no nothing else) in a
> Linux 2.6 environment.  According to ps, it appears to be 3312 bytes,
> which seems absurdly low to me.  However, when I check the size of my
> Python executable, it looks like it is only about 5600 bytes in size,
> so maybe this is reasonable?

Are you sure ps is reporting in bytes not KB? The bare interpreter in
Windows is 3368KB.
On my Gentoo server ps reports 2788KB for the bare interpreter.

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


Re: Very weird behavior that's driving me crazy

2006-08-16 Thread John Machin

Pupeno wrote:
> Hello,
> I am experiencing a weird behavior that is driving me crazy. I have module
> called Sensors containing, among other things:
>
> class Manager:
> def getStatus(self):
> print "getStatus(self=%s)" % self
> return {"a": "b", "c": "d"}
>
> and then I have another module called SensorSingleton that emulates the
> hard-to-code-on-python singleton in this way:
>
> manager = Manager()
> print "manager=%s" % manager
> def getStatus():
> print "getStatus()"
> return manager.getStatus()
>
> and then in some other module, I import SensorSingleton and I do, among
> other things:
>
> print SensorSingleton.getStatus()
>
> and the output is more or less like this. First, the manager:
>
> manager: 
### Uh-oh. The code should print "manager=", not "manager:"
>
> ok, then
>
> Manager.getStatus(self=) =>
### Uh-oh. The code should print "getStatus(self=blahblahblah" i.e.
without "Manager." in the front.

> {"a": "b", "c": "d"}
> None
>
> None is the return of SensorSingleton.getStatus(),
### What evidence do you have for that statement?

 now, my questions are:
>
> - Shouldn't the manager be the same in the first print and the second, that
> is, the id is different, shouldn't it be the same ?
### Yes.

> - What happened with all the output of SensorSingleton.getStatus() ? there's
> no trace of it (but there's output of the method it calls).

### All what output? The only expected output is "getStatus()"

> - Why doesn't the SensorSingleton.getStatus() return the return value of
> manager.getStatus(), it's a very straight forward call to it and return it.
>

If you want help, forget the "more or less" caper -- it's useless. It's
obvious from the above that the output that you describe can *not* have
come from the code fragments that you showed.Cut your 3 modules down to
the bare minimum that still shows the bug. Include copies of those plus
the exact (copy/paste) results of running the test at the OS
command-line (I.e. not in an IDE). Do make sure that none of your
modules are being shadowed or are outdated -- have all 3 in your
current working directory, and delete all .pyc files before running the
test.

What version of Python are you running? 2.3? Which platform?

Below's what I tried -- it's essentially the same as your code, with a
bit more output and with lower-case module names and I didn't bother
with a 2-line calling module.  It works as expected.

HTH,
John

C:\junk>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
|>>> import singleton
[singleton] manager=
|>>> singleton.getStatus()
[singleton] entered getStatus()
[sensors]getStatus(self )
[singleton] stuff = {'a': 'b', 'c': 'd'}
{'a': 'b', 'c': 'd'}
|>>> ^Z

C:\junk>type sensors.py
class Manager:
def getStatus(self):
print "[sensors]getStatus(self %s)" % self
return {"a": "b", "c": "d"}

C:\junk>type singleton.py
from sensors import Manager
manager = Manager()
print "[singleton] manager=%s" % manager
def getStatus():
print "[singleton] entered getStatus()"
stuff = manager.getStatus()
print "[singleton] stuff =", stuff
return stuff
8<---

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


Re: Memory usage of an 'empty' python interpreter

2006-08-16 Thread Ganesan Rajagopal
> neokosmos  <[EMAIL PROTECTED]> writes:

> I was wondering what the approximate amount of memory needed to load a
> Python interpreter (only, no objects, no scripts, no nothing else) in a
> Linux 2.6 environment.  According to ps, it appears to be 3312 bytes,
> which seems absurdly low to me.  However, when I check the size of my
> Python executable, it looks like it is only about 5600 bytes in size,
> so maybe this is reasonable?

It is, when you consider that ps reports in kilobytes :-). It's
meaningless just to compare the size of the python binary. In your case it's
obvious that the python binary is linking to a shared python library.

Ganesan

-- 
Ganesan Rajagopal

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


Re: Memory usage of an 'empty' python interpreter

2006-08-16 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
> I was wondering what the approximate amount of memory needed to load a
> Python interpreter (only, no objects, no scripts, no nothing else) in a
> Linux 2.6 environment.  According to ps, it appears to be 3312 bytes,
> which seems absurdly low to me.

Your spidey sense is working properly, 3312 bytes is absurdly low.

> Here is the output of ps -aux | grep python
>
> USER   PID %CPU %MEMVSZ   RSS TTY  STAT START   TIME
> COMMAND
> paul 17561  0.1  0.6  14616  3312 pts/2S+   02:33   0:00 python
[SNIP]
> If I am reading this right, it says the Python interpreter itself is
> using 3312 bytes of memory, but has 14616 bytes of shared memory it can
> access (which, i assume, is mostly shared libraries).

Nope, ps output for those values is in kilobytes.  It's a bit over 3 MB
RSS, 14MB shared.

> Here's my ls -l /usr/bin/python2.4:
>
> -rwxr-xr-x 1 root root 5424 Jul 21 08:02 /usr/bin/python2.4

I'm not sure what's up here (maybe a shell script wrapper?) try "file
/usr/bin/python2.4" and "ls -alh /usr/bin/python2.4".

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


Re: Memory usage of an 'empty' python interpreter

2006-08-16 Thread John Machin

Ant wrote:
> [EMAIL PROTECTED] wrote:
> > I was wondering what the approximate amount of memory needed to load a
> > Python interpreter (only, no objects, no scripts, no nothing else) in a
> > Linux 2.6 environment.  According to ps, it appears to be 3312 bytes,
> > which seems absurdly low to me.  However, when I check the size of my
> > Python executable, it looks like it is only about 5600 bytes in size,
> > so maybe this is reasonable?
>
> Are you sure ps is reporting in bytes not KB? The bare interpreter in
> Windows is 3368KB.

Where did you get that from? With Python 2.4.3, on my machine (Win XP
SP2):

C:\junk>dir \python24\python*
[snip]
29/03/2006  05:35 PM 4,608 python.exe
29/03/2006  05:35 PM 1,871,872 python24.dll
29/03/2006  05:35 PM 5,120 pythonw.exe

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


Re: Printing n elements per line in a list

2006-08-16 Thread Gerard Flanagan

unexpected wrote:
> If have a list from 1 to 100, what's the easiest, most elegant way to
> print them out, so that there are only n elements per line.
>
> So if n=5, the printed list would look like:
>
> 1 2 3 4 5
> 6 7 8 9 10
> 11 12 13 14 15
> etc.
>
> My search through the previous posts yields methods to print all the
> values of the list on a single line, but that's not what I want. I feel
> like there is an easy, pretty way to do this. I think it's possible to
> hack it up using while loops and some ugly slicing, but hopefully I'm
> missing something

just variations on previous answers:

rng = range(1,101)

#ad hoc
for line in ( rng[i:i+5] for i in xrange(0,100,5) ):
print ' '.join(map(str,line))

#in general
def lines( seq, count=1 ):
n = len(seq)
for x in ( seq[i:i+count] for i in xrange(0,n,count) ):
yield x

for line in lines( rng, 5 ):
print ' '.join(map(str,line))

Gerard

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


Re: What would be the best way to run python client in the background

2006-08-16 Thread Roger Upole
You can use the Task Scheduler to run a script at login.
It's not as robust as creating a service, but it's much less
work.

  Roger

"gel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Hi
> I have written a python client server app that keeps an eye on
> processes starting and ending on a client and makes decision on what to
> do based on information from the server end.  I want to run the client
> end of the app more or less invisibly (no console) on the XP clients
> when ever a users logs on.  What would be the best way to get this
> done?  A bit more info on the purpose of the app... it is to act as a
> licence server, where we have a limited number of licences for software
> and the software installed on all PCs.  The app will only allow a pre
> defined number of clients to run the software at any one time.
> 


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


Re: Printing n elements per line in a list

2006-08-16 Thread John Machin

Gerard Flanagan wrote:

>
> just variations on previous answers:
>
> rng = range(1,101)
>
> #ad hoc
> for line in ( rng[i:i+5] for i in xrange(0,100,5) ):
> print ' '.join(map(str,line))
>
> #in general
> def lines( seq, count=1 ):
> n = len(seq)
> for x in ( seq[i:i+count] for i in xrange(0,n,count) ):
> yield x
>

Don't those last two lines deflate to:
for i in xrange(0,n,count):
yield seq[i:i+count]
???

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


Re: Reference Variables In Python Like Those In PHP

2006-08-16 Thread Laurent Pointal
Chaos a écrit :
> Is It possible to have reference variables like in PHP
> 
> ex.
> 
>  
> $x = 1;
> $y =& $x;
> 
> $y += 1;
> 
> echo $x;
> echo "\n"
> echo $y;
> 
> ?>
> 
> This would show
> 
> 2
> 2
> 
> Is this available in python?

See other replies (ie. in Python all variables are names refering to
objects).

You may achieve same result using an object as a namespace, like this:

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class Dummy(object) : pass
...
>>> x=Dummy()
>>> x.val = 1
>>> y = x   <-- here x and y refer to *same* Dummy object
>>> y.val += 1
>>> x.val
2
>>> y.val
2

A+

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


Re: Creating Charts in Excel with pyExcelerator.ExcelMagic

2006-08-16 Thread Chris
implicate_order wrote:
> Greetings,
> 
Here's an Excel class I use. I'm afraid I can't recall where I found the
basic class. I have a vague recollection it is due to Mark Hammond,
author of the win32com package. Might have been in win32com demos. 
(Whoever the original author is anyway, many thanks). I added a few 
methods, including XY plotting (you can probably tell by the change in 
coding style to that of a newb). Not very generic but you may find it 
useful, as the hardest part I found was discovering what the Excel 
specific methods etc where. The MSDN developer site for Excel is a big 
help. http://msdn.microsoft.com/developercenters/



import win32com.client
from win32com.client import Dispatch, constants

class ExcelWorkbook:
 """ An Excel workbook object"""
 def __init__(self, filename=None):
 # Use these commands in Python code to auto generate .py 
support for excel
 from win32com.client import gencache
 gencache.EnsureModule('{00020813---C000-0046}', 
0, 1, 4)
 # start excel
 self.xlApp = Dispatch('Excel.Application')

 if filename and os.path.exists(filename):
 self.xlBook = self.xlApp.Workbooks.Open(filename)
 else:
 self.xlBook = self.xlApp.Workbooks.Add()
 self.filename = filename

 def save(self, newfilename=None):
 if newfilename:
 self.filename = newfilename
 self.xlBook.SaveAs(newfilename)
 else:
 self.xlBook.Save()

 def close(self):
 self.xlBook.Close(SaveChanges=0)
 del self.xlApp

 def show(self):
 self.xlApp.Visible = 1

 def hide(self):
 self.xlApp.Visible = 0
 def newSheet(self, sheet):
 try:# fails if sheet already exists
 self.xlBook.Sheets(sheet).Name == sheet
 except:
 self.xlSheet = self.xlBook.Worksheets.Add()
 self.xlSheet.Name = sheet

 def deleteSheet(self, sheet):
 try:# ignore if sheet doesn't exist
 self.xlBook.Sheets(sheet).Delete()
 except:
 pass

 def selectSheet(self, sheet):
 self.xlBook.Worksheets(sheet).Select()

 def getCell(self, sheet, row, col):
 "Get value of one cell"
 sht = self.xlBook.Worksheets(sheet)
 return sht.Cells(row, col).Value

 def setCell(self, sheet, row, col, value):
 "set value of one cell"
 sht = self.xlBook.Worksheets(sheet)
 sht.Cells(row, col).Value = value

 def getRange(self, sheet, row1, col1, row2, col2):
 "return a 2d array (i.e. tuple of tuples)"
 sht = self.xlBook.Worksheets(sheet)
 return sht.Range(sht.Cells(row1, col1), sht.Cells(row2, 
col2)).Value

 def setRange(self, sheet, topRow, leftCol, data):
 """insert a 2d array starting at given location.
 Works out the size needed for itself"""
 bottomRow = topRow + len(data) - 1
 rightCol = leftCol + len(data[0]) - 1
 sht = self.xlBook.Worksheets(sheet)
 sht.Range(
 sht.Cells(topRow, leftCol),
 sht.Cells(bottomRow, rightCol)
 ).Value = data

 def getContiguousRange(self, sheet, row, col):
 """Tracks down and across from top left cell until it
 encounters blank cells; returns the non-blank range.
 Looks at first row and column; blanks at bottom or right
 are OK and return None witin the array"""

 sht = self.xlBook.Worksheets(sheet)

 # find the bottom row
 bottom = row
 while sht.Cells(bottom + 1, col).Value not in [None, '']:
 bottom = bottom + 1

 # right column
 right = col
 while sht.Cells(row, right + 1).Value not in [None, '']:
 right = right + 1

 return sht.Range(sht.Cells(row, col), sht.Cells(bottom, 
right)).Value

 def fixStringsAndDates(self, aMatrix):
 # converts all unicode strings and times
 newmatrix = []
 for row in aMatrix:
 newrow = []
 for cell in row:
 if type(cell) is UnicodeType:
 newrow.append(str(cell))
 elif type(cell) is TimeType:
 newrow.append(int(cell))
 else:
 newrow.append(cell)
 newmatrix.append(tuple(newrow))
 return newmatrix

 def convertRCToA1(self, R1C1):
 """
 fromReferenceStyle  =   constants.xlR1C1,
 toReferenceStyle=   constants.xlA1,
 toabsolute  =   constants.xlRelative)
 """
 return self.xlApp.ConvertFormula(R1C1, constants.xlR1C1,
 constants.xlA1, 
constants.xlRelative)

 def insertFormulaInRange(self, sheet, row, col, len, formula):
 self.selectSheet(sheet)
 sht = self.xlBook.Worksheets(sheet)
 sht.

Re: Global Objects...

2006-08-16 Thread Chaz Ginger
KraftDiner wrote:
> I have a question..
> 
> myGlobalDictionary = dictionary()
> 
> 
> class someClass:
>def __init__(self):
>   self.x = 0;
>def getValue(self, v)
>   myGlobalDictionary.getVal(v)
> 
> 
> myGlobalDictionary doesn't seem to be visible to my someClass methods.
> Why?  What should I do?
> 
Is it an oversight that you forgot the ':' on the getValue definition?
You also forgot to do the return. I say the code should look like:

def getValue(self,v) :
return myGlobalDictionary[v]

I am also confused as to what getVal() does.

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


Re: what is the keyword "is" for?

2006-08-16 Thread Dan Sommers
On Wed, 16 Aug 2006 10:06:03 +0200,
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

> In [14]: a is b
> Out[14]: True

> In [15]: a == b
> Out[15]: False

> In [16]: a
> Out[16]: nan

> On my platform the division results in "Not A Number".  Two NaNs
> compared are always `False`.  You could argue that this is the very
> same NaN but to get this effect the interpreter has to take care that
> every NaN produced while a program is running is unique.  Quite huge
> overhead for such a corner case IMHO.

The interpreter isn't doing anything special; nans have [the equivalent
of] an __eq__ method that always returns False.

Regards,
Dan

-- 
Dan Sommers

"I wish people would die in alphabetical order." -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: programming with Python 3000 in mind

2006-08-16 Thread Terry Reedy

"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> (1) How far away is Python 3000?
> Years away, although not that many years. Three? Four?

Try 1 1/2.  Guido hopes to release 3.0a1 next January and 3.0 final a year 
after.

> (2) Will there be automated tools for converting source code from Python 
> 2
> to Python 3000?
> Almost certainly.

There will be tools for detecting things that need examination.  Complete 
auto conversion will probably not be possible.


One way to program for the future is to import the future, in particular, 
'integer division'.

Terry Jan Reedy



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


Re: programming with Python 3000 in mind

2006-08-16 Thread Steve Holden
Steven D'Aprano wrote:
> On Tue, 15 Aug 2006 13:16:27 -0700, beliavsky wrote:
> 
> 
>>The current beta version of Python is 2.5 . How can a Python programmer
>>minimize the number of changes that will be needed to run his code in
>>Python 3000? In general, he should know what is being removed from
>>Python 3000 and if possible use the "modern" analogs in Python.
> 
> 
> In general, you can't, as Python 3000 hasn't been nailed down yet.
> 
> You shouldn't be asking "How do I write for a language that doesn't exist
> yet?" but instead should ask:
> 
> (1) How far away is Python 3000?
> 
> Years away, although not that many years. Three? Four?
> 
Two.

> (2) Will there be automated tools for converting source code from Python 2
> to Python 3000?
> 
> Almost certainly.
> 
Yes.

> (3) Once Python 3000 is released, will Python 2 still be supported and if
> so, for how long?
> 
> I'm sure there will be a nice long transition period, and if the Python
> developers don't want to support Python 2, it will be a wonderful
> opportunity for some commercial operation to charge for support.

For the answers to questions like these see

   http://video.google.com/videoplay?docid=-6459339159268485356

which is Guido's rehearsal for his OSCON presentation on Python 3000.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


wxPython Install

2006-08-16 Thread Dr. Philipp Walderdorff
Hallo James

I had the same problems. But I could solve them.
The problem which is left: I do not know exaktly how I solved it.

I have tried a lots of times, two weeks or fight against dependency-problems.

In FedoraCore5 I did:

yum update yum
yum install python 
python-2.4.2-3.2.1

yum install python-devel
python-devel-2.4.2-3.2.1

you need 
gtk+-1.2.10-50
and 
glib-1.2.10-18.2.2
which was  already installed by FedoraCore5

with wxPython I had a lots of problems. Lots of tries to install from the 
tarball with lots of dependency-problems.
http://www.wxpython.org/download.php

Now I have got 
wxPython-2.6.3.2-1.fc5
installed, but, excuse me, I really don't know anymore what at least helped.
 
Did you solve your problem?
Because I am writing a documentation for wiki I could need your experience.

Thanks
Philipp

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


Re: Printing n elements per line in a list

2006-08-16 Thread Gerard Flanagan

John Machin wrote:
> Gerard Flanagan wrote:
>
> >
> > just variations on previous answers:
> >
> > rng = range(1,101)
> >
> > #ad hoc
> > for line in ( rng[i:i+5] for i in xrange(0,100,5) ):
> > print ' '.join(map(str,line))
> >
> > #in general
> > def lines( seq, count=1 ):
> > n = len(seq)
> > for x in ( seq[i:i+count] for i in xrange(0,n,count) ):
> > yield x
> >
>
> Don't those last two lines deflate to:
> for i in xrange(0,n,count):
> yield seq[i:i+count]
> ???

Yes! Thank you.  (pre-caffeine...)

Gerard

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


Re: programming with Python 3000 in mind

2006-08-16 Thread Paul Boddie
Kay Schluehr wrote:
> Fredrik Lundh wrote:
> > [EMAIL PROTECTED] wrote:
> >
> > > The current beta version of Python is 2.5 . How can a Python programmer
> > > minimize the number of changes that will be needed to run his code in
> > > Python 3000?
> >
> > by ignoring it, until it exists.
>
> And why not ignoring it, when it comes to exist?

The risk of Python 3000 being ignored or marginalised may increase in
direct proportion to the amount of exotic new stuff introduced upon its
release, mostly because people have a large amount of code that may not
work with an extensively modified language, library and runtime
(although the latter is only a remote possibility), and because
newcomers may not see Python 3000 as significantly interesting to adopt
in preference to other languages. This observation, which I'm sure I've
stated before, seems to have influenced (perhaps coincidentally)
various pronouncements about how conservative Python 3000 will be, at
least when compared to the expectations of the python-3000 mailing list
where various participants seem obsessed with reenacting 20th century
Types-SIG mailing list discussions and reproducing works with varying
degrees of similarity to the conclusions of that old activity:

http://www.python.org/community/sigs/retired/types-sig/

Note that links to the Types-SIG archives are broken on python.org, but
the archives are viewable via ASPN:

http://aspn.activestate.com/ASPN/Mail/Browse/Plain/types-sig/

Ultimately, and to the disappointment of a few people, Python 3000's
benefits may very well seem incremental, if only to avoid fracturing
the community.

Paul

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


Defining our own types?

2006-08-16 Thread Michael Yanowitz
Hello:

   I know this will probably turn about to be another dumb question
and I know I have asked a few really dumb ones lately on this list,
but I am hoping otherwise this time:

suppose I type:
ip = 123.45.67.89
  (no quotes)
- is it possible (maybe by catching an exception), to have this
automatically converted to an ip address and maybe have the exception
convert this into:
  ip = make_ip_address (123, 45, 67, 89)

   Or even better, if possible. Can I define my own type
IP = BYTE + '.' + BYTE + '.' + BYTE + '.' + BYTE
BYTE = in range(256)
  and have Python over-ride its rules so that if I type in a number
followed by a dot followed by number followed by a dot followed by a
number followed by a dot and another number, it can call
make_ip_address() on the value?

Thanks in advance:
Michael Yanowitz


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


Re: Defining our own types?

2006-08-16 Thread Steve Holden
Michael Yanowitz wrote:
> Hello:
> 
>I know this will probably turn about to be another dumb question
> and I know I have asked a few really dumb ones lately on this list,
> but I am hoping otherwise this time:
> 
> suppose I type:
> ip = 123.45.67.89
>   (no quotes)
> - is it possible (maybe by catching an exception), to have this
> automatically converted to an ip address and maybe have the exception
> convert this into:
>   ip = make_ip_address (123, 45, 67, 89)
> 
>Or even better, if possible. Can I define my own type
> IP = BYTE + '.' + BYTE + '.' + BYTE + '.' + BYTE
> BYTE = in range(256)
>   and have Python over-ride its rules so that if I type in a number
> followed by a dot followed by number followed by a dot followed by a
> number followed by a dot and another number, it can call
> make_ip_address() on the value?
> 
No, because the interpreter will raise a syntax error rather than 
compiling the code.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Printing n elements per line in a list

2006-08-16 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Dan Sommers  <[EMAIL PROTECTED]> wrote:
>Perhaps not the prettiest, but I can't think of anything simpler to read
>six months from now:
>
>counter = 0
>for an_element in the_list:
>print an_element,
>counter = counter + 1
>if counter == n:
>print
>counter = 0

for counter, an_element in enumerate(the_list):
print an_element,
if not (counter+1) % n:
print
# Plus the final print fixed in an earlier follow-up:
if len(the_list) % n:
print

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: what is the keyword "is" for?

2006-08-16 Thread Sion Arrowsmith
Simon Forman <[EMAIL PROTECTED]> wrote:
>Python 2.4.3 (#2, Apr 27 2006, 14:43:58)
>[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
>
>|>> a = b = 1e1000 / 1e1000
>|>> a is b
>True
>|>> a == b
>False

I agree with you:

$ python
Python 2.4.1 (#2, May  5 2005, 11:32:06)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = b = 1e1000 / 1e1000
>>> a is b
True
>>> a == b
False

Or maybe I don't:

$ python2.3
Python 2.3.5 (#2, Sep  4 2005, 22:01:42)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = b = 1e1000 / 1e1000
>>> a is b
True
>>> a == b
True

See:

http://mail.python.org/pipermail/python-bugs-list/2004-February/022133.html

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Printing n elements per line in a list

2006-08-16 Thread John Machin

Yu-Xi Lim wrote:
> John Machin wrote:
>
> > How did you avoid division when testing for leap year?
> >
>
> Well, you're testing for a modulus, not really a division, so a nasty hack:
>
> def isleapyear(year):
>   return not year&3
>
> works for 1901-2099.
>
> But programming like this causes all kinds of problems in future. Let's
> just hope there aren't too many 1MHz 8-bit computers left by then.

No, I meant a wider range, at least 1 <= year <= . And it's not
only 1MHz 8-bit computers where non-nasty division/modulus avoidance
hacks can come in handy -- IIRC the millicode for the 32-bit HP PA-RISC
architecture takes 32 divide-step instructions to do an unsigned 32-bit
division. Division is intrinsically relatively slow on most boxes, but
division by a non-power-of-2 constant can be sped up, and so can "x %
constant == 0". 

Cheers,
John

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


classes on GladeGen

2006-08-16 Thread Rafal Janas
Hi.

I create simple program using glade and GladeGen.
In main.py is main class and in wind.py is wind class.
In main class is entry1 and button1. When I click on button1 I open wind
class wind.Wind()
In wind class is entry1 field when I type some values and how can I send
this value to main class.
When I type main.Main().widgets['entry1'].set_text("something") it open
new class but I want do it in window which is open
How to do it?

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


Current module reference

2006-08-16 Thread Miguel Galves
HiHow do I get a reference for the current module I'm in ?I have a package called services with a __init__.pythat need to use getattr() to fill out a hash whithmy package attributes. But to use getattr, I need
a object that references my package (kind of this this reference in Java).How can I do it ? the only way I found to o this is to call get attr from anothermodule that imports the services package. But I suppose
it's not the only wayThanks for your helpMiguel-- Miguel Galves - Engenheiro de ComputaçãoJá leu meus blogs hoje? Para geeks http://log4dev.blogspot.com
Pra pessoas normaishttp://miguelgalves.blogspot.com"Não sabendo que era impossível, ele foi lá e fez..."
-- 
http://mail.python.org/mailman/listinfo/python-list

Optimization of __len__() in cgi.py

2006-08-16 Thread Bob Kline
I have a suggestion for speeding up the performance of code like this:

fields = cgi.FieldStorage()
if fields: ...

which, as it turns out, invokes FieldStorage.__len__(), which in turn
calls FieldStorage.keys(), which builds a list of keys by hand, taking
several minutes for large forms.  This implementation of keys() reduces
the amount of time taken by several orders of magnitude:

def keys(self):
return {}.fromkeys([i.name for i in self.list]).keys()

Is there a better place for submitting suggestions like this?

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


Re: Current module reference

2006-08-16 Thread Steve Holden
Miguel Galves wrote:
> Hi
> 
> How do I get a reference for the current module I'm in ?
> I have a package called services with a __init__.py
> that need to use getattr() to fill out a hash whith
> my package attributes. But to use getattr, I need
> a object that references my package (kind of this this reference in Java).
> How can I do it ?
> 
> the only way I found to o this is to call get attr from another
> module that imports the services package. But I suppose
> it's not the only way
> 
sys.modules[__name__] ?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: recommended general-purpose string template packages?

2006-08-16 Thread metaperl

vj wrote:
> I use preppy from reportlab:
>
> http://www.reportlab.org/preppy.html

wow. thanks for the link. I second you on pretty. It is ultra-simple
and nothing but a gateway to python.

also, reportlab makes a number of high-quality open source python
wares.

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


RE: What would be the best way to run python client in the background

2006-08-16 Thread Tim Golden
| > [gel]
| >
| > | I have written a python client server app [...]
| > | I want to run the client end of the app more or less invisibly
| > | (no console) on the XP clients when ever a users logs on.

While this isn't answering the question you first
asked, might I suggest an alternative approach?
Obviously, I'm working from no more than the sketch
you gave of your app and its requirements, but might
it be worth turning the problem on its head, and
using WMI?

Advantages:

1) WMI will -- almost certainly -- already be running on your
target machines. No need to install your own service.

2) WMI has a fair range of mechanisms for determining
what processes are starting, stopping, etc. and for
manipulating them remotely.

3) You can, at least in theory, access any number of machines
from a central server, and with a bit of judicious threading
or looping, you should be able to generate a fair bit of resilience
to machine dropouts etc.

Disadvantages:

1) What you're doing may be far more complex than you've
outlined, requiring a local service per target machine
for other reasons.

2) You may have already invested some amount of time and
effort in developing an app which does what you want.

3) I may have entirely misunderstood what you're trying
to do in any case.

If you're interested and want a code sample, let me know.
If you're not, that's fine.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: idea on how to get/set nested python dictionary values

2006-08-16 Thread metaperl

[EMAIL PROTECTED] wrote:

> | would use a recursive approach for this - given that you have a sort
> of recursive datastructure:
>
> py> def SetNewDataParam2(Data, NewData):
> ... if type(Data[Data.keys()[0]]) == type(dict()):
> ... SetNewDataParam2(Data[Data.keys()[0]], NewData)
> ... else:
> ... Data[Data.keys()[0]] = NewData
> ...

Data[Data.keys()[0]] is used 3 times in the above code. Is there some
way to factor out that usage? I'm just starting python but I'm always
on the lookout for DRY :)

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


Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Bob Kline wrote:

> I have a suggestion for speeding up the performance of code like this:
> 
> fields = cgi.FieldStorage()
> if fields: ...
> 
> which, as it turns out, invokes FieldStorage.__len__(), which in turn
> calls FieldStorage.keys(), which builds a list of keys by hand, taking
> several minutes for large forms.  This implementation of keys() reduces
> the amount of time taken by several orders of magnitude:
> 
> def keys(self):
> return {}.fromkeys([i.name for i in self.list]).keys()

This does not maintain the order of `self.list`.  Don't know if there's
code relying on this.

In a recent Python version one could use `set()` and a generator
expression::

return list(set(item.name for item in self.list))

But maybe it's even faster to change `FieldStorage.__len__()` to return
the length of `self.list` directly without the need to create an
intermediate list that's thrown away immediately.

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


Re: trying to reach kevin smith, author of plastex

2006-08-16 Thread Kevin Smith
On 2006-08-15 15:28:36 -0400, "metaperl" <[EMAIL PROTECTED]> said:

> Email to Kevin Smith regarding his plastex package failed. I hope he
> read this group. The tarball that he needs to reproduce the error is
> here:
> http://arc.livingcosmos.org/wolfram-fruit2/wolfram-fruit.tar.gz
> 
> Hi, when attempting to type plastex wolfram-fruit.tex on the attached
> latex document, I got some errors.

The main issue is that I hadn't implemented the wrapfig package yet.  
plasTeX tried to load it natively, but it was a bit too complicated.  
The good news is that it was very simple to implement in Python.  I've 
pushed my changes to the CVS repository, but I probably won't be 
creating a new release for a while.  If you need a fix right away, you 
can either check out the CVS project, or simply download the two needed 
files from the URLs below and copy them into your plasTeX installation. 
 BTW, thanks for the test case.

Copy to plasTeX/Packages/wrapfig.py
http://plastex.cvs.sourceforge.net/*checkout*/plastex/plastex/plasTeX/Packages/wrapfig.py?revision=1.1

Copy 

to plasTeX/Renderers/XHTML/wrapfig.zpts
http://plastex.cvs.sourceforge.net/*checkout*/plastex/plastex/plasTeX/Renderers/XHTML/wrapfig.zpts?revision=1.1

Kevin 

D. Smith

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


Re: round not rounding to 0 places

2006-08-16 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Tim Leslie <[EMAIL PROTECTED]> wrote:
>On 16 Aug 2006 00:19:24 -0700, Fuzzydave <[EMAIL PROTECTED]> wrote:
>> I have been using a round command in a few places to round
>> a value to zero decimal places using the following format,
>>
>> round('+value+', 0)
>>
>> but this consistantly returns the rounded result of the value
>> to one decimal place with a zero
>>
>> EG:
>>
>> 4.97 is returned as 5.0 when i want it returned as 5, does
>> anyone know why this is and if i can get the round to make
>> the value 5?
>
>round returns a float. You probably want to convert it to an int.
>
 int(round(4.97))
>5
.
.
.
I'm surprised no one has recommended

"%.0f" % 4.97
-- 
http://mail.python.org/mailman/listinfo/python-list


Adding a char inside path string

2006-08-16 Thread Hitesh
Hi,

I get path strings from a DB like:

\\serverName\C:\FolderName1\FolderName2\example.exe

I am writing a script that can give me access to that exe file.
But problem is that string is not universal path, I need to add C$.
Any idea how I can add $ char in that string.
ServerName is not fixed length. It could be any chars length.

Thank you,
hj

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


Re: Adding a char inside path string

2006-08-16 Thread Fredrik Lundh
"Hitesh" wrote:

> I get path strings from a DB like:
>
> \\serverName\C:\FolderName1\FolderName2\example.exe
>
> I am writing a script that can give me access to that exe file.
> But problem is that string is not universal path, I need to add C$.
> Any idea how I can add $ char in that string.
> ServerName is not fixed length. It could be any chars length.

upath = path.replace("C:", "C$")

 



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


Re: Defining our own types?

2006-08-16 Thread Kay Schluehr
Michael Yanowitz wrote:
> Hello:
>
>I know this will probably turn about to be another dumb question
> and I know I have asked a few really dumb ones lately on this list,
> but I am hoping otherwise this time:
>
> suppose I type:
> ip = 123.45.67.89
>   (no quotes)
> - is it possible (maybe by catching an exception), to have this
> automatically converted to an ip address and maybe have the exception
> convert this into:
>   ip = make_ip_address (123, 45, 67, 89)

This will fail already on the parser level. The tokenizer recogizes
'123.45' as a number as well as '.67' and '.89' and can't fit them
together to something meaningfull. So you must adapt the tokenizer to
accept '123.45.67.89' as a number and handle the corresponding NUMBER
token by visiting the syntax tree later on i.e. returning either a
NUMBER or a function call.

I've written a framework that lets you do this [1] but be aware that
you actually create a new language. Personally I don't think it's worth
the effort and would define an IP object instead:

ip = IP (123, 45, 67, 89)

and/or

ip = IP ("123.45.67.89")

Regards,
Kay

[1] http://www.fiber-space.de/EasyExtend/doc/EE.html

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


Re: Memory usage of an 'empty' python interpreter

2006-08-16 Thread Ant
> > Are you sure ps is reporting in bytes not KB? The bare interpreter in
> > Windows is 3368KB.
>
> Where did you get that from? With Python 2.4.3, on my machine (Win XP
> SP2):
>
> C:\junk>dir \python24\python*
> [snip]
> 29/03/2006  05:35 PM 4,608 python.exe
> 29/03/2006  05:35 PM 1,871,872 python24.dll
> 29/03/2006  05:35 PM 5,120 pythonw.exe

He's asking for the memory required, not the disk space used by the
exe. The 3368KB is reported by the Task Manager.

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


Re: programming with Python 3000 in mind

2006-08-16 Thread John Roth

[EMAIL PROTECTED] wrote:
> >> The current beta version of Python is 2.5 . How can a Python
> >> programmer minimize the number of changes that will be needed to run
> >> his code in Python 3000?
>
> Since we don't know what Python 3000 will look like yet (it's still in very
> early development), that is a question that can't be answered today.
>
> Skip

It may not be answerable precisely, but it most likely can
be answered in general terms. As far as I can tell, there is
one really major, overwhelmingly large change in 3.0, and
that is making the str class unicode, with the corresponding
elimination of the 8-bit string type in favor of a new bytes type.
That also implies lots of changes in the I/O classes as well.

In comparison, the elimination of the print statement is a
"so-what". It can be handled by a conversion program.

Most of the rest of the changes seem to be either forward
compatable or easily handable by a conversion program.
The change in the raise statement, for example, can
be handled right now.

John Roth

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


Re: inheritance?

2006-08-16 Thread KraftDiner

Steven D'Aprano wrote:
> On Tue, 15 Aug 2006 19:35:11 -0700, KraftDiner wrote:
>
> > I have two classes:
> >
> > class implicitClass:
> >def __init__(self):
> >def isIVR(self):  #This is a class private method.
>
> The convention is to flag classes as "private" with a leading underscore:
>
> def _isIVR(self):
>
> or double underscores for "really private, no, honestly":
>
> def __isIVR(self):
>
> but google on "python name mangling" before using that.
>
> [snip]
>
> > As you can see the interface is almost identical.
> >
> > How can I define a base class that will abstract
> > the type such that I don't know if its really and inplicit
> > or explicit object?
>
> Something like this?
>
>
> class baseClass:
>def __init__(self):
>raise NotImplementedError("Don't instantiate the base class!")
>def fromfile(self):
>def getElement(self):
># etc.
>
>
> class implicitClass(baseClass):
>def __init__(self):
># code
>def _isIVR(self):
># code
>def fromfile(self, fileObj, byteOrder):
># code
> # etc.
>
> Now, you can define instance = implicitClass() or explicitClass(). When
> you come to use instance, you don't need to know whether it is one or the
> other. If you need to type-test, call "isinstance(instance, baseClass)".
>
> The only minor issue is that the fromfile method has a different
> interface. If you really want to do duck typing, they need to have the
> same interface. That might be as simple as:
>
> class explicitClass(baseClass):
>def fromfile(self, fileObj, byteOrder=None):
># byteOrder is ignored; it is included only for
># compatibility with implicitClass
>
>
> Is that what you're asking for?
>
Yes I believe so but in fromfile I want to call the appropriate
method depending on the in a parameter in fromfile...
like:
class baseClass:
   def fromfile(self, fileObj, byteOrder=None, explicit=False):
  if explicit:
 call fromfile of explicit class
  else:
call fromfile of implicit class

How is that done?


> 
> 
> -- 
> Steven D'Aprano

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


Re: classes on GladeGen

2006-08-16 Thread davelist

On Aug 16, 2006, at 8:05 AM, Rafal Janas wrote:

> Hi.
>
> I create simple program using glade and GladeGen.
> In main.py is main class and in wind.py is wind class.
> In main class is entry1 and button1. When I click on button1 I open  
> wind
> class wind.Wind()
> In wind class is entry1 field when I type some values and how can I  
> send
> this value to main class.
> When I type main.Main().widgets['entry1'].set_text("something") it  
> open
> new class but I want do it in window which is open
> How to do it?


I assume you're referring to GladeGen that was in Linux Journal (July  
2004 I think) - I'm the person who wrote it.

main.Main() creates a new instance of the class, but you want to use  
the existing instance. A simple way around this is to pass the  
instance of the main class to the wind class when you create it.

Assuming you're in a method of the main class when you create it do  
something like:

self.wind = wind(self)

and then your wind constructor includes:

def __init__(self, main):

  self.main = main

and then in your wind method that you want to set the text entry, you  
write:

 self.main.widgets['entry1].set_text('something')

HTH,
Dave



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


Re: Error with: pickle.dumps(numpy.float32)

2006-08-16 Thread Iljya
I have reproduced the error with Numpy 1.0b1

The output with v.1.0b1 reads:
PicklingError: Can't pickle : it's not found as
__builtin__.float32scalar

Has anyone else encountered this?

Thanks,

Iljya

Iljya wrote:
> Hello,
>
> I need to pickle the type numpy.float32 but encounter an error when I
> try to do so. I am able to pickle the array itself, it is specifically
> the type that I cannot pickle.
>
> I am using:
> Numpy version: 0.9.4
> Python version: 2.4.3
> Windows XP
>
> Here is the code that reproduces the error:
> __
> import numpy
> import pickle
>
> pickle.dumps(numpy.float32)
>
> Output:
> PicklingError: Can't pickle : it's not found as
> __builtin__.float32_arrtype
> __
>
> Any suggestions would be much appreciated.
> 
> Thanks,
> 
> Iljya Kalai

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


Question on extracting doc strings from .py files

2006-08-16 Thread metaperl
If you type:
>>> import os; help(os)

Then you see the following (see below). But I don't understand where
the line
"MODULE DOCS
http://www.python.org/doc/current/lib/module-os.html
"

is encoded in os.py anywhere. If you search for the words
'module-os.html' you find
nothing. Ditto for 'MODULE DOCS'


--- output follows ---

Help on module os:

NAME
os - OS routines for Mac, DOS, NT, or Posix depending on what
system we're o
n.

FILE
/usr/lib/python2.4/os.py

MODULE DOCS
http://www.python.org/doc/current/lib/module-os.html

DESCRIPTION
This exports:
  - all functions from posix, nt, os2, mac, or ce, e.g. unlink,
stat, etc.
  - os.path is one of the modules posixpath, ntpath, or macpath
  - os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
  - os.curdir is a string representing the current directory ('.'
or ':')
  - os.pardir is a string representing the parent directory ('..'
or '::')

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


Re: what is the keyword "is" for?

2006-08-16 Thread Alex Martelli
Sybren Stuvel <[EMAIL PROTECTED]> wrote:

> Dan Bishop enlightened us with:
>  a = b = 1e1000 / 1e1000
>  a is b
> > True
>  a == b
> > False
> 
> If "a is b" then they refer to the same object, hence a == b. It
> cannot be otherwise, unless Python starts to defy logic. I copied your

Python also needs to respect standards (such as IEEE 754 for
floating-point arithmetic, and the SQL standards) which do specify the
existence of special objects that "are not equal to anything" including
themselves -- Nan and NULL respectively for these two standards.

We're talking about extremely widespread international standards
developed by huge body of professionals which do include professional
logicians, so I doubt they "defy logic".  Python tries to delegate FP to
the underlying hardware and SQL to an external relational DB engine, so
it should be as compliant as the pieces of infrastructure it's using --
which seems to me to be a good architectural decision (not just for
speed and ease of coding, but to ensure any anomaly is somebody else's
fault:-).


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


How to delete a directory tree in FTP

2006-08-16 Thread T
I connect to a FTP server which can be either unix or windows server.
Once in the FTP session, I would like to delete a directory tree on the
server.  Is there a command that will do this?  If not, can someone
point me to a right direction?

Thanks!

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


Re: Question on extracting doc strings from .py files

2006-08-16 Thread Fredrik Lundh
metaperl wrote:

 import os; help(os)
> 
> Then you see the following (see below). But I don't understand where
> the line
> "MODULE DOCS
> http://www.python.org/doc/current/lib/module-os.html
> "
> 
> is encoded in os.py anywhere. If you search for the words
> 'module-os.html' you find nothing. Ditto for 'MODULE DOCS'

try searching for 'www.python.org/doc/current'



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


Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Georg Brandl
Bob Kline wrote:
> I have a suggestion for speeding up the performance of code like this:
> 
> fields = cgi.FieldStorage()
> if fields: ...
> 
> which, as it turns out, invokes FieldStorage.__len__(), which in turn
> calls FieldStorage.keys(), which builds a list of keys by hand, taking
> several minutes for large forms.  This implementation of keys() reduces
> the amount of time taken by several orders of magnitude:
> 
> def keys(self):
> return {}.fromkeys([i.name for i in self.list]).keys()
> 
> Is there a better place for submitting suggestions like this?

Post a RFE to the Python Tracker at 
http://sourceforge.net/tracker/?group_id=5470&atid=355470

If you want, assign it to me (gbrandl).

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


Re: idea on how to get/set nested python dictionary values

2006-08-16 Thread [EMAIL PROTECTED]

metaperl wrote:
> [EMAIL PROTECTED] wrote:
>
> > | would use a recursive approach for this - given that you have a sort
> > of recursive datastructure:
> >
> > py> def SetNewDataParam2(Data, NewData):
> > ... if type(Data[Data.keys()[0]]) == type(dict()):
> > ... SetNewDataParam2(Data[Data.keys()[0]], NewData)
> > ... else:
> > ... Data[Data.keys()[0]] = NewData
> > ...
>
> Data[Data.keys()[0]] is used 3 times in the above code. Is there some
> way to factor out that usage? I'm just starting python but I'm always
> on the lookout for DRY :)

Bearophilehugs gave a much better answer than I did, it also takes away
the need to evaluate the keys() more than one time

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


QListView and text

2006-08-16 Thread Vojta Drbohlav
Hello,
Can I get all text from first column in QListView? How?

PS. Sorry for my bad English ;)

Than you, Vojta
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Bob Kline
Marc 'BlackJack' Rintsch wrote:
>> def keys(self):
>> return {}.fromkeys([i.name for i in self.list]).keys()
> 
> This does not maintain the order of `self.list`.  Don't know if there's
> code relying on this.

Such code would be flying in the face of an implication that the order
of the keys is *not* preserved, as the keys() method is documented as
"Dictionary style keys() method" (and the documentation for dictionary
keys() says "... listed in an arbitrary order which is non-random ...").

If it were decided that the behavior of keys() should be preserved even
to the extent of preserving the order of the first occurrence of each
field name, then the optimization could just be moved to __len__():

def __len__(self):
return len({}.fromkeys([i.name for i in self.list]))

> But maybe it's even faster to change `FieldStorage.__len__()` to return
> the length of `self.list` directly without the need to create an
> intermediate list that's thrown away immediately.

This approach also risks breaking code that assumes it's getting the
number of unique field names (an assumption which in this case would be
justified, given the documentation of the keys() method quoted above).

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


Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Bob Kline
Sybren Stuvel wrote:
> FieldStorage.__nonzero__ tried first if it exists. You might want to
> use that for more optimization.

Excellent suggestion!  It would be nice if this were adopted to
supplement the original optimization, rather than replace it.

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


Re: Adding a char inside path string

2006-08-16 Thread Hitesh

Thank you Fredrik. That works for a string.
But I am getting list of tuples from DB.

rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',),
('\\serverName\C:\FolderName1\FolderName2\example2.exe',),
('\\serverName\C:\FolderName1\FolderName2\example3.exe',),
('\\serverName\C:\FolderName1\FolderName2\example4.exe',)]

I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path

I am getting path something like

('\\serverName\c$:\FolderName1\FolderName2\example.exe',)

How on the earth I can remove those paranthesis?

ty
hj

Fredrik Lundh wrote:
> "Hitesh" wrote:
>
> > I get path strings from a DB like:
> >
> > \\serverName\C:\FolderName1\FolderName2\example.exe
> >
> > I am writing a script that can give me access to that exe file.
> > But problem is that string is not universal path, I need to add C$.
> > Any idea how I can add $ char in that string.
> > ServerName is not fixed length. It could be any chars length.
> 
> upath = path.replace("C:", "C$")
> 
> 

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


python-dev and setting up setting up f2py on Windows XP

2006-08-16 Thread Sile
Hi,

I've been trying to get f2py working on Windows XP, I am using Python
2.3. I'm new to python so I'm not too sure what I'm doing yet. I need
the python-dev package to run f2py. I have been told this is just the
header files and .dll and I need to put them somewhere my C compiler
can find them. I've searched the web and none of the python-dev
packages I've found are for windows. I was wondering is this
automatically part of the windows version and if so how I set it up so
my C compiler can find them. If it is not part of the standard package
does anyone know where I can find it???

Any help at all would be much appreciated.
Thanks,
Sile

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


Re: inheritance?

2006-08-16 Thread infidel
> Yes I believe so but in fromfile I want to call the appropriate
> method depending on the in a parameter in fromfile...
> like:
> class baseClass:
>def fromfile(self, fileObj, byteOrder=None, explicit=False):
>   if explicit:
>  call fromfile of explicit class
>   else:
> call fromfile of implicit class

class baseClass:
def fromfile(self, fileObj, **kwargs):
raise NotImplementedError()

class implicitClass:
def fromfile(self, fileObj, **kwargs):
byteOrder = kwargs.get('byteOrder', None)
# do something

class explicitClass:
def fromfile(self, fileObj, **kwargs):
# do something

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


Re: QListView and text

2006-08-16 Thread Phil Thompson
On Wednesday 16 August 2006 4:43 pm, Vojta Drbohlav wrote:
> Hello,
> Can I get all text from first column in QListView? How?
>
> PS. Sorry for my bad English ;)
>
> Than you, Vojta

Assuming you are talking about PyQt v3 rather than v4 then use the 
columnText() method.

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


QListView and text

2006-08-16 Thread Vojta Drbohlav
Oh, sorry. I explained it bad.

I use PyQt3 and I need text from all rows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a char inside path string

2006-08-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Hitesh wrote:

> That works for a string.
> But I am getting list of tuples from DB.
> 
> rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',),
> ('\\serverName\C:\FolderName1\FolderName2\example2.exe',),
> ('\\serverName\C:\FolderName1\FolderName2\example3.exe',),
> ('\\serverName\C:\FolderName1\FolderName2\example4.exe',)]
> 
> I tried this:
> for i in rows:
> row = str(i)
> path = row.replace("C:" , "c$")
> print path
> 
> I am getting path something like
> 
> ('\\serverName\c$:\FolderName1\FolderName2\example.exe',)
> 
> How on the earth I can remove those paranthesis?

Well, don't convert the tuple to a string but get the string out of the
tuple instead.

for row in rows:
path = row[0].replace('C:', 'C$')
print path

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


Re: QListView and text

2006-08-16 Thread Phil Thompson
On Wednesday 16 August 2006 5:29 pm, Vojta Drbohlav wrote:
> Oh, sorry. I explained it bad.
>
> I use PyQt3 and I need text from all rows.

row = listView.firstChild()

while row:
for col in range(listView.columns()):
text = row.text(col)

row = row.nextSibling()

...or something like that.

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


Re: Adding a char inside path string

2006-08-16 Thread Tim Williams
On 16/08/06, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 16 Aug 2006 09:00:57 -0700, "Hitesh" <[EMAIL PROTECTED]> declaimed
> the following in comp.lang.python:
>
> >
> > Thank you Fredrik. That works for a string.
> > But I am getting list of tuples from DB.
> >
> > rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',),
> > ('\\serverName\C:\FolderName1\FolderName2\example2.exe',),
> > ('\\serverName\C:\FolderName1\FolderName2\example3.exe',),
> > ('\\serverName\C:\FolderName1\FolderName2\example4.exe',)]
> >
> > I tried this:
> > for i in rows:
> > row = str(i)
> > path = row.replace("C:" , "c$")
> > print path
> >
> > I am getting path something like
> >
> > ('\\serverName\c$:\FolderName1\FolderName2\example.exe',)
> >
> > How on the earth I can remove those paranthesis?
> >
> By accessing the contents of the tuple, not the tuple itself
>
> >>> rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',),
>  ('\\serverName\C:\FolderName1\FolderName2\example2.exe',),
>  ('\\serverName\C:\FolderName1\FolderName2\example3.exe',),
>  ('\\serverName\C:\FolderName1\FolderName2\example4.exe',)]
> >>> rows
> [('\\serverName\\C:\\FolderName1\\FolderName2\\example.exe',),
> ('\\serverName\\C:\\FolderName1\\FolderName2\\example2.exe',),
> ('\\serverName\\C:\\FolderName1\\FolderName2\\example3.exe',),
> ('\\serverName\\C:\\FolderName1\\FolderName2\\example4.exe',)]
> >>> modRows = [itm[0].replace("C:", "C$") for itm in rows]
> >>> modRows
> ['\\serverName\\C$\\FolderName1\\FolderName2\\example.exe',
> '\\serverName\\C$\\FolderName1\\FolderName2\\example2.exe',
> '\\serverName\\C$\\FolderName1\\FolderName2\\example3.exe',
> '\\serverName\\C$\\FolderName1\\FolderName2\\example4.exe']
> >>>

Try

modRows = ['\\'+itm[0].replace(":", "$") for itm in rows]

It will work with any drive letter and makes an allowance for the
first escape character.

>>> modRows
['serverName\\C$\\FolderName1\\FolderName2\\example.exe',
'serverName\\C$\\FolderName1\\FolderName2\\example2.exe',
etc

for r in modRows:
print r

\\serverName\C$\FolderName1\FolderName2\example.exe
\\serverName\C$\FolderName1\FolderName2\example2.exe
..etc


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


ELAN IT - Python Developer - South East

2006-08-16 Thread Jan de Swart
A successful company with global ties is seeking a Software Developer to
work at their site in Reading.  As a company they are expanding fast and
want good developers to join and progress with them, offering the
opportunity for a successful career. My client is a market leading provider
of B2B software who will offer expert training to ensure their staff are the
best at what they do.

They are looking for a candidate with at least 2 years programming
experience in either java, JavaScript, c++, or python.  The right candidates
will be highly technical and have a desire to programme in Python.  

They are a highly progressive team and work in a dynamic environment.  

Please send CV for further details.

£Competitive Salary£ plus excellent benefits and progression






Jan de Swart 

Elan IT | 1st Floor New Minster House
27 - 29 Baldwin Street | Bristol, BS1 1LT   
Tel:01179309737 
Fax:01179304205 
'Recruitment Consultancy of the Year 2003 & 2004' - 'Computing Awards for
Excellence' 
Candidate Attraction Reward Scheme 
Do you have a friend or colleague that is looking for a new position? If so,
please pass their details onto Elan and we will reward you with Virgin
Vouchers when we successfully place them in a permanent position or on a
contract assignment (Terms and Conditions apply). For more information on
Virgin Vouchers please visit:- www.virgin.com/virginvoucher

 


- -
Elan is the world's leading IT&T recruitment company. For more information go 
to www.ElanIT.com.

- -
The contents of this email and any attachment are confidential to the addressee 
and are intended solely for the addressee's use.  If you are not the addressee, 
you have received this email in error.  If so, you must not disclose, copy or 
take any action in reliance on this email and any attachment.  If you received 
this in error, please contact the sender and delete the material from your 
computer.  

Although this email and any attachment have been checked for viruses, no 
liability is accepted by Elan in this regard.  The recipient should carry out 
virus and other checks as it deems necessary to ensure that this email and any 
attachments will not adversely affect its systems or data.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: X windows and Python?

2006-08-16 Thread Paul Rubin
Grant Edwards <[EMAIL PROTECTED]> writes:
> The way (well, _one_ way) it's supposed to work is you make an
> Xlib call to claim ownership of "the selection". ...

Thanks, this explanation was very interesting.  It would be great if
tkinter had some calls to do this stuff, which I guess means the
underlying Tk needs them (I dunno if it has them).  Anyway, for what I
was doing, it wasn't that urgent, and I'm using an awful workaround.
-- 
http://mail.python.org/mailman/listinfo/python-list


profanity filter

2006-08-16 Thread Ronny Abraham
Hi guys,

does anyone have any idea where I can find a profanity filter written in python?

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

Re: Error with: pickle.dumps(numpy.float32)

2006-08-16 Thread Ziga Seilnacht
Iljya wrote:
> I have reproduced the error with Numpy 1.0b1
>
> The output with v.1.0b1 reads:
> PicklingError: Can't pickle : it's not found as
> __builtin__.float32scalar
>
> Has anyone else encountered this?
>
> Thanks,
>
> Iljya
>
> Iljya wrote:
> > Hello,
> >
> > I need to pickle the type numpy.float32 but encounter an error when I
> > try to do so. I am able to pickle the array itself, it is specifically
> > the type that I cannot pickle.
> >
> > I am using:
> > Numpy version: 0.9.4
> > Python version: 2.4.3
> > Windows XP
> >
> > Here is the code that reproduces the error:
> > __
> > import numpy
> > import pickle
> >
> > pickle.dumps(numpy.float32)
> >
> > Output:
> > PicklingError: Can't pickle : it's not found as
> > __builtin__.float32_arrtype
> > __
> >
> > Any suggestions would be much appreciated.
> >
> > Thanks,
> >
> > Iljya Kalai

This looks like a numpy bug. It seems that float32_arrtype's name is
incomplete. Its tp_name field should start with a module name, but
since it doesn't, Python assumes that it is a builtin type:

>>> import numpy
>>> numpy.float32.__module__
'__builtin__'

You should report this bug either to the numpy list:
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

or to their bug tracker:
http://projects.scipy.org/scipy/numpy

Ziga

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


Re: Adding a char inside path string

2006-08-16 Thread Hitesh

Thank you all it worked!.

Tim,

> modRows = ['\\'+itm[0].replace(":", "$") for itm in rows]

What are those two forward slashes for?
I had to remove them otherwise I was getting output like '\\'
inside list or if I print I was getting like \\\

Thanks,
hj


Tim Williams wrote:
> On 16/08/06, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> > On 16 Aug 2006 09:00:57 -0700, "Hitesh" <[EMAIL PROTECTED]> declaimed
> > the following in comp.lang.python:
> >
> > >
> > > Thank you Fredrik. That works for a string.
> > > But I am getting list of tuples from DB.
> > >
> > > rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',),
> > > ('\\serverName\C:\FolderName1\FolderName2\example2.exe',),
> > > ('\\serverName\C:\FolderName1\FolderName2\example3.exe',),
> > > ('\\serverName\C:\FolderName1\FolderName2\example4.exe',)]
> > >
> > > I tried this:
> > > for i in rows:
> > > row = str(i)
> > > path = row.replace("C:" , "c$")
> > > print path
> > >
> > > I am getting path something like
> > >
> > > ('\\serverName\c$:\FolderName1\FolderName2\example.exe',)
> > >
> > > How on the earth I can remove those paranthesis?
> > >
> > By accessing the contents of the tuple, not the tuple itself
> >
> > >>> rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',),
> >  ('\\serverName\C:\FolderName1\FolderName2\example2.exe',),
> >  ('\\serverName\C:\FolderName1\FolderName2\example3.exe',),
> >  ('\\serverName\C:\FolderName1\FolderName2\example4.exe',)]
> > >>> rows
> > [('\\serverName\\C:\\FolderName1\\FolderName2\\example.exe',),
> > ('\\serverName\\C:\\FolderName1\\FolderName2\\example2.exe',),
> > ('\\serverName\\C:\\FolderName1\\FolderName2\\example3.exe',),
> > ('\\serverName\\C:\\FolderName1\\FolderName2\\example4.exe',)]
> > >>> modRows = [itm[0].replace("C:", "C$") for itm in rows]
> > >>> modRows
> > ['\\serverName\\C$\\FolderName1\\FolderName2\\example.exe',
> > '\\serverName\\C$\\FolderName1\\FolderName2\\example2.exe',
> > '\\serverName\\C$\\FolderName1\\FolderName2\\example3.exe',
> > '\\serverName\\C$\\FolderName1\\FolderName2\\example4.exe']
> > >>>
>
> Try
>
> modRows = ['\\'+itm[0].replace(":", "$") for itm in rows]
>
> It will work with any drive letter and makes an allowance for the
> first escape character.
>
> >>> modRows
> ['serverName\\C$\\FolderName1\\FolderName2\\example.exe',
> 'serverName\\C$\\FolderName1\\FolderName2\\example2.exe',
> etc
>
> for r in modRows:
> print r
>
> \\serverName\C$\FolderName1\FolderName2\example.exe
> \\serverName\C$\FolderName1\FolderName2\example2.exe
> ..etc
> 
> 
> :)

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


Re: profanity filter

2006-08-16 Thread skip

Ronny> does anyone have any idea where I can find a profanity filter
Ronny> written in python?

No, but maybe SpamBayes (or a tiny little part of it) would suit your
needs.  Do you want to remove profanity and let the document (email, web
page, etc) pass, just score if for profanity or block it altogether?

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


Re: inheritance?

2006-08-16 Thread John Henry
As others pointed out already, this kind of "if then else"
determination of type is best avoided.

If it looks like a duck, quakes like a duck, must be a duck.

KraftDiner wrote:
> Steven D'Aprano wrote:
> > On Tue, 15 Aug 2006 19:35:11 -0700, KraftDiner wrote:
> >
> > > I have two classes:
> > >
> > > class implicitClass:
> > >def __init__(self):
> > >def isIVR(self):  #This is a class private method.
> >
> > The convention is to flag classes as "private" with a leading underscore:
> >
> > def _isIVR(self):
> >
> > or double underscores for "really private, no, honestly":
> >
> > def __isIVR(self):
> >
> > but google on "python name mangling" before using that.
> >
> > [snip]
> >
> > > As you can see the interface is almost identical.
> > >
> > > How can I define a base class that will abstract
> > > the type such that I don't know if its really and inplicit
> > > or explicit object?
> >
> > Something like this?
> >
> >
> > class baseClass:
> >def __init__(self):
> >raise NotImplementedError("Don't instantiate the base class!")
> >def fromfile(self):
> >def getElement(self):
> ># etc.
> >
> >
> > class implicitClass(baseClass):
> >def __init__(self):
> ># code
> >def _isIVR(self):
> ># code
> >def fromfile(self, fileObj, byteOrder):
> ># code
> > # etc.
> >
> > Now, you can define instance = implicitClass() or explicitClass(). When
> > you come to use instance, you don't need to know whether it is one or the
> > other. If you need to type-test, call "isinstance(instance, baseClass)".
> >
> > The only minor issue is that the fromfile method has a different
> > interface. If you really want to do duck typing, they need to have the
> > same interface. That might be as simple as:
> >
> > class explicitClass(baseClass):
> >def fromfile(self, fileObj, byteOrder=None):
> ># byteOrder is ignored; it is included only for
> ># compatibility with implicitClass
> >
> >
> > Is that what you're asking for?
> >
> Yes I believe so but in fromfile I want to call the appropriate
> method depending on the in a parameter in fromfile...
> like:
> class baseClass:
>def fromfile(self, fileObj, byteOrder=None, explicit=False):
>   if explicit:
>  call fromfile of explicit class
>   else:
> call fromfile of implicit class
> 
> How is that done?
> 
> 
> > 
> > 
> > -- 
> > Steven D'Aprano

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


Re: Open file handles?

2006-08-16 Thread Hari Sekhon




danielx wrote:

  Is there an equivalent in windows?

Jon wrote:
  
  
Perhaps using os you could work with lsof
[http://www.linuxcommand.org/man_pages/lsof8.html]

Jon

Thomas Bartkus wrote:


  This may be more of a Linux question, but I'm doing this from Python. .

How can I know if anything (I don't care who or what!) is in the middle of
using a particular file?

This comes in context of needing to copy a file BUT only if I can verify
that something else doesn't have an open write handle to that file.  IOW - I
need to decline the operation if something else hasn't finished writing to
the file.

How can I know?
Thomas Bartkus
  

  
  
  


yes, handle by sysinternals. 

www.sysinternals.com

not really a python question, more along the lines of bash, which is
why I could answer it

-h




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

Re: os.path.normpath

2006-08-16 Thread Hari Sekhon




[EMAIL PROTECTED] wrote:

  [EMAIL PROTECTED] wrote:
  
  
I am using a windows box and passing a string like "../foo/../foo2" to
normpath which then returns "..\\foo2". But if this string is going
into a webpage link it should really be "../foo".

Is there any way to tell os.path.normpath to act like we are an a unix
style box?

  
  
Use posixpath.normpath() instead.

  

I can't seem to find posixpath in the docs, but I can import posixpath
and a dir shows it does indeed have a normpath.

-h



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

Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Bob Kline
Georg Brandl wrote:
> Post a RFE to the Python Tracker at
> http://sourceforge.net/tracker/?group_id=5470&atid=355470
> 
> If you want, assign it to me (gbrandl).

Done, thanks.

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


Re: QListView and text

2006-08-16 Thread Vojta Drbohlav
Thank you very much.
How can I move slected item up?
This is no work:

sel = list.currentItem()
sel.moveItem(sel.itemAbove())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: inheritance?

2006-08-16 Thread KraftDiner

Steven D'Aprano wrote:
> On Tue, 15 Aug 2006 19:35:11 -0700, KraftDiner wrote:
>
> > I have two classes:
> >
> > class implicitClass:
> >def __init__(self):
> >def isIVR(self):  #This is a class private method.
>
> The convention is to flag classes as "private" with a leading underscore:
>
> def _isIVR(self):
>
> or double underscores for "really private, no, honestly":
>
> def __isIVR(self):
>
> but google on "python name mangling" before using that.
>
> [snip]
>
> > As you can see the interface is almost identical.
> >
> > How can I define a base class that will abstract
> > the type such that I don't know if its really and inplicit
> > or explicit object?
>
> Something like this?
>
>
> class baseClass:
>def __init__(self):
>raise NotImplementedError("Don't instantiate the base class!")
>def fromfile(self):
>def getElement(self):
># etc.
>
>
> class implicitClass(baseClass):
>def __init__(self):
># code
>def _isIVR(self):
># code
>def fromfile(self, fileObj, byteOrder):
># code
> # etc.
>
> Now, you can define instance = implicitClass() or explicitClass(). When
> you come to use instance, you don't need to know whether it is one or the
> other. If you need to type-test, call "isinstance(instance, baseClass)".
>
> The only minor issue is that the fromfile method has a different
> interface. If you really want to do duck typing, they need to have the
> same interface. That might be as simple as:
>
> class explicitClass(baseClass):
>def fromfile(self, fileObj, byteOrder=None):
># byteOrder is ignored; it is included only for
># compatibility with implicitClass
>
>
> Is that what you're asking for?
>
>
Here I tried this example and maybe this will explain the difficulties
I'm having.
1) at the time the baseClass is constructed shouldn't the constructor
of the appropriate
type be called.
2) getName is doing nothing...

class baseClass:
def __init__(self):
pass
def fromfile(self, str):
if (str == 'A'):
a = typeA()
else:
a = typeB()
def getName(self):
pass

class typeA(baseClass):
def __init__(self):
self.name='A'
print 'typeA init'
def fromfile(self, str=None):
print 'typeA fromfile'
def getName(self):
print self.name

class typeB(baseClass):
def __init__(self):
self.name='B'
print 'typeB init'
def fromfile(self, str=None):
print 'typeB fromfile'
def getName(self):
print self.name

bc = baseClass()
bc.fromfile('A')
bc.getName()
bc.fromfile('B')
bc.getName()
bc.getName()

log:
typeA init
typeB init






> 
> -- 
> Steven D'Aprano

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


Re: python-dev and setting up setting up f2py on Windows XP

2006-08-16 Thread [EMAIL PROTECTED]
I'm really not familiar with the package you are trying to use, nor
that familiar with what you get on windows.  I would guess you did a
binary installation download, and you may need to get the python source
tarball instead - in order to get the files you need.

Barring that, I'm certain the headers are available through
sourceforge, they provide svn access for building python itself:  more
info @:

http://www.python.org/dev/faq/

Hope this helps.

Anand

Sile wrote:
> Hi,
>
> I've been trying to get f2py working on Windows XP, I am using Python
> 2.3. I'm new to python so I'm not too sure what I'm doing yet. I need
> the python-dev package to run f2py. I have been told this is just the
> header files and .dll and I need to put them somewhere my C compiler
> can find them. I've searched the web and none of the python-dev
> packages I've found are for windows. I was wondering is this
> automatically part of the windows version and if so how I set it up so
> my C compiler can find them. If it is not part of the standard package
> does anyone know where I can find it???
> 
> Any help at all would be much appreciated.
> Thanks,
> Sile

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


Re: profanity filter

2006-08-16 Thread skip

Ronny> replacement of profanity would be good, like * or so.  It's
Ronny> for a website as opposed to checking email.  Can SpamBayes be
Ronny> applied to comments or strings within a program?

SpamBayes scores inputs which look like emails (header, blank line, body).
All it does is add its score to the headers.  You'd still have to elide the
profanity encountered.  If you have a fixed list of profane words or phrases
it would probably just be easier to replace them with "***" using a (set of)
regular expression(s).

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


Segmentation Fault using MySQLdb and twisted

2006-08-16 Thread jgarber
Hello,

I just upgraded MySQLdb to the 1.2.0 version provided by Redhat
Enterprise Linux ES4.  At that point I began to get segfaults when
importing twisted after MySQLdb, but not before.

--
RedHat Enterprise Linux ES 4 (fully updated)
Python 2.3.4
mysql-python (MySQLdb) version 1.2.0
twisted version 2.4.0
--

For example:

[EMAIL PROTECTED] ~]$ python
Python 2.3.4 (#1, Feb  6 2006, 10:38:46)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> import twisted
Segmentation fault

[EMAIL PROTECTED] ~]$ python
Python 2.3.4 (#1, Feb  6 2006, 10:38:46)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import twisted
>>> import MySQLdb
>>>

Any ideas?

Thanks!
Jason Garber

---
Here is the gdb backtrace of the event:

[EMAIL PROTECTED] zcore]$ gdb python
GNU gdb Red Hat Linux (6.3.0.0-1.96rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i386-redhat-linux-gnu"...(no debugging
symbols found)
Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) run
Starting program: /usr/bin/python
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread -1208486208 (LWP 4302)]
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
Python 2.3.4 (#1, Feb  6 2006, 10:38:46)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
>>> import MySQLdb
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
>>> import twisted
(no debugging symbols found)

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208486208 (LWP 4302)]
0x00b849f8 in strcmp () from /lib/tls/libc.so.6
(gdb) bt
#0  0x00b849f8 in strcmp () from /lib/tls/libc.so.6
#1  0x00494e9d in OBJ_NAME_new_index () from /lib/libcrypto.so.4
#2  0x0049122f in lh_free () from /lib/libcrypto.so.4
#3  0x004914ff in lh_insert () from /lib/libcrypto.so.4
#4  0x00495075 in OBJ_NAME_add () from /lib/libcrypto.so.4
#5  0x00499405 in EVP_add_cipher () from /lib/libcrypto.so.4
#6  0x00590bc7 in SSL_library_init () from /lib/libssl.so.4
#7  0x00969294 in init_ssl () from
/usr/lib/python2.3/lib-dynload/_ssl.so
#8  0x00d140f9 in _PyImport_LoadDynamicModule () from
/usr/lib/libpython2.3.so.1.0
#9  0x00d11ea5 in PyImport_ImportFrozenModule () from
/usr/lib/libpython2.3.so.1.0
#10 0x00d12303 in PyImport_ImportFrozenModule () from
/usr/lib/libpython2.3.so.1.0
#11 0x00d12535 in PyImport_ImportFrozenModule () from
/usr/lib/libpython2.3.so.1.0
#12 0x00d1299a in PyImport_ImportModuleEx () from
/usr/lib/libpython2.3.so.1.0
#13 0x00cf1dee in _PyUnicodeUCS4_IsAlpha () from
/usr/lib/libpython2.3.so.1.0
#14 0x00cca961 in PyCFunction_Call () from /usr/lib/libpython2.3.so.1.0
#15 0x00ca7637 in PyObject_Call () from /usr/lib/libpython2.3.so.1.0
#16 0x00cf92a0 in PyEval_CallObjectWithKeywords () from
/usr/lib/libpython2.3.so.1.0
#17 0x00cfaca7 in _PyEval_SliceIndex () from
/usr/lib/libpython2.3.so.1.0
#18 0x00cff196 in PyEval_EvalCodeEx () from
/usr/lib/libpython2.3.so.1.0
#19 0x00cff45d in PyEval_EvalCode () from /usr/lib/libpython2.3.so.1.0
#20 0x00d107db in PyImport_ExecCodeModuleEx () from
/usr/lib/libpython2.3.so.1.0
#21 0x00d10c0d in PyImport_ExecCodeModule () from
/usr/lib/libpython2.3.so.1.0
#22 0x00d11e81 in PyImport_ImportFrozenModule () from
/usr/lib/libpython2.3.so.1.0
#23 0x00d12303 in PyImport_ImportFrozenModule () from
/usr/lib/libpython2.3.so.1.0
#24 0x00d12571 in PyImport_ImportFrozenModule () from
/usr/lib/libpython2.3.so.1.0
#25 0x00d1299a in PyImport_ImportModuleEx () from
/usr/lib/libpython2.3.so.1.0
#26 0x00cf1dee in _PyUnicodeUCS4_IsAlpha () from
/usr/lib/libpython2.3.so.1.0
#27 0x00cca961 in PyCFunction_Call () from /usr/lib/libpython2.3.so.1.0
#28 0x00ca7637 in PyObject_Call () from /usr/lib/libpython2.3.so.1.0
#29 0x00cf92a0 in PyEval_CallObjectWithKeywords () from
/usr/lib/libpython2.3.so.1.0
#30 0x00cfaca7 in _PyEval_SliceIndex ()

It is __del__ calling twice for some instances?

2006-08-16 Thread Max Yuzhakov
Hello!

It is correct behaviour for python to call __del__ on some
identity of a class object more than once?

In brief I shall describe a situation. Sorry for my english.

For debugin purposes I'm put in my module global counters
for counting __init__ and __del__ calls.

This is a sample code for clearness:
---
init_cnt = 0
del_cnt = 0

class foo:
def __init__(self):
global init_cnt
init_cnt += 1

def __del__(self):
global del_cnt
del_cnt += 1

def stat():
print "init_cnt = %d" % init_cnt
print "del_cnt = %d" % del_cnt
print "difference = %d" % init_cnt-del_cnt
---
And the result of a stat() call in some moment of time
looks like so:

init_cnt = 6233
del_cnt = 6234
difference = -1

It is __del__ called twice for some instance?

Thanks in advance!
-- 
GMT More Then ...
-- 
http://mail.python.org/mailman/listinfo/python-list


trouble understanding inheritance...

2006-08-16 Thread KraftDiner
This is not working the way I think it should
it would appear that fromfile and getName are calling the baseClass
methods which are
simple passes What have I done wrong?

class baseClass:
def __init__(self, type):
if type == 'A':
self = typeA()
else:
self = typeB()
def fromfile(self):
pass
def getName(self):
pass

class typeA(baseClass):
def __init__(self):
self.name='A'
print 'typeA init'
def fromfile(self):
print 'typeA fromfile'
def getName(self):
print self.name

class typeB(baseClass):
def __init__(self):
self.name='B'
print 'typeB init'
def fromfile(self):
print 'typeB fromfile'
def getName(self):
print self.name

a = baseClass('A')
a.fromfile()
a.getName()

b = baseClass('B')
b.fromfile()
b.getName()

log:
typeA init
typeB init

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


Re: It is __del__ calling twice for some instances?

2006-08-16 Thread Max Yuzhakov
Max Yuzhakov writes:

 MY>  print "difference = %d" % init_cnt-del_cnt

Little correction.

  print "difference = %d" % (init_cnt-del_cnt)
-- 
GMT More Then ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Problems with Sizers

2006-08-16 Thread Mario Lacunza
Hello,

I have troubbles in this code when I try to resize the form, all the
widgets dont move. 

Any idea? 

Thansk in advance!


-
# -*- coding: utf8 -*-#
#Boa:Dialog:frmPostales

import wx
#import modGlobals
#from Conectar import Conectar
#import errores

def create(parent):
return frmPostales(parent)

[wxID_FRMPOSTALES, wxID_FRMPOSTALESBTNCANCELAR, wxID_FRMPOSTALESBTNOK, 
 wxID_FRMPOSTALESCBODISTRI, wxID_FRMPOSTALESCBODPTO,
wxID_FRMPOSTALESCBOPAIS, 
 wxID_FRMPOSTALESCBOPROV, wxID_FRMPOSTALESLBLCOD,
wxID_FRMPOSTALESLBLDISTRO, 
 wxID_FRMPOSTALESLBLDPTO, wxID_FRMPOSTALESLBLPAIS,
wxID_FRMPOSTALESLBLPOSTAL, 
 wxID_FRMPOSTALESLBLPROV, 
] = [wx.NewId() for _init_ctrls in range(13)]

class frmPostales(wx.Dialog):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Dialog.__init__(self, id=wxID_FRMPOSTALES,
name=u'frmPostales',
  parent=prnt, pos=wx.Point(579, 295), size=wx.Size(254,
197),
  style=wx.DEFAULT_FRAME_STYLE, title=u'C\xf3digos
Postales')
self.SetClientSize(wx.Size(254, 197))

self.btnOk = wx.Button(id=wxID_FRMPOSTALESBTNOK,
label=u'Aceptar',
  name=u'btnOk', parent=self, pos=wx.Point(28, 148),
  size=wx.Size(85, 34), style=0)
self.btnOk.SetToolTipString(u'Aceptar')
self.btnOk.Bind(wx.EVT_BUTTON, self.OnBtnOkButton,
  id=wxID_FRMPOSTALESBTNOK)

self.btnCancelar = wx.Button(id=wxID_FRMPOSTALESBTNCANCELAR,
  label=u'Cancelar', name=u'btnCancelar', parent=self,
  pos=wx.Point(133, 148), size=wx.Size(85, 34), style=0)
self.btnCancelar.SetToolTipString(u'Salir')
self.btnCancelar.Bind(wx.EVT_BUTTON, self.OnBtnCancelarButton,
  id=wxID_FRMPOSTALESBTNCANCELAR)

self.lblPais = wx.StaticText(id=wxID_FRMPOSTALESLBLPAIS,
  label=u'Pa\xeds', name=u'lblPais', parent=self,
pos=wx.Point(18,
  18), size=wx.Size(20, 12), style=0)

self.cboPais = wx.ComboBox(choices=[],
id=wxID_FRMPOSTALESCBOPAIS,
  name=u'cboPais', parent=self, pos=wx.Point(123, 18),
  size=wx.Size(117, 27), style=0, value=u'')
self.cboPais.SetLabel(u'')
self.cboPais.SetToolTipString(u'Pais')
self.cboPais.Bind(wx.EVT_COMBOBOX, self.OnCboPaisCombobox,
  id=wxID_FRMPOSTALESCBOPAIS)

self.lblDpto = wx.StaticText(id=wxID_FRMPOSTALESLBLDPTO,
  label=u'Departamento', name=u'lblDpto', parent=self,
  pos=wx.Point(18, 45), size=wx.Size(70, 12), style=0)

self.cboDpto = wx.ComboBox(choices=[],
id=wxID_FRMPOSTALESCBODPTO,
  name=u'cboDpto', parent=self, pos=wx.Point(123, 45),
  size=wx.Size(117, 27), style=0, value=u'')
self.cboDpto.SetLabel(u'')
self.cboDpto.SetToolTipString(u'Departamentos')
self.cboDpto.Bind(wx.EVT_COMBOBOX, self.OnCboDptoCombobox,
  id=wxID_FRMPOSTALESCBODPTO)

self.lblProv = wx.StaticText(id=wxID_FRMPOSTALESLBLPROV,
  label=u'Provincia', name=u'lblProv', parent=self,
pos=wx.Point(18,
  72), size=wx.Size(45, 12), style=0)

self.cboProv = wx.ComboBox(choices=[],
id=wxID_FRMPOSTALESCBOPROV,
  name=u'cboProv', parent=self, pos=wx.Point(123, 72),
  size=wx.Size(117, 27), style=0, value=u'')
self.cboProv.SetLabel(u'')
self.cboProv.SetToolTipString(u'Provincias')
self.cboProv.Bind(wx.EVT_COMBOBOX, self.OnCboProvCombobox,
  id=wxID_FRMPOSTALESCBOPROV)

self.lblDistro = wx.StaticText(id=wxID_FRMPOSTALESLBLDISTRO,
  label=u'Distrito', name=u'lblDistro', parent=self,
  pos=wx.Point(18, 99), size=wx.Size(36, 12), style=0)

self.cboDistri = wx.ComboBox(choices=[],
id=wxID_FRMPOSTALESCBODISTRI,
  name=u'cboDistri', parent=self, pos=wx.Point(123, 99),
  size=wx.Size(117, 27), style=0, value=u'')
self.cboDistri.SetLabel(u'')
self.cboDistri.SetToolTipString(u'Distritos')
self.cboDistri.Bind(wx.EVT_COMBOBOX, self.OnCboDistriCombobox,
  id=wxID_FRMPOSTALESCBODISTRI)

self.lblCod = wx.StaticText(id=wxID_FRMPOSTALESLBLCOD,
  label=u'C\xf3digo Postal:', name=u'lblCod', parent=self,
  pos=wx.Point(18, 126), size=wx.Size(70, 12), style=0)

self.lblPostal = wx.StaticText(id=wxID_FRMPOSTALESLBLPOSTAL,
label=u'',
  name=u'lblPostal', parent=self, pos=wx.Point(123, 126),
  size=wx.Size(117, 12), style=0)
self.lblPostal.SetToolTipString(u'Ubigeo')

def __init__(self, parent):
self._init_ctrls(parent)

self.CargarSizers(parent)

#Instancia la Clase
 #   self.oPostal=Postal()

#Establece el encoding segun el OS
# TODO: Revizar este codigo de encoding
if wx.Platform==

Re: sending mailing list with smtplib

2006-08-16 Thread 3KWA

3KWA wrote:
> Just for education purposes  (mine I guess :P) what was the idea behind
> that design decision?

>From the doc (self education :P)

The following methods implement a mapping-like interface for accessing
the message's RFC 2822 headers. Note that there are some semantic
differences between these methods and a normal mapping (i.e.
dictionary) interface. For example, in a dictionary there are no
duplicate keys, but here there may be duplicate message headers. Also,
in dictionaries there is no guaranteed order to the keys returned by
keys(), but in a Message object, headers are always returned in the
order they appeared in the original message, or were added to the
message later. Any header deleted and then re-added are always appended
to the end of the header list.

These semantic differences are intentional and are biased toward
maximal convenience.

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


Re: trouble understanding inheritance...

2006-08-16 Thread Fredrik Lundh
KraftDiner wrote:

> This is not working the way I think it should
> it would appear that fromfile and getName are calling the baseClass
> methods which are
> simple passes What have I done wrong?
> 
> class baseClass:
>   def __init__(self, type):
>   if type == 'A':
>   self = typeA()
>   else:
>   self = typeB()

__init__ is not a constructor, and assigning to self doesn't change the 
type of the constructed object.

looks like you need to get a better tutorial.



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


Re: Clean way to not get object back from instantiation attempt gone bad

2006-08-16 Thread Simon Forman
John Machin wrote:
> Simon Forman wrote:
>
> >
> > |>> class f:
> > ... def __init__(self):
> > ... del self
>
> Of course nothing happens. Args are local variables. 'self' is is a
> vanilla arg of a vanilla function.

I know.

> > ...
> > |>> e = f()
> > |>> e
> > <__main__.f instance at 0xb7dd91ec>
> >
> >
> > |>> class f:
> > ... def __init__(self):
> > ... return None
>
> Of course nothing different happens. There is always an implicit
> "return None" when control falls off the end of a function. Making it
> explicit changes nothing.

I know

> > ...
> > |>> e = f()
> > |>> e
> > <__main__.f instance at 0xb7dd934c>
>
> The whole idea of "del self" or "return None" is not a goer. "self" is
> a reference to the (mutable) newly created object. After __init__ has
> finished mutating it, the constructor will return the object to the
> constructor's caller.

I know that too.

> The whole idea that None should be returned in the event of error is
> ... well, let's just say it leaves me speechless.

Tell me about it.

> > But you could raise an exception and check for it:
> >
> > |>> class f:
> > ... def __init__(self, flag=True):
> > ... if not flag:
> > ... raise
>
> Please read the manual. A lone "raise" does *not* raise an anonymous
> exception; it re-raises an exception that has just been trapped. If
> there are none, it raises None, which causes (as documented) a
> TypeError.

I know

> > ...
> > |>> def f_factory(flag):
> > ... try:
> > ... e = f(flag)
> > ... except:
>
> Blanket exception catching is *never* a good idea. In this case the
> exception being caught is an artifact of your use of the unadorned
> "raise".

I know

> If you inserted here:
> ... import sys
> ... x, y = sys.exc_info()[:2]
> ... print x, y
> you would get:
> exceptions.TypeError exceptions must be classes, instances, or strings
> (deprecated), not NoneType

Yep.

> > ... e = None
> > ... return e
> > ...
> > |>> foo = f_factory(True)
> > |>> foo
> > <__main__.f instance at 0xb7dd944c>
> > |>> foo = f_factory(False)
> > |>> foo
> > |>> print foo
> > None
>
> HTH,
> John

The entire post was meant as a pedantic exercise illustrating what not
to do (and how easy it is to figure that out with an interactive
session,) and sketching how to raise and check for an error instead.

In the three seconds I spent thinking about it, I couldn't decide what
exception to raise, so I used the wicked bare raise and except.  I'm
certainly not advocating their use, but perhaps I should've made that
plain in a post intended to be "educational".

In any event, with your comments it's out there now, and the
educational value of this entire thread has been improved.  Thanks
John.

Peace,
~Simon

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


  1   2   >