Python Forum
See content of modules - not just function names
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
See content of modules - not just function names
#2
You can find out where a module is located,
and built_in docs with something like:

import importlib

def get_module_info(module):
    mod = importlib.import_module(module)
    print('Module location: {}'.format(mod.__file__))
    mdoc = mod.__doc__
    print(mdoc)

get_module_info('tkinter')
results:
Output:
Module location: C:\Python364\lib\tkinter\__init__.py Wrapper functions for Tcl/Tk. Tkinter provides classes which allow the display, positioning and control of widgets. Toplevel widgets are Tk and Toplevel. Other widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton, Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox LabelFrame and PanedWindow. Properties of the widgets are specified with keyword arguments. Keyword arguments have the same name as the corresponding resource under Tk. Widgets are positioned with one of the geometry managers Place, Pack or Grid. These managers can be called with methods place, pack, grid available in every Widget. Actions are bound to events by resources (e.g. keyword argument command) or with the method bind. Example (Hello, World): import tkinter from tkinter.constants import * tk = tkinter.Tk() frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2) frame.pack(fill=BOTH,expand=1) label = tkinter.Label(frame, text="Hello, World") label.pack(fill=X, expand=1) button = tkinter.Button(frame,text="Exit",command=tk.destroy) button.pack(side=BOTTOM) tk.mainloop()

but there is no 'dis-interpreter'
there is however dis (must be imported) for cpython byte code,
see: https://docs.python.org/3/library/dis.html
example:
import importlib
import dis

def disassemble_pcode(module):
    mod = importlib.import_module(module)
    print(dis.dis(mod))
    disassemble_pcode('tkinter')
partial results:
Output:
Disassembly of BaseWidget: Disassembly of __init__: 2283 0 LOAD_FAST 4 (kw) 2 POP_JUMP_IF_FALSE 16 2284 4 LOAD_GLOBAL 0 (_cnfmerge) 6 LOAD_FAST 3 (cnf) 8 LOAD_FAST 4 (kw) 10 BUILD_TUPLE 2 12 CALL_FUNCTION 1 14 STORE_FAST 3 (cnf) 2285 >> 16 LOAD_FAST 2 (widgetName) 18 LOAD_FAST 0 (self) 20 STORE_ATTR 1 (widgetName) 2286 22 LOAD_GLOBAL 2 (BaseWidget) 24 LOAD_ATTR 3 (_setup) 26 LOAD_FAST 0 (self) 28 LOAD_FAST 1 (master) 30 LOAD_FAST 3 (cnf) 32 CALL_FUNCTION 3 34 POP_TOP
Reply


Messages In This Thread
RE: See content of modules - not just function names - by Larz60+ - Feb-25-2018, 06:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star NameError – function doesn't recognize imported modules Sir 4 3,646 Dec-01-2020, 06:36 AM
Last Post: Sir
  function 'return' and file content into a list shiro26 4 3,387 Jul-06-2018, 10:20 PM
Last Post: volcano63
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 8,565 May-25-2017, 08:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020