假设您正在使用 Poetry 来管理 Python PyPI 包。目前,您的项目有一个Makefile包含管理项目安装、单元测试和 linting 的过程。然而,由于这违背了 Poetry 的精神,即理想情况下您有一个配置文件来统治所有这些 ( pyproject.toml),并且因为 saidMakefile在 Windows 构建上可能很烦人,所以您希望Makefile通过以下方式直接将功能移至由 Poetry 管理:利用Poetry 对setuptools脚本的支持。
这是这样一个示例Makefile:
PYMODULE := awesome_sauce\nTESTS := tests\nINSTALL_STAMP := .install.stamp\nPOETRY := $(shell command -v poetry 2> /dev/null)\nMYPY := $(shell command -v mypy 2> /dev/null)\n\n.DEFAULT_GOAL := help\n\n.PHONY: all\nall: install lint test\n\n.PHONY: help\nhelp:\n @echo "Please use \'make <target>\', where <target> is one of"\n @echo ""\n @echo " install install packages and …Run Code Online (Sandbox Code Playgroud) python directory-structure package build-script python-poetry
我正在研究一种"复制粘贴计算器",它可以检测复制到系统剪贴板的任何数学表达式,对它们进行评估并将答案复制到准备粘贴的剪贴板上.但是,虽然代码使用了eval()函数,但考虑到用户通常知道他们正在复制什么,我并不十分担心.话虽如此,我想找到一种更好的方法,而不会给计算带来障碍(例如,删除计算乘法或指数的能力).
这是我的代码的重要部分:
#! python3
import pyperclip, time
parsedict = {"×": "*",
"÷": "/",
"^": "**"} # Get rid of anything that cannot be evaluated
def stringparse(string): # Remove whitespace and replace unevaluateable objects
a = string
a = a.replace(" ", "")
for i in a:
if i in parsedict.keys():
a = a.replace(i, parsedict[i])
print(a)
return a
def calculate(string):
parsed = stringparse(string)
ans = eval(parsed) # EVIL!!!
print(ans)
pyperclip.copy(str(ans))
def validcheck(string): # Check if the copied item is a math expression …Run Code Online (Sandbox Code Playgroud)