Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76662
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re:why i can't get the sourcecode with inspect module? |
| Date | 2014-08-20 09:06 -0400 |
| Organization | news.gmane.org |
| References | <53F41076.8010508@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13205.1408539920.18130.python-list@python.org> (permalink) |
luofeiyu <elearn2014@gmail.com> Wrote in message:
> >>> import inspect
> >>> def changer(x,y):
> ... return(x+y)
> ...
> >>> dir()
> ['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__
> 'changer', 'inspect']
> >>> inspect.getsource(changer)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "D:\Python34\lib\inspect.py", line 830, in getsource
> lines, lnum = getsourcelines(object)
> File "D:\Python34\lib\inspect.py", line 819, in getsourcelines
> lines, lnum = findsource(object)
> File "D:\Python34\lib\inspect.py", line 667, in findsource
> raise OSError('could not get source code')
> OSError: could not get source code
> >>>
>
To put it simply, inspect can get the source if it's in python,
and if it's in a file visible on your own system from the same
location it was built from.
Since your function was built interactively, inspect cannot find
any source.
--
DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re:why i can't get the sourcecode with inspect module? Dave Angel <davea@davea.name> - 2014-08-20 09:06 -0400
csiph-web