Il seguente frammento di codice:formato Python lancia KeyError
template = "\
function routes(app, model){\
app.get('/preNew{className}', function(req, res){\
res.render('{className}'.ejs, {});\
});\
});".format(className=className)
getta un KeyError:
Traceback (most recent call last): File "createController.py", line 31, in <module>
});".format(className=className) KeyError: ' app'
Qualcuno sa perché?
È necessario raddoppiare tutte le parentesi graffe che non devono essere formattate. –
Ti sei imbattuto in [stringhe multilinea] (http://docs.python.org/tutorial/introduction.html#strings)? Se usi le virgolette triple, non devi sfuggire a ogni nuova riga. – katrielalex
possibile duplicato di [str.format() non funziona, keyError] (http://stackoverflow.com/questions/2755201/str-format-does-not-work-keyerror) – luator