Re: Boo who? (was Re: newbie question)

2004-12-21 Thread Ville Vainio
> "Doug" == Doug Holton <[EMAIL PROTECTED]> writes:

Doug> I already stated that I will not mention boo again, to
Doug> comply with Fredrik's wishes and yours.  I will refer to

Relax, and go ahead talking about Boo all you want. I for one enjoy
reading about it, and probably many others as well. Some people may
bitch about it, but, well, that's what people do on usenet.

Doug> only. But I will not be intimidated by the likes of Fredrik
Doug> Lundh.  Trollers will be held accountable.  If it continues

As mentioned elsewhere it's technically not trolling, but rather old
fashioned flaming. Usenet is free-for-all, so people can expect to be
flamed occasionally, often without good reason. It's quite rare in
c.l.py but it happens. Often all you can do is to swallow it, unless
the person in question just lost their temper for a moment and is
willing to apologize. That is not not always the case.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Operators as functions

2004-12-21 Thread Anders Andersson
Steve Holden wrote:
Anders Andersson wrote:
Hello
I want to concatinate (I apologize for bad English, but it is not my 
native language) a list of strings to a string. I could use (I think):

s = ""
map(lambda x: s.append(x), theList)
But I want to do something like (I think that the code above is clumsy):
s = reduce("concatinating function", theList, "")
And here is the questions: What to replace "concatinating function" 
with? Can I in some way give the +-operator as an argument to the 
reduce function? I know operators can be sent as arguments in Haskell 
and since Python has functions as map, filter and listcomprehension 
etc. I hope it is possible in Python too. In Haskell I would write:

foldr (++) []
Thank you for answering!
 >>> l = ["abc", "def", "ghi", "jkl"]
 >>> "".join(l)
'abcdefghijkl'
 >>> ", ".join(l)
'abc, def, ghi, jkl'
 >>>
regards
 Steve
Quiet unexpected, but very beautiful. I will use this! Thank you for 
replaying!

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


Re: Operators as functions

2004-12-21 Thread Anders Andersson
Peter Hansen wrote:
Anders Andersson wrote:
I want to concatinate (I apologize for bad English, but it is not my 
native language) a list of strings to a string. I could use (I think):

s = ""
map(lambda x: s.append(x), theList)
But I want to do something like (I think that the code above is clumsy):
s = reduce("concatinating function", theList, "")
And here is the questions: What to replace "concatinating function" 
with? Can I in some way give the +-operator as an argument to the 
reduce function? I know operators can be sent as arguments in Haskell 
and since Python has functions as map, filter and listcomprehension 
etc. I hope it is possible in Python too. In Haskell I would write:

You are looking for "import operator", followed by a use of
operator.add in the reduce() call.  Note, however, that you
cannot add different types (generally) together, so you will
run into trouble if you take the "naive" approach and just
trying concatenating the strings and the list as you show
above.  Instead, you will need to pass the sequence of
things through a call to map(str, sequence) first, to call
the str() method on everything and make sure you are adding
strings together.  Thus:
import operator
s = reduce(operator.add, map(str, theList))
or something like that.
However, none of this is considered the best approach these days,
with the advent of list comprehensions and generator expressions.
Here's the old approach (shown above) and the shiny new modern
Pythonic approach (requires Python 2.4):
 >>> theList = range(10)
 >>> import operator
 >>> reduce(operator.add, map(str, theList))
'0123456789'
 >>> ''.join(str(x) for x in theList)
'0123456789'
-Peter
Thank you for replaying. The operator.add is new to me and I will keep 
it in mind. It will perhaps come to use. I will use the join function 
since it looks more beatiful!

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


Re: Python To Send Emails Via Outlook Express

2004-12-21 Thread ian
Heavy sigh... 

==
This script WILL send the email
import win32com.client


s = win32com.client.Dispatch('CDO.Message')
c = win32com.client.Dispatch('CDO.Configuration')
cdoSourceOutlookExpress = 2
c.Load(cdoSourceOutlookExpress)
s.Configuration = c
s.From = "[EMAIL PROTECTED]"
s.To = "[EMAIL PROTECTED]"
s.Subject = "The subject"


s.Send()
==


==
But if a change the TO email address to a yahoo address the server
rejects it
import win32com.client


s = win32com.client.Dispatch('CDO.Message')
c = win32com.client.Dispatch('CDO.Configuration')
cdoSourceOutlookExpress = 2
c.Load(cdoSourceOutlookExpress)
s.Configuration = c
s.From = "[EMAIL PROTECTED]"
s.To = "[EMAIL PROTECTED]"
s.Subject = "The subject"


s.Send()
==

It's official. I have given up sending emails any other way but via
smtp.

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


Re: Is this a good use for lambda

2004-12-21 Thread Roel Schroeven
Alan G Isaac wrote:
I need a clarification of the argument.
Are the opponents saying that I should not be able to:
def compose(list_of_functions): return reduce(lambda f, g: lambda x:
f(g(x)), list_of_functions)
Personally, I think something like this is a place where lambdas are 
probably better than named functions. Still, you can do this without 
lambdas:

def compose(list_of_functions):
def compose2(f, g):
def func(x):
return f(g(x))
return func
return reduce(compose2, list_of_functions)

And may I see the proposed "better" replacement for function composition.
Whether this is better or not, I don't know.
--
"Codito ergo sum"
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: convert \uXXXX to native character set?

2004-12-21 Thread Christian Ergh
Miki Tebeka wrote:
Hello Joe,

   Is there any library to convert HTML page with \u encoded text to
  native character set, e.g. BIG5.
Try: help("".decode)
I use HTMLFilter.py, you can download it at
http://www.shearersoftware.com/software/developers/htmlfilter/
Cheers
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a good use for lambda

2004-12-21 Thread Roel Schroeven
Replying to myself, with a simpler version:
Roel Schroeven wrote:
Alan G Isaac wrote:
def compose(list_of_functions): return reduce(lambda f, g: lambda x:
f(g(x)), list_of_functions)
def compose(list_of_functions):
def compose2(f, g):
def func(x):
return f(g(x))
return func
return reduce(compose2, list_of_functions)
def compose(lof):
def func(x):
for f in reversed(lof):
x = f(x)
return x
return func
Still not sure what version is best though.
--
"Codito ergo sum"
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tabnanny really useful?

2004-12-21 Thread Franz Steinhaeusler
On Mon, 20 Dec 2004 13:00:39 -0600, "John Roth"
<[EMAIL PROTECTED]> wrote:

>Tabnanny is intended to check whether indentation
>has mixed tabs and spaces. Files with mixed tabs
>and spaces _can_ compile just fine if the editor
>that produced them agrees with the compiler about
>the number of spaces that a tab occupies.

Thanks for your explanation.

I tried an found:
def a():
->print 
->.print

where point is a space.

tabnanny here complains and python compile it just fine.
-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Operators as functions

2004-12-21 Thread Fredrik Lundh
Anders Andersson wrote:

> I want to concatinate (I apologize for bad English, but it is not my native 
> language)

fast det stavas iofs inte konkatinera på svenska heller ;-)

> a list of strings to a string.

> And here is the questions: What to replace "concatinating function" with? Can 
> I in some way give 
> the +-operator as an argument to the reduce function?

see the operator module.

but as other have already pointed out, turning a list of strings into a single
string is usually written as:

s = "".join(seq)

in contemporary Python, or

import string
s = string.join(seq, "")

in pre-unicode python style (note that in the first case, the "join" operation 
is
actually a method of the separator.  seq can be any object that can produce
a sequence.  it looks a bit weird, though...)

you can solve this by repeatedly adding individual strings, but that's rather
costly: first, your code will copy string 1 and 2 to a new string (let's call it
A).  then your code will copy A and string 3 to a new string B.  then your
code will copy B and string 4 to a new string C.  etc.  lots of unnecessary
copying.

the join method, in contrast, does it all in one operation.

 



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


Re: Tabnanny really useful?

2004-12-21 Thread Fredrik Lundh
Franz Steinhaeusler wrote:

> Thanks for your explanation.
>
> I tried an found:
> def a():
> ->print
> ->.print
>
> where point is a space.
>
> tabnanny here complains and python compile it just fine.

really?  that's a syntax error (you cannot change indentation nillywilly
inside a block), and the Python I'm using surely flags this as an error:

$ python -c "print repr(open('franz.py').read())"
'def a():\n\tprint\n\t print\n'

$ python franz.py
  File "franz.py", line 3
print
^
SyntaxError: invalid syntax

while tabnanny gives it one thumb up:

$ python -m tabnanny -v franz.py
'franz.py': Clean bill of health.

what Python version are you using?

 



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


Re: extending python with a C-written dll

2004-12-21 Thread Jean-Baptiste PERIN

That's got nothing to do with Python.  You have to compile
extensions using a compiler that has an ABI that's compatible
with the ABI of the compiler used to compile Python.
You appear to be using a binary distribution of Python that was
compiled with MSVS 6.0, therefore, you have to compile
extensions with a compiler that has an ABI compatible with MSVS
6.0.  

It's no use complaining to us bout your C compiler not being
ABI compatible with MSVS 6.0.
If you don't like MSVS, then your options are to either use a
different Python binary distro that was compiled with an ABI
that's compatible with your C compiler, or build just build it
yourself using whatever compiler you want. I suspect the latter
will also require re-compiling Blender.
According to what I read in this forum, MinGW is an interesting option..
do you know if it is ABI compatible with MSVC?
otherwise.. I'm gonna explore the solution which consist in building the 
dll with cygwin's gcc .. I've already recompiled Blender with gcc .. I 
know that, in Blender code, there are C++ function that are available 
from Blender's python ..
I've  started exploring the makefile.. apparently they are using dlltool 
 in conjonction with gcc ..

thank you very much for your help ..

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


Re: Best GUI for small-scale accounting app?

2004-12-21 Thread Phil Thompson
> I admit that I don't know much about Qt in Windows.  As, I said, I've
> never seen it.  The fact that they don't offer a GPLed version for
> Windows is a deterrent for me.
>
> I have heard very nice things about Qt's api.  I even bought a book on
> it, but since the apps I've needed to write, had to be cross platform,
> and were nicely done in wxPython/PythonCard on Windows *for free*, I
> haven't been able to justify the time to look at it.
>
> Question for you, does Qt use the native Windows dialogs and widgets or
> does it use its own?  If the latter, how close are they to the native
> look?  Will they change appearance when a user chooses a different
> theme in the Display Dialog?

