小编Val*_*ntz的帖子

使用ISQL执行脚本

我正在创建一个简单的isql脚本,但它不起作用,我需要一些帮助来找出它的错误.
我需要连接到数据库并执行SQL文件.这是我的脚本,名为script.sql:

CONNECT 'localhost:C:\Monde\Servidor\db\monde.fdb' USER 'SYSDBA' PASSWORD 'masterkey';    
update usuario  
set senha = 'MYkWEn0kHLHHdm'  
where login = 'rose'
Run Code Online (Sandbox Code Playgroud)

当我尝试连接到我的数据库使用:

isql.exe -i script.sql
Run Code Online (Sandbox Code Playgroud)

我得到以下消息:

Use CONNECT or CREATE DATABASE to specify a database
Expected end of statement, encountered EOF
Run Code Online (Sandbox Code Playgroud)

firebird interbase isql

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

拥有多列QTreeWidget根项

我正在使用QTreeWidget来显示类别中的项目.项目将使用多个列,但我希望类别(即根项目)使用窗口小部件的整个宽度.

我怎样才能做到这一点?

还有我的一段代码:

class BugsList(QtGui.QDialog):
    def __init__(self, parent, reports):
        super(BugsList, self).__init__(parent) # Call QDialog constructor
        self._tree = QtGui.QTreeWidget(self)
        self._tree.setColumnCount(NUMBER_OF_COLUMNS)
        # ...
        for category, bugs in reports:
            category_widget = QtGui.QTreeWidgetItem(self._tree, [category])
            # ...
Run Code Online (Sandbox Code Playgroud)

以下是我的应用程序当前状态的屏幕截图: 截图

qt pyqt qtreewidget

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

Python importlib对imp.new_module()的模拟

PyCharm告诉我imp已被弃用,所以我想知道是否有任何类似的imp.new_module for importlib.

python python-import python-3.x python-importlib

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

有多个推销员的旅行推销员,每个推销员的城市数量有限制吗?

问题:我需要删除(N)从办公室员工家园(坐标可用).我有(x) 7座和(y) 4座驾驶室.

  1. 我必须设计一种算法,让所有员工在最短距离内离开家.

  2. 此外,该算法必须告诉我必须选择多少7座或/和4座车辆以便行驶最小距离.

例如.如果我有15名员工,那么算法可能会告诉我使用1(7座)驾驶室和2(4座)驾驶室并让每个驾驶室的员工如下:

[(E2,E4,E6,E8),(E1,E3,E5,E7,E9,E10,E12),(E11,E13,E14,E15)]

方法:我认为这是一个旅行推销员问题,有多个推销员,每个人都可以旅行的城市数量上限.销售人员也不需要回到原点.我想到了Ant的殖民地问题,但我无法明智地选择哪种算法可供选择

要求:我真的需要ALGORITHM.无论是TSP还是Ant的殖民地,都无关紧要.我会欢迎意见,但我真的需要算法.

algorithm heuristics mathematical-optimization traveling-salesman

7
推荐指数
2
解决办法
739
查看次数

如何在python中将sha256对象转换为整数并将其打包为bytearray?

我想先把一个hash256对象转换成一个32字节的整数,然后再打包成一个bytearray。

>>> import hashlib
>>> hashobj = hashlib.sha256('something')
>>> val_hex = hashobj.hexdigest()
>>> print val_hex
3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb
>>> print len(val_hex)
64
Run Code Online (Sandbox Code Playgroud)

十六进制字符串是 64 字节而不是 32 字节,这不是我想要的。

>>> val = hashobj.digest()
>>> print val
???E?s????????5Bkz@R???6??H?
>>> print len(val)
32
Run Code Online (Sandbox Code Playgroud)

这是一个 32 字节的字符串,我想将其转换为 32 字节的整数。

当我尝试时,它给了我一条错误消息:

