Re: "0 in [True,False]" returns True

2005-12-15 Thread Antoon Pardon
Op 2005-12-14, Grant Edwards schreef <[EMAIL PROTECTED]>:
> On 2005-12-14, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>
> Well, as you might argue, I'm not tryng to effect a change in
> your behaviour, I'm simply trying to point out how it could be
> made more rational.
> [...]
 Or return NaN instead of raising exception for numeric
 functions ?
>>>
>>> Because usually (in my applications anyway) NaN is a perfectly
>>> valid value and not an "exception" case that needs to be
>>> handled.
>>
>> I don't see the difference. In my application False and True
>> (or Registered and UnRegistered if you prefer) are perfectly
>> valid values too.  They are not "exception" cases that need to
>> be handled.
>
> Well, in my case, a given name (or return value) is always
> bound to a floating point object. I don't test the type of the
> object and treat it in two different ways depending on what
> type it is.  It's just a float.

Do you find that difference so important? As far as I understand
the gtk identifiers are always positive integers. So I could
have coded as follows:

  UnConnected = (-1, -2)
  Registered, UnRegistered = UnConnected
  
  ...

  if self.cb_src in UnConnected:

Now all values are integers and I no longer treat an object different
depending on type but on value. However conceptually nothing changed.
My code branches depending on set membership of this attribute.

Could you explain why it should make a (big) difference between
these two approaches?

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


Re: "0 in [True,False]" returns True

2005-12-15 Thread bonono

Antoon Pardon wrote:
> Op 2005-12-14, Grant Edwards schreef <[EMAIL PROTECTED]>:
> > On 2005-12-14, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> >
> > Well, as you might argue, I'm not tryng to effect a change in
> > your behaviour, I'm simply trying to point out how it could be
> > made more rational.
> > [...]
>  Or return NaN instead of raising exception for numeric
>  functions ?
> >>>
> >>> Because usually (in my applications anyway) NaN is a perfectly
> >>> valid value and not an "exception" case that needs to be
> >>> handled.
> >>
> >> I don't see the difference. In my application False and True
> >> (or Registered and UnRegistered if you prefer) are perfectly
> >> valid values too.  They are not "exception" cases that need to
> >> be handled.
> >
> > Well, in my case, a given name (or return value) is always
> > bound to a floating point object. I don't test the type of the
> > object and treat it in two different ways depending on what
> > type it is.  It's just a float.
>
> Do you find that difference so important? As far as I understand
> the gtk identifiers are always positive integers. So I could
> have coded as follows:
>
>   UnConnected = (-1, -2)
>   Registered, UnRegistered = UnConnected
>
>   ...
>
>   if self.cb_src in UnConnected:
>
> Now all values are integers and I no longer treat an object different
> depending on type but on value. However conceptually nothing changed.
> My code branches depending on set membership of this attribute.
>
> Could you explain why it should make a (big) difference between
> these two approaches?
That is what I would do in C or similar language where a variable can
only be one type.

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


Re: "0 in [True,False]" returns True

2005-12-15 Thread Antoon Pardon
Op 2005-12-14, Mike Meyer schreef <[EMAIL PROTECTED]>:
> [EMAIL PROTECTED] writes:
>> Steve Holden wrote:
>>> >>It would be somewhat more self-documenting, but why not just use one
>>> >>name to indicate the state and another, only meaningful in certain
>>> >>states, to indicate the callback?
>>> > Why should I do that? Checking the type of a variable is conceptually
>>> > no different form testing set membership. So what I did, was just
>>> > bringing two disjoint sets togther and working with a variable from
>>> > that union. This is all in all a rather simple mathematical idea.
>>> > And I don't see why I should put certain information into a seperate
>>> > variable. It makes as much sense as working with numbers and using
>>> > a seperate variable to store whether a particular number is postive,
>>> > even or has some other characteristic. You don't seperate information
>>> > you can easily acquire from the variable itself. So why should I
>>> > seperate this information that is aquired just as easily?
>>> Well, as you might argue, I'm not tryng to effect a change in your
>>> behaviour, I'm simply trying to point out how it could be made more
>>> rational.
>> What would be the difference in his usage and allowing Null in a RDBMS
>> column ? Or return NaN instead of raising exception for numeric
>> functions ?
>
> Having a value to indicate "no value" is, of course, perfectly
> reasonable. However, you then test *for that value*; you don't test
> the type of the value to see if it's of the right type.
>
> Once you get beyond the variable either having a valid value or not,
> it's really time to consider a different approach.

How do you feel about testing for set membership? I can have a set
with values to be treated differently than values not in the set.
Do you consider that an acceptable approach?

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


Re: Questions about working with character encodings

2005-12-15 Thread garabik-news-2005-05
Kenneth McDonald <[EMAIL PROTECTED]> wrote:
> I am going to demonstrate my complete lack of understanding as to  
> going back and forth between
> character encodings, so I hope someone out there can shed some light  
> on this.  I have always
> depended on the kindness of strangers... :-)
> 
> I'm playing around with some very simplistic french to english  
> translation. As some text to
> work with, I copied the following from a french news site:
> 
> Dans les années 1960, plus d'une voiture sur deux vendues aux  
> Etats-Unis était fabriquée par GM.
> Pendant que les ventes s'effondrent, les pertes se creusent :  
> sur les neuf premiers mois de l'année 2005,
> elles s'élèvent à 3,8 milliards de dollars (3,18 milliards  
> d'euros), et le dernier trimestre s'annonce difficile.
> Quant à la dette, elle est hors normes : 285 milliards de  
> dollars, soit une fois et demie le chiffre d'affaires.
> GM est désormais considéré par les agences de notation  
> financière comme un investissement spéculatif.
> Un comble pour un leader mondial !
> 
> Of course, it has lots of accented, non-ascii characters. However, it  
> posted just fine into both
> this email program (hopefully it displays equally well at the other  
> end), 

It has correct charset header indicating ISO-8859-1 encoding, so yes, it
displayed correctly.

> and into my Python
> editing program (jEdit).
> 
> To start with, I'm not at all cognizant of how either the editor or  
> the mail program could even
> know what encodings to use to display this text properly...

You did not tell us what OS are you using, but in case of Unix, it all
goes up and down with locale - you can transparently pass around text
data as long as the characters are in the repertoire of your locale - of
course, as long as the applications are locale-aware - many older ones
are not. (It is best to use UTF-8 encoding, so that all the more or less
obscure characters can be represented)

If you have Windows, it depends on programs working with old 8-bit ANSI
API, or new unicode API. If the programs use unicode API, you can
without problems pass data around, if they use 8-bit API, you are
restricted to the characters from your system codepage.

> 
> Next, having got the text into the Python file, I presumably have to  
> encode it as a Unicode
> string, but trying something like   text = u"""désormais considéré"""  
> complains to the effect
> that :
> 
> UnicodeEncodeError: 'ascii' codec can't encode character u'\x8e'  
> in position 13: ordinal not in range(128)
> 
> This occurs even with the first line in the file of
> 
> # -*- coding: latin-1 -*-
> 
> which I'd hoped would include what I think of as the latin characters  
> including all those ones with
> graves, agues, circonflexes, umlauts, cedilles, and so forth.  

latin-1 is not enough for proper French (lack of œ). It is not even
enough for English, it lacks proper typographic quotes and so on.

> Apparently it does not :-)

Well, it would be enough for your example, "désormais considéré"
does indeed fit into latin-1. But python complains about character \x8e,
which indeed does not belong to latin-1. Without knowing your OS and
your locale (or ANSI codepage), we cannot tell how it got there.

> 
> So I really have two questions:
> 
>   1) How the heck did jEdit understand the text with all the accents  
> I pasted into it? More
> specifically, how did it know the proper encoding to use?

jEdit is written in Java, right? Java has a good internal unicode
support, so if your OS allowed it, pasting from WWW browser worked since
the browser had to new the encoding (in order to display it properly).

> 
>   2) How do I get Python to understand this text? Is there some sort  
> of coding that will
> work in almost every circumstance?

utf-8, obviously. Unless you have a strong reason not to do so, use
utf-8 exclusively - you never know what strange character can appear
(even in plain English), and you working and tested application will
start crashing when it gets to the real worls.

So, use # -*- coding: utf-8 -*-, but MAKE SURE jEdit is configured to
save the file in utf-8 encoding (not knowing jEdit, I cannot tell you
how to achieve this, but jEdit's www page claims that jEdit does support
utf-8).

Then there is a little problem with python stdout trying to convert
unicode strings into system default encoding and failing if it cannot be
done, but let's leave this for the moment :-)

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to get the local mac address?

2005-12-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Frank Millman wrote:
> 
>>[EMAIL PROTECTED] wrote:
>>
>>>Sorry that I can't help you in any way but have a question myself.  Is
>>>there an OS independent way to get this thing(regardless of how to
>>>format it) in Python ? I know this may not matter if all you want is
>>>Windows but there is just another thread talking about one should write
>>>programs that is OS independent.
>>>
>>>Is this a problem of the network library of python ?
>>
>>This is not a generic solution, but it works for me on Linux and
>>Windows
>>
>>def getMacAddress():
>>if sys.platform == 'win32':
>>for line in os.popen("ipconfig /all"):
>>if line.lstrip().startswith('Physical Address'):
>>mac = line.split(':')[1].strip().replace('-',':')
>>break
>>else:
>>for line in os.popen("/sbin/ifconfig"):
>>if line.find('Ether') > -1:
>>mac = line.split()[4]
>>break
>>return mac
>>
> 
> Thanks, but how can I associate the result to the socket, assuming that
> is the reason for wanting to get at the MAC ?
> 
Why should you want to associate a MAC address with a socket? Each 
interface has an IP address, and it's that you should be using.

> I see that some *nix implementation use fcntl/ioctl to read this info
> out of the file handle of a socket but these modules don't exist on
> Windows(may be some other platform as well).
> 
Indeed, and that's why most networkers probably wouldn't regard this as 
a deficiency in Python's network handling but an inevitable consequence 
of the diversity of architectures, utilities and drivers in today's world.

It may well be possible to write Python code that will run on all 
platforms (for example, the same way as the os.path module does, by 
importing the correct piece of code according to the platform), but it 
would need maintenance. Since the interface MAC address is unimportant 
for most network applications I guess nobody has so far thought it worth 
contributing to the core.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: How to get the local mac address?

2005-12-15 Thread Frank Millman

[EMAIL PROTECTED] wrote:
> Frank Millman wrote:
> > [EMAIL PROTECTED] wrote:
> > > Sorry that I can't help you in any way but have a question myself.  Is
> > > there an OS independent way to get this thing(regardless of how to
> > > format it) in Python ? I know this may not matter if all you want is
> > > Windows but there is just another thread talking about one should write
> > > programs that is OS independent.
> > >
> > > Is this a problem of the network library of python ?
> >
> > This is not a generic solution, but it works for me on Linux and
> > Windows
> >
> > def getMacAddress():
> > if sys.platform == 'win32':
> > for line in os.popen("ipconfig /all"):
> > if line.lstrip().startswith('Physical Address'):
> > mac = line.split(':')[1].strip().replace('-',':')
> > break
> > else:
> > for line in os.popen("/sbin/ifconfig"):
> > if line.find('Ether') > -1:
> > mac = line.split()[4]
> > break
> > return mac
> >
> Thanks, but how can I associate the result to the socket, assuming that
> is the reason for wanting to get at the MAC ?
>
> I see that some *nix implementation use fcntl/ioctl to read this info
> out of the file handle of a socket but these modules don't exist on
> Windows(may be some other platform as well).

As you can see, this is a quick and dirty solution.

I am sure you can hack at it some more, bring up the associated ip
address, and compare it with socket.gethostbyaddr() or similar.

I don't know of a more correct solution - maybe someone else can advise
better.

BTW I recall a response some time ago warning that you cannot rely on a
mac address, as they can be modified. Depending on your intended use,
this may or may not be important.

Sorry I cannot be of more help

Frank

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


Re: IsString

2005-12-15 Thread Steve Holden
Donn Cave wrote:
> Quoth Mike Meyer <[EMAIL PROTECTED]>:
> | Donn Cave <[EMAIL PROTECTED]> writes:
> ...
> 
> The question is whether basically everyone needs to get there, or we
> can expect the masses to use the language _without understanding it_
> in this sense, without understanding the language-specific stuff.
> I don't know how important that is, I guess it depends on how real
> the CP4E world is ever going to be, but I think it's wishful thinking
> to expect that to work with Python.
> 
Hear, hear. However you describe it Python is what it is, and this 
interminable discussion about its similarities with and differences from 
various concepts (most lately call by name/call by value) doesn't much 
aid understanding for the majority.

The important question is not "what's that Python concept called in 
other languages" but "do you understand how Python works".

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: OO in Python? ^^

2005-12-15 Thread Antoon Pardon
Op 2005-12-14, Christopher Subich schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Suppose we would add type declarations in python.
>> So we could do things like
>> 
>>   int: a
>>   object: b
>> 
>> Some people seem to think that this would introduce static
>> typing, but the only effect those staments need to have
>> is that each time a variable is rebound an assert statement
>> would implicitly be executed, checking whether the variable is
>> still an instance of the declared type.
>
> Doesn't work; duck typing is emphatically not subclass-typing.

I don't see how that is relevant.

> For this 
> system to still work and be as general as Python is now (without having 
> to make all variables 'object's),

But the way Guido wants python to evolve would make all variables
objects. This is what PEP 3000 states.

  Support only new-style classes; classic classes will be gone.

As far as I understand this would imply that all classes are subclasses
of object and thus that isinstance(var, object) would be true for all variables.

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


Re: OO in Python? ^^

2005-12-15 Thread Antoon Pardon
Op 2005-12-14, Magnus Lycka schreef <[EMAIL PROTECTED]>:
> Christopher Subich wrote:
>> Doesn't work; duck typing is emphatically not subclass-typing.  For this 
>> system to still work and be as general as Python is now (without having 
>> to make all variables 'object's), we'd need true interface checking. 
>> That is, we'd have to be able to say:
>> 
>> implements + like int: a
>> 
>> or somesuch.  This is a Hard problem, and not worth solving for the 
>> simple benefit of checking type errors in code.
>> 
>> It might be worth solving for dynamic code optimization, but that's 
>> still a ways off.
>
> Correct, but he's just trolling you know. What he suggests isn't
> static typing, and he knows it.

What I know or not isn't the point. My impression is that different
people have different ideas on what is static typing and what is not.
I can't read minds about what each individual person thinks. So
I don't know whether you (or someone else) considered this static
typing or not.

> It gives all the rigidity of static
> typing with only a tiny fraction of the claimed benefits, but it would
> give a hefty performance penalty.

Yes it would give a performance penalty. That is irrelavant to the
question asked. Nothing stops the language designers from using
this type information, to produce more efficient code where possible.
But whether or not the designers would do this, would make no difference
on what would be possible to do.

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


Re: How to get the local mac address?

2005-12-15 Thread bonono

Steve Holden wrote:
> Why should you want to associate a MAC address with a socket? Each
> interface has an IP address, and it's that you should be using.
Say for example I want to find out the MAC if a particular interface in
python.

> It may well be possible to write Python code that will run on all
> platforms (for example, the same way as the os.path module does, by
> importing the correct piece of code according to the platform), but it
> would need maintenance. Since the interface MAC address is unimportant
> for most network applications I guess nobody has so far thought it worth
> contributing to the core.
> 
That is a reasonable explanation.

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


Re: How to get the local mac address?

2005-12-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Steve Holden wrote:
> 
>>Why should you want to associate a MAC address with a socket? Each
>>interface has an IP address, and it's that you should be using.
> 
> Say for example I want to find out the MAC if a particular interface in
> python.
> 
When you are asked "why would you want to do something" it isn't 
normally considered sufficient to reply "suppose I want to do 
something". I'm still trying to find out what use case (apart from 
curiosity) drives this need to know.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Self-awareness of imported modules? Do they know where they live?

2005-12-15 Thread Dody Suria Wijaya
import os
print os.__file__

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


Re: Self-awareness of imported modules? Do they know where they live?

2005-12-15 Thread Martin M.
Hi Heiko,

Thanks so much for your help! I just tested it and it works like a
charm!

Test File 1
-- main.py
#!/usr/bin python

from lib import being

being.location()

Test File 2
-- being.py
#!/usr/bin/python

import os

def location():
print os.path.abspath(__file__)

results in:
martin% python main.py
/Volumes/CodeIsland/Projects/glashaus/glashaus0.1a/lib/being.pyc

Now I can use os.path.split() to get the parent directory and
os.path.join() to target my AppleScript file.

Thanks again!

Martin M.

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


Re: PHP = Perl Improved

2005-12-15 Thread Måns Rullgård
Martin Christensen <[EMAIL PROTECTED]> writes:

>> "Tin" == Tin Gherdanarra <[EMAIL PROTECTED]> writes:
>
> Tin> Xah Lee wrote:
>>> recently i got a project that involves the use of php. In 2 days, i
>>> read almost the entirety of the php doc. Finding it a breeze
>>> because it is roughly based on Perl, of which i have mastery.
>
> Tin> I suspect that you are a computer program posing as a human
> Tin> usenet correspondent.
>
> Tin> Please answer these questions: [...]
>
> Will you accept a solution in Perl? He has mastery of that language,
> you know. You might have better luck if you phrase your questions in
> Perl, too, since he doesn't seem to understand it when people tell him
> to bugger off in plain English.

OK, lets try:

die;

-- 
Måns Rullgård
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the local mac address?

2005-12-15 Thread bonono

Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
> > Steve Holden wrote:
> >
> >>Why should you want to associate a MAC address with a socket? Each
> >>interface has an IP address, and it's that you should be using.
> >
> > Say for example I want to find out the MAC if a particular interface in
> > python.
> >
> When you are asked "why would you want to do something" it isn't
> normally considered sufficient to reply "suppose I want to do
> something". I'm still trying to find out what use case (apart from
> curiosity) drives this need to know.
>
That is nothing but curiosity of why there is no such thing. I didn't
start a thread with "what the [EMAIL PROTECTED] hell that I cannot get MAC 
address
through the socket module".

And I answer things the way I want to, if it does fit your expected
answer, there is nothing I can do. I am not here to convince you.

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


Re: How to get the local mac address?

2005-12-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Steve Holden wrote:
> 
>>[EMAIL PROTECTED] wrote:
>>
>>>Steve Holden wrote:
>>>
>>>
Why should you want to associate a MAC address with a socket? Each
interface has an IP address, and it's that you should be using.
>>>
>>>Say for example I want to find out the MAC if a particular interface in
>>>python.
>>>
>>
>>When you are asked "why would you want to do something" it isn't
>>normally considered sufficient to reply "suppose I want to do
>>something". I'm still trying to find out what use case (apart from
>>curiosity) drives this need to know.
>>
> 
> That is nothing but curiosity of why there is no such thing. I didn't
> start a thread with "what the [EMAIL PROTECTED] hell that I cannot get MAC 
> address
> through the socket module".
> 
> And I answer things the way I want to, if it does fit your expected
> answer, there is nothing I can do. I am not here to convince you.
> 
Temper, temper.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: How to get the local mac address?

2005-12-15 Thread bonono

Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
> > Steve Holden wrote:
> >
> >>[EMAIL PROTECTED] wrote:
> >>
> >>>Steve Holden wrote:
> >>>
> >>>
> Why should you want to associate a MAC address with a socket? Each
> interface has an IP address, and it's that you should be using.
> >>>
> >>>Say for example I want to find out the MAC if a particular interface in
> >>>python.
> >>>
> >>
> >>When you are asked "why would you want to do something" it isn't
> >>normally considered sufficient to reply "suppose I want to do
> >>something". I'm still trying to find out what use case (apart from
> >>curiosity) drives this need to know.
> >>
> >
> > That is nothing but curiosity of why there is no such thing. I didn't
> > start a thread with "what the [EMAIL PROTECTED] hell that I cannot get MAC 
> > address
> > through the socket module".
> >
> > And I answer things the way I want to, if it does fit your expected
> > answer, there is nothing I can do. I am not here to convince you.
> > 
> Temper, temper.
> 
you can read my temper from what I write ?

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


Re: Developing a network protocol with Python

2005-12-15 Thread Laszlo Zsolt Nagy
Paul Rubin wrote:

>Laszlo Zsolt Nagy <[EMAIL PROTECTED]> writes:
>  
>
>>But how can I transfer pure python objects otherwise? Pyro also uses
>>Pickle and it also transfers bytecode.
>>
>>
>Pyro in the past used pickle in an insecure way.  I'd heard it had
>been fixed and I didn't realize it still uses pickle.
>  
>
On the features page, you can read this:

"Mobile objects. Clients and servers can pass objects around - even when 
the server has never known them before. Pyro will then automatically 
transfer the needed Python bytecode."

I believe that using cPickle and transferring data (but not the code) is 
still more secure than transferring bytecode. :-)

   Les

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


Re: Get rid of recursive call __getattr__

2005-12-15 Thread bruno at modulix
Steve Holden wrote:
> Peter Otten wrote:
> 
>> Pelmen wrote:
>>
>>
>> class Test:
>>>
>>>
>>>  def __getattr__(self, attr):
>>>print attr
>>>
>>>  def foo(x):
>>>print x
>>>
>>>
>> t = Test()
>> print t
>>>
>>>
>>> __str__
>>>
>>> Traceback (most recent call last):
>>>  File "", line 1, in -toplevel-
>>>print t
>>> TypeError: 'NoneType' object is not callable
>>>
>>> what i have to do? define __str__ explicitly?
>>
>>
>>
>> By seemingly not returning anything your __getattr__() method actually
>> returns None. Instead you should raise an AttributeError when your
>> __getattr__() encounters the name of an attribute it doesn't handle.
>> Let's assume Test.__getattr__() should implement an attribute 'alpha' and
>> nothing else:
>>
>>
> class Test:
>>
>>
>> ... def __getattr__(self, name):
>> ... print "looking up", name
>> ... if name == "alpha":
>> ... return 42
>> ... print "lookup failed for", name
>> ... raise AttributeError
> 
> 
> or, rather better IMHO,
> 
>   raise AttributeError("lookup failed for %s" % name)

or still better in IMNSHO:
  raise AttributeError("%s object has no attribute %s" %
   \ (self.__class__.__name__,
  name))

(which is the 'standard' AttributeError message)



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: efficient 'tail' implementation

2005-12-15 Thread Marius Gedminas
Magnus Lycka wrote:
> To read the last x bytes of a file, you could do:
>
>  >>> import os
>  >>> x = 2000 # or whatever...
>  >>> f=open('my_big_file')
>  >>> l=os.fstat(f.fileno()).st_size
>  >>> f.seek(l-x)
>  >>> f.read()

You don't need fstat/st_size, you can ask seek to move to an offset
relative to the end of the file:

>>> x = 2000
>>> f = open('my_big_file')
>>> f.seek(-x, 2)
>>> f.read()

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


Re: Python packages on OS X vs Windows

2005-12-15 Thread Roel Schroeven
BartlebyScrivener wrote:
> I'm curious about this part of the post. Any fluent Pythoners actually
> happy using Windows XP and, if so, do they use ipython as a kind of
> bash shell substitute? Other alternatives to compensate for the widely
> derided command line in windows?

I often use cygwin's bash (with rxvt). I haven't yet tried ipython.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: threading IOError

2005-12-15 Thread Gabriel Genellina
Andrew MacIntyre ha escrito:

> Gabriel Genellina wrote:
> >   File "C:\Apps\Python\Lib\threading.py", line 218, in wait
> > remaining = endtime - _time()
> > IOError: [Errno 2] No such file or directory
> >
> > The error appears to be inside the time module, and I can't explain the
> > IOError there.
> >
> > Maybe this crash is related too: sometimes, the full program crashes
> > with an Invalid Page Fault with the following info:
> Quite some time ago I saw the same sort of issue - inexplicable
> exceptions from apparently benign code.
>
> Tim Peters prognosticated that there was a bug in an extension module,
> and indeed that proved to be the case (a 3rd party extension, which
> fortunately I had source for and was able to build).
>
> I doubt that any of Python's standard extension modules will be involved
> (as they are generally mature and widely used and tested) but you should
> look at the source for any others looking for unhandled error returns.
> Typically, errno is set but the failure return from the routine setting
> errno is ignored or not properly handled.
>
> What then happens is the next time an exception gets propagated through
> Python's internals, the errno value gets picked up and is used to
> identify the exception (incorrectly).
>
> The invalid page fault may well be because a garbage pointer is handed
> to a routine, possibly as a consequence of the mishandled error return.

Oh, thanks, at least this gives me a starting point to investigate. But
I can´t discard the standard modules; this is an (almost) clean python
install. The download rate has became extremely low and maybe all of
this is related to the recent upgrade to Python 2.4.2... (Maybe
Win98+many threads+sockets is not a well tested combination)

Thanks,
Gabriel Genellina
Softlab SRL

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


Python on GP2X (Linux Based Handheld Console)

2005-12-15 Thread Michael Sparks
Hi,


I hadn't seen any announcements regarding this, but there's a little
device recently released called a GP2X which is a small dual CPU
(2x200Mhz) device which runs Linux.

Anyway, I thought there might be someone in here interested to hear
that python AND pygame have both been ported to it already (not by
me). I've also ported some of our code to it (the bouncing cats demo
I've shown at a couple of python conferences), and found it really nice
to work with so far. The cats bounce at an acceptable (to me)
framerate :-)

