我试图在Ubuntu(16.04.02)上设置MariaDB(10.0.29).在我安装并启动进程(sudo service mysql start)之后,root即使我最初将密码设置为空白,也无法登录.
即mysql -u root会拒绝我的访问.我登录sudo mysql并检查了用户表,即.select user, password, authentication_string from mysql.user和预期一样:
+---------+----------+-----------------------+
| User | password | authentication_string |
+---------+----------+-----------------------+
| root | | |
+---------+----------+-----------------------+
Run Code Online (Sandbox Code Playgroud)
我还创建了一个新用户,即.create user 'test'@'localhost' identified by '';当我尝试做mysql -u test(空密码)时,它按预期工作并登录我.
用户表如下所示:
+---------+----------+-----------------------+
| User | password | authentication_string |
+---------+----------+-----------------------+
| root | | |
| test | | |
+---------+----------+-----------------------+
Run Code Online (Sandbox Code Playgroud)
所以,任何人都可以告诉我为什么我不能像root空密码一样登录,但我可以登录test?
假设我想过滤一个内置的 djangoUser模型,但我只想在 1 个过滤器字段中这样做,而不是每个字段一个过滤器。也就是说,我想直接在过滤器字段中模拟 django 管理员search_fields(django admin search_fields docs)的行为。
因此,例如,不是有一个过滤器field_name='first_name',然后是另一个过滤器field_name'last_name'等等,我想做类似的事情field_name=['first_name', 'last_name', 'email', 'username'],在那里lookup_expr='icontains'可以使用相同的东西。然后查询是一个简单的 OR 查找。这是内置的吗?我在django-filter docs 中找不到它。
或者我必须为此制作自定义过滤器。这似乎是一个非常常见的用例。
我有一个用户表单(excel,VBA),其中有一个2列组合框.当用户从组合框中选择某个值时,我想得到他选择的值,以及与第一个值相关的值(即第二个列值).
我该怎么做呢?只需ComboBox1.Value返回第一列的值即可.ComboBox1.Value(0)不起作用.
我有这种输入:
sometable = {
["a"] = {
"a1",
},
["b"] = {
"b1",
["b2"] = true,
},
["c"] = {
"c1",
["c2"] = true,
},
},
Run Code Online (Sandbox Code Playgroud)
并想将其转换为我可以在python中使用的字典-或基本上,我只需要能够以这种模式读取数据:
print sometable[b][b2]
Run Code Online (Sandbox Code Playgroud)
最好的解决方案是什么?我试图做一堆替换并使用进行转换ast,即:
def make_dict(input): # just body, ie. without 'sometable'
input = input.replace("=", ":")
input = input.replace("[\"", "\"")
input = input.replace("\"]", "\"")
input = input.replace("\t", "")
input = input.replace("\n", "")
input = "{" + input + "}"
return ast.literal_eval(input)
Run Code Online (Sandbox Code Playgroud)
问题是输出是:
{
"a" :
{"a1", },
"b" :
{"b1", "b2" : …Run Code Online (Sandbox Code Playgroud) 据我所知,fprintf将一个字符数组的指针作为参数,并打印出来.我不知道"什么时候"它会停止.请看以下示例:
假设:print_s是
void print_s(const char* s) {
fprintf(stdout,"%s",s);
}
Run Code Online (Sandbox Code Playgroud)
例1:
char c[6];
c[0] = 'a';
c[1] = 'b';
c[2] = 'c';
c[3] = 'd';
c[4] = 'e';
print_s((char*) c);
Run Code Online (Sandbox Code Playgroud)
输出:
abcd // e not printed!
Run Code Online (Sandbox Code Playgroud)
例2:
char c[6];
c[0] = 'a';
c[1] = 'b';
c[2] = 'c';
c[3] = 'd';
c[4] = 'e';
c[5] = 'b';
print_s((char*) c);
Run Code Online (Sandbox Code Playgroud)
输出:
abcdb // works as expected
Run Code Online (Sandbox Code Playgroud)
例3:
char c[6];
c[0] = 'a';
c[2] = 'c';
c[3] = 'd'; …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的课程:
class Item(object):
def __init__(self, guid, sku, name):
self.guid = guid,
self.sku = sku,
self.name = name
Run Code Online (Sandbox Code Playgroud)
当我创建一个对象时,例如:
item1 = Item('abc123', 1, 'abc1')
Run Code Online (Sandbox Code Playgroud)
我这样做:
print item1.guid
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
('abc123',)
Run Code Online (Sandbox Code Playgroud)
而不是预期的:
'abc123'
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?
PS:name按预期工作!
假设我们有以下2个表格:
CREATE TABLE tblProduct
(`Product_ID` int, `Product_Name` varchar(7));
Run Code Online (Sandbox Code Playgroud)
和
CREATE TABLE tblProductExtended
(`Product_ID` int, `Product_Size` int, `Product_Quantity` int);
Run Code Online (Sandbox Code Playgroud)
有了这些价值观:
INSERT INTO tblProduct
(`Product_ID`, `Product_Name`)
VALUES
(1, 'Shoes1'),
(2, 'Shoes2');
Run Code Online (Sandbox Code Playgroud)
和
INSERT INTO tblProductExtended
(`Product_ID`, `Product_size`, `Product_Quantity`)
VALUES
(1, 36, 20),
(1, 37, 20),
(1, 38, 30),
(2, 36, 50),
(2, 37, 60),
(2, 37, 75);
Run Code Online (Sandbox Code Playgroud)
现在很明显,tblProductExpanded中的Product_ID应该是tblProduct的Product_ID的FK.但是,我仍然可以查询:
SELECT tblProduct.Product_ID, Product_Name, Product_Size, Product_Quantity
FROM tblProduct
INNER JOIN tblProductExtended ON tblProduct.Product_id = tblProductExtended.Product_id
Run Code Online (Sandbox Code Playgroud)
哪个回报:
Product_ID Product_Name Product_Size Product_Quantity
1 Shoes1 36 20
1 …Run Code Online (Sandbox Code Playgroud) 我目前使用 Excel 中的 Solver 来寻找制造的最佳解决方案。这是当前的设置:

它涉及在旋转机器上制造鞋子,也就是说,生产是分批重复进行的。例如,一批为“10x A1”(参见表中的 A1),这将产生 10x 尺寸 36、20x 尺寸 37...10x 尺寸 41。
有一些前缀设置;A1、A2;R7...如上表所示。
然后是一个requested变量(或者更确切地说是一个变量列表),它基本上说明了客户的要求,每个尺寸的数量。
目标函数是找到一组重复,使其尽可能匹配请求的数量。因此,在解算器中(抱歉,没有英文屏幕截图),您可以看到目标是N21(即每个大小的绝对差之和)。变量是N2:N9- 这是每次设置的重复次数,唯一的限制是它N2:N9是一个整数。
我如何用 python 模拟这种行为?我的开始:
from collections import namedtuple
from pulp import *
class Setup(namedtuple('IAmReallyLazy', 'name ' + ' '.join(f's{s}' for s in range(36, 47)))):
# inits with name and sizes 's36', 's37'... 's46'
repetitions = 0
setups = [
Setup('A1', 1, 2, 3, 3, 2, 1, 0, 0, 0, 0, 0),
Setup('A2', …Run Code Online (Sandbox Code Playgroud)