Posted messages not appearing in this group

2007-07-18 Thread Sanjay
Hi All,

I tried posting in this group twice since last week, but the messages
did not appear in the forum. Don't know why. Trying this message
again...

Sanjay

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


Re: Best method for inter process communications

2007-07-18 Thread Hendrik van Rooyen
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote:
On Tue, 17 Jul 2007 08:08:45 +0200, Hendrik van Rooyen wrote:

> I heard a rumour once that a "hello world" string takes something like
> 10k bytes in XMLRPC - have never bothered to find out if its BS...

Just try it out:

In [8]: import xmlrpclib

In [9]: a = xmlrpclib.dumps(('hello world',))

In [10]: len(a)
Out[10]: 80

In [11]: print a


hello world



Even with some additional boilerplate like XML declaration etc. there is
still a little bit room until 10 kB are reached.  :-)

LOL - so  one could say it was a bit of an exaggeration...

Thanks - Hendrik

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


Re: Can a low-level programmer learn OOP?

2007-07-18 Thread Hendrik van Rooyen
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote:

> Don't confuse Python's "roaming names" with OOP, though. There are
> OOP languages that still follow the variable=>memory address containing
> object structure.

"roaming names" is a brilliant description!

Thanks Dennis!

- Hendrik

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


Re: Pickled objects over the network

2007-07-18 Thread Hendrik van Rooyen


Walker Lindley  wrote:

8<  complaint about pickle error on receiving side -

Google for netstrings.

It looks to me like you are trying to unpickle something that is not a whole
pickle...

Append the length of the pickle to the front of it, and on the receiving side,
first receive the length, then the pickle...

Also have a look at Pyro

- Hendrik


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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-18 Thread Duncan Booth
Asun Friere <[EMAIL PROTECTED]> wrote:

> On Jul 17, 5:38 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> 
>> indeed anything which has an __int__ method may be
>> passed to the %d formatter:
> 
> Anything?! Sorry to be persnickety here, but what about this:
> 
> class C :
>   def __int__ (self) : pass
> 
> '%d' % C()
> 
__int__ is a reserved method name so it is reasonable to assume that any 
such method will act as documented: "Should return a value of the 
appropriate type." If you choose to ignore the documentation then expect 
exceptions to be thrown.

> or this:
> 
> def foo (val) : return val
> foo.__int__ = lambda x=42 : int(x)
> 
> '%d' % foo('spam')
> 

I don't see any methods named '__int__' there, just a function assigned to 
an attribute. (Yes, I know that isn't the problem, assigning a function to 
an __int__ attribute works for other types, but if you can be silly so can 
I.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing javascript variables within psp code

2007-07-18 Thread Bruno Desthuilliers
BAnderton a écrit :
> Hello all,
> 
> Question:  Is there any way to access a javascript variable from
> within psp code?

Short answer : no (or at least: not directly). And it has nothing to do 
with PSP.


Long answer: this has to do with the http protocol. Things go like this:

1/ the client (usually the browser) send a request (via typing an url in 
the address bar, clicking a link, posting a form...)

2/ the server process the request (this is where your psp - or any other 
server-side - code is executed) and send back a response (in your case, 
what has been generated by the psp code).

3/ the client do something (usually: display) the response. This is 
where Javascript - if any, and if supported by the client - is executed.

 From the server's POV, once the response is sent, the transaction is 
finished.

The only way to have client-side javascript communicate with the server 
is via the XmlHttpRequest object (IOW : ajax). This allow javascript 
code to send a request to a server without reloading the whole page.


(snip)
 >
> FYI, I've already found a workaround for the above example (by placing
> a "get" variable in the URL, reloading the page, and having psp check
> for the existence of that variable before proceeding with deleting the
> appropriate file) 


Beware, GET request should *not* have such side-effects on the server. A 
GET request is meant - as the name implies - to get data from the 
server. Use a POST request instead.

If you're going to do web development, reading the http RFC might be 
helpful...


> but I'd still like this general capability for
> future projects.  

Then you have to learn how to use XmlHttpRequest.

> I've searched several forums, websites, etc. and
> the
> answer has aluded me for two days now.  I'm new to apache, mod_python,
> and javascript, so this may be ridiculously simple.
> 
> Since this is my first post on google groups,


Small correction : you're not posting "on" google groups, you're posting 
on usenet *from* google groups. Most people prefer to access usenet via 
a newsreader.


> I'd also appreciate any
> helpful suggestions on how to best go about getting answers quickly

http://www.catb.org/~esr/faqs/smart-questions.html

And remember that usenet is definitively not an help desk. No one get 
paid for answering your questions.

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


Re: Design question regarding exceptions.

2007-07-18 Thread Bruno Desthuilliers
asincero a écrit :
> I have a class called Users that provides a higher level of
> abstraction to an underlying "users" table in a pgsql database.  It
> has methods like "addUser()" and "deleteUser()" which, obviously, wrap
> the corresponding SQL statements.  My question is would it better to
> let any exceptions thrown by the underlying DB-API calls bubble up
> from these methods, or should I catch them inside the methods, wrap
> them inside my own custom exceptions, and throw those exceptions
> instead?

There's no absolute answer to this. But unless your "abstraction layer" 
is supposed to be usable with non-DB-API backends (ie: text files, LDAP, 
etc), I don't see any reason to abstract the exceptions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a=0100; print a ; 64 how to reverse this?

