Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76662 > unrolled thread

Re:why i can't get the sourcecode with inspect module?

Started byDave Angel <davea@davea.name>
First post2014-08-20 09:06 -0400
Last post2014-08-20 09:06 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re:why i can't get the sourcecode with inspect module? Dave Angel <davea@davea.name> - 2014-08-20 09:06 -0400

#76662 — Re:why i can't get the sourcecode with inspect module?

FromDave Angel <davea@davea.name>
Date2014-08-20 09:06 -0400
SubjectRe:why i can't get the sourcecode with inspect module?
Message-ID<mailman.13205.1408539920.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web