Re: Does python have the static function member like C++

2007-04-11 Thread Bruno Desthuilliers
人言落日是天涯,望极天涯不见家 a écrit :
> I define the class like this:
> class AAA:
> counter = 0
> def __init__(self):
> pass
> def counter_increase():
> AAA.counter += 1
> print "couter now :", AAA.counter

You probably want something like this:

class AAA(object):
 _counter = 0

 @classmethod
 def increase_counter(cls):
 cls._counter += 1
 print "%s._counter is now %d" % (cls.__name__, cls._counter)

> But how could I call the function "counter_incrrease" ?

With the above correction, you can call it eiter on the class or on an 
instance:

AAA.increase_counter()
aaa = AAA()
aaa.increase_counter()

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

Re: Universal Feed Parser issue

2007-04-11 Thread Gabriel Genellina
En Wed, 11 Apr 2007 01:51:13 -0300, i3dmaster <[EMAIL PROTECTED]>  
escribió:

> On Apr 10, 6:45 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
>> En Tue, 10 Apr 2007 14:58:42 -0300, i3dmaster <[EMAIL PROTECTED]>
>> escribió:
>>
>> > 
>> >  ...
>> >   
>> >   
>> > 
>>
>> > After parsed by feedparser, the timezone element does not get the
>> > attribute "America/Mountain". Same thing on status element. This does
>> > not sound an expected result.  I am wondering if it should be
>> > considered a bug...
>>
>> Usually it's a good idea to read the documentation...   
>> http://www.feedparser.org/docs/namespace-handling.html
>
> I did. Perhaps its because of not 100% atom compatible of my feed
> format? See if I use gnosis xml utility to parse it, it works fine
> though...

The link above answers *exactly* your question - have you actually read  
the page?

-- 
Gabriel Genellina

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


Re: Does python have the static function member like C++

2007-04-11 Thread Bruno Desthuilliers
goodwolf a écrit :
(snip)
> 1. In this case you will prefer a classmethod instead a staticmethod.
> 2. If counter is the number of instances of class AAA then you will
> incrase counter inside __init__ method.
> 
> class AAA (object):
> counter = 0
> def __init__(self):
> type(self).counter_increase()

You can call a class method on an instance:
self.counter_increase()

And FWIW, this is probably something I'd put in the constructor (the 
__new__ method), not in the initializer.

> @classmethod
> def counter_increase(cls):
> cls.counter += 1
> 
> or
> 
> class AAA (object):
> counter = 0
> def __init__(self):
> type(self).counter += 1

Instances have a reference to their class, so you can also write this:
   self.__class__.counter += 1

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

Re: tuples, index method, Python's design

2007-04-11 Thread Hendrik van Rooyen
"Carsten Haese" <[EMAIL PROTECTED]> wrote:


> I'm just a user with no influence on the development of Python itself,
> but in my humble opinion, the non-existence of tuple.index is more
> pythonic than its existence would be.

I really cannot follow the logic behind this statement.
I can write:

L = [a,b,c,d,e,f]
T= (a,b,c,d,e,f)

The difference between the two things is that I can add to 
and change L, but not T.

Now it seems to me that whatever argument is used to
justify the existence of:

n = L.index(d)

can be used to justify the existence of:

n = T.index(d)

and vice versa.

Cut down to these basics, it seems to me that the arguments
against the latter construct are simply knee jerk reactions
to preserve the status quo.

If an index method for tuples is such a very bad thing,
then the same arguments can be used to justify the
removal of the list index method from the language.

I happen to agree with Antoon - there is a LOT of merit
in consistency, as it makes things easy to learn and remember.

And I would heretically go even further, and argue that it
should be possible to write stuff like:

T = T.append(x)

And get back a new tuple bound to the old name...

- Hendrik


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


Re: Does python have the static function member like C++

2007-04-11 Thread goodwolf
On Apr 11, 9:09 am, Bruno Desthuilliers  wrote:
> goodwolf a écrit :
> (snip)
>
> > 1. In this case you will prefer a classmethod instead a staticmethod.
> > 2. If counter is the number of instances of class AAA then you will
> > incrase counter inside __init__ method.
>
> > class AAA (object):
> > counter = 0
> > def __init__(self):
> > type(self).counter_increase()
>
> You can call a class method on an instance:
> self.counter_increase()
>
> And FWIW, this is probably something I'd put in the constructor (the
> __new__ method), not in the initializer.
>
> > @classmethod
> > def counter_increase(cls):
> > cls.counter += 1
>
> > or
>
> > class AAA (object):
> > counter = 0
> > def __init__(self):
> > type(self).counter += 1
>
> Instances have a reference to their class, so you can also write this:
>self.__class__.counter += 1

OK, you will use something like this:

class AAA (object):
counter = 0
def __new__(cls):
cls.counter += 1
return super(cls, cls).__new__(cls)

but I think that __new__ is more "low level" and not necessary here,
so I will use:

class AAA (object):
counter = 0
def __init__(self):
self.counter_increase()
@classmethod
def counter_increase(cls):
cls.counter += 1

with yours correction invoking self.counter_increase() instead of more
explicit type(self).counter_increase()

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


Calling Python from Javascript?

2007-04-11 Thread Kenneth McDonald
I know that there's some work out there to let Python make use of 
Javascript (Spidermonkey) via (I assume) some sort of bridging C/C++ 
code. Anyone know of efforts to allow the reverse? I'd really like to 
make use of Python when doing Mozilla DOM programming, and I can never 
get a clear idea of when PyXPCOM might be available to those of us who 
don't know the ins and outs of compiling Mozilla, and its XPCOM 
structures. So if there was an easy way to simply and quickly pass even 
just strings back and forth between Python and Moz Javascript, that 
would make certain things a heck of a lot easier.

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


Re: About Trolltech QT OpenSource license.

2007-04-11 Thread Robert Kern
king kikapu wrote:
> As i said, i do not fully understand all this license stuff. All i
> want to ask is, i can make GPL software and gain money from this ? And
> if that so, then why they "force" you to buy the commercial lisence in
> such case ?

Others have given good answers. I would only like to clarify what I think is the
source of confusion here. While the FSF and many open source advocates make a
distinction between the words "commercial" (meaning that someone derives money
from distributing the software, whether it is GPLed or not) and "proprietary"
(meaning that the software is not being distributed under an open source license
but one that restricts user's rights), Trolltech abuses the term "commercial" to
mean "proprietary" in this case.

If you obey the terms of the GPL and still manage to derive money from it, you
don't need Trolltech's "commercial" license. Just be sure that you do obey the
terms of the GPL; it's not entirely trivial to build a business model around it.
Such a business will be somewhat different from one that uses proprietary 
licenses.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


No zlib in Python 2.4.4

2007-04-11 Thread shamzz
Hi,

I've compiled (configure/make/make install) Python 2.4.4 from source
on Suse Linux Enterprise Server 9 (x64).

I need Python to be compiled with Zlib so that I can compile and use
Zope.

After installing Python, zlib doesn't seem to have been compiled with
it, I've checked the /usr/local/lib/python2.4/lib-dynload/ folder and
there is no zlib.so in there.

Shouldn't zlib be compiled as a Python module automatically in Python
2.4.4.  I'm guessing Python is doing some kind of check and not
compiling zlib for some reason?

Any help would be appreciated.

Thanks,
Shams

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


Re: Does python have the static function member like C++

2007-04-11 Thread Bruno Desthuilliers
goodwolf a écrit :
> On Apr 11, 9:09 am, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
>> goodwolf a écrit :
>> (snip)
>>
>>> 1. In this case you will prefer a classmethod instead a staticmethod.
>>> 2. If counter is the number of instances of class AAA then you will
>>> incrase counter inside __init__ method.
>>> class AAA (object):
>>> counter = 0
>>> def __init__(self):
>>> type(self).counter_increase()
>> You can call a class method on an instance:
>> self.counter_increase()
>>
>> And FWIW, this is probably something I'd put in the constructor (the
>> __new__ method), not in the initializer.
>>
>>> @classmethod
>>> def counter_increase(cls):
>>> cls.counter += 1
>>> or
>>> class AAA (object):
>>> counter = 0
>>> def __init__(self):
>>> type(self).counter += 1
>> Instances have a reference to their class, so you can also write this:
>>self.__class__.counter += 1
> 
> OK, you will use something like this:
> 
> class AAA (object):
> counter = 0
> def __new__(cls):
> cls.counter += 1
> return super(cls, cls).__new__(cls)

   return super(AAA, cls).__new__(cls)

> but I think that __new__ is more "low level" and not necessary here,

It's of course 'not necessary'. But (IMHO):
- increasing the class's instance counter is more a responsability of 
the class than a responsability of the instance - and it has nothing to 
do with initializing the instance's state
- if someone is to subclass AAA, there are fewer chances that he'll 
override the constructer than the initializer, and if he does, there are 
more chances that he won't forget to call on the parent's constructor.

IOW, this is actually *because* it is 'lower level' that I think it's a 
better place for such operations.

But YMMV, of course !-)

My 2 cents...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No zlib in Python 2.4.4

2007-04-11 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, shamzz wrote:

> Shouldn't zlib be compiled as a Python module automatically in Python
> 2.4.4.  I'm guessing Python is doing some kind of check and not
> compiling zlib for some reason?

It only gets compiled if the header files can be found.  Is the zlib-dev
or zlib-devel package installed?

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


Re: Calling Python from Javascript?

2007-04-11 Thread 7stud
On Apr 11, 1:50 am, Kenneth McDonald
<[EMAIL PROTECTED]> wrote:
> I know that there's some work out there to let Python make use of
> Javascript (Spidermonkey) via (I assume) some sort of bridging C/C++
> code. Anyone know of efforts to allow the reverse? I'd really like to
> make use of Python when doing Mozilla DOM programming, and I can never
> get a clear idea of when PyXPCOM might be available to those of us who
> don't know the ins and outs of compiling Mozilla, and its XPCOM
> structures. So if there was an easy way to simply and quickly pass even
> just strings back and forth between Python and Moz Javascript, that
> would make certain things a heck of a lot easier.
>
> Thanks,
> Ken

Javascript can make requests to the server, and far as I know python
can be used with either cgi or apache to respond to server requests.
Therefore, javascript can easily pass strings to a server side python
script, and it can easily handle data sent back that is formatted as a
string, XML, or JSON. I'm not sure what PyXPCOM is or why it's
relevant.

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


Re: No zlib in Python 2.4.4

2007-04-11 Thread Bernard Delmée
 > I need Python to be compiled with Zlib so that I can compile and use
 > Zope.

I am guessing you need zlib_dev.rpm (or somesuch) installed
for the python build process to find the relevant headers.
Sorry I cannot be more specific not being a SuSE user myself
(anymore)...

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


Re: Does python have the static function member like C++

2007-04-11 Thread goodwolf
On Apr 11, 10:15 am, Bruno Desthuilliers  wrote:
> goodwolf a écrit :
>
>
>
> > On Apr 11, 9:09 am, Bruno Desthuilliers  > [EMAIL PROTECTED]> wrote:
> >> goodwolf a écrit :
> >> (snip)
>
> >>> 1. In this case you will prefer a classmethod instead a staticmethod.
> >>> 2. If counter is the number of instances of class AAA then you will
> >>> incrase counter inside __init__ method.
> >>> class AAA (object):
> >>> counter = 0
> >>> def __init__(self):
> >>> type(self).counter_increase()
> >> You can call a class method on an instance:
> >> self.counter_increase()
>
> >> And FWIW, this is probably something I'd put in the constructor (the
> >> __new__ method), not in the initializer.
>
> >>> @classmethod
> >>> def counter_increase(cls):
> >>> cls.counter += 1
> >>> or
> >>> class AAA (object):
> >>> counter = 0
> >>> def __init__(self):
> >>> type(self).counter += 1
> >> Instances have a reference to their class, so you can also write this:
> >>self.__class__.counter += 1
>
> > OK, you will use something like this:
>
> > class AAA (object):
> > counter = 0
> > def __new__(cls):
> > cls.counter += 1
> > return super(cls, cls).__new__(cls)
>
>return super(AAA, cls).__new__(cls)
>
> > but I think that __new__ is more "low level" and not necessary here,
>
> It's of course 'not necessary'. But (IMHO):
> - increasing the class's instance counter is more a responsability of
> the class than a responsability of the instance - and it has nothing to
> do with initializing the instance's state
> - if someone is to subclass AAA, there are fewer chances that he'll
> override the constructer than the initializer, and if he does, there are
> more chances that he won't forget to call on the parent's constructor.
>
> IOW, this is actually *because* it is 'lower level' that I think it's a
> better place for such operations.
>
> But YMMV, of course !-)
>
> My 2 cents...

OK, but then you will use an more flexible constructor:

class AAA (object):
counter = 0
def __new__(cls, *args, **kwargs):
cls.counter += 1
return super(AAA, cls).__new__(cls, *args, **kwargs)

then you see that you will pay lot resources for a "lower level"
operation.

However if your counter is to consider a low level think, than You are
right, but it's more a personal consideration.

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


Re: installing pyqt4 on ubuntu 6.06

2007-04-11 Thread Paul Boddie
On 10 Apr, 20:48, "Joshua J. Kugler" <[EMAIL PROTECTED]> wrote:
> On Tuesday 10 April 2007 07:35, Pradnyesh Sawant wrote:
>
> > Any pointers regarding what packages should i install to get the
> > system into working condition would be very helpful
>
> It's next to impossible, due to conflicts with SIP, and other dependencies.
> See these two threads (both started by me) for more information:
>
> http://ubuntuforums.org/showthread.php?t=243936
> http://ubuntuforums.org/showthread.php?t=244612

