Question

Here's my code;

def save(name):
    if x['fname'] == 'ply.json':
        save1(name)
    elif x['fname'] not 'ply.json':
        write_data({'fname':'ply.json', 'name':'Karatepig'}, 'ply.json')

I get an error stating that I have this syntax error:

File "<stdin>", line 4
  elif x['fname'] not 'ply.json':
                               ^

What am I doing wrong?

Was it helpful?

Solution

something not something is not a valid expression. If you want to test if it is not equal, use !=:

elif x['fname'] != 'ply.json':

However, since this is the exact opposite of the preceding if test, just use else here:

if x['fname'] == 'ply.json':
    save1(name)
else:
    write_data({'fname':'ply.json', 'name':'Karatepig'}, 'ply.json')

OTHER TIPS

You need to use != to test inequality, like this:

    elif x['fname'] != 'ply.json':

But why use elif?

def save(name):
    if x['fname'] == 'ply.json':
        save1(name)
    else:
        write_data({'fname':'ply.json', 'name':'Karatepig'}, 'ply.json)

You need to use != for "not equal":

elif x['fname'] != 'ply.json':
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top