2007-07-18 Thread Bruno Desthuilliers
Karthik Gurusamy a écrit :
> On Jul 17, 5:35 am, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
>> mosi a écrit :
>>
>>
>>
>>> Problem:
>>> how to get binary from integer and vice versa?
>>> The simplest way I know is:
>>> a = 0100
>>> a
>>> 64
>>> but:
>>> a = 100 (I want binary number)
>>> does not work that way.
>>> a.__hex__   exists
>>> a.__oct__ exists
>>> but where is a.__bin__ ???
>>> What`s the simplest way to do this?
(snip)
>>  >>> a = int('100', 2)
>>  >>> a
>> 4
(snip)
> While it's interesting to know we can go from binary to int, the OP
> wanted the other way.

Please reread more carefully the OP's question and code snippet (which 
are just above).

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


Re: Interpreting non-ascii characters.

2007-07-18 Thread ddtl
On Wed, 18 Jul 2007 08:29:58 +1000, John Machin <[EMAIL PROTECTED]> wrote:
> ...

I have a bunch of directories and files from different systems 
(each directory contains files from the same system) which are
encoded differently (though all of them are in Russian), so the
following encodings are present: koi8-r, win-1251, utf-8 etc., 
and I want to transliterate them into a regular ASCII so that they 
would be readable regardless of the system. Personally I use both 
Linux and Windows. So what I do, is read file name using os.listdir, 
convert to list ('foo.txt' => ['f', 'o', ... , 't'], except that 
file names are in Russian), transliterate (some letters in Russian 
have to be transliterated into 2 or even 3 Latin letters),
and then rename file.

It seems though that after all I solved the problem - I thought
that my Windows (2000) used win-1251 and Linux used koi8-r and
because of that I couldn't understand what are those strange 
codes I got while experimenting with locally created Cyrillic
file names, but in effect Linux uses utf-8, and Windows uses cp866,
so after getting it and reading the article you suggested I
solved the problem.

Thanks.

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


Real-time Update

2007-07-18 Thread ReTrY
I'm writing a program with Tkinter GUI, When the program is running it
need to be updated every five seconds (data comes from internet). How
should I do that ? How to make a function in main loop ?

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


Compatibility of python2.5 with pytohn2.3

2007-07-18 Thread VISHAL KANAUJIA
Hi all,
 I am new member of this post. I have a C application which uses
Python(version 2.3) extensively with SWIG wrappers. I want to upgrade
the Python to latest version2.5.

Is there any compatibility issue between two versions? Does latest
Python2.5 provide backward compatibility to previous Python (Version
2.3 in my case) constructs.

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


Re: Discover instance variables

2007-07-18 Thread Dave Baum
In article <[EMAIL PROTECTED]>,
 JonathanB <[EMAIL PROTECTED]> wrote:

> I can handle the formatting and changing the variable itself, no
> problem, but how do I get a list of all the variables in a class
> instance? I almost put a list in there called vars and appended all
> the variables to it so I could iterate the list, but this sounds like
> something useful enough that someone has come up with a better way to
> do it than that. It almost looks like self.__dir__() is what I want,
> but that returns methods as well, correct? I only want variables, but
> I can't think of how to do a list comprehension that would remove the
> methods.

For simple cases, the object's __dict__ will probably give you what you 
want.  By default, that's where an object's instance variables are 
stored, and you can just examine the keys, etc:

class Foo(object):
 def __init__(self):
 self.a = "bar"
 self.z = "test"
 self.var = 2
 
foo = Foo()
print foo.__dict__

-> {'a': 'bar', 'var': 2, 'z': 'test'}

However, there are lots of ways to bypass using the __dict__ to hold 
attributes.  If the class uses any of these techniques, __dict__ either 
will not exist or may not be complete.  A few of the techniques that 
come to mind are:

* custom __getattr__/__setattr__ methods (or __getattribute__ in a new 
style class)

* descriptors (http://docs.python.org/ref/descriptors.html)

* using __slots__ in a new style class


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


Subprocess Poll() to sport Application Crash

2007-07-18 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have an application which launches a sub-process using the sub
process/Popen module, which seems to work great. However on occasion the
launched process will crash, it doesn't appear to full terminate though as
when I run a 'top' command from the Linux system the process is still
displayed in the list, it just appears to be dormant and the TIME+ for the
application stops incrementing.

 

Can I use the poll() method from the sub-process object to test for this? I
would love to test it however the crash is so rare it's very difficult to
simulate, so thought I'd try and see if anyone has any experience of this.

 

Thanks chaps,

 

Rob

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

Subprocess Poll

2007-07-18 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have an application which launches a sub-process using the sub
process/Popen module, which seems to work great. However on occasion the
launched process will crash, it doesn't appear to full terminate though as
when I run a 'top' command from the Linux system the process is still
displayed in the list, it just appears to be dormant and the TIME+ for the
application stops incrementing.

 

Can I use the poll() method from the sub-process object to test for this? I
would love to test it however the crash is so rare it's very difficult to
simulate, so thought I'd try and see if anyone has any experience of this.

 

Thanks chaps,

 

Rob

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

Re: how to find available classes in a file ?

2007-07-18 Thread Alex Popescu
On Jul 17, 4:41 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu  
> <[EMAIL PROTECTED]> escribió:
>
> > On Jul 17, 1:44 am, Stef Mientki <[EMAIL PROTECTED]>
> > wrote:
> >> I want to have a (dynamically) list of all classes defined in a py-file.
> >> Is there a way of getting this list, without manually parsing the file ?
>
> > I have written something that does something like this, but I am not
> > sure it is the pythonic way.
> > Bascially I am loading the module and then using dir() on the module
> > object I am looking for
> > attribute of the type classobj (for old style classes) and type type
> > (for new style classes).
>
> There is also the pyclbr standard module  
>  that does not load the  
> module (just reparses enough of it to get the info needed). So a broken  
> import, or any other initialization error, won't hurt.
>
> > I also heard of the inspect module, but I haven't checked it yet.
>
> inspect.getmembers(the_module, inspect.isclass) would do. But this  
> requires the module to be importable.
>
> --
> Gabriel Genellina

I think I have figured out a difference between how my dir() based
implementation works
and the inspect.getmembers(module, inspect.isclass) works. In my
implementation only the
classes defined in the module are considered, while the inspect
functionality returns also the
imported classes. Am I seeing wrong results on this? (cause the
documentation is not very clear
about the inspect part).

./alex
--
.w( the_mindstorm )p.


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

Re: Pickled objects over the network

2007-07-18 Thread Jean-Paul Calderone
On Tue, 17 Jul 2007 14:57:16 -0700, Walker Lindley <[EMAIL PROTECTED]> wrote:
>I'm working on a distributed computing program and need to send Python
>objects over a TCP socket. Specifically, the objects that I'm working with
>subclass the builtin list type (I don't know whether or not that matters),
>but also include other data fields. These objects are put into dictionaries
>along with some other control information and the dictionaries are pickled
>and sent across the network. I'm using the makefile() function in socket to
>get a file descriptor for the socket and then calling pickle.dump with the
>dictionary object and the socket file descriptor. I was originally using
>pickle protocol 0, but then read about the possibility of buffering problems
>and realized that protocol 0 was giving me strings about 1500 characters
>long. After some testing, I settled on protocol 2 which manages to package
>the data into about 400 characters.
>
>In any case, the client side of the program appears to send the data just
>fine, at least as far as I can tell. On the server side, however, the data
>takes a very long time to get there and then I get an error in the pickle
>module:
>Traceback (most recent call last):
>  File "server.py", line 176, in 
>serv.runServer()
>  File "server.py", line 99, in runServer
>recvPacket = pickle.load(clientFile)
>  File "/usr/lib/python2.5/pickle.py", line 1370, in load
>return Unpickler(file).load()
>  File "/usr/lib/python2.5/pickle.py", line 858, in load
>dispatch[key](self)
>  File "/usr/lib/python2.5/pickle.py", line 1187, in load_appends
>mark = self.marker()
>  File "/usr/lib/python2.5/pickle.py", line 874, in marker
>while stack[k] is not mark: k = k-1
>IndexError: list index out of range
>
>Hopefully I'm doing something obviously wrong, but if anyone can help based
>on that description or if you need to see the source, please let me know
>(it's GPL'd). Thank you so much for any help.
>

The obvious thing you're doing wrong is using pickle over a network. ;)

  http://jcalderone.livejournal.com/15864.html

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


Re: how to find available classes in a file ?

2007-07-18 Thread Alex Popescu
On Jul 17, 4:41 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu  
> <[EMAIL PROTECTED]> escribió:
>
> > On Jul 17, 1:44 am, Stef Mientki <[EMAIL PROTECTED]>
> > wrote:
> >> I want to have a (dynamically) list of all classes defined in a py-file.
> >> Is there a way of getting this list, without manually parsing the file ?
>
> > I have written something that does something like this, but I am not
> > sure it is the pythonic way.
> > Bascially I am loading the module and then using dir() on the module
> > object I am looking for
> > attribute of the type classobj (for old style classes) and type type
> > (for new style classes).
>
> There is also the pyclbr standard module  
>  that does not load the  
> module (just reparses enough of it to get the info needed). So a broken  
> import, or any other initialization error, won't hurt.
>
> > I also heard of the inspect module, but I haven't checked it yet.
>
> inspect.getmembers(the_module, inspect.isclass) would do. But this  
> requires the module to be importable.
>
> --
> Gabriel Genellina

I think I have found a difference between my dir(module) based
implementation
and the inspect.getmember(module, inspect.isclass) functionality. Mine
is
returning only the classes defined in the provided module, while the
later is
returning also the imported classes. Am I getting the results
wrongly?
(I don't seem to see this explanation in the inspect.getmembers doc or
I am just
misreading it).

./alex
--
.w( the_mindstorm )p.


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

XL-RPC Recipe

2007-07-18 Thread Thomas
Hi list!

I'm struggling with a recipe from the Python Cookbook (2nd ed.)
concerning XML-RPC. It's recipe 15.2 "Serving XML-RPC Requests", and
since I thought it's a popular book some other folks might have
discovered (and probably solved) the same issue.

The recipe provides server and client code, and I get an
error when trying the following client request:

print server.python_string.join(['I', 'like it!'], " don't ")

(In the server code the string name space is mapped into the
'python_string' member with "import string; self.python_string = string").

The error report says:

xmlrpclib.Fault: :method
"python_string.join" is not supported'>

This happens with all the string methods in
StringFunctions.python_string. Is there a general issue with mapping
name spaces into an RPC object? Or am I missing a major point here?

I tried all of this on a fairly up-to-date Linux with a stock
Python 2.5 (also tried with WinXP/cygwin/Python2.5.1 and with a
Stackless 2.5.1, always with same outcome, so I don't believe it's an
issue of a local installation).

Any hints?

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


Re: Single-stepping through a python script

2007-07-18 Thread Diez B. Roggisch
Craig Howard wrote:

>  >>Craig Howard schrieb:
>  >> Hello All:
>  >>
>  >> Is is possible to compile a code object and single-step through its
>  >> execution?
> 
>  >import pdb; pdb.set_trace()
>  >
>  >Look up the pdb module documentation.
>  >
>  >Diez
> 
> Sorry, I didn't give enough detail. Is it possible to single-step
> through a
> code object without using pdb? (Pdb uses the console which is not
> what I want.)

Well, what do you want? How do you suppose to perform any interaction with a
running process if not through a window?

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


Re: XL-RPC Recipe

2007-07-18 Thread Thomas
Ah, sorry, found the answer myself (not that I wasn't looking for it for
days...): I was aware that the recipe is online at ActiveState's site
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81549), but I
didn't read all of the comments carefully:

KAMOSAWA Masao wrote on 2006/04/29 that the use of dotted functions is
disabled by default in the server (from Python 2.4 onwards). But it can
be enabled with:

server.register_instance(StringFunctions(), allow_dotted_names = True)

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


Re: Posted messages not appearing in this group

2007-07-18 Thread Alex Popescu
Sanjay  gmail.com> writes:

> 
> Hi All,
> 
> I tried posting in this group twice since last week, but the messages
> did not appear in the forum. Don't know why. Trying this message
> again...
> 
> Sanjay
> 

Something similar seemed to happen to me too, but when checking with gmane I've
noticed that all my posts got in (and now I am trying to figure out how can I
apologize for multiple posts :-) ).

bests,
./alex
--
.w( the_mindstorm )p.


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


Re: Semantics of file.close()

2007-07-18 Thread Hrvoje Niksic
"Evan Klitzke" <[EMAIL PROTECTED]> writes:

>> But the writes are buffered, and close causes the buffer to be
>> flushed.  file.close can throw an exception just like fclose, but
>> it will still ensure that the file is closed.
>
> Is this buffering being done by Python or the kernel?

It is done in the user space, by the C stdio library which Python
currently uses for IO.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickled objects over the network

2007-07-18 Thread Nick Craig-Wood
Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
>  On Tue, 17 Jul 2007 14:57:16 -0700, Walker Lindley <[EMAIL PROTECTED]> wrote:
> >I'm working on a distributed computing program and need to send Python
> >objects over a TCP socket.
[snip]
> >Hopefully I'm doing something obviously wrong, but if anyone can help based
> >on that description or if you need to see the source, please let me know
> >(it's GPL'd). Thank you so much for any help.
> 
>  The obvious thing you're doing wrong is using pickle over a network. ;)
> 
>http://jcalderone.livejournal.com/15864.html

I'd say the obvious thing being done wrong is re-inventing the wheel.
Use pyro instead...

  http://pyro.sourceforge.net/

Pyro does use pickle to serialise objects by default.  It can use XML
instead for an exploit free RPC at the cost of a bit of speed.

  http://pyro.sourceforge.net/manual/9-security.html#pickle

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compatibility of python2.5 with pytohn2.3

2007-07-18 Thread Gerhard Häring
VISHAL KANAUJIA wrote:
> Hi all,
>  I am new member of this post. I have a C application which uses
> Python(version 2.3) extensively with SWIG wrappers. I want to upgrade
> the Python to latest version2.5.
> 
> Is there any compatibility issue between two versions? Does latest
> Python2.5 provide backward compatibility to previous Python (Version
> 2.3 in my case) constructs.

Short answer: yes.

I've never had any issues here (compiling Python extension code in newer
Python versions). The other way around that's of course not the case. I
have to test my extension code against Python 2.4 and Python 2.3 regularly,
because otherwise issues arise where I wouldn't have expected them, like
even simple macros like PyDict_CheckExact not being present in older Python
versions.

-- Gerhard

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


Re: how to find available classes in a file ?

2007-07-18 Thread Alex Popescu
Alex Popescu  gmail.com> writes:

> 
> On Jul 17, 4:41 am, "Gabriel Genellina"  yahoo.com.ar>
> wrote:
> > En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu  
> >  gmail.com> escribi
> 


I apologize for posting the previous message a couple of times, 
but I wasn't seeing it displayed on the  Google groups.

./alex
--
.w( the_mindstorm )p.




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


Re: pytz giving incorrect offset and timezone

2007-07-18 Thread Sanjay
Hi Simon,

localize worked perfectly. Thanks a lot for the vital help! Your
elaboration on the concepts was also very nice and informative!

thanks
Sanjay

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


Copy List

2007-07-18 Thread Robert Rawlins - Think Blue
Hello Guys,

 

What's the best way to create a copy of a list? I've seen several method and
I'm not sure what to use. This will be in a class and one method creates a
list which I then want to move to the self scope, like so:

 

__Init__(self):

Self.myList = []

 

regenerateList(self):

 

newList = []

 

for somthing in somthing:

newList.append('SomeStuff')

 

self.Mylist = newList.copy()

 

See, The iteration and rebuilding of the list could be quite slow, during
which time the application could be reading from the self.mylist variable so
i think simply doing this:

 

regenerateList(self):

 

self.myList = []

 

for somthing in somthing:

self.myList.append('SomeStuff')

 

Might cause a few inconsistencies in the list if it's being read from whilst
I'm appending too it, so I'm guessing that the top example is the best
method, I'm just looking for the best way to copy() that list into the self
scope, should i be using copy(), deepcopy() or simply self.mylist = newlist?

 

Thanks guys,

 

Rob 

 

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

Re: Copy List

2007-07-18 Thread Tim Williams
On 18/07/07, Robert Rawlins - Think Blue
<[EMAIL PROTECTED]> wrote:

>
> What's the best way to create a copy of a list? I've seen several method and
> I'm not sure what to use. This will be in a class and one method creates a
> list which I then want to move to the self scope, like so:
>

listB = listA[:]

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


Re: Copy List

2007-07-18 Thread Joe Riopel
On 7/18/07, Robert Rawlins - Think Blue
<[EMAIL PROTECTED]> wrote:
> What's the best way to create a copy of a list?

I am pretty new to python but this works:

>>> list_one = [0,1,2,3,4,5,6,7,8,9]
>>> list_two = [i for i in list_one]
>>> print list_two
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copy List

2007-07-18 Thread Joe Riopel
I forgot to mention that you can go here for a little more of an explanation:
http://diveintopython.org/native_data_types/mapping_lists.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copy List

2007-07-18 Thread Rustom Mody
The standard idiom (I guess) is to use the slice
>>> a=[1,2,3,4]
>>> b=a
>>> b is a
True
>>> b
[1, 2, 3, 4]
>>> c=a[:]
>>> c is a
False
>>> c
[1, 2, 3, 4]

This is shallow copy
If you want deep copy then
from copy import deepcopy
-- 
http://mail.python.org/mailman/listinfo/python-list


best SOAP module

2007-07-18 Thread Sells, Fred
I need to talk to a vendor side via SOAP,  Googling is overwhelming and many
hits seem to point to older attempts.

Can someone tell me which SOAP module is recommended.  I'm using Python 2.4.

---
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---
-- 
http://mail.python.org/mailman/listinfo/python-list


New guy question - user form

2007-07-18 Thread meg99
I am using a scheduling sw package that uses Python as its scripting
language much like Excel uses Visual Basic.  I am fluent in VB but I
am just beginning in Python.

What I need to do is this:  I need to create a user form that will
contain some predefined data (captured from the scheduling sw
database) and some fields that the user will enter.  When the user is
finished, he will write the data to the database via a command button
on the form.

I have looked at some of the tutorials and I have a couple of books
but I don't see a user form utility like there is in VB.

I am using version 1.5.2 (the sw I am using does not now support
anything else).

Can I do what I have described with what I have?

Regards,

meg99

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


Re: accessing javascript variables within psp code

2007-07-18 Thread Carsten Haese
On Wed, 2007-07-18 at 01:29 +, BAnderton wrote:
> Hello all,
> 
> Question:  Is there any way to access a javascript variable from
> within psp code?
> 
> 
> I'm aware of how to do the reverse of this (js_var='<%=psp_var%>').
> 
> 
> Here's a non-working example of what I'm trying to do:
> 
> 
> - - - (begin example) - - -
> 
> 
> function Test(txt)
> {
> a = confirm('Are you sure you want to delete '+txt+'?')
> if (a)
> {
> //The problem is getting the value of js variable 'txt' recognized in
> "psp space".
> <%
> os.remove(  os.path.join(os.path.dirname(req.filename), '../notes/'+
> %>txt<%)  )
> %>
> 
> 
> }
> }
> 
> 
> - - - (end example) - - -
> 
> FYI, I've already found a workaround for the above example (by placing
> a "get" variable in the URL, reloading the page, and having psp check
> for the existence of that variable before proceeding with deleting the
> appropriate file) but I'd still like this general capability for
> future projects.  I've searched several forums, websites, etc. and
> the
> answer has aluded me for two days now.  I'm new to apache, mod_python,
> and javascript, so this may be ridiculously simple.

>From your vague description it sounds like the contents of your
JavaScript variable come from the server to begin with. In that case
it's easier and more secure to "remember" the correct value on the
server instead of sending it to the client and trusting the client[*] to
send the same value back.

To store variables on the server side between requests by the same
client, use session variables.

[*] A basic premise of web programming is that the client can't be
trusted: Don't trust that maximum form field sizes will be honored,
don't trust that cookies won't be changed, don't trust that GET
parameters won't be changed, don't trust that hidden form fields won't
be changed, etc.

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Charlotte Python Group

2007-07-18 Thread Calvin Spealman
I am looking to start a meetup in or near Charlotte. I already have a
couple people interested, and I see some folks subscribing to new
python groups on meetup. If I can find a few more people, it could be
worth it.

Is anyone in the area and interested in a group? Anyone who might want
to do a talk, about anything interesting? Does anyone have suggestions
of a good place in Charlotte to meet, maybe at a cafe with enough
room? I'm from up in the Kannapolis/Concord area myself, so I'm not
familiar with many places in the city proper, but I see a few
possibilities at Google Maps.

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: exists already

2007-07-18 Thread Xah Lee
About a month ago, i posted a message about modernization of emacs. I
enlisted several items that i think emacs should adapt.

Today I added another section to the frequestly asked questions.
The new section is pasted below. The full article can be found at
http://xahlee.org/emacs/modernization.html

--

Q: The Meta key is logical and proper, it shouldn't be renamed to Alt.

A: Most computer geekers think that the so-called "Meta" key of Emacs
is a more general and logical naming, and they believe in Emacs
documentation the term "Meta key" should not be called the "Alt key"
to fit the mundane PC keyboard.

[image]
above: The Space-cadet keyboard (Source , 2007-07) .

Emacs's naming of Meta key isn't actually a general naming scheme. It
is simply the name of a special modifier key on a particular keyboard
popularly used with Emacs in the 1980s. (see Space-cadet keyboard ) On
this keyboard, it has several modifier keys, including Ctrl, Meta,
Super, Hyper. The Emacs's use of the term "Meta key" simply referred
to that key on that keyboard. Emacs actually also support the other
modifier keys Super and Hyper to this day. The Space-cadet keyboard
fell out of use along with Lisp machine . The IBM PC keyboard  (and
its decendents) becomes the most popular since the 1990s and is
practically the standard keyboard used today. The IBM PC keyboard does
not have Super and Hyper keys, so Emacs's support for them becomes
little known, but Ctrl remains Ctrl while Meta is mapped to the Alt
key.

In Emacs's documentation, the term Meta key should be replaced with
the Alt key, to reflect current usage, since that is the keyboard 99%
of personal computer users know. The "Meta key" name is a major point
of confusion for getting people to learn Emacs. The abbreviation C-
 and M- to represent keyboard shortcuts should similarly be
updated to the more easy-to-understand and universal Ctrl- and
Alt-.

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

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


Re: Discover instance variables

2007-07-18 Thread Bjoern Schliessmann
JonathanB wrote:

> So given that example, is there a clean way to get this output:
> 
> Data for Earth:
> Name = Earth
> WTN = 5.0
> Ag = 0
> Na = 0
> ...
> ...
> Notes = None

Sure, save the __init__ parameters explicitly in a dict.

self.data = {"Name": name,
 "WTN":  WTN,
 "Ag":   Ag,
 ... 
}

To display them, you can iterate through the dict:

print "Data for Earth:"
for field, content in self.data.items():
print "%s = %r" % field, content

Hope that helps.

Regards,


Björn

-- 
BOFH excuse #188:

..disk or the processor is on fire.

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


Re: The Modernization of Emacs: exists already

2007-07-18 Thread Rustom Mody
Xah Lee:

I agree with what you say now and most of what you wrote a month back
-- I even learnt something useful from there -- longlines mode.

Emacs is important to me and (I guess) to many of the subscribers here.

But how does posting an emacs related question help on a python mailing list??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: exists already

2007-07-18 Thread Wildemar Wildenburger
Rustom Mody wrote:
> But how does posting an emacs related question help on a python mailing list??
>   
One Word: Ego.
Don't reply.

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


Re: Problem with building extension in Python

2007-07-18 Thread cornpicker
I solved my problem.

I had the math.h import step in the wrong location. The import step
needed to be outside of the function -- I'm so embarrassed.

Code: [Download]

   1.
   2. #
   3. #  Use C math functions
   4. #
   5.
   6. # Import the native C functions we need
   7. cdef extern from "math.h":
   8. double cos(double theta)
   9. double sin(double theta)
  10.
  11.
  12. def cTest(double theta):
  13.
  14. cdef double result[2]
  15.
  16. import sys
  17.
  18. result[0] = cos(theta)
  19. result[1] = sin(theta)
  20.
  21. pyResult = (result[0], result[1])
  22.
  23. return pyResult
  24.
25.



Now it works

If I type the following into the python shell

import cTest
cTest.cTest(.775)

The function returns

(0.71442103405593138, 0.69971607534660352)


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


Re: Copy List

2007-07-18 Thread Lawrence Oluyede
Joe Riopel <[EMAIL PROTECTED]> wrote:
> I am pretty new to python but this works:
> 
> >>> list_one = [0,1,2,3,4,5,6,7,8,9]
> >>> list_two = [i for i in list_one]
> >>> print list_two
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

>> list_two = list_one[:]

or 

>> list_two = list(list_one)

are better :D

-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand 
something when his salary depends on not
understanding it" - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best SOAP module

2007-07-18 Thread Lawrence Oluyede
Sells, Fred <[EMAIL PROTECTED]> wrote:
> I need to talk to a vendor side via SOAP,  Googling is overwhelming and many
> hits seem to point to older attempts.
> 
> Can someone tell me which SOAP module is recommended.  I'm using Python 2.4.

Try soaplib: 

-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand 
something when his salary depends on not
understanding it" - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: exists already

2007-07-18 Thread Rustom Mody
Eh? Me? you?? Who???
Did I say something offensive? Sorry if I did... but I dont understand...

I must say that I found the earlier post useful to me as an old-time
emacs user who's not quite upto all the latest stuff.  However it was
quite off topic for a python list.
The flame war that followed was quite a waste of time and bandwidth:
-- one person who seems to know little blowing his trumpet
-- others who know a great deal (of emacs) not acknowledging the room
for improvement

All off topic for a python list

Sorry once again if I said something offensive.

On 7/18/07, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote:
> Rustom Mody wrote:
> > But how does posting an emacs related question help on a python mailing 
> > list??
> >
> One Word: Ego.
> Don't reply.
>
> /W
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: exists already

2007-07-18 Thread Joe Riopel
Sorry, I don't understand why this is still on the python mailing list.

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


Mouse/keyboard watcher?

2007-07-18 Thread skip

Sorry to bomb this list with an off-topic post, however...  Ages ago I wrote
a mouse/keyboard watcher in Python+Tk: http://sf.net/projects/watch.  It's
been idle for a long while though, isn't terribly portable and doesn't work
properly with tools like Synergy (http://sf.net/projects/synergy2).
Someone, I thought from this list or maybe python-dev, told me about a newer
open source application in the same space which is more portable and
actively maintained/developed.  Alas, I can't recall the name, nor can I
find it on my computer.  Ring any bells?

Thx,

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


Re: Break up list into groups

2007-07-18 Thread Miki
Hello Dan,

Yet another option (using itertools.groupby):

from itertools import groupby

class GrouperToggler:
def __init__(self):
self.group = 1

def __call__(self, value):
# New packet, toggle group
if value & 0x80:
self.group = 1 - self.group
return self.group

def group(items):
for group, items in groupby(items, GrouperToggler()):
# groupby return [key, group_iterator]
yield [item for item in items]

i = [
0xF0, 1, 2, 3,
0xF0, 4, 5, 6,
0xF1, 7, 8,
0xF2, 9, 10, 11, 12, 13,
0xF0, 14,
0xF1, 15
]

for g in group(i):
print g

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com

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


Re: The Modernization of Emacs: exists already

2007-07-18 Thread Wolfgang Mederle
Xah Lee wrote:

> In Emacs's documentation, the term Meta key should be replaced with
> the Alt key, to reflect current usage, since that is the keyboard 99%
> of personal computer users know. The "Meta key" name is a major point
> of confusion for getting people to learn Emacs. 

This is utter bullshit. On my Mac, the Meta key is mapped to the Command
key, while the Alt (Option) key is used by the system.

Follow-up to comp.emacs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Charlotte Python Group

2007-07-18 Thread Wildemar Wildenburger
Calvin Spealman wrote:
> I am looking to start a meetup in or near Charlotte. I already have a
> couple people interested, and I see some folks subscribing to new
> python groups on meetup. If I can find a few more people, it could be
> worth it.
>
> Is anyone in the area and interested in a group? Anyone who might want
> to do a talk, about anything interesting? Does anyone have suggestions
> of a good place in Charlotte to meet, maybe at a cafe with enough
> room? I'm from up in the Kannapolis/Concord area myself, so I'm not
> familiar with many places in the city proper, but I see a few
> possibilities at Google Maps.
>
>   
Hey, can you get a little less specific, please? I can just about make 
out what place you're talking about. This one 
, 
right?

/W (your personal know-nothing nitpicker)
-- 
http://mail.python.org/mailman/listinfo/python-list


Property Descriptor - Public Getter, Private Setter

2007-07-18 Thread gamehack
Hi all,

I was looking around the net to figure out how I can use the
property() descriptor to make a property readable by everyone and only
settable by the class or any derived classes. Thanks.

Regards,
gh

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


Re: Pickled objects over the network

2007-07-18 Thread Walker Lindley

Thanks for all the help, I tried sending the length and then the string and
that appears to work, so I'll take a look at Pyro, too.


-Walker

On 7/18/07, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:


Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
>  On Tue, 17 Jul 2007 14:57:16 -0700, Walker Lindley <
[EMAIL PROTECTED]> wrote:
> >I'm working on a distributed computing program and need to send Python
> >objects over a TCP socket.
[snip]
> >Hopefully I'm doing something obviously wrong, but if anyone can help
based
> >on that description or if you need to see the source, please let me
know
> >(it's GPL'd). Thank you so much for any help.
>
>  The obvious thing you're doing wrong is using pickle over a network. ;)
>
>http://jcalderone.livejournal.com/15864.html

I'd say the obvious thing being done wrong is re-inventing the wheel.
Use pyro instead...

  http://pyro.sourceforge.net/

Pyro does use pickle to serialise objects by default.  It can use XML
instead for an exploit free RPC at the cost of a bit of speed.

  http://pyro.sourceforge.net/manual/9-security.html#pickle

--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list





--
This e-mail is licensed under the Creative Commons
Attribution-NoDerivs 2.5License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nd/2.5/ or send a letter to Creative
Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105,
USA.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: shutil.copyfile problem for GIS data

2007-07-18 Thread Larry Bates
Ahmed, Shakir wrote:
> Need help to copy a personal geodatabase from one location to another:
> 
> 
> Trying to copy a personal geodatabase from one location to another
> location where all the users are retrieving data from the second
> location:
> 
> 1.I can copy over the updated personal geodatabase to the working
> location and overwrite it, though the file is opened by ArcGIS  users
> (Local Installation of Arc GIS  on the users computers).
> 
> 
> 2.But problem is that  I can't copy over if the same updated
> personal geodatabase to the working location,  if users uses that same
> geodatabase through CITRIX - ArcGIS ( user does not have  permission to
> edit the data)
> 
> 3.the python script which I am using as follows:
> 
> import shutil
> import os
> 
> src = "c:\mydata\test\mygeo.mdb"
> dst = "v:\updated\data\mygeo.mdb"
> 
> shutil.copyfile(src,dst)
> 
> I highly appreciate if any one of you can help me and give me a
> direction that I can solve this problem.
> 
> Thanks in advance.
> 
> Shak

While I'm uncertain about the exact nature of your problem I can tell you that
the src string you have defined won't work becaust \t is a tab character.  To
make shutil.copyfile work you need to do:

src = r"c:\mydata\test\mygeo.mdb"
dst = r"v:\updated\data\mygeo.mdb"

 or

src = "c:\\mydata\\test\\mygeo.mdb"
dst = "v:\\updated\\data\\mygeo.mdb"


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


Re: wxPython and threads

2007-07-18 Thread James Matthews

Sounds like a race condition. is List Ctrl waiting for the gui to return?
Maybe make the processing more then one thread!

On 7/17/07, Stef Mientki <[EMAIL PROTECTED]> wrote:


Benjamin wrote:
> I'm writing a search engine in Python with wxPython as the GUI. I have
> the actual searching preformed on a different thread from Gui thread.
> It sends it's results through a Queue to the results ListCtrl which
> adds a new item. This works fine or small searches, but when the
> results number in the hundreds, the GUI is frozen for the duration of
> the search. I suspect that so many search results are coming in that
> the GUI thread is too busy updating lists to respond to events. I've
> tried buffer the results so there's 20 results before they're sent to
> the GUI thread and buffer them so the results are sent every .1
> seconds. Nothing helps. Any advice would be great.
>
maybe you'ld better ask this question in the wxPython discussion group:

[EMAIL PROTECTED]

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





--
http://www.goldwatches.com/watches.asp?Brand=14
http://www.jewelerslounge.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Pydev 1.3.8 Released

2007-07-18 Thread Fabio Zadrozny

Hi All,

Pydev and Pydev Extensions 1.3.8 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Code-analysis: Detects mixing of spaces and tabs.
* Code-analysis: Reimport not flagged when inside of try..except
ImportError.


Release Highlights in Pydev:
--

* Fixed problems related to the pydev package explorer that appeared when
using java 1.6 (ConcurrentModificationException)
* Other minor bug-fixes



What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and Jython
development -- making Eclipse a first class Python IDE -- It comes with many
goodies such as code completion, syntax highlighting, syntax analysis,
refactor, debug and many others.


Cheers,

--
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Open HTML file in IE

2007-07-18 Thread Larry Bates
gravey wrote:
> Hello.
> 
> Apologies if this is a basic question, but I want to open a HTML
> file from my local drive (is generated by another Python script)
> in Internet Explorer. I've had a look at the webbrowser module and
> this doesn't seem to be what I need. Any help much appreciated.
> 

There are several ways.  Assuming that IE is your default browser, just do:

import os
os.system('filename.html')

If you want to make certain that IE is launched (and not FireForx or some other
defult broswer) you can do:

os.system("start iexplore filename.html")

(at least this works on my system).

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


Re: Property Descriptor - Public Getter, Private Setter

2007-07-18 Thread Diez B. Roggisch
gamehack wrote:

> Hi all,
> 
> I was looking around the net to figure out how I can use the
> property() descriptor to make a property readable by everyone and only
> settable by the class or any derived classes. Thanks.

Forget it. You can try and come up with an implementation that will check
the stack-frames and try and see if the callers belong to the current
class, or some subclass.

But then if somebody wants to accomplish the setting by all means, he/she
just adds a new setter method to your class, and that's it.

What's your usecase? If you give us that, there might be better suggestions.

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


Re: Mouse/keyboard watcher?

2007-07-18 Thread Skip Montanaro
> Someone, I thought from this list or maybe python-dev, told me about
> a newer open source application in the same space which is more
> portable and actively maintained/developed.  Alas, I can't recall
> the name...

Found it: workrave (http://www.workrave.org/).  Sorry for the noise.

Skip


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


wxPython, searching, and threads

2007-07-18 Thread Benjamin
Hello! I am writing a search engine with wxPython as the GUI. As the
search thread returns items, it adds them to a Queue which is picked
up by the main GUI thread calling itself recursively with
wx.CallAfter. These are then added to a ListCtrl. This works fine for
small searches, but with larger and longer searchs the GUI is clogged
and won't respond. I suspect (I may be wrong) that there are so many
results being sent to the ListCtrl that the event loop doesn't have
time to respond to events. I've tried buffering the results before
sending them to the GIU, but that doesn't help at all. Please advise.

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


Re: New guy question - user form

2007-07-18 Thread Diez B. Roggisch
meg99 schrieb:
> I am using a scheduling sw package that uses Python as its scripting
> language much like Excel uses Visual Basic.  I am fluent in VB but I
> am just beginning in Python.
> 
> What I need to do is this:  I need to create a user form that will
> contain some predefined data (captured from the scheduling sw
> database) and some fields that the user will enter.  When the user is
> finished, he will write the data to the database via a command button
> on the form.
> 
> I have looked at some of the tutorials and I have a couple of books
> but I don't see a user form utility like there is in VB.
> 
> I am using version 1.5.2 (the sw I am using does not now support
> anything else).
> 
> Can I do what I have described with what I have?

AFAIK Python 1.5 featured Tkinter, which should do what you want.

But given the embedded nature of your python, I'm not sure if that 
really works (the python interpreter could be crippled), or what that 
software of yours offers itself.


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


Re: Pickled objects over the network

2007-07-18 Thread Rustom Mody
Sure pyro may be the solution but it may also be overkill
Why not use safe_load from the yaml module?
-- 
http://mail.python.org/mailman/listinfo/python-list


help with create menu in wxpython

2007-07-18 Thread franciscodg
hi group:

I have the following code:

..
..
 #MENU
menuFile = wx.Menu()
menuFile.Append(14, "E&xit","Sale del programa")

menuHelp = wx.Menu()
menuHelp.Append(41, "&about Mutamatic","Informacion de
Mutamatic")

menuBar = wx.MenuBar()
menuBar.Append(menuFile, "&File")
menuBar.Append(menuHelp, "&Help") #THIS IR IS THE PROBLEM!!!

self.SetMenuBar(menuBar)
self.sb = self.CreateStatusBar(1, wx.ST_SIZEGRIP)

#menu help
self.Bind(wx.EVT_MENU, self.OnAbout, id=41)
.




The question is the following: how can  put the menu "HELP" in right
part of the window?

for example:

-
|FILE||HELP|
-
|windows  |
||
-

Exist some attribute or function that does it??


thank you very much...

greeting

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


Re: help with create menu in wxpython

2007-07-18 Thread Stef Mientki
better ask in the wx discussion group:
   [EMAIL PROTECTED]

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


Threading XL [was: Re: The Modernization of Emacs: exists already]

2007-07-18 Thread Wildemar Wildenburger
Rustom Mody wrote:
> Eh? Me? you?? Who???
> Did I say something offensive? Sorry if I did... but I dont understand...
>
>   
No no, it's cool. Maybe I was a little too terse. Xah Lee likes to 
crosspost his pseudo-philosophical tech-musings to several discussion 
groups at regular intervalls. He's not too dumb about it either, he 
usually manages to pick topics that you can easily argue about for ages 
and not get anywhere (He sort of picked too easy a target with emacs 
this time.).
I don't know why he does it, but my personal belief is that he just 
likes to start endless discussions to feel better about himself because 
that proves to him his smarts or something (hence my 
one-word-explanation: Ego). Maybe he has other reasons. I couldn't care 
less. What I do care about is that people just go on and on in these 
threads. It's tedious and I wish people would just ignore the guy (Or 
reply to him directly --- now wouldn't that be fun, people?).


> I must say that I found the earlier post useful to me as an old-time
> emacs user who's not quite upto all the latest stuff.  However it was
> quite off topic for a python list.
>   
I fail to see how anything useful came up in this thread (except for 
antropologists/sociologists maybe), but if it did for you: fine. 
Whatever floats your boat :).


> The flame war that followed was quite a waste of time and bandwidth:
> -- one person who seems to know little blowing his trumpet
> -- others who know a great deal (of emacs) not acknowledging the room
> for improvement
>
> All off topic for a python list
>
>   
Very nice summary.


> Sorry once again if I said something offensive.
>   
Once again: You didn't.

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


"The basics" difficulties

2007-07-18 Thread MooMooBunnyLips
I'm trying to get this basic sample to work:
http://docs.python.org/ext/dnt-basics.html

When I get to the last step:
$ python setup.py build

I get this error:
error: Python was build with Visual Studio version 8.0 and
extensions need to be built with the same version of the compiler,
but it isn't installed.

This is bogus, as I do have VS8 installed.  I used it to compile
the python stuff actually.

Is there anyway to get this to work without using the distutils;
i.e. just compiling it myself?

Thank you

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


Re: Fast powerset function

2007-07-18 Thread Arash Arfaee

Hi All

With your help I found lots of good method and algorithm. Also I found out
if I exchange all for loop with while loop it make the program much faster
and also it consumes less memory (almost half!)
Just wanna thank you all.
Cheers,
Arash

On 7/13/07, Mark Dickinson <[EMAIL PROTECTED]> wrote:


If you don't care about the order of the results, you can use a Gray
code (http://en.wikipedia.org/wiki/Gray_code): this has the advantage
of only adding or removing a single element to get from one subset to
the next.

def powerset(s):
d = dict(zip(
(1<>> list(powerset('abc'))
[set([]), set(['a']), set(['a', 'b']), set(['b']), set(['c', 'b']),
set(['a', 'c', 'b']), set(['a', 'c']), set(['c'])]

If you're using the subsets as they appear and don't need to store
them all at once, then it's significantly faster (on my machine) if
you replace the line subset = subset ^ d[i & -i] with an in-place
update:  subset ^= d[i & -i].

Mark


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

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

Re: Implementaion of random.shuffle

2007-07-18 Thread George Sakkis
On Jul 16, 10:51 pm, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Mon, 16 Jul 2007 16:55:53 +0200, Hrvoje Niksic wrote:
> > 2**19937 being a really huge number, it's impossible to exhaust the
> > Mersenne twister by running it in sequence.
>
> "Impossible"?
>
> Surely this will do it:
>
> for n in xrange(2**19937 + 1):
> random.random()
>
> Admittedly, if each call to random() took a picosecond, it would still
> take 1e5982 centuries to run through the lot. You might want to go make a
> coffee or something while you're waiting...

Wow, can you make a coffee in.. 57ms ?

$ time python -c "for n in xrange(2**19937 + 1): random.random()"
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: long int too large to convert to int

real0m0.057s
user0m0.050s
sys 0m0.000s


Time-flies-like-an-arrow-ly y'rs ;-)

George

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


Re: Pickled objects over the network

2007-07-18 Thread Eduardo \"EdCrypt\" O. Padoan
On 7/18/07, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Tue, 17 Jul 2007 14:57:16 -0700, Walker Lindley <[EMAIL PROTECTED]> wrote:
[...]
> The obvious thing you're doing wrong is using pickle over a network. ;)
>
>   http://jcalderone.livejournal.com/15864.html

Ok, maybe not the best tools to the job, but there are some more
secure alternatives:
http://trustedpickle.sourceforge.net/
http://home.gna.org/oomadness/en/cerealizer/index.html

-- 
EduardoOPadoan (eopadoan->altavix::com)
Bookmarks: http://del.icio.us/edcrypt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tibco Rendezvous

2007-07-18 Thread rdahlstrom
Sent you an email - have you found anything else on this?  I'm not all
that familiar with ctypes, and am having a little trouble getting
started with this.  Anything I could use just to get started would be
fantastic - I can go from there.  Thanks!

On Jul 13, 1:43 pm, "Kip Lehman" <[EMAIL PROTECTED]> wrote:
> Circa summer 2003, at a company I previously worked at, a co-worker and
> I had an occasion to see if we could get Python and TIBCO Rendezvous
> working together.
>
> The SWIG-based tibrv mechanism was insufficient, buggy and was problematic
> in terms of keeping up with Python releases.
>
> We resorted to using ctypes with the relevant TIBCO header files
> and confabulating our own package to work with TIBCO Rendezvous messages
> (both publishing and subscribing).
> We didn't concern ourselves with certified messages.
>
> Feel free to contact me directly if you want me to see if I can
> unearth any further info.
>
> --
>
> --
> Kip Lehman
> kipster  t  earthlink  net
>
> ...still waiting for PanAm, Amtrack and the USPS to deliver my .sig


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


Re: Open HTML file in IE

2007-07-18 Thread brad
gravey wrote:
> Hello.
> 
> Apologies if this is a basic question, but I want to open a HTML
> file from my local drive (is generated by another Python script)
> in Internet Explorer. I've had a look at the webbrowser module and
> this doesn't seem to be what I need. Any help much appreciated.

You may try something like this example:

import time
import win32com.client

wie = win32com.client.Dispatch('InternetExplorer.Application')

# Make IE Window Visible.
wie.Visible = 1

# Open this URL
wie.Navigate('www.your_url.com')

# Print 'Busy' while Busy.
while wie.Busy:
 print 'Busy'

# Sleep 2 secs, then go home.
time.sleep(2)
wie.GoHome()

# Sleep 2 secs, then go back.
time.sleep(2)
wie.GoBack()

# Refresh the page
time.sleep(2)
wie.Refresh()

# Close IE Window
time.sleep(2)
wie.Quit()

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


Re: Deleting files and folders used by other processes on Windows

2007-07-18 Thread brad
[EMAIL PROTECTED] wrote:
> Hi,
> 
> I have been looking into making my file cleaning script more
> intelligent.  The goal of the script is to delete everything on a
> drive except for a couple of folders which are skipped by the script.
> Recently, I noticed that some files where not being deleted because a
> process was using them.  

Try this:

 try:
 # Make the file's attributes normal so file can be 
deleted.
 win32api.SetFileAttributes(os.path.join(root, f), 
win32con.FILE_ATTRIBUTE_NORMAL)
 # HKLM/SYSTEM/CurrentControlSet/Control/Session 
Manager/PendingFileRenameOperations
 win32api.MoveFileEx(os.path.join(root, f), None, 
win32con.MOVEFILE_DELAY_UNTIL_REBOOT)
 except Exception, e:
 print e

Upon reboot the file will be gone... careful though, this canl delete 
any Windows system file too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Deleting files and folders used by other processes on Windows

2007-07-18 Thread tkondal
 Hi,

I have been looking into making my file cleaning script more
intelligent. The goal of the script is to delete everything on a
drive except for a couple of folders which are skipped by the script.
Recently, I noticed that some files where not being deleted because a
process was using them. Is there a recipe (needs to run on Windows XP/
2003) for doing the following (more specifically, I need a way to
determine which process is holding a lock on my file):


file=GetFilename();
bLock = IsThereAFileLockOnFile(file)
If (bLock)
{
process = GetLockingProcess(file);
TerminateProcess(process);
}
DeleteFile(file);



Thanks.

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


wxPython, searching, and threads

2007-07-18 Thread Benjamin
Hello! I am writing a search engine with wxPython as the GUI. As the
search thread returns items, it adds them to a Queue which is picked
up by the main GUI thread calling itself recursively with
wx.CallAfter. These are then added to a ListCtrl. This works fine for
small searches, but with larger and longer searchs the GUI is clogged
and won't respond. I suspect (I may be wrong) that there are so many
results being sent to the ListCtrl that the event loop doesn't have
time to respond to events. I've tried buffering the results before
sending them to the GIU, but that doesn't help at all. Please advise.

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


How do you debug when a unittest.TestCase fails?

2007-07-18 Thread Emin.shopper Martinian.shopper

Dear Experts,

How do you use pdb to debug when a TestCase object from the unittest module
fails? Basically, I'd like to run my unit tests and invoke pdb.pm when
something fails.

I tried the following with now success:

Imagine that I have a module _test.py that looks like the following:

---
import unittest
class MyTest(unittest.TestCase):
   def testIt(self):
   raise Exception('boom')
if __name__ == '__main__':
   unittest.main()
---

If I do


import _test; _test.unittest()


no tests get run.

If I try


import _test; t = _test.MyTest()


I get

Traceback (most recent call last):
 File "", line 1, in 
 File "c:\python25\lib\unittest.py", line 209, in __init__
   (self.__class__, methodName)
ValueError: no such test method in : runTest

If I try


import _test; t = _test.MyTest(methodName='testIt'); t.run()


nothing happens.

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

Re: Property Descriptor - Public Getter, Private Setter

2007-07-18 Thread James Stroud
gamehack wrote:
> Hi all,
> 
> I was looking around the net to figure out how I can use the
> property() descriptor to make a property readable by everyone and only
> settable by the class or any derived classes. Thanks.
> 
> Regards,
> gh
> 

Congratulations, you have discovered a principal use of properties--to 
restrict access! But how? By the honor system, of course, and some 
clever naming techniques and documentation. Below we see all of the 
essential components.

 1. clever naming -- our attribute is prepended with an underscore,
 signifying its special status as an internal
 name and will not be exposed to the API.
 2. documentation -- we let our users know about the value property
 3. properties-- we make a property named value that is exposed
 to the API, but we don't expose _value as it
 is not available beyond the class and subclasses
 implicitly, by virtue of clever naming (see 1)

class C(object):
   """
   Instances of this class are endowed with a 'value' property.
   This property is read-only for users of the API. Have a Nice Day.
   """
   def __init__(self):
 self._value = None
   def get_value(self):
 return self._value
   value = property(get_value)


James

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

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


Re: How do you debug when a unittest.TestCase fails?

2007-07-18 Thread Jean-Paul Calderone
On Wed, 18 Jul 2007 16:40:46 -0400, "Emin.shopper Martinian.shopper" <[EMAIL 
PROTECTED]> wrote:
>Dear Experts,
>
>How do you use pdb to debug when a TestCase object from the unittest module
>fails? Basically, I'd like to run my unit tests and invoke pdb.pm when
>something fails.
>
>I tried the following with now success:
>
>Imagine that I have a module _test.py that looks like the following:
>
>---
>import unittest
>class MyTest(unittest.TestCase):
>def testIt(self):
>raise Exception('boom')
>if __name__ == '__main__':
>unittest.main()
>---
>
>If I do
import _test; _test.unittest()
>
>no tests get run.
>
>If I try
import _test; t = _test.MyTest()
>
>I get
>
>Traceback (most recent call last):
>  File "", line 1, in 
>  File "c:\python25\lib\unittest.py", line 209, in __init__
>(self.__class__, methodName)
>ValueError: no such test method in : runTest
>
>If I try
import _test; t = _test.MyTest(methodName='testIt'); t.run()
>
>nothing happens.

I use `trial -b ', which automatically enables a bunch of nice
debugging functionality. ;)  However, you can try this, if you're not
interested in using a highly featureful test runner:

