Re: how do you get the name of a dictionary?

2006-08-22 Thread Fredrik Lundh
Steven D'Aprano wrote:

> But an upside is that it would enable more useful error messages, at least
> sometimes. Here's some trivial pseudo-code:
> 
> def foo(a):
> assert len(a) > 10, "%s is too short" % a.__name__
> 
> y = "hello"
> foo(y)
> 
> would display "AssertionError: y is too short".

why not "a is too short" ?

or for that matter, "x is to short" ?



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


Re: Python and STL efficiency

2006-08-22 Thread Mc Osten
<[EMAIL PROTECTED]> wrote:

> That's to say,
> python is still much faster?

Yes it is. But of course you can't sat that "Python is faster than C++".
We found that the code to do this, written in the most natural way, is a
lot faster in Python. However, if you optimze the code, C++ gets almost
as fast.

In other benchmarks C++ outperforms Python and is 10 or 100 times
faster.


> Maybe someone can post this to the c++ maillist and they will tell how
> to accelerate it.

There are enough C++ experts here to do it. The point is another.

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-22 Thread Mc Osten
Ray <[EMAIL PROTECTED]> wrote:

> Not really, see my test, in my other post in the same thread. I'm using
> VC++ Express 2005. If we're comparing with Python 2.5 I think it's just
> fair that for C++ we're using the latest as well.

In your test, you are looping 1 times, we looped 100.
In Python tests with 1 elements, it was about 10 ms.

Moreover, we tried various Python and C++ configurations. Most of the
tests are done with Python 2.4, not 2.5.
And I used gcc4, that is to say the latest on my platform.
 
> Same here, although that said Python's implementation of those data
> structure must already be as optimal as mortals can do it. 

I think this is the rationale behind it.

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-22 Thread Mc Osten
Ray <[EMAIL PROTECTED]> wrote:

> I'm using VC++ Express, I didn't care to tweak the optimizations, I
> merely chose the "Release" configuration for the executable. It's
> blazing fast, taking only 30+ ms each run.

Of course it is faster. We are looping 100 times, you just 1.

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you get the name of a dictionary?

2006-08-22 Thread Georg Brandl
Steven D'Aprano wrote:
> On Tue, 22 Aug 2006 10:12:00 -0700, BartlebyScrivener wrote:
> 
 how difficult would it be to assign a string name(s)
 to an object upon creation (and upon referencing)?
>> 
>> Exactly the point that's being made. It's so easy just do it yourself:
>> 
>> banana={"name":"banana"}
>> 
>> Hey what is the name of my dictionary?
>> 
>> banana["name"]
>> 
>> But why build it into Python and force everyone else to do it, when
>> most of the time nobody cares what the name is, or they already know?
>> 
>> It's like forcing everybody everywhere always and forever to wear
>> "Hello My Name Is" tags.
> 
> On reflection, I'm wondering if we've been too harsh on Jojoba and not
> thought this through, simply because "that's the way it's always been".
> 
> Functions have a __name__ attribute. So do classes and modules. Why are
> these three objects "special" that they know the name they were created
> with, when other objects don't? Python doesn't attempt to track what name
> they are known at *now*, just the name they were born with.

Because they're not created by simple assignment, because they are
usually created once, because new names are bound to them rarely,
and because it's crucial to know their name in debugging, introspection etc.

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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Fredrik Lundh
jojoba wrote:

 no, you're just wasting a lot of bandwidth making it clear that you just
 cannot be bothered to learn how things actually work.
> 
> By the way, what exactly led you to this conclusion?

the fact that despite all attempts to explain how things work, you're 
still haven't realized that if you want the names of things, you should 
pass *namespaces* to your object viewer, not individual objects.



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


Re: Can I do this with list comprehension?

2006-08-22 Thread Ben Finney
[EMAIL PROTECTED] writes:

> Let's say I have two lists:
> 
> a = [0, 1, 0, 1, 1, 0]
> b = [2, 4, 6, 8, 10, 12]
> 
> I want a list comprehension that has the elements in b where a[element]
> == 1.
> 
> That's to say, in the example above, the result must be: [4, 8, 10]
> 
> Any hints?

What have you already tried, and how is it insufficient?

-- 
 \ "Unix is an operating system, OS/2 is half an operating system, |
  `\   Windows is a shell, and DOS is a boot partition virus."  -- |
_o__)  Peter H. Coffin |
Ben Finney

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


Re: Has anyone used py-xmlrpc?

2006-08-22 Thread Fredrik Lundh
David Hirschfield wrote:

> Searching for a python xmlrpc implementation that supports asynchronous 
> requests

if you have an asynchronous transport, using the builtin xmlrpclib 
module to pack and unpack the requests isn't that hard.

(see xmlrpclib.dumps and xmlrpclib.loads, respectively)



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


Embedding Python in an application plug-in ( .so )

2006-08-22 Thread bEngO
Dear all,When embedding we must link with the python library AND USE -rdynamic OR -Wl,-export-dynamic OR -Xlinker -export-dynamicto export ALL symbols from the Python library even if we do not use all of them.
This is needed when the embedded Python import modules to avoid undefined symbol errors.But it doesn't work when embedding Python into a plug-in ( .so ) for an application.I want to embed Python in a shared object which will be dynamically loaded by an application.
So when i build my share object, i link with the python library ( btw should i link with the .a or .so ? )and i use the flag to export all symbols and Python is accessible from the application when my share object is loaded.
But i can't import Python modules ( example: import socket ), i get some undefined symbols errors.I dont know exactly why.Is it because the rdynamic/export-dynamic flags have no effect when building a shared object ?
Or is it a problem with my compiler: GCC 4.1.0, Linux 2.6.17 ?Or is it because the application is loading my plug-in without the RTLD_GLOBAL flag ?Or what ?Please help :)I found some people having the same problem but no workaround...
Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: key not found in dictionary

2006-08-22 Thread Fredrik Lundh
Ben Finney wrote:

> In the specific use case of wanting a default value when a dictionary
> doesn't have a particular key, you can also use this:
> 
> >>> foo = {0: "spam", 1: "eggs", 7: "beans"}
> >>> for key in [1, 2, 7]:
> ... desc = foo.get(key, None)

usually spelled

  desc = foo.get(key) # returns None if not present

or

  desc = foo.get(key, default)

if you want something other than None.



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


Re: Can I do this with list comprehension?

2006-08-22 Thread Gabriel Genellina

At Wednesday 23/8/2006 01:07, [EMAIL PROTECTED] wrote:


a = [0, 1, 0, 1, 1, 0]
b = [2, 4, 6, 8, 10, 12]

I want a list comprehension that has the elements in b where a[element]
== 1.

That's to say, in the example above, the result must be: [4, 8, 10]


print [belem for aelem,belem in zip(a,b) if aelem==1]
print [belem for i,belem in enumerate(b) if a[i]==1]

Or itertools.izip...


Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: Can I do this with list comprehension?

2006-08-22 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:

> Let's say I have two lists:
> 
> a = [0, 1, 0, 1, 1, 0]
> b = [2, 4, 6, 8, 10, 12]
> 
> I want a list comprehension that has the elements in b where a[element]
> == 1.
> 
> That's to say, in the example above, the result must be: [4, 8, 10]
> 
> Any hints?

 >>> from itertools import izip
 >>> a = [0, 1, 0, 1, 1, 0]
 >>> b = [2, 4, 6, 8, 10, 12]
 >>> [y for x, y in izip(a, b) if x == 1]
[4, 8, 10]


-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Man is a hating rather than a loving animal.
-- Rebecca West
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I do this with list comprehension?

2006-08-22 Thread Cliff Wells
On Tue, 2006-08-22 at 21:07 -0700, [EMAIL PROTECTED] wrote:
> b = [2, 4, 6, 8, 10, 12]

>>> a = [0, 1, 0, 1, 1, 0]
>>> b = [2, 4, 6, 8, 10, 12]
>>> [ j for i, j in zip ( a, b ) if i ]
[4, 8, 10]


-- 

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


Can I do this with list comprehension?

2006-08-22 Thread barberomarcelo
Let's say I have two lists:

a = [0, 1, 0, 1, 1, 0]
b = [2, 4, 6, 8, 10, 12]

I want a list comprehension that has the elements in b where a[element]
== 1.

That's to say, in the example above, the result must be: [4, 8, 10]

Any hints?

Marcelo

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


Re: Python and STL efficiency

2006-08-22 Thread Ray
[EMAIL PROTECTED] wrote:
> That's to say,
> python is still much faster?

Not really, see my test, in my other post in the same thread. I'm using
VC++ Express 2005. If we're comparing with Python 2.5 I think it's just
fair that for C++ we're using the latest as well.

> I am a c++ newbie but I think c++ should be faster here.

Same here, although that said Python's implementation of those data
structure must already be as optimal as mortals can do it. 



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


Re: Python and STL efficiency

2006-08-22 Thread could . net
That's to say,
python is still much faster?

I am a c++ newbie but I think c++ should be faster here.
Maybe someone can post this to the c++ maillist and they will tell how
to accelerate it.
Tim N. van der Leeuw wrote:
> Mc Osten wrote:
> > Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> >
> > > Python's memory allocator is also quite fast, compared to most generic
> > > allocators...
> >
> > In fact also in the two "slow" versions Python outperforms C++.
> > I didn't notice it in the first place.
> >
> > --
> > blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
> > site:  http://www.akropolix.net/rik0/  | tenetevi riso e
> > forum: http://www.akropolix.net/forum/ | bacchette per voi.
>
> Well, I guess I'm getting really obsessed with this. But anyways. I
> installed MinGW on my Windows-XP (sp2) laptop. It is g++ version 3.4.5
> -- ancient, yes, but on windows it's the latest available.
>
> I compiled Mc Osten's C++ program (tweaked the output a little) and ran
> it; ran his version of the python code too.
> Oh boy; yes indeed the slow python is faster than the fast C++
> version... Must be something really awful happening in the STL
> implementation that comes with GCC 3.4!
>
> Here's the output from my console:
>
> [EMAIL PROTECTED] ~/My Documents/Python
> $ g++ -O3 -march=pentium-m -o SpeedTest SpeedTest.cpp
>
> [EMAIL PROTECTED] ~/My Documents/Python
> $ ./SpeedTest.py
> Begin Test
> Number of unique string objects: 4
> so long...
> What do you know
> fool
> chicken crosses road
> Number of unique string objects: 4
> so long...
> What do you know
> fool
> chicken crosses road
> Fast - Elapsed: 0.037574 seconds
> Slow - Elapsed: 0.081520 seconds
>
> [EMAIL PROTECTED] ~/My Documents/Python
> $ ./SpeedTest.exe
> Begin Test
> What do you know?
> chicken crosses road
> fool
> so long...
> What do you know?
> chicken crosses road
> fool
> so long...
> Fast - Elapsed: 2.089 seconds
> Slow - Elapsed: 6.303 seconds
>
> [EMAIL PROTECTED] ~/My Documents/Python
> 
> 
> Cheers,
> 
> --Tim

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


Re: swapping numeric items in a list

2006-08-22 Thread bearophileHUGS
Jiang Nutao:
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
> How to do it fast? My real list is huge.

Note that:

>>> a = range(6)
>>> a
[0, 1, 2, 3, 4, 5]
>>> a[::2]
[0, 2, 4]
>>> a[1::2]
[1, 3, 5]

So you can do:

>>> a[::2], a[1::2] = a[1::2], a[::2]
>>> a
[1, 0, 3, 2, 5, 4]

Bye,
bearophile

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


Re: What do you want in a new web framework?

2006-08-22 Thread John J. Lee
[EMAIL PROTECTED] writes:

> hardemr wrote:
> 
> > I've just read all of the answers. Most of yours said that there are
> > many web frameworks ,so it is nonsense to make a new web framework in
> > python.
> 
> Hardemr, I like Ajacksu's answer, with a twist. Please concnentrate on
> writing a Visual Studio-like gui designer, and make it possible to add
> your Visual Studio like gui designer to Django (and TurboGears, et al).
> 
> 
> Leverage the hard work of others and the installed base; add your
> functionality on top. Don't re-create the wheel, build your internal
> combustion engine powered vehicle on top of the 4 wheels that already
> exist! ;-))

pyjamas!

http://pyjamas.pyworks.org/


Now would be a fantastic time to muck in and do as UrsusMaximus
suggests -- nobody on the pyjamas project is yet talking about such
things, but it's obviously an area that could make you very popular if
done well ;-)


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


Re: key not found in dictionary

2006-08-22 Thread Simon Forman
> Or you can use the has_key() and test it first. For example
>
>   if foo.has_key('bar'):
>   print 'we have it'
>   else :
>   print 'we don't have bar.'
> 

Nowadays you can also say:

if 'bar' in foo:
# do something

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


Re: What are decorated functions?

2006-08-22 Thread Richard Jones
Gabriel Genellina wrote:
> At Tuesday 22/8/2006 17:19, Wolfgang Draxinger wrote:
>> I'm just reading the python language reference and came around
>> the term "decorated functions", but I have no idea, for what
>> they could be used.
> 
> A decorator takes a function/method/callable, "decorates" (modifies)
> it in a certain way, and returns it.

It's important to note here that decorators, using the @decorate syntax[1],
*can only decorate methods and functions*. That is, they must be followed
by either another @decorator or a "def" statement. Anything else will
result in a SyntaxError. For example:

>>> def test(callable): return callable
...
>>> @test
... def foo(): pass
...
>>> @test
... @test
... @test
... def foo(): pass
...
>>> @test
... class bar:
  File "", line 2
class bar:
^
SyntaxError: invalid syntax
>>> @test
... file
  File "", line 2
file
   ^
SyntaxError: invalid syntax
>>>

So you can't decorate classes (the original PEP proposed it, but it was
dropped - see the discussion about this on python-dev[2]). You *can*
decorate a class' __init__ method, but that's not quite the same as eg.
implementing @singleton (mind you, we already have a bazillion ways to
implement the singleton pattern, so I don't think we're poorer for this
limitation )


Richard

[1] of course, you can "anything = decorate(anything)"
[2] http://mail.python.org/pipermail/python-dev/2005-March/052369.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Editor with Autocorrection

2006-08-22 Thread John J. Lee
"Ravi Teja" <[EMAIL PROTECTED]> writes:
[...]
> Most good editors (Scintilla based editors, Emacs, Vi etc) have
> auto-completion for symbols that have occured in the current file; and

What I find really useful in emacs is completion based on *all* open
files (usually I have maybe twenty files open at once).


> some advanced IDEs (PyDev, WingIDE, SPE, Komodo etc) will auto-complete
> to some degree based on your imports through static analysis.

Pythonwin also does that, I'm told.  Emacs can do introspection-based
completion.  The support in emacs was a little clunky, and I found
dabbrev-expand much more useful anyway.


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


Re: key not found in dictionary

2006-08-22 Thread Ben Finney
"KraftDiner" <[EMAIL PROTECTED]> writes:

> I have a dictionary and sometime the lookup fails...
> it seems to raise an exception when this happens.
> What should I do to fix/catch this problem?
> 
> desc = self.numericDict[k][2]
> KeyError: 589824   < This is the error that is being produced,
> because there is no key
> 589824.

Others have suggested the general solution of using 'try ... except
Foo' for catching a particular exception and dealing with it.

In the specific use case of wanting a default value when a dictionary
doesn't have a particular key, you can also use this:

>>> foo = {0: "spam", 1: "eggs", 7: "beans"}
>>> for key in [1, 2, 7]:
... desc = foo.get(key, None)
... print repr(desc)
...
'eggs'
None
'beans'

A brief description is at 'help(dict.get)'.

-- 
 \ "The illiterate of the future will not be the person who cannot |
  `\ read. It will be the person who does not know how to learn."  |
