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

2005-12-13 Thread Antoon Pardon
Op 2005-12-12, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
> Pierre Quentel wrote:
>
>> In some program I was testing if a variable was a boolean, with this
>> test : if v in [True,False]
>>
>> My script didn't work in some cases and I eventually found that for v =
>> 0 the test returned True
>>
>> So I changed my test for the obvious "if type(v) is bool", but I still
>> find it confusing that "0 in [True,False]" returns True
>>
>> By the way, I searched in the documentation what "obj in list" meant and
>> couldn't find a precise definition (does it test for equality or
>> identity with one of the values in list ? equality, it seems) ; did I
>> miss something ?
>
 issubclass(bool, int)
> True
 isinstance(False, int)
> True
 False == 0
> True
 int(False)
> 0
>
> but seriously, unless you're writing an introspection tool, testing for
> bool is pretty silly.  just use "if v" or "if not v", and leave the rest to
> Python.

That depends on the circumstances. I have code where a particular
variable can be a boolean or an integer. I don't want that code
to behave the same on 0 and False nor on any other number and
True.

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


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

2005-12-13 Thread bonono

Antoon Pardon wrote:
> Op 2005-12-12, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
> > Pierre Quentel wrote:
> >
> >> In some program I was testing if a variable was a boolean, with this
> >> test : if v in [True,False]
> >>
> >> My script didn't work in some cases and I eventually found that for v =
> >> 0 the test returned True
> >>
> >> So I changed my test for the obvious "if type(v) is bool", but I still
> >> find it confusing that "0 in [True,False]" returns True
> >>
> >> By the way, I searched in the documentation what "obj in list" meant and
> >> couldn't find a precise definition (does it test for equality or
> >> identity with one of the values in list ? equality, it seems) ; did I
> >> miss something ?
> >
>  issubclass(bool, int)
> > True
>  isinstance(False, int)
> > True
>  False == 0
> > True
>  int(False)
> > 0
> >
> > but seriously, unless you're writing an introspection tool, testing for
> > bool is pretty silly.  just use "if v" or "if not v", and leave the rest to
> > Python.
>
> That depends on the circumstances. I have code where a particular
> variable can be a boolean or an integer. I don't want that code
> to behave the same on 0 and False nor on any other number and
> True.
>
Then your program/implementation/requirement is wrong because it
doesn't fit in the use case of "if v:" or "if not v:", refactor  ;-)

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


Re: ElementTree - Why not part of the core?

2005-12-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> ElementTree on the other hand provides incredibly easy access to XML
> elements and works in a more Pythonic way.  Why has the API not been
> included in the Python core?

$ svn up
$ make
...
$ python
Python 2.5a0 (#1, Dec 12 2005, 19:26:49)

>>> import xml.etree.ElementTree as ET
>>> root = ET.XML("hello, world!")
>>> root

>>> root.text
'hello, world!'

http://svn.python.org/view/python/trunk/Lib/xml/etree/

(and it's all your fault ;-)





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


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

2005-12-13 Thread Steve Holden
Pierre Quentel wrote:
> Hi all,
> 
> In some program I was testing if a variable was a boolean, with this 
> test : if v in [True,False]
> 
> My script didn't work in some cases and I eventually found that for v = 
> 0 the test returned True
> 
> So I changed my test for the obvious "if type(v) is bool", but I still 
> find it confusing that "0 in [True,False]" returns True
> 
> By the way, I searched in the documentation what "obj in list" meant and 
> couldn't find a precise definition (does it test for equality or 
> identity with one of the values in list ? equality, it seems) ; did I 
> miss something ?
> 
It actually uses the __contains__() method of the right-hand operand, 
and in the case of a list that will test for equality of the left-hand 
operand to one of the list elements. Since False == 0 that's why you see 
what you do.

The really interesting question your post raises, though, is "Why do you 
feel it's necessary to test to see whether a variable is a Boolean?".

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: ActivePython and Amara

2005-12-13 Thread Steve Holden
Jay wrote:
> Woah woah woah, calm your ass down a little.
> 
> I didn't say that the "hijacker" made it go off topic. Did I? I just
> said that the thread was going off topic from the dam title. We
> weren't
> talking about XML no more now were we. And who the hell are you talking
> to thinking that I haven't researched my ass off up till 4AM in the
> dam
> morning looking for an explanation on Google, friends and other
> resources... Also,
> 
> 
>>If you had ANY understanding of Python,
> 
> you would have realized this. <
> 
> So now your saying I don't know any
> python when I have read about a shitload of tutorials... So, I think
> first of all, you got some damn attitude, second of all, I never asked
> anyone to debug my program all I freaking asked for was help trying to
> get a module onto activepython which, I would love for you to Google
> "activepython and amara" not many relevant results. Third of all, I
> don't appreciate you saying that I don't know python when I have
> worked
> my ass off learning it!
> 
> Now, with that out of the way. Stay the hell of my thread cuz you have
> some damn attitude problem and I don't need your rants about my
> questions.
> 
> "Sometimes you really need to slow down and learn something before you
> can continue with what you want to do."
> ^^Take your post, and shove it up your ass.
> 
> BYE
> -Jay
> 
For your enlightenment, comp.lang.python is probaly one of the 
best-mannered technical newgroups around, and your attitude clearly 
shows you are even more ignorant of Usenet than you are of Python. This 
isn't "your" thread, this is a thread you started.

And stopped, too, by the look of it. Your behaviour really is obnoxious. 
"BYE" indeed. A very eloquent demonstration of how to make sure you get 
absolutely no help 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: "0 in [True,False]" returns True

2005-12-13 Thread Paul Rubin
Steve Holden <[EMAIL PROTECTED]> writes:
> The really interesting question your post raises, though, is "Why do
> you feel it's necessary to test to see whether a variable is a
> Boolean?".

What's the point of having Booleans, if you can't tell them from integers?
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-12-13 Thread Antoon Pardon
Op 2005-12-13, Steve Holden schreef <[EMAIL PROTECTED]>:
> Pierre Quentel wrote:
>> Hi all,
>> 
>> In some program I was testing if a variable was a boolean, with this 
>> test : if v in [True,False]
>> 
>> My script didn't work in some cases and I eventually found that for v = 
>> 0 the test returned True
>> 
>> So I changed my test for the obvious "if type(v) is bool", but I still 
>> find it confusing that "0 in [True,False]" returns True
>> 
>> By the way, I searched in the documentation what "obj in list" meant and 
>> couldn't find a precise definition (does it test for equality or 
>> identity with one of the values in list ? equality, it seems) ; did I 
>> miss something ?
>> 
> It actually uses the __contains__() method of the right-hand operand, 
> and in the case of a list that will test for equality of the left-hand 
> operand to one of the list elements. Since False == 0 that's why you see 
> what you do.
>
> The really interesting question your post raises, though, is "Why do you 
> feel it's necessary to test to see whether a variable is a Boolean?".

I can give you one example. I have written a tube class. A tube behaves
like Queue but it has additional code so that it can be registed with
gtk in the same way as file descriptor can be registered with
io_add_watch. The way this is implemented is by registering an idle
handler when the tube is not empty and removing it when the tube is
empty. So I have a variable cb_src (for callback source) that can be
a boolean or an integer. The possible values are

  False: Not registered by the user
  True: Registered by the user but no nternal idle callback registerd
  a number: gtk integer ID, from the registered idle callback handler.

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


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

2005-12-13 Thread Erik Max Francis
Paul Rubin wrote:

> Steve Holden <[EMAIL PROTECTED]> writes:
>> The really interesting question your post raises, though, is "Why do
>> you feel it's necessary to test to see whether a variable is a
>> Boolean?".
> 
> What's the point of having Booleans, if you can't tell them from integers?

Because

return True

is clearer than

return 1

if the purpose of the return value is to indicate a Boolean rather than 
an arbitrary integer.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   The basis of optimism is sheer terror.
   -- Oscar Wilde
-- 
http://mail.python.org/mailman/listinfo/python-list


python configuration problems

2005-12-13 Thread ivan . pavlov
I am running Debian/Linux unstable. Trying to upgrade packages
depending on python (via aptitude) has started to give errors and
leaves all packeges unconfigured. When I run dpkg --configure pyhton2.3
the following errors occur.

Any advice on what to do?

Setting up python2.3 (2.3.5-8) ...
Compiling python modules in /usr/lib/python2.3 ...
Compiling /usr/lib/python2.3/site-packages/srcb/generator.py ...
 File "/usr/lib/python2.3/site-packages/srcb/generator.py", line 331
   return (_p( *x ) for x in parser.parse_xdoc( line ))
  ^
SyntaxError: invalid syntax

Compiling /usr/lib/python2.3/site-packages/srcb/interp.py ...
 File "/usr/lib/python2.3/site-packages/srcb/interp.py", line 61
   @staticmethod
   ^
SyntaxError: invalid syntax

Compiling /usr/lib/python2.3/site-packages/srcb/multimethods.py ...
 File "/usr/lib/python2.3/site-packages/srcb/multimethods.py", line 50
   sig = tuple( x.__class__.__name__ for x in args )
   ^
SyntaxError: invalid syntax

Compiling /usr/lib/python2.3/site-packages/srcb/parser.py ...
 File "/usr/lib/python2.3/site-packages/srcb/parser.py", line 67
   mode = dict( (k, tuple( re.compile( e ) for e in v )) for (k, v) in
mode.iteritems() )
 ^
SyntaxError: invalid syntax

Compiling /usr/lib/python2.3/site-packages/srcb/visitor.py ...
 File "/usr/lib/python2.3/site-packages/srcb/visitor.py", line 137
   @staticmethod
   ^
SyntaxError: invalid syntax

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


Re: python configuration problems

2005-12-13 Thread ivan . pavlov
I solved the problem myself. Just removed the folder where the errors
were occuring. Don't know how it came to exists in the first place
though. Now everything seems to work fine, for now...

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


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

2005-12-13 Thread Steve Holden
Paul Rubin wrote:
> Steve Holden <[EMAIL PROTECTED]> writes:
> 
>>The really interesting question your post raises, though, is "Why do
>>you feel it's necessary to test to see whether a variable is a
>>Boolean?".
> 
> 
> What's the point of having Booleans, if you can't tell them from integers?

Booleans are specifically defined as a subtype of int at the C level. 
One might also ask "what's the point of having floats if you can't tell 
them from integers":

 >>> 0.0 in [1,2,0,4]
True
 >>>

It just so happens that __contains__() uses an equality test (which it 
should) and equality tests perform certain coercions (which they 
arguably shouldn't, but in that case I wouldn't be the one doing the 
arguing).

"""
 The only thing that changes is the preferred values to represent
 truth values when returned or assigned explicitly.  Previously,
 these preferred truth values were 0 and 1; the PEP changes the
 preferred values to False and True, and changes built-in
 operations to return these preferred values.
"""

PEP 285.

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: "0 in [True,False]" returns True

2005-12-13 Thread Fredrik Lundh
Erik Max Francis wrote:

> > What's the point of having Booleans, if you can't tell them from integers?
>
> Because
>
> return True
>
> is clearer than
>
> return 1
>
> if the purpose of the return value is to indicate a Boolean rather than
> an arbitrary integer.

the real reason booleans were added was that sillyness like

True = 1 == 1
False = not True

and

return 1 # true

and

class Boolean:

def __init__(self, value = 0):
self.value = operator.truth(value)

def __cmp__(self, other):
if isinstance(other, Boolean):
other = other.value
return cmp(self.value, other)

def __repr__(self):
if self.value:
return "" % id(self)
else:
return "" % id(self)

def __int__(self):
return self.value

def __nonzero__(self):
return self.value

True, False = Boolean(1), Boolean(0)