Yes, so much for cutting edge packages in the bleeding edge Ubuntu
releases. Anyway, I've previously made PyQt4 packages for Ubuntu Hoary
based on the Debian (and possibly Ubuntu) sources plus diffs, and as
far as I remember you just need to choose a version of SIP which is
capable of working with both the PyQt3 and PyQt4 sources. I think I
also had to upgrade my PyQt3 stuff in the process, but since the stuff
shipped with Hoary is almost archaic, that was on the cards, anyway.

Sadly, you'll probably get into issues with the various applications
which need PyQt3, and it might be necessary to rebuild them. I'd
provide some details of what I've done, but they aren't currently to
hand, so I'll try and post some more information at a later time.

Paul

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


Re: No zlib in Python 2.4.4

2007-04-11 Thread shamzz
On Apr 11, 9:14 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, shamzz wrote:
> > Shouldn't zlib be compiled as a Python module automatically in Python
> > 2.4.4.  I'm guessing Python is doing some kind of check and not
> > compiling zlib for some reason?
>
> It only gets compiled if the header files can be found.  Is the zlib-dev
> or zlib-devel package installed?

Thanks for the fast reply... this seems to be going off topic from
Python so sorry about that.

But yep, I've just installed (through YAST) the zlib-devel and zlib-
devel-32 packages (zlib and zlib-32bit are already installed).

I then did a make clean/configure/make/make install with the Python
source, but it's still not compiling with zlib.

I've downloaded the latest (source) version of zlib 1.2.3, is it
possible to manually compile it from the zlib source into Python?

Thanks for your help,
Shams.

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


Re: IPython 0.8.0 is out

