我正在使用Python 3.3.1
64位Ubuntu 13.04
64位运行Eclipse 4.3
64位Pydev 2.7.6
在virtualenv
环境中工作.我的项目在以下目录结构中.
Dictionary
|
----------------------------
| |
src test
| |
petaapan petaapan
| | | |
__init__.py logging __init__.py logging
| | | |
__init__.py mplogging.py __init__.py test_mplogging.py
Run Code Online (Sandbox Code Playgroud)
当我尝试test_mplogging.py
使用pytest
作为测试运行器时,我得到以下结果:
pydev debugger: starting
============================= test session starts ==============================
platform linux -- Python 3.3.1 -- pytest-2.3.5
plugins: pep8, cache
collected 0 items / 1 errors
==================================== ERRORS ====================================
______________________ ERROR collecting test_mplogging.py ______________________
File …
Run Code Online (Sandbox Code Playgroud) 我尝试将 MyPy 与使用 ruamel.yaml 的模块一起使用,并且 Mypy 无法找到 ruamel.yaml,即使 Python 找到它没有问题。我很困惑,因为我找不到名为 YAML.py 的模块或名为 YAML 的类,即使这些语句在 Python 中工作:
from ruamel.yaml import YAML
yaml = YAML()
x = yaml.load()
Run Code Online (Sandbox Code Playgroud)
我需要做什么才能让 MyPy 识别 ruamel.yaml?
我在源代码中有以下格式的 Sphinx 文本:
Line 1 Line 2 Line 3 Line 4
Run Code Online (Sandbox Code Playgroud)
我希望第 4 行在单独的物理行上以 HTML 呈现。这可能吗?
我正在使用以下组件运行 Vscode:
Version: 1.51.1 (user setup)
Commit: e5a624b788d92b8d34d1392e4c4d9789406efe8f
Date: 2020-11-10T23:34:32.027Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Windows_NT x64 10.0.20270
Pylance 2.6
Run Code Online (Sandbox Code Playgroud)
我有以下目录结构:
src
m1.py
.vscode
settings.json
lib
m2.py
.vscode
settings.json
Run Code Online (Sandbox Code Playgroud)
在开发 Python 代码时,我在这个环境中使用了多个 linter。Mypy
没有问题,但pylance
无法解决导入问题。
我试图m2.py
在失败m1.py
时导入模块pylance
。我的目录settings.json
下的文件src
是:
{
"python.autoComplete.extraPaths": [
"*.lib"
]
}
Run Code Online (Sandbox Code Playgroud)
谁能看到如何解决这个问题?
我有一个基类bc
和许多基于的子类bc
.
class bc(Object):
def get_subclass_name(self):
# Retrieve the name of the most derived subclass of this instance
pass
def somemethod(self):
x = self.get_subclass_name()
class sc1(bc):
pass
class sc2(bc)
pass
Run Code Online (Sandbox Code Playgroud)
我们的想法是,当somemethod()
在子类的实例上调用时bc
,它将能够使用该实例的派生程度最高的子类的名称,而无需事先知道可能存在哪些子类.
我为此编了一个测试用例:
class base_class(object):
@classmethod
def get_subclass_name(cls):
return cls.__name__
def somemethod(self):
print(base_class.get_subclass_name())
class sub_class(base_class):
pass
sub_class().somemethod()
Run Code Online (Sandbox Code Playgroud)
运行此代码时,它会产生base_class
而不是sub_class
.
我已经在3.5.0之上安装了Python 3.5.1并且我现在想要更新虚拟环境以使用3.5.1但是我找不到简单的方法来实现这一点.看起来我将不得不删除虚拟环境,然后使用新版本的Python重建它.有没有人有更简单的方法呢?
我正在尝试在以下类中运行 timeit.timeit:
from contextlib import suppress
from pathlib import Path
import subprocess
from timeit import timeit
class BackupVolume():
'''
Backup a file system on a volume using tar
'''
targetFile = "bd.tar.gz"
srcPath = Path("/BulkData")
excludes = ["--exclude=VirtualBox VMs/*", # Exclude all the VM stuff
"--exclude=*.tar*"] # Exclude this tar file
@classmethod
def backupData(cls, targetPath="~"): # pylint: disable=invalid-name
'''
Runs tar to backup the data in /BulkData so we can reorganize that
volume. Deletes any old copy of the backup …
Run Code Online (Sandbox Code Playgroud) 我的 .rst 文件中有以下文本:
Some text.
* Heading
| The first topic.
| Another topic which is very verbose and spans multiple lines ad infinitum.
Topic continued......................................
Run Code Online (Sandbox Code Playgroud)
我希望它呈现为:
Some text.
* Heading
The first topic.
Another topic which is very verbose and spans multiple lines ad infinitum....................
Topic continued.............
Run Code Online (Sandbox Code Playgroud)
然而,它在 Html 中呈现如下:
Some text.
* Heading| The first topic.| Another topic which is very verbose and spans multiple lines ad infinitum .................... Topic continued
Run Code Online (Sandbox Code Playgroud)
Sphinx 文档建议使用该|
符号来表示换行符,就像 Stackoverflow 上的几篇文章一样,但我一直无法让它工作。我想要一种独立于所使用的 Sphinx …
我有一个 Eclipse 工作区,其中~/EclipseWorkspaces/Sabia
包含 Ubuntu 15.10 下的许多项目。这些项目的源代码位于 的 Git 存储库中~/GitRepositories/Sabia
。
我无法在 Pydev Package Explorer 中告诉 Eclipse 这些项目使用 Git 存储库。如果我尝试使用Team->Share,系统会拒绝 Git 存储库,因为存储库中存在每个项目的目录,并且 Eclipse 正在尝试将项目移动到已有项目目录的存储库。
我尝试了Michal Grzejszczak 的建议,但不幸的是它不起作用,因为 Git 存储库不包含完整的项目,只包含项目的源代码树。Eclipse 元数据位于 中/EclipseWorkspaces
,而不是在 Git 存储库中,因此import projects
在 Git 存储库角度上不起作用。
此外,当我尝试删除项目时,我收到以下错误消息:
AppFrame(我的项目之一)包含与 不同步的资源
/home/jonathan/Dropbox/EclipseWorkspaces/Sabia/AppFrame
。按“继续”强制删除`
我一半的项目。
不幸的是,该消息没有提供更多信息,我不知道实际可能存在什么样的问题。在纠正错误之前,我不准备删除任何有缺陷的项目。
如何告诉 Eclipse Pydev Package Explorer Git 存储库所在的位置?
我刚刚将我的文档从 Github 上传到 ReadTheDocs,我发现它在 ReadTheDocs 和我的本地机器上呈现完全不同。我sphinx_rtd_theme
在本地机器上使用最新版本。
这是我本地机器上的显示:
这是 ReadTheDocs 上的渲染:
我在 Chrome、Firefox 和 Microsoft Edge 上尝试过,结果相同,所以它似乎不是浏览器问题。
这是我的 conf.py 的副本:
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these …
Run Code Online (Sandbox Code Playgroud) 我在Eclipse 4.8和Pydev下的Linux Ubuntu 18.04上的Python 3.7下运行。
声明:
args:Dict[str: Optional[Any]] = {}
Run Code Online (Sandbox Code Playgroud)
从我的测试代码导入的模块中。并使用来自type.py的以下错误消息进行标记:
TypeError: Parameters to generic types must be types. Got slice(<class 'str'>, typing.Union[typing.Any, NoneType], None). The stack trace follows: Finding files... done. Importing test modules ... Traceback (most recent call last): File "/Data/WiseOldBird/Eclipse/pool/plugins/org.python.pydev.core_7.0.3.201811082356/pysrc/_pydev_runfiles/pydev_runfiles.py", line 468, in __get_module_from_str
mod = __import__(modname) File "/Data/WiseOldBird/Workspaces/WikimediaAccess/WikimediaLoader/Tests/wiseoldbird/loaders/TestWikimediaLoader.py", line 10, in <module>
from wiseoldbird.application_controller import main File "/Data/WiseOldBird/Workspaces/WikimediaAccess/WikimediaLoader/src/wiseoldbird/application_controller.py", line 36, in <module>
args:Dict[str: Optional[Any]] = {} File "/usr/local/lib/python3.7/typing.py", line 251, in inner
return func(*args, **kwds) File …
Run Code Online (Sandbox Code Playgroud) 我在Windows 10上使用Python 3.6.4和Fall Creators Update.我试图使用以下代码读取XML文件:
with open('file.xml', 'rt', encoding='utf8') as file:
for line in file.readline():
do_something(line)
Run Code Online (Sandbox Code Playgroud)
readline()
每次通话都返回一个字符,而不是完整的一行.该文件是在Linux上生成的,绝对编码为UTF8,在开头没有任何特殊内容,例如BOM,并且已经过十六进制转储验证以包含有效数据.线端是0x0a
因为它来自Linux.我尝试指定-1
作为参数readline()
,这应该是默认值,而不会改变行为.该文件非常大(> 240GB),但问题发生在文件的开头.
关于我可能做错什么的任何建议?
python ×4
python-3.x ×4
eclipse ×1
git ×1
inheritance ×1
mypy ×1
pydev ×1
pylance ×1
pytest ×1
python-3.5 ×1
readline ×1
ruamel.yaml ×1