Given a string “VAR=value” I want to split it (only) at the first ‘=’ sign (< value > may contain more ‘=’ signs), something like this:
var, sep, value = "VAR=value".partition('=')
Is there a way to NOT declare a variable ‘sep’? Like this (just made up the syntax):
var, -, value = "VAR=value".partition('=')
Just for completeness, I’m targetting Python v 2.6
_is indeed a very popular choice for “a name which doesn’t matter” — it’s a legal name, visually unobtrusive, etc. However sometimes these very qualities can hinder you. For example, the GNU gettext module for I18N and L10N, which is part of Python’s standard library, idiomatically uses_very differently, with idioms such as…:to mark and translate all the literal-string messages in the code (also exploiting the relative visual unobtrusiveness of
_('...'). Obviously any code using this module and idiom shouldn’t also be using_to mean something completely different (“a don’t care name”).So a second useful alternative can be to devote the name
unusedto indicate such “don’t care” situations in a visually more explicit way. Google’s python style guide recommends using either_or a prefix ofunused_— the latter can be a bit verbose but tends to be very clear, e.g.:makes crystal-clear that
person_datais a three-item sequence (probably a tuple) and the item you’re skipping (and not using at all) is the surname (because you want to print a friendly message like “Hello, Mr Alex!” or “Hello, Miss Piggy!” ;-). (pylintand similar tools can warn you if you have unused variables named otherwise than_orunused_..., and of course also warn you if you ever do use a variable namedunused_something!-).