小编Geo*_*nov的帖子

在 VSCode 中编辑 Google Colab Jupyter Notebook

我刚刚发现VSCode您可以定义远程Jupyter服务器并Jupyter从内部编辑笔记本VSCode。您只需要定义服务器的 URI Jupyter。我正在检查Google Colab但没有找到获取此 URI 的选项。

有没有一种简单的方法来链接VSCodeGoogle Colab

visual-studio-code jupyter-notebook google-colaboratory

4
推荐指数
1
解决办法
2148
查看次数

从bash导出变量并在Python中使用它

我正在尝试编写一个脚本,该脚本正在Linux服务器上执行几个操作,我想对大多数Linux特定命令使用bash,而对最复杂的东西仅使用Python,但是为此,我需要从bash脚本中导出一些变量并在python脚本中使用它们,但我没有找到一种方法。因此,我尝试创建两个非常小的脚本来测试此功能:1.sh是bash脚本

#!/bin/bash

test_var="Test Variable"
export test_var
echo "1.sh has been executed"
python 2.sh
Run Code Online (Sandbox Code Playgroud)

2.sh是Python脚本:

#!/usr/bin/env python3

print("The python script has been invoked successfully")
print(test_var)
Run Code Online (Sandbox Code Playgroud)

您可以猜测,当我执行第一个脚本时,第二个脚本会失败,并显示有关未知变量的错误:

$ ./1.sh
1.sh has been executed
The python script has been invoked successfully
Traceback (most recent call last):
  File "2.sh", line 4, in <module>
    print(test_var)
NameError: name 'test_var' is not defined
Run Code Online (Sandbox Code Playgroud)

之所以尝试这样做,是因为我对bash更加满意,并且我想在bash中使用$ 1,$ 2变量。在Python中也可以吗?

[编辑]-我刚刚发现如何在Python中使用$ 1和$ 2。您需要使用sys.argv[1]sys.argv[2]并导入sys模块import sys

python linux bash shell

3
推荐指数
2
解决办法
3331
查看次数