django: avoid "Unused variable" warning on get_or_create
Is there a way to avoid "Unused variable" warning on get_or_create method?
level,created= Level.objects.get_or_create( name='Alumnes x Classificar')
because I don't need to read created
variable, IDE show a 开发者_JAVA百科warning about this.
I know that a trivial solutions i to use variable, some thing like: if create: pass
But I'm looking for a more elegant solution.
See you!
One “standard” way of doing this is to use the _
variable:
level, _ = Level.objects.get_or_create(…)
_
is a “real variable” (insomuch as you can read from and write to it), but it's generally understood to mean “ignored”.
You could only capture the level by doing:
level = Level.objects.get_or_create( name='Alumnes x Classificar')[0]
精彩评论