_o__) -- Alvin Toffler |
Ben Finney

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


Re: swapping numeric items in a list

2006-08-22 Thread Simon Forman
Jiang Nutao wrote:
> Hi,
>
> I simplify my problem like below
>
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
>
> How to do it fast? My real list is huge.
>
> Thanks a lot.
> Jason

Here's simple and probably fast enough way (but it won't work right on
odd length lists):

def rev(n):
i = iter(n)
while True:
a = i.next()
yield i.next()
yield a


Example of use:

r = range(24)

print list(rev(r))

If your list comes from binary (str) data, and you're dealing with
endianness, I smell a faster way using struct.

Peace,
~Simon

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


Re: how do you get the name of a dictionary?

2006-08-22 Thread jojoba
thanks Steven!
that does help!
cheers,
jojoba
o(-_-)o

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


Re: swapping numeric items in a list

2006-08-22 Thread faulkner
for i in xrange(0, len(your_list), 2):
your_list[i], your_list[i + 1] = your_list[i + 1], your_list[i]


Jiang Nutao wrote:
> Hi,
>
> I simplify my problem like below
>
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
> 
> How to do it fast? My real list is huge.
> 
> Thanks a lot.
> Jason

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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Steven D'Aprano
On Tue, 22 Aug 2006 09:34:36 -0700, jojoba wrote:

> i don't want to do anything sophisticated with this, i am really only
> looking for a TITLE for my dictionary when i throw it in a tree editor
> that i have built. And i do realize that its not possible now. I am just
> pressing a point here.

Something like this might help.

def get_object_title(object, namespace=None):
"""Returns a possible title/name for object, in the given namespace."""
if namespace is None:
namespace = globals()
try:
return object.__name__ # works for functions, classes, modules
except AttributeError:
# search the namespace
for key,value in namespace.items():
if object is value: # do NOT use ==
return key
# not found in the namespace either
# maybe an unnamed object?
return "Object ID %d" % id(object)

Hope this helps.


-- 
Steven D'Aprano 

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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Steven D'Aprano
On Tue, 22 Aug 2006 10:12:00 -0700, BartlebyScrivener wrote:

>>> how difficult would it be to assign a string name(s)
>>> to an object upon creation (and upon referencing)?
> 
> Exactly the point that's being made. It's so easy just do it yourself:
> 
> banana={"name":"banana"}
> 
> Hey what is the name of my dictionary?
> 
> banana["name"]
> 
> But why build it into Python and force everyone else to do it, when
> most of the time nobody cares what the name is, or they already know?
> 
> It's like forcing everybody everywhere always and forever to wear
> "Hello My Name Is" tags.

On reflection, I'm wondering if we've been too harsh on Jojoba and not
thought this through, simply because "that's the way it's always been".

Functions have a __name__ attribute. So do classes and modules. Why are
these three objects "special" that they know the name they were created
with, when other objects don't? Python doesn't attempt to track what name
they are known at *now*, just the name they were born with.

The obvious downside of giving all objects a __name__ attribute is that it
will increase the size of all objects.

But an upside is that it would enable more useful error messages, at least
sometimes. Here's some trivial pseudo-code:

def foo(a):
assert len(a) > 10, "%s is too short" % a.__name__

y = "hello"
foo(y)

would display "AssertionError: y is too short".

Of course, this could lead to misleading messages too:

y = "hello"  # y.__name__ is "y"
# lots of code
z = y # z.__name__ is "y"
foo(z)

prints "AssertionError: y is too short", probably not helpful.

And what should foo("no name") do?

On balance, I think the benefit for giving all objects a __name__ is
minimal, and the costs significant. But it isn't a completely stupid idea,
since some objects do know the name they were created with, so there are
uses for it, sometimes.



-- 
Steven D'Aprano 

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


Re: What are decorated functions?

2006-08-22 Thread Gabriel Genellina

At Tuesday 22/8/2006 17:19, Wolfgang Draxinger wrote:


I'm just reading the python language reference and came around
the term "decorated functions", but I have no idea, for what
they could be used.


A decorator takes a function/method/callable, "decorates" (modifies) 
it in a certain way, and returns it.
@classmethod and @staticmethod are examples: they take a (normal) 
method, and transform it into another thing.
You can write your own decorators. An example similar to one 
discussed on this list a few days ago: suppose you have a pure 
function taking a long time to compute; you could save the results in 
a dictionary using the arguments as key, and retrieve them later when 
a call is made exactly with the same arguments. This is a known 
pattern ("memoize").


def memoized(function):
function.cache={}
def f(*args):
try: return function.cache[args]
except KeyError:
result = function.cache[args] = function(*args)
return result
return f

@memoized
def fibo(n):
time.sleep(2) # a sloow function
if n<2: return 1
return fibo(n-1)+fibo(n-2)

The original function is fibo() - it works OK but assume it's slow. 
So you "decorate" it with @memoized to improve performance.
(This is just an example, of course - I'm not saying memoizing is the 
right thing to do here, nor this is the best way to do it... just to 
demonstrate what a decorator could be used for)




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

swapping numeric items in a list

2006-08-22 Thread Jiang Nutao
Hi,

I simplify my problem like below

To convert list
aa = [0x12, 0x34, 0x56, 0x78]
into
[0x34, 0x12, 0x78, 0x56]

How to do it fast? My real list is huge.

Thanks a lot.
Jason 



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


Has anyone used py-xmlrpc?

2006-08-22 Thread David Hirschfield
Searching for a python xmlrpc implementation that supports asynchronous 
requests, I stumbled on this project:

http://www.xmlrpc.com/discuss/msgReader$1573

The author is Shilad Sen, and it appears to do what I'm looking for. But 
I'd love some feedback from anyone who might have used it before I go 
and base some server/client code on it.

Anyone out there have experience with this code? Is it as good/stable as 
python's standard xmlrpclib? Better?
Thanks in advance for any notes,
-Dave

-- 
Presenting:
mediocre nebula.

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


Re: What are decorated functions?

2006-08-22 Thread Wolfgang Draxinger
Daniel O'Brien wrote:

> How one actually makes use of decorators beyond the above is an
> exercise of imagination.

Now it rings a bell, thx.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: [EMAIL PROTECTED], ICQ: 134682867
GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Job Jar

2006-08-22 Thread ajaksu
Hi there Steve

D wrote:
> (...) Basically, I'd like to
> create a web-based "job jar", that users in my office can access in
> order to view, and "take ownership" of, misc. office tasks.

I've seen this kind of feature working in Trac [1], but what you really
want is task management software. Of the alternatives already
mentioned, roundup is IMHO the most interesting given your request.

