简体   繁体   English

Time.sleep in lambda function

[英]Time.sleep in lambda function

I was wondering how I can modify the following code to insert a time.sleep(0.5), since the GoogleTranslator API crashes if you send more than 5 request wihtin a second.我想知道如何修改以下代码以插入 time.sleep(0.5),因为如果您每秒发送超过 5 个请求,GoogleTranslator API 就会崩溃。

test["Label"]=test["cleanText"].apply(lambda x:GoogleTranslator(source='auto', target='en').translate(x))

Best, Daniel最好的,丹尼尔

Not sure what the Label and cleanText contains, but can't you can move the lambda out, create a separate function that has the time.sleep and GoogleTranslator logic, then use that inside apply ?不确定LabelcleanText包含什么,但您不能将 lambda 移出,创建一个单独的 function 具有time.sleepGoogleTranslator逻辑,然后在apply中使用它吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM