Re: Is anyone using Python for embedded applications?

2006-12-13 Thread Andre Meyer

Not sure what your target embedded platform is, but there is a Python
version for the Nokia S60 mobile phone platform (Symbian).

http://s60.com/

Python for 
S60http://www.forum.nokia.com/info/sw.nokia.com/id/ee447e84-2851-471a-8387-3434345f2eb0/Python_for_S60.html
Python for S60 allows developers to execute Python commands and run Python
scripts and applications in devices based on S60 Platform. In addition,
developers can execute Python commands and scripts in the emulators of S60
Developer Platform SDKs. Development starts with an interactive console in a
S60 compatible device where Python commands can be executed.

hth
Andre

On 12/12/06, Carl J. Van Arsdall [EMAIL PROTECTED] wrote:


I'm aware of a couple python projects for embedded systems.  I am
currently considering using Python on an embedded platform to develop a
simple application as a personal project, mostly to see if it will
work.  I was wondering if anyone here was using python for anything of
that nature?  For those that are involved in these types of projects,
how does development in python differ for embedded projects versus a
non-embedded project?  Is there a community standard technique or style
for this type of development (i.e. heavy in OO design? commonly used
patterns?)  Are there any good tools to assist for this type of
development environment?

Oh, and if anyone has opinions/facts on why python should not be used in
an embedded platform, I'd like to know that too.  I'm somewhat familiar
with pythons needs on a system, but there are a number of things I am
not aware of.

Thanks to everyone for their input!

-carl

--

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release


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





--
Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safety  http://www.tno.nl/
Delft Cooperation on Intelligent Systems  http://www.decis.nl/

Ah, this is obviously some strange usage of the word 'safe' that I wasn't
previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: funcs without () like print

2006-12-07 Thread Andre Meyer

print is supposed to become a function in Py3k, though.


On 12/7/06, Georg Brandl [EMAIL PROTECTED] wrote:


iwl wrote:
 Hello can I make funktions callable without () like print
 at time the interpreter seems to printout the adres when I type the
 function without ()

print is not a function, it's a statement, and as such equivalent to
raise or assert.



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

Re: Python Plugin for Web Browser

2006-12-06 Thread Andre Meyer

Hi

I was looking for something similar in the past and could not find it. It
would be very useful to have Python applets in web pages. What would you use
them for?

kind regards
André



On 5 Dec 2006 23:59:29 -0800, Sébastien Ramage [EMAIL PROTECTED]
wrote:


des exemples de plugins pour IE oui mais qui ne sont pas embarqué dans
une page Web
je souhaiterai créer qqchose qui ressemble vraiment à Java VM ou
Flash
J'ai trouvé un début de réponse pour Firefox en télécharger le
GeckoSDK
mais je n'arrive pas à compiler les exemples pour le moment...

merci


MC a écrit :

 Bonjour !

 Pour IE, il y a des exemples de plugins, fournis avec PyWin32.
 Pour FF (comme pour Opera), je ne sais pas.

 --
 @-salutations

 Michel Claveau



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





--
Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safety  http://www.tno.nl/
Delft Cooperation on Intelligent Systems  http://www.decis.nl/

Ah, this is obviously some strange usage of the word 'safe' that I wasn't
previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python Plugin for Web Browser

2006-12-06 Thread Andre Meyer

Hi Sebastien

Yes, I am a developer, but not C/C++. I have done Java (and many other
languages) in the past, but use Python nowadays.

So, I am no help for developing the plugin, sorry. I would want to use it
though for developing richer Web sites in Python, rather than in
JavaScript/Ajax. Having said that: maybe you are also interested in pyjamas
(http://pyjamas.pyworks.org/).

kind regards
André



On 12/6/06, Sebastien Ramage [EMAIL PROTECTED] wrote:


Hi

Thank you for your reply.
Yes ! It would be very useful and easy to develop (the applet not the
plugin) !

I don't have real project at this time but, I like Python and use it every
day. Many time I want to make an applet for game, or webcam remote control
but I don't understand and I don't want to learn Java when I know the
powerful python.
Are you a developper? C++ ?

Seb




2006/12/6, Andre Meyer [EMAIL PROTECTED]:

 Hi

 I was looking for something similar in the past and could not find it.
 It would be very useful to have Python applets in web pages. What would you
 use them for?

 kind regards
 André



 On 5 Dec 2006 23:59:29 -0800, Sébastien Ramage [EMAIL PROTECTED]
  wrote:
 
  des exemples de plugins pour IE oui mais qui ne sont pas embarqué dans
  une page Web
  je souhaiterai créer qqchose qui ressemble vraiment à Java VM ou
  Flash
  J'ai trouvé un début de réponse pour Firefox en télécharger le
  GeckoSDK
  mais je n'arrive pas à compiler les exemples pour le moment...
 
  merci
 
 
  MC a écrit :
 
   Bonjour !
  
   Pour IE, il y a des exemples de plugins, fournis avec PyWin32.
   Pour FF (comme pour Opera), je ne sais pas.
  
   --
   @-salutations
  
   Michel Claveau
 
 
 
  --
  http://mail.python.org/mailman/listinfo/python-list
 
 


 --
 Dr. Andre P. Meyerhttp://python.openspace.nl/meyer

 TNO Defence, Security and Safety   http://www.tno.nl/
 Delft Cooperation on Intelligent Systems  http://www.decis.nl/

 Ah, this is obviously some strange usage of the word 'safe' that I
 wasn't previously aware of. - Douglas Adams






--
Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safety  http://www.tno.nl/
Delft Cooperation on Intelligent Systems  http://www.decis.nl/

Ah, this is obviously some strange usage of the word 'safe' that I wasn't
previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

route planning

2006-12-01 Thread Andre Meyer

Hi all

Just a very simple question: where can I find a module for route planning?

I have looked around and found some implementations of graph theory, e.g.
http://sourceforge.net/projects/pynetwork/. But, what I need is not an
abstract graph, but one where nodes/vertices have locations (2D), are
connected (to follow a path, respecting distance among nodes) and where I
can easily find the closest edge and vertex from any point in space.

your links are much appreciated
thanks
André
-- 
http://mail.python.org/mailman/listinfo/python-list

synching with os.walk()

2006-11-24 Thread Andre Meyer

Hi all

os.walk() is a nice generator for performing actions on all files in a
directory and subdirectories. However, how can one use os.walk() for walking
through two hierarchies at once? I want to synchronise two directories (just
backup for now), but cannot see how I can traverse a second one. I do this
now with os.listdir() recursively, which works fine, but I am afraid that
recursion can become inefficient for large hierarchies.

thanks for your help
André
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: synching with os.walk()

2006-11-24 Thread Andre Meyer

That sounds like a good approach.

On 24 Nov 2006 08:27:09 -0800, Paddy [EMAIL PROTECTED] wrote:



Andre Meyer wrote:

 Hi all

 os.walk() is a nice generator for performing actions on all files in a
 directory and subdirectories. However, how can one use os.walk() for
walking
 through two hierarchies at once? I want to synchronise two directories
(just
 backup for now), but cannot see how I can traverse a second one. I do
this
 now with os.listdir() recursively, which works fine, but I am afraid
that
 recursion can become inefficient for large hierarchies.

 thanks for your help
 André

Walk each tree individually gathering file names relative to the head
of the tree and modification data.

compare the two sets of data to generate:
1. A list of what needs to be copied from the original to the copy.
2. A list of what needs to be copied from the copy to the original

Do the copying.

|You might want to show the user what needs to be done and give them
the option of aborting after generating the copy lists.

- Paddy.

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

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

Re: synching with os.walk()

2006-11-24 Thread Andre Meyer

What I forgot to mention is that I want this to run unmodified from both
Windows and Linux (and Mac). Otherwise, there are enough options to choose
from, besides developing it myself, I guess.

On 24 Nov 2006 08:37:13 -0800, Paddy [EMAIL PROTECTED] wrote:



Paddy wrote:

 Andre Meyer wrote:

  Hi all
 
  os.walk() is a nice generator for performing actions on all files in a
  directory and subdirectories. However, how can one use os.walk() for
walking
  through two hierarchies at once? I want to synchronise two directories
(just
  backup for now), but cannot see how I can traverse a second one. I do
this
  now with os.listdir() recursively, which works fine, but I am afraid
that
  recursion can become inefficient for large hierarchies.
 
  thanks for your help
  André

 Walk each tree individually gathering file names relative to the head
 of the tree and modification data.

 compare the two sets of data to generate:
  1. A list of what needs to be copied from the original to the copy.
  2. A list of what needs to be copied from the copy to the original

 Do the copying.

 |You might want to show the user what needs to be done and give them
 the option of aborting after generating the copy lists.

 - Paddy.
P.S. If you are on a Unix type system you can use tar to do the copying
as you can easily compress the data if it needs to go over a sow link,
and tar will take care of creating any needed directories in the
destination if you create new directories as well as new files.
- Paddy.

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





--
Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safety  http://www.tno.nl/
Delft Cooperation on Intelligent Systems  http://www.decis.nl/

Ah, this is obviously some strange usage of the word 'safe' that I wasn't
previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: synching with os.walk()

2006-11-24 Thread Andre Meyer

Cool, this seems to work.

thanks!


On 24 Nov 2006 08:12:08 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


 os.walk() is a nice generator for performing actions on all files in a
 directory and subdirectories. However, how can one use os.walk() for
walking
 through two hierarchies at once? I want to synchronise two directories
(just
 backup for now), but cannot see how I can traverse a second one. I do
this
 now with os.listdir() recursively, which works fine, but I am afraid
that
 recursion can become inefficient for large hierarchies.

I've run into wanting to work with parallel directory structures
before, and what I generally do is something like:

for root, dirs, files in os.walk( dir1 ):
  dir2_root = dir2 + root[len(dir1):]
  for f in files:
dir1_path = os.path.join( root, f )
dir2_path = os.path.join( dir2_root, f )

Does this work for your needs?
-- Nils

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





--
Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safety  http://www.tno.nl/
Delft Cooperation on Intelligent Systems  http://www.decis.nl/

Ah, this is obviously some strange usage of the word 'safe' that I wasn't
previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Feature Request: Py_NewInterpreter to create separate GIL (branch)

2006-11-03 Thread Andre Meyer
Hi allStrange enough, there does not even seem to be interest in removing the GIL in Python 3000.For some interesting answers on this topic you may read through the thread Kill GIL on the py3k mailing list archives:
http://mail.python.org/pipermail/python-3000/2006-September/thread.html.kind regardsAndré
On 11/3/06, robert [EMAIL PROTECTED] wrote:
Feature Request: Py_NewInterpreter to create separate GIL (branch)Daniel Dittmar wrote: robert wrote: I'd like to use multiple CPU cores for selected time consuming Python computations (incl. numpy/scipy) in a frictionless manner.
 Interprocess communication is tedious and out of question, so I thought about simply using a more Python interpreter instances (Py_NewInterpreter) with extra GIL in the same process.
 If I understand Python/ceval.c, the GIL is really global, not specific to an interpreter instance: static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */Thats the show stopper as of now.
There are only a handfull funcs in ceval.c to use that very global lock. The rest uses that funcs around thread states.Would it be a possibilty in next Python to have the lock separate for each Interpreter instance.
Thus: have *interpreter_lock separate in each PyThreadState instance and only threads of same Interpreter have same GIL?Separation between Interpreters seems to be enough. The Interpreter runs mainly on the stack. Possibly only very few global C-level resources would require individual extra locks.
Sooner or later Python will have to answer the multi-processor question.A per-interpreter GIL and a nice module for tunneling Python-Objects directly between Interpreters inside one process might be the answer at the right border-line ? Existing extension code base would remain compatible, as far as there is already decent locking on module globals, which is the the usual case.
Robert--http://mail.python.org/mailman/listinfo/python-list-- Dr. Andre P. Meyer
http://python.openspace.nl/meyerTNO Defence, Security and Safetyhttp://www.tno.nl/Delft Cooperation on Intelligent Systems
http://www.decis.nl/Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help me use my Dual Core CPU!

2006-09-17 Thread Andre Meyer
You may, of course, also have a look at JavaSpaces or TSpaces (both in Java).JavaSpaceshttp://java.sun.com/docs/books/jini/javaspaces/
http://java.sun.com/developer/technicalArticles/tools/JavaSpaces/index.htmlhttp://www.javaworld.com/jw-11-1999/jw-11-jiniology.htmlTSpaces
http://www.almaden.ibm.com/cs/TSpaces/http://www.alphaworks.ibm.com/tech/tspacesOr read the original tuple space articles by David Gelernter:
http://en.wikipedia.org/wiki/David_Gelernterhttp://portal.acm.org/citation.cfm?id=2433
http://citeseer.ist.psu.edu/14383.htmlTuple spaces are cool ;-)On 9/17/06, Ramon Diaz-Uriarte 
[EMAIL PROTECTED] wrote:On 17 Sep 2006 00:55:09 -0700, Paul Rubin
http://phr.cx@nospam.invalid wrote: Ramon Diaz-Uriarte [EMAIL PROTECTED] writes:  You might also want to check
  http://www.lindaspaces.com/products/NWS_overview.html52  by the guys who invented Linda. Cool, I guess.
I've only played a little bit with it, but it does certainly looknice. Nick Carriero (from network spaces) also developed a similarthing for R, the GNU S statistical programming language (also from the
above url), and the demonstration I saw of it was _really_ impressive. I looked at these.Oz/Mozart is a whole nother language, worth examining for its ideas, but the implementation is quite slow.
Yes, that is true. On the plus side, though, the Concepts,techniques, and models of computer programming book, by Van Roy andHaridi, uses Oz/Mozart, so you get a thorough, pedagogical, andextended ---900 pages--- tutorial of it. But the speed and, so far,
limited ways of being friendly to other languages, can be showstoppers. Kamaelia doesn't attempt concurrency at all.Its main idea is to use generators to simulate microthreads.Candygram is a module that lets
 you write code in Python that's sort of like Erlang code, but it uses OS threads for the equivalent of Erlang processes.That misses the point of Erlang pretty badly, which is that processes are extremely
 lightweight (i.e. normally they are microthreads) so you can have millions of them active simultaneously (e.g. one for each active telephone connected to a big phone switch).Thanks for the clarification (I had only cursorily looked at them).
 Right now I want to check out GHCI (the Glasgow Haskell compiler), which may be the closest thing to a winner: - very advanced language, even higher level than Python, once described
 by somebody as what Python should have become - native code compilation - lock-free concurrency using software transactional memory (STM)Thanks for this. I'll check it out!!
Best,R.--http://mail.python.org/mailman/listinfo/python-list-- Dr. Andre P. Meyer
http://python.openspace.nl/meyerTNO Defence, Security and Safetyhttp://www.tno.nl/Delft Cooperation on Intelligent Systems
http://www.decis.nl/Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: best small database?

2006-09-11 Thread Andre Meyer
buzhug is a nice one: http://buzhug.sourceforge.net/ (not sure about binaries, though).greetingsAndreOn 9/11/06, 
km [EMAIL PROTECTED] wrote:
checkout gadfly database.regards,KMOn 9/11/06, David Isaac
 [EMAIL PROTECTED] wrote:

I have no experience with database applications.This database will likely hold only a few hundred items,including both textfiles and binary files.I would like a pure Python solution to the extent reasonable.
Suggestions?Thank you,Alan Isaac--http://mail.python.org/mailman/listinfo/python-list


--http://mail.python.org/mailman/listinfo/python-list
-- Dr. Andre P. Meyerhttp://python.openspace.nl/meyerTNO Defence, Security and Safety
http://www.tno.nl/Delft Cooperation on Intelligent Systemshttp://www.decis.nl/Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Building Python Based Web Application

2006-09-09 Thread Andre Meyer
Karrigell can really be recommended. Simple, but powerful. No need for SQL (though it can), just use the pure Python buzhug, Karrigell services and (Cheetah) templates. Works great.regardsAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: the first arg to super() must be a type, not a class obj?

2006-09-08 Thread Andre Meyer
Another thing: how does super() work wrt. multiple inheritance? It seems like it returns only the first superclass.regardsAndreOn 9/8/06, 
Georg Brandl [EMAIL PROTECTED] wrote:
metaperl wrote: On p.282 of Python Cookbook and in the Python docs on calling super: http://www.python.org/download/releases/2.2.3/descrintro/#cooperation
 it is clear that the first argument to super is a class and not a type. However, for the code below, I am getting an error when attempting to provide a class as my first argument and don't understand why. Also,
 since this is my first attempt at writing anything of any seriousness in Python, any other feedback is welcome.super only works for new-style classes.You could make ftputilx new-style by inheriting from object and FTPHost,
but FTPHost is still old-style, and I don't know if that's okay with super.So in your case it would be advisable to useFTPHost.__init__(self)instead ofsuper(ftputilx, self).__init__()
Georg--http://mail.python.org/mailman/listinfo/python-list-- Dr. Andre P. Meyer
http://python.openspace.nl/meyerTNO Defence, Security and Safetyhttp://www.tno.nl/Delft Cooperation on Intelligent Systems
http://www.decis.nl/Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: IDE

2006-09-06 Thread Andre Meyer
http://pydev.sourceforge.net/http://wiki.python.org/moin/PythonEditors
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python vs java

2006-09-06 Thread Andre Meyer
http://www.ferg.org/projects/python_java_side-by-side.html
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: threading support in python

2006-09-05 Thread Andre Meyer
This seems to be an important issue and fit for discussion in the context of Py3k. What is Guido's opinion?As a developer of a multi-threaded system I would like to know more about these issues, so it's no time wasted for me... ;-)
regardsAndreOn 9/5/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Steve Given the effort that GIL-removal would take, I'm beginning toSteve wonder if PyPy doesn't offer a better way forward than CPython,
Steve in terms of execution speed improvements returned perSteve developer-hour.How about execution speed improvements per hour of discussion about removingthe GIL? ;-)

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

Re: dictionaries vs. objects

2006-08-31 Thread Andre Meyer
On 8/28/06, Steve Holden [EMAIL PROTECTED] wrote:
Andre Meyer wrote: Hi all I have the following question: I need a representation of a physically inspired environment. The environment contains a large number of objects with varying attributes. There may be classes of objects, but there is
 not necessarily a strictly defined hierarchy among them. Object access should be fast, because there a many objects that change often ( e.g., moving objects). My approach is to use a dictionary for the environment model and store
 each object as a slot, which contains either a dictionary or an object. Now, which is better? What is the performance of Python to look up attributes as either slots of a dictionary or attributes of an object?
 What feels more logical? What is more pythonic and performs better? Which is constructed and modified easier and quicker? Are there effects that I am not yet aware of?I'd suggest using objects: quite apart from the fact that name lookup in
a namespace is pretty much equivalent to a dictionary lookup (namespacesuse an internal optimised dictionary-style object) remember that objectscan have methods, and that the names are given as attributes rather than
as strings.From another thread I learned that lookup in dictionaries is way faster than accessing object attributes (which makes use of an internal dictionary). However, the syntax is cleaner with objects and having methods and properties is a plus. So, it seems like it is about speed vs. elegance...
regardsAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Andre Meyer
Hi allIt might be interesting to watch the videos about Django and Rails (http://www.djangoproject.com/snakesandrubies/). Django makes a good impression, although I would not agree with all of their arguments (eg. templating language, ajax). Most striking, though, is the difference in attitude! While Django grew out of a production environment and solves real problems very elegantly, Rails comes out of beauty, whatever that means. Is Ruby code more beautiful than Python - don't think so.
Nevertheless, I agree with original statement that we Python guys need to look very closely at Ruby and why they are able to catch so much attention. There are good things in the language and Python marketing could certainly be improved. The new web site and logo are good steps in the right direction. Now for free t-shirts to create pervasive awareness? ;-)
regardsAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Persistent Session in CGI

2006-08-27 Thread Andre Meyer
Karrigell is a very easy-to-use pure-Python web framework. It has examples of session management.http://karrigell.sourceforge.net/regardsAndre
On 27 Aug 2006 14:48:05 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:Hi,I have started a new small web project, and was wondering if there are
any good guides on how to do Persistent Sessions and Authenticationusing python and CGI. I don't really want too use Zope, because It'sprobably overkill for my tiny project.--
http://mail.python.org/mailman/listinfo/python-list-- Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safetyhttp://www.tno.nl/Delft Cooperation on Intelligent Systemshttp://www.decis.nl/Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python

2006-08-26 Thread Andre Meyer
http://www.python.org/download/releases/2.4/bugs/IDLE now executes code in a separate process.  To communicate
between the main process and executing processes, IDLE opens a
socket to 127.0.0.1 (the local machine).  Some firewalls running on
Windows machines interfere with this and can cause either silent
failures or erroneous popup windows from the firewall.  This problem
only occurs if you run a firewall on the same machine as IDLE.
hthAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

performance of dictionary lookup vs. object attributes

2006-08-25 Thread Andre Meyer

Hi all

