On Sat, Feb 11, 2017 at 3:22 AM, boB Stepp <robertvst...@gmail.com> wrote: > > py3: help(repr) > Help on built-in function repr in module builtins: > > repr(obj, /) > Return the canonical string representation of the object. > > For many object types, including most builtins, eval(repr(obj)) == obj. > > Question: What does the forward slash represent in this context?
It's from the function's __text_signature__. >>> repr.__text_signature__ '($module, obj, /)' It means "obj" is a positional-only argument that cannot be passed as a keyword. >>> s = inspect.signature(repr) >>> s.parameters['obj'].kind <_ParameterKind.POSITIONAL_ONLY: 0> CPython has a lot of built-in functions that don't allow keyword arguments. >>> repr(obj=42) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: repr() takes no keyword arguments Look at open() for comparison. >>> open.__text_signature__ "($module, /, file, mode='r', buffering=-1, encoding=None,\n errors=None, newline=None, closefd=True, opener=None)" All of its parameters can be passed as keyword arguments. >>> s = inspect.signature(open) >>> s.parameters['file'].kind <_ParameterKind.POSITIONAL_OR_KEYWORD: 1> >>> s.parameters['mode'].kind <_ParameterKind.POSITIONAL_OR_KEYWORD: 1> For example: >>> open(file='spam', mode='w') <_io.TextIOWrapper name='spam' mode='w' encoding='UTF-8'> _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor