我用了:
import urllib.request
Run Code Online (Sandbox Code Playgroud)
然后:
d={'value':12345}
urllib.parse.urlencode(d)
Run Code Online (Sandbox Code Playgroud)
我希望python抛出一个异常,因为我没有导入urllib.parse,而是它工作了.它是什么原因?
PS:我使用的是Python 3.3.3
创建此程序以将列车编号和名称插入数据库。名称和数字是正确的(因为注释掉的打印语句证明了这一点)但是当我用 db reader 打开它时 db 文件是空的。
代码:
import sqlite3
import re
conn=sqlite3.connect('example.db')
c=conn.cursor()
c.execute('''CREATE TABLE train
(number text, name text)''')
f=open("train.htm","r")
html=f.read()
num=re.findall(r"(?<=> )[0-9]+", html) #regex to get train number
name=re.findall(r"(?<=<font>)[A-Za-z]+[ A-Za-z]+",html) #regex to get train name
j=8
for i in range(0,len(num)):
#print(num[i],name[j]) #this statement proves that the values are right
c.execute("INSERT INTO train VALUES (?,?)",(num[i],name[j]))
j=j+3
conn.close()
Run Code Online (Sandbox Code Playgroud)
但是当我试图读取这个数据库时,它是空的。
读取数据库的代码:
import sqlite3
conn=sqlite3.connect('example.db')
c=conn.cursor()
for row in c.execute('SELECT * FROM train'):
#the program doesn't even enter this block
print(row)
Run Code Online (Sandbox Code Playgroud)
我尝试在 …
我有一些字符串,如"abc","def","xyz",他们可能会跟着数字.例如:abc123或xyz92
如果我使用:
re.findall("abc|def|xyz[0-9]+",text)
Run Code Online (Sandbox Code Playgroud)
然后它只返回xyz后跟数字,其余的我只得到字符串.
如何在不手动操作的情况下匹配所有这些,如:
re.findall("abc[0-9]+|def[0-9]+|xyz[0-9]+",text)
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
#include <iostream>
using namespace std;
class A
{
int i;
public:
A(int v) : i(v) { }
A(const A& r) : i(r.i) {
cout << "Copy constructor" << endl;
}
A operator=(const A& r) {
cout << "Assignment function" << endl;
return r;
}
void show() {
cout << i << endl;
}
};
int main()
{
A a(1);
A b(2);
a = b;
a.show();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
价值b就是2和价值a是1.在'main'中,b被复制到 …