I was wondering about the performance comparison of either using a
dictionary or an object for a large collection of things. Therefore
I have run the attached test. I create a dictionary and an object.
Both get the same number of items/attributes, respectively. Then, for
both the values are read often (iterations).

Here are the results:

attributes 100
iterations 100
dic 25.515999794
obj 138.57172

Is the test meaningful and are you surprised by the results? I am,
actually, because I would have assumed that attribute access with an
object should be faster because lookup can be precompiled.

kind regards
Andre
import time
import random

ITERATIONS = 100
ATTRIBUTES = 100

class O(object):
pass

class Test(object):
def __init__(self):
self.attributes = []
self.dic = {}
self.obj = O()

for i in range(ATTRIBUTES):
value = 
for s in range(12):
value = value + chr(random.randint(ord('a'), ord('z')))
#print value

attr = 
for s in range(6):
attr = attr + chr(random.randint(ord('a'), ord('z')))
#print attr

self.attributes.append(attr)
self.dic[attr] = value
self.obj.__setattr__(attr, value)

print attributes, len(self.attributes)

def run_dic(self):
t0 = time.time()
for i in range(ITERATIONS):
for a in self.attributes:
v = self.dic[a]
#print i, v
t1 = time.time()
return t1 - t0

def run_obj(self):
t0 = time.time()
for i in range(ITERATIONS):
for a in self.attributes:
v = self.obj.__getattribute__(a)
#print i, v
t1 = time.time()
return t1 - t0

print iterations, ITERATIONS

t = Test()
td = t.run_dic()
to = t.run_obj()

print dic, td
print obj, to
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: performance of dictionary lookup vs. object attributes

2006-08-25 Thread Andre Meyer
Good points! It's always good to learn from the pros!

So, what it means is that the test is not meaningful, because of the
different way that object attributes are accessed (not as o.x, which
could be compiled).

Nevertheless, the general impression remains that dicts *are* faster
than objects, because attribute lookup uses dicts itself. Is that
correct?

thanks
Andre


On 8/25/06, Fredrik Lundh [EMAIL PROTECTED] wrote:
 Andre Meyer wrote:

  Is the test meaningful and are you surprised by the results?

 surprised by the amount of code you needed to test this, at least.  and you
 might wish to use the proper spelling for

 v = self.obj.__getattribute__(a)

 which is

 v = getattr(obj, a)

 and is quite a bit faster, at least in CPython.

 (you should also use setattr() instead of __setattr__; in general, if you 
 find your-
 self *calling* a method named __method__, there's most likely a better way to
 do it).

  I am, actually, because I would have assumed that attribute access with an
  object should be faster because lookup can be precompiled.

 huh?  you're using a reflection API; there's no way the compiler can figure 
 out
 in advance what you're going to pass to getattr().

 /F



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



-- 
Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safety  http://www.tno.nl/
Delft Cooperation on Intelligent Systems  http://www.decis.nl/

Ah, this is obviously some strange usage of the word 'safe' that I
wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list


dictionaries vs. objects

2006-08-24 Thread Andre Meyer
Hi allI have the following question: I need a representation of a physically inspired environment. The environment contains a large number of objects with varying attributes. There may be classes of objects, but there is not necessarily a strictly defined hierarchy among them. Object access should be fast, because there a many objects that change often (
e.g., moving objects).My approach is to use a dictionary for the environment model and store each object as a slot, which contains either a dictionary or an object. Now, which is better? What is the performance of Python to look up attributes as either slots of a dictionary or attributes of an object? What feels more logical? What is more pythonic and performs better? Which is constructed and modified easier and quicker? Are there effects that I am not yet aware of?
thanks for your thoughtsAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to download a web page just like a web browser do ?

2006-08-23 Thread Andre Meyer
You get websucker.py in the standard Python installation. On Win look at C:\Python24\Tools\webchecker or similar.regardsAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: state of SOAP and python?

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

Re: Best IDE for Python