try:
unittest.main()
except:
import pdb
pdb.pm()

This will "post-mortem" the exception, a commonly useful debugging
technique.

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


Re: merge two ranges

2007-07-18 Thread George Sakkis
On Jul 17, 1:29 pm, anoweb <[EMAIL PROTECTED]> wrote:
> I have two ranges of numbers and I need to determine if they overlap
> or adjacent and if so return a new range containing the values.  The
> values are low and high for each pair, such that the first value of
> the tuple is always less than or equal to the second value in the
> tuple.
>
> for example:
> a = (0, 5)
> b = (5, 10)
>
> print getAdjacent(a, b)  # output: (0, 10)
> print getAdjacent(b, a)  # output: (0, 10)
> print getOverlap(a, b) # output: None
> print getOverlap(b, a) # output: None
>
> a = (0, 7)
> b = (3, 10)
> print getAdjacent(a, b) # output: None
> print getAdjacent(b, a) # output: None
> print getOverlap(a, b)  # output: (0, 10)
> print getOverlap(b, a)  # output: (0, 10)
>
> a = (0, 90)
> b = (5, 10)
> print getAdjacent(a, b) # output: None
> print getAdjacent(b, a) # output: None
> print getOverlap(a, b)  # output: (0, 90)
> print getOverlap(b, a)  # output: (0, 90)
>
> a = (0, 5)
> b = (12, 20)
> print getAdjacent(a, b) # output: None
> print getAdjacent(b, a) # output: None
> print getOverlap(a, b)  # output:None
> print getOverlap(b, a)  # output: None
>
> any easy way of doing this?

