小编Per*_*nce的帖子

pybind11“ Python是64位的,选择的编译器是32位的”

我正在尝试在安装了VisualStudio 2015的Windows计算机上编译pybind11。我还安装了python 3.5.3 64bit和cmake 2.8.12。我得到错误:

CMake Error at tools/FindPythonLibsNew.cmake:122 (message):
  Python config failure: Python is 64-bit, chosen compiler is 32-bit
Call Stack (most recent call first):
  tools/pybind11Tools.cmake:16 (find_package)
  CMakeLists.txt:28 (include)
Run Code Online (Sandbox Code Playgroud)

我没有“选择”编译器为32位,并且在CMakeLists.txt中,我没有找到指定运行哪个编译器的地方。那么如何告诉pybind11 / cmake编译为64位呢?

cmake visual-studio-2015 pybind11

5
推荐指数
1
解决办法
3473
查看次数

如何在绝对线宽的SVG中绘制多边形?

我的应用程序生成一组要在SVG中绘制的图形点.点值始终在水平和垂直方向上为0-1000.绘图发生的矩形的大小可能会改变.

这是在200 X 85 rect上绘制图形的SVG元素:

<svg width="200" height="85" viewBox="0 0 1000 1000" preserveAspectRatio="none">
    <polyline  stroke="#e69800"
               stroke-width="2px"
               fill="none"
               points="0,1000 100,900 200,800
                       300,700 400,600 500,500
                       600 400 700,300 800,200900,100 1000,0"/>
</svg>
Run Code Online (Sandbox Code Playgroud)

设置viewBox="0 0 1000 1000"使图形缩小到适当的大小,问题是这也会以相同的比例缩小线条的宽度,因此该线条不再可见.

SVG似乎忽略了属性中的"px" stroke-width="2px".

有没有办法用绝对像素大小指定线宽(笔画宽度)?

svg

3
推荐指数
1
解决办法
2878
查看次数

Python字典使用PyYaml进入yaml文档

我有两个python词典,我想写一个yaml文件,有两个文件:

definitions = {"one" : 1, "two" : 2, "three" : 3}
actions = {"run" : "yes", "print" : "no", "report" : "maybe"}
Run Code Online (Sandbox Code Playgroud)

yaml文件应如下所示:

--- !define
one: 1
two: 2
three: 3

-- !action
run: yes
print: no
report: maybe
...
Run Code Online (Sandbox Code Playgroud)

使用PyYaml我没有找到明确的方法来做到这一点.我确信有一个简单的方法,但深入研究PyYaml文档,只会让我感到困惑.我需要自卸车,发射器还是什么?这些类型产生什么类型的输出?Yaml文字?yaml节点?YAMLObject?无论如何,如果有任何澄清,我将不胜感激.


按照下面unutbu的回答,这是我能提出的最简洁的版本:

DeriveYAMLObjectWithTag是一个创建新类的函数,该类派生自具有所需标记的YAMLObject:

def DeriveYAMLObjectWithTag(tag):
    def init_DeriveYAMLObjectWithTag(self, **kwargs):
        """ __init__ for the new class """
        self.__dict__.update(kwargs)

    new_class = type('YAMLObjectWithTag_'+tag,
                    (yaml.YAMLObject,),
                    {'yaml_tag' : '!{n}'.format(n = tag),
                    '__init__' :  init_DeriveYAMLObjectWithTag})
    return new_class
Run Code Online (Sandbox Code Playgroud)

以下是如何使用DeriveYAMLObjectWithTag获取所需的Yaml:

definitions = {"one" : 1, "two" : 2, …
Run Code Online (Sandbox Code Playgroud)

python yaml pyyaml

3
推荐指数
1
解决办法
1万
查看次数

python3.6 使用unicode创建win32快捷方式

我有python3.6创建 Windows 快捷方式的代码:

\n\n
from win32com.client import Dispatch\npath_to_target = r"C:\\Program Files\\\xe3\x83\x94\xe3\x83\x81\xe3\x83\xa3\xe3\x83\xbc\xe3\x83\xa0\\pycharm64.exe"\npath_to_shortcut = r"C:\\Program Files\\pycharm.lnk"\nshell = Dispatch("WScript.Shell")\nshortcut = shell.CreateShortCut(path_to_shortcut)\xe2\x80\xa8            \nshortcut.Targetpath = path_to_target  # exception here\nshortcut.save()\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果path_to_target包含任何非 ASCII 字符,我会得到一个异常:Property \'&lt;unknown&gt;.Targetpath\' can not be set.

\n\n

path_to_target如果只有 ascii 字符,代码可以正常工作并创建正确的快捷方式。

\n\n

如何创建具有 unicode 字符的目标的快捷方式?

\n\n

是否有替代 API 来创建 Windows 快捷方式?

\n

python pywin32 win32com python-3.6

3
推荐指数
1
解决办法
750
查看次数

在python中将数字转换为意大利语和意大利语转换为数字

我需要 Python 代码来将数字与意大利语相互转换。

查看之前的问题,我了解到 pynum2word 在多种语言中以一种方式(num -> Words)执行操作,但遗憾的是,在意大利语中则不然。

如果 Python 中不存在这样的代码,我不介意从 Perl/Ruby/Java 翻译这样的代码。

谢谢。

python

2
推荐指数
1
解决办法
974
查看次数

没有使用python 3.3的软件包安装程序?

我刚下载了适用于Mac OS的已安装的python 3.3.我使用了python.org标准包

我在python 3.3中找不到包安装工具.没有点子,easy_install,setuptools.看起来像引导带问题:如何在没有软件包安装包的情况下安装软件包安装包?

我错过了一些明显的东西吗?或者我是否需要采取进一步措施才能拥有包安装程序?

macos pip easy-install python-3.x

2
推荐指数
1
解决办法
3809
查看次数

Python实例属性从类属性获取具有相同名称的初始值?

class bambino(object):
    counter = 7
    def __init__(self):
        print("bambino.counter is self.counter ?", bambino.counter is self.counter)
        self.counter += 1
        print("bambino.counter is self.counter ?", bambino.counter is self.counter)

bambi1 = bambino()
print ("bambi1.counter:", bambi1.counter)
print ("bambino.counter:", bambino.counter)
Run Code Online (Sandbox Code Playgroud)

打印:

bambino.counter is self.counter ? True
bambino.counter is self.counter ? False
bambi1.counter: 8
bambino.counter: 7
Run Code Online (Sandbox Code Playgroud)

我明白通过做self.counter += 1 反击成为不属于类的实例的属性.

但为什么bambi1.counter从它的初始价值bambino.counter

python attributes class

1
推荐指数
1
解决办法
96
查看次数