我有一个脚本
#! /bin/sh
set -eux
command_a
command_b | command_c
while [ true ]; do
command_d
done
Run Code Online (Sandbox Code Playgroud)
当任何命令失败时,我希望这失败。如果command_a失败,脚本将失败,但如果command_b或command_d(不确定command_c)失败,脚本将继续执行。
例如,当我尝试运行时:
mpl.rcParams['font.family'] = 'serif'
plt.rcParams['figure.figsize'] = [15,7]
plt.plot(data['flow-time'], data['staticpressurerecovery'])
plt.xlabel('Time [s]')
plt.ylabel('Static Pressure Recovery [-]')
plt.title('McD13_4S3 Plenum: Performance Coefficient ')
plt.ylim((0.33, 0.4))
plt.grid()
plt.show()
Run Code Online (Sandbox Code Playgroud)
在Jupyter笔记本中,我收到以下错误消息:
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1331: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
Run Code Online (Sandbox Code Playgroud)
删除fontList.cache,fontList.json以及fontList.py3.cache
反注释的字体家族相关的部分matplotlibrc文件
matplotlib使用pip uninstall matplotlib和卸载并重新安装pip install matplotlib
没有任何办法解决这个问题。现在我获取不同字体的唯一可能方法是使用LaTeX作为后端,但这是缓慢且不必要的。
有什么想法我接下来可以尝试吗?
编辑:我正在使用Windows 10,所以不apt-get适合我。这似乎是解决这些问题的常用方法,但是我做不到。看来这些解决方案只是将Microsoft字体添加到Linux字体管理器中,所以由于我已经在Microsoft机器上,所以它甚至可能无关紧要。
最低工作示例:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
mpl.rcParams['font.family'] = …Run Code Online (Sandbox Code Playgroud) 我确信已经有人回答过这个问题,但我找不到。
我有一个脚本test.py,其存在的唯一目的是将变量var放入全局命名空间中:
def test():
global var
var = 'stuff'
Run Code Online (Sandbox Code Playgroud)
test.py以下是我在 ipython 中使用运行%run,然后运行test(),然后尝试访问 时发生的情况var。
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %run test.py
In [2]: test()
In [3]: var
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-84ddba356ca3> in <module>()
----> 1 var …Run Code Online (Sandbox Code Playgroud) 所以我有以下列表:
test = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Run Code Online (Sandbox Code Playgroud)
我想遍历i内部列表中的第 th 个元素。我可以通过使用来做到这一点zip:
for x, y, z in zip(test[0], test[1], test[2]):
print(x, y, z)
Run Code Online (Sandbox Code Playgroud)
返回:
1 4 7
2 5 8
3 6 9
Run Code Online (Sandbox Code Playgroud)
有没有更干净、更 Pythonic 的方法来做到这一点?像zip(test, axis=0)什么?
首先,我知道这之前已经发布过,但是要么 A)建议不起作用,要么 B)建议从命名空间中手动删除模块并像平常一样重新导入它。
我有以下模块结构
basedir/
pytools/
__init__.py
tools.py
setup.py
test.py
Run Code Online (Sandbox Code Playgroud)
如果我在basedir,并导入pytools并创建一个 类 的对象testcls。该类的实际属性可在 中找到tools.py。testcls有一个名为的方法,它现在testfunc就简单地打印出来:AAA
>>> import pytools
>>> test = pytools.testcls()
>>> test.testfunc()
AAA
Run Code Online (Sandbox Code Playgroud)
假设我更改testfunc()为现在打印出来BBB。我这样做,并保存文件。然后我重新加载模块并重试,它没有打印出来BBB:
>>> from importlib import reload
>>> reload(pytools)
>>> test = pytools.testcls()
>>> test.testfunc()
AAA
Run Code Online (Sandbox Code Playgroud)
但是,如果我执行完全相同的过程,但改为更改test.py,将该文件作为模块导入,编辑其中的函数,然后重新加载它,它的行为将按预期进行:
>>> import test
>>> testvariable = test.testcls()
>>> testvariable.testfunc2()
AAA
# Change the function here
>>> from importlib …Run Code Online (Sandbox Code Playgroud) 当我git status通过Windows目录(/mnt/c/Users/....)上的WSL(Linux的Windows子系统)在git存储库上运行时,我知道目录中的每个文件都已被修改。每次修改都只是删除并重写原始文件。见下文:

现在,如果我git status通过Powershell在Windows端的完全相同的存储库上运行a ,那么我什么也没得到:
这背后有什么特殊原因吗?我知道这^M与Linux和Microsoft使用的不同行尾有关,但是git在是否进行了更改方面意见不一致,这对我来说似乎很奇怪。
注意:我一直在通过仓库的单独克隆在WSL侧上处理仓库(因此,为什么Windows端要落后15个)。但是,尚未对Windows存储库进行任何编辑。不知道这是否会改变任何东西,但是我想我会提到它。
在标签中使用下划线实际上并不创建下划线。我不确定发生了什么事
最小工作示例:
variable = range(5)
plt.plot(variable, variable, label='test_underscore')
plt.plot(variable, variable, label='escape\_underscore')
plt.plot(variable, variable, label=r'rawtest_underscore')
plt.plot(variable, variable, label=r'rawescape\_underscore')
_=plt.legend()
Run Code Online (Sandbox Code Playgroud)
这是我的rcParams:
plt.rcParams.update({
'font.family': 'serif',
'font.serif': 'cmr10',
'mathtext.fontset': 'cm',
'axes.unicode_minus': False,
'font.size': 11,
'figure.dpi': 200,
'lines.linewidth': 0.5,
'axes.grid': True
})
Run Code Online (Sandbox Code Playgroud)
python ×5
ipython ×2
matplotlib ×2
bash ×1
fonts ×1
for-loop ×1
git ×1
iterator ×1
list ×1
python-3.x ×1
windows-subsystem-for-linux ×1
zip ×1