Just yesterday I found  TaskJuggler[2] (can't remember how) but the
features sound like what you want.
*  Manages tasks, resources and costs
* Automatic resource leveling, tasks conflict resolutions, and task
filtering
* Project tracking and status reporting
* Flexible working hours and vacation handling

This is pretty much "what this kind of software does", not "what
taskjuggler does" :)
There are hundreds of task managers out there worth a check.

Just as examples of the diversity:
* I use Planner [3], which is stand-alone and not so feature-rich,
besides being too focused at central management IMHO. TaskCoach [4]
(wxPython-based) seems pretty similar.

* BaseCamp [5] is an online service, paid, new-ish and looks cool (has
Python bindings)

* dotProject [6] (PHP)  looked cool when I tried it... a couple of
years ago and before knowing any alternative

In Python, faces [7] is the best match I know for your request (take a
look at http://faces.homeip.net/examples.html). Tiny's Enterprise
Resource Planning [8] might be good for you too.

If you have time for that, consider evaluating some projects from:
Freshmeat Office/Scheduling: http://freshmeat.net/browse/130/
Freshmeat Office/Groupware: http://freshmeat.net/browse/917/
SF Office/Scheduling:
http://sourceforge.net/softwaremap/trove_list.php?form_cat=130
SF Project Management:
http://sourceforge.net/softwaremap/trove_list.php?form_cat=607

Wishing you to make a wise choice and enjoy it,
Daniel

[1] http://willbarton.com/code/tracgantt
[2] http://www.taskjuggler.org/
[3] http://live.gnome.org/Planner
[4] http://taskcoach.sourceforge.net
[5] http://www.basecamphq.com/
[6] http://www.dotproject.net/
[7] http://faces.homeip.net/
[8] http://tinyerp.com/

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


Re: Unclear on argument passing to "sendmail'

2006-08-22 Thread John Draper
I will respond to part of this, although it wasn't directed to me.

Tim Williams wrote:

> However it really depends on the use-case,   relaying through another
> server will give you no control over bad addresses,  you have to wait
> for bounces from the recipient's server,  or conversely the ISP server
> can give fails 4xx & 5xx for valid addresses.   The ISP may only
> accept email addressed from their local domains, and you may be
> breaking their TOCs or AUP and get blocked.

I usually will have no problem with this,  and for one reason is because
before I add a new ISP to my spam reporting queue, I establish a
direct SMTP connection with the ISP's "abuse" email server to confirm
the Email is good.  I get a lot more then my share of BAD or Bogus Emails
listed in some of these whois queries I get.

>
> On the flip side, some ISPs block outbound port 25 except through
> their servers, or transparent proxy port 25,  so Direct MX is
> unusable.

I send all of my spam reports through a commercial T1 link..  I made
the bad mistake of sending my spam reports directly from my ComCrap
(err - comcast) account, and my service got hosed for a day or so.

>> Hmmm - the problem I have is if I knowingly
>> put in a bad recipient,  and try to send to a
>> unknown user,  I get all appearances that
>> the mail went through.
>
>
> Yes this will happen if you use a relay server.

yea - I know  :-(

>
>> Ok,   so If I already have a MX hostname
>> of "mail.myhost.com",  then I would put
>> into my "to_email"...@myhost.com for
>
>
> Yes,  if you just used username the server wouldn't know which domain
> the email was being sent to and therefore how to route it.
>
>> By the way,  I'm sending this mail to a "sms"
>> gateway to a cellular provider, so the
>> username is their phone number.
>
>
> If you only ever send to this gateway then you might as well try MX
> records, you will have more control,  but you will need to manage
> queueing yourself for temporary failures,  or you may decide that if
> you get a temporary failure (4xx) to just fire the email off to your
> ISP server and let them deal with it.

I'm currently exploring a number of different options at this time,
including giving the customer an option to go back and re-visit their
order page and get an update in the event the message bounces.

I'm setting up a special "reply_to" address which I use to collect
bounces, and customer's asknowledgement they got the content.
Once I get the Ack from the customer,  I'll KNOW they got the product.

>
>
>> But
>> (sigh),  these providers don't appear
>> to tell me if I put in a bogus phone number.
>
>
> Unfortunately not all mail servers will fail an invalid address even
> if they aren't relaying the email.   

I haven't really run into a lot of them,  but I've had NO experience with
SMTP->SMS gateways.

> But in this case the SMS
> "gateway" is probably relaying to a backend system for the SMSc and
> will accept any address with a valid domain part. 

I already know that Sprint does this,  but (sigh) I don't even get the 
bounces if
I re-direct them to a specific Email box  DARN - Foiled again.

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


Re: Python and STL efficiency

2006-08-22 Thread Ray

Tim N. van der Leeuw wrote:
> Incidentally, I also have a version compiled with VC++ 6 now... (not
> yet w/VC++ 7) .. Compiled with release-flags and maximum optimization
> for speed, here's the result of VC++ 6:


OK, now I'm getting obsessed with this too ;-)

I'm using VC++ Express, I didn't care to tweak the optimizations, I
merely chose the "Release" configuration for the executable. It's
blazing fast, taking only 30+ ms each run.

Here's the code:

int main(){
DWORD begin = ::GetTickCount();
vector a;
string c = "What do you know?";
string d = "so long...";
string e = "chicken crosses road";
string f = "fool";
for (long int i=0; i<1 ; ++i){
a.push_back(c);
a.push_back(d);
a.push_back(e);
a.push_back(f);
}
set b(a.begin(), a.end());
unique_copy(b.begin(), b.end(), ostream_iterator(cout,
"\n"));
DWORD end = ::GetTickCount();
cout << "Ends in " << (end - begin) << " ms.";
}

And here's the result:

\TestSTL\release>TestSTL.exe
What do you know?
chicken crosses road
fool
so long...
Ends in 31 ms.

I tried the original version:

int main(){
DWORD begin = ::GetTickCount();
vector a;
for (long int i=0; i<1 ; ++i){
a.push_back("What do you know?");
a.push_back("so long...");
a.push_back("chicken crosses road");
a.push_back("fool");
}
set b(a.begin(), a.end());
unique_copy(b.begin(), b.end(), ostream_iterator(cout,
"\n"));
DWORD end = ::GetTickCount();
cout << "Ends in " << (end - begin) << " ms.";
}

And the result is only 50% slower:

\TestSTL\release>TestSTL.exe
What do you know?
chicken crosses road
fool
so long...
Ends in 47 ms.

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


Re: Python and STL efficiency

2006-08-22 Thread Mc Osten
Tim N. van der Leeuw <[EMAIL PROTECTED]> wrote:

> And the results of IronPython (1.0rc2) are just in as well:

I can't test this one.

>
> And for Python 2.5:
> [EMAIL PROTECTED] ~/My Documents/Python
> $ /cygdrive/c/Python25/python.exe SpeedTest.py
> Begin Test
> Number of unique string objects: 4
> so long...
> What do you know
> fool
> chicken crosses road
> Number of unique string objects: 40
> so long...
> What do you know
> fool
> chicken crosses road
> Fast - Elapsed: 0.440619 seconds
> Slow - Elapsed: 1.095341 seconds


What the heck... you have a Cray, haven't you?
$ /opt/misc/bin/python2.5 -O set_impl.py 
so long...
What do you know
fool
chicken crosses road
so long...
What do you know
fool
chicken crosses road
Elapsed: 1.30 seconds
Elapsed: 1.29 seconds

Yes... good optimizer work. The 'slow' code here is faster than the fast
one.


$ python -O set_impl.py 
so long...
What do you know
fool
chicken crosses road
so long...
What do you know
fool
chicken crosses road
Elapsed: 1.36 seconds
Elapsed: 3.80 seconds

> (Next step would be to create a VB version and a Java version of the
> same program, oh and perhaps to try a version that would work with
> Jython... perhaps somehow w/o the 'set')

Ok. I can do the Java version. If I find a RealBasic Set class I can do
it. However, I don't remember anything about VB6, and have done nothing
with .Net.
But I don't think it is that interesting. Java strings are immutable
too: I expect it to outperform Python (unless Java Set class sucks). And
I don't see the point of taking in VB.
A good BASIC implentation is comparable with Pascal or C++ speedwise.
(At least this results from Great Language Shootout and Free Basic). 

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-22 Thread Mc Osten
Tim N. van der Leeuw <[EMAIL PROTECTED]> wrote:

> My conclusion from that is, that the vector<> or set<> implementations
> of GCC are far superior to those of VC++ 6, but that memory allocation
> for GCC 3.4.5 (MinGW version) is far worse than that of MSCRT / VC++ 6.
> (And Python still smokes them both).

It would be interesting to test it with VC 8 (2005). I have it in my
Parallels vm, but it looks like something is wrong. The very same code
takes almost a minute, I suppose there is something wrong with it
(Python is almost as fast as the python 2.4 on MacOS).



-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-22 Thread Mc Osten
Tim N. van der Leeuw <[EMAIL PROTECTED]> wrote:

> NB: Your code now tests for address-equality. Does it also still test
> for string-equality? It looks to me that it does, but it's not quite
> clear to me.

It does it.

set b(a.begin(), a.end());
set c; // well ordered set (b is ordered by address)
for (set::iterator it=b.begin(); it!=b.end(); it++)
c.insert(**it);
copy(c.begin(), c.end(), ostream_iterator(cout, "\n"));

When we populate the first set, we get rid of all strings with same
object id/address (it test equality of pointers). Then we populate
another set (and the default equality test is on strings).

However, I would have written the code using a proper compare function
rather than using two sets. In this particular case the number of
elements of the first set is negligible in respect of the initial vector
size, thus copying it again does not take a lot of time.
But such code is optimized for the problem itself: in the real world I
suppose we would have passed set a proper comparison function that
checks address and then string equality.


-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are decorated functions?

2006-08-22 Thread Daniel O'Brien
PEP 318 provides some great examples:
http://www.python.org/dev/peps/pep-0318/

For more information no the decorator pattern in general:
http://en.wikipedia.org/wiki/Decorator_pattern

How one actually makes use of decorators beyond the above is an
exercise of imagination.

Wolfgang Draxinger wrote:
> I'm just reading the python language reference and came around
> the term "decorated functions", but I have no idea, for what
> they could be used.
>
> Any reply gracefully accepted.
>
> Wolfgang Draxinger
> --
> E-Mail address works, Jabber: [EMAIL PROTECTED], ICQ: 134682867
> GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E

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


RE: Newbie questions for Python usage

2006-08-22 Thread Caolan
Title: Re: Newbie questions for Python usage






Thanks 
Fred.
> just assign to the attribute and be done 
with>  it.  if you want to use a placeholder value, use 
None:
 
I thought I had tried that already but got an error. 
I'll try it again, and as for the 2nd one, I was hoping to avoid the usage of 
.cmd or .bat files altogether. Thanks!
 
-Caolan O'Domhnaill




From: 
[EMAIL PROTECTED] on behalf of Fredrik 
LundhSent: Tue 8/22/2006 4:08 PMTo: 
python-list@python.orgSubject: Re: Newbie questions for Python 
usage

Caolan wrote:>    1. I understand HOW 
to use the lambda operator, but WHY would 
you>   want to use it? Can anyone 
please give an example of WHY you 
would>   need it as opposed to just 
declaring a function either in the>   
local scope, or outside?you don't *need* it, 
because callback = lambda arg: 
_expression_is, for most practical purposes, the same thing 
as def 
callback(arg): return 
_expression_(the only difference is that the __name__ attribute for the 
functionobjects will differ; all lambdas are named "", while 
objectscreated by "def" have the original name.)however, in some 
cases, it's may be convenient to use the lambda form,for stylistic 
reasons.>    2. I would like to be able to declare as 
a member attribute a file>   object, 
however because there is no declaration of variable 
types>   like there is in C++, there 
doesn’t seem to be a way to do this>   
without first making a fobj = open(…) call. Is this true?not sure what 
you mean, really -- attributes are not typed, and there'sno way to "declare" 
them.  just assign to the attribute and be done withit.  if you 
want to use a placeholder value, use None: class 
foo: def 
__init__(self): 
self.file = None # not opened 
yet def open(self, 
name): 
self.file = open(name)or class 
foo: file = None # shared 
placeholder def 
__init__(self): 
pass def open(self, 
name): 
self.file = open(name)> Now for an os import question for Windows. I 
wish to automate the> builds of VS.NET 2005 and I can do so by executing 
the os.system(...)> command however I cannot see how to execute the 
vcvars32.cmd first to> set environment variables and then execute the 
actual command-line for> the build itself.there's no easy way to 
do that: environment variables set by a sub-process isn't available to the 
main process.the easiest way to do this might be to simply generate a 
short temporaryBAT-file for each command, and do os.system() on that 
file: f = open("temp.bat", 
"w") f.write("@call 
vcvars32.bat\n") f.write("cl 
...\n") f.close() 
os.system(f.name) 
os.remove(f.name)--http://mail.python.org/mailman/listinfo/python-list


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

Re: Newbie questions for Python usage

2006-08-22 Thread Fredrik Lundh
Caolan wrote:

>1. I understand HOW to use the lambda operator, but WHY would you
>   want to use it? Can anyone please give an example of WHY you would
>   need it as opposed to just declaring a function either in the
>   local scope, or outside?

you don't *need* it, because

 callback = lambda arg: expression

is, for most practical purposes, the same thing as

 def callback(arg):
 return expression

(the only difference is that the __name__ attribute for the function 
objects will differ; all lambdas are named "", while objects 
created by "def" have the original name.)

however, in some cases, it's may be convenient to use the lambda form, 
for stylistic reasons.

>2. I would like to be able to declare as a member attribute a file
>   object, however because there is no declaration of variable types
>   like there is in C++, there doesn’t seem to be a way to do this
>   without first making a fobj = open(…) call. Is this true?

not sure what you mean, really -- attributes are not typed, and there's 
no way to "declare" them.  just assign to the attribute and be done with 
it.  if you want to use a placeholder value, use None:

 class foo:
 def __init__(self):
 self.file = None # not opened yet
 def open(self, name):
 self.file = open(name)

or

 class foo:
 file = None # shared placeholder
 def __init__(self):
 pass
 def open(self, name):
 self.file = open(name)

> Now for an os import question for Windows. I wish to automate the
> builds of VS.NET 2005 and I can do so by executing the os.system(...)
> command however I cannot see how to execute the vcvars32.cmd first to
> set environment variables and then execute the actual command-line for
> the build itself.

there's no easy way to do that: environment variables set by a sub- 
process isn't available to the main process.

the easiest way to do this might be to simply generate a short temporary 
BAT-file for each command, and do os.system() on that file:

 f = open("temp.bat", "w")
 f.write("@call vcvars32.bat\n")
 f.write("cl ...\n")
 f.close()

 os.system(f.name)

 os.remove(f.name)



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


Re: Unclear on argument passing to "sendmail'

2006-08-22 Thread Tim Williams
On 22/08/06, Tim Roberts <[EMAIL PROTECTED]> wrote:
> John Draper <[EMAIL PROTECTED]> wrote:

Hi Tim :)

> Tim William's answer is not exactly correct.  The host you specify in the
> smtplib.SMTP constructor should NOT be the MX record for any of the
> recipients.  You should never have to look up MX records yourself.

actually, I said:
this will be a server from the recipient's domain's mx records (or
your ISP server).  :)

However it really depends on the use-case,   relaying through another
server will give you no control over bad addresses,  you have to wait
for bounces from the recipient's server,  or conversely the ISP server
can give fails 4xx & 5xx for valid addresses.   The ISP may only
accept email addressed from their local domains, and you may be
breaking their TOCs or AUP and get blocked.

On the flip side, some ISPs block outbound port 25 except through
their servers, or transparent proxy port 25,  so Direct MX is
unusable.

Blacklists are hit and miss, even large ISPs can get listed.  If you
are on a "clean" range then it shouldn't matter, you can look up your
IP on various blacklists to see if it is affected.  Also Many fixed IP
addresses don't have valid PTRs so they can fail as often as dynamic
IP addresses which usually do have valid PTRs

 John Draper <[EMAIL PROTECTED]> wrote:

> Hmmm - the problem I have is if I knowingly
> put in a bad recipient,  and try to send to a
> unknown user,  I get all appearances that
> the mail went through.

Yes this will happen if you use a relay server.

> Ok,   so If I already have a MX hostname
> of "mail.myhost.com",  then I would put
> into my "to_email"...@myhost.com for

Yes,  if you just used username the server wouldn't know which domain
the email was being sent to and therefore how to route it.

> By the way,  I'm sending this mail to a "sms"
> gateway to a cellular provider, so the
> username is their phone number.

If you only ever send to this gateway then you might as well try MX
records, you will have more control,  but you will need to manage
queueing yourself for temporary failures,  or you may decide that if
you get a temporary failure (4xx) to just fire the email off to your
ISP server and let them deal with it.


> But
> (sigh),  these providers don't appear
> to tell me if I put in a bogus phone number.

Unfortunately not all mail servers will fail an invalid address even
if they aren't relaying the email.   But in this case the SMS
"gateway" is probably relaying to a backend system for the SMSc and
will accept any address with a valid domain part.

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


Newbie questions for Python usage

2006-08-22 Thread Caolan
Hello,
 
I am fairly new to Python and after exploring the 
language some I have some questions:
 


  I understand HOW to 
  use the lambda operator, but WHY would you want to use it? Can anyone please 
  give an example of WHY you would need it as opposed to just declaring a 
  function either in the local scope, or outside? 
  I would like to be 
  able to declare as a member attribute a file object, however because there is 
  no declaration of variable types like there is in C++, there doesn’t seem to 
  be a way to do this without first making a fobj = open(…) call. Is this 
  true?
  Now for an os 
  import question for Windows. I wish to automate the builds of VS.NET 2005 and 
  I can do so by executing the os.system(...) command however I cannot see how 
  to execute the vcvars32.cmd first to set environment variables and then 
  execute the actual command-line for the build itself.

Thanks for the help all!
Caolan-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how do you get the name of a dictionary?

2006-08-22 Thread jojoba



> > Wow Fredrick! Are you serious?
>
> yes.
> 

Thank you for the clear answer.

> >> no, you're just wasting a lot of bandwidth making it clear that you just
> >> cannot be bothered to learn how things actually work.

By the way, what exactly led you to this conclusion?

jojoba

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


Re: Can, and if yes how could this be done elegant?

2006-08-22 Thread Carl Banks
Wolfgang Draxinger wrote:
> I'm currently developing vegetation creation scripts for the
> Blender 3D modelling software. The first attempts work nice, but
> they're far to inflexible IMHO.
>
> First let me introduce how the system works: The user supplies a
> series of building elements of the plants to be generated (e.g.
> stem, stipe, leaf, branches, blossom) and associated those with
> template 3D models. For each of those elements there is a list,
> which elements can be attached with the current element, and a
> probability function, that takes the various parameters for the
> element to be constructed (distance to the last branch, distance
> to the root, thickness of the last stipe, how much light is
> there). Then a pseudo random generator chooses one of the given
> elements with the given probability, the element is aligned to
> various physical conditions (gravity, light direction). It is
> important, that the tree is constructed with a equal distance to
> the root, i.e. not whole branches and subbranches at a time, but
> first branching level 0, then level 1 and so on. The reason is,
> that with every construction level some of the environment
> condictions (weight of the material, amount of light) change, so
> it's reasonable, that the grow process of the virtual plant
> resembles the real one, even if it's a simplified modell.
>
> Now one cool thing would be, if one could use python to describe
> the plant model itself, too.
>
> Since the Elements are not to be instanciated, but a collection
> of parameters and functions that are fed with the environment
> variables.
>
> class Branch(BasicPlantElement):
> def p():
> return light_scale * light()**light_exponent *
> k/distance_to_root()
> def geom():
> return (light_track * light_vector() - weight() * gravity(),
> position())
>
> But obviously this is not valid python (it lacks the self
> argument). One might now think of a dictionary
>
> Branch = { "p"=lambda:..., "geom"=lambda:..., }
>
> If you look closely, you also see, that the functions are not
> prameterized. Instead, they use some global scope functions.
> Here the idea is, that the environment parameters are put on a
> stack and each recursion copies the topmost element on the stack
> and changes happening there are carried on the stack. But this
> is of course very memory consuming. But the real problem is, to
> bring those values somehow into the scope of the PED (Plant
> Element Descriptor)
>
> Now the challenge:
> - I'd like to write the Plant Element Descriptors in a
> class/member like notation, but don't instanciate it - not
> directly at least. Eventually there will be factory functions,
> that take a PED and create a reparameterized version of it.
> - Calling the functions in the PED somehow needs to bring the
> branching stack into the scope. I have no idea how to do that.
>
> Of course all this might not be possible directly, but that would
> then mean, that I can't use python to describe plants, but have
> to invent a custom language for that then. (Something like POV
> Scene Description Language or similair).

Let me see if I understand:

You have a bunch of physical parameters (gravity, light
direction,etc.).

Every time you recurse to a deeper level, all these physical parameters
change (I suppose because there's a transformation of coordinates).
When creating a new Branch, using some data called Element as a kind of
template, you want to first update the parameters to their new values,
then use those parameters  to create a new Branch.  And you hope that
you can do both things (update parameters, generate branch) with a
single class.  How close am I?

You're doing this recursively, so there's really no way to get rid of
the stack entirely.  I don't know much about your code, but I quite
doubt that it would put much strain your memory at all.

We can, perhaps, help you organize your code better, though.  But I
think you'll need to make another pass at describing your problem.


Carl Banks

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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Fredrik Lundh
jojoba wrote:

>> no, you're just wasting a lot of bandwidth making it clear that you just
>> cannot be bothered to learn how things actually work.
> 
> Wow Fredrick! Are you serious?

yes.



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


Re: how do you get the name of a dictionary?

2006-08-22 Thread jojoba

> > I know i must be driving python purists to their limits...

> no, you're just wasting a lot of bandwidth making it clear that you just
> cannot be bothered to learn how things actually work.


Wow Fredrick! Are you serious? Hey man, come on.I got lambasted on this
topic from the beginning. Everyone keeps saying i dont know what im
talking about, but no one actually gives me a reason why. Every counter
argument i gave was either shrugged off or followed up with a "no,
that's wrong" statement.  Also, why are my PYTHON QUESTIONS wasting
bandwidth, while yours and others RIDICULING STATEMENTS not?

> do you behave this way in real life too, or is it just something you're
> doing on the internet ?

You sure you wanna go there.  I have great respect for you and all you
have done for python. I use your modules often (thank you!).  But im
not sure why my persistence on a this topic means i refuse to learn how
python really works.
If you dont agree with me, fine, PROVE your answerforget about
links.
Tell me what you know or dont know, but please dont mock me.
What is this grade school?
As a community, we can choose to share or not.
We should not bicker, or chide the ignorant (such as myself on this
matter).
Of course i try to learn how python works, just as i am sure you do to.
We all have different levels of expertise (or lack of).
Im just trying to learn man.
Im not asking for a spoon feeding either.
Im just trying to get CLEAR information from people about this "issue"
but that has actually been quite difficult.
And yes, i do inquire about things i dont understand in real life. And
in fact, if i dont get a reasonable, sufficient answer, i will press
the other side until a CLEAR argument sways me one way or the other
(sorry if that bothers you) Thats one of my strong suits. In fact, its
what led me to study and pursue science.
But i digress.
Please be nice to me, thats all im asking.
I will try to be more concise and do "more" research before bothering
others with apparent inadequecies.
Thanks,
jojoba

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


Re: What do you want in a new web framework?

2006-08-22 Thread Cliff Wells
On Tue, 2006-08-22 at 08:15 +, Tim Roberts wrote:

> Ordinarily, I think the "do it yourself" nature of Python is a great thing,
> and I would never try to dissuade someone from reinventing something
> themselves.  However, in the case of web frameworks, I believe Marc is
> fundamentally correct: the web framework proliferation in Python is
> actually doing the language a huge disservice.

I disagree.  Even if most of the frameworks end up being nothing more
than research artifacts, the fact is they embody research.  Without
research the Python web framework space will be forever relegated to
runner-up (and probably has-been at some point).

> Consider Ruby.  If someone asks, "I'd like to do a web site with Ruby, what
> should I use?", the answer comes back loud, clear, and unanimous: Ruby on
> Rails.  

Or Wee. Or Nitro. Or Nemo. Or others that are surely to be written as
Ruby gains acceptance and experienced users capable of writing them.

> If someone asks, "I'd like to do a web site with Python, what
> should I use?", she gets 25 different answers.  "Look at HTMLGen, Cheetah,
> WebWare, CherryPy, Karrigell, Django, Pylons, Plone, Zope, TurboGears,
> etc., etc.", none of which are pre-installed in the typical Linux
> distribution.  To the non-programming decision maker, that kind of response
> makes Python look unprofessional -- a toy.

Ruby on Rails doesn't come preinstalled either.  I don't think it's
appropriate (and apparently most Linux distros currently agree) to
install web programming frameworks by default.

I will add that at least a few distros offer TurboGears, Django and
Pylons as add-ons.

> Now, please do not send me ugly emails accusing me of running down Python.
> I've been a Python believer since 1.52.  I've done web sites in at least 5
> of the frameworks, and I even wrote one of the wiki pages that compares web
> frameworks.  However, it is only the fact that I *AM* a true Python
> believer that gave me the patience and incentive to try 5 different
> frameworks.  If a corporate decision maker were involved, that would never
> happen.  Python would simply fall off of the list of options, and the job
> would get done in PHP or Ruby on Rails.

Yes, because PHP has only one web framework too ;-)

> I agree with Marc.  PLEASE do not create "yet another Python web
> framework."  Let's pick one, and join together to turn it into the One,
> True, Unquestioned Web Solution.

Yes, and for those of us who may not like your choice, we can move to
another language or write our own, so nothing will have changed.

I think the entire concept that Ruby on Rails is successful because it
happens to be the dominant solution on what was previously a practically
unknown language is just plain ridiculous. If that's the case then why
hasn't Eiffel taken over the world?  Or Lua?  Or Io?

No, the reason Rails is successful is due to being a decent, focused
product with *great* marketing (screencasts, anyone?).

We've had several good Python web frameworks for some time, but
practically zero marketing (except for Zope/Plone, which as it turns
out, weren't such great products, at least not for the "80% solution"
that Rails targets).  

Also the fact that Ruby doesn't suck isn't hurting Rails any either.  If
GvR wants to improve Python's status against Ruby, I suggest looking at
what people are *really* raving about in the Ruby world (despite how
they got there) and address those issues rather than getting sidetracked
with this nonsense.  


Regards,
Cliff
-- 

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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Fredrik Lundh
jojoba wrote:

> I know i must be driving python purists to their limits...

no, you're just wasting a lot of bandwidth making it clear that you just 
cannot be bothered to learn how things actually work.

do you behave this way in real life too, or is it just something you're 
doing on the internet ?



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


Re: Python and STL efficiency

2006-08-22 Thread Tim N. van der Leeuw

Maric Michaud wrote:
> Le mardi 22 août 2006 12:55, Mc Osten a écrit :
> > In fact Python here is faster. Suppose it has a really optimized set
> > class...
>
> Maybe I'm missing something but the posted c++codes are not equivalent IMO to
> what python is doing. I discarded the "slow" version, and tried to get the
> equivalent in c++ of :
>

Your C++ version got me the following timings (using gcc 3.4.5 as the
compiler, MinGW version, with -O6):

[EMAIL PROTECTED] ~/My Documents/Python
$ ./testcpp.exe
print_occurence_of_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings_compared_by_address
What do you know?
chicken crosses road
fool
so long...
strings : 2.135
unique strings : 1.103
compared by address : 0.21


For reference, Python's best time was 0.39 seconds on the same computer
(in the 'fast' version, using only 4 unique string instances).

Hmmm... Can we conclude now that carefully crafted C++ code is about
twice as fast as casually and intuitively written Python code? ;) (Just
kidding here of course)

NB: Your code now tests for address-equality. Does it also still test
for string-equality? It looks to me that it does, but it's not quite
clear to me.

Cheers,

--Tim

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


Re: Python and STL efficiency

2006-08-22 Thread Fredrik Lundh
Maric Michaud wrote:

> The problem here, is that the strings in the set are compared by value, which 
> is not optimal, and I guess python compare them by adress ("s*n is s*n" has 
> the same complexity than "s*n == s*n" in CPython, right ?).

wrong.

 > timeit -s"s='x'; n=1000" "s*n is n*s"
100 loops, best of 3: 1.9 usec per loop

 > timeit -s"s='x'; n=1000" "s*n == n*s"
10 loops, best of 3: 4.5 usec per loop



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


Re: how do you get the name of a dictionary?

2006-08-22 Thread jojoba

> How do you take "any" dictionary?  Don't you have to know a name to refer
> to it?  Just pass this very name as additional argument to your tree
> viewer.

I know i must be driving python purists to their limits...but

I'm not sure how to dynamically pass the name of the dictionary without
hard coding it.

> You have to attach a name to a dict every time it's assigned to a name and
> delete a name from the dictionary every time such a name is deleted or
> rebound to some other object.  And all this is unnecessary extra work and
> memory consumption in 99.99% of most programs.

But this is 2006, and my computer can do 50 googlillion computations a
second.
So what does attaching or removing a title matter to my computer. What
searching has to happen?  I know where the dictionary reference points,
so i have immediate accesss to that data structure, don't I?  Please
excuse me if i am way oversimplifying.
Also, i am sure there are many computations going on in any python
program, that technically, might not be needed for that program per se,
but that doesn't invalidate those computations' presence in general.

 > And why do you want to special case dictionaries?  If Python is
doing it
> for dictionaries, sooner or later someone will ask for the names of lists
> or any arbitrary object.

Good question. Indeed I am not limiting this to dicitonaries, as other
data types, lists, tuples, etc. could use this as well.


jojoba

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


Re: Python and STL efficiency

2006-08-22 Thread Tim N. van der Leeuw

[EMAIL PROTECTED] wrote:
> Tim> But beware! For Python2.5 I had to change the code slightly,
> Tim> because it already realized that the expression
>
> Tim> '%s' % 'something'
>
> Tim> will be a constant expression, and evaluates it once only... so I
> Tim> had to replace '%s' with a variable, and I got the timings above
> Tim> which show Python2.5 to be slightly faster than Python2.4.
>
> Shouldn't you then get rid of any compiler optimizations your C++ compiler
> does?  Why penalize 2.5 because it recognizes a useful optimization?
>
The point is that I was trying to create 400.000 string instances. The
extra optimization in 2.5 required an extra trick for that.
The idea is to compare a C++ version which creates 400.000 string
instances, with a Python version which creates 400.000 string
instances; then reduce those 400.000 instances to a set of only 4
unique strings.
(So I cannot just create a list with strings generated from numbers 1 -
400.000, and I didn't want to change the original code too much, so I
just added a trick to make Python allocate a new string each time
round.)

I agree that Python2.5 recognized a useful optimization, and didn't
wish to penalize it for that, however the optimalization was defeating
the purpose of my code in the first place!

Cheers,

--Tim

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


Pure Python Oracle module

2006-08-22 Thread Ellinghaus, Lance
Title: Pure Python Oracle module






Does anyone know of a pure Python module for Oracle similar to Java's pure Oracle module?


Thank you!

Lance Ellinghaus




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

Can, and if yes how could this be done elegant?

2006-08-22 Thread Wolfgang Draxinger
I'm currently developing vegetation creation scripts for the
Blender 3D modelling software. The first attempts work nice, but
they're far to inflexible IMHO.

First let me introduce how the system works: The user supplies a
series of building elements of the plants to be generated (e.g.
stem, stipe, leaf, branches, blossom) and associated those with
template 3D models. For each of those elements there is a list,
which elements can be attached with the current element, and a
probability function, that takes the various parameters for the
element to be constructed (distance to the last branch, distance
to the root, thickness of the last stipe, how much light is
there). Then a pseudo random generator chooses one of the given
elements with the given probability, the element is aligned to
various physical conditions (gravity, light direction). It is
important, that the tree is constructed with a equal distance to
the root, i.e. not whole branches and subbranches at a time, but
first branching level 0, then level 1 and so on. The reason is,
that with every construction level some of the environment
condictions (weight of the material, amount of light) change, so
it's reasonable, that the grow process of the virtual plant
resembles the real one, even if it's a simplified modell.

Now one cool thing would be, if one could use python to describe
the plant model itself, too.

Since the Elements are not to be instanciated, but a collection
of parameters and functions that are fed with the environment
variables.

class Branch(BasicPlantElement):
def p():
return light_scale * light()**light_exponent *
k/distance_to_root()
def geom():
return (light_track * light_vector() - weight() * gravity(),
position())

But obviously this is not valid python (it lacks the self
argument). One might now think of a dictionary

Branch = { "p"=lambda:..., "geom"=lambda:..., }

If you look closely, you also see, that the functions are not
prameterized. Instead, they use some global scope functions.
Here the idea is, that the environment parameters are put on a
stack and each recursion copies the topmost element on the stack
and changes happening there are carried on the stack. But this
is of course very memory consuming. But the real problem is, to
bring those values somehow into the scope of the PED (Plant
Element Descriptor)

Now the challenge:
- I'd like to write the Plant Element Descriptors in a
class/member like notation, but don't instanciate it - not
directly at least. Eventually there will be factory functions,
that take a PED and create a reparameterized version of it.
- Calling the functions in the PED somehow needs to bring the
branching stack into the scope. I have no idea how to do that.

Of course all this might not be possible directly, but that would
then mean, that I can't use python to describe plants, but have
to invent a custom language for that then. (Something like POV
Scene Description Language or similair).

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: [EMAIL PROTECTED], ICQ: 134682867
GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E

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


What are decorated functions?

2006-08-22 Thread Wolfgang Draxinger
I'm just reading the python language reference and came around
the term "decorated functions", but I have no idea, for what
they could be used.

Any reply gracefully accepted.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: [EMAIL PROTECTED], ICQ: 134682867
GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-22 Thread Maric Michaud
Le mardi 22 août 2006 12:55, Mc Osten a écrit :
> In fact Python here is faster. Suppose it has a really optimized set
> class...

Maybe I'm missing something but the posted c++codes are not equivalent IMO to 
what python is doing. I discarded the "slow" version, and tried to get the 
equivalent in c++ of :

"""
#!/usr/bin/env python

size = 100

def f():
a = []
for i in range(size):
a.append('What do you know')
a.append('so long...')
a.append('chicken crosses road')
a.append('fool')
b = set(a)
for s in b:
print s

import time
from time import clock

f_start = clock()
f()
f_end   = clock()

print "Elapsed: %f seconds" % (f_end - f_start)
"""

I came at first with the following, which is still slower than the python 
version :

"""
void print_occurence_of_unique_strings(){
 vector a;
 const string& s1= "What do you know?"  ;
 const string& s2= "so long..." ;
 const string& s3= "chicken crosses road";
 const string& s4= "fool";
for (long int i=0; i b(a.begin(), a.end());
copy(b.begin(), b.end(), 
ostream_iterator(cout, "\n"));
}
"""

Here, all strings, while passed by reference to the vector, are copied one by 
one.
Then, I tried this, it just overcome the performance of python code, but not 
in the proportion I expected :

"""
void print_occurence_of_unique_strings_compare_by_adresses(){
vector a;
string s1 = "What do you know?";
string s2 = "so long...";
string s3 = "chicken crosses road";
string s4 = "fool";
for (long int i=0; i b;
for (vector::iterator it=a.begin(); it!=a.end(); it++)
b.insert(**it);
copy(b.begin(), b.end(), ostream_iterator(cout, "\n"));
}
"""

The problem here, is that the strings in the set are compared by value, which 
is not optimal, and I guess python compare them by adress ("s*n is s*n" has 
the same complexity than "s*n == s*n" in CPython, right ?).

so, finally, the code in c++, about ten times faster than the equivalent in 
python, must be :

"""
void print_occurence_of_unique_strings_compared_by_address(){
cout << "print_occurence_of_unique_strings_compared_by_address" << endl;
vector a;
string s1 = "What do you know?";
string s2 = "so long...";
string s3 = "chicken crosses road";
string s4 = "fool";
for (long int i=0; i b(a.begin(), a.end());
set c; // well ordered set (b is ordered by address)
for (set::iterator it=b.begin(); it!=b.end(); it++)
c.insert(**it);
copy(c.begin(), c.end(), ostream_iterator(cout, "\n"));
}
"""

the result on my box is :

[EMAIL PROTECTED] mar aoû 22 22:24:23:~$ g++ -O3  -o testcpp testcpp.cpp
[EMAIL PROTECTED] mar aoû 22 22:24:29:~$ ./testcpp
print_occurence_of_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings_compared_by_address
What do you know?
chicken crosses road
fool
so long...
strings : 1.89
unique strings : 0.87
compared by address : 0.18
[EMAIL PROTECTED] mar aoû 22 22:24:38:~$ python2.4 testpython.py
so long...
What do you know
fool
chicken crosses road
Elapsed: 1.68 seconds
[EMAIL PROTECTED] mar aoû 22 22:24:51:~$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured 
with: ../src/configure -v 
--enable-languages=c,c++,java,fortran,objc,obj-c++,ada,treelang --prefix=/usr 
--enable-shared --with-system-zlib --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix --enable-nls 
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo 
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/jre --enable-mpfr 
--with-tune=i686 --enable-checking=release 
i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20060613 (prerelease) (Debian 4.1.1-5)

I've joined the full c++ file as an attachment.

-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

#define SIZE 100

void print_occurence_of_strings(){
cout << "print_occurence_of_strings" << endl;
vector a;
const string& s1 = "What do you know?";
const string& s2 = "so long...";
const string& s3 = "chicken crosses road";
const string& s4 = "fool";
for (long int i=0; i b(a.begin(), a.end());
copy(b.begin(), b.end(), ostream_iterator(cout, "\n"));
}
void print_occurence_of_unique_strings(){
cout << "print_occurence_of_unique_strings" << endl;
vector a;
string s1 = "What do you know?";
string s2 = "so long...";
string s3 = "chicken crosses road";
string s4 = "fool";
for 

Re: Python and STL efficiency

2006-08-22 Thread skip

Tim> But beware! For Python2.5 I had to change the code slightly,
Tim> because it already realized that the expression

Tim> '%s' % 'something'

Tim> will be a constant expression, and evaluates it once only... so I
Tim> had to replace '%s' with a variable, and I got the timings above
Tim> which show Python2.5 to be slightly faster than Python2.4.

Shouldn't you then get rid of any compiler optimizations your C++ compiler
does?  Why penalize 2.5 because it recognizes a useful optimization?

Tim> (Next step would be to create a VB version and a Java version of
Tim> the same program, oh and perhaps to try a version that would work
Tim> with Jython... perhaps somehow w/o the 'set')

I don't recall the example exactly, but couldn't you just create a set class
that uses a dict under the covers and only implement the methods you need
for the test?

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


Re: Python and STL efficiency

2006-08-22 Thread Tim N. van der Leeuw

Tim N. van der Leeuw wrote:
> Mc Osten wrote:
> > Tim N. van der Leeuw <[EMAIL PROTECTED]> wrote:
> >
> > > Oh boy; yes indeed the slow python is faster than the fast C++
> > > version... Must be something really awful happening in the STL
> > > implementation that comes with GCC 3.4!
> >
> > And the Python version does the very same number of iterations than the
> > C++ one? I suppose they are looping on arrays of different sizes, just
> > like my "first version".
> >
>
> Hmmm.. You're quite right. The C++ version had an array size 100.000
> (your version), the Python version still had an array size 10.000 (as
> in my modified copy of the original version).
>
> When fixing the Python version to have 100.000 items, like the C++
> version, the Python timings are:
>
[...]
> Fast - Elapsed: 0.512088 seconds
> Slow - Elapsed: 1.139370 seconds
>
> Still twice as fast as the fastest GCC 3.4.5 compiled version!
>
> Incidentally, I also have a version compiled with VC++ 6 now... (not
> yet w/VC++ 7) .. Compiled with release-flags and maximum optimization
> for speed, here's the result of VC++ 6:
>
> [EMAIL PROTECTED] ~/My Documents/Python
> $ ./SpeedTest_VC.exe
[...]
> Fast - Elapsed: 4.481 seconds
> Slow - Elapsed: 4.842 seconds
>
[...]

And the results of IronPython (1.0rc2) are just in as well:

IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>>
>>> import sys
>>> sys.path.append('c:/documents and settings/leeuwt/my documents/python')
>>> import SpeedTest
>>> SpeedTest.run_test()
Begin Test
Number of unique string objects: 4
What do you know
so long...
chicken crosses road
fool
Number of unique string objects: 40
What do you know
so long...
chicken crosses road
fool
Fast - Elapsed: 1.287923 seconds
Slow - Elapsed: 4.516272 seconds
>>>


And for Python 2.5:
[EMAIL PROTECTED] ~/My Documents/Python
$ /cygdrive/c/Python25/python.exe SpeedTest.py
Begin Test
Number of unique string objects: 4
so long...
What do you know
fool
chicken crosses road
Number of unique string objects: 40
so long...
What do you know
fool
chicken crosses road
Fast - Elapsed: 0.440619 seconds
Slow - Elapsed: 1.095341 seconds

[EMAIL PROTECTED] ~/My Documents/Python

But beware! For Python2.5 I had to change the code slightly, because it
already realized that the expression

'%s' % 'something'

will be a constant expression, and evaluates it once only... so I had
to replace '%s' with a variable, and I got the timings above which show
Python2.5 to be slightly faster than Python2.4.

(Next step would be to create a VB version and a Java version of the
same program, oh and perhaps to try a version that would work with
Jython... perhaps somehow w/o the 'set')

Cheers,

--Tim

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


Re: https on ActiveState Python 2.4?

2006-08-22 Thread Jack
Thanks Dennis and Fredrik. This actualy works! I just copyed _socket.pyd and 
_ssl.pyd
from regular Python 2.4.3 into the DLLs directory of the ActiveState Python 
installation.
urllib2.urlopen() starts working for https links :)

I copied ssleay32.dll and libeay32.dll earlier.

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Jack wrote:
>> Thanks for the reply.
>>
>> I found some openSSL patches for earlier versions of ActiveState Python.
>> It involves .pyd files and they look for earlier versions of Python DLLs 
>> and don't run on ActiveState Python 2.4. I suspect the regular Python 
>> solution would
>> have the same problem or even more problems because it's not a pure .py
>> patch.
>
> huh?  the "regular Python solution" ships with a perfectly working SSL 
> library (in DLLs/_ssl.pyd), which look for the appropriate version of the 
> Python DLL:
>
> > dumpbin /imports "\python24\DLLs\_ssl.pyd"
> Microsoft (R) COFF Binary File Dumper Version 6.00.8168
> Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
>
> Dump of file \python24\DLLs\_ssl.pyd
>
> File Type: DLL
>
>   Section contains the following imports:
>
> WSOCK32.dll
> ...
> python24.dll
> ...
>
> (what's the point in using ActiveState's crippled distribution if you need 
> stuff that's shipped with the standard distro, btw?  why not just use the 
> standard version, and install win32all on top of that?)
>
> 
> 


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


Re: how do you get the name of a dictionary?

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

> Aha.
> my problem, (which as i said before, is not really an important
> problem) is to take any dictionary and load it into a tree viewer AND
> get the name(s) of that dictionary (if they exist, and if not, so be
> it).

How do you take "any" dictionary?  Don't you have to know a name to refer
to it?  Just pass this very name as additional argument to your tree
viewer.

> I know i am harping on this, but no one of yet has really proven why
> having such a feature would seriously affect python speed.
> Any ideas?

You have to attach a name to a dict every time it's assigned to a name and
delete a name from the dictionary every time such a name is deleted or
rebound to some other object.  And all this is unnecessary extra work and
memory consumption in 99.99% of most programs.

And why do you want to special case dictionaries?  If Python is doing it
for dictionaries, sooner or later someone will ask for the names of lists
or any arbitrary object.

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


Re: radio buttons in curses

2006-08-22 Thread Fabian Braennstroem
Sorry, me again...
Does nobody have an idea or is it to stupid?

* Fabian Braennstroem <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I want to add some radio and check buttons to my curses
> script. As I understand it, there are no buttons in the
> 'basic' curses module. Now, I found the curses-extra module,
> but I not able to download and install it.
>
> Does anybody have an idea, where I can download the module
> or, even better, how I can create radio and check buttons
> with the 'ordinary' curses module? Would be nice...
>
> Greetings!
>  Fabian
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>

Greetings!
 Fabian

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


Re: key not found in dictionary

2006-08-22 Thread Pierre Quentel
Depending on what you want to do if the key doesn't exist, you might
want to use the dictionary method get() :

value = some_dict.get(key,default)

sets value to some_dict[key] if the key exists, and to default
otherwise

Regards,
Pierre

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


Re: key not found in dictionary

2006-08-22 Thread Philippe Martin
KraftDiner wrote:

> I have a dictionary and sometime the lookup fails...
> it seems to raise an exception when this happens.
> What should I do to fix/catch this problem?
> 
> desc = self.numericDict[k][2]
> KeyError: 589824   < This is the error that is being produced,
> because there is no key
> 589824.

If you agree that the key is not there, then just catch the exception
(try ... except)

Philippe

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


Re: Job Jar

2006-08-22 Thread Gabriel Genellina

At Tuesday 22/8/2006 15:47, D wrote:


Thanks, Fredrik - but could I adapt them so that, instead of using them
for bug tracking (don't need version control, etc.), they're just used
for keeping track of simple tasks?


Roundup  is generic enough to be 
used for almost anything...

It has nothing to do with version control.



Gabriel Genellina
Softlab SRL 




p5.vert.ukl.yahoo.com uncompressed Tue Aug 22 18:27:05 GMT 2006 
	


__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: key not found in dictionary

2006-08-22 Thread Chaz Ginger
KraftDiner wrote:
> I have a dictionary and sometime the lookup fails...
> it seems to raise an exception when this happens.
> What should I do to fix/catch this problem?
> 
> desc = self.numericDict[k][2]
> KeyError: 589824   < This is the error that is being produced,
> because there is no key
> 589824.
> 

As stated you can wrap the access in the try - except - else statement, 
as in

try:
  foo['bar']
except :
  # Handle the error.
  pass
else :
  # We have it, so use it...
  print foo['bar']

Or you can use the has_key() and test it first. For example

  if foo.has_key('bar'):
print 'we have it'
  else :
print 'we don't have bar.'

That'll do it for me.

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


Re: key not found in dictionary

2006-08-22 Thread [EMAIL PROTECTED]
KraftDiner wrote:
> I have a dictionary and sometime the lookup fails...
> it seems to raise an exception when this happens.
> What should I do to fix/catch this problem?
>
> desc = self.numericDict[k][2]
> KeyError: 589824   < This is the error that is being produced,
> because there is no key
> 589824.

Given the information provided the simplest answer would be:

try:
desc = self.numericDict[k][2]
except KeyError:
desc = ''

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


Re: text editor suggestion?

2006-08-22 Thread John Salerno
Ravi Teja wrote:

> ???
> 
> In the same file, near the top.
> 
> keywordclass.python=and assert break class continue def del elif \
> else except exec finally for from global if import in is lambda None \
> not or pass print raise return try while yield
> 
> I could add my own keywords to it.
> 

But I don't want all my keywords to be highlighted in the same way. I 
have different colors for Python keywords, functions and methods, 
exceptions, other words like 'self', etc. and there's no way to do this 
without rewriting the lexer file (which is in C++) and recompiling Scite 
to build the changes into it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: key not found in dictionary

2006-08-22 Thread hiaips

KraftDiner wrote:
> I have a dictionary and sometime the lookup fails...
> it seems to raise an exception when this happens.
> What should I do to fix/catch this problem?
>
> desc = self.numericDict[k][2]
> KeyError: 589824   < This is the error that is being produced,
> because there is no key
> 589824.

It raises a KeyError, as you are seeing. Just use a try/except
construction and handle the error as required by your application:

try:
desc = self.numericDict[k][2]
except KeyError, ke:


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


key not found in dictionary

2006-08-22 Thread KraftDiner
I have a dictionary and sometime the lookup fails...
it seems to raise an exception when this happens.
What should I do to fix/catch this problem?

desc = self.numericDict[k][2]
KeyError: 589824   < This is the error that is being produced,
because there is no key
589824.

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


Re: Create a Multilanguage PDF in Python

2006-08-22 Thread Perseo
Nothing to do!
I enable test2.py and the folder with 777 permission and I write at the
top of the file the PYTHONPATH "#!/usr/bin/python" as you told me but
it doesn't works as well.

this is my organization:
www.domain.com/python/reportlab/ [all files]
www.domain.com/python/test2.py


#!/usr/bin/python

print "Content-Type: text/html\n\n"
print "Hello World"

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas

pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
c = canvas.Canvas("pl.pdf")
c.setFont("Verdana", 12)
c.drawString(100, 600, "Witaj,
¶wiecie!".decode("iso-8859-2").encode("utf-8"))
c.showPage()
c.save()


The verdana font doesn't exist in the reportlab fonts folder. I try to
delete the rows where it is called like (registerFont, setFont) but
nothing to do.

any suggestion?!



Diez B. Roggisch wrote:
> Perseo wrote:
>
> > I can't upload in the PYTHONPATH but in a normal folder of our site.
> > Exist another way to do it?
>
> PYTHONPATH is an environment variable. You can set it to arbitrary paths,
> and python will look for module there, too. Or you modify sys.path before
> you try the import.
> 
> Diez

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


Re: Job Jar

2006-08-22 Thread D
Thanks, Fredrik - but could I adapt them so that, instead of using them
for bug tracking (don't need version control, etc.), they're just used
for keeping track of simple tasks?

Fredrik Lundh wrote:
> D wrote:
>
> > Hello, I apologize in advance for the vague description, but as of now
> > I only have an idea of what I'd like to do, and need some guidance as
> > to if it is feasible, and where to begin.  Basically, I'd like to
> > create a web-based "job jar", that users in my office can access in
> > order to view, and "take ownership" of, misc. office tasks.  One idea I
> > had was that when users select a task (i.e. by selecting a check box
> > and clicking an UPDATE button), tasks are automatically put in an In
> > Progress list (which identifies the task and the user who took
> > ownership of it) - then, when the action is complete, the user updates
> > it again which puts it in a Completed list (again, with the task
> > description and the user who completed it).  However, only certain
> > users should be able to add and modify task descriptions.
>
> why not use an issue tracker?
>
>  http://roundup.sourceforge.net/
>  http://trac.edgewall.org/
>  https://launchpad.net/
> 
> (etc)
> 
> 

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


Re: https on ActiveState Python 2.4?

2006-08-22 Thread Fredrik Lundh
Jack wrote:
> Thanks for the reply.
> 
> I found some openSSL patches for earlier versions of ActiveState Python.
> It involves .pyd files and they look for earlier versions of Python DLLs and 
> don't run on ActiveState Python 2.4. I suspect the regular Python solution 
> would
> have the same problem or even more problems because it's not a pure .py
> patch.

huh?  the "regular Python solution" ships with a perfectly working SSL 
library (in DLLs/_ssl.pyd), which look for the appropriate version of 
the Python DLL:

 > dumpbin /imports "\python24\DLLs\_ssl.pyd"
Microsoft (R) COFF Binary File Dumper Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Dump of file \python24\DLLs\_ssl.pyd

File Type: DLL

   Section contains the following imports:

 WSOCK32.dll
 ...
 python24.dll
 ...

(what's the point in using ActiveState's crippled distribution if you 
need stuff that's shipped with the standard distro, btw?  why not just 
use the standard version, and install win32all on top of that?)



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


Re: Job Jar

2006-08-22 Thread Fredrik Lundh
D wrote:

> Hello, I apologize in advance for the vague description, but as of now
> I only have an idea of what I'd like to do, and need some guidance as
> to if it is feasible, and where to begin.  Basically, I'd like to
> create a web-based "job jar", that users in my office can access in
> order to view, and "take ownership" of, misc. office tasks.  One idea I
> had was that when users select a task (i.e. by selecting a check box
> and clicking an UPDATE button), tasks are automatically put in an In
> Progress list (which identifies the task and the user who took
> ownership of it) - then, when the action is complete, the user updates
> it again which puts it in a Completed list (again, with the task
> description and the user who completed it).  However, only certain
> users should be able to add and modify task descriptions.

why not use an issue tracker?

 http://roundup.sourceforge.net/
 http://trac.edgewall.org/
 https://launchpad.net/

(etc)



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


Re: https on ActiveState Python 2.4?

2006-08-22 Thread Jack
Thanks for the reply.

I found some openSSL patches for earlier versions of ActiveState Python.
It involves .pyd files and they look for earlier versions of Python DLLs and 
don't
run on ActiveState Python 2.4. I suspect the regular Python solution would
have the same problem or even more problems because it's not a pure .py
patch.

"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Mon, 21 Aug 2006 15:31:20 -0700, "Jack" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>> I'm trying to use urllib to retrieve an https page but I am
>> getting an "unknown url type: https"
>>
>> It seems that ActiveState Python doesn't have SSL support.
>> Any advice?
>>
>
> I've not tried, but it may be that the "regular" Python (of the same
> language level) may have SSL as a DLL/PYD & .py set and you could just
> copy them into the ActiveState install directory...
> -- 
> Wulfraed Dennis Lee Bieber KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/ 


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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Fredrik Lundh
jojoba wrote:

> However, although python's object model does not currently support what
> i am asking for, how difficult would it be to assign a string name(s)
> to an object upon creation (and upon referencing)?

if you want to add additional behaviour to an object, wrap it in custom 
class, or use a subclass.

here's an example:

 >>> class dict_with_title(dict):
... title = None
...
 >>> d = dict_with_title()
 >>> d.title = "this is the title"
 >>> d["a"] = "hello"
 >>> d
{'a': 'hello'}
 >>> d.title
'this is the title'



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


Re: how do you get the name of a dictionary?

2006-08-22 Thread jojoba



> At the risk of stating the obvious, why don't you simply add a parameter
> for the title in the invocation of the tree editor? I.e. instead of
> invoke_tree_editor(somedict)
> do
> invoke_tree_editor(somedict, "somedict")
> HTH,
> Carsten.


Thanks Carsten.
This would indeed allow me to assign a title for my dicitonaries, but i
am looking for something more general..
specfically:
given any dictionary, get a name for it.

But yeah, your way would totally work!
Thanks,
jojoba

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


Job Jar

2006-08-22 Thread D
Hello, I apologize in advance for the vague description, but as of now
I only have an idea of what I'd like to do, and need some guidance as
to if it is feasible, and where to begin.  Basically, I'd like to
create a web-based "job jar", that users in my office can access in
order to view, and "take ownership" of, misc. office tasks.  One idea I
had was that when users select a task (i.e. by selecting a check box
and clicking an UPDATE button), tasks are automatically put in an In
Progress list (which identifies the task and the user who took
ownership of it) - then, when the action is complete, the user updates
it again which puts it in a Completed list (again, with the task
description and the user who completed it).  However, only certain
users should be able to add and modify task descriptions.

Is this something that would be extremely lengthy to write in Python,
or are there applications already out there that would make more sense
to use (I've played around with Twiki, but believe it to be overkill).
If it makes sense to design it from scratch, where can I begin in terms
of which libraries to use, etc.? Thanks in advance.

Steve

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


Re: Problem of function calls from map()

2006-08-22 Thread Fredrik Lundh
Sion Arrowsmith wrote:

>> (you cannot really use "profile" to *benchmark* things written in Python 
>> either; the
>> profiler tells you where a given program spends the time, not how fast it is 
>> in com-
>> parision with other programs)
> 
> Hmm. Playing around with timeit suggests that although split() *is*
> faster than split("\t"), it's fractional, rather than the OP's four
> times faster. Is the overhead of profile keeping track of calls in
> Python getting in the way?

correct.

> And why can map() keep everything at the C level when the list com-
 > prehension can't?

map is called with two Python objects (the str.split callable and the 
sequence object), while the list comprehension is turned into a byte-
code loop that evaluates s.split for each item in the sequence; compare 
and contrast:

 >>> def func(a):
... return map(str.split, a)
...
 >>> dis.dis(func)
   2   0 LOAD_GLOBAL  0 (map)
   3 LOAD_GLOBAL  1 (str)
   6 LOAD_ATTR2 (split)
   9 LOAD_FAST0 (a)
  12 CALL_FUNCTION2
  15 RETURN_VALUE

 >>> def func(a):
... return [s.split() for s in a]
...
 >>> dis.dis(func)
   2   0 BUILD_LIST   0
   3 DUP_TOP
   4 STORE_FAST   1 (_[1])
   7 LOAD_FAST0 (a)
  10 GET_ITER
 >>   11 FOR_ITER19 (to 33)
  14 STORE_FAST   2 (s)
  17 LOAD_FAST1 (_[1])
  20 LOAD_FAST2 (s)
  23 LOAD_ATTR0 (split)
  26 CALL_FUNCTION0
  29 LIST_APPEND
  30 JUMP_ABSOLUTE   11
 >>   33 DELETE_FAST  1 (_[1])
  36 RETURN_VALUE

(LOAD_GLOBAL and LOAD_ATTR does full name lookups, while LOAD_FAST loads 
a local variable using an integer index)



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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Gabriel Genellina

At Tuesday 22/8/2006 13:34, jojoba wrote:


i don't want to do anything sophisticated with this, i am really only
looking for a TITLE for my dictionary when i throw it in a tree editor
that i have built. And i do realize that its not possible now. I am
just pressing a point here.

Sorry to ruffle everyone's feathers, but this is a fairly curious
problem.


It's no problem at all: do you need a TITLE for your dictionary? Add 
a "title" attribute and you're done. Do you want a class? Inherit 
from dict and add your title attribute there.
That's pretty standard OO, and there is no need to modify the Python 
language...




Gabriel Genellina
Softlab SRL 




p4.vert.ukl.yahoo.com uncompressed Tue Aug 22 17:27:05 GMT 2006 
	


__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: text editor suggestion?

2006-08-22 Thread Ravi Teja

John Salerno wrote:
> Ravi Teja wrote:
>
> > Stick to SciTE. It takes almost no learning effort and meets everyone
> > of those requirements. As far as customerization goes, SciTE can be
> > customerized quite well. In fact, it can even be scripted with Lua. You
> > seem to be using the single file executable which does not come with
> > the configuration files. Otherwise, I cannot see how you could be
> > missing this ability.
>
> I really like Scite, but I find it's syntax highlighting abilities to be
> quite limited. You can't specify your own groups of words, you can only
> use what is already preset in the lexer files.

???

In the same file, near the top.

keywordclass.python=and assert break class continue def del elif \
else except exec finally for from global if import in is lambda None \
not or pass print raise return try while yield

I could add my own keywords to it.

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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Carsten Haese
On Tue, 2006-08-22 at 12:34, jojoba wrote:
> Hello again,
> 
> Fredrick said:
> 
> > Python's object model.  an object has a value, a type, and an identity,
> > but no name.
> 
> I say:
> 
> Thank you Fredrick for the reply!
> However, although python's object model does not currently support what
> i am asking for, how difficult would it be to assign a string name(s)
> to an object upon creation (and upon referencing)?
> 
> please note:
> i don't want to do anything sophisticated with this, i am really only
> looking for a TITLE for my dictionary when i throw it in a tree editor
> that i have built. And i do realize that its not possible now. I am
> just pressing a point here.

At the risk of stating the obvious, why don't you simply add a parameter
for the title in the invocation of the tree editor? I.e. instead of

invoke_tree_editor(somedict)

do

invoke_tree_editor(somedict, "somedict")

HTH,

Carsten.


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


Re: how do you get the name of a dictionary?

2006-08-22 Thread jojoba
> Exactly the point that's being made. It's so easy just do it yourself:
> banana={"name":"banana"}
> Hey what is the name of my dictionary?
> banana["name"]
> But why build it into Python and force everyone else to do it, when
> most of the time nobody cares what the name is, or they already know?


Aha.
my problem, (which as i said before, is not really an important
problem) is to take any dictionary and load it into a tree viewer AND
get the name(s) of that dictionary (if they exist, and if not, so be
it).
Now, that means that a given dictionary might not have the admittedly
super simple method of binding a name to itself (i.e. the
banana={"name":"banana"}).
This has been my issue. And there is no GENERAL solution that currently
exists.
I completely agree with everybody that a draconian solution is not
necessarily optimal, but i havent been convinced that it would
drastically, deleteriously affect python performance.
However, since i am not one of the wonderful people who commit time to
actually coding python, i dont really have a say.  =)
I know i am harping on this, but no one of yet has really proven why
having such a feature would seriously affect python speed.
Any ideas?
jojoba

o(-_-)o

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


Unicode Error

2006-08-22 Thread Gallagher, Tim (NE)









Hey all I am learning Python
and having a fun time doing so.  I have a question for y'all, it has to do with
active directory.

 

I want to get the last login
for a computer from Active Directory.  I am using the active_directory module
and here is my code.

 

[START]

 

import active_directory

 

computer =
active_directory.root()

for cpu in computer.search
("cn='Computer_Name'"): 

    print cpu.samAccountName    ←---
Works find

    print
cpu.operatingSystem   ←--- Works find

    print cpu.lastLogon ←---
Getting Error

 

[END]

 

 

I get an error that I am not sure what to do with,
the error is TypeError: coercing to Unicode: need string or buffer, instance
found in my line Do I have to change the output to meet Unicode formation?

 

Thanks,

-T






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

Re: Input from the same file as the script

2006-08-22 Thread Dieter Maurer
Georg Brandl <[EMAIL PROTECTED]> writes on Sun, 20 Aug 2006 20:08:38 +0200:
> [EMAIL PROTECTED] wrote:
> > Can the input to the python script be given from the same file as the
> > script itself. e.g., when we execute a python script with the command
> > 'python  > When I ran the below the python interpreter gave an error.

The easiest way would be:

 data = '''\
 here comes your data
 ...
 '''

 # and now you use it
 ... data ...

 # you can even wrap it into a file
 from StringIO import StringIO
 data_as_file = StringIO(data)
 ... data_as_file.readline() ...

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


Re: Create a Multilanguage PDF in Python

2006-08-22 Thread Perseo
Thanks I will try it.

Diez B. Roggisch wrote:
> Perseo wrote:
>
> > I can't upload in the PYTHONPATH but in a normal folder of our site.
> > Exist another way to do it?
>
> PYTHONPATH is an environment variable. You can set it to arbitrary paths,
> and python will look for module there, too. Or you modify sys.path before
> you try the import.
> 
> Diez

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


Re: How to get database metadata information (i.e. existing tables and columns in tables)

2006-08-22 Thread Luis M. González
If you want to know the names of the fields on a recordset, you can use
cursor.description.
For example, lets say you have a connection to a MySQL database:

con = MySQLdb.connect('localhost','root','','mydb')
cur = con.cursor()
cur.execute('select * from customers')
result = cur.fetchall()

fields = [i[0] for i in cur.description]
...
Description gives a list with information about your recordset, being
the first item the name of the field.

Hope this helps...
Luis



Chris Brat wrote:
> Hi,
>
> Is it possible to retrieve details about the database, specifically a
> list of the tables in the database; and then to retrieve the columns
> and their types for the tables?
> 
> Is this dependant on the database? 
> 
> Thanks
> Chris

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


Re: Unclear on argument passing to "sendmail'

2006-08-22 Thread John Draper
Tim Williams wrote:

> On 21/08/06, John Draper <[EMAIL PROTECTED]> wrote:
>
>> In "smtplib" module, the "sendmail" method of function is to be  passed
>
> > host, but it is the Domain name
>
>> for the SMTP Server as gotten from the "dig" command?   IE:   dig -tMX
>> would give me the SMTP
>> server.   In my code I have:
>
> >
>
>> try:
>> print "Sending message to host: %s" % mailHost
>> server=smtplib.SMTP(mailHost)
>> server.sendmail(reply_email,email,body)
>> server.quit()
>> except:
>> print "Uunable to send"
>>
>> Is mailHost like "mail.t-mobile.com" which I get from the MX record for
>> a given domain?
>> But also,  is the "email" just the mail account,  ie:  the username?
>> without the @?
>>
>> I need to be able to query the mail server?   Also,  I want to be able
>> to handle
>> the "SMTPRecipientsRefused" exception.   What is the proper syntax for
>> handling
>> this?
>>
>> Do I do it like this?
>>
>> try:
>> print "Sending message to host: %s" % mailHost
>> server=smtplib.SMTP(mailHost)
>> server.sendmail(reply_email,email,body)
>> server.quit()
>> except SMTPRecipientsRefused:
>> print "Recipient refused"
>>
>> Is that the right syntax?   I have severe problems with not enough
>> example code.
>>
>
> mailHost is the name of the mail server server you are sending the
> email to/via,  for internet mail this will be a server from the
> recipient's domain's mx records (or your ISP server).

Ok,  that's what I thought,  I wasn't sure if I were to put the MAIN host
name or the MX host name.

>
> reply_email is the full email address of the sender, or the email
> address you wish to appear as the sender. It does not have to be the
> same address as used in the body headers

OK

>
> email is a bad choice for a variable name,  try something like
> to_email,  in your case it should contain the full email address of
> the recipeint or a list of recipients.  

Ok,   so If I already have a MX hostname of "mail.myhost.com",  then
I would put into my "to_email"...@myhost.com for
my user name,  is that right?   And not just  without the
@myhost.com,   right?

> The address(es)  do not have
> to be the same address as used in the body headers

OK

>
> server.sendmail returns a list of failed recipient email addresses if
> only some failed,   if all the recipients failed you get an exception.

Hmmm - the problem I have is if I knowingly put in a bad recipient,  and
try to send to a unknown user,  I get all appearances that the mail went 
through.
I never got any kind of failed recipient (Which for me,  is a total 
bummer), because
now I cannot know if the mail was sucessfully sent.  Is this normal 
behaviour for
an SMTP server?   I know in SOME instances,  in the case the SMTP server has
to "relay" the mail to another server,  I wouldn't get this exception 
and it would
appear the mail went through,  but will the "sendmail" method also return
the failed recipient's Email address in this case as well?

By the way,  I'm sending this mail to a "sms" gateway to a cellular 
provider,
so the username is their phone number.   But (sigh),  these providers don't
appear to tell me if I put in a bogus phone number.

>
> Apologies for the bad formatting below,  its untested but should show
> you the structure for managing an SMTP msg send.  You could tidy it up
> without too much effort
>
> import sys
>
> for mailHost in MX_records:
> try:
>print "Sending message to host: %s" % mailHost
>server=smtplib.SMTP(mailHost)
>failed = server.sendmail(reply_email,email,body)
>server.quit()
>break
> except smtplib.SMTPRecipientsRefused, x :  #all recips failed
>for recip in x.recipients:
>print recip
>server.quit()
>break
> except smtplib.SMTPDataError, x: # an error at the end of the
> # message body =  MSG Failed
> # all recips failed
>print x[0], x[1]
>server.quit()
>break
> except smtplib.SMTPSenderRefused, x : # the sender was refused = #MSG 
> failed
> # all recips failed
>print x[0], x[1]
>server.quit()
>break
> except: #can't connect so continue to next MX server - don't fail !!!
>e_error = str(sys.exc_info()[0])
>print e_error
>server.quit()
>continue
>
> for recip in failed:  # some failed, some didn't
>print recip

Hmmm - so THAT's how I use the exceptions.  What is "x"?  Is that the 
error code,
or is that the returned dictionary.I thought I had to do it this way

   d = server.sendmail(reply_email,email,body)

Where "d" is the dictionary.   But in your above code,  you return a 
"failed",  but
you are not using it in any other part of the code.  Is this because "x" 
when used
in the "except" clause is what I'm to use?   Is "x" and "failed" the 
same dictionary?

Ok,  I got one more question...  in the docs on the smtplib class,  a 
"sendmail"
method also has other arguments,   such as mail_options,  and rcpt_options.
What are they,  and could you give me an example 

Re: how do you get the name of a dictionary?

2006-08-22 Thread BartlebyScrivener
>> how difficult would it be to assign a string name(s)
>> to an object upon creation (and upon referencing)?

Exactly the point that's being made. It's so easy just do it yourself:

banana={"name":"banana"}

Hey what is the name of my dictionary?

banana["name"]

But why build it into Python and force everyone else to do it, when
most of the time nobody cares what the name is, or they already know?

It's like forcing everybody everywhere always and forever to wear
"Hello My Name Is" tags.

rd

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


Re: Need advice on how to improve this function

2006-08-22 Thread Gabriel Genellina

At Monday 21/8/2006 12:03, Larry Bates wrote:


> I wrote a function that converts a tuple of tuples into html.  For
> example:
> I'd like to know ways to make it better (more efficient, able to deal
> with enormous-size arguments, etc).  How would I write this as a
> generator?
Before you put too much work into this you might want to take a look
at HTMLgen:  http://www.python.net/crew/friedrich/HTMLgen/html/main.html


Another very good library is 
(Don't be afraid of the date - it's just that HTML standards haven't 
changed very much lately :) )




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: how do you get the name of a dictionary?

2006-08-22 Thread Georg Brandl
jojoba wrote:
> Hello again,
> 
> Fredrick said:
> 
>> Python's object model.  an object has a value, a type, and an identity,
>> but no name.
> 
> I say:
> 
> Thank you Fredrick for the reply!
> However, although python's object model does not currently support what
> i am asking for, how difficult would it be to assign a string name(s)
> to an object upon creation (and upon referencing)?
> 
> please note:
> i don't want to do anything sophisticated with this, i am really only
> looking for a TITLE for my dictionary when i throw it in a tree editor
> that i have built. And i do realize that its not possible now. I am
> just pressing a point here.
> 
> Sorry to ruffle everyone's feathers, but this is a fairly curious
> problem.

Why not add a "name" attribute to your objects? e.g.

class NamedDict(dict):
 def __init__(self, _name_, *args, **kwargs):
 self.name = _name_
 dict.__init__(self, *args, **kwargs)

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


Re: idutils and Python

2006-08-22 Thread [EMAIL PROTECTED]
Ramon Diaz-Uriarte wrote:
> On 21 Aug 2006 22:56:13 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > What exactly are you trying to accomplish?  If you want to index
> > function/class names, variables, etc then you should take a look at
> > "exuberant ctags" http://ctags.sourceforge.net53 --although it started
> > off as a C indexer, it has excellent Python support, it's free, and as
> > a bonus its indices are well supported from inside major editors (vim,
> > emacs, etc) so you can easily follow code flow, find function/class
> > definitions, etc.
>
>
> Sorry for not being clear enough. I want the following:
>
> a) have my editor go to the point where a function/whatever is defined

That's usually ctags/etags

> b) see all places where a function/whatever is used.