2006-08-15 Thread Andre Meyer
PyDev is really nice. I use it a lot and it works great.It's just a bit heavy and why should one need a Java IDE for Python development ;-)Another issue is the lack of integration with a UML tool (code generation and reverse engineering), though an ArgoUML plugin is in the making (not for eclipse).
btw What Web/XML plugins are you using with eclipse?regardsAndreOn 15 Aug 2006 09:03:44 -0700, 
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
I've had a similar experience and tried about everything.Personally -eclipse with PyDev has been the winner for me.I also still do a bunchof Java coding - so there is an added benefit of one tool acrosslanguages.The final thing I really like with eclipse is the svn
plugins - making life very easy.Also, if your doing web/xml and otherstuff - there is a plugin for eclipse for it ;)Not all the pluginswork as seemlessly together (i abandon eclipse for the majority of
plone/zope stuff - most of it isn't python - and setting up eclipse tobe happy with the output of archgen has not been worth the bother - I'msure it's possible)PyLint can kind of be a pain if your on a low powered box, but tweaking
the settings (and I had to do a bit of tweaking) can alleviate theproblems, but still let you reap the benefits.AnandYu-Xi Lim wrote: Michiel Sikma wrote:  By FOS, do you mean FOSS (Free and Open Source Software)? I've never
  seen the acronym FOS used. Maybe he was trying for Free Open Source IDE without the semi-redundant Software  I personally use Eclipse with PyDev.
  http://www.eclipse.org/  http://pydev.sourceforge.net/ Eclipse+PyDev has the advantage over emacs when it comes to big
 projects, IMO. It has features like refactoring, better project management, code coverage. emacs has the advantage of being faster and smaller, and if all you need is a syntax-aware (smart indentation,
 syntax highlighting) editor and integrated debugger, emacs is more than enough. I've tried the other free IDEs like IDLE, SPE, eric3, TruStudio (for Eclipse), Boa, Komodo, WingIDE. I have various issues with them,
 including instability, poor automatic indentation, bad GUI (too many subwindows or uncustomizable), costly, no refactoring, and no project management. It's strangely ironic. I consider Eclipse to be a lousy Java IDE
 especially compared to commercial offerings and yet that's what the project started out as.--http://mail.python.org/mailman/listinfo/python-list
-- Dr. Andre P. Meyerhttp://python.openspace.nl/meyerTNO Defence, Security and Safety
http://www.tno.nl/Delft Cooperation on Intelligent Systemshttp://www.decis.nl/Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Easy to use distributed system?

2006-08-14 Thread Andre Meyer
Hi allWe are using Pyro, too, for our Multi-Agent System framework Spyse (http://spyse.sf.net). We support mobile agents, distributed environments, various threading models and a lot more.
Just ask if you are interested, but use the svn version, mot the 0.1 download. Our 1.0 release should be coming with a month.kind regardsAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: class variables

2006-08-08 Thread Andre Meyer
On 7/31/06, Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 Colin J. Williams wrote:
  Andre Meyer wrote:
  Hi all
 
  I am trying to understand the magic of Python's class variables and
  tried the following code (see below).
 
  Just out of curiosity, I tried to define a property that provides
  access to a seemingly instance variable which is in fact a class
  variable.

 [...]

 I'm afraid there are too much problems with indentation in the posted
 code to give any serious answer.


So, here we go again (plain formatting).

The following code shows two versions of using class variables. The
first one uses the __class__ attribute directly and works. The second
one tries to hide the __class__ attibute with the help of a property,
which does not work, because an assignment in the instance replaces
the property with the assigned value.

Any idea how the second version could be fixed with either a property
and/or a decorator?

thanks for your help
André



class Value(object):
def __init__(self, i):
self.i = i

def work(self):
return 'done', self.i


print; print *** Case A ***; print

class ClassA(object):
v = None

def __init__(self, value):

print '-', self.v
self.__class__.v = Value(value)
print '+', self.__class__.v

@classmethod
def value1(self):
print self.v.work()
return self.v

def value2(self):
print self.__class__.v.work()
return self.__class__.v


va1 = ClassA(1)
va2 = ClassA(2)
print va1.value1()
print va1.value2()
print va1.v
print va1.__class__.v
print va1.v.work()


print *** Case B ***; print

class ClassB(object):

def __set_v(self, v): self.__class__.__v = v
def __get_v(self): return self.__class__.__v
def __del_v(self): del self.__class__.__v
#v = property(__get_v, __set_v, __del_v, 'make class variable')
v = None

def __init__(self, value):
self.v = property(self.__get_v, self.__set_v, self.__del_v,
'make class variable')

print '-', self.v
self.v = Value(value)
print '+', self.v

@classmethod
def value1(self):
print self.v.work()
return self.v

def value2(self):
print self.v.work()
return self.v

vb1 = ClassB(1)
vb2 = ClassB(2)
print vb1.value2()
print vb1.v
print vb1.__class__.v
print vb1.v.work()
-- 
http://mail.python.org/mailman/listinfo/python-list

singleton decorator

2006-08-07 Thread Andre Meyer
While looking for an elegant implementation of the singleton design pattern I came across the decorator as described in PEP318.Unfortunately, the following does not work, because decorators only work on functions or methods, but not on classes.
def singleton(cls):instances = {}def getinstance():if cls not in instances:instances[cls] = cls()
return instances[cls]return getinstance@singletonclass MyClass:...Am I missing something here? What is the preferred pythonic way of implementing singleton elegantly?Thanks for your help
André
-- 
http://mail.python.org/mailman/listinfo/python-list

class variables

2006-07-27 Thread Andre Meyer
Hi allI am trying to understand the magic of Python's class variables and tried the following code (see below).Just out of curiosity, I tried to define a property that provides access to a seemingly instancae variable which is in fact a class variable. All seems to work fine (case 4), but when a custom object is assigned, an instance variable is created instead of using theproerty (case 5).
What goes wrong here? What is the difference between cases 4 and 5? How can case 5 be fixed?thanks a lot for your helpAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

class variables

2006-07-27 Thread Andre Meyer
Hi allI am trying to understand the magic of Python's class variables and tried the following code (see below).Just
out of curiosity, I tried to define a property that provides access to
a seemingly instancae variable which is in fact a class variable. All
seems to work fine (case 4), but when a custom object is assigned, an
instance variable is created instead of using theproerty (case 5).
What goes wrong here? What is the difference between cases 4 and 5? How can case 5 be fixed?thanks a lot for your helpAndreCode Listing=print; print *** Case 1 ***; print
class C1(object):  v = None  def __init__(self, value): print '-', self.v self.v = value  def value(self): return self.v a1 = C1(1)
b1 = C1(2)print a1.value()print; print *** Case 2 ***; printclass C2(object):  v = None  def __init__(self, value): print '-', self.v self.__class__.v = value
  def value(self): return self.__class__.v a2 = C2(1)b2 = C2(2)print a2.value()print; print *** Case 3 ***; printclass C3(object):  v = 5
  def __init__(self, value): print '-', self.v self.v = self.v + value  def value(self): return self.v a3 = C3(1)b3 = C3(2)print a3.value()
print a3.vprint a3.__class__.vprint; print *** Case 4 ***; printclass V4(list): def work(self): return 'done' class C4(object):  def __set_v(self, v): self.__class__.__v = v 
 def __get_v(self): return self.__class__.__v def __del_v(self): del self.__class__.__v v = property(__get_v, __set_v, __del_v, 'make class variable') v = V4()  def __init__(self, value):
 print '-', self.v self.v.append(value) print '+', self.v  @classmethod def value(self): print self.v.work() return self.v a4 = C4(1)
b4 = C4(2)print a4.value()print a4.vprint a4.__class__.vprint a4.v.work()print; print *** Case 5 ***; printclass V5(object): def __init__(self, i): self.i
 = i  def work(self): return 'done', self.i class C5(object):  def __set_v(self, v): self.__class__.__v = v  def __get_v(self): return self.__class__.__v
 def __del_v(self): del self.__class__.__v v = property(__get_v, __set_v, __del_v, 'make class variable') v = None  def __init__(self, value): print '-', self.v self.v
 = V5(value) print '+', self.v# print self.__class__.__dict__# print self.__dict__  @classmethod def value(self): print self.v.work() return self.v
 a5 = C5(1)b5 = C5(2)print a5.value()print a5.vprint a5.__class__.vprint a5.v.work()Output=*** Case 1 ***- None- None1*** Case 2 ***
- None- 12*** Case 3 ***- 5- 5665*** Case 4 ***- []+ [1]- [1]+ [1, 2]done[1, 2][1, 2][1, 2]done*** Case 5 ***
- None+ __main__.V5 object at 0x00AFE0D0- None+ __main__.V5 object at 0x00AFE110Traceback (most recent call last): File classvariables.py, line 121, in ? print a5.value
() File classvariables.py, line 115, in value print self.v.work()AttributeError: 'NoneType' object has no attribute 'work'
-- 
http://mail.python.org/mailman/listinfo/python-list