Re: setup.py and file extensions like ".c++"

2006-08-24 Thread Glenn Hutchings
[EMAIL PROTECTED] wrote:
> Is there any way to get setup.py to recognize file extensions like .c++
> in lieu of .cpp?  I'd love to not have to rename the source files for
> the library I'm trying to wrap in a python C extension.

The python docs imply that the file extension is dealt with by the
native C++ build system, so you have to use a recognized suffix (either
.cpp or .cc, and possibly others).  Looks like .c++ isn't a standard
one.  See

http://docs.python.org/dist/describing-extensions.html#SECTION00232

Glenn

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


Re: pickling and endianess

2006-08-24 Thread Chandrashekhar Kaushik
 >> What about old ASCII?    
The data is large .it also contains floats & double , so ascii will cause two problems -> loss of precision and the data will bloat  --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: lazy arithmetic

2006-08-24 Thread Gabriel G

At Friday 25/8/2006 02:18, [EMAIL PROTECTED] wrote:


> x+y get translated to x.__add__(y)

No that's not true at all. The self argument to __add__ ends
up being the Add instance, not the Item instance:

z=x+y  is translated to z.__add__(y)


Well, I deleted my response after I noticed that Simon Forman has 
done it very well.
Just a note: print z after this line and compare with self inside 
__init__ if you're still not convinced.




Gabriel Genellina
Softlab SRL 






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


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

Re: pickling and endianess

2006-08-24 Thread Gabriel Genellina

At Friday 25/8/2006 03:37, Chandrashekhar Kaushik wrote:

I dont think i really need that much . Just need to be able to send 
data across the network and then retrieve it properly independent of 
the architecture at the remote end :)


What about old ASCII?



Gabriel Genellina
Softlab SRL 






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


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

Re: pickling and endianess

2006-08-24 Thread Chandrashekhar Kaushik
The pickletools.py seems to be giving cool info on the same ( the PM virual machine and all ). Will try to salvage something out of that. I dont think i really need that much . Just need to be able to send data across the network and then retrieve it properly independent of the architecture at the remote end :)
On 8/25/06, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
At Friday 25/8/2006 03:17, Chandrashekhar Kaushik wrote:>I am actually looking to implement serialization routines in C++.>An am facing the problem of how to tackle endianess and sizeof issues.>
>Could you give me a overview of how pickling is done in python ?>Reading pickle.py is obviously the option , but its getting daunting>as i am not that proficient in python :( .Uhm, I think this is a bit hard... The pickle format is actually code
for a stack-based machine, which gets interpreted when you load it.I think you should look for another example implementation; perhapsJava Serializable?Gabriel GenellinaSoftlab SRL
__Preguntá. Respondé. Descubrí.Todo lo que querías saber, y lo que ni imaginabas,está en Yahoo! Respuestas (Beta).¡Probalo ya!
http://www.yahoo.com.ar/respuestas-- --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pickling and endianess

2006-08-24 Thread Gabriel Genellina

At Friday 25/8/2006 03:17, Chandrashekhar Kaushik wrote:


I am actually looking to implement serialization routines in C++.
An am facing the problem of how to tackle endianess and sizeof issues.

Could you give me a overview of how pickling is done in python ? 
Reading pickle.py is obviously the option , but its getting daunting 
as i am not that proficient in python :( .


Uhm, I think this is a bit hard... The pickle format is actually code 
for a stack-based machine, which gets interpreted when you load it.
I think you should look for another example implementation; perhaps 
Java Serializable?




Gabriel Genellina
Softlab SRL 






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


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

Re: pickling and endianess

2006-08-24 Thread Fredrik Lundh
Chandrashekhar Kaushik wrote:

> Thank you for the information.
> A request though.
> 
> I am actually looking to implement serialization routines in C++.
> An am facing the problem of how to tackle endianess and sizeof issues.
> 
> Could you give me a overview of how pickling is done in python ? Reading 
> pickle.py is obviously the option , but its getting daunting as i am not 
> that proficient in python :( .

wouldn't it make more sense to *use* an existing C++ serialization 
library ?  e.g.

 http://www.boost.org/libs/serialization/doc/index.html

(or at least look at that one, or one of the other libraries linked from 
that page, instead of asking Python developers to help you solve a C++ 
task.)



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


Re: pickling and endianess

2006-08-24 Thread Chandrashekhar Kaushik
Thank you for the information.A request though.I am actually looking to implement serialization routines in C++.An am facing the problem of how to tackle endianess and sizeof issues.Could you give me a overview of how pickling is done in python ? Reading 
pickle.py is obviously the option , but its getting daunting as i am not that proficient in python :( .On 8/25/06, Tim Peters <
[EMAIL PROTECTED]> wrote:[Chandrashekhar kaushik]> Can an object pickled and saved on a little-endian machine be unpickled
> on a big-endian machine ?Yes.  The pickle format is platform-independent (native endiannessdoesn't matter, and neither do the native sizes of C's various integertypes).> Does python handle this in some manner  , by say having a flag to indicate
> the endianess of the machine on which the object was pickled ?  And then> using this flag to decide how that data will be unpickled ?Not a flag, no, the pickle format is the same on all platforms.  If
you need to know details, read pickle.py.--http://mail.python.org/mailman/listinfo/python-list-- 
--shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is this a good idea or a waste of time?

2006-08-24 Thread Simon Forman
asincero wrote:
> Would it be considered good form to begin every method or function with
> a bunch of asserts checking to see if the parameters are of the correct
> type (in addition to seeing if they meet other kinds of precondition
> constraints)?  Like:
>
> def foo(a, b, c, d):
>assert type(a) == str
>assert type(b) == str
>assert type(c) == int
>assert type(d) == bool
># rest of function follows
>
> This is something I miss from working with more stricter languages like
> C++, where the compiler will tell you if a parameter is the wrong type.
>  If anything, I think it goes a long way towards the code being more
> self documenting.  Or is this a waste of time and not really "the
> Python way"?
>
> -- Arcadio

Generally asserts should be used to "enforce" invariants of your code
(as opposed to typechecking), or to check certain things while
debugging.

FWIW, if I saw code that that you presented here I'd assume the
programmer who wrote it was either very new(-bie-ish) or just very very
paranoid, so I guess I could say it's not pythonic...  :-)

BTW, speaking of "strictness",  "more stricter" is invalid English,
just "stricter" is the "correct" form.  ;-)

Peace,
~Simon

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


Re: pickling and endianess

2006-08-24 Thread Tim Peters
[Chandrashekhar kaushik]
> Can an object pickled and saved on a little-endian machine be unpickled
> on a big-endian machine ?

Yes.  The pickle format is platform-independent (native endianness
doesn't matter, and neither do the native sizes of C's various integer
types).

> Does python handle this in some manner  , by say having a flag to indicate
> the endianess of the machine on which the object was pickled ?  And then
> using this flag to decide how that data will be unpickled ?

Not a flag, no, the pickle format is the same on all platforms.  If
you need to know details, read pickle.py.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pickling and endianess

2006-08-24 Thread Fredrik Lundh
Chandrashekhar kaushik wrote:

> Can an object pickled and saved on a little-endian machine be unpickled
> on a big-endian machine ?

yes.  the format uses a known byte order.



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


Re: lazy arithmetic

2006-08-24 Thread Simon Forman

[EMAIL PROTECTED] wrote:
> Simon Forman wrote:
>
> >
> > "Item.__add__ = Add" is a very strange thing to do, I'm not surprised
> > it didn't work.
>
> Yes it is strange.
> I also tried this even stranger thing:
>
> class Item(object):
>   class __add__(object):
> def __init__(self, a, b=None):
>   print self, a, b
>   self.a = a
>   self.b = b
> 
> :)
> 
> Simon.

That didn't work either did it? :-)

~Simon F.

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


Re: lazy arithmetic

2006-08-24 Thread Simon Forman
[EMAIL PROTECTED] wrote:
> Gabriel Genellina wrote:
> > At Friday 25/8/2006 00:36, [EMAIL PROTECTED] wrote:
> >
> > ># This is what I have in mind:
> > >
> > >class Item(object):
> > >   def __add__(self, other):
> > > return Add(self, other)
> >
> > And this works fine... why make thinks complicated?
>
> Yes, I agree it's simpler, and up until now that's the way
> I always did it. Many Many times.
> Now I am looking for a way to build ensembles of these lazy classes at
> the meta-level.
> (think abstract algebra).
>
> > >Item.__add__ = Add
> >
> > This doesn't make sense... __add__ should be a method, not a class...
>
> No, that's not true. It can be this callable:
>
> def add(a, b):
>   return Add(a,b)
> Item.__add__ = add

But that's a function, not a class.  When you assign add to an
attribute of Item it "magically" becomes a method of Item:

|>> add

|>> Item.__add__

|>> x.__add__
>

So it works fine.


>
> So my thinking was this: why can't I use a callable class ?
>

When you assign a class to an attibute (be it __add__ or __banana__ or
anything else) the "magic" doesn't take place:

|>> Add

|>> Item.__banana__ = Add
|>> Item.__banana__




> > x+y get translated to x.__add__(y)
>
> No that's not true at all. The self argument to __add__ ends
> up being the Add instance, not the Item instance:

No, that's *exactly* true.  "x+y" does mean "x.__add__(y)" and
"x.__add__"  *is*  the class Add, so you're really calling "Add(y)",
nothing more nor less.

x+y  =>
x.__add__(y)  =>
(x.__add__)(y)  =>
Add(Y)  =>
Hello new Add instance, here's a y for you...  :-)

>
> z=x+y  is translated to z.__add__(y)

Nope.  Just plain wrong.  Not sure why you'd think that.
(No offense intended.)

Peace,
~Simon F.

> 
> Simon.

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


Re: Is this a good idea or a waste of time?

2006-08-24 Thread Qiangning Hong
On 24 Aug 2006 20:53:49 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> That's bad form. If you insist on doing something like this, at least
> use "isinstance(a, str)" instead of typeof.  But even that breaks duck
> typing; if a is a unicode string, that'll fail when the function may
> work fine for unicode strings.

To check both str and unicode, you could use "isinstance(a, basestring)".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lazy arithmetic

2006-08-24 Thread pianomaestro

Simon Forman wrote:

>
> "Item.__add__ = Add" is a very strange thing to do, I'm not surprised
> it didn't work.

Yes it is strange.
I also tried this even stranger thing:

class Item(object):
  class __add__(object):
def __init__(self, a, b=None):
  print self, a, b
  self.a = a
  self.b = b

:)

Simon.

> 
> HTH,
> ~Simon

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


Re: lazy arithmetic

2006-08-24 Thread pianomaestro

Gabriel Genellina wrote:
> At Friday 25/8/2006 00:36, [EMAIL PROTECTED] wrote:
>
> ># This is what I have in mind:
> >
> >class Item(object):
> >   def __add__(self, other):
> > return Add(self, other)
>
> And this works fine... why make thinks complicated?

Yes, I agree it's simpler, and up until now that's the way
I always did it. Many Many times.
Now I am looking for a way to build ensembles of these lazy classes at
the meta-level.
(think abstract algebra).

> >Item.__add__ = Add
>
> This doesn't make sense... __add__ should be a method, not a class...

No, that's not true. It can be this callable:

def add(a, b):
  return Add(a,b)
Item.__add__ = add

So my thinking was this: why can't I use a callable class ?

> x+y get translated to x.__add__(y)

No that's not true at all. The self argument to __add__ ends
up being the Add instance, not the Item instance:

z=x+y  is translated to z.__add__(y)

Simon.

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


pickling and endianess

2006-08-24 Thread Chandrashekhar kaushik
Can an object pickled and saved on a little-endian machine be unpickledon a big-endian machine ? Does python handle this in some manner  , by say having a flag to indicatethe endianess of the machine on which the object was pickled ?  And then 
using this flag to decide how that data will be unpickled ?shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: RE Module

2006-08-24 Thread Simon Forman
Roman wrote:
> I am trying to filter a column in a list of all html tags.

What?

> To do that, I have setup the following statement.
>
> row[0] = re.sub(r'<.*?>', '', row[0])
>
> The results I get are sporatic.  Sometimes two tags are removed.
> Sometimes 1 tag is removed.   Sometimes no tags are removed.  Could
> somebody tell me where have I gone wrong here?
>
> Thanks in advance

I'm no re expert, so I won't try to advise you on your re, but it might
help those who are if you gave examples of your input and output data.
What results are you getting for what input strings.

Also, if you're just trying to strip html markup to get plain text from
a file, "w3m -dump some.html"  works great.  ;-)

HTH,
~Simon

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


Re: lazy arithmetic

2006-08-24 Thread Simon Forman
[EMAIL PROTECTED] wrote:
> # This is what I have in mind:
>
> class Item(object):
>   def __add__(self, other):
> return Add(self, other)
>
> class Add(Item):
>   def __init__(self, a, b):
> self.a = a
> self.b = b
>
> a = Item()
> b = Item()
>
> c = a+b
>
> # Now, I am going absolutely crazy with this idea
> # and using it in a big way. So I'm looking at
> # automating the process. As a first step,
> # I thought maybe this would work:
>
> class Item(object):
>   pass
>
> class Add(Item):
>   def __init__(self, a, b=None):
> print self, a, b
> self.a = a
> self.b = b
>
> Item.__add__ = Add
>
> x = Item()
> y = Item()
>
> print x, y
>
> c = x+y
>
> # This time, the Add constructor gets only the first two arguments:
> "self" and "y".
> # So, what happened to "x" ? Is this some kind of property voodoo going
> on ?
>
> # Simon.

Look at the signature for __add__:

__add__(self, other)

Now look at the signature for __init__:

__init__(self, a, b=None)

Now look at the output of your script:

|>>
<__main__.Item object at 0xb6faa4ac> <__main__.Item object at
0xb6faa3ec>
<__main__.Add object at 0xb6faa5ec> <__main__.Item object at
0xb6faa3ec> None


When python calls x.__add__ as a result of "x+y" it only passes it y as
'other', or, in this case, as 'a'.  The 'self' arg gets filled in with
a brand new Add instance, because __add__ (rather than being a method
of Item) is really the class Add.  (b will never be filled in using the
Add.__init__ method this way.)

Consider:

|>> x
<__main__.Item object at 0xb6f10f0c>
|>> x.__add__

|>> Badd = x.__add__
|>> Badd

|>> b = Badd(23, 18)
<__main__.Add object at 0xb6f10e8c> 23 18
|>> b
<__main__.Add object at 0xb6f10e8c>

Make more sense? :-)

"Item.__add__ = Add" is a very strange thing to do, I'm not surprised
it didn't work.

HTH,
~Simon

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


Re: lazy arithmetic

2006-08-24 Thread Gabriel Genellina

At Friday 25/8/2006 00:36, [EMAIL PROTECTED] wrote:


# This is what I have in mind:

class Item(object):
  def __add__(self, other):
return Add(self, other)


And this works fine... why make thinks complicated?


# Now, I am going absolutely crazy with this idea
# and using it in a big way. So I'm looking at
# automating the process. As a first step,
# I thought maybe this would work:

class Item(object):
  pass

class Add(Item):
  def __init__(self, a, b=None):
print self, a, b
self.a = a
self.b = b

Item.__add__ = Add


This doesn't make sense... __add__ should be a method, not a class...



x = Item()
y = Item()

print x, y

c = x+y

# This time, the Add constructor gets only the first two arguments:
"self" and "y".
# So, what happened to "x" ? Is this some kind of property voodoo going
on ?


x+y get translated to x.__add__(y)
x.__add__ is Add (the class), so Python calls Add, which means using 
it as a constructor with y as the (only) argument.
So you see in the __init__ method: self=a new instance of Add, a=y, 
b=None (default, as only one argument was provided).


If you really want to "inject" __add__ into the Item class, you could 
use a factory:


def AddFactory(a,b):
return Add(a,b)
Item.__add__ = AddFactory

(but as you've said yourself, that's a bit crazy...)


Gabriel Genellina
Softlab SRL 






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


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

Re: sum and strings

2006-08-24 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> There is an alternative: raise a warning instead of an exception. That
> permits the admirable strategy of educating users that join() is
> generally a better way to concatenate a large number of strings, while
> still allowing programmers who want to shoot themselves in the foot to do so.

This is reasonable, but why not just do the right thing and use the
right algorithm?  There is, after all, no guarantee in the docs that
''.join() uses the right algorithm either.  I've come to the view that
the docs should explicitly specify this type of thing, per the
Stepanov interview mentioned earlier.  You may be right that even when
it's not clear what the best algorithm is, using a correct but slow
algorithm is preferable to throwing an error.

But I think for strings, we should rethink how this kind of operation
is done, and build up the sum of strings in terms of some kind of mutable
string object resembling Java's StringBuf or Python's cStringIO objects.

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


Re: Best Practices for Python Script Development?

2006-08-24 Thread Richard Jones
metaperl wrote:
> Searching cheeseshop.python.org/pypi for getopt modules does not work
> very well by the way.

http://docs.python.org/lib/module-getopt.html


Richard

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


Re: sum and strings

2006-08-24 Thread Steven D'Aprano
On Thu, 24 Aug 2006 18:24:19 +0200, Fredrik Lundh wrote:

> besides, in all dictionaries I've consulted, the word "sum" means 
> "adding numbers".  are you sure it wouldn't be more predictable if "sum" 
> converted strings to numbers ?

And then on Thu, 24 Aug 2006 19:12:17 +0200 Fredrik also wrote:

> (and note that the python-dev consensus is that sum is for numbers and
> join is for strings.  anyone who cares about writing readable code knows
> that names matter; different things should have different names.)

And yet sum() sums lists, tuples, custom classes, and many other things
which are not numbers. Did python-dev not notice this? I doubt it.

I've read all the arguments in favour of type-checking the arguments to
sum() (actually only the second argument). I'm not convinced that this
case is special enough to break the rules by raising an exception for
strings. (Insert usual arguments about consistency, duck typing, least
surprise, etc.)

There is an alternative: raise a warning instead of an exception. That
permits the admirable strategy of educating users that join() is
generally a better way to concatenate a large number of strings, while
still allowing programmers who want to shoot themselves in the foot to do
so. Python generally allows the programmer to shoot himself in the foot,
if the programmer insists, e.g. private attributes are by convention, not
enforced by the language. That's one of the nice things about the
language: it *suggests* what to do, but doesn't *insist* it knows what you
want better than you do.



-- 
Steven D'Aprano 

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


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

2006-08-24 Thread Steven D'Aprano
On Wed, 23 Aug 2006 12:16:45 +0200, Fredrik Lundh wrote:

> Steven D'Aprano wrote:
> 
>> Here's a traceback. One of the arguments to spam() is too small. Can you
>> tell which one just by looking at the traceback?
>>
> a, b, c, d = range(4)
> spam(a, b, c, d)
>> Traceback (most recent call last):
>>  File "", line 1, in ?
>>  File "", line 6, in spam
>>  File "", line 5, in eggs
>>  File "", line 4, in beans
>> ValueError: x is too small
>>
>> Of course you can't. x could be any one of a, b, c or d, and the traceback
>> doesn't give you enough information to tell which.
> 
> for some reason, your example gives a different error on my machine:
> 
> StrawManError: Attempt to construct Reductio ad absurdum argument failed

Sheesh Fredrik, what's eating you? I'm trying to have a civil discussion,
and you're being deliberately obtuse.

If I'm factually wrong, if I've made an error of fact or logic, and
somebody points out where the error lies, I will accept that. I am always
willing to learn. But making fatuous, and false, accusations of strawman
and reductio ad absurdum fallacies doesn't invalidate my point that there
are occasions where the traceback refers to a object with one name, but
the object was created in a different scope with a different name. I'm not
making an extraordinary claim here -- what I said should be so obvious it
verges on the banal. The traceback reports the name of the object in the
scope the error occurred in. The line of code responsible for putting the
wrong data into that object can occur in a different scope, with a
different name. Is that really so hard to grasp?

I don't know what more I can do to get through to you that I *don't*
expect Python's object model to change to fix this one single issue. I've
said it AT LEAST twice times so far: such a change would be a lot of cost
for very minimal benefit. But after the undeserved roasting that Jojoba
received, it is only right to that we recognise that there are valid cases
for objects to know their own name -- even if, in the majority of cases,
those valid uses aren't worth the cost of implementing them.


-- 
Steven D'Aprano 

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


RE Module

2006-08-24 Thread Roman
I am trying to filter a column in a list of all html tags.

To do that, I have setup the following statement.

row[0] = re.sub(r'<.*?>', '', row[0])

The results I get are sporatic.  Sometimes two tags are removed.
Sometimes 1 tag is removed.   Sometimes no tags are removed.  Could
somebody tell me where have I gone wrong here?

Thanks in advance

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


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

2006-08-24 Thread Steven D'Aprano
On Wed, 23 Aug 2006 11:16:17 +0200, Sybren Stuvel wrote:

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

No, it is a *simplified* example. There's a difference between simplified
and bad. Would you have preferred me to post five pages of complex
function calls demonstrating the same point, namely that you can bind an
object to a name in one place, then pass it to a function where any
tracebacks will refer to the name in the local namespace rather than the
name in the traceback where the invalid data first existed?


> If you use a real-world function,
> you notice that the current error messages are just fine:
>
> def update(title):
> assert len(title)> 10, "Title too short"
> 
> update("hello")
> 
> would display: "AssertionError: Title too short". Seems fine to me.

Sure, in this case you back-track one level, and see that you passed a
string literal. Easy.

And in other cases, you don't pass a literal, you pass a name (say,
"windowtitle"), and now instead of looking for the name title you're
looking for the name windowtitle. Where did it come from? What's
it's value?

And in some cases, windowtitle wasn't bound to a literal either, it was
bound to (say) filename.upper(), so now you're no longer looking for
either title or windowtitle, but filename. Where did it get its value
from?



-- 
Steven D'Aprano 

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


Re: Is this a good idea or a waste of time?

2006-08-24 Thread [EMAIL PROTECTED]
asincero wrote:
> Would it be considered good form to begin every method or function with
> a bunch of asserts checking to see if the parameters are of the correct
> type (in addition to seeing if they meet other kinds of precondition
> constraints)?  Like:
>
> def foo(a, b, c, d):
>assert type(a) == str
>assert type(b) == str
>assert type(c) == int
>assert type(d) == bool
># rest of function follows

That's bad form. If you insist on doing something like this, at least
use "isinstance(a, str)" instead of typeof.  But even that breaks duck
typing; if a is a unicode string, that'll fail when the function may
work fine for unicode strings.

You could, of course, test explicitly for the interface you need (e.g.
if you need a to have "lower" and "rjust" methods, do assertion tests
for them).  But in practice you're generally better off simply using
the object and getting the exception a few lines lower.

Much of the power of dynamic typing comes from the duck typing concept,
so you should really try to familiarize yourself with it.

> This is something I miss from working with more stricter languages like
> C++, where the compiler will tell you if a parameter is the wrong type.

Stricter is the wrong word.  Python is strictly typed.  The difference
here is dynamic vs. static typing.

>  If anything, I think it goes a long way towards the code being more
> self documenting.  Or is this a waste of time and not really "the
> Python way"?

There are 3 main things that you can do to help here:
1. Choose better names for the arguments so that it's obvious what they
are.  I don't advocate Hungarian naming, normally something like "url"
or "shoeSize" will be strongly indicative of what kinds of values are
acceptable.
2. Write docstrings.  That will not only document the types but also
how they're used, what gets returned, and perhaps limits on exactly
what ranges of values are acceptable.
3. Write unit tests.  They'll catch far more errors than static typing
ever will.

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


lazy arithmetic

2006-08-24 Thread pianomaestro

# This is what I have in mind:

class Item(object):
  def __add__(self, other):
return Add(self, other)

class Add(Item):
  def __init__(self, a, b):
self.a = a
self.b = b

a = Item()
b = Item()

c = a+b

# Now, I am going absolutely crazy with this idea
# and using it in a big way. So I'm looking at
# automating the process. As a first step,
# I thought maybe this would work:

class Item(object):
  pass

class Add(Item):
  def __init__(self, a, b=None):
print self, a, b
self.a = a
self.b = b

Item.__add__ = Add

x = Item()
y = Item()

print x, y

c = x+y

# This time, the Add constructor gets only the first two arguments:
"self" and "y".
# So, what happened to "x" ? Is this some kind of property voodoo going
on ?

# Simon.

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


Re: Best Editor

2006-08-24 Thread assiss
some wxPy IDEs maybe better.

> Friends, I am trying to learn Python.
> It will be of great help to me if you let me know which one would be best 
> editor for learning Python.
> Plese note that I would like to have multiplatform editor which will be 
> useful for both LInux and Windows XP.
> Thanks.

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

Re: Taking data from a text file to parse html page

2006-08-24 Thread DH
SE looks very helpful... I'm having a hell of a time installing it
though:

-

[EMAIL PROTECTED]:~/Desktop/SE-2.2$ sudo python SETUP.PY install
running install
running build
running build_py
file SEL.py (for module SEL) not found
file SE.py (for module SE) not found
file SEL.py (for module SEL) not found
file SE.py (for module SE) not found

--
Anthra Norell wrote:
> You may also want to look at this stream editor:
>
> http://cheeseshop.python.org/pypi/SE/2.2%20beta
>
> It allows multiple replacements in a definition format of utmost simplicity:
>
> >>> your_example = '''
> "Python has been an important part of Google since the
> beginning, and remains so as the system grows and evolves.
> "
> -- Peter Norvig,  '''
> >>> import SE
> >>> Tag_Stripper = SE.SE ('''
>  "~<(.|\n)*?>~="   # This pattern finds all tags and deletes them 
> (replaces with nothing)
>  "~~="   # This pattern deletes comments entirely even 
> if they nest tags
>  ''')
> >>> print Tag_Stripper (your_example)
>
> "Python has been an important part of Google since the
> beginning, and remains so as the system grows and evolves.
> "
> -- Peter Norvig, 
> Now you see a tag fragment. So you add another deletion to the Tag_Stripper 
> (***):
>
> Tag_Stripper = SE.SE ('''
>  "~<(.|\n)*?>~="   # This pattern finds all tags and deletes them 
> (replaces with nothing)
>  "~~="   # This pattern deletes commentsentirely even 
> if they nest tags
>  "  # "-- Peter Norvig,  Norvig has to go too
>''')
> >>> print Tag_Stripper (your_example)
>
> "Python has been an important part of Google since the
> beginning, and remains so as the system grows and evolves.
> "
> -- Peter Norvig,
>
> " you can either translate or delete:
>
> Tag_Stripper = SE.SE ('''
>  "~<(.|\n)*?>~="   # This pattern finds all tags and deletes them 
> (replaces with nothing)
>  "~~="   # This pattern deletes commentsentirely even 
> if they nest tags
>  "  # "-- Peter Norvig,  Peter Norvig has to go too
>  htm2iso.se # This is a file (contained in the SE package that 
> translates all ampersand codes.
>   # Naming the file is all you need to do to 
> include the replacements which it defines.
>''')
>
> >>> print Tag_Stripper (your_example)
>
> 'Python has been an important part of Google since the
> beginning, and remains so as the system grows and evolves.
> '
> -- Peter Norvig,
>
> If instead of "htm2iso.se" you write ""=" you delete it and your output 
> will be:
>
> Python has been an important part of Google since the
> beginning, and remains so as the system grows and evolves.
>
> -- Peter Norvig,
>
> Your Tag_Stripper also does files:
>
> >>> print Tag_Stripper ('my_file.htm', 'my_file_without_tags')
> 'my_file_without_tags'
>
>
> A stream editor is not a substitute for a parser. It does handle more 
> economically simple translation jobs like this one where a
> parser does a lot of work which you don't need.
>
> Regards
>
> Frederic
>
>
> - Original Message -
> From: "DH" <[EMAIL PROTECTED]>
> Newsgroups: comp.lang.python
> To: 
> Sent: Thursday, August 24, 2006 7:41 PM
> Subject: Re: Taking data from a text file to parse html page
>
>
> > I found this
> >
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1bda6ebcfb060f9/ad0ac6b1ac8cff51?lnk=gst&q=replace+text+file&r
> num=8#ad0ac6b1ac8cff51
> >
> > Credit Jeremy Moles
> > ---
> >
> > finds = ("{", "}", "(", ")")
> > lines = file("foo.txt", "r").readlines()
> >
> > for line in lines:
> > for find in finds:
> > if find in line:
> > line.replace(find, "")
> >
> > print lines
> >
> > ---
> >
> > I want something like
> > ---
> >
> > finds = file("replace.txt")
> > lines = file("foo.txt", "r").readlines()
> >
> > for line in lines:
> > for find in finds:
> > if find in line:
> > line.replace(find, "")
> >
> > print lines
> >
> > ---
> >
> >
> >
> > Fredrik Lundh wrote:
> > > DH wrote:
> > >
> > > > I have a plain text file containing the html and words that I want
> > > > removed(keywords) from the html file, after processing the html file it
> > > > would save it as a plain text file.
> > > >
> > > > So the program would import the keywords, remove them from the html
> > > > file and save the html  file as something.txt.
> > > >
> > > > I would post the data but it's secret. I can post an example:
> > > >
> > > > index.html (html page)
> > > >
> > > > "
> > > > "Python has been an important part of Google since the

Re: Best Practices for Python Script Development?

2006-08-24 Thread Robert Kern
metaperl wrote:

> Usage
> =
> Most scripts will be run from cron and so should be driveable via
> command-line options.
> 
> optparse looks very good to me. And I had never thought about
> required versus optional arguments in the way that it does. What an
> eye-opener.
> 
> Searching cheeseshop.python.org/pypi for getopt modules does not work
> very well by the way.

"Does not work very well" how? Are you just not finding anything?

If so, it's probably because there really aren't any, and they wouldn't be 
referred to as "getopt modules." There's the (old) getopt module and the 
(preferred) optparse module in the standard library. optparse really does fill 
the niche quite thoroughly.

However, if you like, there's the newcomer argparse that tries to improve upon 
optparse in several respects:

   http://argparse.python-hosting.com/

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


dictionaries vs. objects

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

Best Practices for Python Script Development?

2006-08-24 Thread metaperl
Hello, I am responsible for converting 30 loosey-goosey Perl scripts
into 30 well-documented easy to understand and use Python scripts.

No one has said anything in particular about how this should be done,
but the end product should be "professional" looking.

So, I'm looking for some books and suggestions which will help me write
high-quality scripts. I know about object-oriented programming and
application configuration and have spent 6 years doing professional
Perl but have decided that Python is the new choice of serious agile
developers. Only thing is, I only figured that out 1 month ago and
don't really know how to write good code yet :)


Documentation
=
I would like browseable HTML documentation for each script. I have
started
to get some idea of using docstrings within a file and that they can
be extracted but would like a pointer to some docs on this practice.

`Pydoc `_ seems to be
built around modules and I want to document scripts.

Configuration
==
Based on `this thread
`__
I plan to use ConfigParser to squirrel away generic information like
database connection info. The chapter "table-driven code" in Bruce
Eckels' "Thinking in Python" seems like it would've been of help but
it is not written. Any weblinks for similar articles?

The directory hierarchy is going to be /data/vendor/X where X is a
particular data vendor. In /data/vendor/config.ini will be the generic
config info along with an index.html giving an overview of the whole
shebang.

Usage
=
Most scripts will be run from cron and so should be driveable via
command-line options.

optparse looks very good to me. And I had never thought about
required versus optional arguments in the way that it does. What an
eye-opener.

Searching cheeseshop.python.org/pypi for getopt modules does not work
very well by the way.

Version Control
===
I've been using bazaar but mercurial seems to be quicker to create
forward-facing browseable web repos. And the propagation and pull
facilities seem more integrated and useable. But both are highly
desireable products.

OS X

I'm doing all this on OS X. I like Unix but am too dumb for Linux.
Windows is a great GUI but I hate the registry and hate jumping back
and forth between Windows and Cygwin and never getting the full power
of either.

I think I'll get 2 Mac Minis - one for the
actual data munging and one to back everything up on.

Which actual Python distro I will use is going to be based on the data
I get from `this thread
`_

Books
=
I think these 4 will carry me a long way, but any other suggestions ar
welcome:
* `Dive into Python `_
* `Text Processing in Python `_
* Python Cookbook
* Programming Python

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


Re: Is this a good idea or a waste of time?

2006-08-24 Thread hiaips

asincero wrote:
> Would it be considered good form to begin every method or function with
> a bunch of asserts checking to see if the parameters are of the correct
> type (in addition to seeing if they meet other kinds of precondition
> constraints)?  Like:
>
> def foo(a, b, c, d):
>assert type(a) == str
>assert type(b) == str
>assert type(c) == int
>assert type(d) == bool
># rest of function follows
>
> This is something I miss from working with more stricter languages like
> C++, where the compiler will tell you if a parameter is the wrong type.
>  If anything, I think it goes a long way towards the code being more
> self documenting.  Or is this a waste of time and not really "the
> Python way"?
>
> -- Arcadio

Many developers who move from a statically-typed languages to dynamic
ones go through this same sort of thought process. I was no different
in that regard, but as I've done more and more Python, I've found that
I just don't encounter type issues all that often. Above all, I see
duck typing as a net benefit - its inherent flexibility far outweighs
the lack of "compile-time" type safety, in my mind.

Along these lines, I'll point you to this article by Bruce Eckel called
"Strong Typing vs. Strong Testing":
http://www.mindview.net/WebLog/log-0025. The bottom line: Focus on unit
tests rather than explicit type checks when you want to verify the
runtime safety of your code. You'll find many more errors this way.

Hope this helps...
--dave

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


Re: When is a subclass not right?

2006-08-24 Thread Gabriel Genellina

At Thursday 24/8/2006 19:51, Chaz Ginger wrote:


>> I was writing some code that used someone else class as a subclass. He
>> wrote me to tell me that using his class as a subclass was incorrect. I
>> am wondering under what conditions, if ever, does a class using a
>> subclass not work.
>>
>> class B1(A);
>>   def __init__(self,a1,a2) :
>> self.c = a1
>> A.__init__(self,ag)
>>
>> class B2:
>>   def __init__(self,a1,a2):
>> self.c = a1
>> self.t = A(a2)
>>
>>   def bar(self) :
>> self.t.bar()
>>
>> Other than the obvious difference of B2 having an attribute 't', I can't
>> see any other obvious differences. Is there something I am missing?
>
> Look any OO book for the difference between 'inheritance' and
> 'delegation'. In short, you should inherit when B 'is an' A (a Car is a
> Vehicle), and delegate/compose in other cases (a Car has an Engine; or
> more precisely, a Car instance has an Engine instance).

I was wondering more about the mechanics of Python: when does B1 show
different characteristics than B2  (forgoing the obvious simple things,
like 't' above).
Inheritance implies that *all* methods/attributes of A are exposed 
by B1; it's directly supported by the language. Inheritance is 
usually a relationship between classes. If you add a method foo() 
to A, instances of B1 automatically have it. A B1 instance "is an" A instance.
Using delegation, you have to delegate the desired method calls 
yourself (but there are ways to do that automatically, too). 
Delegation is a relationship between instances. If you add a method 
foo() to A, you have to add it to B2 too. A B2 instance "is not an" A instance.


Once again you answered all the generic things about classes. I 
could have taken that from a book on OO. All well and good but not 
specifically addressed to the question I asked. Please read what I 
wrote. I am more interested in knowing specifics about the Python 
implementation and if there are any "gotchas" that would make B1 
different from B2.


Please stay on the list.

b1 = B1()
b2 = B2()
isinstance(b1, A) -> True
isinstance(b2, A) -> False

For any other method defined in A, say foo:
b1.foo() is OK
b2.foo() raises AttributeError

So you decide to override foo() too (in both implementations, B1 and B2)
Let's say, A.bar() calls self.foo()
b1.bar() calls B1.foo on b1
b2.bar() calls A.foo on t - B2.foo is *not* called.

Enough examples? Inheritance and delegation are *not* the same thing. 
Anyway, none of these examples is very Python-specific.




Gabriel Genellina
Softlab SRL 




p5.vert.ukl.yahoo.com uncompressed Fri Aug 25 01:27:04 GMT 2006 
	


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

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

setup.py and file extensions like ".c++"

2006-08-24 Thread garyjefferson123
Is there any way to get setup.py to recognize file extensions like .c++
in lieu of .cpp?  I'd love to not have to rename the source files for
the library I'm trying to wrap in a python C extension.

I get:

error: unknown file type '.c++' (from 'parser.c++')

when I type 'python setup.py build'

thanks,
Gary

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


Re: OS X and Python - what is your install strategy?

2006-08-24 Thread hiaips

metaperl wrote:
> I'm about to get a new OS X box on which I will rewrite a bunch of data
> munging scripts from Perl to Python. I know that there are several port
> services for OS X (fink, darwin ports, opendarwin). So I am not sure
> whether to use their port of Python or whether to build from scratch or
> use the Python image file. Also ActivePython is something of a choice
> but for some reason not a front-running one for me. I tend to like
> Gentoo-style compile from source over pre-bundled all-in-one solutions
> like ActivePython.
>
> I'm not going to do much other than maybe install Plone and do some XML
> and CSV processing. Most everything I need is in the Python stdlib.
> Maybe down the road some graphics and web stuff (I like Clever Harold
> or Pylons for that... but I still ahve not examined the 900 other web
> app options in Python :)

These days, I install the OS X universal binary provided on the Python
language web site. You can find it at
http://www.python.org/download/releases/2.4.3. It's more comprehensive
and much more up-to-date than the version included in OS X.

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


Re: OS X and Python - what is your install strategy?

2006-08-24 Thread skip

[ mp asks what version of Python to install on Mac OSX ]

I just do a Unix build from the Subversion repository.  I do have fink
installed, so some of the external libraries match up there.  Also, the
Mac's readline module is really libedit, which doesn't provide enough
functionality for Python's readline module.  Having fink or Darwin Ports
available is handy for that sort of thing.

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


Re: Python editor

2006-08-24 Thread Jason Jiang
Thanks Simon. I finally picked SciTE. No time to do further investigation.

Jason

"Simon Forman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Jason Jiang wrote:
>> Hi,
>>
>> Could someone recommend a good Python editor? Thanks.
>>
>> Jason
>
> There have just been one or two long-ish threads on exactly this
> question.  Search the google groups version of this group for them.
>
> Peace,
> ~Simon
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 



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


Re: List problem

2006-08-24 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> For example i write the following code in the Python command line;
> 
 list = ['One,Two,Three,Four']
> 
> Then enter this command, which will then return the following;
> 
> ['One,Two,Three,Four']
> 
> 
> Now the problem, reading through the Python tutorial's, it describe's
> that list's can sliced, concatenated and so on etc
> 
> So i write the following
> 
 list[1:] + ['Five']
> 
> Then the error returned is that 'str' and 'list' could not be
> concatenated which is where it baffles me. I'm understanding that this
> mean's that the string 'Five' could not be joined onto the list, as i
> havn't defined it in the array. Viewing the Python tutrial they have
> the following, and working code;
> 
 a[:2] + ['bacon', 2*2]
> ['spam', 'eggs', 'bacon', 4]
> 
> How can they have the string 'bacon' and have it returned with no
> error?
> 
Your error message doesn't match your command.  Now if you
typed:

list[0]+['Five']

that gives you the error you showed.

What you meant to type was:

l = ['One','Two','Three','Four']

This is a list of four strings, what you entered was a list of one
string.

NOTE never call a variable 'list' as it will mask the built-in list
method (same goes for str, tuple, int, float, etc).

-Larry Bates

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


Re: OS X and Python - what is your install strategy?

2006-08-24 Thread Diez B. Roggisch
metaperl schrieb:
> I'm about to get a new OS X box on which I will rewrite a bunch of data
> munging scripts from Perl to Python. I know that there are several port
> services for OS X (fink, darwin ports, opendarwin). So I am not sure
> whether to use their port of Python or whether to build from scratch or
> use the Python image file. Also ActivePython is something of a choice
> but for some reason not a front-running one for me. I tend to like
> Gentoo-style compile from source over pre-bundled all-in-one solutions
> like ActivePython.

You will definitely need the OSX-specific framework builds - which you 
can do yourself, but also install as image. All the fink/darwin ports 
stuff is nice, but I bet you prefer whatever gui you might wanna use 
running natively, not under X...

> I'm not going to do much other than maybe install Plone and do some XML
> and CSV processing. Most everything I need is in the Python stdlib.
> Maybe down the road some graphics and web stuff (I like Clever Harold
> or Pylons for that... but I still ahve not examined the 900 other web
> app options in Python :)

All that doesn't affect the above.

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


Re: Python editor

2006-08-24 Thread Larry Bates
Jason Jiang wrote:
> Hi,
> 
> Could someone recommend a good Python editor? Thanks.
> 
> Jason 
> 
> 
> 
For just getting started use Idle that comes with Python.
If you are already a user or if you are looking for a more
powerful solution you can use Eclipse (with Python plug-in).
These represent both ends of the spectrum in editors.

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


Re: When is a subclass not right?

2006-08-24 Thread Rick Zantow
Gabriel Genellina <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> At Thursday 24/8/2006 17:44, Chaz Ginger wrote:
> 
>>That is merely a logical use of OO after all when would a car and an
>>orange be the same?
> 
> Uh... what's the point...?
> By example, an orange inside a car would be modeled using 
> composition, never inheritance.

I've heard of cars that seem to inherit from the *lemon* class, though. Not 
a good object model, that.

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


OS X and Python - what is your install strategy?

2006-08-24 Thread metaperl
I'm about to get a new OS X box on which I will rewrite a bunch of data
munging scripts from Perl to Python. I know that there are several port
services for OS X (fink, darwin ports, opendarwin). So I am not sure
whether to use their port of Python or whether to build from scratch or
use the Python image file. Also ActivePython is something of a choice
but for some reason not a front-running one for me. I tend to like
Gentoo-style compile from source over pre-bundled all-in-one solutions
like ActivePython.

I'm not going to do much other than maybe install Plone and do some XML
and CSV processing. Most everything I need is in the Python stdlib.
Maybe down the road some graphics and web stuff (I like Clever Harold
or Pylons for that... but I still ahve not examined the 900 other web
app options in Python :)

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


Re: Python editor

2006-08-24 Thread Simon Forman
Jason Jiang wrote:
> Hi,
>
> Could someone recommend a good Python editor? Thanks.
>
> Jason

There have just been one or two long-ish threads on exactly this
question.  Search the google groups version of this group for them.

Peace,
~Simon

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


Python editor

2006-08-24 Thread Jason Jiang
Hi,

Could someone recommend a good Python editor? Thanks.

Jason 



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


Re: sum and strings

2006-08-24 Thread Paul Rubin
Fredrik Lundh <[EMAIL PROTECTED]> writes:
> "join" doesn't use __add__ at all, so I'm not sure in what sense that
> would be more predictable.  I'm probably missing something, but I
> cannot think of any core method that uses a radically different
> algorithm based on the *type* of one argument.

3 ** 2, vs. 3 ** 2.5

Actually it's worse than depending on just the type:

(-3.0) ** 2.0 works, while (-3.0) ** 2.5 throws an error.

But you can do

(-3.0) ** (2.5 + 0.0j)

for yet another radically different algorithm.

I'm not sure whether the Python spec requires (-3.0)**2.0 to work, or
if it's just an implementation-specific hack.  In most languages, it
wouldn't work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List problem

2006-08-24 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> For example i write the following code in the Python command line;
> 
 list = ['One,Two,Three,Four']
> 
> Then enter this command, which will then return the following;
> 
> ['One,Two,Three,Four']
> 
> 
> Now the problem, reading through the Python tutorial's, it describe's
> that list's can sliced, concatenated and so on etc
> 
> So i write the following
> 
 list[1:] + ['Five']
> 
> Then the error returned is that 'str' and 'list' could not be
> concatenated which is where it baffles me.

if you got that error, you clearly didn't type what you say you typed:

 >>> list = ['One,Two,Three,Four']
 >>> list
['One,Two,Three,Four']
 >>> list[1:] + ['Five']
['Five']

(note that the first list contains a single string; if you want to put 
multiple strings in a list, you need to be more careful with where you 
put the quotes.)



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


Re: Record Audio Analysis

2006-08-24 Thread Jeffrey Barish
Frank LaFond wrote:

> Jo Chase wrote:
>> I would like to record audio from a mic and perform some basic analysis
>> on
>> the audio wave patterns produced.  What would be the easiest way to
>> accomplish this in Python?
> 
> Take a look at http://pymedia.org
> 
> I think it allows the features you want.
> 
> Frank.

Or try PySonic (http://pysonic.sourceforge.net/) if you prefer a package
that actually works.
-- 
Jeffrey Barish

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


List problem

2006-08-24 Thread kevndcks
For example i write the following code in the Python command line;

>>>list = ['One,Two,Three,Four']

Then enter this command, which will then return the following;

['One,Two,Three,Four']


Now the problem, reading through the Python tutorial's, it describe's
that list's can sliced, concatenated and so on etc

So i write the following

>>>list[1:] + ['Five']

Then the error returned is that 'str' and 'list' could not be
concatenated which is where it baffles me. I'm understanding that this
mean's that the string 'Five' could not be joined onto the list, as i
havn't defined it in the array. Viewing the Python tutrial they have
the following, and working code;

>>> a[:2] + ['bacon', 2*2]
['spam', 'eggs', 'bacon', 4]

How can they have the string 'bacon' and have it returned with no
error?

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


Re: When is a subclass not right?

2006-08-24 Thread Gabriel Genellina

At Thursday 24/8/2006 17:44, Chaz Ginger wrote:


>> I was writing some code that used someone else class as a subclass. He
>> wrote me to tell me that using his class as a subclass was incorrect. I
>> am wondering under what conditions, if ever, does a class using a
>> subclass not work.
>>
>> class B1(A);
>>   def __init__(self,a1,a2) :
>> self.c = a1
>> A.__init__(self,ag)
>>
>> class B2:
>>   def __init__(self,a1,a2):
>> self.c = a1
>> self.t = A(a2)
>>
>>   def bar(self) :
>> self.t.bar()
>>
>> Other than the obvious difference of B2 having an attribute 't', I can't
>> see any other obvious differences. Is there something I am missing?
>
> Look any OO book for the difference between 'inheritance' and
> 'delegation'. In short, you should inherit when B 'is an' A (a Car is a
> Vehicle), and delegate/compose in other cases (a Car has an Engine; or
> more precisely, a Car instance has an Engine instance).

That is merely a logical use of OO after all when would a car and an
orange be the same?


Uh... what's the point...?
By example, an orange inside a car would be modeled using 
composition, never inheritance.



I was wondering more about the mechanics of Python: when does B1 show
different characteristics than B2  (forgoing the obvious simple things,
like 't' above).


Inheritance implies that *all* methods/attributes of A are exposed by 
B1; it's directly supported by the language. Inheritance is usually a 
relationship between classes. If you add a method foo() to A, 
instances of B1 automatically have it. A B1 instance "is an" A instance.
Using delegation, you have to delegate the desired method calls 
yourself (but there are ways to do that automatically, too). 
Delegation is a relationship between instances. If you add a method 
foo() to A, you have to add it to B2 too. A B2 instance "is not an" A instance.




Gabriel Genellina
Softlab SRL 




p4.vert.ukl.yahoo.com uncompressed Thu Aug 24 21:27:05 GMT 2006 
	


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

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

Re: Python & chess

2006-08-24 Thread Paul Boddie
Will McGugan wrote:
>
> I have written a chess module that may be of use to you.
>
> http://www.willmcgugan.com/2006/06/18/chesspy/

See also ChessBoard - a nice implementation of chess using pygame:

http://www.pygame.org/projects/9/282/

Paul

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


Re: wxPython default radiobox choice

2006-08-24 Thread Laszlo Nagy
crystalattice írta:
> In my GUI app, I have a radio box allowing the user to pick his/her
> gender.  When I click a button, I'd like the radio box to tell the
> program which choice is marked.  I can get it to work when I manually
> pick a choice but I get an error when the choice is left at the default
> value, which is "Male".
>
> I have the radio box tied to an event to "see" when a choice is made,
> but how does it work if the person just leaves the default value?  I've
> looked at the wxPython demo but the radio box actions only work for
> changing values.
>
>   
I'm not sure if I understood your problem. You can call the 
wxRadioBox.GetSelection method anytime to get the current value.
If you need that value very often (e.g. thousand times per sec) then you 
can "shadow" the default value in an instance variable.

Example (untested):


class MyClass(wx.Frame):
 """In this frame, you can use the curchoice variable after 
construction."""
def __init__(self):
   # ... create your frame here...
   r =self.radio = wx.RadioBox(self,-1,choiches=['One','Two','Three'])
   # Set default value
   r.SetSelection(0) # This does not cause a 
wxEVT_COMMAND_RADIOBOX_SELECTED event to get emitted.
   self.curchoice = 0
   # Bind the event
   r.Bind(
wx.EVT_COMMAND_RADIOBOX_SELECTED,
self.OnRadioChanged,
r
)
  

def OnRadioChanged(self,event):
   self.curchoice = self.radio.GetSelection()
   # Do whatever you want here...
   event.Skip()



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


Re: Is there an elegant way to dir() module from inside?

2006-08-24 Thread volcano

Sion Arrowsmith wrote:
> volcano <[EMAIL PROTECTED]> wrote:
> >I am looking for a way to discover which classes a module contains from
> >"inside". I am building a testing class that should, when instatntiated
> >within any module, locate certain classes within the containing module.
>
> globals().keys()
>
> --
> \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
>   ___  |  "Frankly I have no feelings towards penguins one way or the other"
>   \X/  |-- Arthur C. Clarke
>her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

thanks, it worked!

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


Re: Python & chess

2006-08-24 Thread tobiah
> Hmmm. I think that if you need to write a very clever chess game, then 
> you need to use very fast routines, written in C or even assembly. 

Oh, right.  Speed.  I thought that you were talking about
some mismatch of capabilities.

Toby

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: When is a subclass not right?

2006-08-24 Thread Chaz Ginger
Gabriel Genellina wrote:
> At Thursday 24/8/2006 16:23, Chaz Ginger wrote:
> 
>> I was writing some code that used someone else class as a subclass. He
>> wrote me to tell me that using his class as a subclass was incorrect. I
>> am wondering under what conditions, if ever, does a class using a
>> subclass not work.
>>
>> class B1(A);
>>   def __init__(self,a1,a2) :
>> self.c = a1
>> A.__init__(self,ag)
>>
>> class B2:
>>   def __init__(self,a1,a2):
>> self.c = a1
>> self.t = A(a2)
>>
>>   def bar(self) :
>> self.t.bar()
>>
>> Other than the obvious difference of B2 having an attribute 't', I can't
>> see any other obvious differences. Is there something I am missing?
> 
> Look any OO book for the difference between 'inheritance' and 
> 'delegation'. In short, you should inherit when B 'is an' A (a Car is a 
> Vehicle), and delegate/compose in other cases (a Car has an Engine; or 
> more precisely, a Car instance has an Engine instance).
> 
> 
> Gabriel Genellina
> Softlab SRL
> 
> 
> p5.vert.ukl.yahoo.com uncompressed Thu Aug 24 19:27:05 GMT 2006 
>
> __ Preguntá. Respondé. 
> Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en 
> Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas

That is merely a logical use of OO after all when would a car and an 
orange be the same?

I was wondering more about the mechanics of Python: when does B1 show 
different characteristics than B2  (forgoing the obvious simple things, 
like 't' above).

Chaz


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


Re: When is a subclass not right?

2006-08-24 Thread Chaz Ginger
Fredrik Lundh wrote:
> please don't hit reply to arbitrary messages when you're posting new
> messages; it messes up the message threading.
> 
> Chaz Ginger wrote:
> 
>> I was writing some code that used someone else class as a subclass. He 
>> wrote me to tell me that using his class as a subclass was incorrect. 
>> I am wondering under what conditions, if ever, does a class using a 
>> subclass not work.
> 
> your terminology is confused: if you inherit from another class, *your* 
> class is the subclass, while the class you inherit from is known as a 
> "base class" or "super class".
> 
> a subclass will share the instance namespace with the base class, which 
> means, among other things, that you may accidentally override internal 
> attributes and methods, and thus break the base class.
> 
> and even if it appears to work now, it may break when you upgrade the 
> base class.  or when you end up in a code path that you haven't tested 
> before.
> 
> 
> 
Sorry for the threading screw up. I thought I had just hit the write button.

I understand when my class overrides the super class. But that would 
just be "normal" class related things. I was wondering if there was 
something more subtle I am missing in Python class handling.

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


Re: String formatting with nested dictionaries

2006-08-24 Thread Maric Michaud
Le jeudi 24 août 2006 21:02, Fredrik Lundh a écrit :
> class wrapper:
>      def __init__(self, dict):
> self.dict = dict
>      def __getitem__(self, key):
> try:
>     return self.dict[key]
> except KeyError:
>    

Quite the same idea, but without eval and the need to know the internal dict 
arborescence :

In [242]: class nested_dict_wrapper :
   .: def __init__(self, dic) :
   .: self._all = [dic] + [nested_dict_wrapper(v) for v in 
dic.values() if isinstance(v, dict)]
   .: def __getitem__(self, v) :
   .: for i in self._all :
   .: try : return i[v]
   .: except KeyError: pass
   .: raise KeyError(v + ' not found in dict and subdicts')
   .:
   .:

In [248]: complex_dict = { '0': 'zero', '1':'one', 'in1' : {'2':'two'}, 'in2':
{'3': 'three', '4' :'four', 'deeper':{'5':'five', '6':'six'}}, '7':'seven' }

In [250]: "%%(%s)s "*7 % tuple(range(7)) % nested_dict_wrapper(complex_dict)
Out[250]: 'zero one two three four five six '

In [251]: "%%(%s)s "*8 % tuple(range(8)) % nested_dict_wrapper(complex_dict)
Out[251]: 'zero one two three four five six seven '

In [252]: "%%(%s)s "*9 % tuple(range(9)) % nested_dict_wrapper(complex_dict)
---
exceptions.KeyError  Traceback (most recent 
call last)

/home/maric/

/home/maric/ in __getitem__(self, v)

KeyError: '8 not found in dict and subdicts'


-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't destroy a wxMiniFrame

2006-08-24 Thread Flavio
It was human error...

I found the bug...

thanks,


Laszlo Nagy wrote:
> Flavio írta:
> > Hi,
> >
> > I have a miniframe composed mainly of combo boxes, that I need to
> > destroy and recreate multiple time with different choice lists for the
> > combo boxes.
> >
> > My problem is that even after destroying a miniframe with the Destroy()
> > method, when it is recreated, the combo boxes show the same lists of
> > its previous incarnation...
> >
> > how can I completely destroy a miniframe?
> >
>  From what you wrote, I think that you did not create a new miniframe.
> Although you called Destroy(), you tried to display it again. This is
> what the documentation says about destroy.
>
> Destroys the window safely. Use this function instead of the delete
> operator, since different window classes can be destroyed differently.
> *Frames and dialogs are not destroyed immediately* when this function is
> called -- they are added to a list of windows to be deleted on idle
> time, when all the window's events have been processed. This prevents
> problems with events being sent to non-existent windows.
> 
> 
> Regards,
> 
>Laszlo

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


signal - no update 'til I move the mouse

2006-08-24 Thread Sorin Schwimmer
Hi,

My project needs to allow some inter-process
communication. That one is solved, and when an answer
is sent, it goes to its destination via a signal.
Then, the Tkinter screen needs to be updated, so the
user can take the next action.

On my laptop it works instantly, on my desktop, only
after I move the mouse inside my application's window.

Configurations:
Laptop: Dell Latitude C600, Gentoo Linux, kernel
2.6.11, Python 2.4.1, KDE 3.3.x

Desktop: IBM NetVista, Gentoo Linux, kernel 2.6.11,
Python 2.4.2, KDE 3.4.x

I am pretty sure that's not a Tkinter related issue,
since I tested some "print" statements and they behave
in a similar way, but what can it be?

Thanks for your advise,
Sorin

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


Re: When is a subclass not right?

2006-08-24 Thread Gabriel Genellina

At Thursday 24/8/2006 16:23, Chaz Ginger wrote:


I was writing some code that used someone else class as a subclass. He
wrote me to tell me that using his class as a subclass was incorrect. I
am wondering under what conditions, if ever, does a class using a
subclass not work.

class B1(A);
  def __init__(self,a1,a2) :
self.c = a1
A.__init__(self,ag)

class B2:
  def __init__(self,a1,a2):
self.c = a1
self.t = A(a2)

  def bar(self) :
self.t.bar()

Other than the obvious difference of B2 having an attribute 't', I can't
see any other obvious differences. Is there something I am missing?


Look any OO book for the difference between 'inheritance' and 
'delegation'. In short, you should inherit when B 'is an' A (a Car is 
a Vehicle), and delegate/compose in other cases (a Car has an Engine; 
or more precisely, a Car instance has an Engine instance).



Gabriel Genellina
Softlab SRL 




p5.vert.ukl.yahoo.com uncompressed Thu Aug 24 19:27:05 GMT 2006 
	


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

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

wxPython default radiobox choice

2006-08-24 Thread crystalattice
In my GUI app, I have a radio box allowing the user to pick his/her
gender.  When I click a button, I'd like the radio box to tell the
program which choice is marked.  I can get it to work when I manually
pick a choice but I get an error when the choice is left at the default
value, which is "Male".

I have the radio box tied to an event to "see" when a choice is made,
but how does it work if the person just leaves the default value?  I've
looked at the wxPython demo but the radio box actions only work for
changing values.

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


Is this a good idea or a waste of time?

2006-08-24 Thread asincero
Would it be considered good form to begin every method or function with
a bunch of asserts checking to see if the parameters are of the correct
type (in addition to seeing if they meet other kinds of precondition
constraints)?  Like:

def foo(a, b, c, d):
   assert type(a) == str
   assert type(b) == str
   assert type(c) == int
   assert type(d) == bool
   # rest of function follows

This is something I miss from working with more stricter languages like
C++, where the compiler will tell you if a parameter is the wrong type.
 If anything, I think it goes a long way towards the code being more
self documenting.  Or is this a waste of time and not really "the
Python way"?

-- Arcadio

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


Re: Is this a good idea or a waste of time?

2006-08-24 Thread skip

Arcadio> Would it be considered good form to begin every method or
Arcadio> function with a bunch of asserts checking to see if the
Arcadio> parameters are of the correct type (in addition to seeing if
Arcadio> they meet other kinds of precondition constraints)? 

If it works for you.  It's not generally considered Pythonic though.  You
should probably read up on "duck typing".  Some food for thought: Do you
normally care that the object passed to foo() is a real honest-to-goodness
file object, or do you just care that it has a write() method?  You will
learn soon enough if it doesn't, and not that much later than if you have an
assert at the beginning of your function.  Of course, sometimes you do truly
care about the type of an object.  Then you test.  When you care.

Arcadio> This is something I miss from working with more stricter
Arcadio> languages like C++, where the compiler will tell you if a
Arcadio> parameter is the wrong type.

It's a mistake to think that Python's typing is somehow less strict than
C++'s.  It's not like Perl where 1 + "2" is valid.  It's simply that its
type checks are performed at run-time, not at compile-time.  If you're
desparate to have some assistance with your code before you run it, check
out pylint and pychecker.

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


Re: wxPython default radiobox choice

2006-08-24 Thread crystalattice

Laszlo Nagy wrote:
> crystalattice írta:
> > In my GUI app, I have a radio box allowing the user to pick his/her
> > gender.  When I click a button, I'd like the radio box to tell the
> > program which choice is marked.  I can get it to work when I manually
> > pick a choice but I get an error when the choice is left at the default
> > value, which is "Male".
> >
> > I have the radio box tied to an event to "see" when a choice is made,
> > but how does it work if the person just leaves the default value?  I've
> > looked at the wxPython demo but the radio box actions only work for
> > changing values.
> >
> >
> I'm not sure if I understood your problem. You can call the
> wxRadioBox.GetSelection method anytime to get the current value.
> If you need that value very often (e.g. thousand times per sec) then you
> can "shadow" the default value in an instance variable.
>
> Example (untested):
>
>
> class MyClass(wx.Frame):
>  """In this frame, you can use the curchoice variable after
> construction."""
> def __init__(self):
># ... create your frame here...
>r =self.radio = wx.RadioBox(self,-1,choiches=['One','Two','Three'])
># Set default value
>r.SetSelection(0) # This does not cause a
> wxEVT_COMMAND_RADIOBOX_SELECTED event to get emitted.
>self.curchoice = 0
># Bind the event
>r.Bind(
> wx.EVT_COMMAND_RADIOBOX_SELECTED,
> self.OnRadioChanged,
> r
> )
>
>
> def OnRadioChanged(self,event):
>self.curchoice = self.radio.GetSelection()
># Do whatever you want here...
>event.Skip()

Thanks for the response.  I got it working now.  I was trying to bind
the radio box to an event, rather than just calling GetSelection().  I
thought I needed to bind it to make it work (based on the wxPython demo
code).

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


Re: When is a subclass not right?

2006-08-24 Thread Carl Banks

Chaz Ginger wrote:
> I was writing some code that used someone else class as a subclass. He
> wrote me to tell me that using his class as a subclass was incorrect. I
> am wondering under what conditions, if ever, does a class using a
> subclass not work.
[snip]
> He said I should use it this way:
>
> class B2:
>   def __init__(self,a1,a2):
>   self.c = a1
>   self.t = A(a2)
>
>   def bar(self) :
>   self.t.bar()
>
> Other than the obvious difference of B2 having an attribute 't', I can't
> see any other obvious differences. Is there something I am missing?

I think it's kind of a fine point.  In my own code I've had cases where
I've switched from subclass to attribute and back over the development,
and vice versa.  I think there are many cases where it's preferable to
use an attribute, but not really wrong to subclass (and vice versa).

The classical advice in choosing whether to subclass or or use
attribute is whether its more an an "is a" or "has a" relationship.  If
it's more natural to say B is an A, then subclass.  If it's more
natural to say B has an A, then use an attribute.  But that's only a
rule of thumb.

I personally find another question helpful.  If it's reasonable that B
could have more than one of A, regardless if it actually does, use an
attribute.  If it's unreasonable, subclass.  Again, rule of thumb.


Carl Banks

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


Re: Python & chess

2006-08-24 Thread Laszlo Nagy
tobiah írta:
> Paolo Pantaleo wrote:
>   
>> Well Python is not a good language for writing a chess engine 
>> 
>
> I'm curious; how does python fall short here, and what are the
> features that make some other language more suitable for the
> task?
>   
Hmmm. I think that if you need to write a very clever chess game, then 
you need to use very fast routines, written in C or even assembly. I 
have heard that the best chess programs use a database. That database 
contains hundreds of thousands of games played previously by famous 
chess players. Usually they play the first few steps by using this 
database (and not using any AI).

Do you plan to beat "Chessmaster"? :-)  If you only want to try your AI 
abilities, then Python is ideal for the task. At least this is my opinion.

  Laszlo

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


Re: Python & chess

2006-08-24 Thread Will McGugan
Paolo Pantaleo wrote:
> Well Python is not a good language for writing a chess engine (even if
> a chess engine exists:
> http://www.kolumbus.fi/jyrki.alakuijala/pychess.html), but it could be
> grat for chess interfaces, for drawing boards, and similar things. I
> foudn out a library for these things
> (http://www.alcyone.com/software/chess/). Does anyone konw about more
> chess related modules?

I have written a chess module that may be of use to you.

http://www.willmcgugan.com/2006/06/18/chesspy/


Will McGugan
--
work: http://www.kelpiesoft.com
blog: http://www.willmcgugan.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When is a subclass not right?

2006-08-24 Thread Simon Forman
Chaz Ginger wrote:
> I was writing some code that used someone else class as a subclass. He
> wrote me to tell me that using his class as a subclass was incorrect. I
> am wondering under what conditions, if ever, does a class using a
> subclass not work.
>
> Here is an example. For instance the original class might look like:
>
> class A :
>   def __init__(self,arg) :
>   self.foo = arg
>   def bar(self) :
>   return self.foo
>
>
> And I defined a class B1 which looked like:
>
>
> class B1(A);
>   def __init__(self,a1,a2) :
>   self.c = a1
>   A.__init__(self,ag)
>
>
> He said I should use it this way:
>
> class B2:
>   def __init__(self,a1,a2):
>   self.c = a1
>   self.t = A(a2)
>
>   def bar(self) :
>   self.t.bar()
>
>
> Other than the obvious difference of B2 having an attribute 't', I can't
> see any other obvious differences. Is there something I am missing?
>
> TIA
> Chaz

When the developer *tells* you it won't work, that's a good indication.
 :-)

You haven't missed anything:  the developer was talking about his
specific code, not python in general.  (I'm on the Twisted list too.
;-) )

Peace,
~Simon

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


Re: Is this a good idea or a waste of time?

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

> def foo(a, b, c, d):
>assert type(a) == str
>assert type(b) == str
>assert type(c) == int
>assert type(d) == bool
># rest of function follows
> 
> This is something I miss from working with more stricter languages like
> C++, where the compiler will tell you if a parameter is the wrong type.
>  If anything, I think it goes a long way towards the code being more
> self documenting.  Or is this a waste of time and not really "the
> Python way"?

Not really the Python way I'd say.  What if `c` is of type `long` for
instance?  Your code would stop with an assertion error for a value that
should work.  Strict type checking prevents "duck typing" which is a quite
fundamental concept in Python.

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


Re: blindness and top vs. bottom posting

2006-08-24 Thread Ben Finney
Tim Chase <[EMAIL PROTECTED]> writes:

> > I am a member of another list that has at least one member who has
> > lost his vision, and reads his news with a speech generator.  It
> > is terribly inconvenient for him to follow a thread full of
> > 'bottom postings', as he is then forced to sit through the
> > previous message contents again and again in search of the new
> > content.
> 
> I'm involved on the Blind Linux users (Blinux) list, and they seem
> to have no problem bottom-posting.
> 
> There are a variety of tools for converting bottom-posting into more
> readable formats.  If you want to suppress comments, a quality MUA
> can suppress them.

The parent poster is complaining about a straw man. As they point out,
"bottom posting" is almost as bad as top posting. Both practices leave
the entire content of quoted material intact, regardless of which
parts are relevant.

The correct solution to both top posting *and* bottom posting is
"interleaved posting", but more importantly to trim away everything
except the quoted material necessary for giving context to one's
response. This is of even greater assistance to the blind, who then
have just the necessary context to understand the current message.

http://en.wikipedia.org/wiki/Top_posting>

-- 
 \ "We are not gonna be great; we are not gonna be amazing; we are |
  `\gonna be *amazingly* amazing!"  -- Zaphod Beeblebrox, _The |
_o__)Hitch-Hiker's Guide To The Galaxy_, Douglas Adams |
Ben Finney

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


Re: When is a subclass not right?

2006-08-24 Thread Fredrik Lundh
please don't hit reply to arbitrary messages when you're posting new
messages; it messes up the message threading.

Chaz Ginger wrote:

> I was writing some code that used someone else class as a subclass. He 
> wrote me to tell me that using his class as a subclass was incorrect. I 
> am wondering under what conditions, if ever, does a class using a 
> subclass not work.

your terminology is confused: if you inherit from another class, *your* 
class is the subclass, while the class you inherit from is known as a 
"base class" or "super class".

a subclass will share the instance namespace with the base class, which 
means, among other things, that you may accidentally override internal 
attributes and methods, and thus break the base class.

and even if it appears to work now, it may break when you upgrade the 
base class.  or when you end up in a code path that you haven't tested 
before.



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


Re: Python and STL efficiency

2006-08-24 Thread Neil Cerutti
On 2006-08-24, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Licheng Fang wrote:
>> Hi, I'm learning STL and I wrote some simple code to compare the
>> efficiency of python and STL.
>>
>> //C++
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>> using namespace std;
>>
>> int main(){
>>  vector a;
>>  for (long int i=0; i<1 ; ++i){
>>  a.push_back("What do you know?");
>>  a.push_back("so long...");
>>  a.push_back("chicken crosses road");
>>  a.push_back("fool");
>>  }
>>  set b(a.begin(), a.end());
>>  unique_copy(b.begin(), b.end(), ostream_iterator(cout, "\n"));
>> }
>
> I think you probably want this C++ code instead:
>
> //C++
> #include 
> #include 
> #include 
> #include 
> #include 
> using namespace std;
>
> int main(){
> vector a;
> a.reserve( 4 );  //<-- note this change
> for (long int i=0; i<1 ; ++i){
> a.push_back("What do you know?");
> a.push_back("so long...");
> a.push_back("chicken crosses road");
> a.push_back("fool");
> }
> set b(a.begin(), a.end());
> unique_copy(b.begin(), b.end(), ostream_iterator(cout,
> "\n"));
> }
>
> It will run a lot faster if it doesn't have to keep resizing
> the array.

I don't see why it should run a lot faster that way.

Appending elements to a vector with push_back takes amortized
constant time. In the example above, preallocating 4 strings
saves (probably) math.log(4, 2) reallocations of the vector's
storage along with the consequent copy-construction and
destruction of some fixed number of strings. Most of those
reallocations take place while the vector is still proportionally
quite small.

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


Re: Why can't I subclass off of "date" ?

2006-08-24 Thread davidfinance
Wow, you guys are fast.

Thanks Georg and Fredrik!!

Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > Ok, maybe this is a stupid question, but why can't I make a subclass of
> > datetime.date and override the __init__ method?
>
> __init__ controls initialization of an already constructed object.  to
> control construction, you need to override __new__:
>
>  http://pyref.infogami.com/__new__
>
> e.g.
>
> class A(date):
>  def __new__(cls, a, b, c, d):
>  print a, b, c, d
>   return super(A, cls).__new__(cls, 2006, 12, 11)
> 
> 

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


When is a subclass not right?

2006-08-24 Thread Chaz Ginger
I was writing some code that used someone else class as a subclass. He 
wrote me to tell me that using his class as a subclass was incorrect. I 
am wondering under what conditions, if ever, does a class using a 
subclass not work.

Here is an example. For instance the original class might look like:

class A :
  def __init__(self,arg) :
self.foo = arg
  def bar(self) :
return self.foo


And I defined a class B1 which looked like:


class B1(A);
  def __init__(self,a1,a2) :
self.c = a1
A.__init__(self,ag)


He said I should use it this way:

class B2:
  def __init__(self,a1,a2):
self.c = a1
self.t = A(a2)

  def bar(self) :
self.t.bar()


Other than the obvious difference of B2 having an attribute 't', I can't 
see any other obvious differences. Is there something I am missing?

TIA
Chaz

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


Re: blindness and top vs. bottom posting (was "all ip addresses of machines in the local network")

2006-08-24 Thread Tim Chase
> I am a member of another list that has at least one member
> who has lost his vision, and reads his news with a speech
> generator.  It is terribly inconvenient for him to follow
> a thread full of 'bottom postings', as he is then forced to
> sit through the previous message contents again and again
> in search of the new content.  

I'm involved on the Blind Linux users (Blinux) list, and they 
seem to have no problem bottom-posting.

There are a variety of tools for converting bottom-posting into 
more readable formats.  If you want to suppress comments, a 
quality MUA can suppress them.  Or you can pipe them through 
sed/grep/whatever and strip out all lines beginning with a 
greater-than sign.  Or, use the search functionality in the 
screen-reader to skip ahead to the next line until you get to one 
  that doesn't begin with a greater-than sign.  Some text-display 
areas even allow you to use searching to move the cursor.  E.g. 
if reading a mail in mutt in a console, you can open it in vim 
and search for "^[^>]" which will move the cursor to the next 
line that doesn't begin with a greater-than sign.  Quite usable 
from within yasr ("yet another screen reader").

Inspired by a problem discussed on the Blinux list, I've also 
created a python tool for converting standard quoting notation 
(using greater-than signs) into a more TTS-friendly 
(text-to-speech) format:

http://www.redhat.com/archives/blinux-list/2006-June/msg00012.html
http://www.redhat.com/archives/blinux-list/2006-June/msg00015.html
http://www.redhat.com/archives/blinux-list/2006-June/msg00016.html

Thus, there are tools for blind/visually-impared folks that can 
make it easier for them to correspond using the standards the 
rest of the world uses.  Even among blind users, there's often a 
division between those that use Braille terminals and those that 
use TTS.  Those using Braille tend to fall in with the rest of 
the internet, preferring bottom-posting.  Those using TTS aren't 
quite so fond of having their own content regurgitated back to 
them.  However, judicial pruning of quoted contend can ease that 
problem.

Thus, there are plenty of tools to help BVI folks operate under 
the standard of bottom-posting.

-tkc



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


Re: callable to disappear?

2006-08-24 Thread Fredrik Lundh
Terry Reedy wrote:

> 1. You cannot know for sure until you call and get a return.

with that argument, you might as well remove functions and methods from 
the language.  after all, anything can happen when you call a function.

not to mention what import can do.

scary.



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


Re: all ip addresses of machines in the local network

2006-08-24 Thread John Bokma
tobiah <[EMAIL PROTECTED]> wrote:

> I am a member of another list that has at least one member
> who has lost his vision, and reads his news with a speech
> generator.  It is terribly inconvenient for him to follow
> a thread full of 'bottom postings', as he is then forced to
> sit through the previous message contents again and again
> in search of the new content.

Yes, that's why it's also recommended to *remove all lines you're not 
replying to*. A full quote is always annoying (unless it's really needed 
to get some context, which is in general rare).

Not only people with a vision problem will be thankful for that. Like I 
recommended to *read* on top posting, instead of repeating myths that are 
made up by people who are ignorant.

Simple recipe:
http://johnbokma.com/mexit/2006/04/11/how-to-reply.html

I am sure that people with a vision problem who jump into the thread 
prefer a small context over listening "upside down" to get some context, I 
mean:

A: top posting
Q: what is the most annoying thing on Usenet

Now imagine that Q is quote after quote after qoute because a hand ful of 
lazy clueless bastards want to save time.
  
-- 
John   MexIT: http://johnbokma.com/mexit/
   personal page:   http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: telnetlib thread-safe?

2006-08-24 Thread Fredrik Lundh
Jerry wrote:

>> define thread-safe.  how do you plan to use it?
> 
> I would like to write a program that spawns ~10 threads.  Each thread
> would get a host to connect to from a Queue object and run then do it's
> thing (i.e. connecting to the host, running some commands, returning
> back a success or fail based on the results).
> 
> I just want to make sure that telnetlib is safe for this.

as long as each thread uses it's own Telnet instance, that should be no 
problem at all (as far as I can tell).



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


[ANN]Py++ 0.8.1

2006-08-24 Thread Roman Yakovenko
I'm glad to announce the new version of Py++.

Download page: http://language-binding.net/pyplusplus/download.html

What is it?
Py++ is an object-oriented framework for creating a code generator for
Boost.Python library.

Project home page: http://language-binding.net/pyplusplus/pyplusplus.html

Changes:
1. Support for Boost.Python indexing suite version 2 was implemented. Indexing
suite 2, provides support for almost all STD containers.
2. Py++ generates "stable" code. If header files were not changed,
Py++ will not
change any file.
3. Support for huge classes was added. Py++ is able to split
registration code for
the class to multiple cpp files.
4. User code could be added almost anywhere, without use of low level API.
5. Py++ will provide user with feedback: warnings about exported declarations.
6. Py++ now supports generation of documentation strings.
7. A lot of bugs were fixed.
8. Documentation was written.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Taking data from a text file to parse html page

2006-08-24 Thread Anthra Norell
You may also want to look at this stream editor:

http://cheeseshop.python.org/pypi/SE/2.2%20beta

It allows multiple replacements in a definition format of utmost simplicity:

>>> your_example = '''
"Python has been an important part of Google since the
beginning, and remains so as the system grows and evolves.
"
-- Peter Norvig, >> import SE
>>> Tag_Stripper = SE.SE ('''
 "~<(.|\n)*?>~="   # This pattern finds all tags and deletes them 
(replaces with nothing)
 "~~="   # This pattern deletes comments entirely even 
if they nest tags
 ''')
>>> print Tag_Stripper (your_example)

"Python has been an important part of Google since the
beginning, and remains so as the system grows and evolves.
"
-- Peter Norvig, ~="   # This pattern finds all tags and deletes them 
(replaces with nothing)
 "~~="   # This pattern deletes commentsentirely even if 
they nest tags
 ">> print Tag_Stripper (your_example)

"Python has been an important part of Google since the
beginning, and remains so as the system grows and evolves.
"
-- Peter Norvig,

" you can either translate or delete:

Tag_Stripper = SE.SE ('''
 "~<(.|\n)*?>~="   # This pattern finds all tags and deletes them 
(replaces with nothing)
 "~~="   # This pattern deletes commentsentirely even if 
they nest tags
 ">> print Tag_Stripper (your_example)

'Python has been an important part of Google since the
beginning, and remains so as the system grows and evolves.
'
-- Peter Norvig,

If instead of "htm2iso.se" you write ""=" you delete it and your output 
will be:

Python has been an important part of Google since the
beginning, and remains so as the system grows and evolves.

-- Peter Norvig,

Your Tag_Stripper also does files:

>>> print Tag_Stripper ('my_file.htm', 'my_file_without_tags')
'my_file_without_tags'


A stream editor is not a substitute for a parser. It does handle more 
economically simple translation jobs like this one where a
parser does a lot of work which you don't need.

Regards

Frederic


- Original Message -
From: "DH" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To: 
Sent: Thursday, August 24, 2006 7:41 PM
Subject: Re: Taking data from a text file to parse html page


> I found this
>
http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1bda6ebcfb060f9/ad0ac6b1ac8cff51?lnk=gst&q=replace+text+file&r
num=8#ad0ac6b1ac8cff51
>
> Credit Jeremy Moles
> ---
>
> finds = ("{", "}", "(", ")")
> lines = file("foo.txt", "r").readlines()
>
> for line in lines:
> for find in finds:
> if find in line:
> line.replace(find, "")
>
> print lines
>
> ---
>
> I want something like
> ---
>
> finds = file("replace.txt")
> lines = file("foo.txt", "r").readlines()
>
> for line in lines:
> for find in finds:
> if find in line:
> line.replace(find, "")
>
> print lines
>
> ---
>
>
>
> Fredrik Lundh wrote:
> > DH wrote:
> >
> > > I have a plain text file containing the html and words that I want
> > > removed(keywords) from the html file, after processing the html file it
> > > would save it as a plain text file.
> > >
> > > So the program would import the keywords, remove them from the html
> > > file and save the html  file as something.txt.
> > >
> > > I would post the data but it's secret. I can post an example:
> > >
> > > index.html (html page)
> > >
> > > "
> > > "Python has been an important part of Google since the
> > > beginning, and remains so as the system grows and evolves.
> > > "
> > > -- Peter Norvig,  > > "
> > >
> > > replace.txt (keywords)
> > > "
> > > 
> > >
> > > "
> > >
> > > "
> > >
> > > -- Peter Norvig,  > >
> > > "
> > >
> > > something.txt(file after editing)
> > >
> > > "
> > >
> > > Python has been an important part of Google since the beginning, and
> > > remains so as the system grows and evolves.
> > > "
> >
> > reading and writing files is described in the tutorial; see
> >
> >  http://pytut.infogami.com/node9.html
> >
> > (scroll down to "Reading and Writing Files")
> >
> > to do the replacement, you can use repeated calls to the "replace" method
> >
> >  http://pyref.infogami.com/str.replace
> >
> > but that may cause problems if the replacement text contains things that
> > should be replaced.  for an efficient way to do a "parallel" replace, see:
> >
> >  http://effbot.org/zone/python-replace.htm#multiple
> >
> >
> > 
>
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: String formatting with nested dictionaries

2006-08-24 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I've got a bit of code which has a dictionary nested within another
> dictionary.  I'm trying to print out specific values from the inner
> dict in a formatted string and I'm running into a roadblock.  I can't
> figure out how to get a value from the inner dict into the string.  To
> make this even more complicated this is being compiled into a large
> string including other parts of the outer dict.
> 
> mydict = {'inner_dict':{'Value1':1, 'Value2':2}, 'foo':'bar',
> 'Hammer':'nails'}
> 
> print "foo is set to %(foo)s - Value One is: %(inner_dict['Value1'])s
> and Value Two is: %(inner_dict['Value2'])s -- Hammers are used to pound
> in %(Hammer)s" % mydict
> 
> The above fails looking for a key named 'inner_dict['Value1']' which
> doesn't exist.

the % operator treats the keys as plain keys, not expressions.  if you 
trust the template provider, you can use a custom wrapper to evaluate 
the key expressions:

mydict = {'inner_dict':{'Value1':1, 'Value2':2}, 'foo':'bar', 
'Hammer':'nails'}

class wrapper:
 def __init__(self, dict):
self.dict = dict
 def __getitem__(self, key):
try:
return self.dict[key]
except KeyError:
return eval(key, self.dict)

print "foo is set to %(foo)s - Value One is: %(inner_dict['Value1'])s 
and Value Two is: %(inner_dict['Value2'])s -- Hammers are used to pound 
in %(Hammer)s" % wrapper(mydict)

foo is set to bar - Value One is: 1 and Value Two is: 2 -- Hammers are 
used to pound in nails



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


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

2006-08-24 Thread olsongt

Peter Maas wrote:
> Alex Martelli wrote:
> > Indeed, it has been truthfully observed that Python's the only language
> > with more web frameworks than keywords.
> >
> > I have already suggested to the BDFL that he can remedy this situation
> > in Py3k: all he has to do, of course, is to add a LOT more keywords.
>
> Here is another remedy: he adds one of the frameworks to the standard
> library :)
>
> Peter Maas, Aachen

But there are already 3 ;-)

http://docs.python.org/lib/module-BaseHTTPServer.html
http://docs.python.org/lib/module-SimpleHTTPServer.html
http://docs.python.org/lib/module-CGIHTTPServer.html

To answer the original poster, I personally like the ASP.NET model of
Controls (I'm sure some people will disagree) that do things like
automatically render, automatically marshall/unmarhall form data and
bind to variables, and respond to events.  I always think it's a little
stupid when I try to use a framework, and I still need to manually
extract info from post data, and I still need to manually construct
simple things like  boxes.  That is probably an
interesting area to explore.

I haven't looked at python web frameworks in a while, so if there are
any existing frameworks out there that do things with a similar model,
someone please let me know.

-Grant

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


Re: Python & chess

2006-08-24 Thread tobiah
Paolo Pantaleo wrote:
> Well Python is not a good language for writing a chess engine 

I'm curious; how does python fall short here, and what are the
features that make some other language more suitable for the
task?

Toby

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: all ip addresses of machines in the local network

2006-08-24 Thread tobiah
I am a member of another list that has at least one member
who has lost his vision, and reads his news with a speech
generator.  It is terribly inconvenient for him to follow
a thread full of 'bottom postings', as he is then forced to
sit through the previous message contents again and again
in search of the new content.  
 
> Google for top posting, and read why it's generally considered bad.
> 

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: Why can't I subclass off of "date" ?

2006-08-24 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Ok, maybe this is a stupid question, but why can't I make a subclass of
> datetime.date and override the __init__ method?

__init__ controls initialization of an already constructed object.  to 
control construction, you need to override __new__:

 http://pyref.infogami.com/__new__

e.g.

class A(date):
 def __new__(cls, a, b, c, d):
 print a, b, c, d
return super(A, cls).__new__(cls, 2006, 12, 11)



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


Re: Why can't I subclass off of "date" ?

2006-08-24 Thread Georg Brandl
[EMAIL PROTECTED] wrote:
> Ok, maybe this is a stupid question, but why can't I make a subclass of
> datetime.date and override the __init__ method?
> 
> ---
> 
> from datetime import date
> 
> class A(date):
> def __init__(self, a, b, c, d):
> print a, b, c, d
> date.__init__(self, 2006, 12, 11)
> 
> d = A(1, 2, 3, 4)
> 
> ---
> 
> $ python break_date.py
> Traceback (most recent call last):
>   File "break_date.py", line 9, in ?
> d = A(1, 2, 3, 4)
> TypeError: function takes exactly 3 arguments (4 given)
> 
> 
> If I make A a subclass of some toy class that is constructed with three
> arguments, it works fine.  Why can't I make "date" the subclass?

You'll have to also override the __new__ method.

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


Re: Python and STL efficiency

2006-08-24 Thread JSprenkle

Licheng Fang wrote:
> Hi, I'm learning STL and I wrote some simple code to compare the
> efficiency of python and STL.
>
> //C++
> #include 
> #include 
> #include 
> #include 
> #include 
> using namespace std;
>
> int main(){
>   vector a;
>   for (long int i=0; i<1 ; ++i){
>   a.push_back("What do you know?");
>   a.push_back("so long...");
>   a.push_back("chicken crosses road");
>   a.push_back("fool");
>   }
>   set b(a.begin(), a.end());
>   unique_copy(b.begin(), b.end(), ostream_iterator(cout, "\n"));
> }

I think you probably want this C++ code instead:

//C++
#include 
#include 
#include 
#include 
#include 
using namespace std;

int main(){
vector a;
a.reserve( 4 );  //<-- note this change
for (long int i=0; i<1 ; ++i){
a.push_back("What do you know?");
a.push_back("so long...");
a.push_back("chicken crosses road");
a.push_back("fool");
}
set b(a.begin(), a.end());
unique_copy(b.begin(), b.end(), ostream_iterator(cout,
"\n"));
}

It will run a lot faster if it doesn't have to keep resizing the array.

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


Re: setuid root

2006-08-24 Thread Tiago Batista
On Thu, 24 Aug 2006 17:48:26 +0200
Patrick Useldinger <[EMAIL PROTECTED]> wrote:

> Tiago Simões Batista wrote:
> > The sysadmin already set the setuid bit on the script, but it
> > still fails when it tries to write to any file that only root has
> > write access to.
> 
> use sudo.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

Thank you, both fot you and for Ove Svensson.

I was looking for a simpler way, that required as little intervention as 
possible from the main sysadmin. Given the situation I am facing, I will 
probably use sudo, it keeps things cleaner...

Again, thank you

Tiago


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

Re: Python Syntax Highlighting Module

2006-08-24 Thread Cliff Wells
On Mon, 2006-08-21 at 08:19 -0700, gene tani wrote:
> [EMAIL PROTECTED] wrote:
> > Hello,
> > I have an idea for a project which involves an editor that supports
> > syntax highlighting.  This would be for any language, particularly php,
> > html, css, etc.  I would like to write this program using python.  It
> > would only make sense to base this upon existing open source code.  My
> > question is there a python module or examples on how to write a code
> > editor which supports modulated syntax highlighting?
> >
> > Thank you,
> > Blaine
> 
> just a *few* examples

If I were to start a GUI editor project, I'd undoubtedly start by
looking at Scintilla:

http://www.scintilla.org/

Also see:
http://scintilla.sourceforge.net/ScintillaRelated.html

Regards,
Cliff
-- 

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


Re: [wxPython-users] [ANN]UliPad 3.3 is released

2006-08-24 Thread Mario Lacunza
Sorry, I correct me:Your link in the message not found, but the link in the web site work Ok.Thanks!2006/8/24, Mario Lacunza <[EMAIL PROTECTED]
>:Hi,Is possible then you correct the path for download the sources Zip file?? 
I want to test this tool but I dont could donwload it...Thansk!2006/8/23, limodou <
[EMAIL PROTECTED]>:
What's it?
It's an Editor based on wxPython. NewEdit is the old name, and UliPadis the new name. UliPad uses Mixin and Plugin technique as itsarchitecture. Most of its classes can be extended via mixin and plugincomponents, and finally become an integrity class at
creating the instance. So UliPad is very dynamic. You can write thenew features in new files, and hardly need to modify the existingcode. And if you want to extend the existing classes, you could writemixins and plugins, and this will be bound to the target class that I
call "Slot Class". This technique will make the changes centralizedand easily managed.What are its features?  *  Cross platformo   based on wxPython, so it can run anywhere that wxPython
works, such as: Windows, Linux.o   Unicode support.  *  Most features of wxStyledTextCtrl(Scintilla)o   Syntax highlighting, support Python, c/c++, html, plaintext, perl, ruby, css, _javascript_
o   Foldingo   Brace Matchingo   ...  *  Extended selectiono   Extended word selection -- You can pressCtrl+MouseDoubleClick to select a word including '.'o   Matched selection -- Select text in quoted chars like:
(), [], {}, '', "".  *  Other editing extensiono   Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, andmore. You can duplicate above or below char, word, lineo   Quoting text -- Add some quoted chars before and after
selected text, just as: "", '', (), [], {}, ando   Text convertion and view -- python -> html, reStructuredText -> html, textile -> html, and you can output or viewo   Utf-8 encoding auto detect
o   Changing document encodingoAuto backupoLast session support -- It'll save all the filenames asclosed, and reopen the files as next started.oSmart judge the indent char -- It'll auto guess the
indent char, and sets it.oFinding in filesoBookmark support  *  Python supportobuilt-in python interactive window based on ?PyShell,support Unicodeo   Auto completion
o   Function syntax calltipso   Run, run with argument, stop python sourceo   Auto change current patho   Python class browsero   Indent pasting support(New)

  *  Code snippetso  You can manage your code snippets with categories, andeach category can have many items. Every item will represent a codesnippet. You can insert an item just by double-clicking on it. It even
supports importing and exporting.  *  Simple project supporto  Can create a special file _project, so every file andfolder under the folder which has the _project can be considered as awhole project.
  *  Extension mechanismo  Script -- You can write easy script to manipulate the allresource of UliPad, just like: text conversion, etc.o  Plugin -- Customized function. More complex but more
powerful. Can easily merge with UliPad, and can be managed via menu.o  Shell command -- Add often used shell commands, and execute them.  *  Ftp supporto  You can edit remote files through ftp. You can add,
rename, delete, upload, download file/directory.  *  Multilanguage supporto  Currently supports two languages: English and Chinese,which can be auto-detected.  *  Shipped plugins(must be configed as used them before)
o  Document links -- Python documentation and wxPython documentation.o  Many plugins can be found at UliPad wiki page.  *  Shipped scriptso  Many scripts can be found at UliPad wiki page.
  *  Wizard (New)o  You can make your own wizard template. The wizard caninput user data, combine with template, and output the result. Andwizard also support code framework created. This feature will help you
improving coding efficiency.  *  Direcotry Browser(New)o  Browse multiple directories, and you can really add,delete, rename directories and files. Double click will open the filein Editor window.
o  Support Copy, Cut, and Paste.o  Search in Directory  *  AutoComPlete(acp)(New)o  Suport user autocomplete file, it can help to input codevery helpful and functional. Just like EditPlus, but may be more
powerful.o  Manually apply some acp files to current document  *  Column Edit Mode(New)Where to download it?download lastest version 3.3:

http://wiki.woodpecker.org.cn/moin/UliPad?action="">also have windows installer:

http://wiki.woodpecker.org.cn/moin/UliPad?action="">wiki: 
http://wiki.woodpecker.org.cn/moin/UliPadsvn: 
http://cvs.woodpecker.org.cn/svn/woodpecker/ulipad/trunk

Why can't I subclass off of "date" ?

2006-08-24 Thread davidfinance
Ok, maybe this is a stupid question, but why can't I make a subclass of
datetime.date and override the __init__ method?

---

from datetime import date

class A(date):
def __init__(self, a, b, c, d):
print a, b, c, d
date.__init__(self, 2006, 12, 11)

d = A(1, 2, 3, 4)

---

$ python break_date.py
Traceback (most recent call last):
  File "break_date.py", line 9, in ?
d = A(1, 2, 3, 4)
TypeError: function takes exactly 3 arguments (4 given)


If I make A a subclass of some toy class that is constructed with three
arguments, it works fine.  Why can't I make "date" the subclass?

Thanks for any advice.

David

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


Re: [wxPython-users] [ANN]UliPad 3.3 is released

2006-08-24 Thread Mario Lacunza
Hi,Is possible then you correct the path for download the sources Zip file?? I want to test this tool but I dont could donwload it...Thansk!2006/8/23, limodou <
[EMAIL PROTECTED]>:What's it?
It's an Editor based on wxPython. NewEdit is the old name, and UliPadis the new name. UliPad uses Mixin and Plugin technique as itsarchitecture. Most of its classes can be extended via mixin and plugincomponents, and finally become an integrity class at
creating the instance. So UliPad is very dynamic. You can write thenew features in new files, and hardly need to modify the existingcode. And if you want to extend the existing classes, you could writemixins and plugins, and this will be bound to the target class that I
call "Slot Class". This technique will make the changes centralizedand easily managed.What are its features?  *  Cross platformo   based on wxPython, so it can run anywhere that wxPython
works, such as: Windows, Linux.o   Unicode support.  *  Most features of wxStyledTextCtrl(Scintilla)o   Syntax highlighting, support Python, c/c++, html, plaintext, perl, ruby, css, _javascript_
o   Foldingo   Brace Matchingo   ...  *  Extended selectiono   Extended word selection -- You can pressCtrl+MouseDoubleClick to select a word including '.'o   Matched selection -- Select text in quoted chars like:
(), [], {}, '', "".  *  Other editing extensiono   Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, andmore. You can duplicate above or below char, word, lineo   Quoting text -- Add some quoted chars before and after
selected text, just as: "", '', (), [], {}, ando   Text convertion and view -- python -> html, reStructuredText -> html, textile -> html, and you can output or viewo   Utf-8 encoding auto detect
o   Changing document encodingoAuto backupoLast session support -- It'll save all the filenames asclosed, and reopen the files as next started.oSmart judge the indent char -- It'll auto guess the
indent char, and sets it.oFinding in filesoBookmark support  *  Python supportobuilt-in python interactive window based on ?PyShell,support Unicodeo   Auto completion
o   Function syntax calltipso   Run, run with argument, stop python sourceo   Auto change current patho   Python class browsero   Indent pasting support(New)
  *  Code snippetso  You can manage your code snippets with categories, andeach category can have many items. Every item will represent a codesnippet. You can insert an item just by double-clicking on it. It even
supports importing and exporting.  *  Simple project supporto  Can create a special file _project, so every file andfolder under the folder which has the _project can be considered as awhole project.
  *  Extension mechanismo  Script -- You can write easy script to manipulate the allresource of UliPad, just like: text conversion, etc.o  Plugin -- Customized function. More complex but more
powerful. Can easily merge with UliPad, and can be managed via menu.o  Shell command -- Add often used shell commands, and execute them.  *  Ftp supporto  You can edit remote files through ftp. You can add,
rename, delete, upload, download file/directory.  *  Multilanguage supporto  Currently supports two languages: English and Chinese,which can be auto-detected.  *  Shipped plugins(must be configed as used them before)
o  Document links -- Python documentation and wxPython documentation.o  Many plugins can be found at UliPad wiki page.  *  Shipped scriptso  Many scripts can be found at UliPad wiki page.
  *  Wizard (New)o  You can make your own wizard template. The wizard caninput user data, combine with template, and output the result. Andwizard also support code framework created. This feature will help you
improving coding efficiency.  *  Direcotry Browser(New)o  Browse multiple directories, and you can really add,delete, rename directories and files. Double click will open the filein Editor window.
o  Support Copy, Cut, and Paste.o  Search in Directory  *  AutoComPlete(acp)(New)o  Suport user autocomplete file, it can help to input codevery helpful and functional. Just like EditPlus, but may be more
powerful.o  Manually apply some acp files to current document  *  Column Edit Mode(New)Where to download it?download lastest version 3.3:
http://wiki.woodpecker.org.cn/moin/UliPad?action="">also have windows installer:
http://wiki.woodpecker.org.cn/moin/UliPad?action="">wiki: http://wiki.woodpecker.org.cn/moin/UliPadsvn: 
http://cvs.woodpecker.org.cn/svn/woodpecker/ulipad/trunkmaillist: http://groups.google.com/group/ulipadIf you have any problem as using UliPad, welcome to join the UliPad
maillist to discuss.Hope fun!--I like

Re: telnetlib thread-safe?

2006-08-24 Thread Diez B. Roggisch
Jerry schrieb:
> Fredrik Lundh wrote:
>> define thread-safe.  how do you plan to use it?
> 
> I would like to write a program that spawns ~10 threads.  Each thread
> would get a host to connect to from a Queue object and run then do it's
> thing (i.e. connecting to the host, running some commands, returning
> back a success or fail based on the results).
> 
> I just want to make sure that telnetlib is safe for this.

Usually, OO-style libs that don't share state between objects are pretty 
safe - and  I'd presume that this holds for telnetlib, too.

There is of course no way except looking into the source to _know_ that 
for sure. So - try it out.

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


[ANN]pygccxml 0.8.1

2006-08-24 Thread Roman Yakovenko
I'm glad to announce the new version of pygccxml is available.

Download page: http://www.language-binding.net/pygccxml/download.html

What is it?
"...The purpose of the  GCC-XML  extension is to generate an XML
description of a C++ program from GCC's internal representation. Since
XML is easy to parse, other development tools will be able to work
with C++ programs without the burden of a complicated C++ parser..."

The purpose of  pygccxml  is to read GCC-XML generated file and
provide a simple framework to navigate C++ declarations using Python
classes.

Project home page: http://www.language-binding.net/pygccxml/pygccxml.html

Changes:
1. The project has been ported to Mac OS.
2. New type traits that works with STD containers were added.
3. Logging and user messages related functionality were improved.
4. Support for Java native types was added.
5. Cache classes implementation and performance were improved.

You can find the full list of changes here:
http://language-binding.net/pygccxml/history/history.html#version-0-8-1

--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't destroy a wxMiniFrame

2006-08-24 Thread Laszlo Nagy
Flavio írta:
> Hi,
>
> I have a miniframe composed mainly of combo boxes, that I need to
> destroy and recreate multiple time with different choice lists for the
> combo boxes.
>
> My problem is that even after destroying a miniframe with the Destroy()
> method, when it is recreated, the combo boxes show the same lists of
> its previous incarnation...
>
> how can I completely destroy a miniframe?
>   
 From what you wrote, I think that you did not create a new miniframe. 
Although you called Destroy(), you tried to display it again. This is 
what the documentation says about destroy.

Destroys the window safely. Use this function instead of the delete 
operator, since different window classes can be destroyed differently. 
*Frames and dialogs are not destroyed immediately* when this function is 
called -- they are added to a list of windows to be deleted on idle 
time, when all the window's events have been processed. This prevents 
problems with events being sent to non-existent windows.


Regards,

   Laszlo

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


can't destroy a wxMiniFrame

2006-08-24 Thread Flavio
Hi,

I have a miniframe composed mainly of combo boxes, that I need to
destroy and recreate multiple time with different choice lists for the
combo boxes.

My problem is that even after destroying a miniframe with the Destroy()
method, when it is recreated, the combo boxes show the same lists of
its previous incarnation...

how can I completely destroy a miniframe?

Flavio

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


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

2006-08-24 Thread Cliff Wells
On Thu, 2006-08-24 at 04:28 -0700, Paul Boddie wrote:
> Cliff Wells wrote:
> > On Thu, 2006-08-24 at 04:04 +, Tim Roberts wrote:
> > > Cliff Wells <[EMAIL PROTECTED]> wrote:
> > > >
> > > >But there are interesting things in Ruby (and Ruby 2 should take care of
> > > >lots of warts Ruby 1.8 has) that Python could learn from.  All-in-all,
> > > >Ruby is mostly as good as Python in most ways and better than Python in
> > > >a couple key ways.
> 
> The big difference between Ruby and Python is the lifecycle phase that
> the languages/systems are in: Ruby arguably has room for a lot of basic
> improvements in the architecture of the virtual machine and presumably
> has a list of "must add" features that cover gaping holes with respect
> to certain audiences [1], whereas Python has been around for ages and
> has covered most of the critical gaps in the feature list (although we
> can always suggest things which bother our own part of the community).
> Whereas the Ruby people merely have to agree on how critical their
> missing features are and to move in one widely agreed direction, the
> Python people face a tougher choice as to what should be done next;
> strategies include a tidying-up exercise to make the language more
> coherent, a complete reimplementation, deep modifications to the
> runtime, the introduction of radical new semantics.

All true, but there's a more fundamental difference that's going to show
more as a larger number of people become used to Ruby's semantics: any
Ruby statement can be used as an expression.  This is firmly from the
Lisp family of languages whereas Python's statement-based syntax is
firmly in the Fortran branch.  With the exception of Lisp itself, no
language has seen the popularity of this style of programming until
Ruby.  I think this represents a real danger to Python's mindshare.
Once people have tried expression-based languages, they tend to be
loathe to return to statement-based languages.  To date,
expression-based languages have been mostly of interest in academia or
to a small group of elitists and so weren't practical to use for
day-to-day work.  Ruby has changed that and I think we're just starting
to see the fallout.  Rails may have brought them there, but Ruby itself
is keeping them there.  My fear is that the expression-based family of
languages is the Homo Sapiens to our statement-based Neanderthals and we
can either evolve or disappear.  Python is unique in many ways and I'd
hate to see those unique features lost because we're stuck on the wrong
evolutionary branch.

> The fewer obvious issues that a language has, the less energy there is
> in the community to deal with those issues thoroughly, I think. I guess
> the Perl community chose a bold new direction in line with the
> observation that a big vision can inspire much more in people than lots
> of incremental changes to an existing vision, but the energy required
> to follow through on such a vision can be immense. In addition to all
> this, a large existing community is more likely to want larger benefits
> for smaller levels of disruption because of the amount of existing
> code. Thus, the available energy for change is less in a mature project
> than in a growing project because people have to constantly monitor the
> breakage in their existing investments in the language.
> 
> > > ...but you can't READ Ruby code.
> >
> > Yeah, that's one of the big reasons I haven't seriously considered
> > trying it.  It's expressive, got interesting features... and appears
> > unreadable to me.  I'm usually pretty good at deciphering most
> > languages, even if I haven't used them before, but Ruby is one of the
> > exceptions.
> 
> My feeling is that I'd rather learn more about Lisp or Scheme than Ruby
> - the benefits are greater and for me Lisp and Scheme increasingly have
> the edge on readability. Perhaps I'm just not "tuned in" to
> Smalltalk-style syntaxes.

I'm in the same camp.  As I mentioned earlier, it's been mostly inertia
and the wealth of the Python community that's kept me with Python.
That's why I was so excited when I found Logix.  Lisp-like features with
Python's syntax that generates Python bytecode.  Actually Logix is
perhaps too far the other direction as it supports Lisp-style macros and
the creation of arbitrary syntax, which perhaps would justify some of
the fears people have of Lisp-like languages.  
The part I found appealing was having Python-like syntax in an
expression-based language, with the capability to integrate completely
with Python libraries.  Absolutely the best of both worlds.  I've been
trying to contact the author of Logix to find out what the status of the
project is or if he's abandoned it.  If you haven't looked at it you
really ought to.

http://livelogix.net/logix/


> > This brings us back around to the web framework debates.  For many
> > people Ruby "fits" their brains and for others Python does.  I think
> > frameworks are similar.  I tried Django and while I th

Python & chess

2006-08-24 Thread Paolo Pantaleo
Well Python is not a good language for writing a chess engine (even if
a chess engine exists:
http://www.kolumbus.fi/jyrki.alakuijala/pychess.html), but it could be
grat for chess interfaces, for drawing boards, and similar things. I
foudn out a library for these things
(http://www.alcyone.com/software/chess/). Does anyone konw about more
chess related modules?

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


Re: telnetlib thread-safe?

2006-08-24 Thread Jerry
Fredrik Lundh wrote:
> define thread-safe.  how do you plan to use it?

I would like to write a program that spawns ~10 threads.  Each thread
would get a host to connect to from a Queue object and run then do it's
thing (i.e. connecting to the host, running some commands, returning
back a success or fail based on the results).

I just want to make sure that telnetlib is safe for this.

--
Jerry

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


  1   2   >