Search code examples
python-3.xpylint

is there is a (void)x; equivalent in python?


I have a simple python code that does some thing like this

for root, dirs, files in os.walk("/var/log"):
  #Some thing with root
  #Uses files
  #Doesn't use dirs

the variable dir is not used in this code section, however pylint is not exactly happy about it and complaining about unused variable

is there an C equivalent way ( (void) dir ; ) I can use to suppress this


Solution

  • In python, you can use an underscore _ to represent a "throwaway" variable you arent going to use.

    Example:

    >>> _, b = (1, 2)
    >>> b
    2
    

    So in your case:

    for root, _, files in os.walk("/var/log"):
    

    Should do the trick.