2007-04-11 Thread Paddy
On Apr 11, 6:18 am, Fernando Perez <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> The IPython team is happy to release version 0.8.0, with a lot of new
> enhancements, as well as many bug fixes.
>
> We hope you all enjoy it, and please report any problems as usual.
>
> WHAT is IPython?
> 
>
> 1. An interactive shell superior to Python's default. IPython has many
> features for object introspection, system shell access, and its own special
> command system for adding functionality when working interactively.
>
> 2. An embeddable, ready to use interpreter for your own programs. IPython
> can
> be started with a single call from inside another program, providing access
> to
> the current namespace.
>
> 3. A flexible framework which can be used as the base environment for other
> systems with Python as the underlying language.
>
> 4. A shell for interactive usage of threaded graphical toolkits. IPython has
> support for interactive, non-blocking control of GTK, Qt and WX applications
> via special threading flags. The normal Python shell can only do this for
> Tkinter applications.
>
> Where to get it
> ---
>
> IPython's homepage is at:
>
> http://ipython.scipy.org
>
> and downloads are at:
>
> http://ipython.scipy.org/dist
>
> We've provided:
>
>   - Source download (.tar.gz)
>   - A Python Egg (http://peak.telecommunity.com/DevCenter/PythonEggs).
>   - A python 2.4 RPM.
>   - A native win32 installer.
>
> The egg is 'light', as it doesn't include documentation and other ancillary
> data.  If you want a full ipython installation, use the source tarball or
> your
> distribution's favorite system.
>
> We note that IPython is now officially part of most major Linux and BSD
> distributions, so packages for this version should be coming soon, as the
> respective maintainers have the time to follow their packaging procedures.
> Many thanks to the distribution packagers for their work, which helps users
> get
> IPython more conveniently.
>
> Thanks to all the users who contributed bug reports, ideas and especially
> patches.  The ChangeLog has hopefully detailed acknowledgements, but please
> let
> us know if we've accidentally ommitted giving you due credit.
>
> Many thanks to Enthought for their continued hosting support for IPython.
>
> Release notes
> -
>
> As always, the full ChangeLog is athttp://ipython.scipy.org/ChangeLog.  The
> highlights of this release follow.  Also see the "What's New" page at
>
>http://ipython.scipy.org/moin/WhatsNew
>
>  * Support for KeyboardInterrupt (Ctrl-C) when running in multithreaded mode
>with GUI support.  This had been a long-requested feature that we had
> never
>quite been able to implement correctly.  Many thanks to Tomer Filiba's
> for
>his ctypes-based trick:http://sebulba.wikispaces.com/recipe+thread2,
> which
>we used (any implementation mistakes are our own and not his fault).
> Users
>of Python 2.4 should note that they need to install ctypes separately to
>access this feature; ctypes is part of Python 2.5 already.
>
>  * Fully syntax-highlighted tracebacks and debugger listings.  IPython used
> to
>color tracebacks, but only certain elements; now the source is actually
>highlighted by the same engine that handles '??' source listings, both in
>tracebacks and during interactive debugging.
>
>  * Improved the ipipe system:http://ipython.scipy.org/moin/UsingIPipe,
>including a new WX-based graphical browser.
>
>  * Much improved unicode support.  There may still be bugs remaining, but a
>number of known-incorrect cases have been fixed.
>
>  * Make the execution of 'from pylab import *' when -pylab is given be
> otional.
>A new flag (which can be set in your ipythonrc file), pylab_import_all
>controls this behavior, the default is True for backwards compatibility.
>
>  * Extensions for perforce support via a new magic (%p4) and custom command
>completers.
>
>  * Improved support for (X)Emacs under win32.
>
>  * Several small fixes and improvements to the interactive demo module.
>
>  * Add \N for the actual prompt number, without any coloring, as an escape
> for
>customized prompt definitions.  This lets users write their own custom
>prompts with arbitrary coloring schemes.
>
>  * Many more bugfixes and small features everywhere (the ChangeLog linked
> above
>has the gory details).
>
> API changes:
>
>  * genutils.clock() now returns user+system time.  The new clocku/clocks
>functions return respectively user and system time only.
>
> Enjoy, and as usual please report any problems.
>
> The IPython team.

Just made a connection between the IPipe feature and Windows
PowerShell http://en.wikipedia.org/wiki/PowerShell
I can't find the link to the orignial PowerShell article but I do
remember them talking about sending objects rather than text through
pipes (as Unix does); and that their was a default printing format for
objects coming out of a pipel

THREADS use 100 % CPU all the time

2007-04-11 Thread matthiasjanes
Hi all,

I have a application where I use different threads. actually all is
working - BUT I just discovered that the [b]CPU is always 100 % [/
b]used.

on the 32-bit machine athlon XP, as well as on the amd 64-bit AMD
Athlon(TM) 64 X2 Dual-Core.

I have to admit I'm not used to threads. I actually use a thirdparty
scheduler [url]http://www.webwareforpython.org/TaskKit/Docs/Source/
Docs/TaskKit.Scheduler.html[/url]
but I checked and a very simple exampe with threading gives me also
all the time 100% CPU.


[code]

import threading, time

class TestThread ( threading.Thread ):
def run ( self ):
print 'TEST'

t = TestThread()
t.start()


while (True):
pass

[/code]


Does anyone know how to run this without consuming all CPU.

regards,

MJ

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


Re: THREADS use 100 % CPU all the time

2007-04-11 Thread Thomas Krüger
[EMAIL PROTECTED] schrieb:
> while (True):
> pass

> Does anyone know how to run this without consuming all CPU.

Your while loop is taking all the CPU time.

Thomas

-- 
sinature: http://nospam.nowire.org/signature_usenet.png
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About Trolltech QT OpenSource license.

2007-04-11 Thread king kikapu
On Apr 11, 10:56 am, Robert Kern <[EMAIL PROTECTED]> wrote:
> Others have given good answers. I would only like to clarify what I think is 
> the
> source of confusion here. While the FSF and many open source advocates make a
> distinction between the words "commercial" (meaning that someone derives money
> from distributing the software, whether it is GPLed or not) and "proprietary"
> (meaning that the software is not being distributed under an open source 
> license
> but one that restricts user's rights), Trolltech abuses the term "commercial" 
> to
> mean "proprietary" in this case.

Ok, i see...So i can use Qt OS edition and earn money from this as
long as i explicitly say (is a reference to a GPL in a readme text
file enough for this ?) that this software is under the GPL lisence
and i have the obligation to give the source code with it.
I will reply to that email of Trolltec's today and i will tell them
about the things mentioned here, basically just the sentence i wrote
above.
I see what they will reply and post it here...

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


Re: __file__

2007-04-11 Thread 7stud
Hi,

Thanks for the response.

On Apr 11, 12:49 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
>
> __file__ corresponds to the filename used to locate and load the module,  
> whatever it is. When the module is found on the current directory  
> (corresponding to '' in sys.path), you get just the filename; if sys.path  
> contains a relative path, that's what you get; the same for any absolute  
> path.
> Whatever path worked to find and load the module, that's stored as  
> __file__.
>
> If you plan to use it, it's a good idea to make it early into an absolute  
> path (using os.path.abspath(__file__)) just in case the current directory  
> changes.
>

That last part doesn't seem to fit with your description above.  What
does the current working directory have to do with the path that was
used to load a module?  I would think the path that was used to load a
module is constant.

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


UDT wrappers

2007-04-11 Thread Justin Ezequiel
Found a couple of papers that mention Python wrappers for UDT have
been written but Google fails me.

Do any of you know of such wrappers?

Have downloaded UDT SDK but source is in C++.

http://udt.sourceforge.net/

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


Re: tuples, index method, Python's design

2007-04-11 Thread Paul Boddie
On 10 Apr, 20:04, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
>
> This is a rare enough use case and is easy enough to work around (convert it 
> to
> a list, write a helper function) that I don't think it's worth any
> language change overhead at all.

It isn't a language change: it's a change to the interface of a data
type, and not a particularly big one, either.

Paul

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


Re: About Trolltech QT OpenSource license.

2007-04-11 Thread Paul Boddie
On 11 Apr, 11:51, "king kikapu" <[EMAIL PROTECTED]> wrote:
>
> Ok, i see...So i can use Qt OS edition and earn money from this as
> long as i explicitly say (is a reference to a GPL in a readme text
> file enough for this ?) that this software is under the GPL lisence
> and i have the obligation to give the source code with it.

I'll leave the specifics of this case to one side and say that for any
software that you intend to distribute under the GPL, you should
provide references to the licence at least in some kind of text file
(I use COPYING.txt for this), but also in your source files (I
typically use module docstrings, but I imagine that comment lines
might be better in some respects), as well as a copy of the licence (I
use LICENCE.txt for this). You should find the licence text in any GPL-
licensed package as well as at the FSF site:

http://www.fsf.org/licensing/licenses/gpl.html

The "making money" aspect can be simplified to this: you can sell
copies of your software, but anyone receiving that software is
entitled to the sources "at cost", and since they receive the software
under the GPL, they are entitled to redistribute it under the same
terms. One popular misunderstanding is that if a company is selling
GPL-licensed software, they have to give the sources away to anyone
who asks; in fact, only people who have received the software are
entitled to the sources:

http://www.fsf.org/licensing/licenses/gpl-faq.html#CanIDemandACopy

Various companies do, however, give away sources to anyone but then
make money out of the effort to turn such sources into executable
systems. For example, Red Hat make the sources on which their products
are based available to anyone, but since the effort in building them,
putting everything together, testing the result, and so on is non-
trivial, people pay them money to do that particular work.

As has been said elsewhere in this discussion, the specific use of the
term "commercial" in the case described may be aimed at a corporate
mindset which equates "commercial" to "proprietary", but Free (and
open source) Software can be the basis for commercial activities, too.

Paul

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


New York City Python Users Group Meeting

2007-04-11 Thread John Clark
Greetings!

The next New York City Python Users Group meeting is this Tuesday, April
10th, 6:30pm at at the Millennium Partners office at 666 Fifth Avenue (53rd
St. and 5th Ave.) on the 8th Floor. We welcome all those in the NYC area who
are interested in Python to attend. However, we need a list of first and
last names to give to building security to make sure you can gain access to
the building. RSVP to [EMAIL PROTECTED] to add your name to the list. 

More information can be found on the yahoo group page:

 
http://tech.groups.yahoo.com/group/nycpython/

Hope to see you there!

-John

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

Shutting down windows using win32api

2007-04-11 Thread Sily Ady


 
-
8:00? 8:25? 8:40?  Find a flick in no time
 with theYahoo! Search movie showtime shortcut.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: calling super()

2007-04-11 Thread Laszlo Nagy
John Clark wrote:
> Please be aware that super() has it's own set of gotchas - it's not as clean
> as you would hope.  For more info: http://fuhm.org/super-harmful/
>
> (I'm not the author, I was referred to this article while struggling with
> wxPython and super())
>   
This was interesting! I'm using single inheritance in most of the cases. 
In very rare cases I use mixin classes, but they do not have 
constructors. In this situlation, I hope I'm right and I can safely use 
super(). I must agree that if a class uses "super" in its constructor, 
then all its descendants and bases must also use super. However, I'm 
using super in other cases. For example, for threading.Thread 
descendants, extensively, without any problems. Am I right in what I'm 
doing?

Thanks,

Laszlo

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


Pass A Var To a Python Script?

2007-04-11 Thread Eric Price
Hi;
How do I pass a variable to a python script? Something like this (which 
doesn't work):

./test.py?var=hello_world

TIA,
Eric

_
Mortgage refinance is Hot. *Terms. Get a 5.375%* fix rate. Check savings 
https://www2.nextag.com/goto.jsp?product=10035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h2bbb&disc=y&vers=925&s=4056&p=5117

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


[OT] MSN client for console project

2007-04-11 Thread Andrés M .
Hey, there.
I just wanted to tell you that Im designing an MSN client for console in 
Python.
I know that the protocol kinda sucks, but Im afraid the chicks I meet in 
here just don't use Jabber.

The 'never seen' thing I am planning for it, is picture support. I do not 
mean to have the possibility of seeing other people's pictures (cause It is 
not the purpuse to use SVGAlib), but for them to see one of out choice.

It's being written in Python, as I said above; using Ncurses, and based on 
MsnLib and ideas from other clients just as CenterICQ y Pebrot.

Please, to all you interested in knowing more, do not hesitate to contact 
me.

Saludos.
Andrés M.

_
Consigue aquí las mejores y mas recientes ofertas de trabajo EE.UU. 
http://latino.msn.com/empleos

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


Re: Why does not my wx.html.HtmlWindow work?

2007-04-11 Thread Carsten Haese
On 7 Apr 2007 20:38:25 -0700, [EMAIL PROTECTED] wrote
> Below are my source code:
> [snip
> html.LoadPage(" 
> http://www.pythonthreads.com/articles/python/incorporating-into-
> wxpython-part-1.html")
> [snip]

Have you tried loading a simpler page, something like http://www.google.com?

-Carsten

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


Get Shift + TAB in ncurses.

2007-04-11 Thread andmarti
Anyone can help me getting the shift + tab key combination ?
I tried with getch () but with no success.
May be using the sys.stdin ??

Please, help would be very appreciated.
-- 
Andrés M.
-
-- 
http://mail.python.org/mailman/listinfo/python-list


multithreading concept

2007-04-11 Thread saroj.nayak




The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email.
 
www.wipro.com-- 
http://mail.python.org/mailman/listinfo/python-list

py script modify it's Modified Time?

2007-04-11 Thread est
I guess os.stat() could retrieve information about ctime, mtime of a
path, but how can I change them? Is it possible to make it work both
under Win32 and Linux?

P.S. How to get the current running python?  (Like
WScript.ScriptFullName in vbscript)

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

Re: Pass A Var To a Python Script?

2007-04-11 Thread rishi pathak

Hi,
Use sys.argv to access the command line arguments
eg:
import sys
print sys.argv[0]
print sys.argv[1]

Run the above script as
/test.py hello world

On 4/7/07, Eric Price <[EMAIL PROTECTED]> wrote:


Hi;
How do I pass a variable to a python script? Something like this (which
doesn't work):

./test.py?var=hello_world

TIA,
Eric

_
Mortgage refinance is Hot. *Terms. Get a 5.375%* fix rate. Check savings

https://www2.nextag.com/goto.jsp?product=10035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h2bbb&disc=y&vers=925&s=4056&p=5117

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





--
Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pass A Var To a Python Script?

2007-04-11 Thread Michael Bentley

On Apr 7, 2007, at 1:13 PM, Eric Price wrote:

> Hi;
> How do I pass a variable to a python script? Something like this  
> (which
> doesn't work):
>
> ./test.py?var=hello_world

The easiest thing would be to drop the '?var=':

./test.py hello_world

Then in your script, use sys.argv to gather the argument (hello_world).

hth,
Michael


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


ANN: Next NYC Python User Group meeting, Tues May 8th, 2007, 6:30 pm

2007-04-11 Thread John Clark
My apologies for the comical timing of the below announcement - I actually
sent the announcement on April 4th, but it obviously didn't clear the
moderator's desk in time for the meeting mentioned below.  In an attempt to
avoid this same problem, let me announce next month's meeting now.
 
The next New York City Python Users Group meeting is Tuesday, May 8th from
6:30-8:30pm at the Millenium Partners office at 666 Fifth Avenue (53rd St.
and 5th Ave.) on the 8th Floor.  We welcome all those in the NYC area who
are interested in Python to attend.  However, we need a list of first and
last names to give to building security to make sure you can gain access to
the building.  RSVP to [EMAIL PROTECTED] to add your name to the list.
 
More information can be found on the yahoo group page:
 
http://tech.groups.yahoo.com/group/nycpython
 
Hope to see you there!
 
-John


  _  

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of John
Clark
Sent: Wednesday, April 04, 2007 3:46 PM
To: [email protected]; [EMAIL PROTECTED]; [email protected]
Subject: New York City Python Users Group Meeting



Greetings!

The next New York City Python Users Group meeting is this Tuesday, April
10th, 6:30pm at at the Millennium Partners office at 666 Fifth Avenue (53rd
St. and 5th Ave.) on the 8th Floor. We welcome all those in the NYC area who
are interested in Python to attend. However, we need a list of first and
last names to give to building security to make sure you can gain access to
the building. RSVP to [EMAIL PROTECTED] to add your name to the list. 

More information can be found on the yahoo group page:

 
http://tech.groups.yahoo.com/group/nycpython/

Hope to see you there!

-John

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

Re: THREADS use 100 % CPU all the time

2007-04-11 Thread A.B., Khalid
On Apr 11, 2:38 am, [EMAIL PROTECTED] wrote:
> Hi all,
>
> I have a application where I use different threads. actually all is
> working - BUT I just discovered that the [b]CPU is always 100 % [/
> b]used.
>
> on the 32-bit machine athlon XP, as well as on the amd 64-bit AMD
> Athlon(TM) 64 X2 Dual-Core.
>
> I have to admit I'm not used to threads. I actually use a thirdparty
> scheduler [url]http://www.webwareforpython.org/TaskKit/Docs/Source/
> Docs/TaskKit.Scheduler.html[/url]
> but I checked and a very simple exampe with threading gives me also
> all the time 100% CPU.
>
> [code]
>
> import threading, time
>
> class TestThread ( threading.Thread ):
> def run ( self ):
> print 'TEST'
>
> t = TestThread()
> t.start()
>
> while (True):
> pass
>
> [/code]
>
> Does anyone know how to run this without consuming all CPU.
>
> regards,
>
> MJ


You need your program to sleep a while to allow a switch to other
tasks. Like so:

###
import threading, time

class TestThread(threading.Thread):
def run(self):
print 'TEST'

t = TestThread()
t.start()

while (True):
time.sleep(0.01)
pass
###


Regards

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


Re: Shutting down windows using win32api

2007-04-11 Thread Tim Golden
On a whim, given the terseness of your post, I
cut-and-pasted your subject line into Google,
added "python" for good measure, and looked at
the results.

I suggest you might do the same. Granted, maybe
this will raise more questions, but at least it
shows willing :)

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


Re: Why does not my wx.html.HtmlWindow work?

2007-04-11 Thread Jorgen Bodde
Hi,

Coming from the wx community, I do know that the wx.HtmlWindow is NOT
meant to load full blown web pages with. It has no concept of
javascript, CSS, and other complex DOM properties.

If you really want to display complex web pages in a window, look at
wxMozilla or the wxIE binding.

So the reason it freaks out might be related to the fact the page is
too complex, or that the simplistic engine cannot cope with html tags
out in the wild.

Regards,
- Jorgen

On 4/8/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On 7 Apr 2007 20:38:25 -0700, [EMAIL PROTECTED] wrote
> > Below are my source code:
> > [snip
> > html.LoadPage("
> > http://www.pythonthreads.com/articles/python/incorporating-into-
> > wxpython-part-1.html")
> > [snip]
>
> Have you tried loading a simpler page, something like http://www.google.com?
>
> -Carsten
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing log in SQL DB to change IPs to hostnames

2007-04-11 Thread KDawg44
On Apr 11, 1:15 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 10 Apr 2007 11:54:18 -0700, "KDawg44" <[EMAIL PROTECTED]> declaimed
> the following in comp.lang.python:
>
>
>
> > [- BEGIN ERROR ---]
> > Traceback (most recent call last):
> >   File "changeLogs.py", line 47, in ?
> > cursor.execute("""UPDATE logs SET msg = %s WHERE seq = %i""",
> > (newMsg,seqNum))
> >   File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
> > 148, in execute
> > query = query % db.literal(args)
> > TypeError: int argument required
> > [- END ERROR ---]
>
> > Here is my code
>
> > [- BEGIN CODE ---]
>
> Comments interspersed
>
>
>
> > #! /usr/bin/python
>
> > import socket
> > import sys
> > import re
> > import string
> > import MySQLdb
>
> > def resolveHost(ipAdds):
> >ipDict = {}
> >for ips in ipAdds:
> >try:
> >ipDict[ips] = socket.gethostbyaddr(ips)[0]
> >except:
> >ipDict[ips] = "Cannot resolve"
> >return ipDict
>
> > ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
> > ipRegEx = re.compile(ipRegExC)
>
> > try:
> >conn = MySQLdb.connect(host="REMOVED",
> >user="REMOVED",
> >passwd="REMOVED",
> >db="REMOVED")
>
> > except MySQLdb.Error, e:
> >print "Error connecting to the database: %s - %s " % (e.args[0], 
> > e.args[1])
>
> #just use %s unless you need particular numeric formatting
> #(field width and decimal places, as in %8.4f)>sys.exit(1)
>
> > cursor = conn.cursor()
>
> cursor.execute("SELECT msg, seq FROM logs WHERE seq = 507702")
> #why the ` around the table name?
> #I also presume at some point that 507702 becomes dynamic -- otherwise
> the returned
> #seq field will always be 507702,-- and if there are multiple instances,
> the update
> #statement below will change all of them each time
>
> #while(1):
> #   row = cursor.fetchone()
> for row in cursor:>ipAddresses = []
> >resolvedDict = {}
>
> #   if row == None:
> #  break>if ipRegEx.search(row[0]):
> >seqNum = row[1]
> >ipAddresses = ipRegEx.findall(row[0])
> >resolvedDict = resolveHost(ipAddresses)
> >newMsg = row[0]
> >for ip in resolvedDict.keys():
> >newMsg = newMsg.replace(ip,
> >ip + "-" +resolvedDict[ip])
>
> cursor.execute(
> """UPDATE REMOVED SET msg = %s WHERE seq = %s""",
> (newMsg, seqNum))
> #the documented parameter code for MySQLdb is %s; use 
> of
> anything
> #else relies upon luck -- luck that the safety logic 
> inside
> the module
> #leaves the parameter in a format compatible with the 
> format
> code!
> #%s is the only code you should use with MySQLd --
> regardless of
> #the type of the actual data
>
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

ohhh okay.  thanks so much.  I knew that it came out as strings, i
guess it makes sense that I would have to send it back IN as a
string.  Changed that and now it works!  THanks so much.

I just specified once specific field so that it would not change the
whole db on a test run.

Thanks so much.

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


Re: tuples, index method, Python's design

2007-04-11 Thread Steven D'Aprano
On Wed, 11 Apr 2007 08:57:43 +0200, Hendrik van Rooyen wrote:

> I can write:
> 
> L = [a,b,c,d,e,f]
> T= (a,b,c,d,e,f)
> 
> The difference between the two things is that I can add to 
> and change L, but not T.

No, that's *one* difference between the two things. There are other
differences, e.g. the obvious is that they are different types (and
therefore different string representations), but also some not so obvious:

>>> hash((1,2,3))
-378539185

>>> hash([1,2,3])
Traceback (most recent call last):
  File "", line 1, in 
TypeError: list objects are unhashable



> Now it seems to me that whatever argument is used to justify the
> existence of:
> 
> n = L.index(d)
> 
> can be used to justify the existence of:
> 
> n = T.index(d)
> 
> and vice versa.

That depends on what you the purpose of lists and tuples are. Yes, they
are both sequences, but they have different uses. Ball-peen hammers and
tack hammers are both hammers, but they have different purposes and
therefore different functionality. Likewise for tuples and lists:

Lists are designed for sequences of homogeneous items, e.g.:

L = [1, 2, 4, 8, 16, 32]

while tuples are designed to be more like structs or records, with
heterogeneous items, e.g.:

T = ("Fred", 32, 12.789, {}, None, '\t')

So according to these intended usages, it makes sense to ask for
L.index(32) because in an application you have no way of telling which
item (if any) 32 would be in. But T.index(32) is seen as meaningless,
because you know that either 32 is in the second slot or it isn't --
you're never going to find yourself in a situation knowing that 32 is
*somewhere* in the tuple without knowing where the one place it *could* be.

(There is one other option: you care that 32 is somewhere in the tuple,
but you don't care where. That's when you use the "in" operator.)

Anyway, that was the original design. When you see tuple, think struct. If
you have a struct, it doesn't make a whole lot of sense to ask "which
field contains 32?", and so according to this intended usage, giving
tuples index and count methods would be a Bad Idea: it just makes extra
work for the Python Dev team, for no benefit.

Personally, I think that tuples do double-duty as *both* immutable lists
and structs/records. So even though index and count methods don't make
sense for a struct, it does make sense for an immutable list, and I for
one would not object to seeing tuples grow those two methods.

[snip]


> And I would heretically go even further, and argue that it should be
> possible to write stuff like:
> 
> T = T.append(x)
> 
> And get back a new tuple bound to the old name...

That's a design decision, and one that's not likely to be accepted because
it's so easy to do:


T = T + (x,)  # like T.append()
T = T + (x, y, z) # like T.extend()
T = tuple(sorted(T))  # like T.sort()
T = T[:4] + T[4:] # like del T[4]
etc.

It makes sense for lists to have these methods because lists can make the
changes in place, but tuples can't.



-- 
Steven.

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


Re: __file__

2007-04-11 Thread John Machin
On Apr 11, 8:03 pm, "7stud" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Thanks for the response.
>
> On Apr 11, 12:49 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > __file__ corresponds to the filename used to locate and load the module,
> > whatever it is. When the module is found on the current directory
> > (corresponding to '' in sys.path), you get just the filename; if sys.path
> > contains a relative path, that's what you get; the same for any absolute
> > path.
> > Whatever path worked to find and load the module, that's stored as
> > __file__.
>
> > If you plan to use it, it's a good idea to make it early into an absolute
> > path (using os.path.abspath(__file__)) just in case the current directory
> > changes.
>
> That last part doesn't seem to fit with your description above.  What
> does the current working directory have to do with the path that was
> used to load a module?  I would think the path that was used to load a
> module is constant.

You are correct, but that is not what GG was talking about. Here is an
example of what he meant:

While your cwd is /bar, you load module foo from a *relative*( path,
e.g. ./foo.py. If you do the os.path.abspath("./foo.py") immediately
as recommended, you get the correct answer: /bar/foo.py. However if
you change your cwd to /zot, then do the os.path.abspath("./foo.py"),
you get /zot/foo.py which is a nonsense.

HTH,
John

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


Re: THREADS use 100 % CPU all the time

2007-04-11 Thread matthiasjanes
On Apr 11, 1:36 pm, "A.B., Khalid" <[EMAIL PROTECTED]> wrote:
> On Apr 11, 2:38 am, [EMAIL PROTECTED] wrote:
>
>
>
> > Hi all,
>
> > I have a application where I use different threads. actually all is
> > working - BUT I just discovered that the [b]CPU is always 100 % [/
> > b]used.
>
> > on the 32-bit machine athlon XP, as well as on the amd 64-bit AMD
> > Athlon(TM) 64 X2 Dual-Core.
>
> > I have to admit I'm not used to threads. I actually use a thirdparty
> > scheduler [url]http://www.webwareforpython.org/TaskKit/Docs/Source/
> > Docs/TaskKit.Scheduler.html[/url]
> > but I checked and a very simple exampe with threading gives me also
> > all the time 100% CPU.
>
> > [code]
>
> > import threading, time
>
> > class TestThread ( threading.Thread ):
> > def run ( self ):
> > print 'TEST'
>
> > t = TestThread()
> > t.start()
>
> > while (True):
> > pass
>
> > [/code]
>
> > Does anyone know how to run this without consuming all CPU.
>
> > regards,
>
> > MJ
>
> You need your program to sleep a while to allow a switch to other
> tasks. Like so:
>
> ###
> import threading, time
>
> class TestThread(threading.Thread):
> def run(self):
> print 'TEST'
>
> t = TestThread()
> t.start()
>
> while (True):
> time.sleep(0.01)
> pass
> ###
>
> Regards



Thanks a lot both of you.

MJ

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


RE: tuples, index method, Python's design

2007-04-11 Thread Hamilton, William
> -Original Message-
> From: [EMAIL PROTECTED]
[mailto:python-
> [EMAIL PROTECTED] On Behalf Of Steven
D'Aprano
> Sent: Wednesday, April 11, 2007 7:49 AM
> To: [email protected]
> Subject: Re: tuples, index method, Python's design
> 
> (There is one other option: you care that 32 is somewhere in the
tuple,
> but you don't care where. That's when you use the "in" operator.)
> 
> Anyway, that was the original design. When you see tuple, think
struct. If
> you have a struct, it doesn't make a whole lot of sense to ask "which
> field contains 32?", and so according to this intended usage, giving
> tuples index and count methods would be a Bad Idea: it just makes
extra
> work for the Python Dev team, for no benefit.
> 
> Personally, I think that tuples do double-duty as *both* immutable
lists
> and structs/records. So even though index and count methods don't make
> sense for a struct, it does make sense for an immutable list, and I
for
> one would not object to seeing tuples grow those two methods. 


>From another function, you receive a tuple of data that it extracted
from a stream.  Within that tuple is a marker that indicates where the
head of the incoming stream's data structure is.  You need to find the
marker and scan from that location on to sync your local data structure
to the incoming stream's data.  

Should the external function provide the stream data in a list rather
than a tuple?  Probably, but someone else wrote the function so that's
out of your control.  Can you cast the tuple to a list?  Sure, but for a
large tuple that's potentially a large speed and memory hit.

That probably the biggest general use case for tuple.index().  A
third-party module returns a tuple in which you need to find a piece of
data.


---
-Bill Hamilton
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2007-04-11 Thread Antoon Pardon
On 2007-04-11, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Wed, 11 Apr 2007 08:57:43 +0200, Hendrik van Rooyen wrote:
>
>> I can write:
>> 
>> L = [a,b,c,d,e,f]
>> T= (a,b,c,d,e,f)
>> 
>> The difference between the two things is that I can add to 
>> and change L, but not T.
>
> No, that's *one* difference between the two things. There are other
> differences, e.g. the obvious is that they are different types (and
> therefore different string representations), but also some not so obvious:
>
 hash((1,2,3))
> -378539185
>
 hash([1,2,3])
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: list objects are unhashable
>
>
>
>> Now it seems to me that whatever argument is used to justify the
>> existence of:
>> 
>> n = L.index(d)
>> 
>> can be used to justify the existence of:
>> 
>> n = T.index(d)
>> 
>> and vice versa.
>
> That depends on what you the purpose of lists and tuples are. Yes, they
> are both sequences, but they have different uses. Ball-peen hammers and
> tack hammers are both hammers, but they have different purposes and
> therefore different functionality. Likewise for tuples and lists:
>
> Lists are designed for sequences of homogeneous items, e.g.:
>
> L = [1, 2, 4, 8, 16, 32]
> while tuples are designed to be more like structs or records, with
> heterogeneous items, e.g.:
>
> T = ("Fred", 32, 12.789, {}, None, '\t')

I think you are confused. Last time I heard this homogeneous items stuf,
it had nothing to do with the types being the same. They were homogeneous
because they somehow belonged together and heterogeneous because they
just happened to live together. Similarity of type played no part in
calling the data homogeneous or heterogeneous.

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


Re: tuples, index method, Python's design

2007-04-11 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Antoon Pardon wrote:

> On 2007-04-11, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>> Lists are designed for sequences of homogeneous items, e.g.:
>>
>> L = [1, 2, 4, 8, 16, 32]
>> while tuples are designed to be more like structs or records, with
>> heterogeneous items, e.g.:
>>
>> T = ("Fred", 32, 12.789, {}, None, '\t')
> 
> I think you are confused. Last time I heard this homogeneous items stuf,
> it had nothing to do with the types being the same. They were homogeneous
> because they somehow belonged together and heterogeneous because they
> just happened to live together. Similarity of type played no part in
> calling the data homogeneous or heterogeneous.

Then you are confused.  The typical use case for tuples are database
records.  The columns in the table can have completely different types but
the values in a row, represented as a Python tuple, of course belong
together.

The homogeneous objects in lists must not be of the same type but share
some behavior so it makes sense to apply some operation on all the
elements.  For example get the length of each item or sum them all up.

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


Connection problems with irclib

2007-04-11 Thread Dropkick Punt
Hi. I've written a bot in python, using the irclib by Joel Rosdahl.

Works fine from my linux box at home, but when I upload it to my shell at
veritynet.net, can't seem to get it to connect to an irc server.

It doesn't report any errors.

Anyone have any idea how I might go about at least diagnosing the problem?
Any suggestions might help.

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


Re: py script modify it's Modified Time?

2007-04-11 Thread kyosohma
On Apr 11, 6:14 am, "est" <[EMAIL PROTECTED]> wrote:
> I guess os.stat() could retrieve information about ctime, mtime of a
> path, but how can I change them? Is it possible to make it work both
> under Win32 and Linux?
>
> P.S. How to get the current running python?  (Like
> WScript.ScriptFullName in vbscript)

I am not sure if you can change a creation time of a file on NT, but
the rest sounds possible; according to this post anyway:

http://mail.python.org/pipermail/python-list/2001-August/100214.html

It mentions using the win32 modules, which can be found here:
http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/win32_modules.html

As to your last question of finding the current running python, use
the sys module's "executable" method, like so: sys.executable

Mike

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


SOAP Webservices and Python

2007-04-11 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I'm pretty new to the world of Python, but I'm slowly getting my head around
things, and on today's agenda I'm looking at consuming SOAP web services.
I've got an Adobe ColdFusion application which I've written that publishes
the web service that I'm looking to consume, but I'm at a loss as to where
to start. I'm running Python 2.4.4 on a Debian Linux distribution, in case
that makes any difference.

 

I thought I'd start with something very simple, just a service I pass an ID
to and it'll return a Boolean value. Here is the web service link.

 

http://www.yourblue.co.uk/webservicetester/ip.cfc?wsdl

 

I'd be interested to hear any thoughts on the best way to go about this, or
perhaps some working code examples of consuming this service. I will always
have the WSDL file available to me by appending the ?wsdl to the URL, I've
heard this makes life easier. 

 

 like I say, I'm pretty new so it's perfectly ok for you guys to assume I'm
an idiot and talk to me as if I were a small child :-D

 

Thanks,

 

Rob

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

Re: Connection problems with irclib

2007-04-11 Thread Paul Boddie
On 11 Apr, 15:31, "Dropkick Punt" <[EMAIL PROTECTED]> wrote:
> Hi. I've written a bot in python, using the irclib by Joel Rosdahl.
>
> Works fine from my linux box at home, but when I upload it to my shell at
> veritynet.net, can't seem to get it to connect to an irc server.

It may well be the case that your hosting provider has blocked various
IRC ports and/or traffic.

> It doesn't report any errors.
>
> Anyone have any idea how I might go about at least diagnosing the problem?
> Any suggestions might help.

Check your provider's usage policy and documentation.

Paul

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


Re: tuples, index method, Python's design

2007-04-11 Thread Antoon Pardon
On 2007-04-11, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, Antoon Pardon wrote:
>
>> On 2007-04-11, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>>> Lists are designed for sequences of homogeneous items, e.g.:
>>>
>>> L = [1, 2, 4, 8, 16, 32]
>>> while tuples are designed to be more like structs or records, with
>>> heterogeneous items, e.g.:
>>>
>>> T = ("Fred", 32, 12.789, {}, None, '\t')
>> 
>> I think you are confused. Last time I heard this homogeneous items stuf,
>> it had nothing to do with the types being the same. They were homogeneous
>> because they somehow belonged together and heterogeneous because they
>> just happened to live together. Similarity of type played no part in
>> calling the data homogeneous or heterogeneous.
>
> Then you are confused.  The typical use case for tuples are database
> records.  The columns in the table can have completely different types but
> the values in a row, represented as a Python tuple, of course belong
> together.

Don't blame me. I don't agree with the view. But that was sort of the
explanation that was given here last time I remember this topic came 
up in defending why tuples and lists differ in a number of ways that
are less obvious.

They wrote about lists containing homogeneous items and tuples
containing hetergenous items but stressed rather strongly that
this shouldn't be understood in terms of type similarities.

> The homogeneous objects in lists must not be of the same type but share
> some behavior so it makes sense to apply some operation on all the
> elements.  For example get the length of each item or sum them all up.

No they don't. The counter example is using a list as a stack when
evaluating expressions. You can use one stack to store the still
to be treated numbers and operands and those two don't need
common behaviour.

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


Re: How to get IP address of client from CGI module?

2007-04-11 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
John Nagle  <[EMAIL PROTECTED]> wrote:
>   The documentation for Python's CGI module doesn't seem to say how to get
>the IP address of the client.  Don't see an obvious way to get that info
>from reading the source, either. Ideas?
>
>   John Nagle

os.environ['REMOTE_ADDR']?
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Apr 11)

2007-04-11 Thread Cameron Laird
QOTW:  "Dictionaries are one of the most useful things in Python. Make sure
you know how to take adavantage of them..." - Jeremy Sanders

"Python has consistently failed to disappoint me." - Tal Einat


"super() only works on new-style classes ..." and "has its own
set of gotchas":
http://groups.google.com/group/comp.lang.python/msg/f44c8c09e1593dcf

Yes, there certainly *are* times that connection to a terminal
makes a difference.  There also are ways to control that difference:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b5975d27da432e92/

Michael Bentley reports satisfaction with Wing IDE's ability
to debug multithreading Python:
http://groups.google.com/group/comp.lang.python/msg/f44c8c09e1593dcf

Does Python know about such matters as '>' ('>')?  Sure:
just "import htmlentitydefs":

http://groups.google.com/group/comp.lang.python/browse_thread/thread/7f96723282376f8c/

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d09417aedc1b807b/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

The Python Papers aims to publish "the efforts of Python enthusiats".
http://pythonpapers.org/

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/python/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
http://python.de/backend.php
For more, see
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally in a
SourceForge reincarnation.
 

Re: tuples, index method, Python's design

2007-04-11 Thread Chris Mellon
On 4/11/07, Hamilton, William <[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: [EMAIL PROTECTED]
> [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of Steven
> D'Aprano
> > Sent: Wednesday, April 11, 2007 7:49 AM
> > To: [email protected]
> > Subject: Re: tuples, index method, Python's design
> >
> > (There is one other option: you care that 32 is somewhere in the
> tuple,
> > but you don't care where. That's when you use the "in" operator.)
> >
> > Anyway, that was the original design. When you see tuple, think
> struct. If
> > you have a struct, it doesn't make a whole lot of sense to ask "which
> > field contains 32?", and so according to this intended usage, giving
> > tuples index and count methods would be a Bad Idea: it just makes
> extra
> > work for the Python Dev team, for no benefit.
> >
> > Personally, I think that tuples do double-duty as *both* immutable
> lists
> > and structs/records. So even though index and count methods don't make
> > sense for a struct, it does make sense for an immutable list, and I
> for
> > one would not object to seeing tuples grow those two methods.
>
>
> >From another function, you receive a tuple of data that it extracted
> from a stream.  Within that tuple is a marker that indicates where the
> head of the incoming stream's data structure is.  You need to find the
> marker and scan from that location on to sync your local data structure
> to the incoming stream's data.
>
> Should the external function provide the stream data in a list rather
> than a tuple?  Probably, but someone else wrote the function so that's
> out of your control.  Can you cast the tuple to a list?  Sure, but for a
> large tuple that's potentially a large speed and memory hit.
>
> That probably the biggest general use case for tuple.index().  A
> third-party module returns a tuple in which you need to find a piece of
> data.
>

So, when you have a) a third party module that you cannot change and
b) it shouldn't return a tuple but it does anyway and c) it's a big
enough tuple that is large enough that conversion to a list is
prohibitive, that's a "general" use case for tuple.index?

Has this supposedly general and common use case actually happened?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2007-04-11 Thread Chris Mellon
On 4/10/07, BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
> > > while not game_has_ended:
> > >   for current_player in p:
> > > player_does_something(current_player)
> > >
> >
> > I'm curious why someone would even consider using a tuple in this case
> > regardless. I think that much of the desire for tuple.index is because
> > people use a tuple where they could have a list, but either a) some
> > vestige of B&D language programming comes out and they want to make
>
> Maybe someone had to much alcohol when they were coding? Maybe they
> don't know better? Maybe they thought that an index method on a
> sequence made sense? Who are you to spoil their fun? Could it be that
> YOU are the B&D person?
>

If you want a language that just adds whatever methods anyone thinks
of, along with whatever aliases for it any can think of, to every data
type, you know where to find Ruby.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Connection problems with irclib

2007-04-11 Thread Dropkick Punt
On Wed, 11 Apr 2007 06:46:14 +, Paul Boddie wrote:

> On 11 Apr, 15:31, "Dropkick Punt" <[EMAIL PROTECTED]> wrote:
>> Hi. I've written a bot in python, using the irclib by Joel Rosdahl.
>>
>> Works fine from my linux box at home, but when I upload it to my shell at
>> veritynet.net, can't seem to get it to connect to an irc server.
> 
> It may well be the case that your hosting provider has blocked various
> IRC ports and/or traffic.

Thanks but no. The shell is generally used for eggdrops, and port 6667 is
open. They even installed python specifically so I could run this bot.

> 
>> It doesn't report any errors.
>>
>> Anyone have any idea how I might go about at least diagnosing the problem?
>> Any suggestions might help.
> 
> Check your provider's usage policy and documentation.

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


run function in separate process

2007-04-11 Thread malkarouri
Hi everyone,

I have written a function that runs functions in separate processes. I
hope you can help me improving it, and I would like to submit it to
the Python cookbook if its quality is good enough.

I was writing a numerical program (using numpy) which uses huge
amounts of memory, the memory increasing with time. The program
structure was essentially:

for radius in radii:
result = do_work(params)

where do_work actually uses a large number of temporary arrays. The
variable params is large as well and is the result of computations
before the loop.

After playing with gc for some time, trying to convince it to to
release the memory, I gave up. I will be happy, by the way, if
somebody points me to a web page/reference that says how to call a
function then reclaim the whole memory back in python.

Meanwhile, the best that I could do is fork a process, compute the
results, and return them back to the parent process. This I
implemented in the following function, which is kinda working for me
now, but I am sure it can be much improved. There should be a better
way to return the result that a temporary file, for example. I
actually thought of posting this after noticing that the pypy project
had what I thought was a similar thing in their testing, but they
probably dealt with it differently in the autotest driver [1]; I am
not sure.

Here is the function:

def run_in_separate_process(f, *args, **kwds):
from os import tmpnam, fork, waitpid, remove
from sys import exit
from pickle import load, dump
from contextlib import closing
fname = tmpnam()
pid = fork()
if pid > 0: #parent
waitpid(pid, 0) # should have checked for correct finishing
with closing(file(fname)) as f:
result = load(f)
remove(fname)
return result
else: #child
result = f(*args, **kwds)
with closing(file(fname,'w')) as f:
dump(result, f)
exit(0)


To be used as:

for radius in radii:
result = run_in_separate_process (do_work, params)

[1] http://codespeak.net/pipermail/pypy-dev/2006q3/003273.html



Regards,

Muhammad Alkarouri

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


passing class by reference does not work??

2007-04-11 Thread wswilson
Here is my code:

class A():
val = 0

def b(item, a):
a.val = a.val + 1
return item + a.val

def c():
d = [1, 2, 3]
print [b(item, A()) for item in d]

c()

I expected this to output [2, 4, 6]. However, it outputs [2, 3, 4]
which is not what I wanted. I thought that if I passed the A()
instance in my list comprehension in c(), then the changes I made to
a.val in b() would be reflected in the A() instance next time the list
comprehension called b(). But, obviously that is not happening. I'm
kinda new at python so I may be missing something obvious here.

Any suggestions?

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


A general question

2007-04-11 Thread amit soni
Hi,

I am using Matlab, Python and Java for sometime. Matlab looks to be very easy 
and having specified methods for almost each and everything. Java on the other 
hand has a good object oriented structure and is very fast. What are the 
advantages of Python over these two or any other language in general? and what 
are the areas it lacks behind and what improvements will make it appealing to 
more and more people?

Thank you,
Amit

   
-
Don't get soaked.  Take a quick peak at the forecast 
 with theYahoo! Search weather shortcut.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: run function in separate process

2007-04-11 Thread kyosohma
On Apr 11, 9:23 am, [EMAIL PROTECTED] wrote:
> Hi everyone,
>
> I have written a function that runs functions in separate processes. I
> hope you can help me improving it, and I would like to submit it to
> the Python cookbook if its quality is good enough.
>
> I was writing a numerical program (using numpy) which uses huge
> amounts of memory, the memory increasing with time. The program
> structure was essentially:
>
> for radius in radii:
> result = do_work(params)
>
> where do_work actually uses a large number of temporary arrays. The
> variable params is large as well and is the result of computations
> before the loop.
>
> After playing with gc for some time, trying to convince it to to
> release the memory, I gave up. I will be happy, by the way, if
> somebody points me to a web page/reference that says how to call a
> function then reclaim the whole memory back in python.
>
> Meanwhile, the best that I could do is fork a process, compute the
> results, and return them back to the parent process. This I
> implemented in the following function, which is kinda working for me
> now, but I am sure it can be much improved. There should be a better
> way to return the result that a temporary file, for example. I
> actually thought of posting this after noticing that the pypy project
> had what I thought was a similar thing in their testing, but they
> probably dealt with it differently in the autotest driver [1]; I am
> not sure.
>
> Here is the function:
>
> def run_in_separate_process(f, *args, **kwds):
> from os import tmpnam, fork, waitpid, remove
> from sys import exit
> from pickle import load, dump
> from contextlib import closing
> fname = tmpnam()
> pid = fork()
> if pid > 0: #parent
> waitpid(pid, 0) # should have checked for correct finishing
> with closing(file(fname)) as f:
> result = load(f)
> remove(fname)
> return result
> else: #child
> result = f(*args, **kwds)
> with closing(file(fname,'w')) as f:
> dump(result, f)
> exit(0)
>
> To be used as:
>
> for radius in radii:
> result = run_in_separate_process (do_work, params)
>
> [1]http://codespeak.net/pipermail/pypy-dev/2006q3/003273.html
>
> Regards,
>
> Muhammad Alkarouri

I found a post on a similar topic that looks like it may give you some
ideas:

http://mail.python.org/pipermail/python-list/2004-October/285400.html
http://www.artima.com/forums/flat.jsp?forum=106&thread=174099
http://www.nabble.com/memory-manage-in-python-fu-t3386442.html
http://www.thescripts.com/forum/thread620226.html

Mike

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


Re: passing class by reference does not work??

2007-04-11 Thread antred

> def b(item, a):
> a.val = a.val + 1
> return item + a.val




This is where the problem lies, specifically the line a.val = a.val +
1
What happens here is that the 1st a.val refers to a member of the
class instance a, called val ... which does not yet exist and is
therefore created as the result of taking the val member of the class
A and adding 1 to it. In other words, a.val is not the same variable
as A.val. Are you following? If not, change your b() method to this:

def b(item, a):
a.val = a.val + 1
assert a.val is A.val
return item + a.val

and see what happens.

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


Writing XML Logs

2007-04-11 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I'm trying to write an application that will log to an XML file, that'll be
later parsed by another application. The proposed log file will look
something like this, listing different event elements and then a record for
each time that event occurs.

 



































































 

What I would really like to do is have a different function for each event,
so logReboot() or something like that which can be called when the
application starts, and it'll create and entry with the current date and
time. This must be a static file that is on the box, allot of the examples
I've seen seem to work using the 'print' function which is a little sketchy
as outputting to the screen isn't any use to me, this needs to be a file
that can be collected by another application.

 

Can anyone offer any advice on how best to get started with this kind of
thing? I'm running python 2.4.4 but when I've tried running any examples
with SAX involved they seem to say 'no module found: sax" or something to
that effect, I was under the impression that sax came bundled with python
2.0 and above?

 

Thanks guys,

 

Rob

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

Re: passing class by reference does not work??

2007-04-11 Thread Alex Martelli
wswilson <[EMAIL PROTECTED]> wrote:

> Here is my code:
> 
> class A():
>   val = 0
> 
> def b(item, a):
>   a.val = a.val + 1
>   return item + a.val
> 
> def c():
>   d = [1, 2, 3]
>   print [b(item, A()) for item in d]
> 
> c()
> 
> I expected this to output [2, 4, 6]. However, it outputs [2, 3, 4]
> which is not what I wanted. I thought that if I passed the A()
> instance in my list comprehension in c(), then the changes I made to
> a.val in b() would be reflected in the A() instance next time the list
> comprehension called b(). But, obviously that is not happening. I'm
> kinda new at python so I may be missing something obvious here.

Yep:

a.val = a.val + 1

sets in INSTANCE variable a the value computed on the RHS.  A.val (the
CLASS variable) is never changed.  You're not "passing the class", of
course, but rather an instance of the class.

To increment A.val, you need to assign to the class variable, or write
some method in class A which assigns to the class variable.  If you
want, you can change class A only, leaving all of the rest of your code
untouched, with a property (but then A needs to be newstile), e.g.:

class A(object):
_val = 0
def getval(self): return A._val
def setval(self, value): A._val = value
val = property(getval, setval)

now your code should work as intended: any read access to a.val returns
A._val, and any setting of a.val actually sets A._val, as you appear to
desire.


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


Re: passing class by reference does not work??

2007-04-11 Thread wswilson
On Apr 11, 10:36 am, "antred" <[EMAIL PROTECTED]> wrote:
> > def b(item, a):
> > a.val = a.val + 1
> > return item + a.val
>
> This is where the problem lies, specifically the line a.val = a.val +
> 1
> What happens here is that the 1st a.val refers to a member of the
> class instance a, called val ... which does not yet exist and is
> therefore created as the result of taking the val member of the class
> A and adding 1 to it. In other words, a.val is not the same variable
> as A.val. Are you following? If not, change your b() method to this:
>
> def b(item, a):
> a.val = a.val + 1
> assert a.val is A.val
> return item + a.val
>
> and see what happens.

OK, I see that. I thought I was creating an instance of the class A()
when I called the list comprehension and that the a parameter in b()
was then a reference to that instance. What can I do instead?

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


RE: passing class by reference does not work??

2007-04-11 Thread Hamilton, William
> -Original Message-
> From: [EMAIL PROTECTED]
[mailto:python-
> [EMAIL PROTECTED] On Behalf Of wswilson
> Sent: Wednesday, April 11, 2007 9:24 AM
> To: [email protected]
> Subject: passing class by reference does not work??
> 
> Here is my code:
> 
> class A():
>   val = 0
> 
> def b(item, a):
>   a.val = a.val + 1
>   return item + a.val
> 
> def c():
>   d = [1, 2, 3]
>   print [b(item, A()) for item in d]
> 
> c()
> 
> I expected this to output [2, 4, 6]. However, it outputs [2, 3, 4]
> which is not what I wanted. I thought that if I passed the A()
> instance in my list comprehension in c(), then the changes I made to
> a.val in b() would be reflected in the A() instance next time the list
> comprehension called b(). But, obviously that is not happening. I'm
> kinda new at python so I may be missing something obvious here.
> 
> Any suggestions?

A() is not the class A.  It calls the constructor of class A, returning
an instance.  If you change that line to:

print [b(item, A) for item in d]

you'll get the output you expected.

---
-Bill Hamilton
[EMAIL PROTECTED]
 

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


Re: passing class by reference does not work??

2007-04-11 Thread wswilson
On Apr 11, 10:40 am, [EMAIL PROTECTED] (Alex Martelli) wrote:
> wswilson <[EMAIL PROTECTED]> wrote:
> > Here is my code:
>
> > class A():
> >   val = 0
>
> > def b(item, a):
> >   a.val = a.val + 1
> >   return item + a.val
>
> > def c():
> >   d = [1, 2, 3]
> >   print [b(item, A()) for item in d]
>
> > c()
>
> > I expected this to output [2, 4, 6]. However, it outputs [2, 3, 4]
> > which is not what I wanted. I thought that if I passed the A()
> > instance in my list comprehension in c(), then the changes I made to
> > a.val in b() would be reflected in the A() instance next time the list
> > comprehension called b(). But, obviously that is not happening. I'm
> > kinda new at python so I may be missing something obvious here.
>
> Yep:
>
> a.val = a.val + 1
>
> sets in INSTANCE variable a the value computed on the RHS.  A.val (the
> CLASS variable) is never changed.  You're not "passing the class", of
> course, but rather an instance of the class.
>
> To increment A.val, you need to assign to the class variable, or write
> some method in class A which assigns to the class variable.  If you
> want, you can change class A only, leaving all of the rest of your code
> untouched, with a property (but then A needs to be newstile), e.g.:
>
> class A(object):
> _val = 0
> def getval(self): return A._val
> def setval(self, value): A._val = value
> val = property(getval, setval)
>
> now your code should work as intended: any read access to a.val returns
> A._val, and any setting of a.val actually sets A._val, as you appear to
> desire.
>
> Alex

Thanks, that should work well. I appreciate it.

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


Re: tuples, index method, Python's design

2007-04-11 Thread Steven D'Aprano
On Wed, 11 Apr 2007 13:13:20 +, Antoon Pardon wrote:

>> Lists are designed for sequences of homogeneous items, e.g.:
>>
>> L = [1, 2, 4, 8, 16, 32]
>> while tuples are designed to be more like structs or records, with
>> heterogeneous items, e.g.:
>>
>> T = ("Fred", 32, 12.789, {}, None, '\t')
> 
> I think you are confused. 

Anything is possible.


> Last time I heard this homogeneous items stuf,
> it had nothing to do with the types being the same. They were homogeneous
> because they somehow belonged together and heterogeneous because they
> just happened to live together. Similarity of type played no part in
> calling the data homogeneous or heterogeneous.

Nevertheless, regardless of whether the items have the same type or
different types, you don't need an index method for heterogeneous items.

Like I said, think of a tuple as a struct. Even if the fields of the
struct all have the same type, there is little reason to ever ask "which
field has such-and-such a value?".

Anyway, that's was the reasoning. As I've said, tuples do double-duty as
both immutable lists and struct-like objects. I wouldn't object to them
growing index and count methods -- but you won't see me volunteering to
write the code for that, because I don't care that much.

So how about it? All you people who desperately want tuples to grow an
index method -- will any of you donate your time to write and maintain the
code?



-- 
Steven.

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


Re: run function in separate process

2007-04-11 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> somebody points me to a web page/reference that says how to call a
> function then reclaim the whole memory back in python.
> 
> Meanwhile, the best that I could do is fork a process, compute the
> results, and return them back to the parent process. This I

That's my favorite way to ensure that all resources get reclaimed: let
the operating system do the job.

> implemented in the following function, which is kinda working for me
> now, but I am sure it can be much improved. There should be a better
> way to return the result that a temporary file, for example. I

You can use a pipe.  I.e. (untested code):

def run_in_separate_process(f, *a, **k):
import os, sys, cPickle
pread, pwrite = os.pipe()
pid = os.fork()
if pid>0:
os.close(pwrite)
with os.fdopen(pread, 'rb') as f:
return cPickle.load(f)
else:
os.close(pread)
result = f(*a, **k)
with os.fdopen(pwrite, 'wb') as f:
cPickle.dump(f, -1)
sys.exit()

Using cPickle instead of pickle, and a negative protocol (on the files
pedantically specified as binary:-), meaning the latest and greatest
available pickling protocol, rather than the default 0, should improve
performance.


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


Seeking list of Python applications on OS X

2007-04-11 Thread Kevin Walzer
Hello,

I am seeking to update this wiki page, which lists Mac OS X applications 
using Python in a significant way:

http://wiki.python.org/moin/MacPython/MacSoftwareUsingPython

This query is directed at developers of cross-platform Python 
applications who provide full support for the Mac. By "full support," I 
mean that you have Mac-specific builds of your application, deployed in 
a Mac-specific manner (wrapped with py2app or bundlebuilder into a 
standalone application with its own icon, for drag-and-drop 
installation), and that the application run natively in the Mac Aqua 
environment (no X11). This query focuses mainly on desktop applications 
developed with one of the major cross-platform toolkits (Tkinter, 
wxPython, PyQt; Gtk does not run natively on the Mac).

Please post to c.l.p. with your replies and I will add the appropriate 
response to the wiki. Thanks.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


is asynchat broken or just not intended to work like other dispatchers? [PATCH]

2007-04-11 Thread Martin Maney
Simple asyncore application where I wanted to use an explicit map (1)
rather than the automagic default.  Worked fine until I tried to use
asynchat to handle an interactive status and control connection (3) and
found it had no notion about using a non-default map.  After convincing
myself that this must be a simple oversight in asynchat, I applied the
following patch to a local copy.  Of course now I have to carry around
this hacked-up version of asynchat, which sort of defeats the
"batteries included" simplicity thing.  :-(

Anyway, in hopes that maybe in a few years I can lose that ugly
duplication, I offer this patch for what I assume was an oversight:

--- my_chat.py  (revision 6)
+++ my_chat.py  (working copy)
@@ -59,11 +59,11 @@
 ac_in_buffer_size   = 4096
 ac_out_buffer_size  = 4096

-def __init__ (self, conn=None):
+def __init__ (self, conn=None, map=None):
 self.ac_in_buffer = ''
 self.ac_out_buffer = ''
 self.producer_fifo = fifo()
-asyncore.dispatcher.__init__ (self, conn)
+asyncore.dispatcher.__init__ (self, conn, map)

 def collect_incoming_data(self, data):
 raise NotImplementedError, "must be implemented in subclass"

(rev 6 was the checkin of the stock asynchat.py under a different name,
of course)

For the docs I cannot make a specific suggestion: it depends on what is
intended to be exposed and what would be better ignored outside the
implementation.  It's at moments like this that I miss the explicit
declaration of things as public/protected/private from C++ a little. 
Sure, it's rather officious, but it has value in reflecting some
important design criteria in the code... it's better than nothing.


(1) maybe I guessed wrong on this score about what was the yuckier
un-or-incompletely-documented bit to use, but non-default maps are at
least mentioned in asyncore's docs, and when you dig into the code (2)
to see what's going on that's not documented (4) it's obvious that at
least the dispatchers defined in asyncore.py are careful to allow for
the optional map argument, so I think it was reasonable to prefer to
use my own mapping with this interface rather than reaching in and
frobbing asyncore's socket_map... especially after puzzling over the
mysterious way it's defined (maybe?) in asyncore.

(2) code is NOT documentation, dammit.  Well, it's not *good*
documentation, and everyone knows it, as Python's docstrings and XP's
"no written docs, but we have to talk and talk about what's not written
down" (aren't oral traditions grand?  not to mention fragile...) stand
in proof of, just to cite a couple obvious examples.

(3) actually it was the other way around: I had that working just fine
using the default mapping, and it was when I moved from the "playing
around to see if asyn* is suitable" to something a little more useful
that I ran into the problem.  Whatever.

(4) del_channel was another gem - that seems to be the clean way for a
channel to shut itself down from within its input handling code, as for
example that simple interactive status and control thing when it gets
the "quit" command.  Not so much as a hint of it in the docs.  I hope
that's not because using it is in fact a bad idea - I had to guess from
looking at the code, so I can't know what the design intent was.  :-(

-- 
I personally refuse to use inferior tools because of ideology.  In
fact, I will go as far as saying that making excuses for bad tools
due to ideology is _stupid_, and people who do that think with
their gonads, not their brains.  -- Linus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No zlib in Python 2.4.4

2007-04-11 Thread David E. Konerding DSD staff
On 2007-04-11, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Apr 11, 9:14 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> In <[EMAIL PROTECTED]>, shamzz wrote:
>> > Shouldn't zlib be compiled as a Python module automatically in Python
>> > 2.4.4.  I'm guessing Python is doing some kind of check and not
>> > compiling zlib for some reason?
>>
>> It only gets compiled if the header files can be found.  Is the zlib-dev
>> or zlib-devel package installed?
>
> Thanks for the fast reply... this seems to be going off topic from
> Python so sorry about that.
>
> But yep, I've just installed (through YAST) the zlib-devel and zlib-
> devel-32 packages (zlib and zlib-32bit are already installed).
>
> I then did a make clean/configure/make/make install with the Python
> source, but it's still not compiling with zlib.

carefully inspect the configure output.  Where it gets to the zlib output, it
should print a message about whether it found the libraries or not.
Usually, in these situations, I find myself looking closely at the output
in config.log to see exactly what gcc command it tried to run.

If that doesn't help, take a look at the 'make' output.  It might be that there
is no check for zlib in configure, but Python goes to build the module and fails
due to missing headers or libraries.

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


UnicodeEncodeError - a bit out of my element...

2007-04-11 Thread erikcw
Hi all,

I'm trying to parse an email message, but am running into this
exception.

Traceback (most recent call last):
  File "wa.py", line 336, in ?
main()
  File "wa.py", line 332, in main
print out['msg']
UnicodeEncodeError: 'ascii' codec can't encode character u'\xd6' in
position 238: ordinal not in range(128)

How can I decode/encode this string to print to stdout and send again
in another email?  Do I have to know what language the email is in?

Thanks!
Erik

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


descriptor object for an attribute?

2007-04-11 Thread Eric Mahurin
Is there a standard way to get a descriptor object for an arbitrary
object attribute - independent of whether it uses the descriptor/
property protocol or not.  I want some kind of handle/reference/
pointer to an attribute.  I know I could make my own class to do this
(using the __dict__ of the object and the attribute name), but I would
like to use something standard (at least a protocol) if it exists.
All that is needed in the protocol is getter and setter methods (like
__get__ and __set__ in a descriptor).  Of course it would be nice to
have a better syntax than those method names of the descriptor (I've
seen unary + for the getter and += for the setter somewhere on the
web).

Now the question I'm going to get is: why?  I've used ruby (everything
is also already a reference to an object) for several years and been
through this discussion.  I realize that 90% of the time you want some
kind of reference/pointer, there is a better way.  But there are those
occassions where the most elegant solution is with the concept of a
reference.  An obvious example in python today is a descriptor object
- it looks just like a reference (but is not a pointer) - having
getter and setter methods.

The times in C/C++ where the elegant solution is with a pointer to a
pointer is also another example.  That is the situation I'm dealing
with now.  I'm using a singly linked list (as opposed to a normal list/
array for performance/memory reasons).  If you want to insert/delete a
node at a certain point in the list, the best thing to have access to
would be "link" (attribute or even local variable) where you want to
insert/delete.  Without a reference, you'd end up with a less than
ideal solution: a) do the operation based on the previous node and
special case the situation where you want to operate at the head (no
previous node), b) do the operation based on the previous node and add
a dummy head node, or c) make the list doubly linked, do the operation
based on the current node, and either special case the head or add a
dummy head node.  Really I'm dealing with a directed graph structure,
but part of it uses singly linked lists (the children of a parent).
Having a handle on any of the links in the graph would be a useful
thing.

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


Re: run function in separate process

2007-04-11 Thread malkarouri
Thanks Mike for you answer. I will use the occasion to add some
comments on the links and on my approach.

I am programming in Python 2.5, mainly to avoid the bug that memory
arenas were never freed before.
The program is working on both Mac OS X (intel) and Linux, so I prefer
portable approaches.

On Apr 11, 3:34 pm, [EMAIL PROTECTED] wrote:
[...]
> I found a post on a similar topic that looks like it may give you some
> ideas:
>
> http://mail.python.org/pipermail/python-list/2004-October/285400.html

I see the comment about using mmap as valuable. I tried to use that
using numpy.memmap but I wasn't successful. I don't remember why at
the moment.
The other tricks are problem-dependent, and my case is not like them
(I believe).

> http://www.artima.com/forums/flat.jsp?forum=106&thread=174099

Good ideas. I hope that python will grow a replacable gc one day. I
think that pypy already has a choice at the moment.

> http://www.nabble.com/memory-manage-in-python-fu-t3386442.html

> http://www.thescripts.com/forum/thread620226.html

Bingo! This thread actually reaches more or less the same conclusion.
In fact, Alex Martelli describes the exact pattern in
http://mail.python.org/pipermail/python-list/2007-March/431910.html

I probably got the idea from a previous thread by him or somebody
else. It should be much earlier than March, though, as my program was
working since last year.

So, let's say the function I have written is an implementation of
Alex's architectural pattern. Probably makes it easier to get in the
cookbook:)

Regards,

Muhammad

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


Re: descriptor object for an attribute?

2007-04-11 Thread Larry Bates
Eric Mahurin wrote:
> Is there a standard way to get a descriptor object for an arbitrary
> object attribute - independent of whether it uses the descriptor/
> property protocol or not.  I want some kind of handle/reference/
> pointer to an attribute.  I know I could make my own class to do this
> (using the __dict__ of the object and the attribute name), but I would
> like to use something standard (at least a protocol) if it exists.
> All that is needed in the protocol is getter and setter methods (like
> __get__ and __set__ in a descriptor).  Of course it would be nice to
> have a better syntax than those method names of the descriptor (I've
> seen unary + for the getter and += for the setter somewhere on the
> web).
> 
> Now the question I'm going to get is: why?  I've used ruby (everything
> is also already a reference to an object) for several years and been
> through this discussion.  I realize that 90% of the time you want some
> kind of reference/pointer, there is a better way.  But there are those
> occassions where the most elegant solution is with the concept of a
> reference.  An obvious example in python today is a descriptor object
> - it looks just like a reference (but is not a pointer) - having
> getter and setter methods.
> 
> The times in C/C++ where the elegant solution is with a pointer to a
> pointer is also another example.  That is the situation I'm dealing
> with now.  I'm using a singly linked list (as opposed to a normal list/
> array for performance/memory reasons).  If you want to insert/delete a
> node at a certain point in the list, the best thing to have access to
> would be "link" (attribute or even local variable) where you want to
> insert/delete.  Without a reference, you'd end up with a less than
> ideal solution: a) do the operation based on the previous node and
> special case the situation where you want to operate at the head (no
> previous node), b) do the operation based on the previous node and add
> a dummy head node, or c) make the list doubly linked, do the operation
> based on the current node, and either special case the head or add a
> dummy head node.  Really I'm dealing with a directed graph structure,
> but part of it uses singly linked lists (the children of a parent).
> Having a handle on any of the links in the graph would be a useful
> thing.
> 
I believe you are looking for setattr(obj, attr, value) and
getattr(obj, attr) functions.  Since everything in python its a
pointer to an object, I wasn't able to understand EXACTLY what you
were asking (an example would help).

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