It's not really hard to come up with a quick and dirty solution;
however if this isn't a homework or a toy program, take a look at the
interval module (http://cheeseshop.python.org/pypi/interval/1.0.0) for
a more thought-out design.

HTH,
George

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


Re: How do you debug when a unittest.TestCase fails?

2007-07-18 Thread Emin.shopper Martinian.shopper

Thanks for the reply, but neither of those work for me. I don't seem to have
the "trial" program installed. Where do you get it?

Also, when I use the try/catch block, I get the following error:

Traceback (most recent call last):
 File "_test.py", line 10, in 
   pdb.pm()
 File "c:\python25\lib\pdb.py", line 1148, in pm
   post_mortem(sys.last_traceback)
AttributeError: 'module' object has no attribute 'last_traceback'


On 7/18/07, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:


On Wed, 18 Jul 2007 16:40:46 -0400, "Emin.shopper Martinian.shopper" <
[EMAIL PROTECTED]> wrote:
>Dear Experts,
>
>How do you use pdb to debug when a TestCase object from the unittest
module
>fails? Basically, I'd like to run my unit tests and invoke pdb.pm when
>something fails.
>
>I tried the following with now success:
>
>Imagine that I have a module _test.py that looks like the following:
>
>---
>import unittest
>class MyTest(unittest.TestCase):
>def testIt(self):
>raise Exception('boom')
>if __name__ == '__main__':
>unittest.main()
>---
>
>If I do
import _test; _test.unittest()
>
>no tests get run.
>
>If I try
import _test; t = _test.MyTest()
>
>I get
>
>Traceback (most recent call last):
>  File "", line 1, in 
>  File "c:\python25\lib\unittest.py", line 209, in __init__
>(self.__class__, methodName)
>ValueError: no such test method in : runTest
>
>If I try
import _test; t = _test.MyTest(methodName='testIt'); t.run()
>
>nothing happens.

I use `trial -b ', which automatically enables a bunch of nice
debugging functionality. ;)  However, you can try this, if you're not
interested in using a highly featureful test runner:

   try:
   unittest.main()
   except:
   import pdb
   pdb.pm()

This will "post-mortem" the exception, a commonly useful debugging
technique.

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

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

Re: Real-time Update

2007-07-18 Thread Aahz
In article <[EMAIL PROTECTED]>,
ReTrY  <[EMAIL PROTECTED]> wrote:
>
>I'm writing a program with Tkinter GUI, When the program is running it
>need to be updated every five seconds (data comes from internet). How
>should I do that ? How to make a function in main loop ?

See the Tkinter example from my threads tutorial on my website.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

I support the RKAB
-- 
http://mail.python.org/mailman/listinfo/python-list


type conversions for comparison operators

2007-07-18 Thread Russ
I recently discovered a bug in one of my programs that surprised me
because I thought Python's dynamic type checking would have
caught it.

Suppose I have a function that returns an integer, such as

def numItems: return len(self.items)

Now I want to do a test like this:

if object.numItems() > 2: 

But suppose I mistakenly leave off the parentheses:

if object.numItems > 2: 

I would have thought that Python would choke on this, but it
doesn't. Apparently, Python converts the operands to a common
type, but that seems risky to me. Is there a good reason for allowing
a function to be compared to an integer? Thanks.

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


Exiting from python shell

2007-07-18 Thread Tobiah
For years now, I've been exiting the shell by typing 'exit\n',
being chid by the shell, and then typing ^D.  I can't
remember a time that I typed the ^D the first time.  Call
me an idiot if you must, but since someone took the trouble
to catch the command 'exit' in a special way, would it have
been so awful to just let it be a way to exit when the shell?

Thanks,

Toby

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Question about how to use cog as a preprocessor :-(

2007-07-18 Thread Steven W. Orr
I have the following module:

#! /usr/bin/python
COG_DEBUG=1
def wrapper( dd ):
 if dd == 1:
 def dfunc( *args ):
 print "print ",
 for ii in args:
 print repr(ii)
 print "compd dfunc"
 return dfunc
 else:
 def nfunc( *args ):
 pass
 print "compd nfunc"
 return nfunc
dbgprint = wrapper(COG_DEBUG)
print "dbgprint = ", repr(dbgprint)
dbgprint("called from def hunk")
print "hello1"

This does what I want, but when I use this code inside cog then the call 
to dbgprint doesn't do anything.

Here's the input to cog:

#! /usr/bin/python
[[[cog
import cog
def wrapper( dd ):
 if dd == 1:
 def dfunc( *args ):
 cog.out( "print " )
 for ii in args:
 cog.out( repr(ii) )
 print
 print "compd dfunc"
 return dfunc
 else:
 def nfunc( *args ):
 pass
 print "compd nfunc"
 return nfunc
dbgprint = wrapper(COG_DEBUG)
print "dbgprint = ", repr(dbgprint)
dbgprint("called from def hunk")
]]]
[[[end]]]

print "hello1"
[[[cog dbgprint( "Hello from dbg" )]]]
[[[end]]]
print "Doo dis"

and this is the cmdline: cog.py -D COG_DEBUG=1 -d -o d1out.py d1.py

And the output is just

#! /usr/bin/python
import sys


print "hello1"
print "Doo dis"

DOes anyone have any ideas? :-(

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-URL! - weekly Python news and links (Jul 16)

2007-07-18 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Kay Schluehr  <[EMAIL PROTECTED]> wrote:
>
>Gabriel Genellina schrieb:
>> QOTW:  "That's a property of open source projects. Features nobody really
>> needs are not implemented." - Gregor Horvath
>
>It's a good QOTW but social romantic nonsense nevertheless.
>
>Not sure if it's important enough to be mentioned in weekly Python
>news but Europython 2007 actually happened and took place in Vilnius.
>
>Kay
>

*I* sure think it's important; is there a summary or narrative 
from the event you recommend?
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie: freebsd admin scripting

2007-07-18 Thread Muffin
I am using python for the first time on Unix and on FBSD. I need a few 
pointer, tips or tricks on scripting on config files. Mostly admin type 
configs like the rc.conf file usually setup like:

someiteam=somevalue#sometype of description

Where I would like to toggle the somevalue in an easy way. I realize I 
could parse it with reg expression but that sounds kinda complicated. Is 
there an easer way a Unix python way of dealing with these type of 
config files.

I found a built in mod for parseconfig but it deal with .ini file styles 
(windows) that include a [section] header as well as uses 
someiteam=somevalue format. I believe it requires the header though.

Books or howtos regarding Unix admin scripting(python) would be great. 
Is this type of scripting mainly executing a Unix command and capturing 
and parsing its output like this:

x=command.getoutput("ifconfig")

and them parsing x for what I want or is there a name space I can call 
to get , for example, a list of all interfaces?

I have mainly used python in windows using the com space or win32 api 
aside from the base python lib, on Unix I am lost on what to do or how 
things are generally done. Advise on how to "think" in Unix python terms 
if that makes any sense.

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


problem with psqlite2 return types

2007-07-18 Thread Danny
Howdy,

I'm having troubles with psqlite2 and the return types from a query. The problem
is that my data which is numeric, is being returned as a string. I'm aware of 
the
detect_types=sqlite.PARSE_DECLTYPES argument to the connect function. 

Here's my connection code:  
self.connection = sqlite.connect(self.dbFile,
detect_types=sqlite.PARSE_DECLTYPES)#
self.connection.text_factory=str
self.cursor = self.connection.cursor()

Here's my sql (I'm returning risk1, which is numeric):
create table risk(
quantity varchar(8),
color varchar(8),
risk1 real,
risk2 real,
primary key (quantity, color)
);

( I have also tried [REAL, float, FLOAT], none work for me)

Here's my query (this will probably be not much use out of context...):
primaryKeys = self.primaryKeyFields[table]
primaryKeyList= ' and '.join(['%s = ?'% pKey for pKey in 
primaryKeys])
query = 'select %s from %s where %s' % (field, table, 
primaryKeyList)
paramList = [state[primaryKey] for primaryKey in primaryKeys]
self.cursor.execute(query, paramList)

Any ideas?

TIA,
Danny

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


Re: Exiting from python shell

2007-07-18 Thread James Stroud
Tobiah wrote:
> For years now, I've been exiting the shell by typing 'exit\n',
> being chid by the shell, and then typing ^D.  I can't
> remember a time that I typed the ^D the first time.  Call
> me an idiot if you must, but since someone took the trouble
> to catch the command 'exit' in a special way, would it have
> been so awful to just let it be a way to exit when the shell?
> 
> Thanks,
> 
> Toby
> 

Yes, this would have required a ground-up approach to redesigning the 
python language, transmuting it to something like a cross between lisp 
and COBOL and would have rendered it impossible to author with C because 
of the way C implements pointers--hardcoding in assembly would likely be 
required. Beyond that, exiting an interpreter is not known in computer 
science and has been shown impossible by Goedel himself in a series of 
monographs on the topic. Thus, to exit python via a keyword would 
require also reformulating mathematics as we know it. Furthermore, such 
a change would propagate itself, via the observer effect, to the 
behavior of sub atomic particles via ill-defined quantum-mechanical 
affects and would likely result in the reversal of the Second Law of 
Thermodynamics, wherein your refrigerator would end up heating its 
contents and milk would spontaneously spoil, among other anomalies.

For these reasons, you might propose a "quit" keyword.

James

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

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


Re: Newbie: freebsd admin scripting

2007-07-18 Thread Evan Klitzke
On 7/17/07, Muffin <[EMAIL PROTECTED]> wrote:
> I am using python for the first time on Unix and on FBSD. I need a few
> pointer, tips or tricks on scripting on config files. Mostly admin type
> configs like the rc.conf file usually setup like:
>
> someiteam=somevalue#sometype of description
>
> Where I would like to toggle the somevalue in an easy way. I realize I
> could parse it with reg expression but that sounds kinda complicated. Is
> there an easer way a Unix python way of dealing with these type of
> config files.
>
> I found a built in mod for parseconfig but it deal with .ini file styles
> (windows) that include a [section] header as well as uses
> someiteam=somevalue format. I believe it requires the header though.

I think you're referring to ConfigParser. This is the standard way to
do config files in Python, and it is very simple to use and work with,
so I would recommend using it. The documentation can be found at
http://docs.python.org/lib/module-ConfigParser.html

> Books or howtos regarding Unix admin scripting(python) would be great.
> Is this type of scripting mainly executing a Unix command and capturing
> and parsing its output like this:
>
> x=command.getoutput("ifconfig")
>
> and them parsing x for what I want or is there a name space I can call
> to get , for example, a list of all interfaces?
>
> I have mainly used python in windows using the com space or win32 api
> aside from the base python lib, on Unix I am lost on what to do or how
> things are generally done. Advise on how to "think" in Unix python terms
> if that makes any sense.

You should use the subprocess module for interacting with other
programs, although it can be a little burdensome to work with. Ideally
you'll have a module that implements the functionality that you need
to use directly, rather than trying to control other processes from
Python.

Also, you should keep a collection of the scripts you write and try to
look for common patterns that come up. If you're diligent with this
you can start writing your own sysadmin python toolkit to make your
job a lot easier.

-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exiting from python shell

2007-07-18 Thread Mark Elston
* James Stroud wrote (on 7/18/2007 4:27 PM):
> Tobiah wrote:
>> For years now, I've been exiting the shell by typing 'exit\n',
>> being chid by the shell, and then typing ^D.  I can't
>> remember a time that I typed the ^D the first time.  Call
>> me an idiot if you must, but since someone took the trouble
>> to catch the command 'exit' in a special way, would it have
>> been so awful to just let it be a way to exit when the shell?
>>
>> Thanks,
>>
>> Toby
>>
> 
> Yes, this would have required a ground-up approach to redesigning the 
> python language, transmuting it to something like a cross between lisp 
> and COBOL and would have rendered it impossible to author with C because 
> of the way C implements pointers--hardcoding in assembly would likely be 
> required. Beyond that, exiting an interpreter is not known in computer 
> science and has been shown impossible by Goedel himself in a series of 
> monographs on the topic. Thus, to exit python via a keyword would 
> require also reformulating mathematics as we know it. Furthermore, such 
> a change would propagate itself, via the observer effect, to the 
> behavior of sub atomic particles via ill-defined quantum-mechanical 
> affects and would likely result in the reversal of the Second Law of 
> Thermodynamics, wherein your refrigerator would end up heating its 
> contents and milk would spontaneously spoil, among other anomalies.
> 
> For these reasons, you might propose a "quit" keyword.
> 
> James
> 

You know, some answers simply *must* be saved for posterity

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


Re: Python-URL! - weekly Python news and links (Jul 16)

2007-07-18 Thread David Boddie
On Wed Jul 18 23:20:51 CEST 2007, Cameron Laird wrote:

> Kay Schluehr   wrote:
>
> >Not sure if it's important enough to be mentioned in weekly Python
> >news but Europython 2007 actually happened and took place in Vilnius.
> 
> *I* sure think it's important; is there a summary or narrative 
> from the event you recommend?

I've started to collect reports, photos and videos from the conference
on the relevant PythonInfo Wiki page:

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

There's no definitive report out there, as far as I can tell. I imagine
that everyone is getting their strength back after a week of talks,
hacking, sightseeing and socialising. :-)

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


Running Python with XAMPP

2007-07-18 Thread Mathias K.
Hello everyone!

I just installed Python 2.5 and i want to use Python to build websites.
I could load mod_python successfully with Apache but i fail to let 
the .py-files to be executed!

In /htdocs/python i got my test file:

[code=python.py]
from mod_python import apache

def index(req):
req.content_type = "text/html"
req.write("")
req.write("Python is running with mod_python...")
return apache.OK
[/code]

And then i got the following code in my httpd.conf:

[code]

AddHandler mod_python .py
pythonHandler index
pythonDebug On

[/code]

But when i type "http://localhost/python/python.py"; it won't execute!
My browser just shows me the source code. :-(

Please, can anyone tell me what i have to do?


Thanks in advance!


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


Interprocess communication

2007-07-18 Thread Murali
Hi Python Gurus,

I am writing a GUI app (on linux) using pygtk which would launch some
external applications and display their stdout and stderr inside the
output window of my application synchronously. I am using the
subprocess module's Popen to launch the external programs and to
capture their stdout and stderr. The problem is that, for some
external programs that I launch inside my interface, I am not able to
capture and display the stdout as the program *runs*.

After some investigation, I found out that this problem had nothing to
do with my GUI app not getting refreshed and I was able to reproduce
this problem with normal python scripts. Here is one such script

#File test.py
from subprocess import Popen
from subprocess import PIPE
import sys
if __name__ == '__main__':
  prog = sys.argv[1]
  proc = Popen(prog, shell = True, stdout = PIPE, bufsize = 0)
  out = proc.stdout
  while proc.poll() is None:
print out.readline()

Run this program as follows
$ test.py "ping -c 10 www.google.com"

Now, you would see the responses as if you just launched ping on the
command line. Now, lets look at another program. Here is a simple C++
program that prints numbers 1 to 10 at the passage of every second
(sort of a stopwatch)

#include 
#include 
#include 
main ( )
{
  timeval t1, t2;
  gettimeofday(&t1, NULL);
  int prev = -1;
  int cur = 0;
  while (true)
  {
gettimeofday(&t2,NULL);
if(t2.tv_sec - t1.tv_sec > 10)
  break;
else
{
  cur = t2.tv_sec-t1.tv_sec;
  if (cur != prev)
  {
printf("%d\r\n",cur);
prev = cur;
  }
}
  }
}

if you would build this program and call it lets say timer ($ g++ -o
timer timer.cpp)  and run it with our python script like this

$python test.py "./timer"

you would see that every time you run the program your results vary
and on top of this the stdout of the timer program gets displayed all
at once presumably when the timer program has completed execution.

Why this discrepancy between the ping and timer programs? Is my
test.py script correct? Is there a better or a preferred method for
doing interprocess communication in Python.

Thanks!
Murali.

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


Re: Exiting from python shell

2007-07-18 Thread James Matthews

try raise SystemExit

On 7/18/07, Mark Elston <[EMAIL PROTECTED]> wrote:


* James Stroud wrote (on 7/18/2007 4:27 PM):
> Tobiah wrote:
>> For years now, I've been exiting the shell by typing 'exit\n',
>> being chid by the shell, and then typing ^D.  I can't
>> remember a time that I typed the ^D the first time.  Call
>> me an idiot if you must, but since someone took the trouble
>> to catch the command 'exit' in a special way, would it have
>> been so awful to just let it be a way to exit when the shell?
>>
>> Thanks,
>>
>> Toby
>>
>
> Yes, this would have required a ground-up approach to redesigning the
> python language, transmuting it to something like a cross between lisp
> and COBOL and would have rendered it impossible to author with C because
> of the way C implements pointers--hardcoding in assembly would likely be
> required. Beyond that, exiting an interpreter is not known in computer
> science and has been shown impossible by Goedel himself in a series of
> monographs on the topic. Thus, to exit python via a keyword would
> require also reformulating mathematics as we know it. Furthermore, such
> a change would propagate itself, via the observer effect, to the
> behavior of sub atomic particles via ill-defined quantum-mechanical
> affects and would likely result in the reversal of the Second Law of
> Thermodynamics, wherein your refrigerator would end up heating its
> contents and milk would spontaneously spoil, among other anomalies.
>
> For these reasons, you might propose a "quit" keyword.
>
> James
>

You know, some answers simply *must* be saved for posterity

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





--
http://www.goldwatches.com/watches.asp?Brand=14
http://www.jewelerslounge.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how to implementation latent semantic indexing in python..

2007-07-18 Thread malkarouri
On 13 Jul, 17:18, 78ncp <[EMAIL PROTECTED]> wrote:
> hi...
> how to implementation algorithm latent semantic indexing in python
> programming...??
>
> thank's for daniel who answered my question before..
>
> --
> View this message in 
> context:http://www.nabble.com/how-to-implementation-latent-semantic-indexing-...
> Sent from the Python - python-list mailing list archive at Nabble.com.

IIRC, there was some explanation of Latent Semantic Analysis (with
Python code) in an IEEE ReadyNotes document called "Introduction to
Python for Artificial Intelligence". It wasn't free I am afraid.

Of course you are aware that LSA is patented..

Muhammad

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


Issue with CSV

2007-07-18 Thread Rohan
Hello,
I'm working on a script which collects some data and puts into a csv
file which could be exported to excel.
so far so good, I'm able to do what I described.
When I run the script for the second time after a certain period of
time the results should appear next to the results of the last run,
I'm unable to make a new column when the script is run after the first
time.
Ideally I would like to have an output which looks like this.
1/20   1/27
we.pywe.py
gh.pygj.py   <- Indicating tht the file has changed
fg.pyfg.py

Please help me out.
Thanks

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


Re: Newbie: freebsd admin scripting

2007-07-18 Thread Will Maier
On Wed, Jul 18, 2007 at 04:31:35PM -0700, Evan Klitzke wrote:
> > I found a built in mod for parseconfig but it deal with .ini
> > file styles (windows) that include a [section] header as well as
> > uses someiteam=somevalue format. I believe it requires the
> > header though.
> 
> I think you're referring to ConfigParser. This is the standard way
> to do config files in Python, and it is very simple to use and
> work with, so I would recommend using it.

rc.conf is a shell script on BSD systems. The OP will need to write
his own parser to read it. Take a look at the wiki's list of
parsers[0], specifically shlex[1]. I haven't used it to parse things
like rc.conf, but I imagine it could be useful.

> > Books or howtos regarding Unix admin scripting(python) would be
> > great.  Is this type of scripting mainly executing a Unix
> > command and capturing and parsing its output like this:
> >
> > x=command.getoutput("ifconfig")
> >
> > and them parsing x for what I want or is there a name space I
> > can call to get , for example, a list of all interfaces?

Nothing in the standard library handles interface configuration,
though there may be a package somewhere to help you with that. In
general, yes, you'll be writing your own scripts wrapping around
system commands. As Evan says, be smart and keep those scripts
around. As you figure things out, generalize your scripts and create
some useful classes, etc.

[0] http://wiki.python.org/moin/LanguageParsing
[1] http://www.python.org/doc/current/lib/module-shlex.html

-- 

[Will [EMAIL PROTECTED]|http://www.lfod.us/]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Break up list into groups

2007-07-18 Thread George Sakkis
On Jul 17, 1:48 pm, Matimus <[EMAIL PROTECTED]> wrote:
> I did some more experimenting and came up with the code below. It
> shows several methods. When run, the script tests the robustness of
> each method (roughly), and profiles it using timeit. The results from
> running on my laptop are shown below the code.
>
> 
> seqs = [# Original:
> [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11,
> 12, 13,
>  0xF0, 14, 0xF1, 15],
> # Single entry:
> [0xF0, 1, 2, 3],
> # empty
> [],
> # No values with 0x80 set
> [1, 2, 3, 14, 15],
> # Does not start with a value that has 0x80 set
> [1, 2, 3, 14, 15, 0xF0, 1, 2, 3]]
>
> expected = [# Original:
> [[0xF0, 1, 2, 3], [0xF0, 4, 5, 6], [0xF1, 7, 8], [0xF2, 9,
> 10, 11, 12, 13],
>  [0xF0, 14], [0xF1, 15]],
> # Single entry:
> [[0xF0, 1, 2, 3]],
> # empty
> [],
> # No values with 0x80 set
> [],
> # Does not start with a value that has 0x80 set
> [[0xF0, 1, 2, 3]]]
>
> def gengroups0(seq):
> group = None
> for val in seq:
> if val & 0x80:
> if group: yield group
> group = []
> try:
> group.append(val)
> except AttributeError:
> pass
> if group: yield group
>
> def getgroups0(seq):
> groups = []
> group = None
> for val in seq:
> if val & 0x80:
> if group:
> groups.append(group)
> group = []
> try:
> group.append(val)
> except AttributeError:
> pass
> if group:
> groups.append(group)
> return groups
>
> def gengroups1(seq):
> idxs = [i for i,v in enumerate(seq) if v&0x80]
> for i,j in zip(idxs,idxs[1:]+[None]):
> yield seq[i:j]
>
> def getgroups1(seq):
> idxs = [i for i,v in enumerate(seq) if v&0x80]
> return [seq[i:j] for i,j in zip(idxs,idxs[1:]+[None])]
>
> # Similar to the partition method on strings
> def partition(seq,f=None):
> if f is None:
> f = lambda x:x
> for i,v in enumerate(seq):
> if f(v):
> return seq[:i],[seq[i]],seq[i+1:]
> return seq,[],[]
>
> def rpartition(seq, f=None):
> if f is None:
> f = lambda x:x
> for i,v in zip(range(len(seq)-1,-1,-1),seq[::-1]):
> if f(v):
> return seq[:i],[seq[i]],seq[i+1:]
> return ([],[],seq)
>
> def gengroups2(seq):
> while seq:
> seq, key, val = rpartition(seq, lambda x: x&0x80)
> if key and val: yield key+val
>
> def getgroups2(seq):
> groups = []
> while seq:
> seq, key, val = rpartition(seq, lambda x: x&0x80)
> if key and val:
> groups.append(key+val)
> return groups
>
> def getgroups3(seq):
>groups = []
>for i in seq:
>  if 0x80 & i:
>groups.append([i])
>  else:
>groups[-1].append(i)
>return [x for x in groups if x]
>
> seq = seqs[0]
> if __name__ == "__main__":
> from timeit import Timer
> import __main__
> for i in range(4):
> fname = "getgroups"+str(i)
> f = getattr(__main__,fname)
> print fname
> for i,(s,e) in enumerate(zip(seqs,expected)):
> print "test %d:"%i,
> try:
> if f(s) == e:
> print "pass"
> else:
> print "fail"
> except:
> print "error"
>
> t = Timer(fname+'(seq)',
>'from __main__ import seq,'+fname)
> print "%.2f usec/pass" % (100 * t.timeit(number=10)/
> 10)
> print
> 
>
> Output from running the above:
> getgroups0
> test 0: pass
> test 1: pass
> test 2: pass
> test 3: pass
> test 4: pass
> 14.85 usec/pass
>
> getgroups1
> test 0: pass
> test 1: pass
> test 2: pass
> test 3: pass
> test 4: pass
> 13.81 usec/pass
>
> getgroups2
> test 0: fail
> test 1: pass
> test 2: pass
> test 3: pass
> test 4: pass
> 56.38 usec/pass
>
> getgroups3
> test 0: pass
> test 1: pass
> test 2: pass
> test 3: error
> test 4: error
> 16.23 usec/pass
>
> `getgropus2' fails test 0 because it produces a reversed list. That
> can easily be fixed by re-reversing the output before returning. But,
> since it is by far the slowest method, I didn't bother.
>
> `getgroups3' is a method I got from another post in this thread, just
> for comparison.
>
> >From my benchmarks it looks like getgroups1 is the winner. I didn't
>
> scour the thread to test all the methods however.

Here's a small improvement of getgroups1, both in time and memory:

from itertools import islice

def getgroups4(seq):
idxs = [i for i,v in enumerate(seq) if v&0x80]
idxs.append(None)
return [seq[i:j] for i,j in izip(idxs, islice(idxs,1,None))]


George

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


Interpreting os.lstat()

2007-07-18 Thread Adrian Petrescu
I'm playing with FUSE's python bindings, and I'm expected to return a
list that matches the structure of a python os.lstat() call. So, for
example:

>>> import os
>>> os.lstat("/home/adrian/fuse_test")
(16877, 1036L, 2050L, 4, 1000, 1000, 4096L, 1184803155,
1184170289, 1184170289)

The problem is, I'm not sure how to recreate this kind of structure
because I have no idea about the significance of the entries. The
docstring wasn't much help:

>>> print os.lstat.__doc__
lstat(path) -> stat result

Like stat(path), but do not follow symbolic links.
>>> print os.stat.__doc__
stat(path) -> stat result

Perform a stat system call on the given path.

I checked the online Python documentation at 
http://python.org/doc/1.5.2/lib/module-stat.html
but it just says to "consult the documentation for your system.". At
this point I'm guessing that os.lstat is nothing more than a wrapper
for some Linux system call, so I looked up the results of running
'stat' on the same file, and I get:

[EMAIL PROTECTED]:~$ stat fuse_test/
  File: `fuse_test/'
  Size: 4096Blocks: 8  IO Block: 4096   directory
Device: 802h/2050d  Inode: 1036Links: 4
Access: (0755/drwxr-xr-x)  Uid: ( 1000/  adrian)   Gid: ( 1000/
adrian)
Access: 2007-07-18 19:59:15.0 -0400
Modify: 2007-07-11 12:11:29.0 -0400
Change: 2007-07-11 12:11:29.0 -0400

I can see some correspondence between the "stat" call and os.lstat
(for example, I'm guessing os.lstat(path)[6] represents the filesize),
but I can't see the correspondence between some of the other fields.
What does os.lstat(path)[0] represent? Are those last three the
created/modified/accessed times in unix time or what? Basically, what
does each field of os.lstat(path) represent?

My system is Linux 2.6.20 and I'm using Python 2.5.1
Thanks in advance, guys! =)

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


Re: Interpreting os.lstat()

2007-07-18 Thread Will Maier
On Wed, Jul 18, 2007 at 05:55:59PM -0700, Adrian Petrescu wrote:
> I can see some correspondence between the "stat" call and os.lstat
> (for example, I'm guessing os.lstat(path)[6] represents the filesize),
> but I can't see the correspondence between some of the other fields.
> What does os.lstat(path)[0] represent? Are those last three the
> created/modified/accessed times in unix time or what? Basically, what
> does each field of os.lstat(path) represent?

There's a whole module available explicitly for "interpreting
results of os.stat() and os.lstat()."

http://www.python.org/doc/current/lib/module-stat.html

-- 

[Will [EMAIL PROTECTED]|http://www.lfod.us/]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to implementation latent semantic indexing in python..

2007-07-18 Thread Tim Churches
malkarouri wrote:
> On 13 Jul, 17:18, 78ncp <[EMAIL PROTECTED]> wrote:
>> hi...
>> how to implementation algorithm latent semantic indexing in python
>> programming...??
> 
> Of course you are aware that LSA is patented..

There is a US patent on it, sealed in 1989, but is it patented in any
other countries? There is no such thing as a "global patent" - patents
only cover the country which issues them. There is a global patent
application process (the Patent Co-operation Treaty), but that just
establishes a priority date for the invention in each country, but the
inventor still needs to file patent applications and have them approved
(sealed)  is each and every country. Did Bellcore do that back in the 1980s?

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


Re: how to implementation latent semantic indexing in python..

2007-07-18 Thread Alex Martelli
Tim Churches <[EMAIL PROTECTED]> wrote:

> malkarouri wrote:
> > On 13 Jul, 17:18, 78ncp <[EMAIL PROTECTED]> wrote:
> >> hi...
> >> how to implementation algorithm latent semantic indexing in python
> >> programming...??
> > 
> > Of course you are aware that LSA is patented..
> 
> There is a US patent on it, sealed in 1989, but is it patented in any
> other countries? There is no such thing as a "global patent" - patents
> only cover the country which issues them. There is a global patent
> application process (the Patent Co-operation Treaty), but that just
> establishes a priority date for the invention in each country, but the
> inventor still needs to file patent applications and have them approved
> (sealed)  is each and every country. Did Bellcore do that back in the 1980s?

Aren't patents supposed to last 17 years, anyway?  A patent granted in
1989 should have expired in 2006, I believe (though IANAL, so...).


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


Interprocess communication woes

2007-07-18 Thread Murali
Hi Python Gurus,

I am writing a GUI app (on linux) using pygtk which would launch some
external applications and display their stdout and stderr inside the
output window of my application synchronously. I am using the
subprocess module's Popen to launch the external programs and to
capture their stdout and stderr. The problem is that, for some
external programs that I launch inside my interface, I am not able to
capture and display the stdout as the program *runs*.

After some investigation, I found out that this problem had nothing to
do with my GUI app not getting refreshed and I was able to reproduce
this problem with normal python scripts. Here is one such script

#File test.py
from subprocess import Popen
from subprocess import PIPE
import sys
if __name__ == '__main__':
 prog = sys.argv[1]
 proc = Popen(prog, shell = True, stdout = PIPE, bufsize = 0)
 out = proc.stdout
 while proc.poll() is None:
   print out.readline()

Run this program as follows
$ test.py "ping -c 10 www.google.com"

Now, you would see the responses as if you just launched ping on the
command line. Now, lets look at another program. Here is a simple C++
program that prints numbers 1 to 10 at the passage of every second
(sort of a stopwatch)

#include 
#include 
#include 
main ( )
{
 timeval t1, t2;
 gettimeofday(&t1, NULL);
 int prev = -1;
 int cur = 0;
 while (true)
 {
   gettimeofday(&t2,NULL);
   if(t2.tv_sec - t1.tv_sec > 10)
 break;
   else
   {
 cur = t2.tv_sec-t1.tv_sec;
 if (cur != prev)
 {
   printf("%d\r\n",cur);
   prev = cur;
 }
   }
 }
}

if you would build this program and call it lets say timer ($ g++ -o
timer timer.cpp)  and run it with our python script like this

$python test.py "./timer"

you would see that every time you run the program your results vary
and on top of this the stdout of the timer program gets displayed all
at once presumably when the timer program has completed execution.

Why this discrepancy between the ping and timer programs? Is my
test.py script correct? Is there a better or a preferred method for
doing interprocess communication in Python.

Thanks!
Murali.

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


Re: type conversions for comparison operators

2007-07-18 Thread Alex Martelli
Russ <[EMAIL PROTECTED]> wrote:

> I recently discovered a bug in one of my programs that surprised me
> because I thought Python's dynamic type checking would have
> caught it.
> 
> Suppose I have a function that returns an integer, such as
> 
> def numItems: return len(self.items)

Syntax errors (you need parentheses before the colon).

> Now I want to do a test like this:
> 
> if object.numItems() > 2: 

Attribute error (unless you've set that numItems "function" to be a
_method_ of the class of "object" AND added a "self" argument).


> But suppose I mistakenly leave off the parentheses:
> 
> if object.numItems > 2: 
> 
> I would have thought that Python would choke on this, but it
> doesn't. Apparently, Python converts the operands to a common
> type, but that seems risky to me. Is there a good reason for allowing
> a function to be compared to an integer? Thanks.

It lets you sort a heterogeneous list which may include objects of many
types (and no "conversion to a common type" is involved, btw).

However, Guido's decided that Python 3.0 will not allow heterogeneous
order-comparisons any more (they can't be removed in 2.* without
breaking backwards compatibility -- 3.0 is allowed to break backwards
compatibility, but 2.* isn't).


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


  1   2   >