Question

I have a small problem in a bigger code... I can reproduce it in the following example

def graph(form): 
    if form == single:
        print 1
    if form == multi:
        print 2

When I type

graph(single)

I get

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-146-c730e3c6bbf1> in <module>()
----> 1 graph(single)

<ipython-input-143-cf1ff0a5e57e> in graph(form)
      5     if form == single:
      6         print 1
----> 7     if form == multi:
      8         print 2
      9 

NameError: global name 'multi' is not defined

1

Where is my mistake?

Was it helpful?

Solution

single and multi have no value. They are not defined anywhere in your function or globally.

You need to define what they mean before your function will work.

If they are just words, you need to wrap them in quotes "single" rather than single.

OTHER TIPS

The error is telling you where your problem resides:

NameError: global name 'multi' is not defined

Somewhere above, you either mistyped or forgot to define the multi variable. If these are globals defined outside your method, you should indicate that at the top of your method with the global statement. There's a good example of global usage here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top