SQLObject 0.7.5

2007-04-11 Thread Oleg Broytmann
Hello!

I'm pleased to announce the 0.7.5 release of SQLObject.

What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and
Firebird.  It also has newly added support for Sybase, MSSQL and MaxDB (also
known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.7.5

News and changes:
http://sqlobject.org/docs/News.html


What's New
==

News since 0.7.4


* Fixed a bug in DateValidator caused by datetime being a subclass of date.

* Fixed test_deep_inheritance.py - setup classes in the correct order
  (required for Postgres 8.0+ which is strict about referential integrity).

For a more complete list, please see the news:
http://sqlobject.org/docs/News.html

Oleg.
-- 
 Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: run function in separate process

2007-04-11 Thread malkarouri
On Apr 11, 3:58 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
[...]
> That's my favorite way to ensure that all resources get reclaimed: let
> the operating system do the job.

Thanks a lot, Alex, for confirming the basic idea. I will be playing
with your function later today, and will give more feedback.
I think I avoided the pipe on the mistaken belief that pipes cannot be
binary. I know, I should've tested. And I avoided pickle at the time
because I had a structure that was unpicklable (grown by me using a
mixture of python, C, ctypes and pyrex at the time). The structure is
improved now, and I will go for the more standard approach..

Regards,

Muhammad

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


Re: tuples, index method, Python's design

2007-04-11 Thread Paul Boddie
On 11 Apr, 16:14, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
>
> If you want a language that just adds whatever methods anyone thinks
> of, along with whatever aliases for it any can think of, to every data
> type, you know where to find Ruby.

Nobody is asking for Ruby, as far as I can see. I even submitted a
quick patch to provide tuple.index (a method that has already been
thought of), given the triviality of the solution, but you won't find
me asking for a bundle of different convenience methods with all their
aliases on every object, regardless of whether you can monkey-patch
them after the fact or not. For example:

http://www.ruby-doc.org/core/classes/Array.html#M002235

There's a pretty big chasm between wanting to be able to apply
existing functionality exactly to a type which for some reason never
acquired it and embracing the method proliferation and other low-
hanging fruit-picking seemingly popular in Ruby. In observing this,
one can make objective decisions about things like this...

http://wiki.python.org/moin/AbstractBaseClasses

Note that, in that document, index and count are methods of
MutableSequence. Quite why this should be from a conceptual
perspective is baffling, but don't underestimate the legacy influence
in such matters.

Paul

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


SQLObject 0.8.2

2007-04-11 Thread Oleg Broytmann
Hello!

I'm pleased to announce the 0.8.2 release of SQLObject.


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and
Firebird.  It also has newly added support for Sybase, MSSQL and MaxDB (also
known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.8.2

News and changes:
http://sqlobject.org/News.html


What's New
==

News since 0.8.1


* Fixed ConnectionHub.doInTransaction() - if the original connection was
  processConnection - reset processConnection, not threadConnection.

* Fixed a bug in DateValidator caused by datetime being a subclass of date.

* Fixed test_deep_inheritance.py - setup classes in the correct order
  (required for Postgres 8.0+ which is strict about referential integrity).

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
-- 
 Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: troubles building python 2.5 on Windows XP x64 Windows Server 2003 sp1 Platform SDK

2007-04-11 Thread bhochstetler
On Apr 4, 5:04 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
> > I am needing to buildpython2.5 on Windows XP x64 Windows Server 2003
> > sp1PlatformSDKand am not finding anything documented on the process
> > to use. Has anyone had any success with this?
>
> I did - I built the official binaries with it.
>
> > If so has anyone
> > documented it? The documentation that resides in pcbuild/readme.txt is
> > not helpful at all.
>
> Did you try to follow it? If so, what precisely did you fail at?
>
> [in another message]
>
> > This doc has not been updated since the 64 bit compilers came out
> > officially.
>
> That is not true. The documentation was last updated on 2006-07-14,
> which is after an AMD-64SDKwas released.
>
> > It doesn't make a whole lot of sense of what steps you
> > should follow to buildpython. I saw a link on the comp.lang.python
> > that had the steps, but that link doesn't go anywhere now. I had to
> > jump through some hoops to get it to build on VC 2005 64 bit, but that
> > at least had an IDE to use
>
> If you use vsextcomp, you also have an IDE to do the build. This
> is indeed how the official AMD-64 binaries forPython2.5 were
> produced.
>
> Regards,
> Martin

I guess I am a little confused on the directions for the vsextcomp. I
don't see an IDE for the vsextcomp. Do you know of any explicit
directions on how to do this build?

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


Re: tuples, index method, Python's design

2007-04-11 Thread Chris Mellon
On 11 Apr 2007 08:37:39 -0700, Paul Boddie <[EMAIL PROTECTED]> wrote:
> On 11 Apr, 16:14, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> >
> > If you want a language that just adds whatever methods anyone thinks
> > of, along with whatever aliases for it any can think of, to every data
> > type, you know where to find Ruby.
>
> Nobody is asking for Ruby, as far as I can see. I even submitted a
> quick patch to provide tuple.index (a method that has already been
> thought of), given the triviality of the solution, but you won't find
> me asking for a bundle of different convenience methods with all their
> aliases on every object, regardless of whether you can monkey-patch
> them after the fact or not. For example:
>

Note that the mail I responded to was using being drunk, not knowing
any better, and having fun as use cases for the method. That sounds
like Ruby-style method proliferation to me ;)


> Note that, in that document, index and count are methods of
> MutableSequence. Quite why this should be from a conceptual
> perspective is baffling, but don't underestimate the legacy influence
> in such matters.
>

Well, I'm not Guido obviously, but here's why I don't find it baffling.

There are 2 main reasons why you'd use an immutable sequence for something:
1) You want to make sure it's not modified by a callee. This is
unPythonic and mostly unnecessary. Pass them a copy if you're that
paranoid.

