import schemdraw
import schemdraw.elements as elm
with schemdraw.Drawing() as drawing:
drawing.config(unit=2)
drawing += (L1 := elm.Line().right())
drawing += (L2 := elm.Line().right())
drawing += (C := elm.Capacitor().down().label('C'))
drawing += (L3 := elm.Line().Left())
drawing += (L4 := elm.Line().left())
drawing += (R := elm.Resistor().endpoints(L1.end, L3.end).label('R').idot())
drawing.draw()
drawing.save('scheme.png')我想为电路编写一个简单的脚本,但我总是遇到这样的错误:
回溯(最近一次调用):文件"C:/Users/Lukas/PycharmProjects/pythonProject1/main.py",第4行,其中schemdraw.Drawing()作为绘图: AttributeError:进入 进程已完成,退出代码为%1
有谁知道什么是不对的吗?
发布于 2022-01-14 14:01:48
直到最近的版本,schemdraw才添加上下文管理器。您可以找到提交这里。
除非您安装了于2022年1月9日发布的版本0.14,否则您将无法访问上下文管理器。
您可以看到版本0.13示例没有使用它。
import schemdraw
import schemdraw.elements as elm
d = schemdraw.Drawing()
d += elm.Resistor().label('100KΩ')
d += elm.Capacitor().down().label('0.1μF', loc='bottom')
d += elm.Line().left()
d += elm.Ground()
d += elm.SourceV().up().label('10V'))
d.draw()
d.save('schematic.svg')但是0.14的例子确实如此。
import schemdraw
import schemdraw.elements as elm
with schemdraw.Drawing(file='schematic.svg') as d:
d += elm.Resistor().label('100KΩ')
d += elm.Capacitor().down().label('0.1μF', loc='bottom')
d += elm.Line().left()
d += elm.Ground()
d += elm.SourceV().up().label('10V')https://stackoverflow.com/questions/70711518
复制相似问题