By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

Very weird bug!

P: n/a
I was looking into currying and

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

************************************************** **************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet.
************************************************** **************

IDLE 1.2.2
>>h = "aja baja"
h += 'e'
h
'aja bajae'
>>h = h+'a'
h
'aja bajaea'
>>a = b = "foo"
a
'foo'
>>b
'foo'
>>a==b
True
>>id(a)
35018400
>>id(b)
35018400
>>a += "bar"
id(a),a
(35110112, 'foobar')
>>id(b),b
(35018400, 'foo')
>>fac
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
fac
NameError: name 'fac' is not defined
>>factorial
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
factorial
NameError: name 'factorial' is not defined
>>import math
math
<module 'math' (built-in)>
>>math.factorial
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
math.factorial
AttributeError: 'module' object has no attribute 'factorial'
>>math.fac
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
math.fac
AttributeError: 'module' object has no attribute 'fac'
>>dir(math)
['__doc__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil',
'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod',
'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow',
'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']
>>pow
<built-in function pow>
>>tan
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
tan
NameError: name 'tan' is not defined
>>math.tan
<built-in function tan>
>>def build(a,b):
return a+b
>>build(5,4)
(5, 4)
>>def build(x,y):
a=x+y
return a
>>build(5,4)
9
>>def b(n, p):
return n + p
>>b(1, 10)
11
>>def b(n,p):
return n+p
>>b(5,2)
7
>>def build(x,y):
return a+b
>>build(5,4)
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
build(5,4)
File "<pyshell#43>", line 2, in build
return a+b
TypeError: cannot concatenate 'str' and 'function' objects
>>def build(x,y):
yreturn x+

SyntaxError: invalid syntax
>>def build(x,y):
return x+y
>>build(5,4)
9
>>def build(a,b):
return a+b
>>build(5,4)
9
>>>

wtf was this in the middle!?
>>def build(a,b):
return a+b
>>build(5,4)
(5, 4)
Jul 6 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ssecorp wrote:
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
wtf was this in the middle!?
>>>def build(a,b):
return a+b
>>>build(5,4)
(5, 4)
I have exactly the same build on Windows and get the expected 9.

Try it again.

Jul 7 '08 #2

P: n/a
i know, idid try it again and it works as expected. but how the h***
did it not work that one time?
Jul 7 '08 #3

P: n/a
Maybe the interpreter remembered the values of some objects you used?
If you type in the interpreter, the objects you create have a lifetime
as long as the interpreter is active, which means it can get a state
behaviour that otherwise is not present if you start a new interpreter
instance. To be safe you should always try it with a script and run it
from the commandline to get the same 'state' everytime your script
runs.

- Jorgen
On Mon, Jul 7, 2008 at 7:36 PM, ssecorp <ci**********@gmail.comwrote:
i know, idid try it again and it works as expected. but how the h***
did it not work that one time?
--
http://mail.python.org/mailman/listinfo/python-list
Jul 8 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.