That's usually cscope  http://cscope.sourceforge.net/ but I've not
tried to use it with Python before; from the web page it looks like it
may be worth a spin:
"The fuzzy parser supports C, but is flexible enough to be useful for
C++ and Java, and for use as a generalized 'grep database' (use it to
browse large text documents!"

The vim integration is very nice.  It has emacs integration too, but I
haven't used it and can't comment on how good it is.

> I think the wish "do not use grep, just look at the index file, and
> immediately display all matches"  is reasonable and probably other
> Python coders had thought about it before. But I am wondering if I am
> missing something obvious, as most people seem to be very happy with
> exuberant ctags.

I am usually happy with grep, but we only have a medium-large size
project (320,000 lines of Python code); I can imagine on very large
codebases that would be too slow to be practical.

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


Re: Python and STL efficiency

2006-08-22 Thread Tim N. van der Leeuw

Mc Osten wrote:
> Tim N. van der Leeuw <[EMAIL PROTECTED]> wrote:
>
> > Oh boy; yes indeed the slow python is faster than the fast C++
> > version... Must be something really awful happening in the STL
> > implementation that comes with GCC 3.4!
>
> And the Python version does the very same number of iterations than the
> C++ one? I suppose they are looping on arrays of different sizes, just
> like my "first version".
>

Hmmm.. You're quite right. The C++ version had an array size 100.000
(your version), the Python version still had an array size 10.000 (as
in my modified copy of the original version).

When fixing the Python version to have 100.000 items, like the C++
version, the Python timings are:

Begin Test
Number of unique string objects: 4
so long...
What do you know
fool
chicken crosses road
Number of unique string objects: 40
so long...
What do you know
fool
chicken crosses road
Fast - Elapsed: 0.512088 seconds
Slow - Elapsed: 1.139370 seconds

Still twice as fast as the fastest GCC 3.4.5 compiled version!

Incidentally, I also have a version compiled with VC++ 6 now... (not
yet w/VC++ 7) .. Compiled with release-flags and maximum optimization
for speed, here's the result of VC++ 6:

[EMAIL PROTECTED] ~/My Documents/Python
$ ./SpeedTest_VC.exe
Begin Test
What do you know?
chicken crosses road
fool
so long...
What do you know?
chicken crosses road
fool
so long...
Fast - Elapsed: 4.481 seconds
Slow - Elapsed: 4.842 seconds

So you can see that it's 'slow' version of the code is faster than the
'slow' version compiled with GCC, but the 'fast' code is barely faster
than the 'slow' code! And the 'fast' version compiled with GCC is much
faster than the 'fast' version compiled with VC++ 6!

My conclusion from that is, that the vector<> or set<> implementations
of GCC are far superior to those of VC++ 6, but that memory allocation
for GCC 3.4.5 (MinGW version) is far worse than that of MSCRT / VC++ 6.
(And Python still smokes them both).

Cheers,

--Tim



> --
> blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
> site:  http://www.akropolix.net/rik0/  | tenetevi riso e
> forum: http://www.akropolix.net/forum/ | bacchette per voi.

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


Re: Translating Javascript programs to python.

2006-08-22 Thread Diez B. Roggisch
Vyz schrieb:
> Hi,
> I have a script with hundreds of lines of javascript spread accross 7
> files. Is there any tool out there to automatically or
> semi-automatically translate the code into python. 

Nope. Besides: in which environment does that script run - a browser? 
Then it would be difficult if not impossible to execute even a 
hypothetic result.

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


Re: how do you get the name of a dictionary?

2006-08-22 Thread jojoba
Hello again,

Fredrick said:

> Python's object model.  an object has a value, a type, and an identity,
> but no name.

I say:

Thank you Fredrick for the reply!
However, although python's object model does not currently support what
i am asking for, how difficult would it be to assign a string name(s)
to an object upon creation (and upon referencing)?

please note:
i don't want to do anything sophisticated with this, i am really only
looking for a TITLE for my dictionary when i throw it in a tree editor
that i have built. And i do realize that its not possible now. I am
just pressing a point here.

Sorry to ruffle everyone's feathers, but this is a fairly curious
problem.

Thanks to all,
jojoba

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


Translating Javascript programs to python.

2006-08-22 Thread Vyz
Hi,
I have a script with hundreds of lines of javascript spread accross 7
files. Is there any tool out there to automatically or
semi-automatically translate the code into python. 

Thanks
Vyz

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


Re: Problem of function calls from map()

2006-08-22 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>Sion Arrowsmith wrote:
>> I think there's something weird going on -- sp4 should be making
>> 154563 calls to str.split. So no wonder it goes faster -- it's not doing
>> any work.
>the problem is that he's using a Python-level profiler to benchmark things 
>written
>in C.
>
>(you cannot really use "profile" to *benchmark* things written in Python 
>either; the
>profiler tells you where a given program spends the time, not how fast it is 
>in com-
>parision with other programs)

Hmm. Playing around with timeit suggests that although split() *is*
faster than split("\t"), it's fractional, rather than the OP's four
times faster. Is the overhead of profile keeping track of calls in
Python getting in the way? (Not having used profile -- hence my
confusion.) And why can map() keep everything at the C level when
the list comprehension can't?

-- 
\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: CONSTRUCT - Module Attributes and Execution Environment

2006-08-22 Thread Georg Brandl
Larry Bates wrote:
> lazaridis_com wrote:
>> I would like to change the construct:
>> 
>> if __name__ == '__main__':
>> 
>> to something like:
>> 
>> if exec.isMain():
>> 
>> My (OO thought) is to place a class in an separate code module and to
>> instantiate an singleton instance which would keep th something like
>> this:
>> 
>> class ExecutionEnv:
>> def isMain(self)
>> if CALLING_MODULE.__name__ == '__main__':
>> return true
>> else
>> return false
>> 
>> exec = ExecutionEnv()
>> 
>> How to I get access to the CALLING_MODULE ?
>> 
>> -
>> 
>> Are ther alternative constructs/mechanism available, which could be
>> used to add this functionality possiby directly to a code-module?
>> 
> Two thoughts:
> 
> 1) Don't call a class instance exec, it will mask the built-in
> exec statement.