By default Qt uses it's own except for the file dialog. By default the
native file dialog is used (but it can be disabled by reseting a bool that
isn't wrapped by PyQt). The same applies to MacOS.

Phil

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


Re: Why are tuples immutable?

2004-12-21 Thread Antoon Pardon
Op 2004-12-17, Jeff Shannon schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>>Op 2004-12-17, Jeff Shannon schreef <[EMAIL PROTECTED]>:
>>  
>>
>>
>>>(And I have to reiterate, here, that I have *never* felt it a hardship 
>>>to be unable to use lists as dictionary keys; it's just never come up 
>>>that the data that I had in a list was something that I wanted to use 
>>>as-is for a dict key, and I can't think of a situation where it *would* 
>>>happen.  What you're saying, essentially, is that for the sake of one 
>>>form of aesthetic purity with no significant practical benefits, we 
>>>should break another form of aesthetic purity with massive practical 
>>>benefits.)
>>>
>>>
>>[...]
>>Besides python doesn't provide such an aesthetic purity. Even if
>>it was true that only immutables could be used as keys in dictionaries
>>there are other times some invariant is established or depended upon
>>and yet python doesn't enforce immutable objects in those cases.
>>So much of the aesthetic purity python provides.
>>  
>>
>
> The aesthetic purity I'm referring to is that Python respects the proper 
> meaning of hashing, even if it doesn't force the programmer to.

And why should that be given much weight, considering that python
doesn't enforce aesthetic purity in other places.

> The 
> builtin objects that Python provides don't offer a __hash__() method 
> that fails to meet the mathematical prerequisites of a proper hash 
> function -- that is, objects that are equal will hash identically.

So? Equal doesn't has to be limited by what you understand as equal.
Besides if you want aesthetic purity and go looking within mathematics,
you will find that there is a lot lacking. Because methematically,
equallity means sameness.

> In 
> addition, dictionaries expect keys to have proper hashing semantics, 
> such that a given object's hash value will not change over its 
> lifetime.

Repeating this, won't make it true. I already responded that dictioanries
expect no such thing. They only expect the hash (and equallity) to be
stable for the objects while they are used as keys.

> It is not possible for a mutable object to satisfy both 
> aspects of proper hashing behavior,

Yes it can. Nobody forces a mutable object to mutate. So a programmer
who is carefull not to mutate the objects that are used as a key in
a dictionary has mutable objects that satisfy both aspects of proper
hashing behaviour. And asking the programmer to be carefull in this
way is no more difficult as being carefull not to mutate an object
in a heapqueue or a sorted list.

> therefore Python does not pretend 
> that mutable objects are hashable.

There is no pretention there. Mutatble objects are just as hashable
as they are sortable. 

> Python does provide features that 
> allow you to define your own __hash__() on your own classes, and it has 
> no way of forcing you to make that a *proper* hash function, which 
> allows you to subvert things and create pseudo-hashable mutable objects, 
> but Python declines to do that itself -- it'll give you the rope to hang 
> yourself with, but it's not tying the noose.

Why is is subvertion? Do you think its is subvertion too when mutable
object are sorted or used in a heapqueue?

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


Re: extending python with a C-written dll

2004-12-21 Thread Jean-Baptiste PERIN
Steve Holden a écrit :
Jean-Baptiste PERIN wrote:


>> error: Python was built with version 6 of Visual Studio, and
extensions need to
be built with the same version of the compiler, but it isn't installed.


How do you expect to be able to write your own extension if you don't 
have
the environment to do so in the first place? that error has nothing 
to do
with python itself, but with you not having installed the right 
compiler.
THe same problem will arise building your own extension.

I know it has nothing to do with python ..
It just makes me sad to see that python cannot get rid of Visual 
Studoi to be extended . It's just amazing !!

Python is free
The compiler I use is free
The code I plan to produce will be free
Where can I find a free version of Visual Studio ?
the only thing I use that is not free is the operating system and it's 
because I had no choice .. my company decided for it

Others suggested trying the ctypes binary installer. Do so.

Yes .. that's what I'm going to do .. but I find it frustrating ..

Perhaps you aren't aware that Microsoft make a free tool chain available 
that can be used to create binary extensions? There has been some 
discussion of this recently, and I managed to compile MySQLdb and a 
couple of the mx extensions, so it's eminently doable [the PIL is 
proving a little less tractable due to dependencies on other libraries 
that I have yet to resolve].

The downloads are quite large, but if you want to try it, take a look at
  http://www.vrplumber.com/programming/mstoolkit/
regards
 Steve

If nothing else works  .. I'll try that way ..
So far, I've tried to keep as far as possible from MS things ..
thank you for your help ...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boo who? (was Re: newbie question)

2004-12-21 Thread Michael Hoffman
Erik Max Francis wrote:
How bizarre is it that they're trying to "sell" Spry by indicating it 
uses the "very best" features of Prothon, given that Prothon was a 
failed project?
And Python uses the very best features of ABC. What's your point? ;-)
Not that I've ever even used Prothon, although I thought the way the 
implementor dropped it into conversation was non-obnoxious. There could 
be a valuable lesson here.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Keyword arguments - strange behaviour?

2004-12-21 Thread brian . bird
Can anyone explain the behaviour of python when running this script?

>>> def method(n, bits=[]):
... bits.append(n)
... print bits
...
>>> method(1)
[1]
>>> method(2)
[1, 2]

It's the same in python 1.5, 2.3 and 2.4 so it's not a bug. But I
expected the variable "bits" to be re-initialised to an empty list as
each method was called. Whenever I explain optional keyword arguments
to someone I have usually (wrongly as it turns out) said it is
equivalent to:

>>> def method(n, bits=None):
... if bits is None:
... bits=[]
... bits.append(n)
... print bits
...
>>> method(1)
[1]
>>> method(2)
[2]

Is there a good reason why these scripts are not the same? I can
understand how/why they are different, it's just not what I expected.
(It seems strange to me that the result of the first method can only be
determined if you know how many times it has already been called)

Is this behaviour what you would (should?) intuitively expect?
Thanks,

Brian

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


Re: extending python with a C-written dll

2004-12-21 Thread Jean-Baptiste PERIN
Jean Brouwers a écrit :
First, you might check the calldll module available here
  
I have one or two things to try before ..but it looks interesting .. 
thank you very much ..

Take a look at Pyrex, it may fit your requirements to access C from
Python.
  
Yes, pirex looks very powerful ..I heard about it already .. I know 
someone who used it .. and the result was just amazing ..
there's also SWIG which looks very sexy
http://www.swig.org/tutorial.html

My current problem is a compilation one .. I need to first solve it 
before exploring these tools ..


If you do not have these already, you may need the Win32 API extension
  
/Jean Brouwers

Thank you very much Jean
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-21 Thread Antoon Pardon
Op 2004-12-18, Nick Coghlan schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Would you have us construct two related classes each time we find
>> ourselves in such a situation and copy an object from one
>> class to the other depending on the circumstances?
>
> Python itself seems to think so, given the pairings of set/frozenset & 
> list/tuple.
>
> Using genuinely immutable objects as dictionary keys is much easier than 
> saying 
> "while this object is part of a dictionary, don't alter it's hash value or 
> comparison results". Instead, the immutable version is provided to say 
> "alterations are not allowed on this copy"

Why then doesn't python think the same about sorted lists. When I have a
sorted list and do operations on it that depend on it being sorted,
I can mess things up just as easily by mutating an element in that
sorted list as I can mess things up by mutating a dictionary key.


> You can certainly *do* the former (using __hash__ and appropriate comparison 
> overrides), but it isn't particularly easy to do correctly,

> and hence usually 
> isn't a great idea unless copies are *really* expensive (and even then, a 
> shallow copy approach can often suffice).

The problem is you have to make copies evrywhere. You have to copy when
you insert a key, you have to make a copy when you access by key, you
have to copy when you want your key be used as an object.

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


Re: extending python with a C-written dll

2004-12-21 Thread Jean-Baptiste PERIN

Note that MinGW32 is a tested path for building (free) C extensions.  I
don't know if anyone has a tested way of using lcc.
Yes, very interesting
I can already conclude that either I don't know how to use lcc
or it doesn't suit my needs ..
in both case I have to quickly get rid of it .. before I throw the 
computer through the window ..

I plan to first test the cygwin's gcc compiler before goign to MinGW32
With MinGW32, your build step will be the delightfully easy:
python setup.py build --compiler=mingw32

Thank you very much for your help
--
http://mail.python.org/mailman/listinfo/python-list


wxPython documentation [was: Best GUI for small-scale accounting app?]

2004-12-21 Thread Richie Hindle

[Gerhard, quoting a blog]
> wxPython doesn't seem bad, but it lacks any documentation

I see this a lot, and it baffles me.  wxPython is a thin wrapper over
wxWidgets, which is very well documented.  Where they differ, the
wxWidgets documentation discusses those differences.  Add the excellent
wxPython demo, and you've got better documentation than some commercial
toolkits (MFC, for instance).

Is it just a communication problem - do newcomers not realise that the
wxWidgets documentation applies to wxPython?

(The latest version of the wxPython demo even lets you modify the demo
code at runtime, and compare the behaviour of your modified version with
the original, all without leaving the demo - fantastic!  Huge thanks to
whoever did that.)

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Is this a good use for lambda

2004-12-21 Thread Nick Coghlan
Alan G Isaac wrote:
I need a clarification of the argument.
Are the opponents saying that I should not be able to:
def compose(list_of_functions): return reduce(lambda f, g: lambda x:
f(g(x)), list_of_functions)
As things stand, I can live with lambda. However, if something can't be said in 
a single expression, then it's too complicated to be embedded inside another 
statement and have the whole remain even remotely readable.

Even the above example is impossible to parse easily unless you happen to 
recognise that the 'compose' means 'function composition'. (cf. Fredrik's 
reaction. . .)

In a nutshell: why?
I dislike the use of lambda here, because it isn't very readable for most 
people, and readability counts. To actually understand what this code does, I 
had to rewrite it as I have below.

To parse a statement using lambdas and figure out what it does, one almost *has* 
to assign a mental name to each lambda. Why should every reader of the code have 
to go to that effort, when the author of the code can do it once, and provide 
premade mental handles for every code reader to come after them?

And may I see the proposed "better" replacement for function composition.
Moving to a programming world where whitespace and typed characters are so cheap 
as to be practically free:

def compose(list_of_functions):
  def compose_pair(f, g):
def composed_pair(x):
  f(g(x))
return composed_pair
  return reduce(compose_pair, list_of_functions)
The advantage of this version is that what it does is fairly obvious, even to 
someone that doesn't often use the term 'function composition' (like, say, me - 
I know what it means, but it doesn't spring to mind naturally).

Moving on, I'd suggest that for any significant list of functions, the 
performance of the recursive version is going to be lousy, and I'd rewrite it 
with the iterative version:

def compose(list_of_functions):
  application_order = reversed(list_of_functions)
  def composed(x):
for f in application_order:
  x = f(x)
return x
  return composed
With this last version, even people that don't use functional programming at all 
can see immediately what the function is doing, including what the order of 
application is for the functions that combine to give the overall function 
composition (I had to go look up the precise operation of reduce() to be sure I 
had the order of application for function composition correct). The initial 
creation is going to be much faster (creating a single function object, rather 
than a big stack of them), and the actual invocation is going to be faster 
(since it's a simple iteration, rather than a big chain of recursive function 
calls).

What are the disavantages of my final version?
1. It will deeply offend the aesthetic sensibilities of any functional purists 
in the audience.

2. It no longer directly implements the theoretical concept of function 
composition (although it has the same effect).

From a real world programming point of view, though, it's self-documenting, 
runs faster and uses less memory, so it's really a pure win.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread deelan
[EMAIL PROTECTED] wrote:
Can anyone explain the behaviour of python when running this script?
(...)
Is there a good reason why these scripts are not the same? I can
understand how/why they are different, it's just not what I expected.
(It seems strange to me that the result of the first method can only be
determined if you know how many times it has already been called)
see "python gotchas":

bye.
--
@prefix foaf:  .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog  .
--
http://mail.python.org/mailman/listinfo/python-list


Re: extending python with a C-written dll

2004-12-21 Thread Jean-Baptiste PERIN
John Machin a écrit :
Jean-Baptiste PERIN wrote:
Hi,
I'm trying to make a windows dll reachable from a python script ..
and
I'm encountering troubles during link step ..
I use "lcc" to compile and link
I use python 2.3 under win XP
[snip]
Here are the errors :
-
Error c:\...\plugins\hello.c 14 undefined reference to
__imp__Py_BuildValue
Error c:\...\plugins\hello.c 46 undefined reference to
__imp__Py_InitModule4
[snip]
return Py_BuildValue("i", 1);
[snip]
void __declspec(dllexport) inithello()
{
(void)Py_InitModule3("hello", helloMethods, MHello__doc__);
Can anyone help me?

Yes. Option 1: *Maybe* you can help yourself. Have you not noticed from
the above that the compiler is magically prepending "__imp__" to the
names of external functions? However the .lib that comes with Python
won't have that "__imp__". You would have to bridge that gap, somehow.
Have you searched the lcc documentation? Are you prepared for the next
several problems that may arise?
Indeed, it's something I can't understand (the __imp__ stuff)..
Nothing appear about that in the
I have posted a question on lcc forum .. the author of lcc answered
"This happens because somewhere you are declaring the functions
Py_BuildValue
and
Py_InitModule
as __declspec(dllimport) "
He's right !!
He adviced me to change that ..
I don't want to make changes to python code .. so .. bye bye lcc
long life to gcc
By the way, lcc also *appears* to change "...Module3" to "...Module4"
:-)
this one is explainable to me .. it is due to the fact that both 
function are equivalent

