error message "str object not callable" when not calling string
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
IPython |
Fix Released
|
Low
|
Unassigned |
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/shaunalyn
NameError: name 'i' is not defined
In [36]: j
-------
NameError Traceback (most recent call last)
/home/shaunalyn
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@
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
Related branches
- Brian Granger: Needs Fixing (overview)
-
Diff: 12304 lines (+6035/-2557)88 files modifiedIPython/__init__.py (+12/-9)
IPython/config/loader.py (+66/-25)
IPython/config/tests/test_loader.py (+9/-10)
IPython/core/application.py (+206/-81)
IPython/core/completer.py (+89/-73)
IPython/core/crashhandler.py (+41/-47)
IPython/core/debugger.py (+33/-0)
IPython/core/history.py (+47/-25)
IPython/core/hooks.py (+1/-2)
IPython/core/ipapp.py (+295/-184)
IPython/core/iplib.py (+240/-179)
IPython/core/magic.py (+96/-60)
IPython/core/prefilter.py (+72/-15)
IPython/core/prompts.py (+20/-8)
IPython/core/pylabtools.py (+145/-0)
IPython/core/quitter.py (+12/-7)
IPython/core/release.py (+1/-1)
IPython/core/tests/obj_del.py (+0/-35)
IPython/core/tests/simpleerr.py (+32/-0)
IPython/core/tests/tclass.py (+14/-10)
IPython/core/tests/test_completer.py (+35/-0)
IPython/core/tests/test_iplib.py (+216/-28)
IPython/core/tests/test_magic.py (+137/-190)
IPython/core/tests/test_prefilter.py (+34/-0)
IPython/core/tests/test_run.py (+174/-0)
IPython/core/ultratb.py (+60/-21)
IPython/core/usage.py (+34/-325)
IPython/extensions/parallelmagic.py (+4/-0)
IPython/extensions/pretty.py (+3/-58)
IPython/extensions/tests/test_pretty.py (+51/-6)
IPython/external/_numpy_testing_utils.py (+120/-0)
IPython/external/argparse.py (+89/-38)
IPython/external/decorators.py (+245/-51)
IPython/frontend/prefilterfrontend.py (+17/-37)
IPython/frontend/tests/test_prefilterfrontend.py (+9/-6)
IPython/gui/wx/ipshell_nonblocking.py (+15/-14)
IPython/kernel/__init__.py (+1/-1)
IPython/kernel/clusterdir.py (+53/-65)
IPython/kernel/core/interpreter.py (+3/-4)
IPython/kernel/core/tests/test_redirectors.py (+6/-6)
IPython/kernel/engineservice.py (+3/-3)
IPython/kernel/error.py (+2/-2)
IPython/kernel/ipclusterapp.py (+8/-19)
IPython/kernel/ipcontrollerapp.py (+14/-34)
IPython/kernel/ipengineapp.py (+8/-27)
IPython/kernel/tests/test_multienginefc.py (+9/-1)
IPython/kernel/tests/test_taskfc.py (+9/-1)
IPython/lib/inputhook.py (+49/-3)
IPython/quarantine/InterpreterPasteInput.py (+0/-124)
IPython/scripts/iptest (+19/-3)
IPython/testing/__init__.py (+18/-0)
IPython/testing/_doctest26.py (+110/-0)
IPython/testing/_paramtestpy2.py (+89/-0)
IPython/testing/_paramtestpy3.py (+62/-0)
IPython/testing/decorators.py (+84/-14)
IPython/testing/decorators_trial.py (+0/-132)
IPython/testing/globalipapp.py (+168/-0)
IPython/testing/iptest.py (+349/-185)
IPython/testing/ipunittest.py (+189/-0)
IPython/testing/nosepatch.py (+53/-0)
IPython/testing/parametric.py (+3/-0)
IPython/testing/plugin/ipdoctest.py (+27/-180)
IPython/testing/plugin/test_ipdoctest.py (+0/-19)
IPython/testing/tests/test_decorators.py (+71/-13)
IPython/testing/tests/test_decorators_trial.py (+9/-4)
IPython/testing/tests/test_ipunittest.py (+122/-0)
IPython/testing/tests/test_tools.py (+31/-9)
IPython/testing/tools.py (+255/-7)
IPython/utils/baseutils.py (+51/-0)
IPython/utils/genutils.py (+129/-41)
IPython/utils/platutils.py (+1/-1)
IPython/utils/platutils_posix.py (+14/-1)
IPython/utils/tests/test_genutils.py (+71/-51)
IPython/utils/tests/test_imports.py (+0/-1)
IPython/utils/tests/test_platutils.py (+19/-6)
MANIFEST.in (+1/-0)
README.txt (+22/-4)
docs/emacs/ipython.el (+1/-1)
docs/source/development/coding_guide.txt (+34/-0)
docs/source/development/index.txt (+1/-0)
docs/source/development/magic_blueprint.txt (+103/-0)
docs/source/development/testing.txt (+366/-32)
docs/sphinxext/ipython_directive.py (+641/-0)
iptest.py (+26/-0)
ipython.py (+6/-2)
setup.py (+44/-3)
setupegg.py (+1/-7)
tools/build_release (+6/-6)
- Brian Granger: Approve
- Diff: None lines
Changed in ipython: | |
importance: | Undecided → Low |
status: | New → Confirmed |
Changed in ipython: | |
status: | Fix Committed → Fix Released |
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: ------- ------- ------- ------- ------- ------- ------- ------- ------- ----- n/<ipython console> in <module>() ------- ------- ------- ------- ------- ------- ------- ------- ------- ----- n/<ipython console> in <module>() ------- ------- ------- ------- ------- ------- ------- ---- ------- ------- ------- ------- ------- ------- ------- ---- duffles: ~$ ipython
> 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/shaunalyn
>
> NameError: name 'i' is not defined
>
> In [36]: j
> -------
> NameError Traceback (most recent call last)
>
> /home/shaunalyn
>
> 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@
> 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 referenc...