Comment 1 for bug 355837

Revision history for this message
Brian Granger (ellisonbg) wrote : Re: [Bug 355837] [NEW] error message "str object not callable" when not calling string

str is a Python built-in. You reassign it to a string. Because
IPython uses the str builtin internally, things go bad in a serious
way. This is probably called by readline as you type. This is not an
IPython bug. Just don't use built-in names for your own variables.

Cheers,

Brian

On Sun, Apr 5, 2009 at 1:51 PM, shaunalynn <email address hidden> wrote:
> Public bug reported:
>
> There have been a few times where, when writing a for-loop, I will get a
> "'str' object is not callable" when I expect just to hit RET and begin
> writing the rest of the loop. The problem fixes itself when I log out
> and back ino ipython. I thought it might be related to defining a python
> name like "dict" in the example below, but I don't think so. Below is a
> transcript of the last occurrence.
>
> I am using ipython 0.8.4 on an IBM Thinkpad x31 running Ubuntu Ibex.
>
>
> In [31]: dict = {'a':'b','c':'d'}
>
> In [32]: str = 'wqe'
>
> In [33]: for i,j in dict:
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> KeyboardInterrupt
>
> In [33]: dict
> Out[34]: {'a': 'b', 'c': 'd'}
>
> In [35]: i
> ---------------------------------------------------------------------------
> NameError                                 Traceback (most recent call last)
>
> /home/shaunalynn/<ipython console> in <module>()
>
> NameError: name 'i' is not defined
>
> In [36]: j
> ---------------------------------------------------------------------------
> NameError                                 Traceback (most recent call last)
>
> /home/shaunalynn/<ipython console> in <module>()
>
> NameError: name 'j' is not defined
>
> In [37]: for i, j in dict:
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> KeyboardInterrupt
>
> In [37]: dictionary = {'a':'b','c','d'}
> ------------------------------------------------------------
>   File "<ipython console>", line 1
>     dictionary = {'a':'b','c','d'}
>                              ^
> SyntaxError: invalid syntax
>
>
> In [39]: dictionary = {'a':'b','c'"'d'}
> ------------------------------------------------------------
>   File "<ipython console>", line 1
>     dictionary = {'a':'b','c'"'d'}
>                                  ^
> SyntaxError: EOL while scanning single-quoted string
>
>
> In [40]: dictionary = {'a':'b','c':'d'}
>
> In [41]: for i, j in dictionary:
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> KeyboardInterrupt
>
> In [41]:
>
> In [42]: exit()
> Do you really want to exit ([y]/n)?
> shaunalynn@duffles:~$ ipython
> Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
> Type "copyright", "credits" or "license" for more information.
>
> IPython 0.8.4 -- An enhanced Interactive Python.
> ?         -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help      -> Python's own help system.
> object?   -> Details about 'object'. ?object also works, ?? prints more.
>
> In [1]: dict = {'a':'b','c':'d'}
>
> In [2]: for i, j in dict:
>   ...:     print i,j
>
> ** Affects: ipython
>     Importance: Undecided
>         Status: New
>
> --
> error message "str object not callable" when not calling string
> https://bugs.launchpad.net/bugs/355837
> You received this bug notification because you are a member of IPython
> Developers, which is subscribed to IPython.
>
> Status in IPython - Enhanced Interactive Python: New
>
> Bug description:
> There have been a few times where, when writing a for-loop, I will get a "'str' object is not callable" when I expect just to hit RET and begin writing the rest of the loop. The problem fixes itself when I log out and back ino ipython. I thought it might be related to defining a python name like "dict" in the example below, but I don't think so. Below is a transcript of the last occurrence.
>
> I am using ipython 0.8.4 on an IBM Thinkpad x31 running Ubuntu Ibex.
>
>
> In [31]: dict = {'a':'b','c':'d'}
>
> In [32]: str = 'wqe'
>
> In [33]: for i,j in dict:
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> KeyboardInterrupt
>
> In [33]: dict
> Out[34]: {'a': 'b', 'c': 'd'}
>
> In [35]: i
> ---------------------------------------------------------------------------
> NameError                                 Traceback (most recent call last)
>
> /home/shaunalynn/<ipython console> in <module>()
>
> NameError: name 'i' is not defined
>
> In [36]: j
> ---------------------------------------------------------------------------
> NameError                                 Traceback (most recent call last)
>
> /home/shaunalynn/<ipython console> in <module>()
>
> NameError: name 'j' is not defined
>
> In [37]: for i, j in dict:
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> KeyboardInterrupt
>
> In [37]: dictionary = {'a':'b','c','d'}
> ------------------------------------------------------------
>   File "<ipython console>", line 1
>     dictionary = {'a':'b','c','d'}
>                              ^
> SyntaxError: invalid syntax
>
>
> In [39]: dictionary = {'a':'b','c'"'d'}
> ------------------------------------------------------------
>   File "<ipython console>", line 1
>     dictionary = {'a':'b','c'"'d'}
>                                  ^
> SyntaxError: EOL while scanning single-quoted string
>
>
> In [40]: dictionary = {'a':'b','c':'d'}
>
> In [41]: for i, j in dictionary:
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> <ERROR: 'str' object is not callable>
> KeyboardInterrupt
>
> In [41]:
>
> In [42]: exit()
> Do you really want to exit ([y]/n)?
> shaunalynn@duffles:~$ ipython
> Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
> Type "copyright", "credits" or "license" for more information.
>
> IPython 0.8.4 -- An enhanced Interactive Python.
> ?         -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help      -> Python's own help system.
> object?   -> Details about 'object'. ?object also works, ?? prints more.
>
> In [1]: dict = {'a':'b','c':'d'}
>
> In [2]: for i, j in dict:
>   ...:     print i,j
>

--
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
<email address hidden>
<email address hidden>