# coding: utf-8 import re import pandas as pd from openpyxl import Workbook
rz = re.compile(r'/(\d+-\d)-.+jpg')
d = {}
dkey = {}
def open_csv(): for file in file_paths: ex = pd.read_csv(file) exs = ex.values.tolist() for i in exs: url = i[4] url_id = rz.findall(url) print(url_id) if len(url_id)== 0 : continue url_id = url_id[0] if url_id not in d: d.update({url_id: [url]}) else: d[url_id].append(url)
for k, v in d.items(): ks = str(k).split('-') k1 = ks[0] k2 = ks[1] if k1 not in dkey: if str(k2) == '1': dkey.update({k1: {'0': [], '1': v}}) else: dkey.update({k1: {'0': v, '1': []}}) else: if str(k2) == '1': dkey[k1]['1'].extend(v) else: dkey[k1]['0'].extend(v)
for k, v in dkey.items(): print(type(k), v) wb.append([str(k), str(v['0']), str(v['1'])])
for i in orl_key: if str(i) not in dkey: print(type(i), 'iii') wb.append([str(i)])
if __name__ == "__main__": orl_urlids = pd.read_excel(r'2.xlsx') orl_urls = orl_urlids.values.tolist() orl_key = [i[0] for i in orl_urls]
// Model base model definition, including fields `ID`, `CreatedAt`, `UpdatedAt`, `DeletedAt`, which could be embedded in your models // type User struct { // gorm.Model // } type Model struct { ID uint `gorm:"primary_key"` CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` }
添加非空约束 alter table 表名 modify column 列名 要修改的类型 not null
默认约束 alter table 表名 modify column 列名 int default 18
添加主键 列级约束 alter table 表名 modify column 列名 int default key; 表级约束 alter table 表名 add primary key(列名)
添加唯一 列级约束 alter table 表名 add primary key(列名) 要修改的类型 notnull 表级约束 alter table 表名 add unique(列名)
添加外键 alter table 表名 add foreign key(majorid) references major(id)
修改表时删除约束
删除非空 alter table 表名 modify column 列名 varchar(20) null; 删除默认约束 alter table 表名 modify column 列名 int; 删除主键 alter table 表名 drop primary key; 删除唯一 alter table 表名 drop index 列名; 删除外键 alter table 表名 drop foreign key 列名;
('Google', 'Runoob', 1997, 2000) 删除后的元组 tup : Traceback (most recent call last): File "main.py", line 9, in print (tup) NameError: name 'tup' is not defined
#!/usr/bin/python3 # Fibonacci series: 斐波纳契数列 # 两个元素的总和确定了下一个数 a, b = 0, 1 while b < 1000: print(b, end=',') a, b = b, a+b
1
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,
条件控制
1 2 3 4 5 6
if condition_1: statement_block_1 elif condition_2: statement_block_2 else: statement_block_3
if 嵌套:可以把 if…elif…else 结构放在另外一个 if…elif…else 结构中
1 2 3 4 5 6 7 8 9 10 11 12
if 表达式1: 语句 if 表达式2: 语句 elif 表达式3: 语句 else: 语句 elif 表达式4: 语句 else: 语句
循环语句
while
1 2
while 判断条件(condition): 执行语句(statements)……
while 循环使用 else 语句
1 2 3 4
while <expr>: <statement(s)> else: <additional_statement(s)>
for中使用了 break 语句,break 语句用于跳出当前循环体:
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/python3 sites = ["Baidu", "Google","Runoob","Taobao"] for site in sites: if site == "Runoob": print("菜鸟教程!") break print("循环数据 " + site) else: print("没有循环数据!") print("完成循环!")
1 2 3 4
循环数据 Baidu 循环数据 Google 菜鸟教程! 完成循环!
range()函数
1 2 3 4
#!/usr/bin/python3 for i in range(5): print(i)
1 2 3 4 5
0 1 2 3 4
使用range指定区间的值
1 2
for i in range(5,9) : print(i)
1 2 3 4
5 6 7 8
使range以指定数字开始并指定不同的增量(甚至可以是负数,有时这也叫做’步长’):
1 2 3 4 5 6 7
for i in range(0, 10, 3) : print(i)
print("负数")
for i in range(-10, -100, -30) : print(i)
1 2 3 4 5 6 7 8
0 3 6 9 负数 -10 -40 -70
结合range()和len()函数以遍历一个序列的索引
1 2 3 4 5
#!/usr/bin/python3 a = ['Google', 'Baidu', 'Runoob', 'Taobao', 'QQ'] for i in range(len(a)): print(i, a[i])
import sys def fibonacci(n): # 生成器函数 - 斐波那契 a, b, counter = 0, 1, 0 while True: if (counter > n): return yield a a, b = b, a + b counter += 1 f = fibonacci(10) # f 是一个迭代器,由生成器返回生成 while True: try: print (next(f), end=" ") except StopIteration: sys.exit()
a, _ := gormadapter.NewAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/") e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a) // Or you can use an existing DB "abc" like this: // The adapter will use the table named "casbin_rule". // If it doesn't exist, the adapter will create it automatically. // a := gormadapter.NewAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/abc", true) e.LoadPolicy()//从数据库加载策略 e.Enforce("alice", "data1", "read")// 检查许可 // 更改策略 // e.AddPolicy(...) // e.RemovePolicy(...) e.SavePolicy()//保存策略 }