in mod support.h:
#define Py_InitModule3(name, methods, doc) \
Py_InitModule4(name, methods, doc, (PyObject *)NULL, \
   PYTHON_API_VERSION)

Option 2: You have been helped already. There are two free compilers
which work quite well for developing extensions in C for win32
platforms; start reading here:
http://docs.python.org/inst/tweak-flags.html#SECTION00062
I'm currently attracted by the cygwin solution .. that I find very sexy !!
If I fail .. I will explore the MingW ..
Thank you very much for helping me ..
--
http://mail.python.org/mailman/listinfo/python-list


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Can anyone explain the behaviour of python when running this script?

the language reference has the full story:

http://www.python.org/doc/2.4/ref/function.html

"Default parameter values are evaluated when the function
definition is executed"

 



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


Re: A rational proposal

2004-12-21 Thread Nick Coghlan
Mike Meyer wrote:
 I'm willing to do the work to get
decimals working properly with it.
Facundo's post reminded me of some of the discussion about the interaction 
between floats and Decimal that went on when he was developing the module that 
eventually made it into the standard library.

Perhaps Rational should have the same "arm's length" interaction with floats 
that Decimal does - require the user to set the precision they want by turning 
the float into a string that is then fed to the Rational constructor. My 
argument is that the following behaviour might be a little disconcerting:

Py> x = 1.1
Py> Rational(x)
Rational("11001 / 1")
as opposed to:
Py> x = 1.1
Py> Rational("%.2f" % x)
Rational("11 / 10")
(A direct Decimal->Rational conversion should be OK, however, since it should 
match standard expections regarding the behaviour of the fractional portion)

The other point is that, since converting a Rational to float() or Decimal() may 
lose information, this is something that Python shouldn't really do 
automatically. As Facundo suggested, a string representation is a suitable 
intermediate format that makes explicit the degree of precision used in the 
conversion.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boo who? (was Re: newbie question)

2004-12-21 Thread Fredrik Lundh
Michael Hoffman wrote:

>> How bizarre is it that they're trying to "sell" Spry by indicating it uses 
>> the "very best" 
>> features of Prothon, given that Prothon was a failed project?
>
> And Python uses the very best features of ABC.

did you learn that from reading Python marketing material, or by careful
study of "the history of python"-documents?  there is a difference...

 



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


Re: List limits

2004-12-21 Thread Nick Coghlan
Raymond Hettinger wrote:
How many items can be stored in a Python list? I have close to 70,000
items... is this within a lists limits?

Lists store pointers to objects.  Unless you have a lot of duplicates, it is the
objects themselves that will consume most of your memory.  The list itself will
likely be small in comparison.
Given the size of the counter, is it actually physically possible for a list to 
run out of room before the application runs out memory?

Even list(None for x in xrange(sys.maxint)) wouldn't do the trick, since each of 
those pointers to None is taking 4 bytes of memory, and Python's internal 
structures are already chewing up some of the address space.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-21 Thread Antoon Pardon
Op 2004-12-17, Jeff Shannon schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>>Op 2004-12-17, Jeff Shannon schreef <[EMAIL PROTECTED]>:
>>  
>>
>>>To take another approach -- given some function that allows lists to 
>>>(pretend to be) hashable:
>>>
>>>.>>> key = [1,2]
>>>.>>> d[key] = 'foo'
>>>.>>> d[[1,2]]
>>>
>>>.>>> key.append(3)
>>>.>>> d[key]
>>>???
>>>.>>>
>>>
>>>As I understand it, it is impossible for there to be a hash function for 
>>>which both of these cases can return the same object.
>>>
>>>
>>
>>How about:
>>
>>  hash = id
>>  
>>
>
> If hash equals id, then the first of those cases fails.  I'm creating a 
> new list with the same value but different.  If hash *doesn't* equal id, 
> then the second case fails.  It's an either-or proposition; you *cannot* 
> have both with mutable objects.  And the proper definition of a hash 
> requires that you have both.

I have both, I just have a different == than the one you have in mind.
Nothing forces me to have two lists as equal just because there elements
happen to be equal.

> Now, even if hash were made to equal id... suppose I then pass that dict 
> to a function, and I want to get the value that I've stored under 
> [1,2].  In order to do that, I'd *also* have to pass in the *exact* list 
> that I used as the key, because *only* that *exact* instance will hash 
> correctly.

Maybe that is what I want.

> Not only that, but if I've got a handful of such values that 
> I want to retrieve, I'll have to pass in *all* of the lists that I used 
> to key the dict.  Any time I want to use the dict elsewhere, I need to 
> pass not only the dict itself, but a list of keys to the dict.  And then 
> I need to know the order of the keys in that list.  Ugh.

Nonsense.

> I suppose I could just use keys() to get a complete list of keys from 
> the dict itself.  But still, I'd have to iterate over keys() to try to 
> find the proper list that matches the value that I need, and then use 
> the key to reference the dict.  That leaves me with code like this:
>
> def process_dict(d):
> for key in d.keys():
> if key == [1,2]:
> value1 = d[key]
> if key == [1,3]:
> value2 = d[key]
> if key == [2,2]:
> # and so on
>
> Double ugh.

That is just your limited imagination. When I would use lists as keys in
such a way, I wouldn't care what value the key itself had. The value in
the dictionary would be associted with the list itself, not with the
value the list has at any one particular moment. Just as when you
want to know who the owner is of a particular car, you only care about
the identity of the car (its serialnumber) not its milage, color,
how much gas is in the tank etc...

>>You also make the fault that because people ask for the possibility of
>>keys being mutable objects, that they want to mutate those object while 
>>being a key.
>>  
>>
>
> If mutable objects can be used as dict keys, then dicts *must* be able 
> to sensibly handle the keys being mutated underneath of them, because it 
> *will* happen. 

No they don't. Just as I don't expect algorithms to handle sensible
when they expect a sorted list, but get an unsorted one because
the programmer was not carefull enough and mutated an element.

> Your assumption that it's okay to make keys mutable, just tell 
> programmers not to do it, is along the same lines as assuming that 
> memory leaks in C aren't a problem because you've told programmers to 
> free() all of the memory that they malloc()'d. 

It is more among the lines as telling programmers not to mutate
objects in a sorted list, while future running code may expect it to
still be sorted.

>>>In order to maintain the logical consistency that if an object is used 
>>>as a dict key, that same object should reasonably be expected to 
>>>retrieve the same value, identity-based hashes are necessary.  As a 
>>>result, the first option must be disallowed.
>>>
>>>
>>
>>Then why don't we disallow lists of mutable objects to be sorted or
>>to be made into a heap. In fact each time we have a structure that
>>relies on some invariant among its members we should disallow mutable
>>members because with mutable members the invariant can be violated
>>without ever rebinding one of the elements.
>>  
>>
>
> If we have an object that, *by definition*, has some invariant that can 
> be violated by having mutable members, then sure.  But lists aren't 
> sorted or heaped by definition.

That doesn't change the fact that conceptually a programmer can use
them that way. So do you think that if a programmer uses a list
as a heap or a sorted list he should limit his object to immutable
objects. Are you saying that programmers shouldn't sort mutable
objects.

> Note also that, if a list becomes unsorted or unheaped, it's fairly easy 
> to resort or re-heapify the list.  It may take some time, but nothing is 
> lost.  If a dictionary key mutates, then data *is* 

Re: Keyword arguments - strange behaviour?

2004-12-21 Thread Duncan Booth
 wrote:

> Can anyone explain the behaviour of python when running this script?
> 
 def method(n, bits=[]):
> ... bits.append(n)
> ... print bits
> ...
 method(1)
> [1]
 method(2)
> [1, 2]
> 
> It's the same in python 1.5, 2.3 and 2.4 so it's not a bug. But I
> expected the variable "bits" to be re-initialised to an empty list as
> each method was called. Whenever I explain optional keyword arguments
> to someone I have usually (wrongly as it turns out) said it is
> equivalent to:



No, it is closer to:

# Assume you have done this earlier:
import new
def _realmethod(n, bits):
bits.append(n)
print bits

# The def is roughly equivalent to this:
_defaultArgs = ([], )
method = new.function(_realmethod.func_code, globals(), 'method', 
_defaultArgs)

Each time you re-execute the def you get a new set of default arguments 
evaluated, but the result of the evaluation is simply a value passed in to 
the function constructor.

The code object is compiled earlier then def creates a new function object 
from the code object, the global dictionary, the function name, and the 
default arguments (and any closure as well, but its a bit harder to 
illustrate that this way).

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


Re: Why are tuples immutable?

2004-12-21 Thread Antoon Pardon
Op 2004-12-18, Nick Coghlan schreef <[EMAIL PROTECTED]>:
> Jp Calderone wrote:
>> On Fri, 17 Dec 2004 11:21:25 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote:
>> 
>>   The correct characterization is that Python makes user-defined
>> mutable classes hashable (arguably correctly so) as the default
>> behavior.
>
> However, that is only achieved by using identity based equality by default. 
> If 
> you inherit from something which *doesn't* use identity based equality (say, 
> list or dict), then the hashability isn't there. So while you're quite 
> correct, 
> it doesn't affect the OP's original complaint (not being allowed to use a 
> list 
> as a dictionary key).
>
> The Python docs are pretty precise about what the rules are:
>
> "__hash__(self)
>  Called for the key object for dictionary operations, and by the built-in 
> function hash(). Should return a 32-bit integer usable as a hash value for 
> dictionary operations. The only required property is that objects which 
> compare 
> equal have the same hash value; it is advised to somehow mix together (e.g., 
> using exclusive or) the hash values for the components of the object that 
> also 
> play a part in comparison of objects. If a class does not define a __cmp__() 
> method it should not define a __hash__() operation either; if it defines 
> __cmp__() or __eq__() but not __hash__(), its instances will not be usable as 
> dictionary keys. If a class defines mutable objects and implements a 
> __cmp__() 
> or __eq__() method, it should not implement __hash__(), since the dictionary 
> implementation requires that a key's hash value is immutable (if the object's 
> hash value changes, it will be in the wrong hash bucket)."
>
> (from: http://www.python.org/dev/doc/devel/ref/customization.html)
>
>
> The key points are:
>1. Objects which compare equal must have the same hash value
>2. An object's hash value must never change during it's lifetime
>
> Lists could achieve the former, but not the latter. Tuples can achieve both, 
> by 
> virtue of being immutable, with immutable contents. Ditto for sets & 
> frozensets.

Yes they can. If you don't mutate a list it will never change during
it's lifetime.

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


Re: Is this a good use for lambda

2004-12-21 Thread Steven Bethard
Nick Coghlan wrote:
def compose(list_of_functions):
  application_order = reversed(list_of_functions)
  def composed(x):
for f in application_order:
  x = f(x)
return x
  return composed
reversed returns an iterator to the list in reverse order, not a copy of 
the list:

>>> lst = range(10)
>>> riter = reversed(lst)
>>> list(riter)
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>>> list(riter)
[]
so you either need to call reversed each time in 'composed' or copy the 
list and call reverse.

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


Re: Should I always call PyErr_Clear() when an exception occurs?

2004-12-21 Thread Nick Coghlan
Tim Peters wrote:
Note that the Python implementation itself uses the Python C API
heavily, in its C files.  You can study those to get many examples of
best practice.  It will help to remember that coding in C isn't
supposed to fun <0.9 wink>.
That's right. Coding in C is supposed to remind you why you love coding in 
Python ;)
Although coding in C when you have the Python API to lean on is a hell of a lot 
better than just coding in C. . .

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tabnanny really useful?

2004-12-21 Thread Franz Steinhaeusler
On Tue, 21 Dec 2004 10:24:40 +0100, "Fredrik Lundh"
<[EMAIL PROTECTED]> wrote:

