Re: Question about extending the interperter

2005-05-10 Thread Eli
Thanks for the answer; I should better explain my problem.

My organization already has a DOS command line tool which I would like
to transffer to Python.
Every function this DOS command line too can execute has a definition
entry in an array:
 {"function name", function address, other info... },
Which means if 'function name' was enetered by the user the command
line tool will call 'function address'. Note that this is a *big*
array.

Now I'm trying to pass the above enteries to Python's interperter
extension:
One way would be going over all of my enteries and add Python calls
like that:

static PyMethodDef pmylib_methods[] = {
{"function name 1", pmylib_1, METH_VARARGS, "..."},
{"function name 2", pmylib_2, METH_VARARGS, "..."},
etc
...
}
The only problem I need to preprocess the input first (initialize
strtok).
So a solution would be creating 'function 1' which preprocess the input
and calls the original function 1, than do so for any other function.
This works, but there are *lots* of such enteries and I'm trying a
general way of doing so.
If I would have the full line the user enetered I could make all of the
extensions to call a general function which will call the original
functions (it can do so because it has the function address as a
parameter).
If I could get the full line the user has entered that would be great,
if that's possible.

Hope I've explained it correctly...
cheers,
Eli

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


Re: sync dir's

2005-05-10 Thread Fredrik Lundh
Timothy Smith wrote:

> what would be the best tool to use to sync my local dir with a remote
> one, say off a http resorce (although i'm open to other options there) i

rsync?  wget --mirror?





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


Re: M2Crypto SSL memory leaks - fixes or alternatives ??

2005-05-10 Thread Roger Binns
> I notice that M2Crypto (a python wrap of OpenSSL) leaks (haemorrhages)
> memory significantly and affects my long running app very badly.
>
> Does anyone know of fixes to this problem?
>
> Does anyone recommmend alternatives to M2C ? e.g pyopenssl.

If you control both ends of the connection then you can do what I did and
switch to SSH.  The Python Paramiko library implements it really well.
(I ended up doing XML-RPC over SSH).

Roger 


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


Re: sync dir's

2005-05-10 Thread Timothy Smith
Fredrik Lundh wrote:

>Timothy Smith wrote:
>
>  
>
>>what would be the best tool to use to sync my local dir with a remote
>>one, say off a http resorce (although i'm open to other options there) i
>>
>>
>
>rsync?  wget --mirror?
>
>
>
>
>
>  
>
i need something which has a python library, so far i haven't seen 
anything like that for rsync. i'll check out the others but
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-10 Thread Fredrik Lundh
Paul Rubin wrote:

> > Is there an easy way to grab the Unique elements from a list?
> > For Example:
> > data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]
>
> Untested: here's an iterator that gives you the index and value,
> without reordering.  Uses dicts instead of sets for backwards compatibility.
>
> def unique_elements(data):
> seen = {}
> for n,x in data:
>if x not in seen:
>   seen[x] = 1
>   yield n,x

you forgot enumerate()

and if you fix that, you'll notice that the output doesn't quite match
the OP's spec:

> For Example:
> data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]
>
> what I am looking for is the unique elements 0.4 and 0.9 with their
> index from the list.

here's a straight-forward variation that gives the specified output,
in the original order:

def unique_elements(data):
count = {}
data = list(enumerate(data))
for n,x in data:
count[x] = count.setdefault(x, 0) + 1
for n,x in data:
if count[x] == 1:
yield x, n # value with index

depending on the data, it might be more efficient to store the
"last seen index" in a dictionary, and sort the result on the way
out (if necessary).  something like

from operator import itemgetter

def unique_elements(data):
seen = {}; index = {}
for n, x in enumerate(data):
if x in seen:
del index[x]
else:
index[x] = seen[x] = n
index = index.items()
index.sort(key=itemgetter(1)) # leave this out if order doesn't matter
return index

could work.





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


Re: Exception in Python 2.3.3 Interpreter

2005-05-10 Thread Saravanan D

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "Saravanan D" wrote:
>
> > > > 03 023ffaa4 1e013182  055b1250 00637470
python23!cmp_outcome(int
> > op
> > > > = 88026108, struct _object * v = 0x0001, struct _object * w =
> > > > 0x)+0xa9 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @
3880]
> > > > 04 023ffb18 1e016ba4 014f3318 0002 0099f170
> > python23!eval_frame(struct
> > > > _frame * f = 0x053f2bfc)+0x542
> > [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c
> > > > @ 1965]
> > > > 05 023ffb30 1e016a69 0099f170 023ffb7c 0002
> > > > python23!fast_function(struct _object * func = ,
> > struct
> > > > _object *** pp_stack = , int n =  > error>,
> > > > int na = , int nk = )+0x94
> > >
> > > the above doesn't look very healthy.  does your application involve
> > > non-standard extensions (including extensions you've written your-
> > > self)?  does the extensions contain callbacks into Python code?
> > >
> >
> > My application uses extension modules which devliers the callbacks to
Python
> > Code. Im using SWIG 1.3.19 version to generate relevant python
interfaces
> > for the C++ code.
>
> how are you accessing the callbacks?  if you're doing that from threads
> created at the C++ level, you must make sure that the thread state is
> properly set up.  see:

Callbacks have been called from the threads which are created in C++ code.
Before calling the callback, the thread state has been properly set  (as per
python documentation).  The application runs 3 to 4 days continuously with
out having any issues.  But, crash happens sparadically. (once in a week /
once in 4 days )



> do you keep track of the thread state, so that callbacks run in the
> same state as they were registered in?
>
> 
>
>
>


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


Re: Unique Elements in a List

2005-05-10 Thread Edvard Majakari
James Stroud <[EMAIL PROTECTED]> writes:

> from sets import Set
>
> data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]
>
> [x for x in Set(data) if data.count(x) == 1]

Um.

...I must have missed something, but I'll post nevertheless:

wouldn't just

[x for x in data if data.count(x) == 1]

suffice? it is also "stable"  preserving order of items. Lemme demo:

>>> [x for x in Set(data) if data.count(x) == 1]
[0.90002, 0.40002]

>>> [x for x in data if data.count(x) == 1]
[0.40002, 0.90002]

Though I'll admit I also thought of Sets first, because I didn't remember
there was such a nice method list.count().

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!
One day, when he was naughty, Mr Bunnsy looked over the hedge into Farmer
Fred's field and it was full of fresh green lettuces. Mr Bunnsy, however, was 
not full of lettuces. This did not seem fair.  --Mr Bunnsy has an adventure 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-10 Thread Max M
Fredrik Lundh wrote:

> depending on the data, it might be more efficient to store the
> "last seen index" in a dictionary, and sort the result on the way
> out (if necessary).  something like


form sets import Set

data = list(Set([0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]))


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble saving unicode text to file

2005-05-10 Thread Thomas Bellman
John Machin <[EMAIL PROTECTED]> writes:

> Which raises a question: who or what is going to read your file? If a
> Unicode-aware application, and never a human, you might like to
> consider encoding the text as utf-16.

Why would one want to use an encoding that is neither semi-compatible
with ASCII (the way UTF-8 is), nor uses fixed-with characters (like
UTF-32 does)?


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"You are in a twisty little passage of   !  bellman @ lysator.liu.se
 standards, all conflicting."!  Make Love -- Nicht Wahr!
-- 
http://mail.python.org/mailman/listinfo/python-list


extra a column from a 2-D array?

2005-05-10 Thread Joe Wong



Hello,
 
 Suppose I have a python array as 
follow:
 
    s=[ [1,3,5],
  [2,4,6],
      
[9,8,7]]
 
what is the quickest way to extract the second 
colum from all rows? That is: [3,4,8] in this example.
 
Best regards,
 
- Joe
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.7 - Release Date: 2005/5/9
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: extra a column from a 2-D array?

2005-05-10 Thread Robert Kern
Joe Wong wrote:
> Hello,
>  
>  Suppose I have a python array as follow:
>  
> s=[ [1,3,5],
>   [2,4,6],
>   [9,8,7]]
>  
> what is the quickest way to extract the second colum from all rows? That 
> is: [3,4,8] in this example.

Use Numeric. http://numeric.scipy.org

from Numeric import *
s = array([[1,3,5], [2,4,6], [9,8,7]])
print s[:,1]

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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

Re: Unique Elements in a List

2005-05-10 Thread Edvard Majakari
"Michael J. Fromberger" <[EMAIL PROTECTED]> writes:

> One reasonable solution might be as follows:
>
>   def unique_elts(seq):
> elts = {}
> for pos, elt in enumerate(seq):
>   elts.setdefault(elt, []).append(pos)
>
> return [ (x, p[0]) for (x, p) in elts.iteritems()
>  if len(p) == 1 ]

This is neat. Being lazy (the wrong way) I've never payed much attention why
would I need dict.setdefault() when I have things as dict.get(k, [def]). This
was a nice example of good use for setdefault() because it works like
dict.get() except it also sets the value if it didn't exist.

+1 IOTW (idiom of the week).

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strip white spaces from source

2005-05-10 Thread Richie Hindle

[qwweeeit]
> If someone is interested (I think nobody...) I can give my solution.

I'd be interested to see it, certainly.

It's always a good idea to post your solution, if only for future reference.
It's frustrating to do a Google Groups search for a problem and find that
someone else has solved it but without saying *how*.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Does TKinter Have A Grid ?

2005-05-10 Thread Peter Moscatt
Does TKinter have a Grid widget ?
If not (as I assume), what is the alternative ?

Pete

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


Re: Advice needed on __del__

2005-05-10 Thread stasz
On Mon, 09 May 2005 22:49:06 -0300, André Roberge wrote:

> Scott David Daniels wrote:
>> André Roberge wrote:
>> 
>>>...  Each time I refresh the screen, I could
>>>force that call, then check to see if Evil has been
>>>destroyed by Python, which would give me the information
>>>I need to destroy Evil_twin behind the scene myself -
>>>which is what I am really after.
Wouldn't it be better if the robots draw themselfs onto the canvas?
That way you don't have to worry about deletion, a robot would only
draw itself when he's has to.
So perhaps it's an idea to delegate the drawing of stuff to the objects
themself rather then in the 'visibleworld' class.

> However (famous last words follow...) I feel it's not going to bite me
> this time.  The main reason is that, when Evil is gone, before the
> screen gets updated, lots of drawing calls and wxYield() calls are made,
> so that __del__ has lots of time to get called.
Your relying on something that *will* bite you, the question is rather
*when* will it bite you :-)

IMHO, the approach to rely on Python to do your dirty work and then
checks if it's done seems a bit VB to me :-)


Stas Zytkiewicz


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


Re: sync dir's

2005-05-10 Thread Gerhard Haering
On Tue, May 10, 2005 at 05:21:30PM +1000, Timothy Smith wrote:
> i need something which has a python library, so far i haven't seen 
> anything like that for rsync. i'll check out the others but

http://osx.freshmeat.net/projects/pysync/

"""
Pysync has both a demonstration implementation of the rsync and
related algorithms in pure Python, and a high speed librsync Python
extension. The pure Python is not fast and is not optimized, however
it does work and provides a simple implementation of the algorithm
for reference and experimentation. It includes a combination of
ideas taken from librsync, xdelta, and rsync. The librsync Python
extension is less flexible and harder to understand, but is very
fast.
"""
-- 
Gerhard Häring - [EMAIL PROTECTED] - Python, web & database development

pysqlite - Powerful and fast embedded database engine "SQLite" for Python.


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

Re: Does TKinter Have A Grid ?

2005-05-10 Thread Martin Franklin
Peter Moscatt wrote:
> Does TKinter have a Grid widget ?
> If not (as I assume), what is the alternative ?
> 
> Pete
> 

Pete,

If by grid you mean Table widget or Spreadsheet type widget then no Tk
does not have one (therefore nor does Tkinter)   However as luck would
have it there are a couple of extensions to Tk that provide a Table 
widget both Tk 'c' based and Tcl based.

for more about this (and lots of other useful stuff!)

http://tkinter.unpythonic.net/wiki/Widgets

It mentions two Table widgets, Tktable and tablelist both have python 
(tkinter) wrappers

Martin

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


Re: Does TKinter Have A Grid ?

2005-05-10 Thread Harlin Seritt
Not a grid widget necessarilly but a 'grid' method you can use instead
of pack(). Take a look at
http://www.pythonware.com/library/tkinter/introduction/grid.htm. If
this isn't what you mean, come back.

Harlin Seritt

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


Re: pyvm -- faster python

2005-05-10 Thread Stelios Xanthakis
Kay Schluehr wrote:
> 
> could You tell us a bit more about Your motivation to create an
> alternative C-Python interpreter? There is AFAIK no such ambitious
> project that has ever survived. The last one I remember died shortly
> after it was born:
> 

The motivation is that I just needed some bytecode engine. I deciced
to go with python bytecode, because well, IMO it's the best!
Eventually it turned out what it is.

I'm afraid this may end up dead before unborn too.
So it depends what people want. If nobody cares, I just learned python
the hard way and the project does to the abandonware cemetary.


Stelios



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


Re: pyvm -- faster python

2005-05-10 Thread Stelios Xanthakis
[EMAIL PROTECTED] wrote:

> This project is probably a LOT of work; maybe people can tell us about
> such efforts *before* doing so much work, so we can discuss it, and
> avoid wasting time.
> 

It is a lot of work indeed.
Usually, when people announce "we shall create X", it doesn't happen.
And you don't know if you can do it at all *before*.


> Maybe you can explain us why it is so fast, and/or maybe you can work
> with the other developers to improve the speed of the normal CPython,
> this can require equal or less work for you, and it can produce more
> long-lasting results/consequences for your work.
> 

The reason is that it's built from the scratch.
Guido would disagree with that, see py-dev thread:

http://www.mail-archive.com/python-dev@python.org/msg01225.html


There *are* alternative ways to do some things in the vm and Joel
is simply wrong:)
Could this be  Python 3000!!!? :)


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


Re: pyvm -- faster python

2005-05-10 Thread Stelios Xanthakis
Roger Binns wrote:

>>could You tell us a bit more about Your motivation to create an
>>alternative C-Python interpreter?
> 
> 
> I'd also be curious to know if the performance gains would remain
> once it gets fleshed out with things like closures, long numbers,
> new style classes and a C library compatibility shim.
> 

I guess it will.  There are several places with /*XXX:speed up*/
and a couple more ideas to gain exrta speed.  On the other hand
pyvm does not check for Bad Internal Calls and other checks Cpython
does to be OK in all cases (for example if __cmp__ modifies a list
while it's being sorted, in pyvm you *can* get a crash).

There is no plan to implement closures; unless there is a way to
turn closures to default arguments with bytecode hacking.  But yes,
closures are interesting, especially in generator expressions and
lambdas.

I am not very interested on C compatibility.  Once the source is
open people can implement it if they want but I'd rather go with
an advanced ctypes module which will make loading dynamic libraries
a matter of python code.


Stelios

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


Module on Getting the Date & Time

2005-05-10 Thread Sara Khalatbari
Is there a Modules in Python that returns the time &
date of today when ran?










__ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] new version of rur-ple (0.8.5)

2005-05-10 Thread Marco Aschwanden
On Tue, 10 May 2005 00:49:40 -0300, André Roberge  
<[EMAIL PROTECTED]> wrote:

> Learning to program computer should be fun, for adults and children
> alike. RUR-PLE is an environment designed to help you learn computer
> programming using the language Python. To use RUR-PLE, you need
> wxPython. You can learn more about RUR-PLE or you can go to the download
> page.

Surrender to Python - Resistance is futile! This is a fine piece of  
introduction!
Thanks for your efforts,
Marco

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


A Module on Time & Date

2005-05-10 Thread Sara Khalatbari
Is there a Module in Python that gives you the time &
date of today???




__ 
Do you Yahoo!? 
Make Yahoo! your home page 
http://www.yahoo.com/r/hs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Module on Time & Date

2005-05-10 Thread Michele Simionato
You should read the documentation and this:
http://www.catb.org/~esr/faqs/smart-questions.html

 Michele Simionato

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


Re: A Module on Time & Date

2005-05-10 Thread John Abel
Sara Khalatbari wrote:

>Is there a Module in Python that gives you the time &
>date of today???
>
>
>
>   
>__ 
>Do you Yahoo!? 
>Make Yahoo! your home page 
>http://www.yahoo.com/r/hs
>  
>
time - http://docs.python.org/lib/module-time.html
datetime - http://docs.python.org/lib/module-datetime.html

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


Re: Unique Elements in a List

2005-05-10 Thread Fredrik Lundh
Max M wrote:

>> depending on the data, it might be more efficient to store the
>> "last seen index" in a dictionary, and sort the result on the way
>> out (if necessary).  something like
>
> form sets import Set
>
> data = list(Set([0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]))

read the OP's spec again.

 



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


why this happend using model random?

2005-05-10 Thread flyaflya
from random import *

col = [0 for i in range(10)]
a = [col for  i in range(10)]

seed()
for i  in range(10):
 for j in  range(10):
 a[i][j] = randint(0, 100)
print a

the result is:
[[78, 65, 35, 5, 68, 60, 1, 51, 81, 70],
[78, 65, 35, 5, 68, 60, 1, 51, 81, 70],
[78, 65, 35, 5, 68, 60, 1, 51, 81, 70], .]
why result isn't true random?
but when the code like this:
from random import *
seed()
for i  in range(10):
 for j in  range(10):
 print randint(0, 100)
the result  is true random, what's deffient between these two segment codes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-10 Thread Bengt Richter
On 9 May 2005 15:36:37 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

>OK I need to be more clear I guess!Unique Elements I mean, elements
>that are non repeating. so in the above list 0.4, 0.9 are unique as
>they exist only once in the list.
>
You want to be careful of your definitions, especially with floating point 
values,
which may surprise the uninitiated. Dicts and sets hash numerically equal values
to the same hash, and then do equality test, so you get legitimate results like:

 >>> set([9*.1-8*.1, .1])
 set([0.10001, 0.099978])
 >>> set([123, 123.0, 123L])
 set([123])
 >>> set([123.0, 123, 123L])
 set([123.0])
 >>> set([123L, 123, 123.0])
 set([123L])


You may want to consider creating representations other than the original data
to use in your uniqueness testing, depending on your definition.

If you are happy with the way dicts and sets compare elements, you could do
a dict that keeps counts, or FTHOI something different (hot off untested 
griddle,
so test before relying ;-)

 >>> data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]
 >>> once=set()
 >>> more=set()
 >>> for el in data:
 ... if el in once: more.add(el)
 ... else: once.add(el)
 ...
 >>> once-more
 set([0.90002, 0.40002])

Not the most efficient space-wise, not sure about speed.

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


Re: why this happend using model random?

2005-05-10 Thread Fredrik Lundh
"flyaflya" wrote:

> from random import *
>
> col = [0 for i in range(10)]
> a = [col for  i in range(10)]

http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list

> seed()
> for i  in range(10):
> for j in  range(10):
> a[i][j] = randint(0, 100)
> print a
>
> the result is:
> [[78, 65, 35, 5, 68, 60, 1, 51, 81, 70],
> [78, 65, 35, 5, 68, 60, 1, 51, 81, 70],
> [78, 65, 35, 5, 68, 60, 1, 51, 81, 70], .]
> why result isn't true random?

because you've assigned all the values to the same list ("col").  see the link 
above
for details.

 



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


Re: why this happend using model random?

2005-05-10 Thread Robert Kern
flyaflya wrote:
> from random import *
> 
> col = [0 for i in range(10)]
> a = [col for  i in range(10)]

This is the problem. The list "a" now has ten references to the same 
object "col". They are not copied.

> seed()
> for i  in range(10):
>  for j in  range(10):
>  a[i][j] = randint(0, 100)

So every time you index into "a[i][j]" you are always getting "col[j]".

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


Re: A Module on Time & Date

2005-05-10 Thread Sakesun Roykiattisak
import datetime
print datetime.datetime.now()

Sara Khalatbari wrote:

>Is there a Module in Python that gives you the time &
>date of today???
>
>
>
>   
>__ 
>Do you Yahoo!? 
>Make Yahoo! your home page 
>http://www.yahoo.com/r/hs
>  
>

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


Re: Advice needed on __del__

2005-05-10 Thread André Roberge
stasz wrote:
> On Mon, 09 May 2005 22:49:06 -0300, André Roberge wrote:
> 
> 
>>Scott David Daniels wrote:
>>
>>>André Roberge wrote:
>>>
>>>
...  Each time I refresh the screen, I could
force that call, then check to see if Evil has been
destroyed by Python, which would give me the information
I need to destroy Evil_twin behind the scene myself -
which is what I am really after.
> 
> Wouldn't it be better if the robots draw themselfs onto the canvas?
> That way you don't have to worry about deletion, a robot would only
> draw itself when he's has to.
> So perhaps it's an idea to delegate the drawing of stuff to the objects
> themself rather then in the 'visibleworld' class.
> 

I thought about doing something like this... but gave it up.  The other 
way works well.

