小编eri*_*rip的帖子

点子安装错误django

去年夏天我想学习做web开发,所以我安装了Django 1.8,这是一个不稳定的版本.我安装它没有点子.我最近决定再次尝试,但是想要使用稳定版本1.7.1,并且为了简单起见想要使用pip进行安装.

我看,为了去除不PIP安装的Django,必须删除整个.egg/Library/Python/2.7/site-packages/,所以我做到了这一点.

从那以后,我一直在搞笑.当我发出'pip install django'时,我明白了

bash-3.2$ pip install django
Downloading/unpacking django
  Downloading Django-1.7.1-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded
Installing collected packages: django
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 671, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 901, in move_wheel_files
    pycompile=self.pycompile,
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line …
Run Code Online (Sandbox Code Playgroud)

python django

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

`for_each`没有像我预期的那样工作

我正在使用函数式编程的一些功能,并试图为向量中的每个对象调用成员函数.到目前为止,这是我的代码.

emplace.cc

#include <iostream>
#include <vector>
#include <string>
#include <functional>

class Person {
   public:
      Person(std::string name, size_t age) : _name(name), _age(age) { std::cout << "Hello, " << getName() << std::endl; }
      ~Person() { std::cout << "Goodbye, "<< getName() << std::endl; }
      void greet() { std::cout << getName() << " says hello!" << std::endl; }
      std::string getName() const { return _name; }
   private:
      std::string _name;
      size_t _age;

};

int main()
{
   std::vector<Person> myVector;
   myVector.emplace_back("Hello", 21);
   myVector.emplace_back("World", 20);

   std::for_each(myVector.begin(), myVector.end(), std::bind1st(std::mem_fun(&Person::greet), this)); …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm functional-programming bind

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

如何投射和使用u.8

我正在研究Rust中的一些编码挑战,其中一个问题是确定一个短语是否是一个pangram.我见过以下实现:

// Copy chars into a vector, sort and remove duplicates
let mut chars: Vec<char> = pangram.chars().collect();
chars.sort();
chars.dedup();
Run Code Online (Sandbox Code Playgroud)

然而,这种解决方案是O(nlogn)时间因为排序.我可以及时做到O(n),但我遇到了问题.

下面是我试过写的代码:

fn is_pangram(s: String) -> bool {
    let mut num_seen = 0;
    let mut seen: [bool; 26] = [false; 26];

    for c in s.to_lowercase().as_bytes() {
        // ASCII 10 is newline character
        if c as usize == 10 {
            break;
        }

        // Lowercase ASCII is 97 to 122
        if !seen[122 - c as usize] {
            seen[122 - …
Run Code Online (Sandbox Code Playgroud)

casting rust

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

数据通过引用而不是值

我正在尝试制作一个具有菜单的程序,并且可以选择设置"当前"日期.我可以定义日期,它将一直保持到程序关闭.我有另一种方法来获取日期,通过询问用户链接一个人的日期,问题是它不会继续主菜单上的主要数据.它只是人员结构上.date的数据,我想我解释得很好.我尝试了很多方法,如果有人可以帮我解决的话,我真的无法理解...

typeData readData() {    
    int val;
    typeData data;
    do {
        printf("Day: ");
        data.day = readInteger(MIN_DAYS, MAX_DAYS);
        printf("Month: ");
        data.month = readInteger(MIN_MONTH, MAX_MONTH);
        printf("Year: ");
        data.year = readInteger(MIN_YEAR, MAX_YEAR);
        val = validateData(data);
        if(val == 0) {
            printf("The data is not valid.\n");
        }
    } while (val == 0);
    return data;
}
Run Code Online (Sandbox Code Playgroud)

我想我需要通过引用得到它,但我已经尝试了一段时间而且不能这样做.感谢大家.

c

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

哪种数据结构类似于双向链表和数组的组合?

是否有任何已经创建的结构是简单basic arraydoubly linked list nodes

我的意思是,然后你使用get(int index)它将直接从数组(array[i].element)返回元素。使用这种结构,我也可以轻松地执行 foreach 操作,因为每个元素都会相互链接,因此我不需要考虑空白数组位置。

问:为什么我需要这个?答:我有无限的内存,我知道我需要多大的数组,并且我希望该结构是最快的。

c++ data-structures

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

如何从 Flask 中的输入中获取表单数据作为变量?

我正在开发一个简单的用户界面来通过 ID 启动和停止游戏。我写的基本HTML如下(game_id由JS填充):

  <div align="center" class="top">
    <div align="left" class="game-id-input">
      Game ID: <input type="text" name="game_id" id="game_id">
    </div>

    <div align="right" class="buttons">
      <form action="{{ url_for('start_game', game_id=game_id) }}" method="get">
        <input type="submit" name="start" value="Start game" class="btn btn-success"></input>
      </form>
      <form action="{{ url_for('end_game', game_id=game_id) }}" method="get">
        <input type="submit" name="end" value="End game" class="btn btn-danger"></input>
      </form>
    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

看起来像

输入和按钮

我还为每种形式定义了 Flask 路由函数:

@app.route("/start_game/<game_id>")
def start_game(game_id):
    # ...

@app.route("/end_game/<game_id>")
def end_game(game_id):
    # ...
Run Code Online (Sandbox Code Playgroud)

在我的表单中,如何才能game_idgame_idfrom相对应#game_id

目前,当我提交开始和结束游戏时,我收到“文件未找到”错误,因为它只是将文字附加<game_id>到路线。

我是网络开发新手。这应该是微不足道的,但我不知道要搜索什么。提前抱歉问这么简单的问题。

html python routes flask

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

静默打印导入的Python脚本

我想将python脚本导入到另一个脚本中.

$ cat py1.py
test=("hi", "hello")

print test[0]

$ cat py2.py
from py1 import test

print test
Run Code Online (Sandbox Code Playgroud)

如果我执行py2.py:

$ python py2.py 
hi
('hi', 'hello')
Run Code Online (Sandbox Code Playgroud)

无论如何我可以静音第一个print来自的from py1 import test

我不能评论的printpy1,因为它正在使用其他地方.

python

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

为什么我不能抓住我的例外?

我有以下函数捕获ComObject的系统异常并抛出我自己的异常:

int TReader::ExecSQL(...) {
  try {
    // ...
  } catch (Comobj::EOleException& e) {
    throw myDBError("TReader::Open", "TReader", e.Message);
  }
// ...   
}
Run Code Online (Sandbox Code Playgroud)

我无法捕获自己的异常,总是"异常未知!"!为什么?

void main() {
  try {
    ExecSQL(...);
  } catch(myDBError& e) {
    log(e.Message);
  } catch(...) {
    log("Exception unknown!");
  }
}
Run Code Online (Sandbox Code Playgroud)

c++ exception

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

Arduino - 通过指针传递struct似乎比按值慢

我写了一些假代码,可以解释我在实际应用程序中发现的问题(Arduino 1.6 - https://github.com/maciejmiklas/LEDDisplay):

Display.h:

class Display {

public:
    void testRef();
    void testVal();

private:
    typedef struct {
            uint8_t xOnFirstKit;
            uint8_t yOnFirstKit;
            uint8_t xRelKit;
            uint8_t yRelKit;
            uint8_t xRelKitSize;
            uint8_t yRelKitSize;
            uint8_t xDataBytes;
            uint8_t xKit;
            uint8_t yKit;
            uint8_t xOnKit;
            uint8_t yOnKit;
            uint8_t xOnKitSize;
            uint8_t yOnKitSize;
            uint8_t xOnScreenIdx;
            uint8_t yOnScreenIdx;
            uint8_t yDataIdx;
        } KitData;

 inline void paintOnKitRef(KitData *kd); 
 inline void paintOnKitVal(KitData kd); 
}


Display.cpp:

#include "Display.h"

void Display::testRef(){
    KitData *kd = ....

    for(int i = 0 ; i < 5000 ; i++){ …
Run Code Online (Sandbox Code Playgroud)

c++ arduino

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

如何使用multiindex数据框创建海洋回归图?

我有时间序列数据,这些数据在(年,月)上具有多个索引,如下所示:

print(df.index)
print(df)
Run Code Online (Sandbox Code Playgroud)
MultiIndex(levels=[[2016, 2017], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]],
           labels=[[0, 0, 0, 0, 0, 0, 0, 0], [2, 3, 4, 5, 6, 7, 8, 9]],
           names=['Year', 'Month'])
            Value
Year Month            
2016 3       65.018150
     4       63.130035
     5       71.071254
     6       72.127967
     7       67.357795
     8       66.639228
     9       64.815232
     10      68.387698
Run Code Online (Sandbox Code Playgroud)

我想对这些时间序列数据进行非常基本的线性回归。因为pandas.DataFrame.plot不进行任何回归,所以我打算使用Seaborn进行绘图。

我尝试通过使用以下方法lmplot

sns.lmplot(x=("Year", "Month"), y="Value", data=df, fit_reg=True) 
Run Code Online (Sandbox Code Playgroud)

但我得到一个错误:

TypeError: '>' not supported between instances of 'str' and 'tuple'
Run Code Online (Sandbox Code Playgroud)

这对我来说特别有趣,因为中的所有元素df.index.levels[:]都是类型 …

linear-regression python-3.x pandas seaborn

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