>>> val_int = int(val, 10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '?\xc9\xb6\x89E\x9ds\x8f\x8c\x88\xa3\xa4\x8a\xa9\xe35B\x01kz@R\xe0\x01\xaa\xa56\xfc\xa7H\x13\xcb'
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能得到我的 int_val?

以及如何使用 struct 将其(32 字节)打包为字节数组?我发现python结构文档中最长的格式是'Q',它只有8个字节。

非常感谢。

python type-conversion python-2.x

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

不能将一个数组分配给另一个

我尝试通过不同的方式将一个数组指针复制到另一个数组指针,但没有成功。这是我的尝试,以及相关的错误消息。

typedef long int coordinate;
typedef coordinate coordinates[3];

void test(coordinates coord) {
    coordinates coord2 = coord; // error: invalid initializer
    coordinates coord3;
    coord3 = coord; // error: incompatible types when assigning to type ‘coordinates’ from type ‘long int *’
    coord3 = (coordinates) coord; // error: cast specifies array type
    coord3 = (coordinate[]) coord; // error: cast specifies array type
    coord3 = (long int*) coord; // error: incompatible types when assigning to type ‘coordinates’ from type ‘long int *’
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用 …

c

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

numpy数组上的可分离过滤器

假设我有一个numpy数组a,我想创建一个新的数组,bb[i, j]是一个函数,比如说:

a[i-1, j-1], a[i-1, j  ], a[i-1, j+1],
a[i  , j-1], a[i  , j  ], a[i  , j+1],
a[i+1, j-1], a[i+1, j  ], a[i+1, j+1]
Run Code Online (Sandbox Code Playgroud)

最快的方法是什么?

由于这是一个可分离的过滤器,有没有办法在多个线程中运行它?(不是进程,因为我必须将数据复制回来)

或者正在编写C代码以绕过GIL强制执行?

部分解决方案(如假设功能是线性的)也是受欢迎的.

python arrays numpy image-processing gil

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

使用textwrap.wrap的字节数

如何textwrap在行达到一定字节数之前使用模块拆分(不拆分多字节字符)?

我想要这样的东西:

>>> textwrap.wrap('? ?? ?? ? ? ?? ??', bytewidth=10)
? ??
?? ?
? ??
??
Run Code Online (Sandbox Code Playgroud)

python split word-wrap python-3.x python-unicode

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

在unordered_map中设置unordered_set

如何将(静态定义的)unordered_set添加到unordered_map,而不必复制unordered_set?

我试过这个:

std::unordered_map<int, std::unordered_set<std::string>> my_map;
for (int i=0; i<100; i++)
  my_map.emplace(i, {"foo", "bar"});
Run Code Online (Sandbox Code Playgroud)

还有这个:

std::unordered_map<int, std::unordered_set<std::string>> my_map;
for (int i=0; i<100; i++)
  my_map.insert(i, std::move(std::unordered_set<std::string>({"foo", "bar"})));
Run Code Online (Sandbox Code Playgroud)

但是没有一个编译,我得到这些错误(分别):

error: no matching function for call to ‘std::unordered_map<int, std::unordered_set<std::basic_string<char> > >::emplace(int&, <brace-enclosed initializer list>)’
Run Code Online (Sandbox Code Playgroud)

error: no matching function for call to ‘std::unordered_map<int, std::unordered_set<std::basic_string<char> > >::insert(int&, std::remove_reference<std::unordered_set<std::basic_string<char> > >::type)’
Run Code Online (Sandbox Code Playgroud)

c++ unordered-map move c++11 emplace

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

“借入的数据不能在其关闭之外存储”是什么意思?

编译以下代码时:

fn main() {
    let mut fields = Vec::new();
    let pusher = &mut |a: &str| {
        fields.push(a);
    };
}
Run Code Online (Sandbox Code Playgroud)

编译器给我以下错误:

fn main() {
    let mut fields = Vec::new();
    let pusher = &mut |a: &str| {
        fields.push(a);
    };
}
Run Code Online (Sandbox Code Playgroud)

此错误是什么意思,我该如何修复我的代码?

closures ownership rust borrow-checker

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