3

I stumbled upon the following syntax in Python decorator to keep signature and user defined attribute:

> def func():
...     return "Hello World!"
...
> func?
Signature: func()
Docstring: <no docstring>
File:      ~/<ipython-input-8-934f46134434>
Type:      function

Attempting the same in my Python Shell, whether 2 or 3, simply raises a SyntaxError. So what is this exactly, is it specific to some shells?

cs95
  • 379,657
  • 97
  • 704
  • 746
Olivier Melançon
  • 21,584
  • 4
  • 41
  • 73

2 Answers2

2

The reasons using the ? character in the pre-packaged Python IDLE shell fails, is because using the ? is specific to IPython:

Typing ?word or word? prints detailed information about an object. If certain strings in the object are too long (e.g. function signatures) they get snipped in the center for brevity. This system gives access variable types and values, docstrings, function prototypes and other useful information.

Christian Dean
  • 22,138
  • 7
  • 54
  • 87
2

This is an IPython feature, described here

Typing ?word or word? prints detailed information about an object.
...
Typing ??word or word?? gives access to the full information, including the source code where possible. Long strings are not snipped.

Barmar
  • 741,623
  • 53
  • 500
  • 612