小编dav*_*o36的帖子

Python line_profiler 安装

嗨,我是 Python 新手程序员。我想要逐行分析,因此尝试安装 line_profiler 包。但它不起作用。这是我所做的:

顺便说一下,我使用的是 64 位 Windows 8.1,并且正在使用 Enthought Canopy。

我从这里得到了 Windows 安装包:https : //pypi.python.org/pypi/line_profiler并安装了它。

它在 line_profiler 站点上说 a) 我不需要构建它或需要 Cython,b) 我应该这样做:

对于 IPython 0.11+,您可以通过编辑 IPython 配置文件 ~/.ipython/profile_default/ipython_config.py 将“line_profiler”项添加到扩展列表中来安装它:

c.TerminalIPythonApp.extensions = ['line_profiler', ]

我重新启动了 Canopy,没有运气。应该有一个魔法命令 %lprun。它不在那里。

我尝试了 %load_ext line_profiler 但收到了这条消息:

C:\Users\OEM\AppData\Local\Enthought\Canopy\User\lib\site-packages\line_profiler.py in () 10 import sys 11 ---> 12 from _line_profiler import LineProfiler as CLineProfiler 13 14

导入错误:DLL 加载失败:%1 不是有效的 Win32 应用程序。

其他事情:我为此寻找了 setup.py,但找不到似乎安装在 C:\Users\OEM\AppData\Local\Enthought\Canopy\User\Lib\site-packages 中的 line_profiler文件夹。

因此,请感谢任何帮助。

python installation enthought canopy

5
推荐指数
2
解决办法
5895
查看次数

Python 多重处理和参数传递需要帮助

您好,我正在尝试运行文档中的多处理示例:http://docs.python.org/3.4/library/concurrent.futures.html,该示例使用素数但有很小的差异。

我希望能够调用具有多个参数的函数。我正在做的是将小块文本(在大约 30k 长的列表中)与更大的文本块进行匹配,并返回较大字符串中较小字符串的开始位置。

我可以像这样连续执行此操作:

matchList = []
for pattern in patterns:

    # Approximate pattern matching
    patternStartingPositions = processPattern(pattern, numMismatchesAllowed, transformedText, charToIndex, countMatrix, firstOccurrence, suffixArray)

    # Now add each starting position found onto our master list.
    for startPos in patternStartingPositions:
        matchList.append(startPos)
Run Code Online (Sandbox Code Playgroud)

但我想这样做是为了加快速度:

matchList = []
with concurrent.futures.ProcessPoolExecutor() as executor:
    for pattern, res in zip(patterns, executor.map(processPattern(pattern, numMismatchesAllowed, transformedText, charToIndex, countMatrix, firstOccurrence, suffixArray), patterns)):
        print('%d is starts at: %s' % (pattern, res))
Run Code Online (Sandbox Code Playgroud)

在这个阶段,我刚刚在那里得到了打印调用,因为我无法得到上面的行,即调用进程的工作。

我想要做的和示例代码之间唯一真正的区别是我的函数需要 7 个参数,但我不知道如何去做,花了半天时间。

上面的调用会生成此错误:

UnboundLocalError:赋值前引用的局部变量“模式”。

这是有道理的。

但是,如果我省略第一个参数(即每次调用时都会更改的参数),并省略函数的第一个参数 …

multiprocessing argument-passing python-3.x

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

如何在Golang中使用gobuffalo / packr

我正在尝试播放Golang的声音。这是一个.wav文件。我想使用packr将.wav文件打包到可执行文件中

我在这里创建了一个非常小的项目:带有代码的packr-test存储库

当我在其默认文件夹中运行可执行文件(./packr-test)时,会播放声音。但是我遇到的问题是,当我将可执行文件移动到另一个目录时,尝试播放声音文件时出现错误。我认为这可能意味着声音文件没有与可执行文件捆绑在一起。

这是在Ubuntu上。我使用的是默认情况下经常安装的“播放”命令,但是如果没有,可以使用以下命令完成:

sudo apt-get install sox
sudo apt-get install sox libsox-fmt-all
Run Code Online (Sandbox Code Playgroud)

要使用播放命令:

play file_name.extension
Run Code Online (Sandbox Code Playgroud)

为了节省您的查找,这是我的Go代码:

package main

import (
    "fmt"
    "os/exec"

    "github.com/gobuffalo/packr"
)

func main() {

    soundsBox := packr.NewBox("./sounds")
    if soundsBox.Has("IEEE_float_mono_32kHz.wav") {
        fmt.Println("It's there.")
    } else {
        fmt.Println("It's not there.")
    }

    args := []string{"-v20", "./sounds/IEEE_float_mono_32kHz.wav"}
    output, err := exec.Command("play", args...).Output()
    if err != nil {
        // Play command was not successful
        fmt.Println("Got an error.")
        fmt.Println(err.Error())
    } else {
        fmt.Println(string(output))
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的输出:

sudo ./packr-test …
Run Code Online (Sandbox Code Playgroud)

go

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

Go 模板一起迭代多个数组

我在这里阅读了很多与 Go 模板相关的帖子,但找不到我要找的内容。

我有这两个结构,我无法更改它们,因为它们在我正在帮助的项目的其他地方使用:

type Schedule struct {
    Description   string
    ControlNights int
    PlayNights    int
    StartDay      int
    Combos        []Combo
}

type Combo struct {
    From    time.Time
    Every   int
    Until   time.Time
    Sounds  []string
    Volumes []int
    Waits   []int
}
Run Code Online (Sandbox Code Playgroud)

我需要在 html 页面上显示这些数据。所以我需要迭代每个 Combo。我可以做到这一点,但我需要将声音、音量和等待放在一起,即声音 x 音量 y 等待 z。其中 x、y 和 z 是 Sounds、Volumes 和 Waits 数组中的值。这些数组可以是 >= 1 的任意长度,但它们都具有相同的长度。

我希望它看起来像这样:

在此输入图像描述

我已经尝试过这个:

            {{range .Schedule.Combos}}
            <div class="container">
                <div class="row">
                    <div class="col">
                        <div class="card mt-2 ml-2">
                            <div class="card-body">
                                <h5 class="card-title">
                                    <strong>Timing</strong>
                                </h5>
                                <h5 class="card-text">
                                    Play every …
Run Code Online (Sandbox Code Playgroud)

html templates go

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