我目前正在使用Sphinx来记录一个混合语言项目,该文档不仅包含 Python 中的交互式会话示例,还包含 bash 和 Windows 命令行以及 MATLAB 和其他解释器中的交互式会话示例。虽然 Pygments 很好地突出显示了所有内容,但到目前为止我在文档中包含的所有交互式会话都显示在 HTML 输出中,前面带有 Python 提示符>>>. $例如,在记录 bash 会话时,如何将该提示更改为?
编辑澄清:
如 Sphinx 手册中的“显示代码示例”下所述,Sphinx 文档的 ReST 源可以包含如下代码:
>>> # python code here
>>> print "foo"
foo
Run Code Online (Sandbox Code Playgroud)
然后,此代码将转换为标记,如Python 标准库文档中的argparse 文档中演示的那样,将 后面的代码显示>>>为突出显示的代码片段。虽然很明显,可以简单地将未突出显示的块与其他提示字符一起排版,但我想知道如何将提示与argparse 示例>>>中显示的交互式提示样式结合起来。
我遵循以下指南。
$ pip install sphinx sphinx-autobuild
$ pip freeze | grep "sphinx"
sphinx-autobuild==0.6.0
sphinxcontrib-websupport==1.0.0
$ cd docs
$ sphinx-quickstart
$ make html
Run Code Online (Sandbox Code Playgroud)
make html 给出以下错误:
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named sphinx
make: *** [help] Error 1
Run Code Online (Sandbox Code Playgroud)
[问]如何防止发生此错误?
感谢您的宝贵时间和帮助。
假设我们有一个如下所示的文档结构
.
|____src
| |____abc.py
|____docs
Run Code Online (Sandbox Code Playgroud)
现在我们使用以下命令生成文档:
sphinx-apidoc -F -o docs src
Run Code Online (Sandbox Code Playgroud)
这会在./docs/文件夹中生成多个文件,其中包括./docs/abc.rst,我现在可以使用文件夹make html中的来构建它./docs/。
现在,在添加一些附加功能后,./src/abc.py我想重建文档。我尝试了同样的操作,Sphinx 说其余文件已经存在,因此它没有得到更新。我必须手动删除相关文件才能更新文档。
现在的问题是,如何在不删除.rst文件的情况下完成整个过程。
我正在尝试使用 OrderedDict 打印有序字典,但是当我打印它时,“OrderedDict”也会打印。仅供参考,这只是一个代码段,而不是整个代码。我能做些什么来解决这个问题?我正在使用 Python 3.2
看起来像这样:
def returnAllStats(ints):
choices = ["Yes","No"]
dictInfo = {"Calories":ints[2], "Servings per Container":ints[0], "Amount per Serving":ints[1], "Total Fat":(ints[3]/100)*ints[2], "Saturated Fat":(ints[4]/100)*(ints[3]/100)*ints[2], "Cholesterol":ints[5], "Fiber":ints[6], "Sugar":ints[7], "Protein":ints[8], "Sodium":ints[9], "USA":choices[ints[10]], "Caffeine":ints[11]}
dictInfo = collections.OrderedDict(dictInfo)
return dictInfo
Run Code Online (Sandbox Code Playgroud)
我在写入的文本文件中得到了这个:
('snack', 'bananana')OrderedDict([('USA', 'No'), ('Sodium', 119), ('Calories', 479), ('Servings per Container', 7), ('Sugar', 49), ('Saturated Fat', 37.553599999999996), ('Total Fat', 234.71), ('Cholesterol', 87), ('Amount per Serving', 40), ('Fiber', 1), ('Caffeine', 7), ('Protein', 53)])
Run Code Online (Sandbox Code Playgroud)
谢谢!
我需要从 RST 更改 Sphinx 生成的 Latexpdf 的封面页。
如何在不修改 Sphinx 包本身的情况下做到这一点?
我注意到conf文件中的latex_preamble,但这似乎只是附加了一些东西。如果是这样的话,一个例子会有所帮助。现在我所做的一切似乎只是添加而不是删除封面页。
我正在尝试使用 Python 的 xml 模块解析 XML 文件中的信息。问题是,当我指定文件列表并开始解析策略时,在(据称)成功解析第一个文件后,我收到以下错误:
Parsing 20586908.xml ..
Parsing 20586934.xml ..
Traceback (most recent call last):
File "<ipython-input-72-0efdae22e237>", line 11, in parse
xmlTree = ET.parse(xmlFilePath, parser = self.parser)
File "C:\Users\StefanCepa995\miniconda3\envs\dl4cv\lib\xml\etree\ElementTree.py", line 1202, in parse
tree.parse(source, parser)
File "C:\Users\StefanCepa995\miniconda3\envs\dl4cv\lib\xml\etree\ElementTree.py", line 601, in parse
parser.feed(data)
xml.etree.ElementTree.ParseError: parsing finished: line 1755, column 0
Run Code Online (Sandbox Code Playgroud)
这是我用来解析 XML 文件的代码:
class INBreastXMLParser:
def __init__(self, xmlRootDir):
self.parser = ET.XMLParser(encoding="utf-8")
self.xmlAnnotations = [os.path.join(root, f)
for root, dirs, files in os.walk(xmlRootDir)
for f in files if f.endswith('.xml')]
def …Run Code Online (Sandbox Code Playgroud) 我使用 Sphinx 编写文档。
现在页面路径是“folder/html/”。我想用“folder/”替换它。我尝试更改 BUILDDIR,但没有帮助。
怎么做?我用的是窗户
我已经开始学习java并且正在为这种练习编写代码.请告诉我哪里出错了,它说我在第27行有一个非法的表达.
import java.util.Scanner;
public class steps
{
public static void main(String []args)
{
Scanner Keyboard = new Scanner(System.in);
print("What is your name?");
String name = Keyboard.nextLine();
print("What is five + five?");
String number = Keyboard.nextLine();
String gj = (", Good Job");
switch (number){
case "ten":
print("correct" + gj + (" ") + name);
break;
case "Ten":
print("correct" + gj +(" ") + name);
break;
case "10":
print("correct" + gj +(" ") + name);
break;
default:
print("Wroung try again");
}
static …Run Code Online (Sandbox Code Playgroud) I have the following structure
<root>
<data>
<config>
CONFIGURATION
<config>
</data>
</root>
Run Code Online (Sandbox Code Playgroud)
使用 Python 的 ElementTree 模块,我想添加一个父元素来<config>标记为
<root>
<data>
<type>
<config>
CONFIGURATION
<config>
</type>
</data>
</root>
Run Code Online (Sandbox Code Playgroud)
此外,xml 文件可能在其他地方有其他配置标签,但我只对出现在数据标签下的那些感兴趣。
我想在 reStructuredText 文档中添加一些注释,这些注释在我构建文档时不会显示。例如,我想将以下内容放入文件中:
This is the source of my .rst file. I would like the following block to be excluded when the docs are built.
..
This should not show up in the HTML.
This should not either.
This text would show up in the HTML, as we're past the comment block.
Run Code Online (Sandbox Code Playgroud)
根据Sphinx 文档,“根据输出格式化程序,注释可能会从处理后的输出中删除。” 但是,我在HTML 输出配置文档中没有看到任何选项。
我正在使用 Sphinx ( sphinx-build) 来构建我的文档。我使用sphinx-quickstart进行设置,从而通过make html.
提前致谢!
我知道 GitHub 强烈建议使用消息,但我和我的兄弟一起从事半公共项目,而且我们在同一个房间工作,所以显然我们不需要对我们的承诺做出任何评论。是否有其他选项可以至少对于特定存储库/项目/文件完全禁用承诺消息?
我发现这个命令可以做出一个承诺:git commit -a --allow-empty-message -m ""它工作得很好,但我已经厌倦了每次都输入它。
python ×7
elementtree ×2
python-3.x ×2
xml ×2
dictionary ×1
git ×1
git-commit ×1
java ×1
latex ×1
pdflatex ×1
pip ×1
xml-parsing ×1