Multiple assignment?
Irmen de Jong
irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Mon Apr 21 06:13:18 EDT 2003
Mehta, Anish wrote:
> Can someone tell me the what is being done here in this line of code.
>
> dir, file = os.path.split(input)
>
Your message title was already on the right track.
This is a Tuple Assignment (also called Tuple Unpacking).
os.path.split returns a tuple with 2 elements; (directoryname, filename).
Using tuple unpacking these two elements of the tuple
are assigned to "dir" and "file", respectively.
--Irmen
PS: bad idea to use "dir" and "file" because
you'll hide the builtin "dir" and "file" identifiers.
More information about the Python-list
mailing list