He won't be able to ;)

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


Re: CONSTRUCT - Module Attributes and Execution Environment

2006-08-22 Thread Larry Bates
lazaridis_com wrote:
> I would like to change the construct:
> 
> if __name__ == '__main__':
> 
> to something like:
> 
> if exec.isMain():
> 
> My (OO thought) is to place a class in an separate code module and to
> instantiate an singleton instance which would keep th something like
> this:
> 
> class ExecutionEnv:
> def isMain(self)
> if CALLING_MODULE.__name__ == '__main__':
> return true
> else
> return false
> 
> exec = ExecutionEnv()
> 
> How to I get access to the CALLING_MODULE ?
> 
> -
> 
> Are ther alternative constructs/mechanism available, which could be
> used to add this functionality possiby directly to a code-module?
> 
Two thoughts:

1) Don't call a class instance exec, it will mask the built-in
exec statement.

2) IMHO all the suggestions are way more complicated than
if __name__ == "__main__" and are not SOP for most pythoneers.
I know what the former construct means/does.  I have to
decipher your class to figure our what the latter does and it
doesn't really save you any code or provide a performance
enhancement.

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


Re: unicode "table of character" implementation in python

2006-08-22 Thread Nicolas Pontoizeau
2006/8/22, Brian Beck <[EMAIL PROTECTED]>:
> Nicolas, check out the unicodedata module:
> http://docs.python.org/lib/module-unicodedata.html
>
> Find "import unicodedata" on this page for how to use it:
> http://www.amk.ca/python/howto/unicode
>
> I'm not sure if it has built-in support for finding which language block a
> character is in, but a table like this might help you:
> http://www.unicode.org/Public/UNIDATA/Blocks.txt

As usual, Python has a solution that goes beyond my needs!
Thanks for the links I will dive into it.

Nicolas

-- 
http://www.nicolas.pontoizeau.org/
Nicolas Pontoizeau - Promotion EFREI 2005
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode "table of character" implementation in python

2006-08-22 Thread Brian Beck
Nicolas Pontoizeau wrote:
> I am handling a mixed languages text file encoded in UTF-8. Theres is
> mainly French, English and Asian languages. I need to detect every
> asian characters in order to enclose it by a special tag for latex.
> Does anybody know if there is a unicode "table of character"
> implementation in python? I mean, I give a character and python replys
> me with the language in which the character occurs.

Nicolas, check out the unicodedata module:
http://docs.python.org/lib/module-unicodedata.html

Find "import unicodedata" on this page for how to use it:
http://www.amk.ca/python/howto/unicode

I'm not sure if it has built-in support for finding which language block a
character is in, but a table like this might help you:
http://www.unicode.org/Public/UNIDATA/Blocks.txt

-- 
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >