78912

How to print the python code of a function to the terminal? [duplicate]

<div class="question-status question-originals-of-duplicate">

This question already has an answer here:

    <li> Python reflection - Can I use this to get the source code of a method definition <span class="question-originals-answer-count"> 4 answers </span> </li> </ul>

    I've got a system in which I constantly experiment with the contents of a function, after which I run the program. Since I often have many terminal windows open, I sometimes don't exactly know which version of the function belongs to which terminal window.

    Is there a way to print the source code of a specific function to the terminal?

    Answer1:

    Alright. Thanks to Hoopdady who provided a similar question here on Stackoverflow. Just to give the solution for future readers. I needed to use the inspect module, and using its method "getsource" I can simply print the source of a method or function to the command line.

    import inspect import mymodule print inspect.getsource(mymodule.sayHello)

    Thanks Hoopdady!

Recommend

  • How to create new layer or new protocol with scapy?
  • Stylus not allowing basic subtraction
  • Synchronous XHR deprecation
  • Multiprocessing in Python: how to implement a loop over “apply_async” as “map_async” using a callbac
  • Create child Window of another process's HWND? (e.g. screensaver preview)
  • LatLong falls within a given polygon in D3 + Leaflet
  • opengl window freezing during move/resize
  • Does sql server minds the way records where inserted?
  • WP7 difficulties binding data to listbox itemssource - won't refresh
  • Ruby 1.8.6 Array#uniq not removing duplicate hashes
  • Interpreting STRACE output - pipes and forks
  • Configure Spring's MappingJacksonHttpMessageConverter
  • MeeGo Handset Emulator not starting on Windows 7
  • AppleScript : find open tab in safari by name and open it
  • Memory error in python- how to use more memory
  • Ajax Upload File: $_FILES is empty but files exists in request header
  • Differences in dis-assembled C code of GCC and Borland?
  • Is playing sound in Javascript performance heavy?
  • Setting up SourceTree to merge unity3d scenes with UnityYAMLMerge
  • Alert pop up with LWUIT
  • Algorithm for a smudge tool?
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • Sony Xperia Z Tablet not found by adb
  • SSO with signing and signature validation doesn't work
  • Deserializing XML into class C#
  • Javascript convert timezone issue
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • How to include full .NET prerequisite for Wix Burn installer
  • AngularJs get employee from factory
  • How do you join a server to an Active Directory (domain)?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Checking variable from a different class in C#
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?