Getting an unexpected NameError in pycassaShell when invoking one function from another
Asked Answered
B

4

13

I'm playing with pycassaShell (as part of the Cassandra and the Twissandra tutorial). When trying to add two functions inside the shell, and call one from the other I get an error that the Name is not recognized.

This is probably something very simple, but I did not find how to do this.

The pycassaShell looks like:

In [3]: def aaa(): print 5
In [4]: aaa()
5

In [5]: def bbb(): aaa()

In [6]: bbb()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
...
NameError: global name 'aaa' is not defined
Brag answered 19/7, 2012 at 11:55 Comment(5)
Can you include the elided output in the traceback (assuming that there is some)? There might be something useful there and I don't have Cassandra/pycassa set up at the moment, so I can't check for myself.Sidoon
Works perfectly in pure IPython.Polyphone
Works fine in pure python as wellPiassava
Had similar problems myself with django shell. Looks like it may be a bug in ipyrhon: github.com/ipython/ipython/issues/2532Brigade
I agree: It afects my django shell and pycassaShell - each of which use ipythonMombasa
A
1

This is an issue with the way Pycassa is embedding IPython. This is the same problem @Benjamin White references regarding Django's IPython use. Django fixed the bug by accepting a pull request from an IPython core dev.

I took the liberty to file an issue with Pycassa. Hopefully they'll be able to investigate why a similar fix won't work for them.

Autolysin answered 8/4, 2013 at 16:52 Comment(0)
P
0

This is odd. I don't know why it is happening, but try this:

def aaa(): print 5

def bbb():
    global aaa
    aaa()
Piassava answered 30/7, 2012 at 20:34 Comment(2)
could you run dir() and tell us the output? In python it should say ['__builtins__', '__doc__', '__name__', '__package__', 'aaa', 'bbb'].Piassava
@Brag can you please run dir()?Piassava
R
0

Is it possible that you are using Python 3? If you are, visit http://docs.python.org/release/3.0.1/whatsnew/3.0.html for the list of changes.

It worked both in IPython and regular python v2.7.

Riboflavin answered 31/7, 2012 at 20:16 Comment(0)
B
0

What about:

def aaa(self): print 5 
def bbb(): self.aaa

That's what I do when I get Name Errors...

Brigettebrigg answered 10/8, 2012 at 10:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.