> 
>>However (famous last words follow...) I feel it's not going to bite me
>>this time.  The main reason is that, when Evil is gone, before the
>>screen gets updated, lots of drawing calls and wxYield() calls are made,
>>so that __del__ has lots of time to get called.
> 
> Your relying on something that *will* bite you, the question is rather
> *when* will it bite you :-)
> 
Well, since
1) this is used only as a demonstration of scoping in Python, in one example
2) other examples do not involve the temporary creation of robots (i.e. 
they would never go out of scope)
3) it works so far...

I'll wait for someone telling me that demonstration doen't work for 
them. ;-)

> IMHO, the approach to rely on Python to do your dirty work and then
> checks if it's done seems a bit VB to me :-)
> 
Ouch!  You don't mince words, do you?  Trying to get the QOTW? ;-)
> 
> Stas Zytkiewicz
> 
Unless I am sorely mistaken, I believe *you* have a full copy of the 
source code.  Why don't you try and see if your approach can be 
incorporated in the program? I'll buy you a beer if you make it work! ;-)

André

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


Re: sync dir's

2005-05-10 Thread Timothy Smith
Gerhard Haering wrote:

>On Tue, May 10, 2005 at 05:21:30PM +1000, Timothy Smith wrote:
>  
>
>>i need something which has a python library, so far i haven't seen 
>>anything like that for rsync. i'll check out the others but
>>
>>
>
>http://osx.freshmeat.net/projects/pysync/
>
>"""
>Pysync has both a demonstration implementation of the rsync and
>related algorithms in pure Python, and a high speed librsync Python
>extension. The pure Python is not fast and is not optimized, however
>it does work and provides a simple implementation of the algorithm
>for reference and experimentation. It includes a combination of
>ideas taken from librsync, xdelta, and rsync. The librsync Python
>extension is less flexible and harder to understand, but is very
>fast.
>"""
>  
>
pysync hasn't been worked on in years by the looks of it. no new 
releases since 03. and the last release was for 2.1, so i'm dubious 
about it working at all? the windows installer doesn't work either.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sync dir's

2005-05-10 Thread Steve Holden
Timothy Smith wrote:
> what would be the best tool to use to sync my local dir with a remote 
> one, say off a http resorce (although i'm open to other options there) i 
> haven't gotten any feed back on my problems with loading pysvn on win98, 
> and i can apprechiate if the dev's are too busy/can't be bothered with 
> win98. but i still need to find a solution that can achieve the same 
> result, and i'm starting to look for other options.
> 
You could always take a look at the ftpmirror code in the Tools 
subdirectory of your source distro. I've used that several times with 
great satisfaction, and it's fairly low-end - all you need is an FTP 
server at the other end.

regards
  Steve
-- 
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/

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


Re: extra a column from a 2-D array?

2005-05-10 Thread Uwe Lauth
Joe Wong wrote:
(original posting not on my nntp server)
>>Hello,
>> 
>> Suppose I have a python array as follow:
>> 
>>s=[ [1,3,5],
>>[2,4,6],
>>[9,8,7]]
>> 
>>what is the quickest way to extract the second colum from all rows? That 
>>is: [3,4,8] in this example.

[a[1] for a in s]

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

Re: Module on Getting the Date & Time

2005-05-10 Thread Simon Brunning
On 5/10/05, Sara Khalatbari <[EMAIL PROTECTED]> wrote:
> Is there a Modules in Python that returns the time &
> date of today when ran?

http://www.google.com/search?q=python+time+date

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sync dir's

2005-05-10 Thread Steve Holden
Timothy Smith wrote:
> Steve Holden wrote:
> 
>> Timothy Smith wrote:
>>  
>>
>>> what would be the best tool to use to sync my local dir with a remote 
>>> one, say off a http resorce (although i'm open to other options 
>>> there) i haven't gotten any feed back on my problems with loading 
>>> pysvn on win98, and i can apprechiate if the dev's are too busy/can't 
>>> be bothered with win98. but i still need to find a solution that can 
>>> achieve the same result, and i'm starting to look for other options.
>>>
>>>   
>>
>> You could always take a look at the ftpmirror code in the Tools 
>> subdirectory of your source distro. I've used that several times with 
>> great satisfaction, and it's fairly low-end - all you need is an FTP 
>> server at the other end.
>>
>> regards
>>  Steve
>>  
>>
> this has to work on both windows and nix's
> 

Indeed. Did I suggest anywhere that it wouldn't? The client can be any 
type of machine that you want, and the server can be most FTP servers.

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


Re: Does TKinter Have A Grid ?

2005-05-10 Thread Peter Moscatt
Mardy.   that's exactly what I was chasing.  I have downloaded the
tarball now it's just a matter of working out how I use Tcl with Python -
and I guess it won't hurt if I also use Tk in there as well

Pete


On Tue, 10
May 2005 10:11:59 +0100, Martin Franklin wrote:

> Peter Moscatt wrote:
>> Does TKinter have a Grid widget ?
>> If not (as I assume), what is the alternative ?
>> 
>> Pete
>> 
> 
> Pete,
> 
> If by grid you mean Table widget or Spreadsheet type widget then no Tk
> does not have one (therefore nor does Tkinter)   However as luck would
> have it there are a couple of extensions to Tk that provide a Table 
> widget both Tk 'c' based and Tcl based.
> 
> for more about this (and lots of other useful stuff!)
> 
> http://tkinter.unpythonic.net/wiki/Widgets
> 
> It mentions two Table widgets, Tktable and tablelist both have python 
> (tkinter) wrappers
> 
> Martin

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


Re: Re: extra a column from a 2-D array?

2005-05-10 Thread Whoami
Uwe Lauth,您好!

 Very good!

=== 2005-05-10 18:57:38 您在来信中写道:===

>Joe Wong wrote:
>(original posting not on my nntp server)
>>>Hello,
>>> 
>>> Suppose I have a python array as follow:
>>> 
>>>s=[ [1,3,5],
>>>[2,4,6],
>>>[9,8,7]]
>>> 
>>>what is the quickest way to extract the second colum from all rows? That 
>>>is: [3,4,8] in this example.
>
>[a[1] for a in s]
>
>Uwe
>
>-- 
>http://mail.python.org/mailman/listinfo/python-list

= = = = = = = = = = = = = = = = = = = =


致
礼!
 
 
Whoami
[EMAIL PROTECTED]
  2005-05-10

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

Re: sync dir's

2005-05-10 Thread Steve Holden
Timothy Smith wrote:
> Steve Holden wrote:
> 
>> Timothy Smith wrote:
>>
>>> Steve Holden wrote:
>>>
 Timothy Smith wrote:
  

> what would be the best tool to use to sync my local dir with a 
> remote one, say off a http resorce (although i'm open to other 
> options there) i haven't gotten any feed back on my problems with 
> loading pysvn on win98, and i can apprechiate if the dev's are too 
> busy/can't be bothered with win98. but i still need to find a 
> solution that can achieve the same result, and i'm starting to look 
> for other options.
>
>   



 You could always take a look at the ftpmirror code in the Tools 
 subdirectory of your source distro. I've used that several times 
 with great satisfaction, and it's fairly low-end - all you need is 
 an FTP server at the other end.

 regards
  Steve
  

>>> this has to work on both windows and nix's
>>>
>>
>> Indeed. Did I suggest anywhere that it wouldn't? The client can be any 
>> type of machine that you want, and the server can be most FTP servers.
>>
>> regards
>>  Steve
> 
> 
> oic source distro = python, i assumed you were making a linuxism
> 
Well that's because for everything but Windows (?) you only get Tools if 
you download the source. IIRC the Tools directory comes in the binary 
installer (or, at least, I have it somehow in my Windows Python 2.4, but 
not in my Cygwin Python 2.4. So I mentioned source, but the bottom line 
is that the code is accessible, even if you have to poke around for it.

Generally speaking I try to remain platform agnostic.

Since you are looking for a "low tech" solution (i.e. broadly available 
on most platforms) FTP might just do the job.

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


Re: Module on Getting the Date & Time

2005-05-10 Thread Whoami
Simon Brunning,您好!


>>> import time
>>> current = time.time()
>>> time.localtime(current)
(2005, 5, 10, 19, 28, 14, 1, 130, 0)
>>> time.ctime(current)
'Tue May 10 19:28:14 2005'

=== 2005-05-10 19:09:42 您在来信中写道:===

>On 5/10/05, Sara Khalatbari <[EMAIL PROTECTED]> wrote:
>> Is there a Modules in Python that returns the time &
>> date of today when ran?
>
>http://www.google.com/search?q=python+time+date
>
>-- 
>Cheers,
>Simon B,
>[EMAIL PROTECTED],
>http://www.brunningonline.net/simon/blog/
>-- 
>http://mail.python.org/mailman/listinfo/python-list
>

= = = = = = = = = = = = = = = = = = = =


致
礼!
 
 
Whoami
[EMAIL PROTECTED]
  2005-05-10

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

Regarding Mail sending Module

2005-05-10 Thread praba kar
Dear All,
  In Php we can do all the mailing operations like
sending a text as a message, adding attachment to a
mail, adding additional headers and so on using
Mail_mime class.  I want to know like that class or
modules in Python. 
   I already gone through MimeWriter,smtplib and so
on. But I can't get clear details. so if anyone know
regarding this kindly give me answer

regards
Prabahar



Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why this happend using model random?

2005-05-10 Thread flyaflya
Robert Kern wrote:
> flyaflya wrote:
> 
>> from random import *
>>
>> col = [0 for i in range(10)]
>> a = [col for  i in range(10)]
> 
> 
> This is the problem. The list "a" now has ten references to the same 
> object "col". They are not copied.
> 
>> seed()
>> for i  in range(10):
>>  for j in  range(10):
>>  a[i][j] = randint(0, 100)
> 
> 
> So every time you index into "a[i][j]" you are always getting "col[j]".
> 
thanks,I see,I know about reference and copy,but when is it a copy?when 
a reference?how can I get a copy when need?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-10 Thread Max M
Fredrik Lundh wrote:
> Max M wrote:
> 
> 
>>>depending on the data, it might be more efficient to store the
>>>"last seen index" in a dictionary, and sort the result on the way
>>>out (if necessary).  something like
>>
>>form sets import Set
>>
>>data = list(Set([0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]))
> 
> 
> read the OP's spec again.

Well if you want to haggle over minor details like a spec, it's easy to 
be critical!


data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]

freqs = {}
for position in xrange(len(data)):
 freqs.setdefault(data[position], []).append(position)
unique = [(value, positions[0]) for (value, positions) in freqs.items()
   if len(positions) == 1]



-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why this happend using model random?

2005-05-10 Thread Robert Kern
flyaflya wrote:
> Robert Kern wrote:
> 
>>flyaflya wrote:
>>
>>
>>>from random import *
>>>
>>>col = [0 for i in range(10)]
>>>a = [col for  i in range(10)]
>>
>>
>>This is the problem. The list "a" now has ten references to the same 
>>object "col". They are not copied.
>>
>>
>>>seed()
>>>for i  in range(10):
>>> for j in  range(10):
>>> a[i][j] = randint(0, 100)
>>
>>
>>So every time you index into "a[i][j]" you are always getting "col[j]".
>>
> 
> thanks,I see,I know about reference and copy,but when is it a copy?when 
> a reference?how can I get a copy when need?

Usually, references get passed around wherever possible. Just putting 
"col" into the list comprehension like you did will never copy.

If you need a copy of a list, you could do "col[:]" or "list(col)". More 
generally, see the "copy" module.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


Re: Regarding Mail sending Module

2005-05-10 Thread Max M
praba kar wrote:
> Dear All,
>   In Php we can do all the mailing operations like
> sending a text as a message, adding attachment to a
> mail, adding additional headers and so on using
> Mail_mime class.  I want to know like that class or
> modules in Python. 
>I already gone through MimeWriter,smtplib and so
> on. But I can't get clear details. so if anyone know
> regarding this kindly give me answer


You need the 'email' module for reading and writing email messages, and 
the 'smtplib' module for sending them.

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding comments/suggestions - first python script - sshd/ftpd blocking

2005-05-10 Thread bruno modulix
[EMAIL PROTECTED] wrote:
> If anyone is interested in a /etc/hosts.deny automatic update script
> (Unix only) based on sshd/vsftpd attacks, here's a python script:
> http://www.aczoom.com/tools/blockhosts/
> 
> This is a beta release, and my first attempt at Python coding.
> Any comments, suggestions, pointers on using more common Python idioms
> or example coding snippets, etc, welcome!

First thing: I had *many* indentation errors (emacs + python_mode on a 
linux-box). *Please* take care of this.

I just gave a quick glance, not even pretending to really understand 
what the code do, so what follow are just some general advices:

***
def die(msg, ex=None):
 print msg
 if ex: print ex
 sys.exit(1)

- errors messages (including usage) should be written to stderr (stdout 
is for normal output)
- you may want to use positional arguments (*args) instead of 'ex'

def die(msg, *args):
 print >> sys.stderr, msg
 for ex in args:
print >> sys.stderr, ex
 sys.exit(1)

***
class LockFile:
 (...)
 def lock(self):
 try:
try:
self.fp = open(self.path, "r+")
 # r+ prevents trashing the file!
except Exception, e :

You should use IOError instead of Exception here.
*Always* use the most specific exception class possible.

if e.errno == errno.ENOENT: # no such file

Here if you have anything else than an IOError (well, anything that 
doesn't have a 'errno' attribute), you'll get an AttributeError...
(...)

if DEBUG: print " ... first r+ lock file open failed, so 
opened 
with w+ mode"

You may want to define a 'debug_trace' function (or use an existing 
trace/log lib) that encapsulate the test...

***
class BlockHosts:
 (...)
 def load_hosts_deny(self, logoffsets):
 self.__remaining_lines = []

if self.__verbose: print " ... hosts.deny: loading from ", 
self.__denyfile

Same as for DEBUG : you may want to encapsulate the test in a method.

HTH
Bruno
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for 
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language documentation ( was Re: Computing Industry shams)

2005-05-10 Thread alex goldman
Sean Burke wrote:

> 
> alex goldman <[EMAIL PROTECTED]> writes:
> 
>> vermicule wrote:
>> 
>> > 
>> > What is so hard to understand ?
>> > Should be perfectly clear even to a first year undergraduate.
>> > 
>> > As for "greedy" even a minimal exposure to Djikstra's shortest path
>> > algorithm would have made the concept intuitive. And from memory,
>> > that is the sort of thing done in Computing 101 and in  Data Structures
>> > and Algorithms 101
>> > 
>> > It seems to me that you want the Python doc to be written for morons.
>> > And that is not a valid complaint.
>> 
>> He's right actually. If we understand the term "greedy" as it's used in
>> graph search and optimization algorithms, Python's RE matching actually
>> IS greedy.
> 
> No, you're just confused about the optimization metric.
> In regexes, "greedy" match optimizes for the longest match,
> not the fastest.
> 
> And this is common regex terminology - man perlre and you will
> find discussion of "greedy" vs. "stingy" matching.

Read what you quoted again. Everyone (Xah, vermicule, myself) was talking
about "greedy" as it's used in graph search and optimization algorithms.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sync dir's

2005-05-10 Thread Peter Hansen
Timothy Smith wrote:
> Gerhard Haering wrote:
>> http://osx.freshmeat.net/projects/pysync/
>>
> pysync hasn't been worked on in years by the looks of it. no new 
> releases since 03. and the last release was for 2.1, so i'm dubious 
> about it working at all? the windows installer doesn't work either.

You can (apparently) contact the maintainer ("ABO") for windows binaries 
if you need them.  He is also on the librsync project, which has as its 
latest news "0.9.6 released", and the release in 2003 of pysync was 
intended to update it to use librsync 0.9.6.  That suggests to me this 
is more a case of "things work" than a case of "dead project".

In any case, pysync itself doesn't even have code to walk the directory 
tree or send data, just the delta/patch code, so unless you plan to 
build the other parts for yourself it may not be what you need.  (On the 
other hand, if you need just the delta/patch code, it sounds like it 
should work fine.)  I haven't tried it myself (yet).

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


The first programming riddle on the net. Python-challenge

2005-05-10 Thread Sara Khalatbari
Hey guys!
Thanks for helping me find time&date.

Have you seen this?
This is the first programming riddle on the net with
20 levels! 

http://www.pythonchallenge.com/

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice needed on __del__

2005-05-10 Thread flupke
phil wrote:


> A class instance based language doesn't have to BE C++ to have a
> destructor method.
> 
> All I wanted to know is: is the apparent treatment of __del__
> which SEEMS to work fine for me in 2.3.4 deprecated or mangled
> in some later release or future plans.
> If someone doesn't know the answer to this question or if noone
> knows the answer to this question, I will still love and
> respect the Python Community.  In large part cause it ain't C++>

I like to use destructors to and find the way __del__ works a bit 
strange. For instance if you want to use a class variable in the __del__ 
function it's possible that it's not reachable via 
. and then you have to call it via 
self.__class__..
I find this non intuitive. I heard the explanations why but that doens't 
make it more intuitive.

Then i got a tip that you can register a function that needs to be 
called when the object is going to be deleted.
For instance to register a function __exit, you do this:

import atexit
...
class Bla:
 def __init__(self)
 ...
 atexit.register(self.__exit)
 ...
 def __exit(self):

It still doesn't feel right to me as i would rather use __del__ but 
since the behaviour can't be predicted, using atext is the next best thing

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


Re: Advice needed on __del__

2005-05-10 Thread Brian Quinlan
phil wrote:
> I'm probably dense and don't quite get the point, even though I
> have coded about 200,000 lines of Python and coded .5 million lines of
> C before there was a C++
> 
> A class instance based language doesn't have to BE C++ to have a
> destructor method.

Very true. But meaningful finalizers are a difficult problem in 
languages like Python. For example:

class A:
 def __del__(self): print self.b

class B:
 def __init__(self, a): self.a = a
 def __del__(self): print self.a

a = A()
a.b = B(a)
del a

What should happen? How would you implement that behavior? How would 
you implement that behavior on Java and .NET (neither of which 
gaurantee that finalizers/destructors will be called).

> All I wanted to know is: is the apparent treatment of __del__
> which SEEMS to work fine for me in 2.3.4 deprecated or mangled
> in some later release or future plans.

__del__ is not currently gauranteed to do anything. Currently it does 
something. Depending on that something is a bad idea. Could you explain 
your problem in more detail - maybe we'll have some suggestions.

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


Merging overlapping spans/ranges

2005-05-10 Thread Max M
I am writing a "find-free-time" function for a calendar. There are a lot 
of time spans with start end times, some overlapping, some not.

To find the free time spans, I first need to convert the events into a 
list of non overlapping time spans "meta-spans".

This nice ascii graph should show what I mean.

1) ---
2) ---
3)   ---
4)  -
5) -

 >> ---   # meta spans

