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
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
eran
  • 6,731
  • 6
  • 35
  • 52

4 Answers4

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.

Don Spaulding
  • 764
  • 5
  • 13
0

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

def aaa(): print 5

def bbb():
    global aaa
    aaa()
Logan
  • 1,614
  • 1
  • 14
  • 27
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.

Michael Guantonio
  • 409
  • 1
  • 6
  • 14
0

What about:

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

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

Antoni4040
  • 2,297
  • 11
  • 44
  • 56