Re: Re: Guido's new method definition idea

2008-12-06 Thread acerimusdux

Russ P. wrote:

Python already uses shorthand extensively. How about "def"? For people
who are so worried about self-explanatory symbols, what the heck does
that stand for? Default? Defeat? Defect? Defunct? Defer?


  


I think the difference here is that those other  abbreviations are 
mostly fairly standard. The "def" keyword is the same in Ruby, and 
similar enough to "define" or "defun" in Scheme or LISP. The "!=" 
operator is pretty much standard across nearly all languages. What is 
being proposed with "$" here though, would be different from how it is 
used anywhere else and would be confusing.


Moreover, I especially don't like proposing to eliminate as well in this 
instance the "dot notation", which is standard in nearly all object 
oriented languages. Using something as a substitute for "self" is one 
thing, and you can mostly use what you like there now, as "self" is more 
a convention than a requirement.  But the "dot" that belongs there is 
critical to understanding, you can't hide that to save one keystroke.


Getting back to Guido's suggestion, though, I think it makes some sense. 
Being new to Python, I did find myself occasionally forgetting "self" in 
instance methods. But, I also thought the requirement to include it was 
helpful in reminding me what was really going on there, that I was 
creating an instance method which was really a function that wouldn't 
actually be created until the instance was initiated.  I tend to think 
this may be clearer though using the dot notation rather than passing 
the instance variable as a parameter.


I'm not sure though whether allowing both syntaxes would make things 
more or less confusing. It might actually be helpful in some respects 
for newcomers to realize that self.method(arg) is somewhat the same as 
method(self, arg).  Perhaps I'm wrong on this, I don't fully understand 
yet what is going on under the hood, but it seems to me that that would 
be part of the glue that allows Python to be so multi-paradigm; much of 
the difference between OOP and procedural or functional is just 
different syntax for the same thing.




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


Re: Re: Rich Comparisons Gotcha

2008-12-07 Thread acerimusdux

James Stroud wrote:
Rasmus 
Fogh wrote:

Current behaviour is both inconsistent and counterintuitive, as these
examples show.


x = float('NaN')
x == x

False


Perhaps this should raise an exception? I think the problem is not 
with comparisons in general but with the fact that nan is type float:


py> type(float('NaN'))


No float can be equal to nan, but nan is a float. How can something be 
not a number and a float at the same time? The illogicality of nan's 
type creates the possibility for the illogical results of comparisons 
to nan including comparing nan to itself.





I initially thought that looked like a bug to me.  But, this is 
apparently standard behavior required for "NaN".  I'm only using 
Wikipedia as a reference here, but about 80% of the way down, under 
"standard operations":

http://en.wikipedia.org/wiki/IEEE_754-1985

"Comparison operations. NaN is treated specially in that NaN=NaN always 
returns false."


Presumably since floating point calculations return "NaN" for some 
operations, and one "Nan" is usually not equal to another, this is the 
required behavior. So not a Python issue (though understandably a bit 
confusing).


The array issue seems to be with one 3rd party library, and one can 
choose to use or not use their library, to ask them to change it, or 
even to decide to override their == operator, if one doesn't like the 
way it is designed.


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


Beginner trying to understand functions.

2008-12-08 Thread acerimusdux

simonh write:

In my attempt to learn Python I'm writing a small (useless) program to
help me understand the various concepts. I'm going to add to this as I
learn to serve as a single place to see how something works,
hopefully. Here is the first approach:



name = input('Please enter your name: ')
print('Hello', name)

while True:
try:
age = int(input('Please enter your age: '))
break
except ValueError:
print('That was not a valid number. Please try again.')

permitted = list(range(18, 31))

if age in permitted:
print('Come on in!')
elif age < min(permitted):
print('Sorry, too young.')
elif age > max(permitted):
print('Sorry, too old.')

input('Press any key to exit.')



That works fine. Then I've tried to use functions instead. The first
two work fine, the third fails:



def getName():
name = input('Please enter your name: ')
print('Hello', name)

def getAge():
while True:
try:
age = int(input('Please enter your age: '))
break
except ValueError:
print('That was not a valid number. Please try again.')

def checkAge():
permitted = list(range(18, 31))
if age in permitted:
print('Come on in!')
elif age < min(permitted):
print('Sorry, too young.')
elif age > max(permitted):
print('Sorry, too old.')

getName()
getAge()
checkAge()

I get this error message: NameError: global name 'age' is not
defined.

I'm stuck, can someone help? Thanks.
  


You are running into Python's scoping rules. Variables in Python are not 
global by default, they are local to their scope. Each function has it's 
own scope (but blocks like if: and while: don't.) So your variable "age" 
only exists in
getage(). It doesn't exist in checkage().  You could simply add a 
"global age" statement to getAge() before you first use the age 
variable, and that will likely work.


Or, rather than declare it global, you might want to have getage() 
return a value, and then pass it to checkage () as a function parameter. 
Add a "return age" statement to getage() before "break". Then, for your def:


def checkage(age):

And then when calling:

A=getAge()
checkAge(A)





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


Re: Re: Python is slow

2008-12-10 Thread acerimusdux

cm_gui wrote:

You guys are living in denial.
Python is SLOW, especially for web apps.

Instead of getting mad, why don't get together and come up with a
faster VM/interpreter?

The emperor doesn't like to be told he is not wearing any clothes?


O


The one in denial is the one without any evidence to back his 
assertions. as someone once said, "In God we Trust. All others must have 
data."


For example, the most recent benchmarks from The Computer Language 
Benchmark Game:


http://shootout.alioth.debian.org/u64/benchmark.php?test=all&lang=al
http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=all
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all

On Gentoo on a Pentium 4 for example:

mean
07.10 Python Psyco
19.34 Lua
23.00 Python
28.27 Perl
30.00 PHP
66.28 Javascript SpiderMonkey
75.12 Ruby

I have no idea about Zope, but if that's slow, go complain to the 
devlopers of Zope. The Python interpreter is one of the fastest for a 
dynamically interpreted language. And Psyco is competitive with many 
other JIT compilers. I would think someone who has been obsessing about 
the speed of Python since May, and especially interested in a Python 
"VM" would have learned by now about Psyco?









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