小编Cra*_*arB的帖子

IntelliJ IDEA 12 Python包管理器?

我使用JetBrains的IntelliJ IDEA 12进行Java和Python开发(通过官方Python IntelliJ插件进行Python开发).我的朋友使用PyCharm(同样的公司和类似的界面,专门用于Python),他向我展示了PyCharm的一个很酷的功能:IDE内置了一个Python包管理器.我查看了IntelliJ IDEA中的菜单选项,但是我找不到任何与Python包有关的内容.这是否存在于IntelliJ IDEA/Python插件中,或者我现在运气不好/除非我转到PyCharm进行专门的Python开发?

我目前正在使用Python 3.2和IntelliJ 12.1.4以及Python插件2.10.1.

intellij-idea pycharm python-3.x

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

将Boost标头安装到特定目录(Windows)

我已经下载,提取和编译了Boost库(包括单独编译的库).我现在已经使用了他们的安装程序几次,但我似乎无法完全按照我的意愿去做.现在,当我在编译后安装Boost时,它会进入

C:\Boost
Run Code Online (Sandbox Code Playgroud)

这可以.编译的库转到

C:\Boost\lib
Run Code Online (Sandbox Code Playgroud)

这也没关系.我遇到的问题是安装了预编译的头文件.他们得到了

C:\Boost\include\boost-1_54\boost
Run Code Online (Sandbox Code Playgroud)

有没有办法使用Boost构建系统和安装工具来设置要安装的预编译头文件

C:\Boost\include
Run Code Online (Sandbox Code Playgroud)

并没有Boost版本号是该文件夹层次结构的一部分?

我不打算同时使用多个版本的Boost,所以我没有实际拥有该版本号的用途.我意识到我可以在安装完成后手动移动它们,但我想首先看看我是否忽略或误解了Boost的构建系统.

c++ windows boost install

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

Python timeit模块执行混乱

我正在尝试使用Python中的timeit模块(编辑:我们使用的是Python 3)来决定几个不同的代码流.在我们的代码中,我们有一系列if语句来测试字符串中是否存在字符代码,如果有,则将其替换为:

if "<substring>" in str_var:
    str_var = str_var.replace("<substring>", "<new_substring>")
Run Code Online (Sandbox Code Playgroud)

对于不同的子串,我们这样做了很多次.我们在这之间进行辩论并使用像这样的替换:

str_var = str_var.replace("<substring>", "<new_substring>")
Run Code Online (Sandbox Code Playgroud)

我们尝试使用timeit来确定哪一个更快.如果上面的第一个代码块是"stmt1"而第二个是"stmt2",我们的设置字符串看起来像

str_var = '<string><substring><more_string>',
Run Code Online (Sandbox Code Playgroud)

我们的timeit语句如下所示:

timeit.timeit(stmt=stmt1, setup=setup)
Run Code Online (Sandbox Code Playgroud)

timeit.timeit(stmt=stmt2, setup=setup)
Run Code Online (Sandbox Code Playgroud)

现在,在我们的两台笔记本电脑上运行它(相同的硬件,类似的处理负载)stmt1(带有if语句的语句)即使在多次运行后也会运行得更快(3-4个百分点,大约四分之一) stmt2的第二个).

但是,如果我们定义函数来做两件事(包括创建变量的设置),如下所示:

def foo():
    str_var = '<string><substring><more_string>'
    if "<substring>" in str_var:
        str_var = str_var.replace("<substring>", "<new_substring>")
Run Code Online (Sandbox Code Playgroud)

def foo2():
    str_var = '<string><substring><more_string>'
    str_var = str_var.replace("<substring>", "<new_substring>")
Run Code Online (Sandbox Code Playgroud)

和运行timeit像:

timeit.timeit("foo()", setup="from __main__ import foo")
timeit.timeit("foo2()", setup="from __main__ import foo2")
Run Code Online (Sandbox Code Playgroud)

没有if语句(foo2)的语句运行得更快,与非功能结果相矛盾.

我们是否遗漏了Timeit的工作原理?或者Python如何处理这样的案例?

编辑这里是我们的实际代码:

>>> def foo():
    s = "hi 1 2 3"
    s = s.replace('1','5')

>>> …
Run Code Online (Sandbox Code Playgroud)

python timeit python-3.x

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

标签 统计

python-3.x ×2

boost ×1

c++ ×1

install ×1

intellij-idea ×1

pycharm ×1

python ×1

timeit ×1

windows ×1