Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76630 > unrolled thread
| Started by | luofeiyu <elearn2014@gmail.com> |
|---|---|
| First post | 2014-08-20 11:05 +0800 |
| Last post | 2014-08-20 05:00 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
why i can't get the sourcecode with inspect module? luofeiyu <elearn2014@gmail.com> - 2014-08-20 11:05 +0800
Re: why i can't get the sourcecode with inspect module? Steven D'Aprano <steve@pearwood.info> - 2014-08-20 05:00 +0000
| From | luofeiyu <elearn2014@gmail.com> |
|---|---|
| Date | 2014-08-20 11:05 +0800 |
| Subject | why i can't get the sourcecode with inspect module? |
| Message-ID | <mailman.13186.1408503952.18130.python-list@python.org> |
>>> 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
>>>
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2014-08-20 05:00 +0000 |
| Message-ID | <53f42b67$0$29884$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #76630 |
On Wed, 20 Aug 2014 11:05:26 +0800, luofeiyu wrote: >>>> import inspect > >>> def changer(x,y): > ... return(x+y) The interactive interpreter doesn't store the source code you type. It compiles it to byte-code, executes the byte-code, and throws the source code away. -- Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web