Is there any significance in the triple underscore in Python?
This was in a script for getting all .txt
files in a directory.
for ___,___,files in os.walk(some_folder):
files[:]=[x for x in files if x.lower().endswith('txt')]
for file in files:
Reading other questions on here a single underscore is normally used for throw away variables, is this use of a triple underscore just bad practice or is there significance to it?
Single, double, triple and, in general, any amount of underscore only names in a script implicitly signifies that the value will not be used (the fact that it isn't given a "name" using any letters signifies this).
This is, of course, not set in stone (that is, Python doesn't treat ___
any differently than a name like foo
) instead it's a convention programmers usually understand and respect.
The single underscore has a purpose only in interactive mode and it's the one that's employed in scripts instead of __
or ___
. Using ___
and __
just look ugly and really are completely unecessary; I can't see why someone would decide to use it over _
; don't copy them and opt for _
when you need to get the same message across.