有没有办法找出缓冲区在Emacs中活动了多长时间?
M-x list-buffers 列出它们,但没有办法推断缓冲区存在多长时间.
有没有办法修改python/pip,每当导入在运行时失败时,它会尝试从pip安装模块(同名)然后导入模块?
我会说这是一个更好的默认值而不是抛出一个错误.如果从pip加载模块后发生任何问题,那么它也会抛出错误,类似于我注意到我无法导入的东西,尝试pip install然后得到相同的错误消息.
我知道我们可以requirements.txt用来捆绑一个包,但我是从"客户端"(运行脚本的人)而不是"提供者"(提供脚本的人)角度谈论的; 也就是说,作为客户端,我希望能够导入任何脚本并自动解决依赖关系.
我知道这可能会带来麻烦,但每当我看到一个ImportError时,我都会尝试使用pip install该模块.只有在pip安装后模块不能正常工作"我才能提出进一步的问题".
我想到了像python进程"内置"的这个片段:
def getDirectoryOfInterpreter(p):
return "someway to return the directory"
try:
import somemodule
except ImportError:
os.system(getDirectoryOfInterpreter('THIS_INTERPRETER_BINARY') + ' pip install ' + "MODULE_NAME")
import somemodule
Run Code Online (Sandbox Code Playgroud) 如何评估+ 5工作(扰流警报:结果是5)?
是不是+通过调用__add__方法来工作?5将在" other"中:
>>> other = 5
>>> x = 1
>>> x.__add__(other)
6
Run Code Online (Sandbox Code Playgroud)
那么允许添加5的"空白"是什么?
void.__add__(5)
另一个线索是:
/ 5
Run Code Online (Sandbox Code Playgroud)
抛出错误:
TypeError: 'int' object is not callable
Run Code Online (Sandbox Code Playgroud) 我找不到aiohttp与登录页面结合的工作代码.目标很简单:使用用户名和密码进行基于表单的身份验证,我希望在随后的aiohttp async fetch调用中使用该cookie.
似乎整个Session概念在版本之间的aiohttp中发生了变化,所以我很好奇如何在最新版本中实现它.我不确定如何获取cookie一次,然后在异步事件中使用它.
我真的很想看到一个完整的例子,因为不幸的是我无法使用我在任何地方找到的片段.
我想这可能是一个开始,但我不确定,我当然不知道如何将所有内容连接到它(我还需要一个aiohttp.TCPConnector吗?)
http://aiohttp.readthedocs.org/en/latest/ client_reference.html#aiohttp.client.ClientSession
使用mechanize在Python 2中我的非异步版本的示例(虽然我自然地使用Python 3进行asyncio等):
import mechanize
import urllib
class MyClass()
def __init__(self):
self.data = {'username' : 'me', 'password' : 'pw'}
self.login_url = 'http://example.com/login'
self.login()
def call(self, url):
request2 = mechanize.Request(url)
self.cookie_jar.add_cookie_header(request2)
response2 = mechanize.urlopen(request2).read()
return response2
def login(self):
request = mechanize.Request(self.login_url)
# 'username' and 'password' keys are actually the name of the <input>
logInfo = urllib.urlencode({'username' : self.data['username'],
'password' : self.data['password']})
response = mechanize.urlopen(request, data = logInfo) …Run Code Online (Sandbox Code Playgroud) 给定数据集 1
name,x,y
st. peter,1,2
big university portland,3,4
Run Code Online (Sandbox Code Playgroud)
和数据集 2
name,x,y
saint peter3,4
uni portland,5,6
Run Code Online (Sandbox Code Playgroud)
目标是合并
d1.merge(d2, on="name", how="left")
Run Code Online (Sandbox Code Playgroud)
虽然没有完全匹配的名称。所以我想做一种模糊匹配。在这种情况下,技术无关紧要,更重要的是如何将其有效地合并到 Pandas 中。
例如,st. peter可能与saint peter另一个匹配,但big university portland可能偏差太大,我们不会将其与uni portland.
考虑它的一种方法是允许以最低的 Levenshtein 距离加入,但前提是编辑次数低于 5(st. --> saint是 4)。
生成的数据框应仅包含 row st. peter,并包含“名称”变体以及x和y变量。
有没有办法使用熊猫进行这种合并?
在R中,有一个函数(cm.rnorm.cor来自包CreditMetrics),它采用样本量,变量数量和相关矩阵来创建相关数据.
Python中有相应的东西吗?
可以使用公式的快捷方式 lm()
m <- matrix(rnorm(100), ncol=5)
lm(m[,1] ~ m[,2:5]
Run Code Online (Sandbox Code Playgroud)
在这里它将是相同的
lm(m[,1] ~ m[,2] + m[,3] + m[,4] + m[,5]
Run Code Online (Sandbox Code Playgroud)
但是在变量不是同一级别的情况下(至少这是我现在的假设)这不起作用,我得到错误:
Error in model.frame.default(formula = hm[, 1] ~ hm[, 2:4], drop.unused.levels = TRUE) :
invalid type (list) for variable 'hm[, 2:4]'
Run Code Online (Sandbox Code Playgroud)
数据(hm):
N cor.distance switches time
1 50 0.04707842 2 0.003
2 100 -0.10769441 2 0.004
3 200 -0.01278359 2 0.004
4 300 0.04229509 5 0.008
5 500 -0.04490092 6 0.010
6 1000 0.01939561 4 0.007
Run Code Online (Sandbox Code Playgroud)
是否还有一些捷径可以避免编写长公式?
我正在为R构建一个包,我希望能够跨平台.我正在Linux下开发,该函数mclapply将从parallel包中使用.Windows(使用doParallel)不支持此程序包.我真的很喜欢这个parallel软件包,因为它的简单性和速度,我不知道这是否应该是为CRAN提供2个不同版本的软件包的原因,对于单独的操作系统(似乎需要额外的维护工作),而不是提到它是否被允许.
思考?
而且,现在我对parallel的是
mclapply(ldata, function(x), mc.cores=cores)
Run Code Online (Sandbox Code Playgroud)
相当于doParallel's
cl <- makeCluster(cores)
parLapply(cl, ldata, function(x))
Run Code Online (Sandbox Code Playgroud)
那是对的吗?
更新:这不适用于R在Mac上的劣质ESS流程,但当然我对Python感兴趣.
更多更新:似乎缓冲区评估换行缓慢.
每当我评估(发送文本)到劣质缓冲区时,发送和渲染低级缓冲区中的文本都非常慢.你可以从字面上看到它...为每一行编写.所以假设有一个100行函数,这需要一段时间(注意:函数的实际执行没有问题,只是缓冲区的写行).
改变的变量是什么?
尝试:
def uselessfunction():
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
Run Code Online (Sandbox Code Playgroud)
然后在输出缓冲区中打印:
>>> >>> >>> ... ... ... ... ... ... ... ... >>>
Run Code Online (Sandbox Code Playgroud)
看起来真的很慢.
另一个例子,使用:
(process-send-string PROCESS "\n\n\n\n")
也很慢,以及(comint-send-input)在下部python shell中写入一些行之后.
似乎大多数进入正在减缓这一点.
请注意,在Ubuntu中并非如此.