2) Because you are representing a known, structured data type. This
can be either unordered, in which case index() is meaningless (as in
frozenset), or it can be ordered, in which case the order is an
implicit part of the structure. In such a case, index() is also
meaningless, and should never be necessary.

The primary use case for index on tuple is because people use them as
immutable lists. That's fine as far as it goes, but I want to know
what the justification is for using an immutable list, and if you have
one why you need to use index() on it. There's only 2 use cases I've
heard so far for that: certain types of binary parsing, which I don't
think is common enough to justify modification to the language core,
and third party libs returning silly things, which I *certainly* don't
think justifies changes to the language core.

I'm pretty against tuples growing index() ever. I think that if there
is a real need (and just because I haven't seen one doesn't mean it's
not there) for an immutable list, the introduction of fozenlist() to
the collections module (or something) would be a better solution. On
the other hand, if tuples grew list methods and we got a new immutable
sequence that had order, unpacking, and *named fields* along the lines
of Pascal records I'd be happy with that too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError - a bit out of my element...

2007-04-11 Thread kyosohma
On Apr 11, 10:16 am, "erikcw" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm trying to parse an email message, but am running into this
> exception.
>
> Traceback (most recent call last):
>   File "wa.py", line 336, in ?
> main()
>   File "wa.py", line 332, in main
> print out['msg']
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xd6' in
> position 238: ordinal not in range(128)
>
> How can I decode/encode this string to print to stdout and send again
> in another email?  Do I have to know what language the email is in?
>
> Thanks!
> Erik

