Re: OO in Python? ^^

2005-12-11 Thread Ernst Noch
Matthias Kaeppler wrote:
> Brian Beck wrote:
> 
>> def foo(self):
>> raise NotImplementedError("Subclasses must implement foo")
> 
> 
> That's actually a good idea, though not as nice as a check at 
> "compile-time" (jesus, I'm probably talking in C++ speech again, is 
> there such a thing as compile-time in Python at all?!)
> 
> Another thing which is really bugging me about this whole dynamically 
> typing thing is that it seems very error prone to me:
> 
> foo = "some string!"
> 
> # ...
> 
> if (something_fubar):
>fo = "another string"
> 
> Oops, the last 'o' slipped, now we have a different object and the 
> interpreter will happily continue executing the flawed program.
> 
> I really see issues with this, can anyone comment on this who has been 
> working with Python more than just a day (like me)?
> 
> Regards,
> Matthias

Matthias,

maybe this article is of interest for you:
http://www.mindview.net/WebLog/log-0025

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


Re: making fractals in python

2005-12-12 Thread Ernst Noch
evil_daffid wrote:
> hi,
> Im reseaching fractals, and how to make them in python using recursion.
> I've written a bit of code to make the   koch isalnd   but something isn't
> right, I have the basic shape but there's something wrong with the
> recursion i've used, could someone help me.
> 
> Here is the code im using:
> 
[Code snipped]

Is this a homework assignment or something?

Anyway, this is a little bit more pythonic and flexible, though my 
python has gotten a little bit rusty. It uses L-Systems for state storage.
Recursion is only left in because you asked for it.
Iterate() should get more sophisticated for more complex string 
substitutions.

import turtle
turtle.clear

class fractal(object):

 def __init__(self, lstring, rule, line_length, angle, 
shrink_factor):
 self.lstring = lstring
 self.rule = rule
 self.line_length = line_length
 self.angle = angle
 self.shrink_factor=shrink_factor

 def draw(self):
 drawingdict = {'F': lambda: turtle.forward(self.line_length),
'-':lambda: turtle.right(self.angle),
'+':lambda: turtle.left(self.angle),}
 for rule in self.lstring:
 drawingdict[rule]()

 def iterate(self):
 self.lstring = self.lstring.replace(rule[0],rule[1])
 self.line_length=self.line_length/self.shrink_factor

def recurse(f,smallest):
 if f.line_length>=smallest:
 turtle.reset()
 f.iterate()
 f.draw()
 recurse(f,smallest)

if __name__=='__main__':
 start = 'F+F+F+F'
 rule = ('F','F+F-F-FF+F+F-F')
 f = fractal(start,rule,50,90,2)
 recurse(f,10)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Providing 'default' value with raw_input()?

2005-12-28 Thread Ernst Noch
Alex Martelli wrote:

> In some situations it may be impractical to rely on the editor closing;
> for example, the user's favorite editor might be a multitab one that's
> big, heavy, and slow to start, so that the user doesn't close the whole
> process but rather just a specific tab.  In such cases, unless you can
> build in some hook specific to the user's favorite editor (so you can
> know when a specific tab/file is done getting edited), you may end up
> requiring the user to press enter at your prompt to indicate he or she's
> done editing, or some such semi-kludge.  I cannot think of a
> sufficiently general solution, given the variety of editors around, to
> just magically divine the crucial "done with editing" condition...
> 
> 
> Alex

The ExternalEditor product for Zope does this in a quite clever way - 
probably not perfect, but it worked for me every time in windows and linux.
The product is used to be able to edit any Zope object in an external 
editor and automatically transfer the edited file from the client to the 
server after save.

The source can be found at http://plope.com/software/ExternalEditor.


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


Re: predicting function calls?

2005-12-31 Thread Ernst Noch
Roy Smith wrote:
> I think I know the answer to this, but I'll ask it just in case
> there's something I hadn't considered...
> 
> I'm working on a python interface to a OODB.  Communication with the
> DB is over a TCP connection, using a model vaguely based on CORBA.
> I'll be creating object handles in Python which are proxies for the
> real objects in the database by doing something like:
> 
> handle = connection.getObjectHandle (className, instanceName)
> 
> Objects can have attributes (data) and operations associated with
> them.  It would be very convenient to use the "." syntax to access
> both of these, i.e. be able to say:
> 
> print handle.someAttribute
> print handle.someOperation (arg1, arg2)
> 
> I'm using __getattr__() to process both of these constructs, and
> herein lies the rub; I need to do different things depending on
> whether the name is an attribute or an operation.  I can ask the DB
> for a list of the names of all the operations supported by a given
> object, but that's a fairly expensive thing to do, so I'd rather avoid
> it if possible.  It would be really nice if I had some way to find
> out, from inside __getattr__(), if the value I'm about to return will
> get called as a function (i.e., the name is followed by an open
> paren).  I can't see any way to do that, but maybe I'm missing
> something?
> 

For various reasons also mentioned by other posters it's also not clear 
to me how relying on user input should work. Esp. for the

x=obj.meth
print x(args)

case.

Couldn't you just, for every access to a member of your object, first 
try to treat is as an access to an operation? If this fails (you 
mentioned the db will throw an error if this is an attribute instead of 
an operation), fall back to ask the db for an attribute of that name.

Or maybe just ask the db to look up this attribute in the list of 
operations, depending which is faster.

Btw. if the system is very dynamic, you might have to think about also 
implementing the attributes as proxies.


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


Re: Application architecture (long post - sorry)

2006-01-01 Thread Ernst Noch
[EMAIL PROTECTED] wrote:
> Hi all,
> 
> I want to create a mobile field worker data solution.
> 
> Let me explain...
> 
> I work for a company that has some software used by call takers to
> enter information into a database about faults with electrical
> appliances they manufacture, sell to customers, and then provide
> maintenance contracts for.
> 
> The company has a number of field workers (growing number) servicing
> these appliances, and information about the faults and customer
> locations is fed to them by printing off job sheets from the call
> taking system and then either faxing them to the engineers or the
> engineers drop in to the office and collect them.
> 
> There are lots of problems with this, such as lost job information,
> incomplete forms, incorrect non validated data, the cost of printing
> off job sheets and also the engineers having to collect, regular phone
> calls to the engineers to update them on call informtion, and then the
> fact that all this data then has to be inputted back into another
> system manully.
> 
> Basically I want to create a means of getting this data to them
> electronically.
> 
> I know there are a few companies who could provide this solution but
> they are very expensive and possibly overkill at the moment, we could
> start developing our own basic system then it can grow over time.

Just one advise from my personal experience:

Don't build it yourself.

This part of your company seems to be growing, and a number of 60 field 
engineers is already considerable.
So, processes will change, managers will ask for specific KPIs, the need 
will come up to dispatch engineers based on their location/skillset etc. 
etc.
You might run into technical problems with the client appliances 
(compability) if you don't do extensive testing.
So, soon a commercial application might not be overkill anymore, but you 
already have a Big Ball of Mud sitting there.
( http://www.laputan.org/mud/mud.html#PiecemealGrowth )

All in all you should at least do a careful cost comparison between 
commercial off-the-shelf software (COTS) and inhouse development for
the next 3 to 5 years.
Don't understimate testing and training costs and the change of your 
business.

I could see two alternatives:
1. Buy a COTS package which has the big additional benefit of being 
implemented for some tried and tested processes, so that your company 
doesn't have to reeinvent their processes from scratch (it worked with 
SAP, didn't it ;) )
2. Go the super cheap route, like buying a blackberry package from a 
local mobile provider and send the jobs to the engineers via email.
The neat thing is that it pushes out the mails to the clients.
Maybe there are also some ready made packages to implement some forms on 
the blackberry's email client.
That way, you have the alternative of cheaply learning how things go in 
practice, and refine the requirements.







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


Re: Python article in Free Software Magazine

2006-01-01 Thread Ernst Noch
Steven D'Aprano wrote:
> On Sun, 01 Jan 2006 06:09:14 -0500, Dan Sommers wrote:
> 
> 
>>On Sun, 01 Jan 2006 18:06:10 +1100,
>>Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>>
>>
>>>I don't want to nit-pick all my way through the article, which is very
>>>decent and is worth reading, but I will say one more thing: you
>>>describe Python as "an expressive, interpreted language" ...
>>
>>So does .
> 
> 
> Then it is time it stopped.
> 
> In fairness, from a technical perspective, describing Python as
> interpreted is not wrong -- as I've pointed out, machine code is
> interpreted too -- but neither does it give the correct impression.
> Many people have argued that the terms interpreted and compiled are no
> longer meaningful in this day and age. I wouldn't go that far, but given
> the negative connotations of "interpreted" I think it is both better and
> more accurate to emphasis the fact that Python code is byte-code compiled
> and only use the I-word when discussing Python's interactive environment
> and eval/exec. If I could think of another word for interpreter, I would
> use it even then.
> 
> People who are smart and care about correctness -- the "reality-based
> community" -- often don't realise just how many decisions are made on the
> basis of unfacts like "everybody knows interpreted languages are slow and
> inefficient, that's what my professor told me when I did a semester of C
> in 1982, we better stick to Java or .Net".
> 

Right on. Here's a tongue-in-cheek proposal for the python.org homepage 
to describe a combination of python, twisted and zope or something similar.
It yields a 10 on the buzzword meter, but is unfortunately blatantly stolen:

"""
Today, more and more developers want to write distributed transactional 
applications for the enterprise and leverage the speed, security, and 
reliability of server-side technology. If you are already working in 
this area, you know that in today's fast-moving and demanding world of 
e-commerce and information technology, enterprise applications have to 
be designed, built, and produced for less money, faster, and with fewer 
resources than ever before.

To reduce costs and fast-track enterprise application design and 
development, the Python Platform Enterprise Edition technology provides 
a component-based approach to the design, development, assembly, and 
deployment of enterprise applications. The Python Enterprise platform 
gives you a multitiered distributed application model, the ability to 
reuse components, a unified security model, and flexible transaction 
control. Not only can you deliver innovative customer solutions to 
market faster than ever, but your platform-independent Python 
component-based solutions are not tied to the products and APIs of any 
one vendor.

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


Re: Visualisation Engine for Python

2006-01-03 Thread Ernst Noch
rodmc wrote:
> I am looking for a 2D data visualisation or graphics library for
> Python. Can anyone point me in the right direction?
> 
> 
> Thanks in advance,
> 
> rod
> 

Maybe download and install the enthought python edition
from http://code.enthought.com/enthon/
Contains the following libraries which might be of interest
for you

# wxPython 2.6.1.0: wxWindows for Python
# PIL 1.1.4: Python Imaging Library
# VTK 4.4.2: 3D Visualization Toolkit
# MayaVi 1.3: 3D Data Visualization Tool
# Numeric 23.8: Numerical Python
# SciPy 0.3: Scientific Library for Python
# ScientificPython 2.4.5: A collection of Python modules for scientific 
computing
# Chaco 0.2.0: Plotting toolkit for Python

At least it's an easy way to play around with the different
toolkits and see them in action, there are a lot of demos
included.

And then there are gnuplot bindings for python:
http://gnuplot-py.sourceforge.net/

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


Re: Calling GPL code from a Python application

2006-01-04 Thread Ernst Noch
Heiko Wundram wrote:
> Terry Hancock wrote:
> 
>>Given that Google has been using this fact extensively, and
>>they have not been sued over it, I think it's a fairly
>>clearly established interpretation, whether it is popular or
>>not (but of course it's not a legal precedent until somebody
>>does sue and loses).
> 
> 
> This is not what the general interpretation of the GPL seems to be with
> TrollTech and several other companies. They specifically state that even
> when you develop inhouse software with GPL-libraries (Qt in the former
> case), you are required to release the code of the application under the
> GPL. 

This is not true, and a often misunderstood issue w.r.t. to Trolltech/QT.

 From the FAQ:

Entry number: 123 - I want to dual license my software too! That means I 
can use the Open Source edition for development, right?

"""
No. In order to write software that will be sold or licensed 
commercially, in addition to open source, all of your programmers will 
need a commercial license from the outset of the development phase.

If you use the Open Source edition of Qt, you can only publish the 
software under the GPL. Trolltech's commercial license terms do not 
allow you to develop any proprietary software using the Open Source edition.
"""

What happens is that the Commercial License prohibits that it is 
"transfered" to software developed with the GPL Version.




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


Re: Calling GPL code from a Python application

2006-01-04 Thread Ernst Noch
Mike Meyer wrote:
> Heiko Wundram <[EMAIL PROTECTED]> writes:
> 
>>I've asked TrollTech more than once for their stance on this, and each time
>>they have told me that it's illegal for me to develop an inhouse
>>application (such as a frontend to some webapp I've written that's only
>>used by us and will never ever be given away commercially) using the Open
>>Source edition of Qt (which I have not commercially licensed, of course,
>>which is way to expensive for me and Uni won't pay), unless I convince the
>>people at my univ to _release_ the code I've written under a GPL-compatible
>>open source license itself.
> 
> 
> I can't see how they could *require* you to release the code. The GPL
> certainly doesn't (or didn't) require that. Possibly they have a
> GPL-compatible license that adds that requirement.

No, they use the pure GPL. And that's what I was trying to get at in 
another post. What they are doing is prohibiting *in their commercial 
license* that you apply it on projects previously developed under the 
GPLed QT.

Obviously some individuals from the company have a different opinion, 
but I found another FAQ entry which states it clearly (note the phrase 
"non-opensource" in the question).

Note: Esp. concerning open source, I still think it's a good idea to 
repect the wishes of a rights owner even if the license he grants might 
be more permissive.

"""
Entry number: 190 - Using the Qt Open Source Edition, can I make 
non-opensource software for internal use in my company/organization?
Answer:

No. Software developed with the Qt Open Source Edition is always open 
source software, i.e. it can only be distributed under a open source 
software license. In particular, all the source code for all the modules 
your software is based on, regardless of whether they have been written 
by you or by others, must be open source software (because of the 
"viral" nature of the GPL). This is part of our commitment to the open 
source software community, and enables those who contribute to the open 
source software pool to do so without paying license fees.

Although it is possible to write open source software for internal use, 
it is difficult to ensure that such software is used and distributed 
legally. For example, if your open source software requires any modules 
that impose conditions on you that contradict the conditions of the GNU 
GPL, including, but not limited to, software patents, commercial license 
agreements, copyrighted interface definitions or any sort of 
non-disclosure agreement, then you cannot distribute it at all; hence it 
cannot be given to consultants, employees for their personal computers, 
subsidiaries, other divisions, or even to new owners.
Consequently we recommend using commercial licenses for all internal 
software development.

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


Re: Calling GPL code from a Python application

2006-01-04 Thread Ernst Noch
Mike Meyer wrote:

> In my case, I get paid for building custom applications. If I use
> GPL'ed software, I'm required to give my client the software under the
> GPL (or, as you point out, a GPL-compatible license). I never bother -
> I hand them a tarball and installation instructions and they install
> it on their systems, or I install the stuff on their systems for them,
> and it never goes anywhere else. I believe that's in compliance with
> the GPL, because they get all the rights that the GPL wants them to
> have. 

  [snip]

Yeah, and you are in absolute compliance with what the FSF intends the 
GPL to be:

http://www.gnu.org/philosophy/selling.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling GPL code from a Python application

2006-01-04 Thread Ernst Noch
Heiko Wundram wrote:
> Heiko Wundram wrote:
> 
>>..., unless I convince the
>>people at my univ to _release_ the code I've written under a
>>GPL-compatible open source license itself.
> 
> 
> The can of worms in this is basically that management at my uni doesn't want
> employees to take the software home and release it there, which would be
> allowed if I were to put it under GPL but released it only inhouse.
> 
> --- Heiko.

They can prohibit this. There a various ways how, independent from the 
license. Basically the same way how an employer can prohibit you to 
download any software on your workplace and take it home, even if the 
download was completely legal.

But the simplest reasoning is that the code _you_ have is owned by you 
or probably your university. Therefore making a copy of the complete 
package is illegal for the employees under copyright law unless 
expressly permitted by the license to _your_ code, even if everything 
else is GPL.

And your portion of the code doesn't have to be GPL, because you are not 
distributing it!

Note, this would even work if you weren't "part" of your University, 
because nowhere does the GPL mandate

a) That you have to distribute the software at all
b) To whom you have to distribute the software

That means that your University just can refuse to distribute the 
software to anybody else. And if someone steals the software from them, 
that isn't distribution.










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


Re: Occasional OSError: [Errno 13] Permission denied on Windows

2006-01-05 Thread Ernst Noch
Alec Wysoker wrote:
>>>Using Python 2.3.5 on Windows XP, I occasionally get OSError: [Errno
>>>13] Permission denied when calling os.remove().  This can occur with a
>>>file that is not used by any other process on the machine,
>>
>>How do you know that?
> 
> 
> Yeah, good point.  I don't really know.  I should have said no process
> that I am aware of is using the file.  I'll give sleep a try instead of
> gc.  Thanks.

FWIW, you could use Filemon from Sysinternals, 
http://www.sysinternals.com/Utilities/Filemon.html

If you are there, be sure to also look the other stuff on that side, 
Mark Russinovich a has written a lot of very nice Windows utilities.




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


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Ernst Noch
Mike Meyer wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
> 
>>Thinking about Python's behaviour ("it always passes references to
>>objects") will invoke misleading frames in many programmers' minds. The
>>word "reference" is misleading and should be avoided, because what the
>>average non-Python programmer understands by the word is different from
>>what the experienced Pythonista understands by it.
> 
> 
> Yes, but it's not misleading because "reference" doesn't mean what
> they think it means. "reference" means the same thing in Python as it
> does in C and similar languages. It's misleading because "variables"
> and "assignment" in Python don't do the things they do in C. Some of
> the places that this shows up is when you're dealing with call by
> reference, or with references in a list.


Maybe next time showing something like the following trivial snippet 
might help demonstrate that the core of the matter doesn't is not the 
way python treats parameters?

>>> def func(param, what):
if what:
param['foo'] = 'changed'
else:
temp = param['foo'] # temp is _not_ a reference!
temp = 'changed'

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


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Ernst Noch
Mike Meyer wrote:
> Ernst Noch <[EMAIL PROTECTED]> writes:
> 
>>Maybe next time showing something like the following trivial snippet
>>might help demonstrate that the core of the matter doesn't is not the
>>way python treats parameters?
> 
> 
> Did you insert an extra "doesn't" in that? If so, then I agree about
> what isn't the core of the matter.

Uhm, yes. Seems the whole message was written too hastily.

> 
> On the other hand, the snippet doesn't help without an
> explanation. Especially with misleading comments.

Absolutely, it was mainly meant as an example to demonstrate in practice 
that the way python passes parameters has nothing to do with what happens.

> 
> 
>>>>>def func(param, what):
>>
>>  if what:
>>  param['foo'] = 'changed'
>>  else:
>>  temp = param['foo'] # temp is _not_ a reference!
> 
> 
> Except temp *is* a reference. What it's not is a reference to
> param['foo']. Instead, it's a reference to the same object that
> param['foo'] is a reference to.
> 

Oh dear, yes. I inserted that comment as an afterthought.




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


Re: Copy an Object (Again?)

2006-01-06 Thread Ernst Noch
KraftDiner wrote:
> I'm having trouble getting a copy of and object... (a deep copy)
> 
> I'm writing a method that creates a mirror image of an object (on
> screen)
> In order to do this i need to get a copy of the object and then modify
> some
> of its attributes.
> 
> I tried:
> objs = myListOfObjects
> for obj in objs:
>if obj.flag:
>   newObject = copy.deepcopy(obj)
>   newObject.mirror()
>   myListOfObjects.append(newObject)
> 
> That doesn't seem to work.. the new object seems to disapear from
> existance.
> I'm wondering if its a bug in my application or if this is my shallow
> understanding of the language.
> 
> TIA
> B.
> 
Another remark, are you sure that your "for obj in objs" doesn't get you 
into an infinite loop?
If myListOfObjects is a normal list, your assignment

objs = myListofObjects

doesn't make a copy of the list:

 >>> MyListOfNumbers = [1,2,3,4]
 >>> numbs = MyListOfNumbers
 >>> MyListOfNumbers.append(5)
 >>> numbs
[1, 2, 3, 4, 5]

If anything, that makes your alorithm hard to read, because you are 
iterating over a list while appending to it.

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