我想在 python 中添加两个分数
如果输入 1/4 + 1/4,我期待 1/2 结果
我用__add__
加法方法构建了一个分数类
from fractions import gcd
class fraction:
def __init__(self, numerator, denominator):
self.num = numerator
self.deno = denominator
def __add__(self, other):
self.sumOfn = self.num + other.num
self.sumOfd = gcd(self.deno,other.deno)
return(self.sumOfn, self.sumOfd)
print(fraction(1,4)+fraction(1,4))
Run Code Online (Sandbox Code Playgroud)
但是我得到 2,4 作为输出,实际上是 1/2,只是没有简化。我怎么能解决这个问题?
重新启动主机时,我希望我的Docker引擎在启动时启动。
这可能吗?谁能指出我正确的方向?
我的操作系统是RHEL 7.3,/ usr / lib / systemd / system / docker.service文件如下所示:
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target firewalld.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Python 3.4.6。
这里是工厂:
def create_parser():
""" Create argument parser """
# Input configuration parameters
_parser = argparse.ArgumentParser(description='Segments Engine')
# Application only parameters
_parser.add_argument(
'-V', '--version', version='%(prog)s ' + __version__,
action='version')
_pasrser.add_argument(
'-d', '--debug', action='store_true')
return _parser
Run Code Online (Sandbox Code Playgroud)
测试用例如下:
class TestCli(unittest.TestCase):
""" Test the cli.py module """
def __init__(self, *args, **kwargs):
""" Initialize Unit Test """
super(TestCli, self).__init__(*args, **kwargs)
def setup(self):
""" Setup before each test case """
setup_config(app)
setup_logging(app)
def teardown(self):
""" Tear down after each test case """
pass …
Run Code Online (Sandbox Code Playgroud) 我正在按照办公室指南创建钩子并将其添加到预提交检查过程中。我需要创建 3 个文件
.pre-commit-config.yaml
.pre-commit-hooks.yaml
theCheckFile.sh
Run Code Online (Sandbox Code Playgroud)
配置文件配置hooks文件,该文件调用theCheckFils.sh文件来检查我的代码风格。
Q.1我应该把这些文件放在哪里?我目前将它们放入我的项目文件夹中,并编辑 .gitignore 文件以忽略所有它们,有更好的建议吗?或者这样就可以了。
Q.2 pre-commit-config.yaml 文件中需要 rev,我应该在哪里找到此信息,我当前使用的代码 Repo 中没有版本信息,我可以随机创建一个数字吗?
我正在尝试遵循JupyterHub的贡献文档,但在运行时出现错误pre-commit run
该错误与我的 python 版本有关。3.6
尽管一切都安装了 Python ,但出于某种原因,它仍然在期待3.7.3
。这是运行命令的输出:
(.hub) {~/jupyter/jupyterhub} (master %)$ pre-commit run
[INFO] Initializing environment for https://github.com/asottile/reorder_python_imports.
[INFO] Initializing environment for https://github.com/ambv/black.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/asottile/reorder_python_imports.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: Command: ('/Users/nicholasbrady/jupyter/jupyterhub/.hub/bin/python3', '-mvirtualenv', '/Users/nicholasbrady/.cache/pre-commit/repo5hv9ofak/py_env-python3.6', '-p', 'python3.6')
Return code: 3
Expected return code: 0
Output:
The path python3.6 …
Run Code Online (Sandbox Code Playgroud) 我有一个Python
项目,当我尝试提交(通过 miniconda)时:
$ git add -A && git commit -m `test`
Run Code Online (Sandbox Code Playgroud)
我得到以下失败:
(base) D:\machinelearning.com-python>git commit -m 'test'
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\anon/.cache\pre-commit\patch1570560215.
Trim Trailing Whitespace.................................................Passed
Check for added large files..............................................Passed
Check python ast.........................................................Passed
Check JSON...........................................(no files to check)Skipped
Check for merge conflicts................................................Passed
Check Xml............................................(no files to check)Skipped
Check Yaml...........................................(no files to check)Skipped
Debug Statements (Python)................................................Passed
Fix End of Files.........................................................Passed
Fix requirements.txt.................................(no files to check)Skipped
Mixed line ending........................................................Passed
Flake8...................................................................Passed
isort....................................................................Failed
hookid: isort
Files were …
Run Code Online (Sandbox Code Playgroud) Yelp 检测机密是一个防止机密进入您的代码库的系统。我想安装它提供的预提交钩子。
我以前从未使用过 git hooks,但我看到的所有示例文件.git/hooks/
都是 bash,而yelp的自述文件中给出的示例是一个 yaml 文件。
它们链接到pre-commit.com;“用于管理和维护多语言预提交挂钩的框架”。
这是否意味着 yelp pre-commit hook 只能通过先安装pre-commit框架才能使用?
如果是这样,我有点迷失在预提交的使用中。我已经安装了它,我可以调用它。所以在现有的仓库中,我运行了pre-commit install
. 但是我现在如何添加 yelp 检测秘密预提交钩子?
当然,我已经查看了pre-commit.com上的文档,但我有点迷失了。欢迎任何提示。
我想在我的 mac 终端中创建一个虚拟环境,但出现以下错误。你能帮我解决这个问题吗?
hangsunkim@Hangs-MacBook-Pro ~ % virtualenv --system-site-packages -p python3 ./venv
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
@_call_aside
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside
f(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 585, in _build_master
return cls._build_from_requirements(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'zipp>=0.5' …
Run Code Online (Sandbox Code Playgroud) 我有一个 JS 前端和 Python 后端的项目。前端已经配置了 husky pre-commit hook。今天我已经用预提交库配置了 Pylint,但是 husky hooks 已经被这个举动覆盖了。是否可以结合 pre-commit 和 husky 库?如果没有......解决问题的最佳方法是什么?
我的管道中有一个步骤在 Bitbucket 上运行我们配置的预提交:
...
- step:
name: Passing linters
image: python:3.7-slim-stretch
script:
- pip3 install "pre-commit==2.17.0"
- apt-get update && apt-get --assume-yes install git
- pre-commit run --all-files
Run Code Online (Sandbox Code Playgroud)
没有进行任何更改,但它突然停止工作。
管道结果:
+ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/psf/black.
[INFO] Initializing environment for https://github.com/psf/black:click==8.0.4.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/maximevast/pre-commit-tslint/.
[INFO] Initializing environment for https://github.com/maximevast/pre-commit-tslint/:tslint-react@4.1.0,tslint@5.20.1,typescript@4.0.2.
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] …
Run Code Online (Sandbox Code Playgroud) bitbucket pre-commit pre-commit-hook bitbucket-pipelines pre-commit.com