a=QLabel("123")
a.setWordWrap(True)
主窗口
class Panel3(QFrame):
def __init__(self):
super().__init__()
self.diglog = AddDialog()
self.addbtn=QPushButton(self)
self.addbtn.setText("增加")
def showaddDig(self):#点击按钮事件
self.diglog.mySignal.connect(self.getlist) #弹窗的自定义信号 绑定窗口1的槽函数getlist
self.diglog.show()#弹窗显示
pass
def getlist(self,list): #参数list 可获得携带list信息的信号
print("list"+str(list))
self.diglog.mySignal.disconnect(self.getlist) # 要断开,否则关闭弹窗时会死机
子弹窗
class AddDialog(QDialog):
mySignal= pyqtSignal(list)#自定义可携带list的信号
def __init__(self):
super().__init__()
self.id=""
self.name=""
self.resize(600, 400)
self.setWindowTitle("add")
self.setWindowModality(Qt.ApplicationModal)#模态窗口,使得不关弹窗不能操作主窗口
self.btn1=QPushButton("确定")
self.btn1.clicked.connect(self.confirmbtn)
self.btn2=QPushButton("取消")
self.btn2.clicked.connect(self.cancelbtn)
self.input1=QLineEdit("id1")
self.res=QLineEdit("name1")
def confirmbtn(self):#点击确认按钮
tp=[]
tp.append(self.input1.text())
tp.append(self.res.text())
#复位
self.input1.setText("")
self.res.setText("")
self.mySignal.emit(tp)#发射带着list信息的信号
#由于信号已经绑定主窗口的槽函数getlist,所以发射信号的终点是槽函数getlist
self.close()#关闭弹窗
def cancelbtn(self):#点击取消按钮
self.close()#关闭弹窗
读+遍历,a,b是csv的列名
reader = open("data/comments.csv", "r", newline='', encoding='utf-8-sig')
csv_reader = csv.reader(reader)
for a,b in csv_reader:
print(str(a)+" "+str(b))
写,a是用来往后加,w是用来替换
list['a1','b1']
writer = open("data/taobao_like.csv", "a", newline='', encoding='gbk')
csv_writer = csv.writer(writer)
csv_writer.writerow(list)
writer.close()
from lxml import etree
url="https://www.baidu.com"
res1 = requests.get(url)
res1.encoding = "gbk"
dom = etree.HTML(res1.text)
a_text = dom.xpath('//meta[@name="keywords"]/@content')
# 获取meta下name=keywords的content属性的内容
删除xxxList里面的widgetItem会用上倒序遍历
for i in range(0,self.input1.count())[::-1]:
self.input1.removeItem(i)
from pandas import read_csv
dellist=[2,3]
csv_data = read_csv("yyy/xxx.csv", header=None, encoding="gbk")
csv_data = csv_data.drop(index=dellist, axis=0, inplace=False)
csv_data.to_csv("yyy/xxx_tmp.csv", header=None, encoding="gbk", index=0)
os.remove("yyy/xxx.csv")
os.rename("yyy/xxx_tmp.csv", "yyy/xxx.csv")
import re
s="sss scscs \"money\":\"1.2\" \"money\":\"1.3\" sasa"
list=re.findall(r'\"money\"\:\"[\d\.]+\"',s)
print(list)
for i in range(len(list)):
print(eval(list[i].split(':')[1]))//
re.findall(r' 正则 ',原字符串) 返回一个list
"要写成 \" 表示转义
正则:[\d\.]* 匹配小数 *表示前面那串[]出现0~无穷次,如果你要非空就换成+
(注意像1..22..2这种也会匹配到)
字符串.spilt(":"): 以:分割 返回一个list
eval(字符串):获取表达式的值 https://baijiahao.baidu.com/s?id=1617211914887604328&wfr=spider&for=pc
上面程序输出 1.2 1.3
不加eval输出‘1.2’‘1.3’
然后还有一个常用的
.* 匹配任意串 (后往前找)
.*? 匹配任意串(前往后找)
s="1010000000122221"
print(re.findall(r'1.*1',s))
print(re.findall(r'1.*?1', s))
s="10100000001"
print(re.findall(r'1.*1',s))
print(re.findall(r'1.*?1', s))
['1010000000122221']
['101', '122221']
['10100000001']
['101']