were all too common in the wild.

for the full story, see

http://www.python.org/peps/pep-0285.html

and, to briefly return to the original topic, note that

"This PEP does *not* change the fact that almost all object types
can be used as truth values.  For example, when used in an if
statement, an empty list is false and a non-empty one is true;
this does not change and there is no plan to ever change this.

The only thing that changes is the preferred values to represent
truth values when returned or assigned explicitly.  Previously,
these preferred truth values were 0 and 1; the PEP changes the
preferred values to False and True, and changes built-in
operations to return these preferred values."

in general, returning True and False is pythonic, explicitly testing for
them is not.





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


Re: ActivePython and Amara

2005-12-13 Thread James
Jay,
  Profanity is unwelcome in this newsgroup. Alex's advice is very well
placed and you will realize that once you stop seeing it as a personal
attack. Different newsgroups have different attitudes. comp.lang.python
is not exactly a tech support group. Bug reports posters here are
frequently advised to go to the respective module forums. You were not
singled out.

  A large number of contributors to this group are well educated
professionals and strong contributors to Python. If you expect
responses, you must behave accordingly. If you cannot, you will have to
find a group where such culture is better tolerated, like IRC. And your
post is better suited for IRC to begin with as you seem to be needing a
number of clarifications at a time. Not to mention your impatience.
IRC, once again is more real time for you.

  And for the last time... your problem is not ActivePython related.
>From what has been established so far, it is a bug in the build of the
Win32 binary installer of the module for your Python version.

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


Re: python configuration problems

2005-12-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I am running Debian/Linux unstable. Trying to upgrade packages
> depending on python (via aptitude) has started to give errors and
> leaves all packeges unconfigured. When I run dpkg --configure pyhton2.3
> the following errors occur.

the "srcb" package uses 2.4 features (generator expressions and
decorators).

whoever told you to add that package to your 2.3 install should
be slapped with a medium-sized fish.





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


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

2005-12-13 Thread Robin Becker
Carsten Haese wrote:
...
> 
> Where/how did you search? http://docs.python.org/lib/typesseq.html
> states unambiguously that "x in s" returns "True if an item of s is
> equal to x, else False"
.

exactly and I see

 >>> 0==False
True
 >>>

so I guess nothing is wrong :)
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-12-13 Thread bonono

Erik Max Francis wrote:
> Paul Rubin wrote:
>
> > Steve Holden <[EMAIL PROTECTED]> writes:
> >> The really interesting question your post raises, though, is "Why do
> >> you feel it's necessary to test to see whether a variable is a
> >> Boolean?".
> >
> > What's the point of having Booleans, if you can't tell them from integers?
>
> Because
>
>   return True
>
> is clearer than
>
>   return 1
>
> if the purpose of the return value is to indicate a Boolean rather than
> an arbitrary integer.
>
True, but if that is the only reason, Two built-in value of
True/False(0/1) serves the need which is what is now(well sort of). Why
have seperate types and distinguish them ?

>>>True == 1
True
>>>True is 1
False

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


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

2005-12-13 Thread Steve Holden
Antoon Pardon wrote:
> Op 2005-12-13, Steve Holden schreef <[EMAIL PROTECTED]>:
> 
>>Pierre Quentel wrote:
>>
>>>Hi all,
>>>
>>>In some program I was testing if a variable was a boolean, with this 
>>>test : if v in [True,False]
>>>
>>>My script didn't work in some cases and I eventually found that for v = 
>>>0 the test returned True
>>>
>>>So I changed my test for the obvious "if type(v) is bool", but I still 
>>>find it confusing that "0 in [True,False]" returns True
>>>
>>>By the way, I searched in the documentation what "obj in list" meant and 
>>>couldn't find a precise definition (does it test for equality or 
>>>identity with one of the values in list ? equality, it seems) ; did I 
>>>miss something ?
>>>
>>
>>It actually uses the __contains__() method of the right-hand operand, 
>>and in the case of a list that will test for equality of the left-hand 
>>operand to one of the list elements. Since False == 0 that's why you see 
>>what you do.
>>
>>The really interesting question your post raises, though, is "Why do you 
>>feel it's necessary to test to see whether a variable is a Boolean?".
> 
> 
> I can give you one example. I have written a tube class. A tube behaves
> like Queue but it has additional code so that it can be registed with
> gtk in the same way as file descriptor can be registered with
> io_add_watch. The way this is implemented is by registering an idle
> handler when the tube is not empty and removing it when the tube is
> empty. So I have a variable cb_src (for callback source) that can be
> a boolean or an integer. The possible values are
> 
>   False: Not registered by the user
>   True: Registered by the user but no nternal idle callback registerd
>   a number: gtk integer ID, from the registered idle callback handler.
> 
Well I guess you'd better hope that gtk never returns a zero or one, then.

Note, though, that True and False are defined to be singleton instances, 
so it *is* permissible to say

 if i is False:

 >>> 0 is False
False
 >>> 1 is True
False
 >>>

However I must say the coupling in that interface has a very definite 
code smell. Why not use two variables, a Boolean "registered" and an 
integer ID that is meaningless when registered is False?

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: Developing a network protocol with Python

2005-12-13 Thread Laszlo Zsolt Nagy
Tom Anderson wrote:

>>I think to be effective, I need to use TCP_NODELAY, and manually 
>>buffered transfers.
>>
>>
>Why?
>
Because of the big delays when sending small messages (size < 1500 bytes).


>Personally, i'd steer clear of doing it like this, and try to use an 
>existing, language-neutral generic marshalling layer. XML and ASN.1 would 
>be the obvious ones, but i wouldn't advise using either of them, as 
>they're abominations. JSON would be a good choice:
>
>http://www.json.org/
>  
>
I need to send Python objects too. They are too elaborate to convert 
them to XML. (They are using cyclic weak references and other Python 
specific stuff.) I can be sure that on both sides, there are Python 
programs. Is there any advantage in using XML if I already need to send 
Python objects? Those objects cannot be represented in XML, unless 
pickled into a CDATA string.

>And didn't get much in the way of answers. Someone did point to this, 
>though:
>
>http://www.internet2.edu/~shalunov/writing/protocol-design.html
>  
>
Hmm, this was very helpful. Thank you!

  Les

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


How To Read Excel Files In Python?

2005-12-13 Thread Anand
Hello,

Can I get some help on how to read the excel files using python?

from win32com.client import Dispatch
xlApp = Dispatch("Excel.Application")
xlWb = xlApp.Workbooks.Open("Read.xls")
xlSht = xlWb.WorkSheets(1)

But sadly, I am unable to proceed further about how to read the cells of the
worksheet of my excel file!

Thanks for your help and cooperation.

Best regards,
Anand


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


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

2005-12-13 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:

> True, but if that is the only reason, Two built-in value of
> True/False(0/1) serves the need which is what is now(well sort of). Why
> have seperate types and distinguish them ?

Because of this:

x = True
y = 1 # but I mean it to represent true

print x, y

Besides, it's not the only reason, but it's a good one.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Ipsa scientia potestas est. "Knowledge itself is power."
   -- a Latin proverb
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-12-13 Thread bonono

Erik Max Francis wrote:
> [EMAIL PROTECTED] wrote:
>
> > True, but if that is the only reason, Two built-in value of
> > True/False(0/1) serves the need which is what is now(well sort of). Why
> > have seperate types and distinguish them ?
>
> Because of this:
>
>   x = True
>   y = 1 # but I mean it to represent true
>
>   print x, y
>
> Besides, it's not the only reason, but it's a good one.
>
True too, and could be the reason(or similar too) why the OP wants to
test the type rather than the logical value of it.

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


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

2005-12-13 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:

> True too, and could be the reason(or similar too) why the OP wants to
> test the type rather than the logical value of it.

The type is for the self-documentation purposes.  The value is the same; 
so no, that's not a good reason either.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Ipsa scientia potestas est. "Knowledge itself is power."
   -- a Latin proverb
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How To Read Excel Files In Python?

2005-12-13 Thread Tim Golden
[Anand]

> Can I get some help on how to read the excel files using python?

> from win32com.client import Dispatch
> xlApp = Dispatch("Excel.Application")
> xlWb = xlApp.Workbooks.Open("Read.xls")
> xlSht = xlWb.WorkSheets(1)

> But sadly, I am unable to proceed further about how 
> to read the cells of the worksheet of my excel file!

Well, I could (and doubtless others will) give you
some working code, but the code you give above must
come from somewhere -- some Microsoft example, or
a VBS repository, perhaps. Since you've already done
the only Python-specific part of the operation,
calling win32com.client.Dispatch, the rest is the
same in Python as in any other language.

However, to get you going...


import win32com.client

xlApp = win32com.client.gencache.EnsureDispatch ("Excel.Application")
xlWb = xlApp.Workbooks.Open ("c:/temp/temp.xls")
xlSht = xlWb.Worksheets (1)
for row in range (3):
  for col in range (3):
print "(%d,%d) => %s" % (row, col, xlSht.Cells (1+row, 1+col).Value)

xlApp.Quit ()



NB There are several ways to do most of this. You could use,
for example, xlWb.ActiveSheet rather than Worksheets (1) etc.
Just go with whatever works for you.

Also, note that it's often useful to record what you want to
do as a macro within Excel, and then to look at the resulting
VBA to know what Python should be doing to achieve the same
result.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


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

2005-12-13 Thread Duncan Booth
 wrote:

>> if the purpose of the return value is to indicate a Boolean rather than
>> an arbitrary integer.
>>
> True, but if that is the only reason, Two built-in value of
> True/False(0/1) serves the need which is what is now(well sort of). Why
> have seperate types and distinguish them ?
> 
True == 1
> True
True is 1
> False
> 

Within Python that would probably be sufficient, but some external 
libraries e.g. COM or XMLRPC make a distinction between integers and 
booleans, so it makes it more convenient if there is a defined way to 
distinguish between calling one overloaded method which takes an integer or 
another of the same name which take a boolean.

Before Python had a separate boolean type there was an implementation 
detail which mean that it was possible to distinguish the constants 0 and 1 
which were generated by a comparison from other constant 0 and 1 values. 
The python COM libraries used this 'feature'.

XMLRPC has its own Boolean class which is used in Python versions where 
boolean is not a builtin.

Another reason to have a boolean type is of course to provide a cast:

   def isNameSet(self):
  return boolean(self.name)

instead of:

   def isNameSet(self):
   if self.name:
  return True
   else:
  return False
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How To Read Excel Files In Python?

2005-12-13 Thread Dennis Benzinger
Anand schrieb:
> Hello,
> 
> Can I get some help on how to read the excel files using python?
> [...]

Besides using the Excel component you could use the pyExcelerator 
 module.
You even don't need Windows for it.


Bye,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-12-13 Thread quentel . pierre
Ok, I'll explain why I wanted to test if the value was a boolean

I have a program that generates HTML tags with attributes. The
principle is that
TAG('text',arg1=val1,arg2=val2)
generates
text

For HTML attributes that don't have an explicit value (such as the
SELECTED attribute in OPTION) the keyword argument to the function must
have the value True

My program has a class for each tag, all derived from a generic TAG
class whose __init__ method takes the arguments :
def __init__(self, innerHTML="", **attrs):

I have to handle differently the cases where the value is a boolean or
another type:
- if it's a boolean then if the value is True, generate the argument
name ; if the value is False, don't generate anything
- if it's not a boolean, generate arg="val". Specifically, it val is 0,
generate val = "0"

Testing with "if v:" as suggested would fail for val = 0

Anyway, I exposed my silly "if v in [True,False]" just to give my
opinion that I found confusing that
0 in [True,False]
or (boolean type checking set aside)
0 in [1,range(2),False,'text']

return True

Regards,
Pierre

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


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

2005-12-13 Thread bonono

Erik Max Francis wrote:
> [EMAIL PROTECTED] wrote:
>
> > True too, and could be the reason(or similar too) why the OP wants to
> > test the type rather than the logical value of it.
>
> The type is for the self-documentation purposes.  The value is the same;
> so no, that's not a good reason either.
>
I don't know why he wants it, let alone whether it is a good or bad
reason. The only thing I read from his post is that he wants to
distinguish the type, why and how it fits in his big picture, no one
but he knows. It could be for similar reason, say to document the
content of data, store it in text file, translate it to another
language(say converting python object to js object but I forgot if
javascript treat 0/1 the same way as python).

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


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

2005-12-13 Thread quentel . pierre
Thanks for the link Carsten, the explanation is clear

I didn't know where to search in the Python documentation, there isn't
a section about keywords (always wondered why without daring to say -
now it's done). So I typed ' "in" operator Python ' in Google, which
gave :
- on the first page a link to AM Kuchling's and Moshe Zadka's "What's
new in Python 2.0" which said :
"obj in seq returns true if obj is present in the sequence seq; Python
computes this by simply trying every index of the sequence until either
obj is found or an IndexError is encountered"
- on the second page a link to the Python tutorial that says : "The
comparison operators in and not in check whether a value occurs (does
not occur) in a sequence"

I couldn't tell if "present in the sequence" or "obj is found" or
"occurs/does not occur in a sequence" meant "is equal to" or "is the
same object as". The answer you pointed me to is clear, but for some
reason I didn't have the idea of looking in the section "Sequence Types
-- str, unicode, list, tuple, buffer, xrange" for the definition of
"in" (after all "in" is also used in list comprehensions, generator
expressions, exec, etc... and for iteration on iterators)

Regards,
Pierre

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


Re: How To Read Excel Files In Python?

2005-12-13 Thread Steve Holden
Anand wrote:
> Hello,
> 
> Can I get some help on how to read the excel files using python?
> 
> from win32com.client import Dispatch
> xlApp = Dispatch("Excel.Application")
> xlWb = xlApp.Workbooks.Open("Read.xls")
> xlSht = xlWb.WorkSheets(1)
> 
> But sadly, I am unable to proceed further about how to read the cells of the
> worksheet of my excel file!
> 
> Thanks for your help and cooperation.
> 
> Best regards,
> Anand
> 
> 
The best way to proceed is to record actions as macros in Excel and then 
use the recorded VBA as a guide to the Pythin required.

Unfortunately the office APIs aren't very complete in their documentation,

Good places to look, as long as you don't mind rooting around:

   http://msdn.microsoft.com/office/understanding/excel/default.aspx
 
http://msdn.microsoft.com/office/understanding/excel/documentation/default.aspx

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: "0 in [True,False]" returns True

2005-12-13 Thread Ron Griswold
I haven't read all of the responses to this thread, so perhaps this has
already been suggested. But it occurs to me that if one needs to
determine whether a variable is a bool or int it could be done like so:

>>> Booltype = False
>>> var = 0
>>> Booltype == var
True
>>> Booltype.__class__ == var.__class__
False

Ron Griswold
Character TD
R!OT Pictures
[EMAIL PROTECTED]

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


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

2005-12-13 Thread Fredrik Lundh
Duncan Booth wrote:

> Another reason to have a boolean type is of course to provide a cast:
>
>def isNameSet(self):
>   return boolean(self.name)
>
> instead of:
>
>def isNameSet(self):
>if self.name:
>   return True
>else:
>   return False

given that Python already had a function for this, that wasn't
much of a reason:

>>> help(operator.truth)
Help on built-in function truth in module operator:

truth(...)
truth(a) -- Return True if a is true, False otherwise.

(truth returned 1 or 0 in pre-boolean versions)

(btw, instead of speculating about the rationale, why don't you all
go and read Guido's PEP ?)





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


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

2005-12-13 Thread Duncan Booth
 wrote:

> For HTML attributes that don't have an explicit value (such as the
> SELECTED attribute in OPTION) the keyword argument to the function must
> have the value True
> 

A better way to do this (given that HTML defines exactly which attributes 
do not take a value) is to use the attribute name and simply generate the 
attribute only if the value is non-false.

>From Zope's TAL parser:

BOOLEAN_HTML_ATTRS = [
# List of Boolean attributes in HTML that may be given in
# minimized form (e.g.  rather than )
# From http://www.w3.org/TR/xhtml1/#guidelines (C.10)
"compact", "nowrap", "ismap", "declare", "noshade", "checked",
"disabled", "readonly", "multiple", "selected", "noresize",
"defer"
]

EMPTY_HTML_TAGS = [
# List of HTML tags with an empty content model; these are
# rendered in minimized form, e.g. .
# From http://www.w3.org/TR/xhtml1/#dtds
"base", "meta", "link", "hr", "br", "param", "img", "area",
"input", "col", "basefont", "isindex", "frame",
]
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-12-13 Thread bonono

Fredrik Lundh wrote:
> Duncan Booth wrote:
>
> > Another reason to have a boolean type is of course to provide a cast:
> >
> >def isNameSet(self):
> >   return boolean(self.name)
> >
> > instead of:
> >
> >def isNameSet(self):
> >if self.name:
> >   return True
> >else:
> >   return False
>
> given that Python already had a function for this, that wasn't
> much of a reason:
>
> >>> help(operator.truth)
> Help on built-in function truth in module operator:
>
> truth(...)
> truth(a) -- Return True if a is true, False otherwise.
>
> (truth returned 1 or 0 in pre-boolean versions)
>
I see you skip another use case of XMLRPC Duncan mentioned, is that a
valid reason ?

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


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

2005-12-13 Thread Fredrik Lundh
Duncan Booth wrote:
>
> > For HTML attributes that don't have an explicit value (such as the
> > SELECTED attribute in OPTION) the keyword argument to the function must
> > have the value True
>
> A better way to do this (given that HTML defines exactly which attributes
> do not take a value) is to use the attribute name and simply generate the
> attribute only if the value is non-false.

footnote: strictly speaking, minimized attributes have values but no names;
it's up to the parser to determine what attribute you're setting when you
specify the value.

(for example, in , "ismap" is the value, not the attribute name.
it's up to the parser to figure out (from the DTD) that this value can only
be used by the "ismap" attribute, and interpret it as )





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


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

2005-12-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I see you skip another use case of XMLRPC Duncan mentioned, is that a
> valid reason ?

the PEP has the answer.  also see my reply to Erik Max Francis:

http://groups.google.com/group/comp.lang.python/msg/adb5e9389ea20b3c

(the silly Boolean class in that post is taken from Python's xmlrpclib library)





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


Re: OO in Python? ^^

2005-12-13 Thread Magnus Lycka
Welcome to Python Matthias. I hope you will enjoy it!

Matthias Kaeppler wrote:
> Another thing which is really bugging me about this whole dynamically 
> typing thing is that it seems very error prone to me:
> 
> foo = "some string!"
> 
> # ...
> 
> if (something_fubar):
>fo = "another string"
> 
> Oops, the last 'o' slipped, now we have a different object and the 
> interpreter will happily continue executing the flawed program.

As an old hardware designer from the space industry, I'm well
aquainted with the idea of adding redundancy to make things
more reliable. I also know that this doesn't come without a
prize. All this stuff you add to detect possible errors might
also introduce new errors, and it takes a lot of time and
effort to implement--time that could be spent on better things.

In fact, the typical solutions that are used to increase the
odds that hardware doesn't fail before its Mean Time To
Failure (MTTF), will significantly lower the chance that it
works much longer than its MTTF! More isn't always better.

While not the same thing, software development is similar.
All that redundancy in typical C++ programs has a high
development cost. Most of the stuff in C++ include files
are repeated in the source code, and the splitting of
code between include and source files mean that a lot of
declarations are far from the definitions. We know that
this is a problem: That's why C++ departed from C's concept
of putting all local declarations in the beginning of
functions. Things that are closely related should be as
close as possible in the code!

The static typing means that you either have to make several
implementations of many algorithms, or you need to work with
those convoluted templates that were added to the language as
an afterthought.

Generally, the more you type, the more you will mistype.
I even suspect that the bug rate grows faster than the
size of the code. If you have to type five times as much,
you will probably make typos five times as many times,
but you also have the problem that the larger amount of
code is more difficult to grasp. It's less likely that
all relevant things are visible on the screen at the same
time etc. You'll make more errors that aren't typos.

Python is designed to allow you to easily write short and
clear programs. Its dynamic typing is a very important
part of that. The important thing isn't that we are
relieved from the boring task of typing type declarations,
but rather that the code we write can be much more generic,
and the coupling between function definitions and function
callers can be looser. This means that we get faster
development and easier maintenace if we learn to use this
right.

Sure, a C++ or Java compiler will discover some mistakes
that would pass through the Python compiler. This is not
a design flaw in Python, it's a direct consequence of its
dynamic nature. Compile time type limitations goes against
the very nature of Python. It's not the checks we try to
avoid--it's the premature restrictions in functionality.

Anyway, I'm sure you know that a successful build with
C++ or Java doesn't imply correct behaviour of your
program.

All software needs to be tested, and if we want to work
effectively and be confident that we don't break things
as we add features or tidy up our code, we need to make
automated tests. There are good tools, such as unittest,
doctest, py.test and TextTest that can help us with that.

If you have proper automated tests, those tests will
capture your mistypings, whether they would have been
caught by a C++ or Java compiler or not. (Well, not if
they are in dead code, but C++/Java won't give you any
intelligent help with that either...)

I've certainly lost time due to mistyped variables now
and then. It's not uncommon that I've actually mistyped
in a way that Java/C++ would never notice (e.g. typed i
instead of j in some nested for loop etc) but sometimes
compile time type checking would have saved time for me.

On the other hand, I'm sure that type declarations on
variables would bring a rigidity to Python that would
cost me much more than I would gain, and with typeless
declarations as in Perl (local x) I would probably
waste more time on adding forgotten declarations (or
removing redundant ones) than I would save time on
noticing the variable mistypings a few seconds before
my unittests catch them. Besides, there are a number
of lint-like tools for Python if you want static code
checks.

As I wrote, the lack of type checking in Python is a
consequence of the very dynamic nature of the language.
A function should assume as little as possible about
its parameters, to be able to function in the broadest
possible scope. Don't add complexity to make you code
support things you don't know of a need for, but take
the chance Python gives you of assuming as little as
possible about your callers and the code you call.

This leads to more flexible and maintainable software.
A design change in your software will probably

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

2005-12-13 Thread Stefan Rank
on 13.12.2005 11:39 Fredrik Lundh said the following:
> Duncan Booth wrote:
>>Another reason to have a boolean type is of course to provide a cast:
>>
>>   def isNameSet(self):
>>  return boolean(self.name)
[snip]
> 
> given that Python already had a function for this, that wasn't
> much of a reason:
> 
help(operator.truth)
> 
> Help on built-in function truth in module operator:
> 
> truth(...)
> truth(a) -- Return True if a is true, False otherwise.
> 
[snip]

As operator.truth() is equivalent to bool()
and as it is the only thing in operator that is not really reflecting an 
operator, I had a look into PEP3000 to see if (the redundant) 
operator.truth is going to be removed. It is not mentioned.

(not that I really care, but I thought I could provide something 
productively new to discuss about, to end the "why is bool an int?" 
discussion ;-)

stefan

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


Datetime, pytz and strange offset

2005-12-13 Thread David Pratt
Hi. I am creating a couple of small methods to help me manage time from 
UTC as standard but I am getting strange results.

If I start with a datetime of 2005-12-12 14:30:00 in timezone 
'America/Halifax'
and I want to turn this into a UTC representation.

from datetime import datetime
from pytz.reference import UTC
import pytz

fmt = '%Y-%m-%d %H:%M:%S %Z%z'
tz = pytz.timezone('America/Halifax')
dt = datetime(year=2005, month=12, day=11, hour=14, minute=30, second=0, 
microsecond=0, tzinfo=tz)
print dt.strftime(fmt)

This is giving me a strange offset of -0414 and LMT timezone.
ie. 2005-12-12 14:30:00 LMT-0414
I am not sure where this is coming from

To get the utc equivalent using dt = dt.astimezone(UTC) I get this 
strange result which is obviously also not correct:
# '2005-12-12 18:44:00 UTC+'

If I do datetime.now instead with the same timezone I get the correct 
timezone and correct offset.

ie.
dt = datetime.now(tz=tz)
# '2005-12-12 21:37:17 AST-0400'

If I get now time from this as utc it is correct
dt = dt.astimezone(UTC)
# '2005-12-12 01:37:17 UTC+'

If I do a different timezone of 'America/Vancouver'
I get something appropriate for the 2:30 case

tz = pytz.timezone('America/Vancouver')
dt = datetime(year=2005, month=12, day=12, hour=14, minute=30, second=0, 
microsecond=0, tzinfo=tz)
print dt.strftime(fmt)
# 2005-12-12 20:30:00 PST-0800

I am not sure why I am getting  -0414 and LMT for 'America/Halifax' 
timezone? Is this a bug in the pytz package? Many thanks.

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


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

2005-12-13 Thread Fredrik Lundh
Duncan Booth wrote:

> A better way to do this (given that HTML defines exactly which attributes
> do not take a value) is to use the attribute name and simply generate the
> attribute only if the value is non-false.

another approach (which may or may not be suitable in this case) is to
use the presence of an attribute in the dictionary as an indication that
it should be included in the file, and use the special value None to mean
that it should be minimized.

yet another approach is to use an existing HTML serialization library, and
do whatever they do.





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


Re: I want a Python Puppy !

2005-12-13 Thread Diez B. Roggisch
> Knoppix failed to access my USB ports and it comes with Python 2.3 and I
> am using already Python 2.4.2 .

In the current c't there is an article how to customize knoppicilin, the
knoppix-based antivirus distribution. I didn't have a deeper look so far,
but I'm eager to see if that couldn't be used to create special
distriubutions for e.g. gnome-meeting based vid-conferencing, or a
python-super-developer-distribution :)
-- 
Regards,

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


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

2005-12-13 Thread Antoon Pardon
Op 2005-12-13, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Op 2005-12-13, Steve Holden schreef <[EMAIL PROTECTED]>:
>> 
>>>Pierre Quentel wrote:
>>>
Hi all,

In some program I was testing if a variable was a boolean, with this 
test : if v in [True,False]

My script didn't work in some cases and I eventually found that for v = 
0 the test returned True

So I changed my test for the obvious "if type(v) is bool", but I still 
find it confusing that "0 in [True,False]" returns True

By the way, I searched in the documentation what "obj in list" meant and 
couldn't find a precise definition (does it test for equality or 
identity with one of the values in list ? equality, it seems) ; did I 
miss something ?

>>>
>>>It actually uses the __contains__() method of the right-hand operand, 
>>>and in the case of a list that will test for equality of the left-hand 
>>>operand to one of the list elements. Since False == 0 that's why you see 
>>>what you do.
>>>
>>>The really interesting question your post raises, though, is "Why do you 
>>>feel it's necessary to test to see whether a variable is a Boolean?".
>> 
>> 
>> I can give you one example. I have written a tube class. A tube behaves
>> like Queue but it has additional code so that it can be registed with
>> gtk in the same way as file descriptor can be registered with
>> io_add_watch. The way this is implemented is by registering an idle
>> handler when the tube is not empty and removing it when the tube is
>> empty. So I have a variable cb_src (for callback source) that can be
>> a boolean or an integer. The possible values are
>> 
>>   False: Not registered by the user
>>   True: Registered by the user but no nternal idle callback registerd
>>   a number: gtk integer ID, from the registered idle callback handler.
>> 
> Well I guess you'd better hope that gtk never returns a zero or one, then.

Why? It won't break my code.

> Note, though, that True and False are defined to be singleton instances, 
> so it *is* permissible to say
>
>  if i is False:
>
> >>> 0 is False
> False
> >>> 1 is True
> False
> >>>
>
> However I must say the coupling in that interface has a very definite 
> code smell. Why not use two variables, a Boolean "registered" and an 
> integer ID that is meaningless when registered is False?

Because the integer ID can be meaningless when registered is True.
If I should use two variables, the "registered" variable should
be a three value variable. Something like:

  0: Not registered by the user
  1: Registered by the user but no internal idle callback registerd
  2: internal idle callback registerd

Only in the last case is the integer ID meaningfull. But IMO I buy
nothing buy seperating the information over two variables. Checking
whether the "registered" variable is 2 or not, doesn't buy me
anything over checking whether the cb_src is of BooleanType or
not.

And having the information in one variable means I have to worry
less about synchronisation. If I register the internal idle
handler I just store its ID in cb_src, without having to worry
about another variable that has to be set right.

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


Re: IsString

2005-12-13 Thread Steven D'Aprano
On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:

[snippidy-doo-dah]

> I had the same thought, but reread the post.  He asks "if a given
> variable is a character or a number".  I figured that even if he
> is coming from another language he knows the difference between
> "a given variable" and the "contents of a give variable".  I guess
> we will see ;-).  This list is so good, he gets BOTH questions
> answered.

The problem is, Python doesn't have variables (although it is
oh-so-tempting to use the word, I sometimes do myself). It has names in
namespaces, and objects. 

It be a subtle difference, but an important one. That's why, for instance,
Python is neither call by reference nor call by value, it is call by
object.



-- 
Steven.

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-13 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Zeljko Vrba wrote:

> Actually, after I learned Python, I value "funny squiggles" in other
> languages even more. It's very annoying, for example, that I can't split
> a long line in the following way:
> 
> print a + b + 
>   c + d
> print "other statement"
> 
> I guess I'm required to insert some unneccessary () around the long expression
> to disable the white space parsing..

They are not unneccesary.  At least not in Python.  Unless you use the
line continuation with trailing '\' which is a bit uglier than parenthesis
(IMHO).

And you want to trade occasional parenthesis for mandatory curly braces? I
guess it leads to much more braces or other explicit end markers for suits
than the few "unneccessary" parenthesis one has to use to group long
expressions.

Ciao,
Marc 'BlackJack' Rintsch.

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


Re: IsString

2005-12-13 Thread Gary Herron
Tuvas wrote:

>I need a function that will tell if a given variable is a character or
>a number. Is there a way to do this? Thanks!
>
>  
>
In Python, all values have an associated type which you can query with 
type(v) thus:

  from types import *

  if type(v) == IntType:
  ... whatever ...

Several types would qualify as "numbers":  IntType, FloatType, LongType, 
and ComplexType,
and several as "strings":  StringType and UnicodeType

Gary Herron

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


Re: Python is incredible!

2005-12-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Tom Anderson  <[EMAIL PROTECTED]> wrote:
>On Mon, 12 Dec 2005, Cameron Laird wrote:
>
>> While there is indeed much to love about Lisp, please be aware
>> that meaningful AI work has already been done in Python
>
>Wait - meaningful AI work has been done?
.
.
.
I richly deserved that.  As penance, I follow-up
with http://www.robotwisdom.com/ai/ >.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want a Python Puppy !

2005-12-13 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Diez" == Diez B Roggisch <[EMAIL PROTECTED]> writes:
Diez> In the current c't there is an article how to customize
Diez> knoppicilin, the knoppix-based antivirus distribution. I didn't
Diez> have a deeper look so far, but I'm eager to see if that couldn't
Diez> be used to create special distriubutions for e.g. gnome-meeting
Diez> based vid-conferencing, or a python-super-developer-distribution
Diez> :)

I'll shortly be announcing the public availability of Pynux... :-)

Seriously, though, I can see the sense in having 'live' CD distros
specialised for antivirus (or general rescue/sysadmin work), video
conferencing and stuff like that, but what would be the reasoning for
a Python specific distro, or indeed any special development needs? To
me it seems that a general-purpose distro with whatever development
tools the individual programmer needs is going to be a perfect fit.
Any specialised development distro sounds like specialisation for its
own sake to me.

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOevbkACgkQYu1fMmOQldWE6gCcDGcwD3mm1ucRgOEYS+N8NmWQ
w9MAnixGhwJYvSU1jp4pk3Dnm7jaQC45
=+E+a
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IsString

2005-12-13 Thread Duncan Booth
Gary Herron wrote:

> In Python, all values have an associated type which you can query with 
> type(v) thus:
> 
>   from types import *
> 
>   if type(v) == IntType:
>   ... whatever ...
> 
> Several types would qualify as "numbers":  IntType, FloatType, LongType, 
> and ComplexType,
> and several as "strings":  StringType and UnicodeType

This is bad practice on so many levels...

If you really do need to test for a type use isinstance, not 
'type(v)==something'.

You didn't need to import any of those types from types: they are all 
builtins albeit under different names.

If you really must:

   if isinstance(v, (int, float, long, complex)):
  ...

or for strings use the base type:

   if isinstance(v, basestring):
  ...
-- 
http://mail.python.org/mailman/listinfo/python-list


How do i read line from an input file, without the /n

2005-12-13 Thread doritrieur
How do i read line from an input file, without the /n ?
the readline function returns also the /n character at the end. i need
to read a line without the training /n
is this possible?

thanks, Dorit

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


Re: How do i read line from an input file, without the /n

2005-12-13 Thread Aggelos Orfanakos
f.readline().rstrip('\n') should do it. If you are sure that lines
always end in '\n', then you could even use f.readline()[:-1]

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


Re: How do i read line from an input file, without the /n

2005-12-13 Thread Fredrik Lundh
"doritrieur" <[EMAIL PROTECTED]> wrote:

> How do i read line from an input file, without the /n ?
> the readline function returns also the /n character at the end. i need
> to read a line without the training /n

so strip if off!

line = line[:-1] # remove last char

see also:

http://www.python.org/doc/faq/programming.html#is-there-an-equivalent-to-perl-s-chomp-for-removing-trailing-newlines-from-strings

 



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


writing IM bots

2005-12-13 Thread Amit Khemka
Hello,
I am trying to write an IM Bot, which automatically replies to a
message, in Python.
I was wondering If there are python modules for connecting to Yahoo!,
msn networks ...
ideally I would like to have a multithreaded module.

This is one I found for msn, if anyone has used it please comment,
- http://users.auriga.wearlab.de/~alb/msnlib/

cheers,
amit.


--

Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want a Python Puppy !

2005-12-13 Thread Magnus Lycka
Claudio Grondi wrote:
> I have just discovered the existance of Puppy Linux which is a complete 
> operating  system with a suite of GUI apps,  only about 50 - 60M booting 
> directly off the CDROM ( http://www.puppylinux.org ).
> 
> This approach appears to me very Pythonic, so it were a nice thing to 
> have a full featured Puppy Linux Live CD prepared for Python programming.
> 
> Have someone already breed a Python Puppy and is so kind to share a copy 
> of it with me?

I think the Ubuntu Live CD has a lot of Python thingies, but it's
much bigger than 50-60MB. That hardly matters if you intend to use
a CD, but it might not fit on a cheap USB memory...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sql using characters like é and ã

2005-12-13 Thread Magnus Lycka
Diez B. Roggisch wrote:
> "Select * from table where name like '%s%%'" %
> "José".decode("latin-1").encode("utf-8")

Ouch! Please use parameter passing instead of building full SQL
statements with embedded parameter values. You're opening up for
SQL injection attacks if you allow user provided input in SQL code.

Imagine that instead of "José", you had gotten
"';DELETE FROM TABLE;SELECT * FROM TABLE WHERE NAME LIKE='"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pattern matching with string and list

2005-12-13 Thread BartlebyScrivener
Taking you literally, I'm not sure you need regex. If you know or can
find position n, then can't you just:

sentence = "the color is $red"
patterns = ["blue","red","yellow"]
pos = sentence.find("$")
for x in patterns:
if x==sentence[pos+1:]:
print x, pos+1

But maybe I'm oversimplifying.

rpd

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


Re: Developing a network protocol with Python

2005-12-13 Thread Lawrence Oluyede
Il 2005-12-12, Laszlo Zsolt Nagy <[EMAIL PROTECTED]> ha scritto:
>
>   Hello,
>
> I would like to develop a new network protocol, where the server and the 
> clients are Python programs.

You should use Twisted for this:

Writing clients
http://twistedmatrix.com/projects/core/documentation/howto/clients.html

Writing servers
http://twistedmatrix.com/projects/core/documentation/howto/servers.html


> I think to be effective, I need to use TCP_NODELAY, and manually 
> buffered transfers.
> I would like to create a general messaging object that has methods like
>
> sendinteger
> recvinteger
> sendstring
> recvstring

You can inherit from twisted.internet.protocol.Protocol or one of its
subclasses, they handle buffering and all sort of these things for
you. Cannot have to reinvent the wheel.

> To be more secure, I think I can use this loads function to transfer 
> more elaborate python stuctures:
>
> def loads(s):
> """Loads an object from a string.
>
> @param s: The string to load the object from.
> @return: The object loaded from the string. This function will not 
> unpickle globals and instances.
> """
> f = cStringIO.StringIO(s)
> p = cPickle.Unpickler(f)
> p.find_global = None
> return p.load()

Using untrusted pickle loading is *NOT* more secure:
http://www.python.org/doc/2.2.3/lib/pickle-sec.html
and
http://www.livejournal.com/users/jcalderone/15864.html


-- 
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: PythonWin troubleshooting

2005-12-13 Thread Colin J. Williams
chuck wrote:
> Build 205 for the win32 ext.
> 
I have been having similar problems with build 205.

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


Re: Question about start using ZServerSSL on win box...

2005-12-13 Thread Thomas G. Apostolou
After reading and searching for a while i found that all about running
ZService as service start from C:\Program Files\Plone
2\Data\bin\zopeservice.py
But still i cannot fully understand where the server is called so that i
replace it with z2s.py or what ever needed...
Any ideas?

"Thomas G. Apostolou" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello all,
>
> Dear Ng Pheng Siong,
> thank you for your great job with M2Crypto.
>
> I have got and build 0.15 version on a win xp box recently and was reading
> your "ZServerSSL HOWTO" document so that i can start using https,
> xmlprc-over-https etc.
>
> I have to tell that i have installed from Plone 2.0.5 binary for windows
> witch comes with Zope 2.7.0 and Python 2.3.3 (i have patched
> SimpleHTTPServer.py as corrected for 2.3.5).
>
> As reading your "ZServerSSL HOWTO" i suppose that the corresponding $ZOPE
is
> my "C:\Program Files\Plone 2\Zope\lib\python" because only there i can
find
> $ZOPE/ZServer. Correct me if i am wrong with this...
>
> What i also need to know is that since i have installed so that Zope
server
> runs as a service what is the corresponding steps for me in the section
> where you say :
>
>   1.. Copy $ZSSL/z2s.py into $ZOPE.
>
>   2.. Depending on your operating system, modify $ZOPE/start or
> $ZOPE/start.bat to invoke $ZOPE/z2s.py, instead of $ZOPE/z2.py. The files
> $ZSSL/starts and $ZSSL/starts.bat serve as examples.
>
> I do not have any $ZOPE/start or $ZOPE/start.bat or $ZOPE/z2.py, i only
have
> a file named PythonService.exe into "C:\Program Files\Plone 2\Zope\bin"
>
> Do i HAVE to reinstall Plone and set it not to run as service?
>
> Thank you in advance...
>
> Thomas G. Apostolou
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


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

2005-12-13 Thread Chris Mellon
On 13 Dec 2005 11:29:10 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> Op 2005-12-13, Steve Holden schreef <[EMAIL PROTECTED]>:
> > Antoon Pardon wrote:
> >> Op 2005-12-13, Steve Holden schreef <[EMAIL PROTECTED]>:
> >>
> >>>Pierre Quentel wrote:
> >>>
> Hi all,
> 
> In some program I was testing if a variable was a boolean, with this
> test : if v in [True,False]
> 
> My script didn't work in some cases and I eventually found that for v =
> 0 the test returned True
> 
> So I changed my test for the obvious "if type(v) is bool", but I still
> find it confusing that "0 in [True,False]" returns True
> 
> By the way, I searched in the documentation what "obj in list" meant and
> couldn't find a precise definition (does it test for equality or
> identity with one of the values in list ? equality, it seems) ; did I
> miss something ?
> 
> >>>
> >>>It actually uses the __contains__() method of the right-hand operand,
> >>>and in the case of a list that will test for equality of the left-hand
> >>>operand to one of the list elements. Since False == 0 that's why you see
> >>>what you do.
> >>>
> >>>The really interesting question your post raises, though, is "Why do you
> >>>feel it's necessary to test to see whether a variable is a Boolean?".
> >>
> >>
> >> I can give you one example. I have written a tube class. A tube behaves
> >> like Queue but it has additional code so that it can be registed with
> >> gtk in the same way as file descriptor can be registered with
> >> io_add_watch. The way this is implemented is by registering an idle
> >> handler when the tube is not empty and removing it when the tube is
> >> empty. So I have a variable cb_src (for callback source) that can be
> >> a boolean or an integer. The possible values are
> >>
> >>   False: Not registered by the user
> >>   True: Registered by the user but no nternal idle callback registerd
> >>   a number: gtk integer ID, from the registered idle callback handler.
> >>
> > Well I guess you'd better hope that gtk never returns a zero or one, then.
>
> Why? It won't break my code.
>
> > Note, though, that True and False are defined to be singleton instances,
> > so it *is* permissible to say
> >
> >  if i is False:
> >
> > >>> 0 is False
> > False
> > >>> 1 is True
> > False
> > >>>
> >
> > However I must say the coupling in that interface has a very definite
> > code smell. Why not use two variables, a Boolean "registered" and an
> > integer ID that is meaningless when registered is False?
>
> Because the integer ID can be meaningless when registered is True.
> If I should use two variables, the "registered" variable should
> be a three value variable. Something like:
>
>   0: Not registered by the user
>   1: Registered by the user but no internal idle callback registerd
>   2: internal idle callback registerd
>
> Only in the last case is the integer ID meaningfull. But IMO I buy
> nothing buy seperating the information over two variables. Checking
> whether the "registered" variable is 2 or not, doesn't buy me
> anything over checking whether the cb_src is of BooleanType or
> not.
>
> And having the information in one variable means I have to worry
> less about synchronisation. If I register the internal idle
> handler I just store its ID in cb_src, without having to worry
> about another variable that has to be set right.
>

This is the sort of horrible smelly wretchedness that makes me gag in
C. Bearing in mind that you of course are free to write your code in
whatever way you want, and I'm not your boss, this is horrible and
shouldn't be considered something to be catered for.

First and most importantly, you're replacing a literate,
self-documenting mechanism with an obtuse one.

if self.userRegisteredCallback:

is much, much better than

if type(self.callback) is bool:


If you have a consistent API and you're checking for error values from
your GTK functions, then you already have a lot more code than using 2
varaibles will cost you. 10 lines, maybe.

The fact that you think setting two variables is "too hard" but you're
perfectly happy with checking for boolean types instead just testing
truth values I think is a real problem. You aren't saving yourself any
performance. You're barely even saving yourself any typing, and you're
making your code (intentionally, it seems) that much more compllicated
and hard to understand.

Granted, of course, it's your code. But I wouldn't accept it in
anything I was in charge of.


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


Re: PythonWin troubleshooting

2005-12-13 Thread chuck
Sticking with 2.4.2 I reverted to win32 ext 204 and problems were the
same or worse.  Then I uninstalled both, removed the dangling py*24.dll
and then installed "ActivePython 2.3.5.236".  All the problems went
away.

I hate to go back to 2.3 cause there are some nice updates in the 2.4
library that I'd like to have.  Time permitting I'll try other versions
of various windows distributions and let you know the outcome.  I'd be
interested in hearing more from other folks who may or may not be
experiencing similar problems.

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


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

2005-12-13 Thread bonono

Chris Mellon wrote:
> Granted, of course, it's your code. But I wouldn't accept it in
> anything I was in charge of.
>
That says it all. It is his code, whether you would accept it means
nothing. If you can point out that it is functionally wrong, it may
mean something. Otherise, it is nothing more than "I prefer it this
way". It may be hard to understand, hard to maintain(probably by
others, probably by him a few years down the road) but no one(other
than him) knows what the program is about so whether it needs to be
touched again.

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


Re: newbie: generate a function based on an expression

2005-12-13 Thread Jacob Rael
Overall I am trying to learn OOP by porting
CppSim (http://www-mtl.mit.edu/~perrott) to Python.

In CppSim, classes are defined that allow various functions to be
defined, like amplifiers. In some cases they are linear:

y = A*x

some have offsets:

y = A*x + off

some are non-linear

y = A*x - C*x**3

The coefficients and the function will remain constant once the
function is defined.

I read about the security concerns involved in using eval(). I don't
expect this project to grow to the point where I require a web
interface. However, since I am learning, I might as well learn the
right way.

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


Re: newbie: generate a function based on an expression

2005-12-13 Thread Jacob Rael
Another example is a filter. From the CppSim doc:

Filter filt("1+1/(2*pi*fz)s","C3*s +
C3/(2*pi*fp)*s^2","C3,fz,fp,Ts",1/gain,fz,fp,Ts);

jr

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


Re: Developing a network protocol with Python

2005-12-13 Thread Lawrence Oluyede
Il 2005-12-13, Laszlo Zsolt Nagy <[EMAIL PROTECTED]> ha scritto:
> I need to send Python objects too. They are too elaborate to convert 
> them to XML. (They are using cyclic weak references and other Python 
> specific stuff.) I can be sure that on both sides, there are Python 
> programs. Is there any advantage in using XML if I already need to send 
> Python objects? Those objects cannot be represented in XML, unless 
> pickled into a CDATA string.

If you have to send Python objects over the wire the best way is to have
twisted on both ends and use twisted's PerspectiveBroker, see:
http://twistedmatrix.com/projects/core/documentation/howto/pb-intro.html



-- 
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-13 Thread bonono

Magnus Lycka wrote:
> The static typing means that you either have to make several
> implementations of many algorithms, or you need to work with
> those convoluted templates that were added to the language as
> an afterthought.
I don't see this in Haskell.

> While feature-by-feature comparisions of different
> programming languages might have some merit, the only
> thing that counts in the end is how the total package
> works... I think you'll find that Python is a useful
> package, and a good tool in a bigger tool chest.
That is very true.

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


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

2005-12-13 Thread Antoon Pardon
Op 2005-12-13, Chris Mellon schreef <[EMAIL PROTECTED]>:
>> > However I must say the coupling in that interface has a very definite
>> > code smell. Why not use two variables, a Boolean "registered" and an
>> > integer ID that is meaningless when registered is False?
>>
>> Because the integer ID can be meaningless when registered is True.
>> If I should use two variables, the "registered" variable should
>> be a three value variable. Something like:
>>
>>   0: Not registered by the user
>>   1: Registered by the user but no internal idle callback registerd
>>   2: internal idle callback registerd
>>
>> Only in the last case is the integer ID meaningfull. But IMO I buy
>> nothing buy seperating the information over two variables. Checking
>> whether the "registered" variable is 2 or not, doesn't buy me
>> anything over checking whether the cb_src is of BooleanType or
>> not.
>>
>> And having the information in one variable means I have to worry
>> less about synchronisation. If I register the internal idle
>> handler I just store its ID in cb_src, without having to worry
>> about another variable that has to be set right.
>>
>
> This is the sort of horrible smelly wretchedness that makes me gag in
> C. Bearing in mind that you of course are free to write your code in
> whatever way you want, and I'm not your boss, this is horrible and
> shouldn't be considered something to be catered for.
>
> First and most importantly, you're replacing a literate,
> self-documenting mechanism with an obtuse one.
>
> if self.userRegisteredCallback:
>
> is much, much better than
>
> if type(self.callback) is bool:

Well either your self-documenting code is not that obvious or
your code doesn't make the same disctinction than the one
you want to replace it with.

And if you want self documenting code then I guess I could rewrite
it as follows

if type(self.callback) is not GtkID:

> If you have a consistent API and you're checking for error values from
> your GTK functions, then you already have a lot more code than using 2
> varaibles will cost you. 10 lines, maybe.
>
> The fact that you think setting two variables is "too hard" but you're
> perfectly happy with checking for boolean types instead just testing
> truth values I think is a real problem.

These aren't just truth values. If I would have to go split in 
meaningfull truth values I would need at least three variables.

> You aren't saving yourself any
> performance. You're barely even saving yourself any typing, and you're
> making your code (intentionally, it seems) that much more compllicated
> and hard to understand.

There is nothing complicated or hard to understand.

I find it odd that each time declaration are mentioned people here
react very rejecting and say that one of the features they love
about python is the freedom that a name is not limited to a variable
of one type, while when someone makes use of that freedom labeling
such code as code smell.

But lets make an effort to make the code more readable. What
about the following suggestion. I use a kind of EnumType with
two values: NotRegistered and Registerd. And the name of the
type is NotConnected. So I can then write

  if type(self.callback) is NotConnected.

Would that be selfdocumenting enough for you?

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


Re: writing IM bots

2005-12-13 Thread Josef Meile
Hi,

> I am trying to write an IM Bot, which automatically replies to a
> message, in Python.
> I was wondering If there are python modules for connecting to Yahoo!,
> msn networks ...
> ideally I would like to have a multithreaded module.
> 
> This is one I found for msn, if anyone has used it please comment,
> - http://users.auriga.wearlab.de/~alb/msnlib/
I haven't used that, but it looks cool ;-)

If you are interested in yahoo, then here is another python application
to connect to the yahoo messenger:

http://www.nongnu.org/curphoo/

Again, I haven't tried that one, but perhaps you could just test it.

I have other links to tools based in the libyahoo2[1] package, but
unfortunately all are written in C or java. Perhaps you could find a
python wrapper in google.

Regards,
Josef


[1] http://libyahoo2.sourceforge.net

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


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

2005-12-13 Thread Grant Edwards
On 2005-12-13, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Fredrik Lundh wrote:
>> [EMAIL PROTECTED] wrote:
>>
>> > > but seriously, unless you're writing an introspection tool, testing for
>> > > bool is pretty silly.  just use "if v" or "if not v", and leave the rest 
>> > > to
>> > > Python.
>> > >
>> > The OP's code(and his work around) doesn't look like he is testing for
>> > boolean
>>
>> which of course explains why he wrote
>>
>> In some program I was testing if a variable was a boolean
>>
>> in the post I replied to...
>>
>> > but more like the data type of something. I thought there is some idiom
>> > in python which said something like "don't assume" ?
>>
>> "think before you post" ?
>>
> Don't know what you mean.
>
> He seems to be testing "boolean type", not whether it is true
> or false.

Right.  But that's almost always pointless.  Knowing whether a
variable is a boolean or not is very rarely useful.  What one
wants to know is whether a varible is true or not. The code for
that is:

  if v:
  something

  if not v:
  something  

-- 
Grant Edwards   grante Yow!  My DIGITAL WATCH
  at   has an automatic SNOOZE
   visi.comFEATURE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda (and reduce) are valuable

2005-12-13 Thread Christopher Subich
Chris Mellon wrote:
> functions with real names is crucial to maintainable code. The only
> reason to ever use a lamdba in Python is because you don't want to
> give a function a name, and that is just not a compelling use case for
> GUI events.

Ah, but that neglects the sheer utility of delayed-evaluation 
expressions.  Consider the key= parameter to list.sort, et. al:

complicated_list.sort(key=lambda x: x[3])

Decorate-sort-undecorate is another way of doing this, but it's also 
boilerplate, involves list copies that have nothing to do with the flow 
of the program itself, and can possibly error (if done naively: key is 
comparable, but complex_list[i][0] isn't comparable, such as sorting a 
list of complex numbers by the real part, if two or more items have the 
same real).

The key= parameter was implemented just to make this sort of thing 
clearer and easier (and, in an odd way, actually more semantically 
explicit).  The utility of a full function for the key= is nice and 
necessary, but simultaneously a lot of the uses are going to be for 
one-off expressions (like item[3]).  There, the idea of a named function 
seems conceptual overkill.

The most significant problem with Python's lambda is that it's billed as 
an anonymous function, when it's really an encapsulated expression.  My 
preferred solution is to replace lambda with something along the lines 
of an 'expression comprehension,' with similar syntax to list and 
generator comprehensions as-is:

lambda param1, param2: stuff_with(param2,param1) would become

<(param1, param2): stuff_with(param2, param1)>
or, to become even more similar to comprehension syntax:


The only real problem, parsing-wise, with this syntax is that it can 
sometimes conflict with the << or >> operators if used without 
whitespace near comparisons.

The scope of what can be contained in the expression comprehension 
(lambda currently) is exactly the same as what can be contained in a 
list/generator comprehension, so why not capitalize on the parallelism?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sql using characters like é and ã

2005-12-13 Thread tjerk
I will try it with the "José".decode("latin-1").encode("utf-8")
Utf-8 is the same as Unicode?
Herdsman again

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


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

2005-12-13 Thread Grant Edwards
On 2005-12-13, Paul Rubin <> wrote:
> Steve Holden <[EMAIL PROTECTED]> writes:

>> The really interesting question your post raises, though, is
>> "Why do you feel it's necessary to test to see whether a
>> variable is a Boolean?".
>
> What's the point of having Booleans, if you can't tell them
> from integers?

You _can_ tell them from integers.  The point is that thinking
you need to in "normal" code is usually wrong.  Or at least
unpythonic.

-- 
Grant Edwards   grante Yow!  It's NO USE... I've
  at   gone to "CLUB MED"!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IsString

2005-12-13 Thread Tuvas
LOL. As to me being a newbie to programming, well, I've been
programming to some extent for the last 10 years, although never
professionally. The first few questions were enough to help me solve
the problem that I had. And I've been programming Python for 4 months
or so, but it's been pretty intense, my current code is about 1000
lines or so for the program that I am doing. The reason I had this need
is basically trying to correct a mistake that I had made, sometime I
passed a function characters, other times I passed it numbers, and I
needed to have one uniform system. But, after a while, I found that I
really didn't need this uniformed system, so I was alright. But, thanks
for all of our help!

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


Re: IsString

2005-12-13 Thread Tom Anderson
On Tue, 13 Dec 2005, Steven D'Aprano wrote:

> On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
>
> [snippidy-doo-dah]
>
>> I had the same thought, but reread the post.  He asks "if a given 
>> variable is a character or a number".  I figured that even if he is 
>> coming from another language he knows the difference between "a given 
>> variable" and the "contents of a give variable".  I guess we will 
>> see ;-).  This list is so good, he gets BOTH questions answered.
>
> The problem is, Python doesn't have variables (although it is 
> oh-so-tempting to use the word, I sometimes do myself). It has names in 
> namespaces, and objects.

In what sense are the names-bound-to-references-to-objects not variables?

> It be a subtle difference, but an important one.

No, it's just spin, bizarre spin for which i can see no reason. Python has 
variables.

> That's why, for instance, Python is neither call by reference nor call 
> by value, it is call by object.

No, python is call by value, and it happens that all values are pointers. 
Just like java, but without the primitive types, and like LISP, and like a 
load of other languages. Python's parameter passing is NO DIFFERENT to 
that in those languages, and those languages are ALL described as 
call-by-value, so to claim that python does not use call-by-reference but 
some random new 'call-by-object' convention is incorrect, unneccessary, 
confusing and silly.



I'm sure this has been argued over many times here, and we still 
all have our different ideas, so please just ignore this post!

tom

-- 
So the moon is approximately 24 toasters from Scunthorpe.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-12-13 Thread bonono

Grant Edwards wrote:
> > He seems to be testing "boolean type", not whether it is true
> > or false.
>
> Right.  But that's almost always pointless.  Knowing whether a
> variable is a boolean or not is very rarely useful.  What one
> wants to know is whether a varible is true or not. The code for
> that is:
>
>   if v:
>   something
>
>   if not v:
>   something
>
He doesn't want to know whether a variable is true or not, but whether
it is a boolean value. He seems to use the same variable to store both
boolean value, as well as other data type(see another post by OP) for
distinct meaning. Whether this is a good design is another matter and
debatable. Within Python, I think it is not needed as 1/0 and
True/False are basically interchangeable no matter where it is used.

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


Re: Python is incredible!

2005-12-13 Thread Tom Anderson
On Mon, 12 Dec 2005, Xavier Morel wrote:

> Luis M. Gonzalez wrote:
>
>> You are not the first lisper who fell inlove with Python...
>> Check this out:
>> http://www.paulgraham.com/articles.html
>
> Paul Graham is not in love with Python though, he's still very much in love 
> with Lisp.
>
> He merely admits being unfaithful to Lisp from time to time (and clearly 
> states that Python is one of the non-Lisp languages he likes best).

Oh come on - he loves LISP but he plays away with python every chance he 
gets? What he has with LISP is a hollow sham - he's only keeping up the 
pretense for the children.

;)

tom

-- 
So the moon is approximately 24 toasters from Scunthorpe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sql using characters like é and ã

2005-12-13 Thread fumanchu
Diez B. Roggisch wrote:
> "Select * from table where name like '%s%%'" %
> "José".decode("latin-1").encode("utf-8")

Make it easy on yourself and encode the whole statement:

conn.execute(query.encode('utf8'))


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

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


Re: Python Graph API

2005-12-13 Thread Steven Bethard
Nathan Gilbert wrote:
> Has there been any work done lately on the Python Graph API? 

Well there doesn't really seem to be a standard one.  The wiki was last 
updated in August.

 http://wiki.python.org/moin/PythonGraphApi

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


Re: Python is incredible!

2005-12-13 Thread Tom Anderson
On Tue, 13 Dec 2005, Cameron Laird wrote:

> In article <[EMAIL PROTECTED]>,
> Tom Anderson  <[EMAIL PROTECTED]> wrote:
>> On Mon, 12 Dec 2005, Cameron Laird wrote:
>>
>>> While there is indeed much to love about Lisp, please be aware
>>> that meaningful AI work has already been done in Python
>>
>> Wait - meaningful AI work has been done?
>
> I richly deserved that.  As penance, I follow-up with  http://www.robotwisdom.com/ai/ >.

I think that document actually sells AI a little short: it's true that 
little progress has been made with language or reasoning, but vision's 
actually done rather well; the recent winning of the Grand Challenge drive 
across the Mojave is proof of that.

But then, i don't think AI was ever really the goal of the AI movement - 
it was basically a time when DARPA gathered together smart, curious 
people, and threw torrents of resources at them to use as they pleased. We 
didn't get AI out of it, but we did get a hell of a lot of cool stuff. It 
was a bit like the Apollo programme, but without the air force dudes 
planting flags at the end. An AI refugee, who worked at SAIL in the 70s, 
recently told me "AI was always just a sandpit, now it's become a tarpit 
the clever people have moved on" - because it was the environment and the 
opportunity to do neat stuff, rather than AI per se, that drove them.

tom

-- 
So the moon is approximately 24 toasters from Scunthorpe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Still Loving Python

2005-12-13 Thread Kamilche
I switched to Python a couple years ago, and haven't looked back. I've
used Python for many applications, including several commercial plugins
for Poser. I don't post on here much, because I don't need to; working
in Python is so obvious and easy, it's rare that I get stumped by the
limitations and need help from others. I sometimes read the group to
help others, but not very often. I just wanted to let you all know that
I'm still here, and even though I'm not vocal, I DO still use Python on
a daily basis.

Python still suffers from the lack of a good GUI, which I believe is
slowing its acceptance by the programming community at large. (I know
about tKinter, no need to post links to it, thanks.)

--Kamilche

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


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

2005-12-13 Thread Mike Meyer
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:
> Duncan Booth wrote:
>> > For HTML attributes that don't have an explicit value (such as the
>> > SELECTED attribute in OPTION) the keyword argument to the function must
>> > have the value True
>> A better way to do this (given that HTML defines exactly which attributes
>> do not take a value) is to use the attribute name and simply generate the
>> attribute only if the value is non-false.
> footnote: strictly speaking, minimized attributes have values but no names;
> it's up to the parser to determine what attribute you're setting when you
> specify the value.
> (for example, in , "ismap" is the value, not the attribute name.
> it's up to the parser to figure out (from the DTD) that this value can only
> be used by the "ismap" attribute, and interpret it as )

But this isn't necessarilly true:  is perfectly legal.
I would say that ismap only has one valid value - "ismap", so the
parser knows that it should interepret a bare "ismap" as ismap=ismap,
which gets you the same behavior in the end.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want a Python Puppy !

2005-12-13 Thread Claudio Grondi
Magnus Lycka wrote:
> Claudio Grondi wrote:
> 
>> I have just discovered the existance of Puppy Linux which is a 
>> complete operating  system with a suite of GUI apps,  only about 50 - 
>> 60M booting directly off the CDROM ( http://www.puppylinux.org ).
>>
>> This approach appears to me very Pythonic, so it were a nice thing to 
>> have a full featured Puppy Linux Live CD prepared for Python programming.
>>
>> Have someone already breed a Python Puppy and is so kind to share a 
>> copy of it with me?
> 
> 
> I think the Ubuntu Live CD has a lot of Python thingies, but it's
> much bigger than 50-60MB. That hardly matters if you intend to use
> a CD, but it might not fit on a cheap USB memory...

Ubuntu Live CD comes directly with Python 2.4.2. Ubuntu was able to use 
  mainboards (ASUS P4P800-SE) onboard sound out of the box and to write 
files to USB stick. I have some trouble to understand how Python works 
on it because it is not organized as on Windows (e.g. there is no [Lib] 
directory under the [Python2.4] one) and I failed to start Idle (can't 
access idlelib) after a longer time of searching for a  file to start 
it. At least the Python command line runs when I type  \>python  in the 
console window and some of the Tkinter examples run too.
Compared to Suse installation DVD full packed with data, Ubuntu Linux is 
limited to a CD - I don't have enough experience to tell if it good or 
bad, but it seems, that Ubuntu supports less software packages then 
Suse. Does it matter, when one has the option to install software by 
compiling source code distributions?

Currently Ubuntu is my favorite, because it seems to be at the moment 
the only Linux distribution supporting already Python 2.4.2 out of the 
box, so maybe it is worth to dig deeper into it for the purpose of 
installing it on a harddrive. Anyone here who uses Ubuntu for developing 
larger Python projects?

Inbetween I was also told 
(http://www.murga.org/~puppy/viewtopic.php?t=4612), that Python for 
Puppy Linux "is available in the grafpup package repositories (try 
googling grafpup). Install it as an alien package using pupget.", so 
there seems to be Python 2.4.2 
(ftp://grafpup.com/packages/python-2.4r2.tar.gz) support in Puppy Linux.

But that is not what I was looking for - it can only serve as a starting 
point for building a Python Puppy Live CD/DVD distribution myself. 
Probably I have much to try and learn before I can start on it and 
succeed, so "I want a Python Puppy" is still open for beeing provided.

My vision is to have a Python Puppy DVD, i.e. 4 GByte of files with the 
entire Python environment and another software tools I could use on 
almost any PC to continue work on Python projects stored on an USB 
stick. This would make my programming environment mobile without the 
need of carrying a notebook/laptop with me (a DVD and a USB stick should 
be enough to be mobile in the todays world, where it is so easy to get 
access to a PC).

I can only hardly believe, that there is none Puppy Linux derived 
Python distribution with most of the important extension modules already 
available out of the box completed to a nice package with Gimp, 
Firefox/Thunderbird, Open Office, etc., so please let me know about it 
helping this way to avoid reinventing the wheel.

I am surprized, that the Puppy kind of Linux distribution seems not to 
be popular among the users of comp.lang.python, so maybe someone can 
explain to me why it is that way to calm down my fascination before I 
put too much efforts into it in order to discover, that it is maybe a 
dead end.

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


Re: Still Loving Python

2005-12-13 Thread Lawrence Oluyede
Il 2005-12-13, Kamilche <[EMAIL PROTECTED]> ha scritto:
> Python still suffers from the lack of a good GUI, which I believe is
> slowing its acceptance by the programming community at large. (I know
> about tKinter, no need to post links to it, thanks.)

Let me say I'm not agree, I'm developing a lot of GUI based stuff in PyGTK
and I'll never look back. The API is not perfect but suits our needs. I'm
a Gnome lover and hence having Gnome-style GUIs it's awesome. Add the plus
that is easy and powerful and you have a good toolkit to work on. I think
that the same thing can be said about the QT-side (not sure about wx,
don't like it at all).

Python *does* have GUI, you only have to decide which one you prefer.

ps. the customer wants Windows as a platform, we develop on Linux using
PyGTK, postgre and sql server for some old data. This is the true power of
cross-platform :)


-- 
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: writing IM bots

2005-12-13 Thread David Wahler
Amit Khemka wrote:
> Hello,
> I am trying to write an IM Bot, which automatically replies to a
> message, in Python.
> I was wondering If there are python modules for connecting to Yahoo!,
> msn networks ...
> ideally I would like to have a multithreaded module.

I have found that the best solution is to use the Jabber protocol via
xmpppy (http://xmpppy.sourceforge.net/). It's very easy to use; once
you have it working with Jabber, you can use a Jabber to Yahoo/MSN/AIM
gateway to access all the different networks without writing code for
each one.

-- David

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


Re: Documentation suggestions

2005-12-13 Thread A.M. Kuchling
On 8 Dec 2005 08:00:25 -0800, 
BartlebyScrivener <[EMAIL PROTECTED]> wrote:
> The bulleted points in BeginnersGuide/Overview are, again, things that
> are important to programmers ("Automatic garbage collection frees you
> from the hassles of memory management" means nothing to me, even now
> after reading a Python book and several tutorials).

I've reworked Overview to use more straightforward language, and to
break out the programming-language features into a separate list.
Maybe that will help.

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


Re: PythonWin troubleshooting

2005-12-13 Thread Sibylle Koczian
chuck schrieb:
> Sticking with 2.4.2 I reverted to win32 ext 204 and problems were the
> same or worse.  Then I uninstalled both, removed the dangling py*24.dll
> and then installed "ActivePython 2.3.5.236".  All the problems went
> away.
> 
> I hate to go back to 2.3 cause there are some nice updates in the 2.4
> library that I'd like to have.  Time permitting I'll try other versions
> of various windows distributions and let you know the outcome.  I'd be
> interested in hearing more from other folks who may or may not be
> experiencing similar problems.
> 
Windows XP SP2, Python 2.4.2, win32 extensions build 205, no problem 
whatsoever. I find this on the windows extensions homepage 
(http://starship.python.net/crew/mhammond/win32/):

"MFC DLLs for Pythonwin
To run Pythonwin, you may need a copy of the Microsoft MFC DLLs.  You 
should only install these files if the install process tells you the DLL 
can not be found, or if Pythonwin fails to start due to this DLL missing.

 * For Python 2.3 the DLL is likely to already be installed - but if 
not, you can use mfc42.dll (995,383 bytes)
 * For Python 2.4, the DLL is likely to not be installed - you need 
mfc71.dll (1,060,864 bytes)

Download these files and save them to your Windows System32 directory."

The filenames are links for downloading.

If this doesn't help and nobody has better ideas: do you use PythonWin 
simply as your IDE? In that case, couldn't you return to Python 2.4.2 
and use IDLE instead of PythonWin? Doesn't print your scripts with 
syntax highlighting, which is a pity, but otherwise ok, I think.

Koczian

-- 
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-12-13 Thread Fredrik Lundh
Mike Meyer wrote:

> > (for example, in , "ismap" is the value, not the attribute name.
> > it's up to the parser to figure out (from the DTD) that this value can only
> > be used by the "ismap" attribute, and interpret it as )
>
> But this isn't necessarilly true:  is perfectly legal.
> I would say that ismap only has one valid value - "ismap", so the
> parser knows that it should interepret a bare "ismap" as ismap=ismap,
> which gets you the same behavior in the end.

I think you could have figured out what I meant, but alright, replace
value with "enumeration value".  the "alt" attribute isn't an enumeration,
and cannot be minimized.

the point is that SGML lets you say things like

"format can be one of A4, Letter, or Legal"

and then set the format simply by saying



on the other hand, this means that you cannot say things like

"paper can be one of A4, Letter, or Legal"
"pdf-size can be one of A4, Letter, or Legal"

and use minimization for these attributes.

(unless I'm missing some obscure corner of the spec, HTML only uses
attribute minimization for boolean attributes, so exactly how this is
done doesn't really matter.  I'll better go *plonk* myself now...)





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


PyQt on Mac OS X

2005-12-13 Thread Michael McGarry
Hi,

I am using the default Python installation that comes with Mac OS X
Tiger. I want to use the Qt module. How can I install the Qt module?

Qt is already installed.

Michael

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


Re: debug 'continue' does not appear to work right

2005-12-13 Thread newsposter
Ok, thanks. I see what the problem is.

I am working on an application which requires Python 2.1, but I also
installed Python 2.4.2. It appears that my path for the command-lines
is setup with 2.1 first.

Thanks,
Chris

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


Re: Still Loving Python

2005-12-13 Thread Ivan Voras
Lawrence Oluyede wrote:
> Python *does* have GUI, you only have to decide which one you prefer.
> 
> ps. the customer wants Windows as a platform, we develop on Linux using
> PyGTK, postgre and sql server for some old data. This is the true power of
> cross-platform :)

Maybe the OP really wants a GUI builder.

More than 5 years ago, i programmed in Visual Basic and Delphi and I 
still miss the wonderful ease of graphically creating the user interface 
in WYSIWYG mode. If you haven't tried it, you don't know what you're 
missing :)

I only know about Glade and similar GUI builders (Boa) and they are not 
even close to the robustness & ease of use. Are there any easy GUI 
builders for any Python-supported toolkits?

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


Re: PyQt on Mac OS X

2005-12-13 Thread Kevin Walzer
Michael McGarry wrote:
> Hi,
> 
> I am using the default Python installation that comes with Mac OS X
> Tiger. I want to use the Qt module. How can I install the Qt module?
> 
> Qt is already installed.
> 
> Michael
> 

See http://sourceforge.net/projects/pyqt-mac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Still Loving Python

2005-12-13 Thread Lawrence Oluyede
Il 2005-12-13, Ivan Voras <[EMAIL PROTECTED]> ha scritto:
> More than 5 years ago, i programmed in Visual Basic and Delphi and I 
> still miss the wonderful ease of graphically creating the user interface 
> in WYSIWYG mode. If you haven't tried it, you don't know what you're 
> missing :)

I used Delphi for some time. It's one of the best environments I've ever
used.  The point is that every toolkit works in a different way. You
cannot have one toolkit to rule them all.

> I only know about Glade and similar GUI builders (Boa) and they are not 
> even close to the robustness & ease of use. 

Boa is not my tool. Glade + Pygtk (or better Gazpacho) are.

> Are there any easy GUI 
> builders for any Python-supported toolkits?

No


-- 
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: PyQt on Mac OS X

2005-12-13 Thread Fredrik Lundh
Michael McGarry wrote:

> I am using the default Python installation that comes with Mac OS X
> Tiger. I want to use the Qt module. How can I install the Qt module?

http://pdb.finkproject.org/pdb/search.php?summary=pyqt

?





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


py2exe 0.6.3 and pyparallel 0.2

2005-12-13 Thread Hervé Broutin



I'm trying to create a .exe file under windows 
xp1.
When i run the script file an error occurs.i use ctypes 
version 0.9.6 
 
>>>running py2exe>>>*** searching for required 
modules ***>>>error: compiling 
'D:\appli\Python23\lib\site-packages\parallel\parallelioctl.py' faile
 
Cordialement, HERVE BROUTIN
 
BROUTIN HervéPort Autonome de Bordeaux152, Quai de 
Bacalan33082 BORDEAUX CedexTel : 05 56 90 59 73Fax : 05 56 90 58 
78
 
d>>>    SyntaxError: invalid syntax 
(parallelioctl.py, line 5)
 
and in the parallelioctl.py, line 5 is : "static int fd = 
0;  
//file handle for parport/ppdev"
 
could you help me?
-- 
http://mail.python.org/mailman/listinfo/python-list

threading IOError

2005-12-13 Thread Gabriel Genellina
Hi

I'm using Python 2.4.2 on Windows 98 SE.

In a program with several threads, sometimes (I cant determine exactly
when or why) one thread dies with the following traceback:

12/13/05 02:17:47 (WatchDog   ) Unhandled thread exception
Traceback (most recent call last):
  File "E:\prog\pop3\TaskScheduler.py", line 60, in run
self.finished.wait(self.interval)
  File "C:\Apps\Python\Lib\threading.py", line 348, in wait
self.__cond.wait(timeout)
  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:

PYTHONW provocó un error de página no válida en el módulo
PYTHON24.DLL de 016f:1e0ab51f.
Registros:
EAX=1e19d1af CS=016f EIP=1e0ab51f EFLGS=00010206
EBX=00841f80 SS=0177 ESP=0071e6ec EBP=
ECX=73962000 DS=0177 ESI=1e06a1b0 FS=1a07
EDX=1e19d1b0 ES=0177 EDI= GS=

Any ideas?

Gabriel Genellina
Softlab SRL

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


Horribly noobful string question

2005-12-13 Thread SeNTry
Hi Everyone,

My first post here as I just begin to learn programming in general and 
python in particular.  I have all the noobie confused questions, but as I 
work thru the tutorials I'm sure I'll find most my answers.

This one is eluding me tho... I am working in the tutorials, writing scripts 
as presented and then modifying and expanding on my own to try to learn. 
I'm working with one that asks the user to 'guess a number I'm thinking', 
and with simple while loop, flow control and operands, returning an answer 
to guess again or you got it.  I've added a 'playagain' function I've got 
working, but what I want is to stop the program from crashing when someone 
enters a string value instead of a int value.  I know strings are immutable, 
and they can be changed to an int equivalent, but I just want the script to 
recognize the input as a string and print a simple "that's not a number, try 
again' type of message.  I can't find the syntax to include in the 
if/elif/else block to include a line that says something like,

elif guess == 
print "that's not a number! please guess again!"

I know that's not right, but can you see what I'm looking for and offer a 
suggestion?

Thanks in advance all. 


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


how can i change the default python?

2005-12-13 Thread Koray Bostancı
Hi all,

When i type python in terminal it runs the python2.3 interpreter, but i
want to use 2.4 and Python2.4 package is already installed.

How can i change the default python in my system? I searched google for
a little but couldn't find.

Using Debian GNU/Linux.


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


Visual Python, really "Visual"?

2005-12-13 Thread Tolga
After a very rapid entrance into the Python, I have immediately looked
for a good IDE. Komodo and Wing IDE look very good and I think they are
enough. But now, I am searching for a Pyhton environment which should
look like Delphi / Kylix, Borland's C++ builder or Allegro Common Lisp.
I have found a plug-in named "Visual Python" and this name naturally
maked me happy. But is it really "Visual" and does it provide a WYSIWYG
rapid development environment? Has it drag'n drop buttons, checkboxes,
radio buttons, forms et cetera?

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


Re: IsString

2005-12-13 Thread Steve Holden
Tom Anderson wrote:
> On Tue, 13 Dec 2005, Steven D'Aprano wrote:
> 
> 
>>On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
>>
>>[snippidy-doo-dah]
>>
>>
>>>I had the same thought, but reread the post.  He asks "if a given 
>>>variable is a character or a number".  I figured that even if he is 
>>>coming from another language he knows the difference between "a given 
>>>variable" and the "contents of a give variable".  I guess we will 
>>>see ;-).  This list is so good, he gets BOTH questions answered.
>>
>>The problem is, Python doesn't have variables (although it is 
>>oh-so-tempting to use the word, I sometimes do myself). It has names in 
>>namespaces, and objects.
> 
> 
> In what sense are the names-bound-to-references-to-objects not variables?
> 
In a very important sense, one which you should understand in order to 
understand the nature of Python.

In C if you declare a variable as (for example) a character string of 
length 24, the compiler will generate code that allocates 24 bytes to 
this variable on the stack frame local to the function in which  it's 
declared. Similarly if you declare a variable as a double-length 
floating point number the compiler will emit code that allocates 16 
bytes on the local stack-frame.

In Python a name (*not* a "variable", though people do talk loosely 
about "instance variables" and "class variables" just to be able to use 
terms familiar to users of other to languages)  is simply *bound* to a 
value. The only storage that is required, therefore, is enough to hold a 
pointer (to the value currently bound to the name). Thus assignment 
(i.e. binding to a name, as opposed to binding to an element of a data 
structure) NEVER copes the object, it simply stores a pointer to the 
bound object in the part of the local namespace allocated to that name.
> 
>>It be a subtle difference, but an important one.
> 
> 
> No, it's just spin, bizarre spin for which i can see no reason. Python has 
> variables.
> 
You appear very confident of your ignorance ;-)
> 
>>That's why, for instance, Python is neither call by reference nor call 
>>by value, it is call by object.
> 
> 
> No, python is call by value, and it happens that all values are pointers. 
> Just like java, but without the primitive types, and like LISP, and like a 
> load of other languages. Python's parameter passing is NO DIFFERENT to 
> that in those languages, and those languages are ALL described as 
> call-by-value, so to claim that python does not use call-by-reference but 
> some random new 'call-by-object' convention is incorrect, unneccessary, 
> confusing and silly.
> 
> 
> 
> I'm sure this has been argued over many times here, and we still 
> all have our different ideas, so please just ignore this post!
> 
Couldn't!

I do apologise, though, for any implication you assertions are based on 
ignorance because you do demonstrate quite a sophisticated knowledge of 
what goes on under the hood. As long as you can accept that "Python 
'variables' are all references" then the rest is indeed semantics.

Of course it will be helpful for newcomers if we can adopt a standard 
terminology ...

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: Horribly noobful string question

2005-12-13 Thread Fredrik Lundh
"SeNTry" wrote:

> My first post here as I just begin to learn programming in general and
> python in particular.  I have all the noobie confused questions, but as I
> work thru the tutorials I'm sure I'll find most my answers.
>
> This one is eluding me tho... I am working in the tutorials, writing scripts
> as presented and then modifying and expanding on my own to try to learn.
> I'm working with one that asks the user to 'guess a number I'm thinking',
> and with simple while loop, flow control and operands, returning an answer
> to guess again or you got it.  I've added a 'playagain' function I've got
> working, but what I want is to stop the program from crashing when someone
> enters a string value instead of a int value.  I know strings are immutable,
> and they can be changed to an int equivalent, but I just want the script to
> recognize the input as a string and print a simple "that's not a number, try
> again' type of message.  I can't find the syntax to include in the
> if/elif/else block to include a line that says something like,

assuming you're using raw_input() to get the guess, you always
have a string (in python's sense of that word).

what you seem to want is to check if the string contains a number
or not.  here's one way to do this:

guess = raw_input("make a guess: ")
if guess == secret:
print "congratulations!"
elif not guess.isdigit():
print "that's not a number! please guess again!"
...

isdigit returns true if the string contains nothing but digits:

>>> help(str.isdigit)

isdigit(...)
S.isdigit() -> bool

Return True if there are only digit characters in S,
False otherwise.

if you're using some other way to read user input, let us know.





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


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

2005-12-13 Thread Steve Holden
Antoon Pardon wrote:
> Op 2005-12-13, Chris Mellon schreef <[EMAIL PROTECTED]>:
[...]
>>If you have a consistent API and you're checking for error values from
>>your GTK functions, then you already have a lot more code than using 2
>>varaibles will cost you. 10 lines, maybe.
>>
>>The fact that you think setting two variables is "too hard" but you're
>>perfectly happy with checking for boolean types instead just testing
>>truth values I think is a real problem.
> 
> 
> These aren't just truth values. If I would have to go split in 
> meaningfull truth values I would need at least three variables.
> 
> 
>>You aren't saving yourself any
>>performance. You're barely even saving yourself any typing, and you're
>>making your code (intentionally, it seems) that much more compllicated
>>and hard to understand.
> 
> 
> There is nothing complicated or hard to understand.
> 
Nope, just a messy, hard to maintain misuse of a single variable for 
multiple purposes. Perfectly simple, perfectly easy to understand and 
rather more bug-prone that a straightforward separation of state and 
other data.

> I find it odd that each time declaration are mentioned people here
> react very rejecting and say that one of the features they love
> about python is the freedom that a name is not limited to a variable
> of one type, while when someone makes use of that freedom labeling
> such code as code smell.
> 
There's a difference between using a single name to refer to values of 
polymorphic types (which can therefore all be handled by the same code) 
and using the same name to reference state information in one case (this 
  item has no connected callback) and other data (the callback is to 
such-and-such an object).

> But lets make an effort to make the code more readable. What
> about the following suggestion. I use a kind of EnumType with
> two values: NotRegistered and Registerd. And the name of the
> type is NotConnected. So I can then write
> 
>   if type(self.callback) is NotConnected.
> 
> Would that be selfdocumenting enough for you?
> 
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?

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: Visual Python, really "Visual"?

2005-12-13 Thread Ravi Teja
No! Visual Python does not have a WYSIWYG GUI Builder.

Boa Constructor is the closest.
PythonCard is another contender.

Once, XAML comes in, this will become less of an issue.

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


  1   2   3   >