在我的本地计算机上,我只需进入“系统属性 -> 环境变量”并添加一个新变量及其在用户变量中的值。
然后,我可以在 Python 中使用它来检索该值:
import os
os.environ["VAR_NAME"]
Run Code Online (Sandbox Code Playgroud)
然而,我最近刚刚开始使用 Google Colab,它似乎无法检测到环境变量,因为它给了我这个错误:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-36-28128554cf91> in <module>()
1 import os
----> 2 os.environ["REDDIT_NAME"]
/usr/lib/python3.7/os.py in __getitem__(self, key)
679 except KeyError:
680 # raise KeyError with the original key value
--> 681 raise KeyError(key) from None
682 return self.decodevalue(value)
683
KeyError: 'REDDIT_NAME'
Run Code Online (Sandbox Code Playgroud)
我应该如何做才能让 Google Colab 检测我的用户环境变量?我需要修改特定路径吗?
谢谢。
此代码对 中的每个案例 id 执行 GET 请求cases。然后它会验证每个案例是否已满或有错误。
let cases = [ /* array of case objects having the property CaseId */ ];
let promises = [];
// fetch all cases first
cases.forEach(c => promises.push(CaseSource.get(c.CaseId)));
// validate each case
Promise.allSettled(promises).then((results) => {
results.forEach((promise) => {
if (promise.status === "fulfilled") {
let fetchedCase = promise.value;
let caseSize = fetchedCase.Evidences.length;
if (caseSize + 1 > MAX_CASE_SIZE) {
fullCases.push(fetchedCase.Title);
} else {
validCases.push(fetchedCase);
}
} else {
let error = promise.reason;
this.loadCaseError(ApiException.parse<IExceptionModel>(error), /* …Run Code Online (Sandbox Code Playgroud)