You'll need to do some encoding/decoding work. Check out the following
links on unicode:

http://www.reportlab.com/i18n/python_unicode_tutorial.html
http://www.amk.ca/python/howto/unicode
http://www.jorendorff.com/articles/unicode/python.html

And here's a few links on parsing:

http://docs.python.org/api/arg-parsing.html
http://www.diveintopython.org/xml_processing/unicode.html

Probably more information than you need, but it should help answer
your question (and maybe any future questions about Unicode).

Mike

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


Re: UnicodeEncodeError - a bit out of my element...

2007-04-11 Thread liupeng
I cut from Sam Python Phrasebook
"Converting Unicode to Local Strings"

import string locStr = "El " 
uniStr = u"Ni\u00F1o" 
print uniStr.encode('utf-8') 
print uniStr.encode('utf-16') 
print uniStr.encode('iso-8859-1') 
#Combine local and unicode results 
#in new unicode string 
newStr = locStr+uniStr 
print newStr.encode('iso-8859-1') 
#ascii will error because character '\xF1' 
#is out of range 
asciiStr = newStr.encode('iso-8859-1') 
asciiStr =asciiStr.translate(\ 
string.maketrans('\xF1','n'), '') 
print asciiStr.encode('ascii') 
print newStr.encode('ascii')

unicode_str.py 

Niño 
ÿN|I|ñ|o 
Niño 
El Niño 
El Nino 
Traceback (most recent call last): 
  File "C:\books\python\CH2\code\unicode_str.py", 
line 19, in ? 
print newStr.encode('ascii') 
UnicodeEncodeError: 'ascii' codec can't encode 
 character u'\xf1' in position 5: ordinal not in 
 range(128)

On Wed, Apr 11, 2007 at 08:16:07AM -0700, erikcw wrote:
> Hi all,
> 
> I'm trying to parse an email message, but am running into this
> exception.
> 
> Traceback (most recent call last):
>   File "wa.py", line 336, in ?
> main()
>   File "wa.py", line 332, in main
> print out['msg']
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xd6' in
> position 238: ordinal not in range(128)
> 
> How can I decode/encode this string to print to stdout and send again
> in another email?  Do I have to know what language the email is in?
> 
> Thanks!
> Erik
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 


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

Re: Seeking list of Python applications on OS X

2007-04-11 Thread Frank Niessink
Hi Kevin,

2007/4/11, Kevin Walzer <[EMAIL PROTECTED]>:
> Hello,
>
> I am seeking to update this wiki page, which lists Mac OS X applications
> using Python in a significant way:

Task Coach is developed with python and wxPython and is distributed as
dmg. See http://www.taskcoach.org

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


bittorent

2007-04-11 Thread Linus Nordström
Hello
Im planing playing a bit whit bittorrent, but I'm having some trouble
about where to start. So if anyone could point me in the right
direction it would be much appreciated.
The best would be if there are some already written modules that
handle downloading and seeding torrents, but if that cant be found a
good source on how one dose to build some sort of bitorrent client
would be nice.

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


SQLObject 0.9.0b1

2007-04-11 Thread Oleg Broytmann
Hello!

