Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find what is in a PYC file

Tags:

python

pyc

This may be a noobie questions, but...

So I have a pyc file that I need to use, but I don't have any documentation on it. Is there a way to find out what classes and functions are in it and what variables they take? I don't need to code, just how to run it.

Thanks

like image 859
lovefaithswing Avatar asked Dec 09 '22 14:12

lovefaithswing


1 Answers

As long as you can import the file, you can inspect it; it doesn't matter whether it comes from a .py or .pyc.

>>> import getopt
>>> dir(getopt)
['GetoptError', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'do_longs', 'do_shorts', 'error', 'getopt', 'gnu_getopt', 'long_has_args', 'os', 'short_has_arg']
>>> type(getopt.getopt)
<type 'function'>
>>> inspect.getargspec(getopt.getopt)
ArgSpec(args=['args', 'shortopts', 'longopts'], varargs=None, keywords=None, defaults=([],))
>>> help(getopt.getopt)
Help on function getopt in module getopt:
...
like image 122
Glenn Maynard Avatar answered Dec 28 '22 06:12

Glenn Maynard