I can then iterate through the meta-spans and find non-busy times.

I have written the class below, but it is rather O^2, so I wondered if 
anybody has an idea for a better approach?


##
# -*- coding: latin-1 -*-

"""
1) ---
2) ---
3)   ---
4)  -
5) -

 >> ---  
"""

class MetaSpans:

 """
 Populate with a list of span tuples [(start,end)], and it will make 
"meta"
 spans, with overlapping spans folded into one span.
 """

 def __init__(self):
 self.spans = []

 def add(self, span):
 start, end = span
 overlapping = [span]
 non_overlapping = []
 for spn in self.spans:
 spn_start, spn_end = spn
 # span rules for iterated spans
 starts_before = spn_start <= start
 ends_after = spn_end >= end
 is_outside = starts_before and ends_after
 starts_inside = start <= spn_start <= end
 ends_inside =  start <= spn_end <= end
 overlaps = starts_inside or ends_inside or is_outside
 if overlaps:
 overlapping.append(spn)
 else:
 non_overlapping.append(spn)
 # overlapping spans are changed to one span
 starts = []
 ends = []
 for start, end in overlapping:
 starts.append(start)
 ends.append(end)
 min_start = min(starts)
 max_end = max(ends)
 non_overlapping.append( (min_start, max_end) )
 self.spans = non_overlapping


 def findFreeTime(self, duration):
 self.spans.sort()




if __name__ == '__main__':

 ms = MetaSpans()
 ms.add((0,3))
 ms.add((4,7))
 ms.add((2,5))
 ms.add((9,14))
 ms.add((12,17))
 print ms.spans


 from datetime import datetime
 ms = MetaSpans()
 ms.add((datetime(2005, 1, 1, 0, 0, 0), datetime(2005, 1, 1, 3, 0, 0)))
 ms.add((datetime(2005, 1, 1, 4, 0, 0), datetime(2005, 1, 1, 7, 0, 0)))
 ms.add((datetime(2005, 1, 1, 2, 0, 0), datetime(2005, 1, 1, 5, 0, 0)))
 ms.add((datetime(2005, 1, 1, 9, 0, 0), datetime(2005, 1, 1, 14, 0, 0)))
 ms.add((datetime(2005, 1, 1, 12, 0, 0), datetime(2005, 1, 1, 17, 0, 
0)))
 print ms.spans





-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The first programming riddle on the net. Python-challenge