I'm pleased to announce the 0.9.0b1 release of SQLObject, the first beta of
the upcoming 0.9 release.


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and
Firebird.  It also has newly added support for Sybase, MSSQL and MaxDB (also
known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.9.0b1

News and changes:
http://sqlobject.org/News.html


What's New
==

News since 0.8
--

Features & Interface


* Support for Python 2.2 has been declared obsolete.

* Removed actively deprecated attributes;
  lowered deprecation level for other attributes to be removed after 0.9.

* SQLite connection got columnsFromSchema(). Now all connections fully support
  fromDatabase. There are two version of columnsFromSchema() for SQLite -
  one parses the result of "SELECT sql FROM sqlite_master" and the other
  uses "PRAGMA table_info"; the user can choose one over the other by using
  "use_table_info" parameter in DB URI; default is False as the pragma is
  available only in the later versions of SQLite.

* Changed connection.delColumn(): the first argument is sqlmeta, not
  tableName (required for SQLite).

* SQLite connection got delColumn(). Now all connections fully support
  delColumn(). As SQLite backend doesn't implement "ALTER TABLE DROP COLUMN"
  delColumn() is implemented by creating a new table without the column,
  copying all data, dropping the original table and renaming the new table.

* Versioning_.

.. _Versioning: Versioning.html

* MySQLConnection got new keyword "conv" - a list of custom converters.

* Use logging if it's available and is configured via DB URI.

* New columns: TimestampCol to support MySQL TIMESTAMP type;
  SetCol to support MySQL SET type;
  TinyIntCol for TINYINT; SmallIntCol for SMALLINT;
  MediumIntCol for MEDIUMINT; BigIntCol for BIGINT.

Small Features
--

* Support for MySQL INT type attributes: UNSIGNED, ZEROFILL.

* Support for DEFAULT SQL attribute via defaultSQL keyword argument.

* Support for MySQL storage ENGINEs.

* cls.tableExists() as a shortcut for conn.tableExists(cls.sqlmeta.table).

* cls.deleteMany(), cls.deleteBy().

Bug Fixes
-

* idName can be inherited from the parent sqlmeta class.

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
-- 
 Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-list


Shebang or Hashbang for modules or not?

2007-04-11 Thread Chris Lasher
Should a Python module not intended to be executed have shebang/
hashbang (e.g., "#!/usr/bin/env python") or not? I'm used to having a
shebang in every .py file but I recently heard someone argue that
shebangs were only appropriate for Python code intended to be
executable (i.e., run from the command line).

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


Re: Parsing log in SQL DB to change IPs to hostnames

2007-04-11 Thread Steve Holden
KDawg44 wrote:
[ ... ]
> 
> ohhh okay.  thanks so much.  I knew that it came out as strings, i
> guess it makes sense that I would have to send it back IN as a
> string.  Changed that and now it works!  THanks so much.
> 
> I just specified once specific field so that it would not change the
> whole db on a test run.
> 
> Thanks so much.
> 
It's great that you solved your problem, but please disabuse yourself of 
the notion that the database returns everything as strings:

  >>> curs.execute("SELECT * from contact")
  >>> data = curs.fetchone()
  >>> for item in data:
  ...   print type(item)
  ...







  >>>

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

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


pop() clarification

2007-04-11 Thread Scott
As said before I'm new to programming, and I need in depth explaination to 
understand everything the way I want to know it, call it a personality quirk 
;p.

With pop() you remove the last element of a list and return its value:

Now I know list is a bad name, but for the sake of arguement lets assume its 
not a built in sequence>

>>>list = ['this', 'is', 'an', 'example']
>>>list.pop()
'example'
>>>list
['this', 'is', 'an']

I understand all that.  What I don't understand is why all the documentation 
I see says, "When removing a specific element from a list using pop() it 
must be in this format: list.pop([i]).
At first I took that to mean that list.pop(i) would return some type of 
error, but it doesn't.
I can't find any documentation saying that this rule that I keep reading 
about (again list.pop([i]) ) is the only format to use when removing a 
specific element because..with the explaination to follow.

Now I'm not stupid enough to believe that I'm the first to try:
>>>list = ['this', 'is', 'an', 'example']
>>>list.pop(1)
and have it return the desired effect of:
'is'
>>>list
['this', 'an', 'example']


I guess simplistically all I'm asking is:  Is this just a community agreed 
upon rule for readability purposes? or Is it a rule that's in place for a 
reason I'll learn later on?  Please keep in mind my intro sentence to this 
post.  I would like a very detailed explaination, or at least a link to a 
very detailed expression.  ONLYof courseif the explaination isn't, 
well it just is because we all agreed to use it that way.  That explaination 
I'll understand and except, but with a bit of dissatisfaction. 


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


Re: bittorent

2007-04-11 Thread Terry Reedy

"Linus Nordström" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Hello
| Im planing playing a bit whit bittorrent, but I'm having some trouble
| about where to start. So if anyone could point me in the right
| direction it would be much appreciated.
| The best would be if there are some already written modules that
| handle downloading and seeding torrents, but if that cant be found a
| good source on how one dose to build some sort of bitorrent client
| would be nice.

Bittorrent, the program, is written in Python. 



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

Re: Universal Feed Parser issue

2007-04-11 Thread i3dmaster
On Apr 11, 12:06 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Wed, 11 Apr 2007 01:51:13 -0300, i3dmaster <[EMAIL PROTECTED]>
> escribió:
>
>
>
> > On Apr 10, 6:45 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > wrote:
> >> En Tue, 10 Apr 2007 14:58:42 -0300, i3dmaster <[EMAIL PROTECTED]>
> >> escribió:
>
> >> > 
> >> >  ...
> >> >   
> >> >   
> >> > 
>
> >> > After parsed by feedparser, the timezone element does not get the
> >> > attribute "America/Mountain". Same thing on status element. This does
> >> > not sound an expected result.  I am wondering if it should be
> >> > considered a bug...
>
> >> Usually it's a good idea to read the documentation...
> >>http://www.feedparser.org/docs/namespace-handling.html
>
> > I did. Perhaps its because of not 100% atom compatible of my feed
> > format? See if I use gnosis xml utility to parse it, it works fine
> > though...
>
> The link above answers *exactly* your question - have you actually read
> the page?
>
> --
> Gabriel Genellina

Hmm... well I don't know if I made my question clear then or you might
have misread it?... Anyway, the namespace handling wasn't the issue
of  this question. feedparser handles it as expected but only when
there is a text value associated with it. Look at the rdf file you
will see  the prism:issn element has a text value but in my case, the
foo:timezone element DOES NOT have a text value but a Attribute or
maybe attributes... What it looks like is feedparser simply ignores
all the attributes when parsing it. This behavior wasn't seen from
other xml parsers though.

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


Re: Shebang or Hashbang for modules or not?

2007-04-11 Thread Paddy
On Apr 11, 5:29 pm, "Chris Lasher" <[EMAIL PROTECTED]> wrote:
> Should a Python module not intended to be executed have shebang/
> hashbang (e.g., "#!/usr/bin/env python") or not? I'm used to having a
> shebang in every .py file but I recently heard someone argue that
> shebangs were only appropriate for Python code intended to be
> executable (i.e., run from the command line).

If you don't intend the module to be executable then adding a shebang
line and/or setting the files execute bit are both contrary to
intended use. You should therefore leave out the shebang/not set the
execute bit to emphasise your intended use.
During development however, intended use may differ from use when
deployed.

- Paddy.

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


Creating Unique Dictionary Variables from List

2007-04-11 Thread Greg Corradini

Hello All,
I'm attempting to create multiple dictionaries at once, each with unique
variable names. The number of dictionaries i need to create depends on the
length of a list, which was returned from a previous function.
The pseudo code for this problem would be:

returnedlist = [x,y,z]
count = 0
for i in returnedlist:
   if count < len(returnedlist):
   # then create a dictionary (beginning with variable dic) for each i
with a unique name such that
   # my unique name would be dic + count

Any ideas about this?
Greg


-- 
View this message in context: 
http://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560469.html#a9943317
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Creating Unique Dictionary Variables from List

2007-04-11 Thread Greg Corradini

Hello All,
I'm attempting to create multiple dictionaries at once, each with unique
variable names. The number of dictionaries i need to create depends on the
length of a list, which was returned from a previous function.
The pseudo code for this problem would be:

returnedlist = [x,y,z]
count = 0
for i in returnedlist:
   if count < len(returnedlist):
   # then create a dictionary (beginning with variable dic) and add a
unique ending such that
   # my final dictionary name would be dic + count for each i

Any ideas about this?
Greg


-- 
View this message in context: 
http://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560470.html#a9943320
Sent from the Python - python-list mailing list archive at Nabble.com.

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


text file vs. cPickle vs sqlite a design question

2007-04-11 Thread Dag
I have an application which works with lists of tuples of the form
(id_nr,'text','more text',1 or 0).  I'll have maybe 20-50 or so of these 
lists containing anywhere from 3 to over 3 tuples.  The actions I
need to do is either append a new tuple to the end of the list, display 
all the tuples or display all the tuples where the last element is a 1

Basically what I'm wondering is the best way to store these data stuctures 
to disc.  As the subject mentioned I've basically got three approaches.
Store each list as a text file, pickle each list to file or shove the
whole thing into a bunch of database tables.  I can see pros and cons
with each approach.  Does anybody have any advice as to whether any of
these approaches is obviously better than any other?  On one hand I like
the text file approach since it lets me append without loading
everything into memory, on the other hand the sqlite approach makes it
easy to select stuff with SELECT * FROM foo WHERE... which could be
handy if ever need to add more advanced filtering.

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


Re: Hellow World:)

2007-04-11 Thread Scott
The author of that book is qouted as saying:
''Note: My more recent book, Beginning Python is an expanded and revised 
version of this book.''

That qoute can be found at http://hetland.org/writing/practical-python/
However, from my personal experience some of the codes in beginning python 
have some errors and without a decent foundation in programming can lead to 
very frustrated attempts at understanding a topic, but the source for all 
code examples can be found online at 
http://hetland.org/writing/beginning-python/

As someone thats new to programming myself visit http://diveintopython.org/ 
its a book thats written by the same guy (I believe), and so far its helped 
me tremendously in conjuction with beginning python and (now dont laugh) 
python for dummies.  That book was suggested to me when I asked basically 
the same thing you are asking.


"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> En Thu, 29 Mar 2007 16:19:24 -0300, void pointer 
> <[EMAIL PROTECTED]> escribió:
>
>> Hi All ..I am looking for PDF version of " Practical Python"  and a 
>> language to stick to .Should I find that book ,I wil lconsder  this 
>> Python :)


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

Re: pop() clarification

2007-04-11 Thread Jerry Hill
On 4/11/07, Scott <[EMAIL PROTECTED]> wrote:
> I see says, "When removing a specific element from a list using pop() it
> must be in this format: list.pop([i]).

The tutorial (http://docs.python.org/tut/node7.html) says the following:

pop( [i] )
Remove the item at the given position in the list, and return it.
If no index is specified, a.pop() removes and returns the last item in
the list. (The square brackets around the i in the method signature
denote that the parameter is optional, not that you should type square
brackets at that position. You will see this notation frequently in
the Python Library Reference.)

Does that answer your question?

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


Creating Unique Dictionary Variables from List

2007-04-11 Thread Greg Corradini

Hello All,
I'm attempting to create multiple dictionaries at once, each with unique
variable names. The number of dictionaries i need to create depends on the
length of a list, which was returned from a previous function.
The pseudo code for this problem would be:

returnedlist = [x,y,z]
count = 0
for i in returnedlist:
   if count < len(returnedlist):
   # then create a dictionary (beginning with variable dic) and add a
unique ending such that
   # my final dictionary name would be dic + count for each i

Any ideas about this?
Greg
-- 
View this message in context: 
http://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560471.html#a9943321
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: bittorent

2007-04-11 Thread Jonathan Smith
Linus Nordström wrote:
> Hello
> Im planing playing a bit whit bittorrent, but I'm having some trouble
> about where to start. So if anyone could point me in the right
> direction it would be much appreciated.
> The best would be if there are some already written modules that
> handle downloading and seeding torrents, but if that cant be found a
> good source on how one dose to build some sort of bitorrent client
> would be nice.
> 
> thanks in advance

you might start with bittorrent itself [1] - it is written in python.

[1]: http://www.bittorrent.com/download

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


Re: Parsing log in SQL DB to change IPs to hostnames

2007-04-11 Thread KDawg44
On Apr 11, 11:58 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 11 Apr 2007 05:39:21 -0700, "KDawg44" <[EMAIL PROTECTED]> declaimed
> the following in comp.lang.python:
>
> > ohhh okay.  thanks so much.  I knew that it came out as strings, i
> > guess it makes sense that I would have to send it back IN as a
> > string.  Changed that and now it works!  THanks so much.
>
> I'd be interested in the schema definition -- my experience has been
> that numeric fields come out of MySQLdb as numerics...
>
> >>> import MySQLdb
> >>> cn = MySQLdb.connect(host="localhost", user="BestiariaCP", db="bestiaria")
> >>> cr = cn.cursor()
> >>> cr.execute("select * from comics where banner is not Null")
> 35L
> >>> cr.fetchone()
>
> (2L, 'Anxiety Cafe', 'Anxiety Cafe',
> 'http://rockerbot.artistrealm.org/', 'images/ronandrockerbutton.jpg',
> 234L, 60L, 'Platitudes from a platypus.', 'On hiatus - site rebuild',
> 'N', 'Y')
>
>
>
> Note the first field there -- a Python long integer (the schema
> defines that as an integer auto_increment field). Also the "234L, 60L,"
> (image width/height) -- all returned as numeric.
>
> If your data is coming out as a string, I'd suspect the schema
> defined it as a character type.
>
> >>> cr.description
>
> (('ID', 3, 2, 11, 11, 0, 0), ('name', 253, 33, 100, 100, 0, 0),
> ('sortname', 253, 33, 100, 100, 0, 0), ('URL', 253, 56, 75, 75, 0, 0),
> ('banner', 253, 29, 75, 75, 0, 1), ('width', 3, 3, 11, 11, 0, 1),
> ('height', 3, 3, 11, 11, 0, 1), ('description', 252, 170, 65535, 65535,
> 0, 0), ('occurs', 253, 58, 125, 125, 0, 1), ('isactive', 254, 1, 1, 1,
> 0, 0), ('isonline', 254, 1, 1, 1, 0, 0))
>
>
>
> CREATE TABLE `comics` (
>   `ID` int(11) NOT NULL auto_increment,
>   `name` varchar(100) NOT NULL default '',
>   `sortname` varchar(100) NOT NULL default '',
>   `URL` varchar(75) NOT NULL default '',
>   `banner` varchar(75) default NULL,
>   `width` int(11) default NULL,
>   `height` int(11) default NULL,
>   `description` text NOT NULL,
>   `occurs` varchar(125) default NULL,
>   `isactive` enum('N','Y') NOT NULL default 'Y',
>   `isonline` enum('N','Y') NOT NULL default 'Y',
>   PRIMARY KEY  (`ID`),
>   KEY `namesort` (`sortname`)
> ) ENGINE=MyISAM AUTO_INCREMENT=92 DEFAULT CHARSET=latin1;
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

I see your point.  Somewhere in my head I must have mixed them up.  It
goes in as a string but comes out as whatever data type.

Thanks.

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


SOAPPY Install Issues

2007-04-11 Thread Robert Rawlins - Think Blue
Hi Guys,

 

I've been trying hopelessly -ALL- afternoon to get python-xml and
python-soappy working nicely, but for the -LIFE- of me I keep running into
the same brick wall over and over.

 

I'm running Debian and I've installed the latest stable builds of Python,
Python-XML and Python-SOAPPY along with all there depensancies but i get the
following error when trying to run my code.

 

Traceback (most recent call last):

  File "xml.py", line 1, in ?

from SOAPpy import SOAPProxy

  File "/var/lib/python-support/python2.4/SOAPpy/__init__.py", line 5, in ?

from Client  import *

  File "/var/lib/python-support/python2.4/SOAPpy/Client.py", line 57, in ?

from Parser  import parseSOAPRPC

  File "/var/lib/python-support/python2.4/SOAPpy/Parser.py", line 9, in ?

import xml.sax

  File "/pblue/xml.py", line 1, in ?

from SOAPpy import SOAPProxy

ImportError: cannot import name SOAPProxy

 

This is my Code:

 

from SOAPpy import SOAPProxy

url = 'http://services.xmethods.net:80/soap/servlet/rpcrouter'

namespace = 'urn:xmethods-Temperature'  

server = SOAPProxy(url, namespace)  

server.getTemp('27502')

 

It's a very simple program, and its driving me bonkers not being able to get
it working, I'd appreciate any help you can offer to help resolve it.

 

Thanks guys, I'm sure this is just a typical NOOB mistake, but hopefully
once the damn thing is up and running it'll be clear sailing.

 

Rob

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

  1   2   3   >