>Franz Steinhaeusler wrote:
>
>> Thanks for your explanation.
>>
>> I tried an found:
>> def a():
>> ->print
>> ->.print
>>
>> where point is a space.
>>
>> tabnanny here complains and python compile it just fine.
>
>really?  that's a syntax error (you cannot change indentation nillywilly
>inside a block), and the Python I'm using surely flags this as an error:
>
>$ python -c "print repr(open('franz.py').read())"
>'def a():\n\tprint\n\t print\n'
>
>$ python franz.py
>  File "franz.py", line 3
>print
>^
>SyntaxError: invalid syntax
>
>while tabnanny gives it one thumb up:
>
>$ python -m tabnanny -v franz.py
>'franz.py': Clean bill of health.
>
>what Python version are you using?
>
> 
>
>

Oh sorry, I meant
def a():
->print
.->print

C:\Python23\Lib>tabnanny.py -v c:\franz.py
'c:\\franz.py': *** Line 3: trouble in tab city! ***
offending line: ' \tprint\n'
indent not equal e.g. at tab size 1

C:\Python23\Lib>python -c "print repr(open('c:/franz.py').read())"
'def a():\n\tprint\n \tprint\n'

C:\Python23\Lib>c:/franz.py

C:\Python23\Lib>
-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Read word tables

2004-12-21 Thread Rameshwari

Hi,

I would like to read a ms-word document using python.

Basically the word document contains number of tables  and the rows 
in each table do not have same number of columns.

Does anyone have a sample code to read a table?

Thank you
Best Regards,
Rameshwari




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


ANN: SPE 0.7.0.a Python IDE now with uml viewer

2004-12-21 Thread www.stani.be
Spe is a python IDE with auto-indentation, auto completion, call tips,
syntax coloring, uml viewer, syntax highlighting, class explorer,
source index, auto todo list, sticky notes, integrated pycrust shell,
python file browser, recent file browser, drag&drop, context help, ...
Special is its blender support with a blender 3d object browser and its
ability to run interactively inside blender. Spe ships with wxGlade
(gui designer), PyChecker (source code doctor) and Kiki (regular
expression console). Spe is extensible with wxGlade.

SPE offers now a built-in Python UML viewer. An Uml diagram is
hierarchal 2d map of classes. See
http://spe.pycs.net/pictures/800x600/11.html for a nice screenshot.
Attentive users notice that the uml view also uses the separators of
the class explorer for a better outline. Once you get used to it, you
can't live without.

I see that still a lot of people are unfortunately downloading old
tar.gz versions. This makes absolutely no sense!! Because of problems
with tar.gz archives on the blender website, Linux and Mac users must
download the zip archive. I release them especially for that purpose.
The exe installer is of course for Windows.

A special thanks for everyone who donates. That always pushes me to new
release (hint,hint,...)

:Batteries included:
- Kiki:
Regular Expression (regex) console. For more info:
http://project5.freezope.org/kiki/index.html
- PyChecker:
PyChecker is a tool for finding bugs in python source code. It
finds problems that are typically caught by a compiler for
less dynamic languages, like C and C++. It is similar to lint.
For more info: http://pychecker.sourceforge.net
- wxGlade:
wxGlade is a GUI designer written in Python with the
popular GUI toolkit wxPython, that helps you create
wxWindows/wxPython user interfaces. As you can guess by the
name, its model is Glade, the famous GTK+/GNOME GUI builder,
with which wxGlade shares the philosophy and the look & feel
(but not a line of code). For more info:
http://wxglade.sourceforge.net

:New features:
- UML viewer

:Requirements:
- full python 2.3+
- wxpython 2.5.3.8+
- optional blender 2.35+

:Links:
- Homepage: http://spe.pycs.net
- Website:  http://projects.blender.org/projects/spe/
- Screenshots:  http://spe.pycs.net/pictures/index.html
- Forum:http://projects.blender.org/forum/?group_id=30
- RSS feed: http://spe.pycs.net/weblog/rss.xml

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


Re: Is this a good use for lambda

2004-12-21 Thread Nick Coghlan
Steven Bethard wrote:
Nick Coghlan wrote:
def compose(list_of_functions):
  application_order = reversed(list_of_functions)
  def composed(x):
for f in application_order:
  x = f(x)
return x
  return composed

so you either need to call reversed each time in 'composed' or copy the 
list and call reverse.
These iterator thingies sure are handy most of the time, but occasionally. . . I 
suspect the iterator (e.g. reversed()) vs list (e.g. sorted()) distinction is 
going to end up on a few of those 'Python Gotchas' pages.

Ah well, at least I caught the 'return x' that was missing from my first draft 
version  :)

Corrected version:
def compose(functions):
  application_order = list(functions)
  application_order.reverse()
  def composed(x)
for f in application_order:
  x = f(x)
return x
  return composed
Cheers,
Nick.
P.S. For the curious:
C:\>python -m timeit -s "x = range(1)" "y = x[:]; y.reverse()"
1 loops, best of 3: 102 usec per loop
C:\>python -m timeit -s "x = range(1)" "y = list(x); y.reverse()"
1 loops, best of 3: 100 usec per loop
C:\>python -m timeit -s "x = range(1)" "y = list(reversed(x))"
1 loops, best of 3: 166 usec per loop
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-21 Thread Antoon Pardon
Op 2004-12-18, Bengt Richter schreef <[EMAIL PROTECTED]>:
>>
>>As it turns out, python makes no difference in difficulty for making
>>either mutable or immutable objects usable as dictionary keys. The
>>only difference is that python only made its standard immutable
>>types hashable and not its standard mutable objects.
>>
> In one sense a mutable could looked upon as immutable until it is mutated,
> so why not allow its use in the same way as immutables?
> Is that basically the point of view you are trying to explain?
>
> Ok, suppose you did allow that. What kind of error symptoms would you like
> to have after a dict key is mutated and an attempt is made to look up the 
> value
> using a mutable equal to the original key value? Presumably a KeyError 
> exception?
> Or did you want to use a "frozen" copy of the original key, and not get a 
> KeyError?
> Or should a new value equal to the mutated current value of the original key 
> succeed?

Why should we expect certain error symptoms? If you have sorted mutable
objects, mutated one element in the list and then apply an algorithm
that depended on the list to be sorted; would you then expect a
particular error symptom?

> Assuming the latter, what does this imply implementation-wise?

You assume wrongly. I'm a bit sorry for that, because you obviously
spend time in this.

> Hm, just for the heck of it, does this do what you want? (all features not 
> tested, none tested beyond what you see,
> and special methods like update and iterators will just work on the plain 
> dict part if they work at all, unless
> you add the code ;-)

I don't expect anyting special. Python provides all that is needed. It
is just that the documentation suggests otherwise.

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


Re: Why are tuples immutable?

2004-12-21 Thread Antoon Pardon
Op 2004-12-18, Roy Smith schreef <[EMAIL PROTECTED]>:
> Nick Coghlan <[EMAIL PROTECTED]> wrote:
> [quoting from the Reference Manual]
>> If a class defines mutable objects and implements a __cmp__() 
>> or __eq__() method, it should not implement __hash__(), since the dictionary 
>> implementation requires that a key's hash value is immutable (if the 
>> object's 
>> hash value changes, it will be in the wrong hash bucket)."
>
> I know that's what it says, but I don't think it's good advice.  All 
> that is really required is that __hash__() always returns the same value 
> over the lifetime of the object, and that objects which __cmp__() the 
> same always return the same hash value.  That's it.  That's all a 
> dictionary cares about.

It cares about even less. It only cares that these conditions are
met while the object is a key. If those things would change before
or after the object is a key, the dictionary wouldn't care about
it.

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


Re: Read word tables

2004-12-21 Thread Peter Nuttall
On Tuesday 21 Dec 2004 11:24, Rameshwari wrote:
> Hi,
>
> I would like to read a ms-word document using python.
>
> Basically the word document contains number of tables  and the rows
> in each table do not have same number of columns.
>
> Does anyone have a sample code to read a table?
>
> Thank you
> Best Regards,
> Rameshwari

Hi, 

a fast google on the terms reading word docs with python threw up some 
results for you. Some of them may help. It is worth remembering that the ms 
word format is a binary format, and as such will be very hard to parse if 
you have to do it yourself. 

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


Re: odbc script

2004-12-21 Thread Steve Holden
Chris wrote:
Thanks Benji,
  I took your advice and added in the conn.commit() into 
the script but still had the same problem.  I did some digging around the 
odbc documentation and found this bug:
**
4. Hirendra Hindocha also reports: inserting a single row into a table 
doesn't work properly unless one specifically deallocates the cursor.
for example the following code snippet -
conn = odbc.odbc(str)
cur = conn.cursor()
sql = 'insert into abc_table values(1,2,'abc')
cur.execute(sql)
conn.commit()
cur.close()
conn.close()doesn't work, unless you add the following lines

cur = None
conn = None at the end of the above code snippet. Tracing with ODBC and a 
look into odbc.cpp shows that sqlfreestmt is not being called until the 
explicit deallocation is done. [Note however, Bill Tutt seems to think that 
this problem implies a problem with the specific ODBC driver, rather than 
with the ODBC implementation of Python. I haven't a clue!]

*
I figured what the heck and added in the 2 lines specified:
cur = None
conn = None
and sure enough it worked after that!  I am not sure why but figure that 
when the last loop goes through it is as if it is updating 1 single row?
Either way it works now.  Thanks for the help as I am sure I needed the 
conn.commit() as well.

Chris
"Benji York" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Chris wrote:
what ever is the last loop through doesn't seem to update the
database?
Try a conn.commit() after your loop.
--
Benji York 


Chris:
Please note that the odbc module is a bit long in the totth now, though 
it surely is convenient to get it with win32all. If this work is being 
done for personal use you might want to look at www.egenix.com and think 
about installing the mxODBC module, which I have used with very good 
results.

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


Parallelization with Python: which, where, how?

2004-12-21 Thread Mike M?ller
> Can someone recommend a parallelization approach? Are there examples or 
> documentation? Has someone got experience with stability and efficiency?

I am successfully using pyro http://pyro.sourceforge.net for my
parallelization task (8 node Linux cluster, embarrassing parallel).
It comes with a good documentation and it is easy to use. It works on
clusters as well as on heterogeneous networks. You just need to start
a server on each cluster node (e.g. rsh node1 startserver.py). You
also need a name server running (maybe on your master node). Then a
client can just asks a server to calculate and gets some result back.
You can also send an object that calculates on the server and comes
back including the result.

There are some examples included in the documentation you can start
with and just change the parts that are specific to your application.

It is easy to understand and use and has been working well for me for
more than 2 years.

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


Re: List limits

2004-12-21 Thread Fredrik Lundh
Nick Coghlan wrote:

> Given the size of the counter, is it actually physically possible for a list 
> to run out of room 
> before the application runs out memory?

depends on the system architecture, of course: consider an 64-bit computer
with 32-bit integers and 256 GB of memory...

 



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


Python, VB and COM

2004-12-21 Thread Nick Leaton
I have a class built as a class library. It makes
a Test.dll, and I can call this from other VB projects

class PyTest

private _name as string

Public Property Name() as string
Get
return _name
End Get
Set (byval value as string)
_name = value
End Set
End Property

End Class

Then I was expecting to do something like

import win32Com.client

pt = win32com.client.Dispatch ("Test.PyTest")
pt.Name = "fred"
print pt.Name

However it doesn't look like the Test.dll is known.
Any pointers?

Thanks

Nick

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


Re: BASIC vs Python

2004-12-21 Thread Steve Holden
Doug Holton wrote:
Mike Meyer wrote:
Logo (my pick) has been called "Lisp without the parenthesis". It has
the advantage of using standard algebraic notation for formulas,
instead of operator post or pre.

This is comp.lang.python, not comp.lang.logo.  Please refrain from 
discussing topics not related to CPython.
'Scuse me? This group has a long history of off-topic posting, and 
anyway who decided that CPython should be the exclusive focus? Even 
on-topic we can talk about Jython and PyPy as well as CPython.

Off-topic we can talk about what we damned well please. Even boo :-) I 
detect sour grapes here.

You may be smarting about the way people have responded to your tireless 
promotion of boo, but frankly that's different. No matter how many times 
you may say that the syntax of boo is "very like Python's" the semantics 
make it an entirely different language, entirely deserving of its own 
(separate) newsgroup.

Plus, each time you mention it there's this undercurrent of evangelism. 
It's sort of like a baptist dropping in at an episcopal church and 
complaining that the choirs sing better at the baptist church. Bad form, 
old chap.

So please don't let your own upset start you being unpleasant to others. 
 There's no point souring your outlook just because the world isn't 
beating a path to your door. Maybe it's the mousetrap's fault.

wouldn't-normally-say-python-to-a-goose-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: odbc script

2004-12-21 Thread Peter Hansen
Steve Holden wrote:
Please note that the odbc module is a bit long in the totth now, though 
it surely is convenient to get it with win32all. If this work is being 
done for personal use you might want to look at www.egenix.com and think 
about installing the mxODBC module, which I have used with very good 
results.
Or, even if you're not using it for personal use, considering
using mxODBC.  As I understand it, it's quite available for
non-personal use, just at a (reasonable, IMHO) price.
(Of course, Steve knew that, but just didn't think to mention
it.  I think.  :-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Easy "here documents" ??

2004-12-21 Thread Jim Sizelove
Doug Holton wrote:
Bengt Richter wrote:
variable1 = 1
variable2 = 2
s = """
  v = ${variable1}
  v2's value is: ${variable2}
"""
However, Python 3.0 is likely years away.  If you want to know how to 
run code like this today, consult Fredrik Lundh.

Or replace ${...} with equally simple %(...)s in the above and be 
happy ;-)

I'm afraid you are incorrect.  Simply replacing the $ with % in my 
example will not work in Python.
If you would like to use % instead of $, I recommend requesting that 
feature for Python 3.0: http://www.python.org/cgi-bin/moinmoin/Python3.0
Oh, but it does work:
>>> variable1 = 1
>>> variable2 = 2
>>> s = """
...v1 = %(variable1)s
...v2's value is: %(variable2)s
... """
>>> print s % vars()
   v1 = 1
   v2's value is: 2
--Jim
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tabnanny really useful?

2004-12-21 Thread Steve Holden
Franz Steinhaeusler wrote:
On Tue, 21 Dec 2004 10:24:40 +0100, "Fredrik Lundh"
<[EMAIL PROTECTED]> wrote:

Franz Steinhaeusler wrote:

Thanks for your explanation.
I tried an found:
def a():
->print
->.print
where point is a space.
tabnanny here complains and python compile it just fine.
really?  that's a syntax error (you cannot change indentation nillywilly
inside a block), and the Python I'm using surely flags this as an error:
$ python -c "print repr(open('franz.py').read())"
'def a():\n\tprint\n\t print\n'
$ python franz.py
File "franz.py", line 3
  print
  ^
SyntaxError: invalid syntax
while tabnanny gives it one thumb up:
$ python -m tabnanny -v franz.py
'franz.py': Clean bill of health.
what Python version are you using?
 



Oh sorry, I meant
def a():
->print
..->print
C:\Python23\Lib>tabnanny.py -v c:\franz.py
'c:\\franz.py': *** Line 3: trouble in tab city! ***
offending line: ' \tprint\n'
indent not equal e.g. at tab size 1
C:\Python23\Lib>python -c "print repr(open('c:/franz.py').read())"
'def a():\n\tprint\n \tprint\n'
C:\Python23\Lib>c:/franz.py
C:\Python23\Lib>
Well, you've probably answered your own question, then. Do you think 
tabnanny is a useful piece of code now? I used it a lot when I first 
started using Python, and still run it over code from unknown sources 
(no pun intended) from time to time.

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


Re: better lambda support in the future?

2004-12-21 Thread Antoon Pardon
Op 2004-12-17, Terry Reedy schreef <[EMAIL PROTECTED]>:
>
> "Jason Zheng" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Steven Bethard wrote:
>>> Jason Zheng wrote:
>>>
 I'm wondering why python still has limited lambda support. What's 
 stopping the developers of python to support more lisp-like lambda 
 function?
>
> They already have: given the fundamental syntax difference between all 
> expressions and expressions within statements, def statements are at least 
> the equivalent of lisp lambdas + name binding.  When you get an exception 
> traceback, a unique name is more helpful than the pseudoname . 
> Isolating the definition of a function in a separate statement also makes 
> it possible to unittest the function.
>
>>> This comes up every few weeks on the list.  If you haven't already, 
>>> check the archives in Google for 'anonymous def' or 'anonymous 
>>> function'.  The usual response to this question is something along the 
>>> lines of "if it's good enough to create a function for, it's good enough 
>>> to name".
>
> What puzzles me is 1) why some people apparently think anonymity is good --  
> is it really that hard to name non-trivial functions?

Do you name every object, number, string ... before you use it.
If not it seems you don't object to anonymity.

And yes it sometimes is hard. Of course you can just name it f1, f2 etc,
but that is no improvement over anonymity and sometimes the best you
can do is describe what the function does, but the code does that
better.

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


Re: Easy "here documents" ??

2004-12-21 Thread Steve Holden
Doug Holton wrote:
Bengt Richter wrote:
variable1 = 1
variable2 = 2
s = """
  v = ${variable1}
  v2's value is: ${variable2}
"""
However, Python 3.0 is likely years away.  If you want to know how to 
run code like this today, consult Fredrik Lundh.

Or replace ${...} with equally simple %(...)s in the above and be 
happy ;-)

I'm afraid you are incorrect.  Simply replacing the $ with % in my 
example will not work in Python.
If you would like to use % instead of $, I recommend requesting that 
feature for Python 3.0: http://www.python.org/cgi-bin/moinmoin/Python3.0
Or use boo - it's probably in there already ;-)
must-stop-baiting-the-holton-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: xmlrpclib question

2004-12-21 Thread Fredrik Lundh
"writeson" <[EMAIL PROTECTED]> wrote:

> I tried the xmlrpclib examples from the Python Cookbook and had a
> problem. The example works fine so long as the server and client are on
> the same machine. But as soon as I try to run the client from another
> machine (all linux machines on the same network) I get a socket.error
> 111, connection refused. I've tried some different things to get past
> this, different ports, put machines in /etc/hosts, but to no avail.

the xmlrpclib client library doesn't need any special configuration to access a
remote host -- all you need is being able to connect to the host via a TCP/IP
socket, and having someone at the other end that accepts the connection.

if you're 100% sure that there's a HTTP server running at the remote end, it
looks like the server (or firewalls/routers in your network) doesn't accept 
TCP/IP
connections from the machine you're running the client on.

what happens if you point an unproxied web browser to the same address?

what happens if you telnet to the machine?  (make sure you telnet to the right 
port)

$ telnet somemachine someport
Trying 123.456.789...
Connected to somemachine.
Escape character is '^]'.
HELP

501 Method Not Implemented

Method Not Implemented
HELP to / not supported.

...

 



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


Re: Boo who? (was Re: newbie question)

2004-12-21 Thread Istvan Albert
Doug Holton wrote:

The syntax is indeed virtually identical to python.  You are yet another 
person who has trolled before. 
> Do you have financial conflict of interest too like Fredrik?
You'll easily get away by calling me a troll, but trying to make
it look like that the effbot is one, that's just hilarious.
Istvan.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with msvcrt60 vs. msvcr71 vs. strdup/free

2004-12-21 Thread Gerhard Haering
Of not so much interest to most Pythoneers, but ...

I cross-posted this to python-list to make people aware that thare are
*real* problems with mingw + Python 2.4, not only theoretical ones.

-- Gerhard


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

Re: Easy "here documents" ??

2004-12-21 Thread Fredrik Lundh
Steve Holden wrote:

>> If you would like to use % instead of $, I recommend requesting that feature 
>> for Python 3.0: 
>> http://www.python.org/cgi-bin/moinmoin/Python3.0
>
> Or use boo - it's probably in there already ;-)

weren't you supposed to ask me about it?

 



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


python cookbook

2004-12-21 Thread emami
L.S.,
I have heard that Python cookbook is free! Could somebody tell me where 
I can find it?

The second one is that I am busy to translate some "csh/bash" scripts to 
Python script. Where can I find a good reference to do easy this work?

with regards,
Nader
--
http://mail.python.org/mailman/listinfo/python-list


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread brian . bird
Thanks, this makes perfect sense. The phrase which sums it up neatly is
"Default parameter values are evaluated when the function definition is
executed"

However, is there a good reason why default parameters aren't evaluated
as the function is called? (apart from efficiency and backwards
compatibility)? Is this something that's likely to stay the same in
python3.0?

I'm really looking for a neat way to do the following:

def method(a,b,opt1=None,opt2=None,opt3="",opt4=None):
if opt1 is None: opt1=[]
if opt2 is None: opt2={}
if opt4 is None: opt4=[]

Python syntax is normally so neat but this just looks a mess if there
are lots of parameters.

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


Re: Python, VB and COM

2004-12-21 Thread Steve Holden
Nick Leaton wrote:
I have a class built as a class library. It makes
a Test.dll, and I can call this from other VB projects
class PyTest
private _name as string
Public Property Name() as string
Get
return _name
End Get
Set (byval value as string)
_name = value
End Set
End Property
End Class
Then I was expecting to do something like
import win32Com.client
pt = win32com.client.Dispatch ("Test.PyTest")
pt.Name = "fred"
print pt.Name
However it doesn't look like the Test.dll is known.
Any pointers?
Thanks
Nick
Well, first of all it would have been easier to deal with your specific 
problem if you'd copied the error message you got.

Exercising my psychic powers. I'll assume you saw something like
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
The best advice I can give is as follows:
1. Start pythonWin
2. Bring up Help | PythonWin Reference
3. Follow the win32com ReadMe link under "Python COM"
4. Follow the "win32com documentation index" link
5. Follow the "A quick start to Client Side COM" link.
The document you reach (yes, accessible, isn't it - I have learned to 
accept that in the open source world some people program and some people 
write documentation, but the two sets rarely coincide) will explain the 
linkages between COM Objects and win32com, and the section under "To 
generate Python sources supporting a COM object" is probably what you need.

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


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> However, is there a good reason why default parameters aren't evaluated
> as the function is called? (apart from efficiency and backwards 
> compatibility)?

how would you handle this case:

def function(arg=otherfunction(value)):
return arg

 



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


Re: Why are tuples immutable?

2004-12-21 Thread Nick Coghlan
Antoon Pardon wrote:
Why then doesn't python think the same about sorted lists. When I have a
sorted list and do operations on it that depend on it being sorted,
I can mess things up just as easily by mutating an element in that
sorted list as I can mess things up by mutating a dictionary key.
Incorrect, and this appears to be the point where our major disagreement 
lies.
Mutate a value in a sorted list and you can fix that easily, just by calling its 
sort() method again (and, in fact, mutate and resort is a fairly common idiom 
for small datasets). 'sorted' and 'heapified' are list properties that are 
easily broken by direct manipulation, but are also easily restored by once again 
'sorting' or 'heapifying'.

Change the hash value of an item used as a key in a dictionary, and *the 
internal state of the dictionary is likely to broken in a manner you probably 
cannot fix*. The only reason the 'probably' is there is because you should be 
able to 'fix it' by changing the hash value back to what it was originally.

Waitasec - wouldn't it be easier if dictionaries just made it a rule that the 
hash value wasn't allowed to change? Hang on, that's exactly what they do.

Now, if all you want is a mutable container that can be used as a dictionary 
key, then inherit from list and override the comparison methods (including hash) 
to work solely by object id. Then use that container instead of list().

Or, as I suggested elsewhere in this thread, use a special KeyedById class which 
*doesn't copy anything anywhere*.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tabnanny really useful?

2004-12-21 Thread Franz Steinhaeusler
On Tue, 21 Dec 2004 08:36:31 -0500, Steve Holden <[EMAIL PROTECTED]>
wrote:

>Franz Steinhaeusler wrote:
>
>[...]
>> 
>> Oh sorry, I meant
>> def a():
>> ->print
>> ..->print
>> 
>> C:\Python23\Lib>tabnanny.py -v c:\franz.py
>> 'c:\\franz.py': *** Line 3: trouble in tab city! ***
>> offending line: ' \tprint\n'
>> indent not equal e.g. at tab size 1
>> 
>> C:\Python23\Lib>python -c "print repr(open('c:/franz.py').read())"
>> 'def a():\n\tprint\n \tprint\n'
>> 
>> C:\Python23\Lib>c:/franz.py
>> 
>> C:\Python23\Lib>
>
>Well, you've probably answered your own question, then. Do you think 
>tabnanny is a useful piece of code now? 

Not really soo useful, because most syntax and also indentation errors
are actually detected by invoking python, i.e. the command compile.
But as combination for this: yes why not.
I looked for Stanis spe editor, which uses a combination of these two.

The background is:

I'm a member of the wxPython project Drpython (Python text editor 
and much more), and wanted also check the usefulness of a kind of syntax
check, which should run, before saving a Python file.
PythonCard Codeeditor also uses tabnanny, as far as i can remember.

>[...]

regards
-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Change vars in the parent process

2004-12-21 Thread Thomas Guettler
Am Tue, 21 Dec 2004 06:20:09 -0800 schrieb Markus Franz:

> Hi!
> 
> 
> Is there any possibility to change vars inside a parent process from
> the inside of a child process?
> Thanks

Hi,

No, that's impossible. At least on unix.

 Thomas


-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: Python, VB and COM

2004-12-21 Thread Nick
Thanks Steve.

I eventually found the library. Running makepy over the library
produced the requisite file.

Its working.

Help appreciated.

Nick

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


Re: Tabnanny really useful?

2004-12-21 Thread Steve Holden
Franz Steinhaeusler wrote:
On Tue, 21 Dec 2004 08:36:31 -0500, Steve Holden <[EMAIL PROTECTED]>
wrote:

Franz Steinhaeusler wrote:
[...]
Oh sorry, I meant
def a():
->print
..->print
C:\Python23\Lib>tabnanny.py -v c:\franz.py
'c:\\franz.py': *** Line 3: trouble in tab city! ***
offending line: ' \tprint\n'
indent not equal e.g. at tab size 1
C:\Python23\Lib>python -c "print repr(open('c:/franz.py').read())"
'def a():\n\tprint\n \tprint\n'
C:\Python23\Lib>c:/franz.py
C:\Python23\Lib>
Well, you've probably answered your own question, then. Do you think 
tabnanny is a useful piece of code now? 

Not really soo useful, because most syntax and also indentation errors
are actually detected by invoking python, i.e. the command compile.
But as combination for this: yes why not.
I looked for Stanis spe editor, which uses a combination of these two.
The background is:
I'm a member of the wxPython project Drpython (Python text editor 
and much more), and wanted also check the usefulness of a kind of syntax
check, which should run, before saving a Python file.
PythonCard Codeeditor also uses tabnanny, as far as i can remember.


[...]

regards
I've used drpython, and liked it. I think it would be a good way for 
people to start to use the language, as it avoids the "just the command 
line" syndrome without being as complex as IDLE or PythonWin. In short, 
just about right for a beginner.

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


Re: Easy "here documents" ??

2004-12-21 Thread Steve Holden
Fredrik Lundh wrote:
Steve Holden wrote:

If you would like to use % instead of $, I recommend requesting that feature for Python 3.0: 
http://www.python.org/cgi-bin/moinmoin/Python3.0
Or use boo - it's probably in there already ;-)

weren't you supposed to ask me about it?
 
Aah, right, sorry about that. I understand you are the world's expert on 
writing advanced solutions in which you have a financial interest 
without using features only available in Python 3.0.

Would you care to comment on why you wouldn't say "boo" to a goose, and 
whether the easierInBoo() decorator will be implemented in Imaging 1.2?

must-stop-going-for-the-low-hanging-fruit-ly y'rs  - steve
PS: If Doug Holton will just laugh at himself, even once, I promise to 
stop this nonsense immediately. There's always other nonsense to replace it.
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question

2004-12-21 Thread Luis M. Gonzalez

Fredrik Lundh wrote:
> it's the new Boo marketing motto: "have you harrassed a Pythoneer
today?"

Fredrik, I think you're being a little bit injust.
As far as I could see, everythime the word "boo" is typed, some sort of
censorship or plain bashing comes up, and I think this is not fair.

In my case, if some topic or thread is not of my interest, I simply
skip it.
Why don't we all do the same and live in peace? :-)

By the way, this is from comp.lang.python home page:
"Pretty much anything Python-related is fair game for discussion, and
the group is even fairly tolerant of off-topic digressions"

Seeing what was going on in this thread, I think that we probably
should delete this part, because this is getting far from "fairly
tolerant".

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


xmlrpclib question

2004-12-21 Thread writeson
Hi,
I tried the xmlrpclib examples from the Python Cookbook and had a
problem. The example works fine so long as the server and client are on
the same machine. But as soon as I try to run the client from another
machine (all linux machines on the same network) I get a socket.error
111, connection refused. I've tried some different things to get past
this, different ports, put machines in /etc/hosts, but to no avail.
Does anyone have any suggestions about what I'm doing wrong? Is there
something I have to enable external access to the server?
Thanks in advance,
Doug Farrell

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


Re: python cookbook

2004-12-21 Thread Steve Holden
emami wrote:
L.S.,
I have heard that Python cookbook is free! Could somebody tell me where 
I can find it?

In your stocking this Christmas, I hope, otherwise you'll probably have 
to pay for the printed version.

The recipes are extracted from the ActiveState web site, however - see
  http://aspn.activestate.com/ASPN/Cookbook/
Lots of good code there, for more than just Python.
The second one is that I am busy to translate some "csh/bash" scripts to 
Python script. Where can I find a good reference to do easy this work?

Not sure about this one, so I'll leave it to others.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change vars in the parent process

2004-12-21 Thread Steve Holden
Markus Franz wrote:
Hi!
Is there any possibility to change vars inside a parent process from
the inside of a child process?
Thanks

Not without adopting some specific inter-process mechanism such as a 
network socket. The idea is that processes are *intended* to provide 
protection boundaries around separate activities.

Maybe what you need is threads, which can easily access each other's 
resources. They do need careful control, though, precisely because they 
share a single process's address space and protection boundary.

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


Re: python cookbook

2004-12-21 Thread Fredrik Lundh
"emami" <[EMAIL PROTECTED]> wrote:

> I have heard that Python cookbook is free!

http://aspn.activestate.com/ASPN/Python/Cookbook/

> Could somebody tell me where I can find it?

google?

 



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


Lazy argument evaluation (was Re: expression form of one-to-many dict?)

2004-12-21 Thread Nick Coghlan
Mike Meyer wrote:
Personally, I'd love a language feature that let you create a function
that didn't evaluate arguments until they were actually used - lazy
evaluation. That lets you write the C ?: operator as a function, for
a start.
The basic idea is to just specify that those arguments must be zero-argument 
callables, and only call them if you actually need them.

The rest of this message is something that just occured to me that could make 
that style 'prettier' (if lambda looks as ugly in function calls to you as it 
does to me). It's completely untested, though :)

First, some utility functions to convert values and functions with arguments to 
a lazily evaluable function:

def lazy(x, *args, **kwds):
  """Executes x(*args, **kwds) when called"""
  if args or kwds:
return lambda : x(*args, **kwds)
  else:
return x # No arguments, so x must be callable by itself
def lazyval(x):
  """Allows passing a normal value as a deferred argument"""
  return lambda : x
def lazycall(x, *args, **kwds):
  """Executes x(*args, **kwds)() when called"""
  return lambda : x(*args, **kwds)()
For literals, their constructor provides a zero-argument callable 
equivalent:
[] -> list
(,) -> tuple
{} -> dict
0 -> int
"" -> str
0L -> long
And the operator module provides a way to delay most operations:
import operator
lazy(operator.mul, x, y) # Delayed x * y
lazy(operator.itemgetter(i), x) # Delayed x[i]
lazy(operator.attrgetter("a"), x) # Delayed x.a
lazycall(lazy(operator.attrgetter("a"), x)) # Delayed x.a()
(That last example is why I added lazycall() to the utility functions)
Then you can write a function called 'select':
def select(selector, *args, **kwds):
  if kwds:
return kwds[selector]()
  else:
return args[selector]()
And one called 'either' (since 'if' is taken and using 'select' would get the 
true case and the false case back to front):

def either(pred, true_case, false_case):
  if pred:
return true_case()
  else:
return false_case()
And use them as follows:
  select(selector, list, lazyval(mylist), lazy(eval, expr, globals(), locals()))
  select(selector, c1 = list, c2 = lazyval(mylist), c3 = lazy(myfunc, a, b, c))
  either(condition, guarded_operation, lazyval(default_case))
Huh. I think I like the idea of lazy() much better than I like the current PEP 
312. There must be something wrong with this idea that I'm missing. . .

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread brian . bird
def function(arg=otherfunction(value)):
return arg

My expectation would have been that otherfunction(value) would be
called if (and only if) the arg keyword parameter was missing from the
function() call (ie. the optional value is evaluated the lazy way).
Also, otherfunction would be called each and every time this function()
is called without the arg keyword. (At least, I would have assumed this
before today)

Still, I can see why it's been implemented the way it has, it just
seems a shame there isn't a neat shortcut to default lots of optional
arguments to new mutable objects. And since I'm not the only one to
fall into this trap it makes me wonder why the default behaviour isn't
made to be what most people seem to expect?

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


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> def function(arg=otherfunction(value)):
> return arg
>
> My expectation would have been that otherfunction(value) would be
> called if (and only if) the arg keyword parameter was missing from the
> function() call (ie. the optional value is evaluated the lazy way).

what otherfunction?  what value?

 



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


Re: Tabnanny really useful?

2004-12-21 Thread Franz Steinhaeusler
On Tue, 21 Dec 2004 09:34:47 -0500, Steve Holden <[EMAIL PROTECTED]>
wrote:


Hello Steve,

>I've used drpython, and liked it. 

thank you, I'm sure, our project Admin will be pleased to hear this :)

>I think it would be a good way for 
>people to start to use the language, 

yes, this project is intended to fulfill this purpose.

>as it avoids the "just the command 
>line" syndrome without being as complex as IDLE or PythonWin. 

I think, it isn't too far away from these two anymore ;)
Considering the expansion with scripts and plugins,
and there are a several of them available.

>In short, 
>just about right for a beginner.

I use it exclusively for a few months for any Python source editing.

>
>regards
>  Steve

regards,
-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Change vars in the parent process

2004-12-21 Thread Markus Franz
Hi!


Is there any possibility to change vars inside a parent process from
the inside of a child process?
Thanks


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


How to extend inner classes?

2004-12-21 Thread harold fellermann
Thank you very much. Of course I know how to do it in python. The
problem is that I want to reimplement these classes as a python
extension in C. The question is: how can I add class members (like
e.g. inner classes) to a PyTypeObject defined in a C extension?

- harold -


> You can define a class variable Pos with the class Pos as its value
> 
> class PeriodicGrid :
> class Pos:
>  pass
> Pos = Pos 
> 
> >>> grid = PeriodicGrid()
> >>> grid.Pos()
> <__main__.Pos instance at 0x00EEFAD0>
> 
> Ciao
> Kay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-21 Thread Ruben Baumann

"Doug Holton" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Mike Meyer wrote:
>> Logo (my pick) has been called "Lisp without the parenthesis". It has
>> the advantage of using standard algebraic notation for formulas,
>> instead of operator post or pre.
>>
>> 
> This is comp.lang.python, not comp.lang.logo.  Please refrain from 
> discussing topics not related to CPython.


Holton, you've turned into a boring ass.

So you got your feelings hurt.

Get over it!  Call 1-800-'Boo'-hoo!

RB



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


Re: Processes and their childs

2004-12-21 Thread Jeff Epler
"flush" your files before forking.

For me, this program gives the correct output 'hello\n' when correct=1.  
When correct=0, I get either 'hello\nhello' or 'hellohello\n' as output.


correct = 0
import sys, os
sys.stdout.write('hello')
if correct: sys.stdout.flush()
if os.fork() == 0: sys.stdout.write('\n')


Jeff


pgpDFwCkshuhD.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Parallelization with Python: which, where, how?

2004-12-21 Thread Jp Calderone
On 21 Dec 2004 05:04:36 -0800, Mike M?ller <[EMAIL PROTECTED]> wrote:
>> Can someone recommend a parallelization approach? Are there examples or 
> > documentation? Has someone got experience with stability and efficiency?
> 
> I am successfully using pyro http://pyro.sourceforge.net for my
> parallelization task (8 node Linux cluster, embarrassing parallel).
> It comes with a good documentation and it is easy to use. It works on
> clusters as well as on heterogeneous networks. You just need to start
> a server on each cluster node (e.g. rsh node1 startserver.py). You
> also need a name server running (maybe on your master node). Then a
> client can just asks a server to calculate and gets some result back.
> You can also send an object that calculates on the server and comes
> back including the result.
> 
> There are some examples included in the documentation you can start
> with and just change the parts that are specific to your application.
> 
> It is easy to understand and use and has been working well for me for
> more than 2 years.

  How have you chosen to deal with the security implications?

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


Re: Problem with msvcrt60 vs. msvcr71 vs. strdup/free

2004-12-21 Thread Thomas Heller
Gerhard Haering <[EMAIL PROTECTED]> writes:

> Hello,
>
> I used to build Python extension modules with mingw. Now, Python has
> switched to the MSVCR71 runtime with version 2.4, and I thought mingw
> has support for this. But I get problems with symbols being referenced
> from the wrong DLLs.
>
> You can see the problem by compiling this:
>
> ##
> #include 
>
> int main()
> {
> char* s;
> int i;
>
>
> for (i = 0; i < 10; i++) {
> s = strdup("foo");
> free(s);
> }
>
> return 0;
> }
> ##
>
> with gcc x.c -lmsvcr71
>
> Then if you run a.exe it crashes.
>
> If you use depends.exe on it, you see that it resolves strdup() via
> msvcrt, but the rest with msvcr71.dll. That's why strdup() is using
> the one malloc, but free() a different free() from the other DLL,
> which is undoubtedly the reason for the crash.
>
> Is there any way I can force mingw to not link in msvcr for things
> like strdup?

Only guesswork, but replacing this section in the
lib\gcc-lib\mingw32\3.2.3\specs file (I can only guess wht this file does)

  *libgcc:
  %{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt

with this one:

  *libgcc:
  %{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcr71

seemed to do the trick.

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


Problem with msvcrt60 vs. msvcr71 vs. strdup/free

2004-12-21 Thread Gerhard Haering
Hello,

I used to build Python extension modules with mingw. Now, Python has
switched to the MSVCR71 runtime with version 2.4, and I thought mingw
has support for this. But I get problems with symbols being referenced
from the wrong DLLs.

You can see the problem by compiling this:

##
#include 

int main()
{
char* s;
int i;


for (i = 0; i < 10; i++) {
s = strdup("foo");
free(s);
}

return 0;
}
##

with gcc x.c -lmsvcr71

Then if you run a.exe it crashes.

If you use depends.exe on it, you see that it resolves strdup() via
msvcrt, but the rest with msvcr71.dll. That's why strdup() is using
the one malloc, but free() a different free() from the other DLL,
which is undoubtedly the reason for the crash.

Is there any way I can force mingw to not link in msvcr for things
like strdup?

I think I found a very strange and ugly workaround: if I use _strdup()
instead of strdup(), it is resolved using the msvcr71 DLL.

I hope it is (soon) possible to use only the msvcr71 runtime from the
mingw compiler.

-- Gerhard
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


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

Re: python cookbook

2004-12-21 Thread Franz Steinhaeusler
On Tue, 21 Dec 2004 14:54:23 +0100, emami <[EMAIL PROTECTED]> wrote:

>L.S.,
>
>I have heard that Python cookbook is free! Could somebody tell me where 
>I can find it?
>
>[...]

You mean, the whole cookbook as chm archive?

It was published first, but then removed again.
For reasons:

http://miaw.tcom.ou.edu/~dody/

regards
-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Processes and their childs

2004-12-21 Thread Markus Franz
Hi!


Inside a Python script (I use Python 2.4) several different child
processes are created by using os.fork().

My problem: I want only the parent process to print some output and
then create the child processes. But even If I use print BEFORE using
os.fork, everything that was printed by the parent process untill this
point is printed by every child process again. How can I avoid this?

Does anybody habe a solution for my problem???
Thanks.


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


Re: Tabnanny really useful?

2004-12-21 Thread John Roth
"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Do you think tabnanny is a useful piece of code now? I used it a lot when 
I first started using Python, and still run it over code from unknown 
sources (no pun intended) from time to time.
I think it's a lot less useful today than it was a few
years ago, but it's still useful if you're stuck with an
editor that doesn't give you a robust set of options,
or if you've got to check a lot of modules in a library.
I think most python-aware editors have included
the needed functionality, or at least some reasonable
approximation.
I know what I would like to see in an editor:
First, it autodetects whether the module uses
tabs consistently, spaces consistently or a
mixture. If it uses tabs consistently, it then
uses the current default.
If it uses spaces consistently, it should also
autodetect the indentation setting in use in
the module and offer to change it if it's
different from the current default indentation
setting.
If it's inconsistent, it should make an attempt
to deduce the model the creating software
used; if it can it should change it to the
default setting without complaining. Otherwise
it should complain.
John Roth
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Read word tables

2004-12-21 Thread Thomas Guettler
Am Tue, 21 Dec 2004 11:24:35 + schrieb Rameshwari:

> 
> Hi,
> 
> I would like to read a ms-word document using python.
> 
> Basically the word document contains number of tables  and the rows 
> in each table do not have same number of columns.
> 
> Does anyone have a sample code to read a table?

Hi,

There is a small script[1] which parses the XML produced
by Excel. Something like this should be possible for msword, too.

Other way: You can export to the openoffice format and unzip it.
The read these xml files.

HTH,
  Thomas

[1]:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/192914

-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: Tabnanny really useful?

2004-12-21 Thread Steve Holden
John Roth wrote:
[...]
I know what I would like to see in an editor:
First, it autodetects whether the module uses
tabs consistently, spaces consistently or a
mixture. If it uses tabs consistently, it then
uses the current default.
If it uses spaces consistently, it should also
autodetect the indentation setting in use in
the module and offer to change it if it's
different from the current default indentation
setting.
If it's inconsistent, it should make an attempt
to deduce the model the creating software
used; if it can it should change it to the
default setting without complaining. Otherwise
it should complain.
John Roth
Sounds like WingIDE to me. I'm a recent convert, but one feature that 
impressed me was the instant warning I got when I indented code with 
spaces in a tab-oriented source file.

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


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread harold fellermann
Hi,
I cannot see any strange behavior. this code works exacly as you and I 
suspect:

>>> def otherfunction(x) :
... return x
...
>>> def function(arg=otherfunction(5)) :
... return arg
...
>>> function(3)
3
>>> function()
5
Or is this not what you excepted?
- harold -
On 21.12.2004, at 15:47, [EMAIL PROTECTED] wrote:
def function(arg=otherfunction(value)):
return arg
My expectation would have been that otherfunction(value) would be
called if (and only if) the arg keyword parameter was missing from the
function() call (ie. the optional value is evaluated the lazy way).
Also, otherfunction would be called each and every time this function()
is called without the arg keyword. (At least, I would have assumed this
before today)
Still, I can see why it's been implemented the way it has, it just
seems a shame there isn't a neat shortcut to default lots of optional
arguments to new mutable objects. And since I'm not the only one to
fall into this trap it makes me wonder why the default behaviour isn't
made to be what most people seem to expect?
--
http://mail.python.org/mailman/listinfo/python-list

--
Freunde, nur Mut,
Lächelt und sprecht:
Die Menschen sind gut --
Bloß die Leute sind schlecht.
-- Erich Kästner
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boo who? (was Re: newbie question)

2004-12-21 Thread Aahz
In article <[EMAIL PROTECTED]>,
Michael Hoffman  <[EMAIL PROTECTED]> wrote:
>Doug Holton wrote:
>> Istvan Albert wrote:
>>>
>>> All that boo does is borrows a few syntactical constructs
>>> from python. Calling it virtually identical
>>> is *very* misleading.
>> 
>> The syntax is indeed virtually identical to python.  You are yet another 
>> person who has trolled before.  See your obvious trolling reply here,
>
>You keep using that word. I do not think it means what you think it means.

Inconceivable!
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread Fredrik Lundh
"harold fellermann" wrote:

> I cannot see any strange behavior. this code works exacly as you and I 
> suspect:

you seem to have missed some of the posts that led up to the one you
replied to.  (most importantly, the first one).

 



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


Re: Keyword arguments - strange behaviour?

2004-12-21 Thread Steve Holden
harold fellermann wrote:
Hi,
I cannot see any strange behavior. this code works exacly as you and I 
suspect:

 >>> def otherfunction(x) :
 return x

 >>> def function(arg=otherfunction(5)) :
 return arg

 >>> function(3)
3
 >>> function()
5
Or is this not what you excepted?
Channelling the effbot, I think he was asking what namespace context you 
expected the expression "arg=otherfunction(x)" to be evaluated in when 
it's used at the time of a function call to dynamically create a new 
default value for arg.

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


Re: atmosphere on c.l.py (WAS: How about "pure virtual methods"?)

2004-12-21 Thread Aahz
In article <[EMAIL PROTECTED]>,
Doug Holton  <[EMAIL PROTECTED]> wrote:
>
>Unfortunately, I may have jumped the gun on that one.  He does not even 
>acknowledge his behavior outside of the three instances he referred to.

>From my POV, your use of a munged e-mail address makes you far more
antisocial than Fredrik.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question

2004-12-21 Thread Peter Hansen
Luis M. Gonzalez wrote:
As far as I could see, everythime the word "boo" is typed, some sort of
censorship or plain bashing comes up, and I think this is not fair.
Luis, your defense of the genial nature of the newsgroup/mailing list
is admirable, and I thank you for it.
I think doing this by defending Doug's postings, however, might weaken
the strength of your position just a little. (Okay, I mean "a lot".)
About the only time the word "boo" _does_ come up, it comes up
in one of Doug's posts, often in an apparent attempt to "help"
a Python newbie by pointing him in a misleading manner to
an entirely different language which just happens to have a syntax
that was inspired by and looks a fair bit like Python's.
Until Doug posted about "virtually identical" (and note he didn't
mention the syntax at the time, thus my wondering if he meant
the whole language), I had never noticed him or Boo.  Yes, in
spite of all the past postings.  I look at postings by newbies
and try to help; I rarely look carefully at the other replies,
and if I ever saw a "there's also this thing called Boo" post,
I suspect I just mentally blanked out of disinterest and moved on.
As a result of all the activity in the "Boo who?" thread, however,
I went and searched a bit to find out who this Doug character is.
It turns out that he's been mentioning Boo in postings *to newbies*
repeatedly over the last few months.  These are people trying
to use Python, having a question or difficulty about it, and he
launches into a sales job about some other language.
Would you defend someone who came into this group and responded
(admittedly helpfully, sometimes, in other ways) to newbie
questions by constantly saying "you can do this much more easily
in Perl of course, see www.perl.codehaus.org"?  I think you'd
find that after the first few posts like that, it was getting
tedious.  Then downright offensive.  And yet Perl has more in
common with Python than Boo does!
What Doug has been doing is like standing at the door of
a mission run by a church and trying to redirect those coming
for help to a different church down the street, with promises
that the meals are better.  And when one of the volunteers comes
out and looks offended, he turns on them and accuses them
of religious persecution, and being unfriendly to boot.
By the way, this is from comp.lang.python home page:
"Pretty much anything Python-related is fair game for discussion, and
the group is even fairly tolerant of off-topic digressions"
Boo is not Python related.  It's that simple.  Boo has some
passing resemblance to Python, and claims that it's much
more than that are patently false.  And clearly designed
to be marketing propaganda to get more Boo users onboard.
I wouldn't have seen this with only one or two posts by Doug,
but after reviewing his recent posting history I can only
say that I'm actually appalled at his gall in the matter.
Seeing what was going on in this thread, I think that we probably
should delete this part, because this is getting far from "fairly
tolerant".
I believe the definition of "fairly tolerant" doesn't necessarily
imply total tolerance of all topics under any circumstances.
(And I know you didn't mean that.)
If Doug wants to come in from time to time and mention Boo,
however, he's welcome to do so.  (And no, I'm not a moderator,
I just get one opinion, like everybody else.)  He might get
a few people questioning Boo's merits each time, but that's
par for the course.  If he doesn't like the heat, he can stay
out of the kitchen.  More likely, if he can accept such posts,
or ignore them, he'll be making his point, marketing his pet
language, and making a few converts.
If, on the other hand, he keeps jumping on newbies, who I
imagine are often overwhelmed by Python as it is, and who
just want an answer to their one simple question, and he
shouts "Boo" at them all the time, then the rest of us are
going to feel both offended that he's standing on our corner
where we're trying to help people, and worried that he's
misrepresenting Boo to Python newbies and confusing them
even more than they might already be.  Doug: move on,
there's another street corner just down thataway, and
it's called comp.lang.boo.  Or the Boo mailing list or
your own blog or something.
I could go on, but that's enough of a rant as it is.  Luis,
I have appreciated reading your thoughtful and caring words
on this whole subject, and I understand your point of view.
I just don't share it in this instance and wanted to get
this off my chest.  Thanks for listening. :-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tabnanny really useful?

2004-12-21 Thread Franz Steinhaeusler
On Tue, 21 Dec 2004 09:06:12 -0600, "John Roth"
<[EMAIL PROTECTED]> wrote:

>
>"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
>news:[EMAIL PROTECTED]
>
>> Do you think tabnanny is a useful piece of code now? I used it a lot when 
>> I first started using Python, and still run it over code from unknown 
>> sources (no pun intended) from time to time.
>
>I think it's a lot less useful today than it was a few
>years ago, but it's still useful if you're stuck with an
>editor that doesn't give you a robust set of options,
>or if you've got to check a lot of modules in a library.
>
>I think most python-aware editors have included
>the needed functionality, or at least some reasonable
>approximation.
>
>I know what I would like to see in an editor:
>
>First, it autodetects whether the module uses
>tabs consistently, spaces consistently or a
>mixture. If it uses tabs consistently, it then
>uses the current default.
>

>If it uses spaces consistently, it should also
>autodetect the indentation setting in use in
>the module and offer to change it if it's
>different from the current default indentation
>setting.
>
>If it's inconsistent, it should make an attempt
>to deduce the model the creating software
>used; if it can it should change it to the
>default setting without complaining. Otherwise
>it should complain.


Again, DrPython does this almost as you described ;)

There is an option in the preferences:
"Use File's Indentation"

and the indent setttings are set to the one,
what is found in the opened source file.

In the status line, the mode "SPACES" or "TABS" or
"MIXED" is displayed.

There are also the functions:
Edit=>Whitespace=>Check Indentation
Edit=>Whitespace=>Set Indentation to spaces 
(replaces all tabs with the preset nr of spaces for tab

Exception 1:
 (it could set then the tab mode to spaces)
and respectively:
Edit=>Whitespace=>Set Indentation to spaces 

Exception 2:

If open a file, there could be a check, whether 
tabs and spaces indentations are mixed, try to correct
if possible or complain (let the user decide).

=> Feature Request ;)

regards,
-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-21 Thread Antoon Pardon
Op 2004-12-21, Nick Coghlan schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Why then doesn't python think the same about sorted lists. When I have a
>> sorted list and do operations on it that depend on it being sorted,
>> I can mess things up just as easily by mutating an element in that
>> sorted list as I can mess things up by mutating a dictionary key.
>
> Incorrect, and this appears to be the point where our major disagreement lies.
>
> Mutate a value in a sorted list and you can fix that easily, just by calling 
> its 
> sort() method again (and, in fact, mutate and resort is a fairly common idiom 
> for small datasets). 'sorted' and 'heapified' are list properties that are 
> easily broken by direct manipulation, but are also easily restored by once 
> again 
> 'sorting' or 'heapifying'.

That is an implemantation detail. Likewise a dictionary is probably not
always in a sane state when a new key is inserted. The fact remains that
in a sorted list or a heap, mutating an element arbitrarily can mess up
things greatly.

> Change the hash value of an item used as a key in a dictionary, and *the 
> internal state of the dictionary is likely to broken in a manner you probably 
> cannot fix*. The only reason the 'probably' is there is because you should be 
> able to 'fix it' by changing the hash value back to what it was originally.

I could argue that this is then a failing of dictionary that doesn't
provide a method to clean up after a key is mutated.

> Waitasec - wouldn't it be easier if dictionaries just made it a rule that the 
> hash value wasn't allowed to change? Hang on, that's exactly what they do.

No it is not.

And yes I know what to do if I want to use mutable keys as objects. I'm
just argueing against those who think that should be somehow forbidden.

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


Re: how to pass globals across modules (wxPython)

2004-12-21 Thread Jorge Luiz Godoy Filho
Peter Hansen, Segunda 20 Dezembro 2004 08:01, wrote:

> An even better approach might be to find a way to avoid
> having to access the main window through a global, but
> I'll have to leave this up to you, as it may depend on
> your program structure.

This might be a problem also to share a database connection, where one needs
to pass the open and authenticated connection to several specialized
modules. 

Maybe a module where you can access that should be a better option...

Be seeing you,
Godoy.
-- 
http://mail.python.org/mailman/listinfo/python-list


getting env variable from bourne shell script

2004-12-21 Thread biner
Hello,

  I have file called PARAMETRES that is used in bourne shell script to
define variable. In order to do so I put a ". PARAMETRES" line and the
script has acces to all the variable defined in the PARAMETRES file.

  Now, I would like to be able to get the same thing in python. I
googled and played with os.system to try to come up with something but
no success so far. I also tryed exec but it doesn't work becaus a lot
of string variable difined in the PARAMETRES file do not have the '
sign needed in python string.

  for example. Let's say I have a file PARAMETRES containing
TOTO=whatever, I would like to have a command to read that file and
have the variable TOTO='whatever' in python.

Thanks for any help.

Sébastien
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to pass globals across modules (wxPython)

2004-12-21 Thread Fredrik Lundh
Jorge Luiz Godoy Filho wrote:

>> An even better approach might be to find a way to avoid
>> having to access the main window through a global, but
>> I'll have to leave this up to you, as it may depend on
>> your program structure.
>
> This might be a problem also to share a database connection, where one needs
> to pass the open and authenticated connection to several specialized
> modules.
>
> Maybe a module where you can access that should be a better option...

or a single "application context class" instance, which is passed to various
parts of the system as necessary.

making subsystems dependent on a module can hinder reuse; making them
dependent on (parts of) the interface of an application context object makes
them a lot easier to reuse.

 



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


Re: getting env variable from bourne shell script

2004-12-21 Thread Thomas Guettler
Am Tue, 21 Dec 2004 07:51:53 -0800 schrieb biner:

> Hello,
> 
>   I have file called PARAMETRES that is used in bourne shell script to
> define variable. In order to do so I put a ". PARAMETRES" line and the
> script has acces to all the variable defined in the PARAMETRES file.

Hi,

you can run ". PARAMETERS; set" with popen. Then read stdin and
parse the lines:

The lines from stdin look like this:

ACLOCAL_PATH=/opt/gnome/share/aclocal
BASH=/bin/bash
BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release" 
[5]="i586-suse-linux")
BASH_VERSION='2.05b.0(1)-release'
COLORTERM=1
COLUMNS=143
CPU=i686
CVSROOT=:ext:[EMAIL PROTECTED]:/raid/develop
CVS_RSH=ssh
 

you could use '^(.*?)=(.*)$' as regex to parse each line
group(1) is the variable name group(2) the value.

 HTH,
   Thomas



-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: getting env variable from bourne shell script

2004-12-21 Thread Fredrik Lundh
Thomas Guettler wrote:

> you could use '^(.*?)=(.*)$' as regex to parse each line
> group(1) is the variable name group(2) the value.

may I recommend:

key, value = line.split("=", 1)

 



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


PyCon is coming - we need your help

2004-12-21 Thread Steve Holden

Dear Python User:

I wonder if you would be kind enough to take the time to
read this email and help us to publicize PyCon DC 2005,
being held March 23-26 at the Cafritz Conference Center of
George Washington University.

The Call for Participation went out some time ago, but it
is a good time to remind people that the deadline for
submissions is December 31. If you personally are thinking
of submitting a paper then this can be a reminder to do so
soon!

We already have acceptances from two keynote speakers, and
hope to announce them when a third is finalised shortly.

As always you can find out about the conference at

http://www.pycon.org/
http://www.python.org/pycon/

This year we are going to be able to accept credit card
payments for the first time, which we hope will be more
convenient for delegates.

The registration fees this year are the same as for 2004:

Early Bird (to Jan 22)   $175 ($125 student)
Regular (to Mar 19)  $250 ($175 student)
On-Site  $300 ($225 student)

A further announcment will be made when the registration
site opens for business. In the meantime I would appreciate
your assistance in posting this message via any channels you
know of that have an interest in the Python language and its
applications - publicity is the key to getting the most
diverse group of people at PyCon.


regards
Steve Holden
Chairman, PyCON DC 2005
-- 
PyCon DC 2005: The third Python Community Conference
http://www.pycon.org/   http://www.python.org/pycon/
The scoop on Python implementations and applications
-- 
http://mail.python.org/mailman/listinfo/python-list


What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Doug Holton
Steve Holden wrote:
'Scuse me? This group has a long history of off-topic posting, and 
anyway who decided that CPython should be the exclusive focus? Even 
on-topic we can talk about Jython and PyPy as well as CPython.
I agree with your point, although Hans Nowak and others may not. 
Anything related to python or from the perspective of a current or 
potential python user is on-topic for this list.  We can talk about 
logo, jython, java or other topics whenever and whereever we want.  If 
you can't accept free speech and different perspectives, you're going to 
be disappointed.  But please do not react by trying to intimidate and 
troll others here.
--
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-21 Thread Scott Robinson
On Mon, 20 Dec 2004 08:46:14 + (UTC), Alan Gauld
<[EMAIL PROTECTED]> wrote:

>> >>> was too late).  A machine designed to be run on Forth would have been
>> >>> unbelievably powerful from the late 70s to the mid 90s (it would be
>> >>> more painful now than the x86 legacy, but still).
>
>A small data point here is that Sun still use Forth in their
>Sparc workstations. Their system prompt is really a Forth
>interpreter... I don;t know where the interpreter resides,
>presumably not in Sparc since its a RISC but interesting that
>they still use it. (Or they did last time I used a 
>Sparc - 4 years ago?)
>
>Alan G.
>Author of the Learn to Program website
>http://www.freenetpages.co.uk/hp/alan.gauld

It was still there three years ago.  While debugging some Sun based
hardware I tried playing with it after it crashed.  Forth was still
there.  It certainly is useful for a hardware independent bios, but I
was making the point it would be good for general purpose.  I suspect
that it would quickly run up against memory limitations and would go
no faster than the machine driving the memory market (with a possible
last gasp when Rambus came online).

Scott Robinson

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


  1   2   3   >