[英]Passing python variable into the shell
I have a folder, say myFolder
, in which there are multiple csv files and I want to bzip2
them. 我有一个文件夹,例如myFolder
,其中有多个csv文件,我想对其进行bzip2
。 One option is of course to use shell: 一种选择当然是使用shell:
bzip2 myFolder/file1.csv
How can I do it (same command) in jupyter notebook? 如何在Jupyter Notebook中执行该命令(相同命令)?
I tried: 我试过了:
for x in os.listdir("myFolder"):
sourceFile = 'myFolder/'+x
!bzip2 sourceFile
which returns 哪个返回
bzip2: Can't open input file sourceFile: No such file or directory. bzip2:无法打开输入文件sourceFile:没有这样的文件或目录。
for x in os.listdir("myFolder"):
sourceFile = 'myFolder/'+x
!bzip2 {sourceFile}
Passing Python variables into the shell–is possible using the {varname} syntax 使用{varname}语法可以将Python变量传递到外壳中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.