1

I saw in many python functions people using a single standalone "*" parameter, but it is not args or kwargs. I just saw an example on shutil standard lib documentation.:

shutil.copy(src, dst, *, follow_symlinks=True)

I tried to google it, but only found examples about args. What does this parameter do exactly?

Thanks.

  • 4
    IIRC, it means that `follow_symlinks` has to be named as a parameter when the function is invoked. So you can't do `copy(mySrc, myDest, True)` - you have to do `copy(mySrc, myDest, follow_symlinks=True)`. It forces the user to name the parameter for which they are passing a value – inspectorG4dget Jul 17 '19 at 14:02
  • 3
    See the last part of the top answer: "Also Python 3 adds new semantic (refer PEP 3102):" https://stackoverflow.com/a/36908/6260170 – Chris_Rands Jul 17 '19 at 14:06
  • 1
    https://www.python.org/dev/peps/pep-3102/ explains why and how it came into the fold – Vikramaditya Gaonkar Jul 17 '19 at 14:07
  • It looks similar to the idea of doing `a, _ = foo()`? `_` has no practical use -- except giving an ability to collect only one item if required. – Nishant Jul 17 '19 at 14:07

0 Answers0