Link for python:
http://gp2x-emulation.dcemu.co.uk/python.shtml

Link for device:
http://www.gp2x.com/product/product.asp

Just thought I'd post about this, since I thought someone might find it
useful :)


Michael.
-- 
[EMAIL PROTECTED], http://kamaelia.sourceforge.net/
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This message contains personal views which are not the views of the
BBC unless specifically stated.

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


Re: Windows Services

2005-12-15 Thread Mondal
Hi,

Thanks to Peter, now I know how to control an *existing* Windows
service and how to run a *python script* as a Windows service. Although
these were really useful, my point was different.

I have developed a script that monitors a specified folder for changes
in the files or folders within it. I converted that script to a stand
alone exe using py2exe. ***Now I would like to run that exe as a
Windows service***.

I also intend to create an exe that will retrieve any information
stored by the file monitor mentioned above.

Please tell me how do I go about it.

Although I am a beginner in Python and Windows Services (Daemon), I am
a moderately experienced programmer.

-Regards

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


Re: How to get the local mac address?

2005-12-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Steve Holden wrote:
> 
>>[EMAIL PROTECTED] wrote:
>>
>>>Steve Holden wrote:
>>>
>>>
[EMAIL PROTECTED] wrote:


>Steve Holden wrote:
>
>
>
>>Why should you want to associate a MAC address with a socket? Each
>>interface has an IP address, and it's that you should be using.
>
>Say for example I want to find out the MAC if a particular interface in
>python.
>

When you are asked "why would you want to do something" it isn't
normally considered sufficient to reply "suppose I want to do
something". I'm still trying to find out what use case (apart from
curiosity) drives this need to know.

>>>
>>>That is nothing but curiosity of why there is no such thing. I didn't
>>>start a thread with "what the [EMAIL PROTECTED] hell that I cannot get MAC 
>>>address
>>>through the socket module".
>>>
>>>And I answer things the way I want to, if it does fit your expected
>>>answer, there is nothing I can do. I am not here to convince you.
>>>
>>
>>Temper, temper.
>>
> 
> you can read my temper from what I write ?
> 
Nope, but I can make inferences, whose correctness you can choose to lie 
or tell the truth about. I was merely trying to make the point that your 
response failed to further anybody's understanding of anything. I'm not 
really bothered *why* you do what you do.

I asked "Why should you want to associate a MAC address with a socket?" 
and you replied "Say for example I want to find out the MAC if a 
particular interface in python". Fine. But if you don't want to engage 
in a dialogue, why bother posting at all?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: How to get the local mac address?

2005-12-15 Thread bonono

Steve Holden wrote:
> Nope, but I can make inferences, whose correctness you can choose to lie
> or tell the truth about. I was merely trying to make the point that your
> response failed to further anybody's understanding of anything. I'm not
> really bothered *why* you do what you do.
That is nice try. I said I am not, you can fit it as "I am lying". As
for failed or not failed, I don't know what anybody want to get out of
it. I just curious why there is no such function in the socket model,
when I saw a "OS dependent" implementation of getting MAC. Nothing
more. And your answer that there is not sufficient need for putting it
in the standard libary(for the maintainance work needed), answered my
puzzle.

>
> I asked "Why should you want to associate a MAC address with a socket?"
> and you replied "Say for example I want to find out the MAC if a
> particular interface in python". Fine. But if you don't want to engage
> in a dialogue, why bother posting at all?
Huh ? You ask why, I come up with an example. I said it all started
with curiosity, not out of need. I don't see why it is not a dialogue.
You think that it is not because it doesn't meet your expectation
answer(thus your "you are supposed" response), that I can do nothing as
that is your right or thought.

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


Re: Windows Services

2005-12-15 Thread Frank Millman

Mondal wrote:
> Hi,
>
> Thanks to Peter, now I know how to control an *existing* Windows
> service and how to run a *python script* as a Windows service. Although
> these were really useful, my point was different.
>
> I have developed a script that monitors a specified folder for changes
> in the files or folders within it. I converted that script to a stand
> alone exe using py2exe. ***Now I would like to run that exe as a
> Windows service***.
>
> I also intend to create an exe that will retrieve any information
> stored by the file monitor mentioned above.
>
> Please tell me how do I go about it.
>
> Although I am a beginner in Python and Windows Services (Daemon), I am
> a moderately experienced programmer.
>
> -Regards

Here is an alternative solution.

I have a simple socket server program, which I wanted to run as a
service on Linux and Windows.

On Linux it was easy - start it from rc.local with a trailing &.

On Windows, I was given advice on how to use pywin32 to set up the
program as a Windows service, but it felt like overkill. Then someone
suggested 'srvany', a utility that allows you to run any program as a
service. It is part of the NT Resource Kit. I downloaded it and it
works fine for me. Google has plenty of references.

Frank Millman

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


Re: How to get the local mac address?

2005-12-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Steve Holden wrote:
> 
>>Nope, but I can make inferences, whose correctness you can choose to lie
>>or tell the truth about. I was merely trying to make the point that your
>>response failed to further anybody's understanding of anything. I'm not
>>really bothered *why* you do what you do.
> 
> That is nice try. I said I am not, you can fit it as "I am lying". As
> for failed or not failed, I don't know what anybody want to get out of
> it. I just curious why there is no such function in the socket model,
> when I saw a "OS dependent" implementation of getting MAC. Nothing
> more. And your answer that there is not sufficient need for putting it
> in the standard libary(for the maintainance work needed), answered my
> puzzle.
> 
> 
>>I asked "Why should you want to associate a MAC address with a socket?"
>>and you replied "Say for example I want to find out the MAC if a
>>particular interface in python". Fine. But if you don't want to engage
>>in a dialogue, why bother posting at all?
> 
> Huh ? You ask why, I come up with an example. I said it all started
> with curiosity, not out of need. I don't see why it is not a dialogue.
> You think that it is not because it doesn't meet your expectation
> answer(thus your "you are supposed" response), that I can do nothing as
> that is your right or thought.
> 
I'm probably just not reading your responses carefully enough.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: OO in Python? ^^

2005-12-15 Thread Ben Sizer

Antoon Pardon wrote:
> Op 2005-12-14, Christopher Subich schreef
> > Doesn't work; duck typing is emphatically not subclass-typing.
>
> I don't see how that is relevant.
>
> > For this
> > system to still work and be as general as Python is now (without having
> > to make all variables 'object's),
>
> But the way Guido wants python to evolve would make all variables
> objects. This is what PEP 3000 states.
>
>   Support only new-style classes; classic classes will be gone.
>
> As far as I understand this would imply that all classes are subclasses
> of object and thus that isinstance(var, object) would be true for all 
> variables.

But that's still useless for your purposes. Everything will be derived
from object but it doesn't mean everything file-like will be derived
from file or everything dictionary-like will be derived from
dictionary. Duck-typing means that code told to 'expect' certain types
will break unnecessarily when a different-yet-equivalent type is later
passed to it.

-- 
Ben Sizer

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


Re: Windows Services

2005-12-15 Thread Steve Holden
Mondal wrote:
> Hi,
> 
> Thanks to Peter, now I know how to control an *existing* Windows
> service and how to run a *python script* as a Windows service. Although
> these were really useful, my point was different.
> 
> I have developed a script that monitors a specified folder for changes
> in the files or folders within it. I converted that script to a stand
> alone exe using py2exe. ***Now I would like to run that exe as a
> Windows service***.
> 
> I also intend to create an exe that will retrieve any information
> stored by the file monitor mentioned above.
> 
> Please tell me how do I go about it.
> 
> Although I am a beginner in Python and Windows Services (Daemon), I am
> a moderately experienced programmer.
> 
I'm afraid that you can't just run any old executable as a Windows service.

If something is going to be run as a service then it has to use the 
Windows service API so it responds correctly to being started and 
stopped, for example, and "pumps" the event queue from time to time.

regards
  Steve

-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: How to get the local mac address?

2005-12-15 Thread bonono

Steve Holden wrote:
> I'm probably just not reading your responses carefully enough.
That is fine, misunderstanding happens all the time. And why I am
curious that there is no such thing in Python, it is because of this :

http://search.cpan.org/~lds/IO-Interface-0.98/Interface.pm

I am learning python and from time to time, I would come up with
ideas(yup, nothing but ideas as an excercise) of how to implement
certain thing in python, most of them have no usage value. The OP just
prompt me to the idea of "what if I want to implement something like
ifconfig in python".

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


PyOpengl text rendering with autocad font

2005-12-15 Thread Marco
I must use text in Opengl, Python
This text is for architecture design then I need to use AutoCad fonts
(extension .shx).
I have two troubles:

I don't find a guide, a good program, something for use any kind of
fonts in PyOpengl. The nehe tutorial has some bugs in translation to
Python.
I need to scale rotate the text.

I don't know anything about handling fonts, I must use this .shx but I
don't know. In which way can I take this file and put them in my
programs?

In two afternoons in Google I don't find anything.

If somebody wants to help me :-)
Thanks.
Marco Bonifazi



http://www.marcobonifazi.com

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-15 Thread Ben Sizer
Mike Meyer wrote:
> [Not sure if this attribution is correct.]
> > Alex Martelli wrote:
> > Because of course if other languages have 1 or two frameworks, python
> > needs a dozen.
>
> People keep talking about Python's wealth of web frameworks as if it
> were a bad thing. I just don't see it. Just like I like to have more
> than 1 or 2 languages available for programming, I like to have more
> than 1 or 2 web frameworks available for building web sites. That I
> can get the flexibility I want in this area *without* having to
> abandon Python is a plus for Python.

Flexibility is good, but personally I think the problem is that instead
of useful variety, we have redundant overlap. How many different
templating systems, sql<-->object mappings, and URL dispatch schemes do
we need? And what exactly is the difference between them all, except
for slightly different syntax?

One major benefit of reducing the number of such frameworks is that a
larger community would form around each product, meaning better
documentation and examples. Also, it would be easier to know which one
to recommend for a given task, when there are fewer available and they
are more distinct. In particular, it would be helpful to have something
simple in the standard library, as currently there's a large barrier to
entry for the Python newbie who wants to get into web programming,
compared to ASP or PHP, or even Java servlets.

-- 
Ben Sizer

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


Re: Windows Services

2005-12-15 Thread bonono

Steve Holden wrote:
> Mondal wrote:
> > Hi,
> >
> > Thanks to Peter, now I know how to control an *existing* Windows
> > service and how to run a *python script* as a Windows service. Although
> > these were really useful, my point was different.
> >
> > I have developed a script that monitors a specified folder for changes
> > in the files or folders within it. I converted that script to a stand
> > alone exe using py2exe. ***Now I would like to run that exe as a
> > Windows service***.
> >
> > I also intend to create an exe that will retrieve any information
> > stored by the file monitor mentioned above.
> >
> > Please tell me how do I go about it.
> >
> > Although I am a beginner in Python and Windows Services (Daemon), I am
> > a moderately experienced programmer.
> >
> I'm afraid that you can't just run any old executable as a Windows service.
>
> If something is going to be run as a service then it has to use the
> Windows service API so it responds correctly to being started and
> stopped, for example, and "pumps" the event queue from time to time.
>
I think there is some wrapper programs that can wrap around any console
window programs as service, either from cygwin or may be stand alone
too. Of course, the wrapped program would be stopped through some
"kill" signal rather than proper start/stop API calls.

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


Re: Recommend an E-book Meeting the Following Criteria (Newbie, Long)

2005-12-15 Thread andypurshottam
I reccomend David Mertz's text:
http://gnosis.cx/TPiP/
Despite name its more that just text processing, he uses
"modern" (ie, 20 - 30 years old) style of programming in examples,
often using  library packages, especially parsing tools. Online version
is free, but you can pay him buy buying the p-book. Has short examples
that can be tried out from command line.

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


Re: How to get the local mac address?

2005-12-15 Thread Jorge Godoy
Steve Holden <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
> > Steve Holden wrote:
> >
> >>Why should you want to associate a MAC address with a socket? Each
> >>interface has an IP address, and it's that you should be using.
> > Say for example I want to find out the MAC if a particular interface in
> > python.
> >
> When you are asked "why would you want to do something" it isn't normally
> considered sufficient to reply "suppose I want to do something". I'm still
> trying to find out what use case (apart from curiosity) drives this need to
> know.

One thing that I've seen more than once is restricting the use of the software
to one machine.  There you can use the MAC address as an item of assurance
that you're on the authorized machine.

Of course, MAC addresses can be cloned, changed, etc.  But this is one use
case for knowing the MAC address and not using it with networking.

-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Why and how "there is only one way to do something"?

2005-12-15 Thread Tolga

As far as I know, Perl is known as "there are many ways to do
something" and Python is known as "there is only one way". Could you
please explain this? How is this possible and is it *really* a good
concept?

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


Re: Python on GP2X (Linux Based Handheld Console)

2005-12-15 Thread Peter Hansen
Michael Sparks wrote:
> I hadn't seen any announcements regarding this, but there's a little
> device recently released called a GP2X which is a small dual CPU
> (2x200Mhz) device which runs Linux.
> 
> Anyway, I thought there might be someone in here interested to hear
> that python AND pygame have both been ported to it already (not by
> me). I've also ported some of our code to it (the bouncing cats demo
> I've shown at a couple of python conferences), and found it really nice
> to work with so far. The cats bounce at an acceptable (to me)
> framerate :-)

But is the rate at which they bounce truly acceptable *to them*?

;-)

-Peter

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


Re: OO in Python? ^^

2005-12-15 Thread Antoon Pardon
Op 2005-12-15, Ben Sizer schreef <[EMAIL PROTECTED]>:
>
> Antoon Pardon wrote:
>> Op 2005-12-14, Christopher Subich schreef
>> > Doesn't work; duck typing is emphatically not subclass-typing.
>>
>> I don't see how that is relevant.
>>
>> > For this
>> > system to still work and be as general as Python is now (without having
>> > to make all variables 'object's),
>>
>> But the way Guido wants python to evolve would make all variables
>> objects. This is what PEP 3000 states.
>>
>>   Support only new-style classes; classic classes will be gone.
>>
>> As far as I understand this would imply that all classes are subclasses
>> of object and thus that isinstance(var, object) would be true for all 
>> variables.
>
> But that's still useless for your purposes.

What purpose would that be? Maybe you can tell me, so I can
know too.

> Everything will be derived from object but it doesn't mean
> everything file-like will be derived from file or everything
> dictionary-like will be derived from dictionary.

So? I answered a question. That my answer is not usefull for
a specific purpose is very well prosible but is AFAIC irrelevant.
I didn't notice a specific purpose behind the question
and didn't answer the question with a specific purpose in mind.

> Duck-typing means that code told to 'expect' certain types
> will break unnecessarily when a different-yet-equivalent type is later
> passed to it.

I think you mixed things up.

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread jmdeschamps

Tolga wrote:
> As far as I know, Perl is known as "there are many ways to do
> something" and Python is known as "there is only one way". Could you
> please explain this? How is this possible and is it *really* a good
> concept?

if you 'import this', you get a bit of Python Zen... from which I have
taken this line:
*...
There should be one-- and preferably only one --obvious way to do it.
...*
If this is what you are referring to then here is an explanation.

So there is not 'only one way', but rather there should be a way to do
something that is obvious, re easy to find, evident, 'given'...
The quality(ies) looked for here that makes this *really* good is
1- that you don't spend an inordinate amount of time looking for it -
you just go along and use it so your mind can be focussed of what you
need to achieve instead of how you can achieve it.
2- If it's 'obvious', then chances are others will see it and use it
also, so that their code is more understandable by others. For anyone
who has taken care of code of others this can be *really really good*
;-)

Jean-Marc

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

[EMAIL PROTECTED] wrote:
> Tolga wrote:
> > As far as I know, Perl is known as "there are many ways to do
> > something" and Python is known as "there is only one way". Could you
> > please explain this? How is this possible and is it *really* a good
> > concept?
>
> if you 'import this', you get a bit of Python Zen... from which I have
> taken this line:
> *...
> There should be one-- and preferably only one --obvious way to do it.
> ...*
> If this is what you are referring to then here is an explanation.
>
> So there is not 'only one way', but rather there should be a way to do
> something that is obvious, re easy to find, evident, 'given'...
> The quality(ies) looked for here that makes this *really* good is
> 1- that you don't spend an inordinate amount of time looking for it -
> you just go along and use it so your mind can be focussed of what you
> need to achieve instead of how you can achieve it.
> 2- If it's 'obvious', then chances are others will see it and use it
> also, so that their code is more understandable by others. For anyone
> who has taken care of code of others this can be *really really good*
> ;-)
What I don't quite understand is, if it is "obvious", whether there is
a Zen, people would still code it that way(unless of course they want
to hide it from others or make it difficult to understand on purpose),
there won't be any argument of "which one is the obvious way".
And if there is an argument(or disagreement), which one is the obvious
?

I think it is more like there is a preferred way, by the language
creator and those share his view.

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Steve Holden
Tolga wrote:
> As far as I know, Perl is known as "there are many ways to do
> something" and Python is known as "there is only one way". Could you
> please explain this? How is this possible and is it *really* a good
> concept?
> 
Perl's credo is actually "There's more than one way to do it", often 
abbreviated to TMTOWTDI.

(Part of) Python's credo (which you can read in context by typing

 import this

at an interactive command prompt) is "There should be one (and 
preferably only one) way to do it".

Clearly as Python is improved (well, develops, anyway :-) new ways to 
perform old tasks will become possible. So the obvious way to iterate 
over the lines of a text file *used* to be

 while 1:
 line = f.readline()
 if not f:
 break
 # process the line

whereas now it's

 for line in f:
 # process the line

As with all credos this should be approached with a large-ish grain of 
salt and a pragmatic air. As with all Zen knowledge it's important to 
avoid taking the Zen too literally, otherwise it may be necessary to hit 
you on the side of the head with a stick to get you moving back towards 
enlightenment <0.8 wink>.

We try not to be rude to perlmongers on this group. After all, they have 
come much closer to world domination than we have so far, and they can't 
help their peculiar penchant for coding in what looks like line noise. 
[As you can see it's OK to poke a bit of good-humoured fun at them from 
time to time].

Overall Python emphasises two things, readability and comprehensibility, 
as primary values. Readability, comprehensibility and a welcoming 
approach to newcomers ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Chris Mellon
On 15 Dec 2005 04:32:39 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> [EMAIL PROTECTED] wrote:
> > Tolga wrote:
> > > As far as I know, Perl is known as "there are many ways to do
> > > something" and Python is known as "there is only one way". Could you
> > > please explain this? How is this possible and is it *really* a good
> > > concept?
> >
> > if you 'import this', you get a bit of Python Zen... from which I have
> > taken this line:
> > *...
> > There should be one-- and preferably only one --obvious way to do it.
> > ...*
> > If this is what you are referring to then here is an explanation.
> >
> > So there is not 'only one way', but rather there should be a way to do
> > something that is obvious, re easy to find, evident, 'given'...
> > The quality(ies) looked for here that makes this *really* good is
> > 1- that you don't spend an inordinate amount of time looking for it -
> > you just go along and use it so your mind can be focussed of what you
> > need to achieve instead of how you can achieve it.
> > 2- If it's 'obvious', then chances are others will see it and use it
> > also, so that their code is more understandable by others. For anyone
> > who has taken care of code of others this can be *really really good*
> > ;-)
> What I don't quite understand is, if it is "obvious", whether there is
> a Zen, people would still code it that way(unless of course they want
> to hide it from others or make it difficult to understand on purpose),
> there won't be any argument of "which one is the obvious way".
> And if there is an argument(or disagreement), which one is the obvious
> ?
>

Many programmers, being clever people, like to do clever things in
order to prove how clever they are. Python programmers are not immune
to this but Perl programmers absolutely revel in it.

As you may be able to tell, I place a very large value on readability
and obviousness and I despise cleverness in code and attempt to stamp
it out when I do it (although, of course, it's hard to see when you're
violating your own rules). As an example, if someone posts on this
list asking how to print the lines of a file, they'll probably get a
bunch of answers with the obvious for loop solution, and a couple from
people being clever with list comprehensions. Even the clever list
comprehension people will usually use the for loop in real code.
Asking the same question on a Perl list will result in 30 different
aswers from 20 different people, and all 30 of those will be used in
real code.

When there is one obvious way to do things, it makes for a large
degree of consistency in code. It improves the readability and
maintainability of Python code in general and flattens the learning
curve. When there is *only* one obvious way to do something, it's even
better.

By and large, programmers are smart people who enjoy solving problems.
That means that doing clever, different ways of doing things is like
candy to programmers and a real temptation. I'm no exception - I
started using perl very early in my programming career and I loved
using all the line noise and cute operators in clever ways. It took
time and some effort to drop that portion of ego from my code and
instead take pride in how mundane, straightforward, and obvious I
could make it, rather than how clever and tricky it was.

And thats why I love the "only one way to do it" thing in Python ;)

> I think it is more like there is a preferred way, by the language
> creator and those share his view.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iniciante

2005-12-15 Thread Alvaro Figueiredo
At Thursday 15 December 2005 00:33, tetri wrote:
> alguém recomenda algum material disponível na internet para iniciar
> os estudos em python?
> outra coisa, peço que brasileiros (ou ao menos aqueles que me
> entendem) se identifiquem, assim podemos começar discussões em
> português mesmo, o que acham?

There is a brazilian mail list for python in the site below.
Há uma lista de e-mail brasileira de Python no site abaixo.

http://www.pythonbrasil.com.br/

-- 
Alvaro Figueiredo
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

Chris Mellon wrote:
> On 15 Dec 2005 04:32:39 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > [EMAIL PROTECTED] wrote:
> > > Tolga wrote:
> > > > As far as I know, Perl is known as "there are many ways to do
> > > > something" and Python is known as "there is only one way". Could you
> > > > please explain this? How is this possible and is it *really* a good
> > > > concept?
> > >
> > > if you 'import this', you get a bit of Python Zen... from which I have
> > > taken this line:
> > > *...
> > > There should be one-- and preferably only one --obvious way to do it.
> > > ...*
> > > If this is what you are referring to then here is an explanation.
> > >
> > > So there is not 'only one way', but rather there should be a way to do
> > > something that is obvious, re easy to find, evident, 'given'...
> > > The quality(ies) looked for here that makes this *really* good is
> > > 1- that you don't spend an inordinate amount of time looking for it -
> > > you just go along and use it so your mind can be focussed of what you
> > > need to achieve instead of how you can achieve it.
> > > 2- If it's 'obvious', then chances are others will see it and use it
> > > also, so that their code is more understandable by others. For anyone
> > > who has taken care of code of others this can be *really really good*
> > > ;-)
> > What I don't quite understand is, if it is "obvious", whether there is
> > a Zen, people would still code it that way(unless of course they want
> > to hide it from others or make it difficult to understand on purpose),
> > there won't be any argument of "which one is the obvious way".
> > And if there is an argument(or disagreement), which one is the obvious
> > ?
> >
>
> Many programmers, being clever people, like to do clever things in
> order to prove how clever they are. Python programmers are not immune
> to this but Perl programmers absolutely revel in it.
>
> As you may be able to tell, I place a very large value on readability
> and obviousness and I despise cleverness in code and attempt to stamp
> it out when I do it (although, of course, it's hard to see when you're
> violating your own rules). As an example, if someone posts on this
> list asking how to print the lines of a file, they'll probably get a
> bunch of answers with the obvious for loop solution, and a couple from
> people being clever with list comprehensions. Even the clever list
> comprehension people will usually use the for loop in real code.
> Asking the same question on a Perl list will result in 30 different
> aswers from 20 different people, and all 30 of those will be used in
> real code.
>
> When there is one obvious way to do things, it makes for a large
> degree of consistency in code. It improves the readability and
> maintainability of Python code in general and flattens the learning
> curve. When there is *only* one obvious way to do something, it's even
> better.
>
> By and large, programmers are smart people who enjoy solving problems.
> That means that doing clever, different ways of doing things is like
> candy to programmers and a real temptation. I'm no exception - I
> started using perl very early in my programming career and I loved
> using all the line noise and cute operators in clever ways. It took
> time and some effort to drop that portion of ego from my code and
> instead take pride in how mundane, straightforward, and obvious I
> could make it, rather than how clever and tricky it was.
>
> And thats why I love the "only one way to do it" thing in Python ;)
>
It is perfectly ok to define coding policy within an organisation, for
a project that have more than one developer and things like that. But
if the language allows more than one way to do it, people would try if
that is what they want and they can.

I would say that if "only one way to do it" is the intend, make it into
the language and any other way is simply error. Say if ternary operator
is not the "preferred way", don't have it in the language. If someone
find a way to work around it, change that part of the language to break
their code.

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


Re: Self-awareness of imported modules? Do they know where they live?

2005-12-15 Thread Simon Brunning
The only self aware Python scripts that I'm aware are the timbot and
the effbot. Their sources are available from the PSU website at
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO in Python? ^^

2005-12-15 Thread Ben Sizer

Antoon Pardon wrote:
> Op 2005-12-15, Ben Sizer schreef <[EMAIL PROTECTED]>:

> So? I answered a question. That my answer is not usefull for
> a specific purpose is very well prosible but is AFAIC irrelevant.

The point being made was that your declarations such as these:

  int: a
  object: b

would break the original idea (a module containing a sum() function
that can take any object that has an addition operator). Inheritance
isn't good enough in this situation. I apologise if that isn't what you
were answering, but that seems to have been the thread context.

-- 
Ben Sizer

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Chris Mellon
On 15 Dec 2005 05:08:02 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Chris Mellon wrote:
> > On 15 Dec 2005 04:32:39 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > >
> > > [EMAIL PROTECTED] wrote:
> > > > Tolga wrote:
> > > > > As far as I know, Perl is known as "there are many ways to do
> > > > > something" and Python is known as "there is only one way". Could you
> > > > > please explain this? How is this possible and is it *really* a good
> > > > > concept?
> > > >
> > > > if you 'import this', you get a bit of Python Zen... from which I have
> > > > taken this line:
> > > > *...
> > > > There should be one-- and preferably only one --obvious way to do it.
> > > > ...*
> > > > If this is what you are referring to then here is an explanation.
> > > >
> > > > So there is not 'only one way', but rather there should be a way to do
> > > > something that is obvious, re easy to find, evident, 'given'...
> > > > The quality(ies) looked for here that makes this *really* good is
> > > > 1- that you don't spend an inordinate amount of time looking for it -
> > > > you just go along and use it so your mind can be focussed of what you
> > > > need to achieve instead of how you can achieve it.
> > > > 2- If it's 'obvious', then chances are others will see it and use it
> > > > also, so that their code is more understandable by others. For anyone
> > > > who has taken care of code of others this can be *really really good*
> > > > ;-)
> > > What I don't quite understand is, if it is "obvious", whether there is
> > > a Zen, people would still code it that way(unless of course they want
> > > to hide it from others or make it difficult to understand on purpose),
> > > there won't be any argument of "which one is the obvious way".
> > > And if there is an argument(or disagreement), which one is the obvious
> > > ?
> > >
> >
> > Many programmers, being clever people, like to do clever things in
> > order to prove how clever they are. Python programmers are not immune
> > to this but Perl programmers absolutely revel in it.
> >
> > As you may be able to tell, I place a very large value on readability
> > and obviousness and I despise cleverness in code and attempt to stamp
> > it out when I do it (although, of course, it's hard to see when you're
> > violating your own rules). As an example, if someone posts on this
> > list asking how to print the lines of a file, they'll probably get a
> > bunch of answers with the obvious for loop solution, and a couple from
> > people being clever with list comprehensions. Even the clever list
> > comprehension people will usually use the for loop in real code.
> > Asking the same question on a Perl list will result in 30 different
> > aswers from 20 different people, and all 30 of those will be used in
> > real code.
> >
> > When there is one obvious way to do things, it makes for a large
> > degree of consistency in code. It improves the readability and
> > maintainability of Python code in general and flattens the learning
> > curve. When there is *only* one obvious way to do something, it's even
> > better.
> >
> > By and large, programmers are smart people who enjoy solving problems.
> > That means that doing clever, different ways of doing things is like
> > candy to programmers and a real temptation. I'm no exception - I
> > started using perl very early in my programming career and I loved
> > using all the line noise and cute operators in clever ways. It took
> > time and some effort to drop that portion of ego from my code and
> > instead take pride in how mundane, straightforward, and obvious I
> > could make it, rather than how clever and tricky it was.
> >
> > And thats why I love the "only one way to do it" thing in Python ;)
> >
> It is perfectly ok to define coding policy within an organisation, for
> a project that have more than one developer and things like that. But
> if the language allows more than one way to do it, people would try if
> that is what they want and they can.

You can never stop people from being clever. You can only encourage
them to improve themselves. It's like when a teenager finally realizes
that exactly how many studs he has on his jacket really isn't that
important. (Am I dating myself? Do teenagers still put studs on their
jackets?)

>
> I would say that if "only one way to do it" is the intend, make it into
> the language and any other way is simply error.

These are called declarative languages and people hate them because
they aren't flexible or extensible. There is a big, big difference
between "only one way to do something, by fiat" and "only one obvious
way to do something".

>Say if ternary operator
>is not the "preferred way", don't have it in the language. If someone
> find a way to work around it, change that part of the language to break
> their code.

My understanding of the PEP involved is that the ternary operator is
coming into Python not because of it's merits, but because of the
overly-clever and often 

Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
[...]
> It is perfectly ok to define coding policy within an organisation, for
> a project that have more than one developer and things like that. But
> if the language allows more than one way to do it, people would try if
> that is what they want and they can.
> 
> I would say that if "only one way to do it" is the intend, make it into
> the language and any other way is simply error. Say if ternary operator
> is not the "preferred way", don't have it in the language. If someone
> find a way to work around it, change that part of the language to break
> their code.
> 
This would have the unfortunate side effect of only allowing changes to 
Python that allowed users to do things which are currently impossible.

Since Python is Turing-complete, this would effectively inhibit all 
further changes to the language.

Would you, say, remove "for" loops because they could be written as 
"while" loops. Don't forget the word "obvious" that appears in that 
catchphrase ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Terry Hancock
On 15 Dec 2005 05:08:02 -0800
[EMAIL PROTECTED] wrote:
> I would say that if "only one way to do it" is the intend,
> make it into the language and any other way is simply
> error. Say if ternary operator is not the "preferred way",
> don't have it in the language. If someone find a way to
> work around it, change that part of the language to break
> their code.

But that is precisely what it does mean -- Python's language
design tries to be "reasonably minimal": there's usually one
fairly easy way to do a task. Unintentionally, there may
well be a half-dozen really hard ways to do it. The point of
telling this to the potential coder is to suggest that "if
it's hard, you're probably doing it the wrong way" and nudge
them into looking at how the language designers have
intended those problems to be solved.

But of course, this is simply a reaction to the Perl motto:
Having a half-dozen more or less equally difficult, equally
documented methods, with no expressed preference, means that
you will find all half-dozen in the wild, which means in
turn that reading and understanding code is six-times harder
to do. Since readability is the primary use of source code,
this translates to the language being pretty close
to six-times harder to use overall.

The problem that has happened with Python is that as the
language is improved, the old "best way" gets replaced with
a new "best way" (hopefully easier).  The Python development
team's response to this problem is to specifically
deprecate the old way, and encourage users to adopt the new
way.  Generally, the old way does still work so that code
isn't needlessly broken, though there have been exceptions
(such as when the scoping rules were changed).

OTOH, no one can possibly anticipate everything you need to
do, and it is always possible that you have important
requirements for doing things a certain way. We assume that
you are mature enough to know the difference between
"breaking the rules accidentally" and "breaking the rules on
purpose".


-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

Chris Mellon wrote:
>You seem very, very interested in portraying anyone who
> wants to encourage good style and readability as a language Nazi. I
> don't appreciate that. You'll notice that I haven't taken the easy way
> out and told you to go away and play with Perl, right?
Noop. My stand is that good style and readability is a subjective
matter, to certain extend. The often quoted example of the ternary
operator demonstate that. I have no problem reading it as "this is the
preferred way in python, because we have done a large usability study
which indicate that", but saying it as "obvious" as if it is truth is
just strange to me and yes I would repeatedly pointing that out. You
can tell me to go away but that won't change anything. For most people,
they are not what you described as "trying to be smart" but because of
their background, truly feel that their way is more intuitive(or
obvious). It is just like there are language on this planet that reads
from right to left horizontally, as well as top to bottom, then right
to left. And you are trying to tell them that English way is the "right
way" or the obvious way.

I can't get your meaning of "language Nazi" so using the idiom of
"don't assume", I cannot comment on that part.

> Any time you want to write something in any way other than the obvious
> way, ask yourself why? Is it more obvious *to you*, which is a good
> reason as long as you're only writing code for yourself? Or is it just
> to be different, or because you think it'll be faster, or just because
> the slickness of it appeals to you?
>
The point is again, "obvious" is not so obvious sometimes. You seem to
be assuming that anyone that use style different from you is
intentionally doing it and that your style would first come to their
mind but they don't use it, for the sake of proving that they are
smart.
I don't know where you get that idea.

For most of the question I see asking here, they are from another
language background and their obvious way is what they are asking for
that they cannot find in python.

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


Dr. Dobb's Python-URL! - weekly Python news and links (Dec 14)

2005-12-15 Thread Cameron Laird

QOTW:  "If I feel the need for languages that enforce my design
decisions, I know where to find them." - Mike Meyer

"There's ... unavoidable complexity involved in managing a software
distribution composed of third party software packages.  At the very
least, you've got the original sources and the copy in the distribution
package, which leads to a synchronization problem." - Jeremy Hylton


Python's big enough and serious enough that "put X in the core"
has more consequences than a naive observer might first realize.
*Not* having things there, or, worse, a flawed standard library,
also have their costs:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e095cc79d1efb99/

Michael P. Soulier observes that, though "Object finalization
and cleanup" happens to be written in Javan, it fully applies
to Pythonia:
http://www.javaworld.com/javaworld/jw-06-1998/jw-06-techniques_p.html

Mike Meyer, Kent Johnson, and others detail how to get object
orientation and Python to team up ("manipulate the class rather
than the attributes") to serve successful application development
(rather than any of the other reverses):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8df795b928a75a5/

There are several ways to "read Excel".  Some of them don't even
require Windows:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8c93f90a2ce6c8fc/

Paul McGuire provides a sermon on portability, Python examples,
learning trajectories, run-time libraries, and more:
http://groups.google.com/group/comp.lang.python/msg/d762399b1687c05f

bonono, Gerald Klix, Nick Craig-Wood, Bengt Richter, Magnus Lycka,
and others provide correct code and anlysis for model "tails".
Tail is paradigmatic; it exemplifies many common requirements:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/41545f457f06e9be/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Among several Python

Re: Newbie question - deleting records from anydbm database

2005-12-15 Thread Dan M
>> Now how can I go about deleting that record when it's too old?
>> 
> (untested)
> 
> try
> 
>  del db[ipAddress]

Yep, that did it. Thanks!

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


Overlapping Regular Expression Matches With findall()

2005-12-15 Thread Mystilleef
Hello,

Is there a simple flag to set to allow overlapping matches
for the findall() regular expression method? In other words,
if a string contains five occurrences of the string pattern
"cat", calling findall on the string returns a list
containing five "cat" strings. Is it possible for findall()
to just return one "cat" string?

Thanks

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

Steve Holden wrote:
> This would have the unfortunate side effect of only allowing changes to
> Python that allowed users to do things which are currently impossible.
>
> Since Python is Turing-complete, this would effectively inhibit all
> further changes to the language.
I don't quote understand the above.

>
> Would you, say, remove "for" loops because they could be written as
> "while" loops. Don't forget the word "obvious" that appears in that
> catchphrase ...
>
If every "for" usage can be done with "while" and that "while" is the
preferred way, why not ? As I said, the problem is that "obvious"
really is subjective in many case. And if it really is obvious, it
really is obvious and I doubt there would be that much disagreement. I
am a left handed and any time I use something that is designed to be
right-handed, I have the same feeling too, luckily there isn't that
much thing in real life.

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


Re: SVG rendering with Python

2005-12-15 Thread Andreas Lobinger
Aloha,

richard wrote:
> Dennis Benzinger wrote:
>>Does anybody know of a SVG rendering library for Python?
> Google "python svg"

... to find what?

Whishing a happy day
LOBI
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

Terry Hancock wrote:
> But that is precisely what it does mean -- Python's language
> design tries to be "reasonably minimal": there's usually one
> fairly easy way to do a task. Unintentionally, there may
> well be a half-dozen really hard ways to do it. The point of
> telling this to the potential coder is to suggest that "if
> it's hard, you're probably doing it the wrong way" and nudge
> them into looking at how the language designers have
> intended those problems to be solved.
Um, that is fine. However, what I usually see is like this :

C-programmer learning python :

Hi, where is condition ? true : false

someone prefer the if/else statement type:

Can't you see that the following is much more readable, stupid(well not
the exact word but tone in such a way like words of messy or elegant
etc.)

if condition:
  true
else:
  false

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


Re: How to get the local mac address?

2005-12-15 Thread Grant Edwards
On 2005-12-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Why should you want to associate a MAC address with a socket? Each
interface has an IP address, and it's that you should be using.
>>>
>>> Say for example I want to find out the MAC if a particular
>>> interface in python.
>>
>> When you are asked "why would you want to do something" it
>> isn't normally considered sufficient to reply "suppose I want
>> to do something". I'm still trying to find out what use case
>> (apart from curiosity) drives this need to know.
>
> That is nothing but curiosity of why there is no such thing. I
> didn't start a thread with "what the [EMAIL PROTECTED] hell that I cannot
> get MAC address through the socket module".
>
> And I answer things the way I want to, if it does fit your
> expected answer, there is nothing I can do. I am not here to
> convince you.

Taking an attitude like that towards one of the most respected
people in the Python community is bound to be rather counter
productive.  

Nobody owes you any answers, so yes, in fact, you _are_ here to
convince people that you deserve their help.

-- 
Grant Edwards   grante Yow!  Didn't I buy a 1951
  at   Packard from you last March
   visi.comin Cairo?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the local mac address?

2005-12-15 Thread Grant Edwards
On 2005-12-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

>>Why should you want to associate a MAC address with a socket? Each
>>interface has an IP address, and it's that you should be using.
>
>Say for example I want to find out the MAC if a particular interface in
>python.
>

When you are asked "why would you want to do something" it isn't
normally considered sufficient to reply "suppose I want to do
something". I'm still trying to find out what use case (apart from
curiosity) drives this need to know.

>>>
>>> That is nothing but curiosity of why there is no such thing. I didn't
>>> start a thread with "what the [EMAIL PROTECTED] hell that I cannot get MAC 
>>> address
>>> through the socket module".
>>>
>>> And I answer things the way I want to, if it does fit your expected
>>> answer, there is nothing I can do. I am not here to convince you.
>>> 
>> Temper, temper.
>
> you can read my temper from what I write ?

If not, then you should be more careful what you write.

-- 
Grant Edwards   grante Yow!  Sign my PETITION.
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-15 Thread gene tani

Ben Sizer wrote:
> Mike Meyer wrote:
> > [Not sure if this attribution is correct.]
> > > Alex Martelli wrote:
> > > Because of course if other languages have 1 or two frameworks, python
> > > needs a dozen.
> >

woops, that attribution is absolutely *wrong*, DH said that, sorry Alex

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


Re: How to get the local mac address?

2005-12-15 Thread bonono

Grant Edwards wrote:
> On 2005-12-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Why should you want to associate a MAC address with a socket? Each
> interface has an IP address, and it's that you should be using.
> >>>
> >>> Say for example I want to find out the MAC if a particular
> >>> interface in python.
> >>
> >> When you are asked "why would you want to do something" it
> >> isn't normally considered sufficient to reply "suppose I want
> >> to do something". I'm still trying to find out what use case
> >> (apart from curiosity) drives this need to know.
> >
> > That is nothing but curiosity of why there is no such thing. I
> > didn't start a thread with "what the [EMAIL PROTECTED] hell that I cannot
> > get MAC address through the socket module".
> >
> > And I answer things the way I want to, if it does fit your
> > expected answer, there is nothing I can do. I am not here to
> > convince you.
>
> Taking an attitude like that towards one of the most respected
> people in the Python community is bound to be rather counter
> productive.
>
> Nobody owes you any answers, so yes, in fact, you _are_ here to
> convince people that you deserve their help.
>
I get my answer anyway, and I don't know who is respected on here and
if I do, it won't change a thing in the way I answer it.

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


Re: How to get the local mac address?

2005-12-15 Thread bonono

Grant Edwards wrote:
> > you can read my temper from what I write ?
>
> If not, then you should be more careful what you write.
> 
such as ?

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


Re: "0 in [True,False]" returns True

2005-12-15 Thread Grant Edwards
On 2005-12-15, Antoon Pardon <[EMAIL PROTECTED]> wrote:

> Or return NaN instead of raising exception for numeric
> functions ?

 Because usually (in my applications anyway) NaN is a perfectly
 valid value and not an "exception" case that needs to be
 handled.
>>>
>>> I don't see the difference. In my application False and True
>>> (or Registered and UnRegistered if you prefer) are perfectly
>>> valid values too.  They are not "exception" cases that need to
>>> be handled.
>>
>> Well, in my case, a given name (or return value) is always
>> bound to a floating point object. I don't test the type of the
>> object and treat it in two different ways depending on what
>> type it is.  It's just a float.
>
> Do you find that difference so important?

Possibly.  In my case, a float is always a float.  You can
always do the same set of operations on it.

> As far as I understand
> the gtk identifiers are always positive integers. So I could
> have coded as follows:
>
>   UnConnected = (-1, -2)
>   Registered, UnRegistered = UnConnected

In your case, there isn't a single set of operations that work
regardles of the value.  You have to _check_ the value in order
to decide what operations are allowed on that value.  I'm not
saying the latter is "evil" but I think the distinction is
important.

>   ...
>
>   if self.cb_src in UnConnected:
>
> Now all values are integers and I no longer treat an object different
> depending on type but on value. However conceptually nothing changed.
> My code branches depending on set membership of this attribute.
>
> Could you explain why it should make a (big) difference between
> these two approaches?

Your examples are still both very different from the NaN
example.  A NaN is a floating point operation that supports all
the same operations as all other floating point operations.  In
your example an integer object of -2 does not support the same
"operations" that a "real" GTK identifier does.  They are two
different types.

-- 
Grant Edwards   grante Yow!  Hey, wait a
  at   minute!! I want a
   visi.comdivorce!!... you're not
   Clint Eastwood!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-15 Thread gene tani

Ben Sizer wrote:
> Mike Meyer wrote:
> > [Not sure if this attribution is correct.]
> > > Alex Martelli wrote:
> > > Because of course if other languages have 1 or two frameworks, python
> > > needs a dozen.
> >
> > People keep talking about Python's wealth of web frameworks as if it
> > were a bad thing. I just don't see it. Just like I like to have more
> > than 1 or 2 languages available for programming, I like to have more
> > than 1 or 2 web frameworks available for building web sites. That I
> > can get the flexibility I want in this area *without* having to
> > abandon Python is a plus for Python.
>
> Flexibility is good, but personally I think the problem is that instead
> of useful variety, we have redundant overlap. How many different
> templating systems, sql<-->object mappings, and URL dispatch schemes do
> we need? And what exactly is the difference between them all, except
> for slightly different syntax?
>
> One major benefit of reducing the number of such frameworks is that a
> larger community would form around each product, meaning better
> documentation and examples. Also, it would be easier to know which one
> to recommend for a given task, when there are fewer available and they
> are more distinct. In particular, it would be helpful to have something
> simple in the standard library, as currently there's a large barrier to
> entry for the Python newbie who wants to get into web programming,
> compared to ASP or PHP, or even Java servlets.
>
> --
> Ben Sizer

as to the actual substance of this thread, i searched and couldn't find
the number of committers for rails, django, zope, subway etc, anybody
know?

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Ben Sizer
Steve Holden wrote:

> Would you, say, remove "for" loops because they could be written as
> "while" loops. Don't forget the word "obvious" that appears in that
> catchphrase ...

Interestingly - and somewhat related to this - the other day I was
looking for a do..while or do..until loop in the Python language
reference, thinking that there must be a statement for it, since
semantically they're distinct from while loops. I had a use case that
could have been slightly simplified by such a construct. The fact that
I didn't find one seemed slightly strange at first, coming from a
C/Pascal background, although it did occur to me that I've used Python
for years now and not noticed this lack before.

-- 
Ben Sizer

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


Re: OO in Python? ^^

2005-12-15 Thread Antoon Pardon
Op 2005-12-15, Ben Sizer schreef <[EMAIL PROTECTED]>:
>
> Antoon Pardon wrote:
>> Op 2005-12-15, Ben Sizer schreef <[EMAIL PROTECTED]>:
>
>> So? I answered a question. That my answer is not usefull for
>> a specific purpose is very well prosible but is AFAIC irrelevant.
>
> The point being made was that your declarations such as these:
>
>   int: a
>   object: b
>
> would break the original idea (a module containing a sum() function
> that can take any object that has an addition operator).

1) a declaration as 

  object: b

Wouldn't break the original idea, since b would be basically a python
object as it is now.

2) Sure a declaration as

  int: a

would break the original idea, but that was just given as an example
of what kind of declarations one might possibly use. You are not obligated
to use declarations that limits you so much.

> Inheritance
> isn't good enough in this situation. I apologise if that isn't what you
> were answering, but that seems to have been the thread context.

No I wasn't answering that. I was just trying to give an idea from
a different angle. People seem to think that one uses static typing
or inheritance typing or duck typing. IMO the possibility of inheritance
typing doesn't have to prevent duck typing.

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Steve Holden
Chris Mellon wrote:
[...]
> (Am I dating myself?  ...)
> 
Do we need to know about your love life here? Are you hermaphroditic? If 
not the relationship will never go anywhere.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Steve Holden wrote:
> 
>>This would have the unfortunate side effect of only allowing changes to
>>Python that allowed users to do things which are currently impossible.
>>
>>Since Python is Turing-complete, this would effectively inhibit all
>>further changes to the language.
> 
> I don't quote understand the above.
> 
It says that Python is already adequately expressive to allow it to 
solve all solvable problems: more briefly, "Python can already do 
everything". Hence there is no need to change the language.

Of course I use this as a /reductio ad absurdum/ to try to show you the 
falsehood of your position. Sadly I fear this will simply result in 
another response which won't move the dialogue forwards.
> 
>>Would you, say, remove "for" loops because they could be written as
>>"while" loops. Don't forget the word "obvious" that appears in that
>>catchphrase ...
>>
> 
> If every "for" usage can be done with "while" and that "while" is the
> preferred way, why not ? As I said, the problem is that "obvious"
> really is subjective in many case. And if it really is obvious, it
> really is obvious and I doubt there would be that much disagreement. I

It seems to me you either don't understand the words "obvious" and 
"preferably".

> am a left handed and any time I use something that is designed to be
> right-handed, I have the same feeling too, luckily there isn't that
> much thing in real life.
> 
I believe I have also suggested that the phrases of the Zen aren't to be 
taken too literally. You seem to distinguish between "obvious" meaning 
"obvious to Steve but not necessarily to me" and "really obvious" 
meaning "obvious to both Steve and me". So where does the subjectivity 
creep in? And are you going to spend the rest of your life arguing 
trivial semantics?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


tkinter: drop-down widget

2005-12-15 Thread Alex Hunsley
Can anyone recommend some code for creating drop-down menus in tkinter?
To be absolutely clear, here's an example of a drop-down:

http://www.google.co.uk/preferences?hl=en
(see the language selection widget)

I've found the odd bit of code here and there, such as:
http://infohost.nmt.edu/tcc/cgi/pre.cgi?file=/u/www/docs/tcc/help/lang/python/mapping/dropdown.py

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread jmdeschamps
Yes, a shared preferred way.
And the same is true of many... Think Haskell, OCaml, Lua, Ruby, Lisp,
Smalltalk, Java, C... They all have qualities of some sort, that appeal
to some of us. Not all the same, nor to all of us. It's really a
question of perspective.

In this Python community, one shared preferred way is obviousness, that
we agree or disagree upon, that we argue or ignore as best suits us. It
is not 'the law', it is a wish. For clarity, for communication, for
exchange and for certainly many more reasons.

As a personal experience, I've often been able to use the language
structures, and functions for that matter, out of thin air, because it
seemed *obvious* in the context. But the Help files remain close-by...

Jean-Marc

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Gerard Flanagan
Tolga wrote:

> As far as I know, Perl is known as "there are many ways to do
> something" and Python is known as "there is only one way". Could you
> please explain this? How is this possible and is it *really* a good
> concept?

Yes it is a good concept because you can concentrate on Strategy rather
than Tactics.

Strategy and Tactics

in warfare, related terms referring, respectively, to large-scale and
small-scale planning to achieve military success. Strategy may be
defined as the general scheme of the conduct of a war, tactics as the
planning of means to achieve strategic objectives. Not all theorists of
war make this a primary distinction. In the Chinese and Japanese
traditions processes and paradoxes are emphasized more than categories
(see Sun Tzu ). Karl von Clausewitz , the Prussian military theorist,
who was influenced by Niccolo Machiavelli , described strategy as the
planning of a whole campaign and tactics as the planning of a single
battle. In Clausewitz's theory all military strategy is part of the
larger political pattern, and all the nation's resources are to be
subordinated to the task of attaining the political objective of the
war; to this concerted effort he gave the name "grand strategy."
Antoine H. Jomini , an influential Swiss military theorist and general,
regarded strategy as the art of moving forces to the field of battle
and tactics as the conduct of forces in battle. Another school views
strategy as a means of bringing the enemy to battle and tactics as the
means of defeating him in battle. Some theorists focus on clear sets of
general principles; some wrote books on principles, formations and
maneuvers; and still others dwell on the importance of spirit or other
intangibles.
taken from http://www.encyclopedia.com/html/s1/strategy.asp


Sun Tzu
The Art of War.stresses the unpredictability of battle, the
importance of deception and surprise, the close relationship between
politics and military policy, and the high costs of war. The futility
of seeking hard and fast rules and the subtle paradoxes of success are
major themes. The best battle, Sun Tzu says, is the battle that is won
without being fought.
from http://www.encyclopedia.com/html/S/SunT1zu.asp


Gerard

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


Re: Python packages on OS X vs Windows

2005-12-15 Thread Kevin Walzer
Kenneth McDonald wrote:
> At the moment I'm doing most of my stuff on a Mac, but I've been
> considering also getting
> a Windows laptop. One of the reasons is that I've found it very
> difficult to get certain
> Python related things running on the Mac; for example, if one wants to
> use the most
> up-to-date Python on the mac, rather than the one installed by Apple,
> things can get
> a bit hairy, and then if one wants to go PyQT/wxPy/etc, it can get even
> worse with
> trying to get all the compiling/linking to work.

I'm really, really puzzled by this statement...

how is building Python 2.4.2 and extensions on OS X "difficult"?

Updating to the latest Python took me an hour, and most of that was
doing other things while the build ran in the background. A bit more
work than using Bob Ippolito's installer of 2.4.1, but hey.

wxPython has a binary installer for Python 2.4.x on OS X. You don't even
need to reinstall it if you update your own build of Python as point
releases (2.4.x) of Python are binary compatible with extensions,
correct me if I am wrong?

Other extensions are pretty simple to build: python setup.py install.
Doesn't seem hard to me. And if you don't want that, use the installers
(Bob Ippolito's again) at http://undefined.org/python/.

I'll grant that PyQt is a pain. It takes a couple of days to build, and
isn't very stable once you get it built. That's why I stopped
maintaining Mac packages for it, because I decided to look at Tkinter as
my main GUI toolkit for Python. But even with that, PyQt isn't hard to
build--just time-consuming. The instructions are very well-presented.

I've found some aspects of working with Python frustrating--specifically
the lack of a really good native IDE (which has been solved with the
release of Komodo for OS X) and in trying to choose a GUI toolkit--but
getting it installed and configured properly is not among the problems
I've encountered.

-- 
Cheers,

Kevin Walzer, PhD
WordTech Software - "Tame the Terminal"
http://www.wordtech-software.com
sw at wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

Steve Holden wrote:
> This would have the unfortunate side effect of only allowing changes to
> Python that allowed users to do things which are currently impossible.
>
> Since Python is Turing-complete, this would effectively inhibit all
> further changes to the language.
I don't quote understand the above.

>
> Would you, say, remove "for" loops because they could be written as
> "while" loops. Don't forget the word "obvious" that appears in that
> catchphrase ...
>
If every "for" usage can be done with "while" and that "while" is the
preferred way, why not ? As I said, the problem is that "obvious"
really is subjective in many case. And if it really is obvious, it
really is obvious and I doubt there would be that much disagreement. I
am a left handed and any time I use something that is designed to be
right-handed, I have the same feeling too, luckily there isn't that
much thing in real life.

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

Steve Holden wrote:
> It says that Python is already adequately expressive to allow it to
> solve all solvable problems: more briefly, "Python can already do
> everything". Hence there is no need to change the language.
>
> Of course I use this as a /reductio ad absurdum/ to try to show you the
> falsehood of your position. Sadly I fear this will simply result in
> another response which won't move the dialogue forwards.
Still don't quite understand what you intend to say.

> >
> >>Would you, say, remove "for" loops because they could be written as
> >>"while" loops. Don't forget the word "obvious" that appears in that
> >>catchphrase ...
> >>
> >
> > If every "for" usage can be done with "while" and that "while" is the
> > preferred way, why not ? As I said, the problem is that "obvious"
> > really is subjective in many case. And if it really is obvious, it
> > really is obvious and I doubt there would be that much disagreement. I
>
> It seems to me you either don't understand the words "obvious" and
> "preferably".
My intepretation of "obvious" is that 99 out of 100 people would
immediately see that "this is the way to do it". I am not sure your
"right meaning" of it.

> I believe I have also suggested that the phrases of the Zen aren't to be
> taken too literally. You seem to distinguish between "obvious" meaning
> "obvious to Steve but not necessarily to me" and "really obvious"
> meaning "obvious to both Steve and me". So where does the subjectivity
> creep in? And are you going to spend the rest of your life arguing
> trivial semantics?
Again, don't quite understand what you what to say.

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Steve Holden
Ben Sizer wrote:
> Steve Holden wrote:
> 
> 
>>Would you, say, remove "for" loops because they could be written as
>>"while" loops. Don't forget the word "obvious" that appears in that
>>catchphrase ...
> 
> 
> Interestingly - and somewhat related to this - the other day I was
> looking for a do..while or do..until loop in the Python language
> reference, thinking that there must be a statement for it, since
> semantically they're distinct from while loops. I had a use case that
> could have been slightly simplified by such a construct. The fact that
> I didn't find one seemed slightly strange at first, coming from a
> C/Pascal background, although it did occur to me that I've used Python
> for years now and not noticed this lack before.
> 
You'll find it's exercised the group frequently from time to time. 
Without wishing to stir the whole thing up again, the essence of the 
problem is the unnatural fit with Python's suite design.

Would you say

 do:
 suite
 while condition

or what? Basically do ... while and do ... until most naturally put the 
test after the loop body (suite), and it's difficult to think of a 
consistent and natural syntax for expressing the construct. Not that 
this stopped lots of people from coming forward with their personal 
favourites ... some suggestions even offered "n and a half" looping 
possibilities.

In the end nobody managed to convince Guido that a suitable solution was 
readily to hand, so nothing happened.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Haskell Typeclasses (was Re: OO in Python? ^^)

2005-12-15 Thread Aahz
In article <[EMAIL PROTECTED]>,
Alex Martelli <[EMAIL PROTECTED]> wrote:
>
>Right, you can get good genericity with Haskell's typeclasses (I've
>posted about that often in the past, and desperately and so far
>unsuccessfully tried to convince Guido to use something close to
>typeclasses rather than "interfaces" for such purposes as PEP 246
>[protocol adaptation]); it's the state of _templates_ in Haskell,
>specifically, which I was rather dubious about (it may be that I just
>haven't dug into them deep enough yet, but they do seem not a little
>"convoluted" to me, so far).

Hrm.  I don't recall anything about typeclasses, so my suspicion is that
you were writing something lengthy and above my head.  Can you write
something reasonably short about it?  (I'm asking partly for your
benefit, because if it makes sense to me, that will likely go a long way
toward making sense to Guido -- we seem to think similarly in certain
ways.)
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"Don't listen to schmucks on USENET when making legal decisions.  Hire
yourself a competent schmuck."  --USENET schmuck (aka Robert Kern)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Carl J. Van Arsdall
[EMAIL PROTECTED] wrote:
>   
 Would you, say, remove "for" loops because they could be written as
 "while" loops. Don't forget the word "obvious" that appears in that
 catchphrase ...

 
>>> If every "for" usage can be done with "while" and that "while" is the
>>> preferred way, why not ? As I said, the problem is that "obvious"
>>> really is subjective in many case. And if it really is obvious, it
>>> really is obvious and I doubt there would be that much disagreement.
>>>   
I think comparing "for" and "while" loops in python is problematic.  
Although yes a "for" loop could be done with a "while" in python a "for" 
loop shouldn't be used for general looping, the "obvious" case for a 
"for" loop is to iterate though a list or something similar to that.  I 
wouldn't typically use "while" loops for that, and although it could be 
done, if you were familiar with python using a "for" loop would be the 
most obvious.  I think it really is obvious in most cases with python.

Although, obvious to whom is a good question.  If you don't know the 
language very little will be obvious to you, however one who is familiar 
with python (rtfm) would know which cases should obviously use "while" 
and which cases should obviously use "for"

2cents

-- 

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

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


Re: tkinter: drop-down widget

2005-12-15 Thread Alex Hunsley
Alex Hunsley wrote:
> Can anyone recommend some code for creating drop-down menus in tkinter?
> To be absolutely clear, here's an example of a drop-down:
> 
> http://www.google.co.uk/preferences?hl=en
> (see the language selection widget)
> 
> I've found the odd bit of code here and there, such as:
> http://infohost.nmt.edu/tcc/cgi/pre.cgi?file=/u/www/docs/tcc/help/lang/python/mapping/dropdown.py
>  

This seems to work ok, except it's a little rough around the edges (e.g. 
the drop-down is a button with no visual affordance that it is a drop 
down, the button changes size depending on what is selected, etc...)

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Aahz
In article <[EMAIL PROTECTED]>,
Steve Holden  <[EMAIL PROTECTED]> wrote:
>
>(Part of) Python's credo (which you can read in context by typing
>
> import this
>
>at an interactive command prompt) is "There should be one (and 
>preferably only one) way to do it".

Actually, I've gotten used to doing

python -c 'import this'
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"Don't listen to schmucks on USENET when making legal decisions.  Hire
yourself a competent schmuck."  --USENET schmuck (aka Robert Kern)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Richie Hindle

[Steve]
> Since Python is Turing-complete

Is there some equivalent of Godwin's Law that we can invoke at this
point?  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Xavier Morel
Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Steve Holden  <[EMAIL PROTECTED]> wrote:
>> (Part of) Python's credo (which you can read in context by typing
>>
>> import this
>>
>> at an interactive command prompt) is "There should be one (and 
>> preferably only one) way to do it".
> 
> Actually, I've gotten used to doing
> 
> python -c 'import this'
Which can be built even more easily with

$ python -m this
(no quotes needed btw)

It's usually useful to pipe it through grep too, in order to get only 
the piece of zen knowledge you need.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python packages on OS X vs Windows

2005-12-15 Thread BartlebyScrivener
Mike,

I nosed around after reading the posts herein. Have you heard of monad,
the new Windows Command Shell in beta?

http://www.microsoft.com/downloads/details.aspx?FamilyID=2ac59b30-5a44-4782-b0b7-79fe2efd1280&DisplayLang=en

http://en.wikipedia.org/wiki/MSH_(shell)

Or a better article:

http://arstechnica.com/guides/other/msh.ars

Might be promising, esp if it could be downloaded and used with xp.



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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

Carl J. Van Arsdall wrote:
> Although, obvious to whom is a good question.  If you don't know the
> language very little will be obvious to you, however one who is familiar
> with python (rtfm) would know which cases should obviously use "while"
> and which cases should obviously use "for"
>
So far, I haven't seen any for/while argument on this thread. So their
usage seems to be obvious to most if not all(which one to choose).

reduce/map/filter obviously is not the obvious way for people from C or
other imperative background, and may not be for those who never program
before.

However, for those who know these functions as well as the for style,
it is no longer so obvious(in the sense which is better/clearer). It
would then become a style choice. It can also be some policy choice,
like because an organisation want to be certain that newly hired
programmer(who would most likely be people from imperative background)
can pick up the program easily, it is better not to use the FP style.

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Steve Holden
Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Steve Holden  <[EMAIL PROTECTED]> wrote:
> 
>>(Part of) Python's credo (which you can read in context by typing
>>
>>import this
>>
>>at an interactive command prompt) is "There should be one (and 
>>preferably only one) way to do it".
> 
> 
> Actually, I've gotten used to doing
> 
> python -c 'import this'

Faster:

   python -m this

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread bonono

Steve Holden wrote:
> This would have the unfortunate side effect of only allowing changes to
> Python that allowed users to do things which are currently impossible.
>
> Since Python is Turing-complete, this would effectively inhibit all
> further changes to the language.
I don't quite understand the above.

>
> Would you, say, remove "for" loops because they could be written as
> "while" loops. Don't forget the word "obvious" that appears in that
> catchphrase ...
>
If every "for" usage can be done with "while" and that "while" is the
preferred way, why not ? As I said, the problem is that "obvious"
really is subjective in many case. And if it really is obvious, it
really is obvious and I doubt there would be that much disagreement. I
am a left handed and any time I use something that is designed to be
right-handed, I have the same feeling too, luckily there isn't that
much such thing in real life.

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


Re: Python packages on OS X vs Windows

2005-12-15 Thread Kevin Walzer
Re: package installers:

I misspoke. The address for them is http://pythonmac.org/packages/


-- 
Cheers,

Kevin Walzer, PhD
WordTech Software - "Tame the Terminal"
http://www.wordtech-software.com
sw at wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


newbie to python

2005-12-15 Thread exter_c
Hello,

How do I find out what modules have been included in my python install?
I am having issues with crypt functions not working on ubuntu or redhat
but they work on Slackware.

Any assistance would be great.

Regards,

Johhny.

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Simon Brunning
On 12/15/05, Steve Holden <[EMAIL PROTECTED]> wrote:
> Aahz wrote:
> > python -c 'import this'
>
> Faster:
>
>python -m this

So, there's two ways to do it. ;-)

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Rocco Moretti
[EMAIL PROTECTED] wrote:
> Chris Mellon wrote:
> 
>>Any time you want to write something in any way other than the obvious
>>way, ask yourself why? Is it more obvious *to you*, which is a good
>>reason as long as you're only writing code for yourself? Or is it just
>>to be different, or because you think it'll be faster, or just because
>>the slickness of it appeals to you?
>>
> 
> The point is again, "obvious" is not so obvious sometimes. You seem to
> be assuming that anyone that use style different from you is
> intentionally doing it and that your style would first come to their
> mind but they don't use it, for the sake of proving that they are
> smart.

My take on it is that "obvious" is intended to be prescriptive, not 
descriptive. (Note that in the Zen it is phrased "There *should* be 
...".) It describes what Python aspires to, not what it is. If the 
currently preferred method is not "the one obvious way", steps should be 
taken to make the preferred way "the obvious way" (i.e. the way that you 
reach for first, when you want to "do it").

Keep in mind that the Zen was written at a time when there was a certain 
amount of "Perl vs. Python deathmatch" feeling in the air. That line in 
the Zen was a reaction to Perl's "There's more than one way to do it 
(TMTOWTDI)."

Perl took the view that flexibility was a virtue to be praised above all 
others, and allows and encourages (or at least used to) different ways 
of doing things. I don't think a syntactic construct was excluded from 
Perl for the sole reason "well, we already can do that with this 
construct ..."

Python, in part due to a backlash to the Perl philosophy, emphasized 
clarity and readability. There are *many* constructs which have been 
excluded from Python just because they weren't any clearer than what is 
already in the language. (Once a language is "Turing complete", anything 
you can program a computer to do, you can use that language to do. There 
is no guarantee that it's short or pretty, though.) That's what the "one 
obvious way" refers to - the clearest, most readable way of expressing 
what you want to accomplish.

In this "obviousness", there is (often) little consideration for what 
other languages you previously might have used, or might be trying to 
drag idioms from. As an absurd analogy, if you were born and grew up in 
a country with a crazed totalitarian leader who, under penalty of death, 
made you turn around three times while hopping and whistling the 
national anthem before you sat down for dinner, it might be "obvious" to 
you that one must turn around three times, hopping and whistling before 
sitting down for dinner. However, if you move out of that country to, 
say, the Netherlands, for instance, you no longer need to 
hop-whistle-turn, and your new countrymen will look at you strangely if 
you do. That's not to say you can't hop-whistle-turn if the fancy 
strikes you, but in any practical setting, people will expect you do the 
simple, "obvious" thing -- just sit.


BTW. People who are quick to bring up the Zen (and I'm as guilty as 
others at times) should also keep in mind that the Zen is found under 
the *humor* section of the Python website. It's not an actual design 
document, it's just a surprisingly intuitive description of Python's nature.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Binary representation of floating point numbers

2005-12-15 Thread Torsten Bronger
Hallöchen!

Sorry for the late response, but the subject didn't catch my
attention ...

Mike Meyer <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] writes:
>
>> In float mode, the instrument returns a sequence of bits that are
>> exactly the ieee754 number in the case of floats, or just the
>> flags in the case of flags.  PyVisa, when set to float mode, will
>> convert everything to float, because it is unaware apriori that
>> one of the fields returned is actually intended to be used as
>> binary flags.
>
> You need to get PyVisa to return strings of bytes to you.

PyVISA does so when calling the read_raw() method.

> [...]
>
> Struct is the right tool for the job.

Exactly.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python packages on OS X vs Windows

2005-12-15 Thread gene tani

Kenneth McDonald wrote:
> At the moment I'm doing most of my stuff on a Mac, but I've been
> considering also getting
> a Windows laptop. One of the reasons is that I've found it very
> difficult to get certain
> Python related things running on the Mac; for example, if one wants
> to use the most
> up-to-date Python on the mac, rather than the one installed by Apple,

Imageine the WIndows marketing push: "Switch", "It just works"... ;-}

I went the othe way, I just bought my first mac a month or so ago, I
love it (and textmate and Komodo).  So i go to install python and ruby.
 I find the python-mac-sig is perfect, finite volume (~20 threads for
December so far) and Bob Ippolito is right there answering questions.

http://aspn.activestate.com/ASPN/Mail/Browse/Collapsed/pythonmac-sig/
http://mail.python.org/mailman/listinfo/pythonmac-sig

but i punt and go with ActiveState dmg.

I must say my experience with trying to install ruby 1.8.2 with
tarballs, fink, darwinports was totally unsatisfactory but that's for
another group.

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


Re: Why and how "there is only one way to do something"?

2005-12-15 Thread Brian Cully

[EMAIL PROTECTED] wrote:
> C-programmer learning python :
>
> Hi, where is condition ? true : false
>
> someone prefer the if/else statement type:
>
> Can't you see that the following is much more readable, stupid(well not
> the exact word but tone in such a way like words of messy or elegant
> etc.)
>
> if condition:
>   true
> else:
>   false

Except that the latter isn't an expression, and thus can't be used
inline.

Where you can do: somevar = condition ? true : false

You have to do, instead:
if condition:
somevar = true
else:
somevar = false

It may not seem like a big deal to you, but this approach has a number
of problems, depending on what you're doing. When you're using the
ternary operator you avoid temporary variables, and if you use it a
lot, that's much less that you have to keep track of. It's embeddable
in other arbitrary code, so you can move it around as you need to, or
just keep the morass of side-effects down.

Readability isn't just line-by-line, but a whole work. if/else may work
well most of the time, but sometimes it's ugly, and even though it's
obvious, it doesn't necessarily make your code easier to read.

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


Re: How to get the local mac address?

2005-12-15 Thread mwilliams

Well, that kinda depends on what you want the MAC Address of.  Personally (on 
Unix systems) I 
simply read from a popen('ifconfig') and use a regular expression to parse out 
the mac address.  
Works perfectly.

Just my 2¢,
Michael

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


Re: ?: in Python

2005-12-15 Thread Dave Hansen
On Wed, 14 Dec 2005 21:16:23 +0100 in comp.lang.python, Lawrence
Oluyede <[EMAIL PROTECTED]> wrote:

>Il 2005-12-14, Andy Leszczynski <[EMAIL PROTECTED]> ha scritto:
>> How can do elegantly in Python:
>>
>> if condition:
>> a=1
>> else:
>> a=2
>>
>> like in C:
>>
>> a=condition?1:2
>>
>
>There are tons of threads on this newsgroup and in the python-dev mailing
>list about a ternary operator. There's also a PEP AFAIK.
>
>I like this:
>
>In [1]:switch = True
>
>In [2]:a = (1, 2)[switch]
>
>In [3]:print a
>2

Note, however, you have the logic backwards.  To duplicate the
functionality of the OP's example, you need

   a = (2,1)[condition]

or

   a = (1,2)[not condition]

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie to python

2005-12-15 Thread Lawrence Oluyede
Il 2005-12-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> ha scritto:
> How do I find out what modules have been included in my python install?

Look in site-packages directory

> I am having issues with crypt functions not working on ubuntu or redhat
> but they work on Slackware.

Crypt functions? Are u missing python2.x-crypto package?


-- 
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO in Python? ^^

2005-12-15 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> > [protocol adaptation]); it's the state of _templates_ in Haskell,
> > specifically, which I was rather dubious about (it may be that I just
> > haven't dug into them deep enough yet, but they do seem not a little
> > "convoluted" to me, so far).
> >
> Yup, the templates is an afterthought and the point of discussion by
> Lispers(?) too. I have no idea what it is intended for, there must be
> some need for it but definitely beyond what I can handle.

I believe that the basic idea is to make available a powerful "compile
time language" in parallel to the "runtime language" -- so in a sense
the motivation is related to that for macros in Lisp, at least if I grok
it correctly... but with more anchoring in the typesystem rather than in
syntactic aspects of the base language.  As it turns out that C++'s
templates also make up a Turing-complete compile-time language anchored
in the (admittedly weaker/less elegant) typesystem of the base language,
it's not all that different "philosophically" (if my understanding is
correct).  I gather that the next C++ standard will have "concepts" (in
the generic programming sense of the word) as a first-class construct,
rather than just as an abstraction to help you think of templates, so it
may be that the current distinctions will blur even further...


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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-15 Thread Alex Martelli
gene tani <[EMAIL PROTECTED]> wrote:

> Ben Sizer wrote:
> > Mike Meyer wrote:
> > > [Not sure if this attribution is correct.]
> > > > Alex Martelli wrote:
> > > > Because of course if other languages have 1 or two frameworks, python
> > > > needs a dozen.
> 
> woops, that attribution is absolutely *wrong*, DH said that, sorry Alex

NP, I noticed but decided not to comment, particularly since I roughly
agree with the spirit of DH's comment.  Graham and Norvig, among others,
have often argued that there are parallels between Lisp and Python; the
proliferation of frameworks for a given task, I think, is one of them.
Good thing we have more things "nailed down" in the standard library...
but even then, e.g. with asyncore vs Twisted, there's no holding down a
different [here, better] implementation of similar ideas from emerging
as a third-party framework, anyway.


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


Re: Haskell Typeclasses

2005-12-15 Thread Alex Martelli
Aahz <[EMAIL PROTECTED]> wrote:
   ...
> Hrm.  I don't recall anything about typeclasses, so my suspicion is that
> you were writing something lengthy and above my head.  Can you write
> something reasonably short about it?  (I'm asking partly for your
> benefit, because if it makes sense to me, that will likely go a long way
> toward making sense to Guido -- we seem to think similarly in certain
> ways.)

Think of a typeclass as something "like an interface, more than an
interface" to which a type can easily be "adapted" by a third programmer
even if the two programmers who wrote the type and typeclass were
working separately and with no knowledge of each other -- not too far
from the vaguer idea of "protocol" I support in PEP 246 (which focuses
on the adaptation), except that in Haskell things happen at compile time
while in Python we prefer to avoid the strong distinction between
compile time and runtime.

You may think of a typeclass as akin to an abstract baseclass, because
it's not constrained to only giving the signatures of methods, it can
also supply some default implementations of some methods in terms of
others.  Guido blogged in August about interfaces versus ABCs, not
remembering why he had once Pronounced about preferring ABCs, and in his
critique of ABCs he mentions that one weakness of their ability to
provide default implementations is that you have to decide about what is
the most fundamental subset, in whose terms the rest is implemented.
But *typeclasses do away with that need*.  Consider (arbitrary
pythonesquoid syntax):

typeclass mapping:
  def __getitem__(self, key):
_notthere=[]
result = self.get(key, _notthere)
if result is notthere: raise KeyError
return result
  def get(self, key, default):
try: return self[key]
except KeyError: return default
  # etc etc

this LOOKS like mutual recursion, but since it's a typeclass it doesn't
mean that: it means __getitem__ may be defined (and then get uses the
provided default implementation unless overridden) OR get may be defined
(and then it's __getitem__ that may use the default implementation
supplied by the the typeclass, or else override it).

When you compile a typeclass you build a directed graph of dependencies
of methods on each other, which may include cycles; when you show how a
type adapts to a typeclass, you build a copy of that graph removing the
dependencies of those methods which do get explicitly implemented (in
the type or in the adapter) -- if the copy at the end of these
compilations still has cycles, or leaves (methods that the typeclass
requires and neither the type nor the adapter supply), then this raises
an exception (incomplete adaptation).

Thus, a typeclass clearly shows the semantics intended for methods that
depend on each other, and conveniently lets you, the adapter's author,
choose what to implement -- the typeclass's author has not been forced
to pick the "most fundamental" methods.  ABCs, or extremely handy mixins
such as UserDict.DictMixin, do force a programmer who knows nothing
about the internals of your class (the author of the ABC or mixin) to
pick "most fundamental" methods.  Thus, typeclasses are more useful than
ABCs by as much as ABC are more useful than (simply "syntactical")
interfaces -- coupled with adaptation mechanisms, the overall result can
be extremely handy (as any Haskell programmer might confirm).


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


Re: Optimize function similiar to dict.update() but adds common values

2005-12-15 Thread Christopher Subich
Peter Otten wrote:
> 
> def add_freqs3(freq1, freq2):
> total = dict(freq1)
> for key, value in freq2.iteritems():
> try:
> total[key] += value
> except KeyError:
> total[key] = value
> return total
> 

Untested, but replacing the try/except pair with the following should be 
semantically equivalent and a bit faster:

total[key] = total.get(key,0) + value
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimize function similiar to dict.update() but adds common values

2005-12-15 Thread bonono

Christopher Subich wrote:
> Peter Otten wrote:
> >
> > def add_freqs3(freq1, freq2):
> > total = dict(freq1)
> > for key, value in freq2.iteritems():
> > try:
> > total[key] += value
> > except KeyError:
> > total[key] = value
> > return total
> >
>
> Untested, but replacing the try/except pair with the following should be
> semantically equivalent and a bit faster:
>
> total[key] = total.get(key,0) + value
Would that have a performance impact as it seems that key needs to be
hashed twice or may be += also need to do it twice ? Just curious.

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


  1   2   3   >