2005-05-10 Thread Peter Hansen
Sara Khalatbari wrote:
> Hey guys!
> Thanks for helping me find time&date.
> 
> Have you seen this?
> This is the first programming riddle on the net with
> 20 levels! 
> 
> http://www.pythonchallenge.com/

Yes, there's been "a bit" of discussion since this was announced a week 
or two ago: 
http://groups.google.ca/group/comp.lang.python/browse_thread/thread/7a755219ea1a5cec/7c98f7717c030b12?q=riddle&hl=en#7c98f7717c030b12

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


Re: pyvm -- faster python

2005-05-10 Thread François Pinard
[Stelios Xanthakis]

> I'm afraid this may end up dead before unborn too.  So it depends what
> people want. If nobody cares, [...]

People might not care so much about what could be done about your
project, unless you give them proper and complete means for evaluating
the state of affairs.  Your project is very likely to die if you keep
your sources closed, and yourself loose interest in the project.

Opening your sources is no guarantee either that the community will
adopt your project.  But this might give your project a better chance.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Module on Getting the Date & Time

2005-05-10 Thread Whoami
Simon Brunning,您好!


>>> import time
>>> current = time.time()
>>> time.localtime(current)
(2005, 5, 10, 19, 28, 14, 1, 130, 0)
>>> time.ctime(current)
'Tue May 10 19:28:14 2005'

=== 2005-05-10 19:09:42 您在来信中写道:===

>On 5/10/05, Sara Khalatbari <[EMAIL PROTECTED]> wrote:
>> Is there a Modules in Python that returns the time &
>> date of today when ran?
>
>http://www.google.com/search?q=python+time+date
>
>-- 
>Cheers,
>Simon B,
>[EMAIL PROTECTED],
>http://www.brunningonline.net/simon/blog/
>-- 
>http://mail.python.org/mailman/listinfo/python-list
>

= = = = = = = = = = = = = = = = = = = =


致
礼!
 
 
Whoami
[EMAIL PROTECTED]
  2005-05-10

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

Re: Regarding Mail sending Module

2005-05-10 Thread Larry Bates
There is a great class for doing just this at:

http://motion.technolust.cx/related/send_jpg.py

I've used it many times and it has worked very
well.

-Larry Bates


praba kar wrote:
> Dear All,
>   In Php we can do all the mailing operations like
> sending a text as a message, adding attachment to a
> mail, adding additional headers and so on using
> Mail_mime class.  I want to know like that class or
> modules in Python. 
>I already gone through MimeWriter,smtplib and so
> on. But I can't get clear details. so if anyone know
> regarding this kindly give me answer
> 
> regards
> Prabahar
> 
> 
> 
> Yahoo! India Matrimony: Find your life partner online
> Go to: http://yahoo.shaadi.com/india-matrimony

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


Re: Language documentation ( was Re: Computing Industry shams)

2005-05-10 Thread Lawrence Kirby
On Tue, 10 May 2005 04:58:48 -0700, alex goldman wrote:

> Sean Burke wrote:

...

>> No, you're just confused about the optimization metric.
>> In regexes, "greedy" match optimizes for the longest match,
>> not the fastest.
>> 
>> And this is common regex terminology - man perlre and you will
>> find discussion of "greedy" vs. "stingy" matching.
> 
> Read what you quoted again. Everyone (Xah, vermicule, myself) was talking
> about "greedy" as it's used in graph search and optimization algorithms.

However the original quote was in the context of regular expressions, so
discussion of the terminology used in regular expressions is far more
relevant than the terminology used in graph search and optimisation
algorithms.

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


Announce: Python for .NET 1.0 RC1 released

2005-05-10 Thread Brian Lloyd
Hi all -

I'm happy to announce the release of Python for .NET 1.0 RC1.
You can download it from:

  http://www.zope.org/Members/Brian/PythonNet

Highlights of this release:

- Implemented a workaround for the fact that exceptions cannot be
  new-style classes in the CPython interpreter. Managed exceptions
  can now be raised and caught naturally from Python

- Implemented support for invoking methods with out and ref parameters.
  Because there is no real equivalent to these in Python, methods that
  have out or ref parameters will return a tuple. The tuple will contain
  the result of the method as its first item, followed by out parameter
  values in the order of their declaration in the method signature.

- Fixed a refcount problem that caused a crash when CLR was imported in
  an existing installed Python interpreter.

- Added an automatic conversion from Python strings to byte[]. This
makes
  it easier to pass byte[] data to managed methods (or set properties,
  etc.) as a Python string without having to write explicit conversion
  code. Also works for sbyte arrays. Note that byte and sbyte arrays
  returned from managed methods or obtained from properties or fields
  do *not* get converted to Python strings - they remain instances of
  Byte[] or SByte[].

- Added conversion of generic Python sequences to object arrays when
  appropriate (thanks to Mackenzie Straight for the patch).

- Added a bit of cautionary documentation for embedders, focused on
  correct handling of the Python global interpreter lock from managed
  code for code that calls into Python.

- PyObject.FromManagedObject now correctly returns the Python None
  object if the input is a null reference. Also added a new
AsManagedObject
  method to PyObject, making it easier to convert a Python-wrapped
  managed object to the real managed object.

- Created a simple installer for windows platforms.


All known bugs have also been fixed - thanks to all who have sent in issue
reports and patches for past releases.

At this point, the only thing I plan to do before a 1.0 final is fix any
new issues and add to the documentation (probably including a few specific
examples of embedding Python for .NET in a .NET application).

Enjoy! ;)


Brian Lloyd[EMAIL PROTECTED]
V.P. Engineering   540.361.1716
Zope Corporation   http://www.zope.com

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


Re: Language documentation ( was Re: Computing Industry shams)

2005-05-10 Thread alex goldman
Lawrence Kirby wrote:

> On Tue, 10 May 2005 04:58:48 -0700, alex goldman wrote:
> 
>> Sean Burke wrote:
> 
> ...
> 
>>> No, you're just confused about the optimization metric.
>>> In regexes, "greedy" match optimizes for the longest match,
>>> not the fastest.
>>> 
>>> And this is common regex terminology - man perlre and you will
>>> find discussion of "greedy" vs. "stingy" matching.
>> 
>> Read what you quoted again. Everyone (Xah, vermicule, myself) was talking
>> about "greedy" as it's used in graph search and optimization algorithms.
> 
> However the original quote was in the context of regular expressions, so
> discussion of the terminology used in regular expressions is far more
> relevant than the terminology used in graph search and optimisation
> algorithms.

I replied to "And from memory, that is the sort of thing done in Computing
101 and in  Data Structures and Algorithms 101", and I fully explained what
I meant by "greedy" as well. There was no ambiguity.
-- 
http://mail.python.org/mailman/listinfo/python-list


www.pythonchallange.com

2005-05-10 Thread Gabor Farkas
www.pythonchallange.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: www.pythonchallange.com

2005-05-10 Thread Gabor Farkas
Gabor Farkas wrote:
> www.pythonchallange.com

sorry, wanted to send it to someone else..

(too tired...)

;(

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


Re: Advice needed on __del__

2005-05-10 Thread Sion Arrowsmith
=?ISO-8859-1?Q?Andr=E9_Roberge?=  <[EMAIL PROTECTED]> wrote:
>If I need to have the user call Evil.destroy() as Evil
>is getting out of scope, it would miss the whole point
>of teaching about the natural way scope and namespace
>work.

The problem, it seems to me, is that in Python "scope" applies
to names, but you're trying to apply it to objects. A name going
out of scope shouldn't be assumed to have much of an impact on
the object it referred to, and by emphasising too close a link
between name and object I think you're more likely to run into
trouble later on.

As was pointed out upthread, Python isn't C++. (Speaking as
someone who's been bitten by a very similar issue due to Java
not being C++ either.)

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

Re: Advice needed on __del__

2005-05-10 Thread Fredrik Lundh
André Roberge wrote:

> If I need to have the user call Evil.destroy() as Evil
> is getting out of scope, it would miss the whole point
> of teaching about the natural way scope and namespace
> work.

well, if you insist on using finalizers to keep track of what's in the current
scope, I'd say that you are missing the point about how scopes and name-
spaces work...

(to track the contents of a scope, you have to look at the scope.)

> A thought occurred to me, regarding "when" __del__
> is called.  Can I force Python, through some function call,
> to perform this.  Each time I refresh the screen, I could
> force that call, then check to see if Evil has been
> destroyed by Python, which would give me the information
> I need to destroy Evil_twin behind the scene myself -
> which is what I am really after.

the correct solution is to inspect the current namespace every time you
refresh the screen, and make sure the screen contents matches what's
in the namespace.

 



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

Re: why this happend using model random?

2005-05-10 Thread flyaflya
flyaflya wrote:
> Robert Kern wrote:
> 
>> flyaflya wrote:
>>
>>> from random import *
>>>
>>> col = [0 for i in range(10)]
>>> a = [col for  i in range(10)]
>>
>>
>>
>> This is the problem. The list "a" now has ten references to the same 
>> object "col". They are not copied.
>>
>>> seed()
>>> for i  in range(10):
>>>  for j in  range(10):
>>>  a[i][j] = randint(0, 100)
>>
>>
>>
>> So every time you index into "a[i][j]" you are always getting "col[j]".
>>
> thanks,I see,I know about reference and copy,but when is it a copy?when 
> a reference?how can I get a copy when need?
I find the answer on  chapter4.5,it's a practical book for 
the newbies like me,maybe many newbie using c/c++ would make such mistake
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice needed on __del__

2005-05-10 Thread André Roberge
Fredrik Lundh wrote:
> André Roberge wrote:
>>If I need to have the user call Evil.destroy() as Evil
>>is getting out of scope, it would miss the whole point
>>of teaching about the natural way scope and namespace
>>work.
> 
> 
> well, if you insist on using finalizers to keep track of what's in the current
> scope, I'd say that you are missing the point about how scopes and name-
> spaces work...
> 
I don't think I do, but I think I didn't explain things well enough.
1. The user creates an object, within a "local" scope.  When he does 
that, I update a list of images in a "global" scope.  I then use that 
list of images to decide what to display on the screen.

The user is unaware of the connection I am making behind the scene.
> 
[Snip]
> 
> the correct solution is to inspect the current namespace every time you
> refresh the screen, and make sure the screen contents matches what's
> in the namespace.

To do that, I would need to put a "link", in the "global" scope between 
the object created by the user, and the user. However, in doing so
(if I am not missing the point about how scopes and namespaces work...)
the object created by the user would always have a reference in the 
global scope ... and thus would never disappear from the namespace.

I understand that, if the "link" is a "weak reference", then it might 
disappear when the object goes out of scope.  Is that what you mean I 
should do?

André
>  


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


Re: Advice needed on __del__

