Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76662
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder4.news.weretis.net!newsfeed.datemas.de!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'lines,': 0.07; 'source.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'def': 0.12; 'wrote': 0.14; "'__doc__',": 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; '>>>': 0.22; 'import': 0.22; 'visible': 0.24; 'source': 0.25; 'skip:" 20': 0.27; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; 'raise': 0.29; 'code': 0.31; "skip:' 10": 0.31; '"",': 0.31; 'inspect': 0.31; 'file': 0.32; '(most': 0.33; 'subject:the': 0.34; 'could': 0.34; 'subject:with': 0.35; 'subject:?': 0.36; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'subject:get': 0.81; 'subject::': 0.85; 'from.': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re:why i can't get the sourcecode with inspect module? |
| Date | Wed, 20 Aug 2014 09:06:15 -0400 (EDT) |
| Organization | news.gmane.org |
| References | <53F41076.8010508@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | wsip-68-106-144-188.dc.dc.cox.net |
| X-Newsreader | PiaoHong.Usenet.Client.VIP:1.56 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13205.1408539920.18130.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1408539920 news.xs4all.nl 2973 [2001:888:2000:d::a6]:44646 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:76662 |
Show key headers only | View raw
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