hi!!

to show the source code I thought it is supposed to do this (at least it worked using ipython with version 2 of python):

>>> method??

I'm using version 3. How can I show the source of a method.
eg:
>>>def sayHi():
print('Hi')

>>>sayHi??
then show the source code.

Thanks!!

From the module inspect 's documentation: inspect.getsourcelines(object) Return a list of source lines and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of the lines corresponding to the object and the line number indicates where in the original source file the first line of code was found. An IOError is raised if the source code cannot be retrieved. inspect.getsource(object) Return the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An IOError is raised if the source code cannot be retrieved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.