【发布时间】:2018-11-24 19:58:45
【问题描述】:
我使用inspect.getsource 来检查我导入的库:
In[52]: from django.views.generic import View
In[53]: view_code = inspect.getsource(View)
In[54]: len(view_code)
Out[54]: 3242
检索格式化代码
In[55]: print(view_code)
class View(object):
"""
Intentionally simple parent class for all views. Only implements
dispatch-by-method and simple sanity checking.
"""
http_method_names = ['get', 'post', 'put',
'patch', 'delete', 'head', 'options', 'trace']
def __init__(self, **kwargs):
我想将代码存储到我的笔记中以供进一步参考,
为此,我必须滚动整个代码以复制它。
代码够长就不方便了。
如何直接将print 的输出复制到剪贴板?
【问题讨论】:
-
您真的想要一种将
print的结果捕获到剪贴板的方法,还是只是一种将字符串发送到剪贴板而不打印的方法?