我有 Python 3.7,但我想创建一个 Python 2.7 虚拟环境来运行一些仅适用于 Python 2.7 的代码。
如何创建这个 python 2.7 虚拟环境?
python3 -m venv
Run Code Online (Sandbox Code Playgroud)
像这样?
我希望能够从shell脚本判断任何POSIX系统上是否存在命令.
在Linux上,我可以执行以下操作:
if which <command>; then
...snip...
fi
Run Code Online (Sandbox Code Playgroud)
但是,which当命令不存在时,Solaris和MacOS 不提供退出失败代码,它们只是向STDOUT输出错误消息.
另外,我最近发现which命令本身不是POSIX(参见http://www.opengroup.org/onlinepubs/009695399/utilities/)
有任何想法吗?
我正在学习python,我像这样循环json转换为字典:它工作,但这是正确的方法吗?谢谢 :)
import json
output_file = open('output.json').read()
output_json = json.loads(output_file)
for i in output_json:
print i
for k in output_json[i]:
print k, output_json[i][k]
print output_json['webm']['audio']
print output_json['h264']['video']
print output_json['ogg']
Run Code Online (Sandbox Code Playgroud)
这里是JSON:
{
"webm":{
"video": "libvp8",
"audio": "libvorbis"
},
"h264": {
"video": "libx264",
"audio": "libfaac"
},
"ogg": {
"video": "libtheora",
"audio": "libvorbis"
}
}
Run Code Online (Sandbox Code Playgroud)
这里输出:
> h264
audio libfaac video libx264
ogg
> audio libvorbis video libtheora webm
> audio libvorbis video libvp8 libvorbis
> libx264 {u'audio': u'libvorbis',
> u'video': u'libtheora'}
Run Code Online (Sandbox Code Playgroud) 在Ubuntu上,我想得到一个磁盘文件:
foo $(bar)
Run Code Online (Sandbox Code Playgroud)
我想使用cat命令创建此文件,例如
cat <<EOF > baz.txt
type_magic_incantation_here_that_will_produce_foo_$(bar)
EOF
Run Code Online (Sandbox Code Playgroud)
问题是美元符号.我尝试了反斜杠,单引号和双引号字符的多种组合,但无法使其工作.
我试图在Bash脚本中运行一些Python代码,所以我想了解之间的区别是什么:
#!/bin/bash
#your bash code
python -c "
#your py code
"
Run Code Online (Sandbox Code Playgroud)
VS
python - <<DOC
#your py code
DOC
Run Code Online (Sandbox Code Playgroud)
我检查了网络,但无法编译主题周围的位.你认为一个比另一个好吗?如果你想从Python代码块返回一个值到你的Bash脚本,那么heredoc是唯一的方法吗?
我有这个file.csv:
coordinate1,coordinate2,value1
11111,a1,65
11111,a2,32
22222,b1,39
22222,b3,55
33333,c5,12
33333,c9,16
coordinate1,coordinate2,value2
54656,a1,65
21342,a2,32
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
568568,c5,12
568568,c9,16
coordinate1,coordinate2,value3
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
11111,a1,65
11111,a2,32
22222,b1,39
22222,b3,55
33333,c5,12
33333,c9,16
Run Code Online (Sandbox Code Playgroud)
现在我想将这个文件分成3个文件,每个人只有数据块
Es: 1° file
coordinate1,coordinate2,value1
11111,a1,65
11111,a2,32
22222,b1,39
22222,b3,55
33333,c5,12
33333,c9,16
Es: 2° file
coordinate1,coordinate2,value2
54656,a1,65
21342,a2,32
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
568568,c5,12
568568,c9,16
Run Code Online (Sandbox Code Playgroud) # ./scripts/replace-md5sums.py
bash: ./scripts/replace-md5sums.py: Permission denied
Run Code Online (Sandbox Code Playgroud)
replace-md5sums.py 有chmod 600
# ls -l ./scripts/replace-md5sums.py
-rw------- 1 ubuntu ubuntu 661 2011-04-27 16:30 ./scripts/replace-md5sums.py
Run Code Online (Sandbox Code Playgroud) 请允许任何人给我一个答案,我已经尝试过了
sudo apt-get install makeinfo textinfo texi2html
Run Code Online (Sandbox Code Playgroud)
但我仍然收到错误"无法找到包裹".
以下失败,我不明白为什么:
$ echo "#!"
Run Code Online (Sandbox Code Playgroud)
以下也失败并出现相同的错误消息:
$ echo "\#!"
Run Code Online (Sandbox Code Playgroud)
错误信息:
-bash: !": event not found
Run Code Online (Sandbox Code Playgroud)
为什么会失败?该怎么echo办呢?
我试图从Linux SSH安全Shell命令行环境运行python脚本,我试图导入argparse库,但它给出错误:"ImportError:没有名为argparse的模块".
我认为这是因为Linux shell使用的Python环境中没有argparse库,我想我可以修复它,如果我能找到Python环境所使用的库的目录,并且将argparse库复制到其中,但我找不到该目录所在的位置.
我很感激找到这个目录的任何帮助(我想我现在可以将argparse库包含在与我的python脚本相同的目录中,但我宁愿在其他Python库所在的地方使用argparse库,因为它应该).
bash ×5
python ×4
shell ×2
ubuntu ×2
ubuntu-12.04 ×2
unix ×2
argparse ×1
command-line ×1
debian ×1
denied ×1
dictionary ×1
echo ×1
escaping ×1
file ×1
heredoc ×1
json ×1
linux ×1
loops ×1
package ×1
permissions ×1
posix ×1
python-2.7 ×1
python-3.7 ×1
python-3.x ×1
python-venv ×1
sh ×1
split ×1
virtualenv ×1