2005-05-10 Thread Scott David Daniels
André Roberge wrote:
> Scott David Daniels wrote:
> 
>> André Roberge wrote:
>>
>>> ...  Each time I refresh the screen, I could
>>> force that call, then check to see if Evil has been
>>> destroyed by Python, which would give me the information
>>> I need to destroy Evil_twin behind the scene myself -
>>> which is what I am really after.
>>
>> What might work is to keep a weakref to Evil in Evil_twin.
>> Upon refresh, you could check if the weakref has gone stale.
>> Is that good enough?
> 
> ...
Try something like this:
++ import weakref
>  class UsedRobot(object):
-- def __init__(self, ..., parent=Visible_world()):
++ def __init__(self, ..., jeckyll=None, parent=Visible_world()):
++ # need to know if we are good or evil.
>  # Visible_world is a Singleton - see Python cookbook
-->true_robot = parent.addOneRobot(...)# <---Evil_twin created
>  self.robot = parent.robot_dict[true_robot.name]
>  self.name = true_robot.name
>  self.program = rur_program() # Singleton
>  self.parent = parent
>  self.parent.object_dict[self.name] = True  # <--- new trick
>  self.program.wait_update_refresh(self.robot, self.name)
++ if jeckyll is None:
++ # Making a good twin.  Make an evil partner
++ twin = parent.addOneRobot(..., jeckyll=self)
++ self.twin = lambda: return twin # match weakref interface
++ # hold a ref to the evil twin, so it will be alive
++ else:
++ # Making an evil twin.  Make a weak ref to the good
++ twin = parent.addOneRobot(..., jeckyll=self, ...)
++ self.twin = weakref.ref(jeckyll)
-->def __del__(self):
-->self.parent.object_dict[self.name] = False
...

Somewhere else when deciding to draw a particular robot:
  ... robot = whatever ...
-->  
++   if robot.twin() is None:
++   # This must be an evil twin with a dead good twin
++   
++   else:
++   # this is either a good twin or
++   
...

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Library Naming Conventions.

2005-05-10 Thread chris . lyon
quoting:

  Modules should have short, lowercase names, without underscores.

this still doesn't explain Cookie.




[EMAIL PROTECTED] wrote:
> see http://www.python.org/peps/pep-0008.html for naming conventions
and
> other style issues

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


Re: Strip white spaces from source

2005-05-10 Thread qwweeeit
Hi Richie,
I did not post my solution because I did not want to "pollute" the
pythonic way of programming.
Young programmers, don't follow me!
I hate (because I am not able to use them...) classes and regular
expressions.
Instead I like lists, try/except (to limit or better eliminate
debugging) and os.system + shell programming (I use Linux).
The problem of stripping white spaces from python source lines could be
easily (not for me...) solved by RE.

Instead I choosed the hard way:
Imagine you have a lot of strings representing python source lines (in
my case I have almost 3 lines).
Let's call a generic line "sLine" (with or without the white spaces
representing indentation).
To strip the un-necessary spaces you need to identify the operands.

Thanks to the advice of Alex Martelli, there is a parsing method based
on tokenize module, to achieve this:

import tokenize, cStringIO
try:
.   for x in
tokenize.generate_tokens(cStringIO.StringIO(sLine).readline):
.   .   if x[0]==50:
.   .   .sLine=sLine.replace(' '+x[1],x[1])
.   .   .sLine=sLine.replace(x[1]+' ',x[1])
except tokenize.TokenError:
.   pass

- x[0] is the 1st element of the x tuple, and 50 is the code for
OPERAND.
(For those who want to experiment on the x tuple, you can print it
merely by a
"print str(x)". You obtain as many tuples as the elements present in
the line).
- x[1] (the 2nd element of the x tuple) is the Operand itself.

The try/except is one of my bad habits:
the program fails if the line is a multiline.
Ask Alex... I haven't gone deeper.

At the end you have sLine with white spaces stripped...
There is yet a mistake...: this method  strip white spaces also inside
strings.
(I don't care...).

A last word of caution: I haven't tested this extract from my
routine...

This small script is part of a bigger program: a cross-reference tool,
but don't ask me for that...

Bye.

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


Re: Library Naming Conventions.

2005-05-10 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> quoting:
> 
>   Modules should have short, lowercase names, without underscores.
> 
> this still doesn't explain Cookie.

Sure it does.  The subject line says "conventions", and a convention 
isn't a firm rule, just something many people agree on.  Obviously the 
author of Cookie has different preferences.  Nobody is bound by a 
convention.

The PEP describes what is widespread but not universal preference, 
that's all.

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


Re: Merging overlapping spans/ranges

2005-05-10 Thread bearophileHUGS
This is the problem of finding the connected components inside an
interval graph. You can implement the algorithms yourself, of you can
use my graph data structure here:

http://sourceforge.net/projects/pynetwork/

The graph methods:
createIntervalgGraph
And:
connectedComponents
can probably solve your problem quite fast, algorithmically, and with
few lines of code.
If you need more help, then ask for it and I'll give the little code
needed.

Bear hugs,
Bearophile

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


Re: Library Naming Conventions.

2005-05-10 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> quoting:
>
>   Modules should have short, lowercase names, without underscores.
>
> this still doesn't explain Cookie.

the document you're quoting also says:

This document was adapted from Guido's original Python Style
Guide essay[2]

where [2] points to a document that says:

Module names can be either MixedCase or lowercase.
There is no unambiguous convention to decide which
to use. Modules that export a single class (or a number
of closely related classes, plus some additional support)
are often named in MixedCase, with the module name
being the same as the class name (e.g. the standard
StringIO module). Modules that export a bunch of
functions are usually named in all lowercase.





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


Re: Library Naming Conventions.

2005-05-10 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> quoting:
> 
>   Modules should have short, lowercase names, without underscores.
> 
> this still doesn't explain Cookie.

PEP-008 didn't exist since the beginning of Python's development. Cookie 
(I believe) predates PEP-008.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


Re: Strip white spaces from source

2005-05-10 Thread William Park
[EMAIL PROTECTED] wrote:
> Hi all,
> I need to limit as much as possible the lenght of a source line,
> stripping white spaces (except indentation).
> For example:
> .   .   max_move and AC_RowStack.acceptsCards ( self, from_stack, cards
> )
> must be reduced to:
> .   .   max_move and AC_RowStack.acceptsCards(self,from_stack,cards)
> 
> My solution has been (wrogly): ''.join(source_line.split())
> which gives:
> max_moveandAC_RowStack.acceptsCards(self,from_stack,cards)
> 
> Without considering the stripping of indentation (not a big problem),
> the problem is instead caused by the reserved words (like 'and').
> 
> Can you help me? Thanks.

Perhaps, you can make indent(1) do what you want.  It's designed for C
program, but...

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Filenames of files downloaded via urlretrieve that have been redirected

2005-05-10 Thread Ray Slakinski
I got a small issue, I am using urllib.urlretreive to download files
but in some cases I'm downloading from a CGI that is redirecting
urlretrieve to a different url.

Example:

urllib.urlretreive('http://someurl.com/files.asp?file=55',
'tempFileName.tmp')

Is there a way to know what filename files.asp is redirecting to so I
can rename tempFileName.tmp to the correct name?

Thanks in advance,
Ray

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


Iterating package's module list

2005-05-10 Thread ischenko
Hi,

I'm trying to find all modules that contain doctests and execute them
(using DocTestSuite). The problem is how to iterate (programmatically)
through the package's modules.

>>> import M
>>> inspect.getmembers(M, inspect.ismodule)
[]

Iterating through the source files (via glob) does not help either:

>>> __import__('M.foobar')


See, individual modules points to the base package, not to the module
itself.

How can I iterate through the modules that comprise a Python package?

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


object oriented inheritance problem

2005-05-10 Thread Matthew Thorley
I am trying to inherit from ElementTree so I can add some methods. This
is the code I am trying to make work, and the following is the error I
am getting.

from elementtree import ElementTree
class AcidTree(ElementTree):
def write_string(self):


File "/home/hope/var/proj/acid/server/mgacparse.py", line 22, in ?
class AcidTree(ElementTree):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)


I have *no* idea what is going on here. AcidTree does not implement an
__init__. It just adds two simple methods, which aren't even being
called when then exception is thrown. The exception occurs on the class
definition line when I try to inherit from ElementTree.

I looked around, and read some stuff in the python cook book, and
everything I've seen indicates that it should just work. My only thought
is that its a 'oldstyle' vs 'newstyle' classes issue. I know that
elementtree was written to be compatible with python 1.5 so maybe it
doesn't work with the new stuff. But thats just a crazy assumption I
made up to make myself feel better.

If anyone could please exmplain what my problem *really* is I would
appreciate it greatly. Thanks very much.

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


Re: object oriented inheritance problem

2005-05-10 Thread Michele Simionato
It looks like ElementTree is a module and not a class.
The same error message was posted here few weeks ago.
Actually, I discuss it in my Oxford lectures, page 30:
see
http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_wondersofpython.zip

(there also everything you want to know about new-style
classes and more).

   Michele Simionato

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


Desrtuctor WOES, was Advice on __del__

2005-05-10 Thread phil
> you haven't answered my question, btw: why are you using __del__
> to do something that the garbage collector should do for you?


After more reading it seems I have made an ass of my self on this
subject.  Here is my problem at length.

I teach high school geometry.  I have created a program with a
scalable graph on which to make drawings to illustrate concepts.
This is working well.


I like to MOVE the objects one pixel at a time or ROTATE them
one degree at a time so the students can follow the progress of
the lesson.

A script of a simple drawing might be:

scale 100
color red
tr1 = triangle from x y base baselength angles 30 60
rotate centerx centery degrees objlist   # eg tr1

This would create an instance of triangle which would
create an instance of polygon which would create 3
instances of lines, which are point pairs.

class line:
def __init__(s,glob,argl,color=''):
s.glob = glob
:::
 :::

 x0 = a0  * s.glob.scale + 400
 y0 = 300 - b0  * s.glob.scale
 x1 = a1  * s.glob.scale + 400
 y1 = 300 - b1 * s.glob.scale
s.obj = glob.can.create_line(x0,y0,x1,y1,
width=glob.width,fill=s.color)
def __del__(s):
s.glob.can.delete(s.obj)

This calls Canvas.create_line.  Tkinter keeps its own list of
drawn objects.  I store the ref in s.obj

NOW when I rotate the triangle 45 degrees, recomputing the points
each time, it creates 45 new instances of triangle but dels the
old one.  __del__  then deletes the Canvas line object.

Without that, the list of objects grows very long,
and refresh gets slow.
This is a very complex program, 1000 lines now, propably 2000
lines eventually.  There are dozens of places where I depend on
__del__ deleteting canvas objects.

SO: without significant rewrite of each class such as triangle
and line, how can I ensure those canvas lines get deleted?
You don't really need to understand Canvas, just trust me
I have to delete those objects and they are not properties of the
class which go away with garbage collection.

Thanks.

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


A Faster Way...

2005-05-10 Thread andrea . gavana
Hello NG,

  it is probably a beginner question, but I didn't solve it without
for-loops, and I am unable to determine if there is a faster way (probably
using some built-in function) to do this task. I have to speed up a
wxPython code that uses a lot of string concatenation (and uses these
strings to build some Fancy StaticText Controls). I found a way, but I need
a little bit of help from you, NG.

If I simplify the problem, suppose I have 2 lists like:

a = range(10)
b = range(20,30)

What I would like to have, is a "union" of the 2 list in a single tuple. In
other words (Python words...):

c = (0, 20, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, .

and so on.

Sorry if it seems an homework assignment.

Thanks to you all.

Andrea
--
 Message for the recipient only, if received in error, please notify the
sender and read http://www.eni.it/disclaimer/


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


Put a file on an ftp server over ssl

2005-05-10 Thread Daniel Santa Cruz
Hello all!

I have been troubled for the past couple of days trying to write a
simple script that sends a file to an ftp server.  It used to be the
easiest thing in the world, but now the server has changed to a ftps
(ftp over ssl) server.  All of the sudden, the world has come to a
crawling stop.

Seems that M2Crypto would maybe do the trick, but I can't buy the thing
(they won't pay for it).  Other than suggesting projects, does any one
have actuall working code to do something like this?  My, it seems like
it should be VERY simple, but it has become a nightmare.

Oh do I wish...

f = ftps.connect('username', 'password', port)
ftps.put(localFilePath)

Done!

Thanks for any help!

Daniel

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


win32com and IIS

2005-05-10 Thread Chris Curvey
Hi all,

I have a python script that uses the PAMIE libraries to drive IE.  It
runs fine from the command line, but it appears to have some
permissions problem when I run it via CGI.  Here's the stack trace that
I'm getting.

  File "c:\documents and settings\chris\my
documents\cms\com\artfact\cms\model\cPAMIE.py", line 54, in __init__
self._ie = DispatchEx('InternetExplorer.Application')
  File "C:\Program Files\Plone
2\Python\lib\site-packages\win32com\client\__init__.py", line 112, in
DispatchEx
dispatch = pythoncom.CoCreateInstanceEx(clsid, None, clsctx,
serverInfo, (pythoncom.IID_IDispatch,))[0]
com_error: (-2147024891, 'Access is denied.', None, None)

I found this thread in the archives, but the changes made there don't
seem to have helped.

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/3273ca109892b275/0da814cb9f341568?q=win32com+iis&rnum=2#0da814cb9f341568

Any suggestions?

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


Re: object oriented inheritance problem

2005-05-10 Thread Fredrik Lundh
Matthew Thorley wrote:

> I am trying to inherit from ElementTree so I can add some methods. This
> is the code I am trying to make work, and the following is the error I
> am getting.
>
> from elementtree import ElementTree
> class AcidTree(ElementTree):
> def write_string(self):
> 
>
> File "/home/hope/var/proj/acid/server/mgacparse.py", line 22, in ?
> class AcidTree(ElementTree):
> TypeError: Error when calling the metaclass bases
> module.__init__() takes at most 2 arguments (3 given)
>
> I have *no* idea what is going on here.

note that you're trying to inherit from a module.  the error message could
need some work...

something like

from elementtree.ElementTree import ElementTree, tostring

class AcidTree(ElementTree):
def write_string(self):
return tostring(self)

should work better.





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


Re: win32com and IIS

2005-05-10 Thread Chris Curvey
my OS is Win2K (server, I think) if that makes any difference.

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


Re: A Faster Way...

2005-05-10 Thread Bill Mill
On 5/10/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello NG,
> 
>   it is probably a beginner question, but I didn't solve it without
> for-loops, and I am unable to determine if there is a faster way (probably
> using some built-in function) to do this task. I have to speed up a
> wxPython code that uses a lot of string concatenation (and uses these
> strings to build some Fancy StaticText Controls). I found a way, but I need
> a little bit of help from you, NG.
> 
> If I simplify the problem, suppose I have 2 lists like:
> 
> a = range(10)
> b = range(20,30)
> 
> What I would like to have, is a "union" of the 2 list in a single tuple. In
> other words (Python words...):

well a "union" can be obtained with:

>>> z = range(10) + range(20, 30)
>>> z
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]

> 
> c = (0, 20, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, .

Alternating the items can be done by:

>>> [z[((i%2)*(len(z/2)))+i/2] for i in range(len(z))]
[0, 20, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, 6, 26, 7, 27, 8, 28, 9, 29]

Or in a slightly different format:

>>> zip(range(10), range(20, 30))
[(0, 20), (1, 21), (2, 22), (3, 23), (4, 24), (5, 25), (6, 26), (7, 27), (8, 28)
, (9, 29)]

> Sorry if it seems an homework assignment.

It'd be one heck of a short homework assignment. I hope you've read
the python tutorial at http://docs.python.org/tut/tut.html ; it'll
help you a lot to go through it a couple times.

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyvm -- faster python

2005-05-10 Thread Terry Reedy

"Stelios Xanthakis" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> Maybe you can explain us why it is so fast, and/or maybe you can work
>> with the other developers to improve the speed of the normal CPython,
>> this can require equal or less work for you, and it can produce more
>> long-lasting results/consequences for your work.
>>
>
> The reason is that it's built from the scratch.
> Guido would disagree with that, see py-dev thread:

Guido, like me, believes in being correct before being fast.

> http://www.mail-archive.com/python-dev@python.org/msg01225.html
>
>
> There *are* alternative ways to do some things in the vm and Joel
> is simply wrong:)

The smiley doesn't negate your silliness.  Joel explicitly talked about 
complex, mature, debugged, in-use systems, with actual or potential 
competitive replacements, not laboratory development toys and prototypes. 
Three years between releases *is* a long time.  And the Python codebase 
*does* embody a lot of hard-won knowledge, hardly available elsewhere, that 
should not be tossed.  A particular example is how to get certain things to 
work across numerous platforms in the face of ambuiguity and 'not defined' 
behavior in the C standard and implementations.

Its possible that some future reference Python will be based on a new, 
built-from-scratch core developed *in parallel* with current Python.  But 
that will only happen after it has been tested on a hundred different 
platforms with a hundred different applications and packages (as happens, 
more or less, with each new CPython release).

Terry J. Reedy



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


Re: Listing of declared variables and functions

2005-05-10 Thread Fernando Perez
ohms377 wrote:

> Dear python users,
> 
> In interactive mode, I was wondering if there is a way to list all
> declared variables and functions (and from global workspace).

In [1]: def foo(): pass
   ...:

In [2]: x=1

In [3]: a='hello'

In [4]: import re

In [5]: whos
Variable   TypeData/Info

a  str hello
foofunction
re module  
x  int 1

In [6]: whos int
Variable   TypeData/Info

x  int 1


This is using ipython for the interactive work.

Cheers,

f

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


Re: object oriented inheritance problem

2005-05-10 Thread Matthew Thorley
So is elementtree a module of modules? I didn't know you could do that.
I just assumed that from elementtree import ElementTree imported a class
from the module elementtree.

It works now. Thanks guys.

Fredrik Lundh wrote:
> Matthew Thorley wrote:
> 
> 
>>I am trying to inherit from ElementTree so I can add some methods. This
>>is the code I am trying to make work, and the following is the error I
>>am getting.
>>
>>from elementtree import ElementTree
>>class AcidTree(ElementTree):
>>def write_string(self):
>>
>>
>>File "/home/hope/var/proj/acid/server/mgacparse.py", line 22, in ?
>>class AcidTree(ElementTree):
>>TypeError: Error when calling the metaclass bases
>>module.__init__() takes at most 2 arguments (3 given)
>>
>>I have *no* idea what is going on here.
> 
> 
> note that you're trying to inherit from a module.  the error message could
> need some work...
> 
> something like
> 
> from elementtree.ElementTree import ElementTree, tostring
> 
> class AcidTree(ElementTree):
> def write_string(self):
> return tostring(self)
> 
> should work better.
> 
> 
> 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Faster Way...

2005-05-10 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> If I simplify the problem, suppose I have 2 lists like:
>
> a = range(10)
> b = range(20,30)
>
> What I would like to have, is a "union" of the 2 list in a single tuple. In
> other words (Python words...):
>
> c = (0, 20, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, .
>
> and so on.

here are some alternatives:

c = sum(zip(range(10), range(20, 30)), ())

or

c = []
[c.extend(x) for x in zip(range(10), range(20, 30))]
c = tuple(c)

or

from _tkinter import _flatten
c = _flatten(zip(range(10), range(20, 30)))

(timeit is your friend)





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


error using process module Process class

2005-05-10 Thread Earl Eiland
When executing the following code snippet

import process
...
...
for x in Files:
Command_String = 'C:\Program Files\WinRK\WinRK.exe -create ' +
os.path.join(InputDirectory, os.path.splitext(x)[0]) + ' -set
compression_method ppmz -setg include_paths none -add ' +
os.path.join(InputDirectory, x) + ' -apply -quit'
PROC = process.Process(Command_String)
PROC.wait()

from the command line

C:\Documents and Settings\eeiland\Desktop>Thesis_Programs\Compressor2.py
Test_Da
ta\sliceX12 Test_Output\Test

generates the following error:

Traceback (most recent call last):
  File "C:\Documents and
Settings\eeiland\Desktop\Thesis_Programs\Compressor2.py
", line 61, in ?
PROC = process.Process(Command_String)
  File "C:\Python24\Lib\site-packages\process.py", line 839, in __init__
self._startOnWindows()
  File "C:\Python24\Lib\site-packages\process.py", line 913, in
_startOnWindows
cmd = _whichFirstArg(cmd, self._env)
  File "C:\Python24\Lib\site-packages\process.py", line 303, in
_whichFirstArg
import which
ImportError: No module named which


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


Re: Language documentation ( was Re: Computing Industry shams)

2005-05-10 Thread Lawrence Kirby
On Tue, 10 May 2005 06:52:18 -0700, alex goldman wrote:

> Lawrence Kirby wrote:

...

>> However the original quote was in the context of regular expressions, so
>> discussion of the terminology used in regular expressions is far more
>> relevant than the terminology used in graph search and optimisation
>> algorithms.
> 
> I replied to "And from memory, that is the sort of thing done in Computing
> 101 and in  Data Structures and Algorithms 101", and I fully explained what
> I meant by "greedy" as well. There was no ambiguity.

My response talks about relevance, not ambiguity.

Lawrence

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


Python Graphing Utilities.

2005-05-10 Thread Kenneth Miller
Hello All,

I am new to Python and i was wondering what graphing utlities would be
available to me. I have already tried BLT and after weeks of unsuccesful
installs i'd like to find something else. Anything someone would recommend?

Regards,
Ken


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


Destructor Woes, was Advice needed on __del__

2005-05-10 Thread phil

> Then i got a tip that you can register a function that needs to be 
> called when the object is going to be deleted.
> For instance to register a function __exit, you do this:
> 


Here is the complete line class with your suggestion:

Below is the output.

Nice idea, maybe I did something wrong?

class line:
def __init__(s,glob,argl,color=''):
atexit.register(s.__exit)
s.glob = glob
s.type = 'line'
s.color = color
if not s.color: s.color = glob.color
if len(argl) == 2:
wobj = glob.objs[ argl[0] ][0]
s.x0 = a0 = wobj.x
s.y0 = b0 = wobj.y
wobj = glob.objs[ argl[1] ][0]
s.x1 = a1 = wobj.x
s.y1 = b1 = wobj.y

elif len(argl) == 4:
s.x0 = a0 = float( argl[0] )
s.y0 = b0 = float( argl[1] )
s.x1 = a1 = float( argl[2] )
s.y1 = b1 = float( argl[3] )
else: return
s.midx = (s.x0 + s.x1) / 2
s.midy = (s.y0 + s.y1) / 2
s.len = sqrt( (s.x1 -s.x0)**2  + (s.y1 -s.y0)**2 )
if  (s.y1 -s.y0) == 0: s.slope = 0
elif  (s.x1 -s.x0) == 0: s.slope = 99
else: s.slope = (  (s.y1 -s.y0) / (s.x1 -s.x0) )

# center point of graph is 400,300
# scale is no of pixels per unit of measure
 x0 = a0  * s.glob.scale + 400
 y0 = 300 - b0  * s.glob.scale
 x1 = a1  * s.glob.scale + 400
 y1 = 300 - b1 * s.glob.scale
s.obj = glob.can.create_line(x0,y0,x1,y1,
width=glob.width,fill=s.color)
def __exit(s):
print 'exit'
s.glob.can.delete(s.obj)

# def __del__(s):
# s.glob.can.delete(s.obj)


exit

Error in sys.exitfunc:
Traceback (most recent call last):
   File "/usr/local/lib/python2.3/atexit.py", line 20, in _run_exitfuncs
 func(*targs, **kargs)
   File "./graph.py", line 972, in __exit
 s.glob.can.delete(s.obj)
   File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2085, in delete
 self.tk.call((self._w, 'delete') + args)
_tkinter.TclError: invalid command name ".1076354284"

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


Re: object oriented inheritance problem

2005-05-10 Thread Fredrik Lundh
Matthew Thorley wrote:

> So is elementtree a module of modules? I didn't know you could do that.

"elementtree" is a package.  see:

http://docs.python.org/tut/node8.html#SECTION00840

for a bit more information.





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


Re: Python Graphing Utilities.

2005-05-10 Thread Fredrik Lundh
Kenneth Miller wrote:

> I am new to Python and i was wondering what graphing utlities would be
> available to me. I have already tried BLT and after weeks of unsuccesful
> installs i'd like to find something else. Anything someone would recommend?

start here:

http://www.python.org/moin/NumericAndScientific/Plotting
http://starship.python.net/crew/jhauser/plot-res.html

or roll your own:

http://effbot.org/zone/wckgraph.htm





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


Solipsis: Python-powered Metaverse

2005-05-10 Thread Terry Reedy
Today I followed a link to an interesting Python application I have not 
seen mentioned here before:  http://solipsis.netofpeers.net/wiki/HomePage/.

"A peer-to-peer system for a massively multi-participant virtual world "

It is a France Telecom R&D project, LGPL licenced, still in alpha, built on 
Python, Twisted, WxPthon, PIL, and probably other components actual or 
considered.  The new Node software, rewritten with Twisted, was released 
yesterday.

Terry J. Reedy





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


Re: Merging overlapping spans/ranges

2005-05-10 Thread Jordan Rastrick

Max M wrote:
> I am writing a "find-free-time" function for a calendar. There are a
lot
> of time spans with start end times, some overlapping, some not.
>
> To find the free time spans, I first need to convert the events into
a
> list of non overlapping time spans "meta-spans".
>
> This nice ascii graph should show what I mean.
>
> 1) ---
> 2) ---
> 3)   ---
> 4)  -
> 5) -
>
>  >> ---   # meta spans
>
> I can then iterate through the meta-spans and find non-busy times.
>
> I have written the class below, but it is rather O^2, so I wondered
if
> anybody has an idea for a better approach?
>
>
> ##
> # -*- coding: latin-1 -*-
>
> """
> 1) ---
> 2) ---
> 3)   ---
> 4)  -
> 5) -
>
>  >> ---  
> """
>
> class MetaSpans:
>
>  """
>  Populate with a list of span tuples [(start,end)], and it will
make
> "meta"
>  spans, with overlapping spans folded into one span.
>  """
>
>  def __init__(self):
>  self.spans = []
>
>  def add(self, span):
>  start, end = span
>  overlapping = [span]
>  non_overlapping = []
>  for spn in self.spans:
>  spn_start, spn_end = spn
>  # span rules for iterated spans
>  starts_before = spn_start <= start
>  ends_after = spn_end >= end
>  is_outside = starts_before and ends_after
>  starts_inside = start <= spn_start <= end
>  ends_inside =  start <= spn_end <= end
>  overlaps = starts_inside or ends_inside or is_outside
>  if overlaps:
>  overlapping.append(spn)
>  else:
>  non_overlapping.append(spn)
>  # overlapping spans are changed to one span
>  starts = []
>  ends = []
>  for start, end in overlapping:
>  starts.append(start)
>  ends.append(end)
>  min_start = min(starts)
>  max_end = max(ends)
>  non_overlapping.append( (min_start, max_end) )
>  self.spans = non_overlapping
>
>
>  def findFreeTime(self, duration):
>  self.spans.sort()
>
>
>
>
> if __name__ == '__main__':
>
>  ms = MetaSpans()
>  ms.add((0,3))
>  ms.add((4,7))
>  ms.add((2,5))
>  ms.add((9,14))
>  ms.add((12,17))
>  print ms.spans
>
>
>  from datetime import datetime
>  ms = MetaSpans()
>  ms.add((datetime(2005, 1, 1, 0, 0, 0), datetime(2005, 1, 1, 3,
0, 0)))
>  ms.add((datetime(2005, 1, 1, 4, 0, 0), datetime(2005, 1, 1, 7,
0, 0)))
>  ms.add((datetime(2005, 1, 1, 2, 0, 0), datetime(2005, 1, 1, 5,
0, 0)))
>  ms.add((datetime(2005, 1, 1, 9, 0, 0), datetime(2005, 1, 1, 14,
0, 0)))
>  ms.add((datetime(2005, 1, 1, 12, 0, 0), datetime(2005, 1, 1, 17,
0,
> 0)))
>  print ms.spans
>
>
>

I think the following code does what you want. It should be O(n log n)
- at least I hope thats what Python takes to sort the list of spans :)
Of course I've assumed you have the spans available to you all at once
as a list, and dont need to add them one at a time as you did in your
original code.

def get_metaspans(spans):
"""Given a list of span tuples [(start,end)], will generate all
meta spans, with overlapping spans folded into one span.
"""
spans.sort()
spans = iter(spans)
metaspan = spans.next()
for span in spans:
start, end = span
m_start, m_end = metaspan
if start > m_end:
yield metaspan
metaspan = span
elif end > m_end:
metaspan = (m_start, end)
# Need to yield the final metaspan once the span list is exhausted
yield metaspan

def get_breaks(metaspans):
"""Gets all the breaks in between a sequence of metaspans"""
metaspans = iter(metaspans)
_, prev_end = metaspans.next()
for metaspan in metaspans:
start, end = metaspan
yield (prev_end, start)
prev_end = end

I must admit I'm a bit of a generatoraholic, I'll tend to throw yields
at anything given half a chance :) Having to yield once more at the end
of the get_metaspans loop seems a little inelegant, maybe it could be
done a bit better. But its nice the way empty lists are handled
gracefully - the StopIteration thrown by the .next() calls are just
absorbed by the, uh, generatorness.

A little bit of testing:

>>> spans = [(12, 13), (0,3), (2,5), (1,4), (4,6), (1,2), (8,9), (9,
10)]
>>> print list(get_metaspans(spans))
[(0, 6), (8, 10), (12, 13)]
>>> print list(get_breaks(get_metaspans(spans)))
[(6, 8), (10, 12)]

Is that more or less what was required?

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


Re: Put a file on an ftp server over ssl

2005-05-10 Thread Jp Calderone
On 10 May 2005 09:55:32 -0700, Daniel Santa Cruz <[EMAIL PROTECTED]> wrote:
>Hello all!
>
>I have been troubled for the past couple of days trying to write a
>simple script that sends a file to an ftp server.  It used to be the
>easiest thing in the world, but now the server has changed to a ftps
>(ftp over ssl) server.  All of the sudden, the world has come to a
>crawling stop.
>
>Seems that M2Crypto would maybe do the trick, but I can't buy the thing
>(they won't pay for it).  Other than suggesting projects, does any one
>have actuall working code to do something like this?  My, it seems like
>it should be VERY simple, but it has become a nightmare.
>
>Oh do I wish...
>
>f = ftps.connect('username', 'password', port)
>ftps.put(localFilePath)
>
>Done!
>
>Thanks for any help!

  Twisted () has some rudamentary FTP support.  
It also has SSL support.  It will probably take a little effort on your part to 
get them to work together, but I'm sure it will be easier than coming up with 
your own FTP implementation or kludging the standard library's ftp support into 
working.

  Jp

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


Re: Python Graphing Utilities.

2005-05-10 Thread Bill Mill
On 5/10/05, Kenneth Miller <[EMAIL PROTECTED]> wrote:
> Hello All,
> 
> I am new to Python and i was wondering what graphing utlities would be
> available to me. I have already tried BLT and after weeks of unsuccesful
> installs i'd like to find something else. Anything someone would recommend?

matplotlib is awesome:

http://matplotlib.sourceforge.net/

and gnuplot.py is passable:

http://gnuplot-py.sourceforge.net/

(a better version of gnuplot.py is available with the excellent
ipython interpreter at http://ipython.scipy.org/)

All of the above are cross-platform to at least linux and windows.

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >