Very weird bug!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ssecorp

    Very weird bug!

    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#1 4>", line 1, in <module>
    fac
    NameError: name 'fac' is not defined
    >>factorial
    Traceback (most recent call last):
    File "<pyshell#1 5>", line 1, in <module>
    factorial
    NameError: name 'factorial' is not defined
    >>import math
    >>math
    <module 'math' (built-in)>
    >>math.factoria l
    Traceback (most recent call last):
    File "<pyshell#1 8>", line 1, in <module>
    math.factorial
    AttributeError: 'module' object has no attribute 'factorial'
    >>math.fac
    Traceback (most recent call last):
    File "<pyshell#1 9>", 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#2 2>", 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#4 4>", line 1, in <module>
    build(5,4)
    File "<pyshell#4 3>", 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)
  • Terry Reedy

    #2
    Re: Very weird bug!

    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.

    Comment

    • ssecorp

      #3
      Re: Very weird bug!

      i know, idid try it again and it works as expected. but how the h***
      did it not work that one time?

      Comment

      • Jorgen Bodde

        #4
        Re: Very weird bug!

        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 <circularfunc@g mail.comwrote:
        i know, idid try it again and it works as expected. but how the h***
        did it not work that one time?
        --

        >

        Comment

        Working...