python使用import 中出现的问题qwq
主函数:
自定义函数:
报错:
你调用错了 你主函数调用的是f() 可是你在自定义函数定义的是f_s()
函数先申明在调用是 你申明的函数名字和你调用的函数名字要是一致的
打个比如
我申明函数
def func():
print('你好')
我在调用的时候页应该是func()
最近双11,生产系统需要重保,所以领导要求各个系统每隔两个小时在qq群通报一次系统运行情况,这样晚上的话也需要有人半夜起来发消息,很不方便,所以实现了一个定时自动发消息的程序,只要程序挂着就会定时发消息到qq群。
工具:python3.7 | pycharm | pywin32包
where python
来查看python安装位置,前提是配置了环境变量PyCharm Community Edition 2020.3.5
import win32con
import win32gui
import win32clipboard as w
import time
from random import choice
from random import randrange
import datetime
class sendMsg():
def __init__(self,receiver,msg):
self.receiver=receiver
self.msg=msg
self.setText()
#设置剪贴版内容
def setText(self):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_UNICODETEXT, self.msg)
w.CloseClipboard()
#发送消息
def sendmsg(self):
qq=win32gui.FindWindow(None,self.receiver)
win32gui.SendMessage(qq,win32con.WM_PASTE , 0, 0)
win32gui.SendMessage(qq, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
print("sucessfuly send",self.msg)
def getmessage(fileName):
f=open(fileName,'r',encoding='utf-8')
lines=f.readlines()
f.close()
return choice(lines)
def main():
receiver='备注测试'#这里填入接收者的备注名
while True:
time1=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# print(time1)
hour=time1[11:13]
minnute = time1[14:16]
second = time1[17:19]
# print(hour,minnute,second)
if int(hour)%2==0 and minnute=='00' and second=='30':
print(time1)
# msg = getmessage('C:\\Users\\Administrator\\Desktop\\message.txt')
print(time1)
msg = '截止' + time1[5:7] + '月' + time1[8:10] + '日' + hour + '时,CRM系统运行正常'
qq = sendMsg(receiver, msg)
qq.sendmsg()
time.sleep(7000)
# 测试案例 每5秒钟发送一次消息
if int(second)%5==0:
msg = '时间:' + time1 + ',系统运行正常!'
qq = sendMsg(receiver, msg)
qq.sendmsg()
time.sleep(3)
if __name__ == '__main__':
main()
6.在pycharm里,File -> Settings -> Project:pythonProject -> Python Interpreter(或者settings搜索里直接搜Python Interpreter),然后点击后面设置的按钮,选择Add…
7.选择Virtualenv Environment,然后点击Base interpreter后面选择的按钮
8.选择python3.7安装目录下的python.exe
9.点击ok ,可以看到pywin32包也会出现在这里,之前应该是没有的,我上面的截图有是因为我截图时已经安装了,然后点击Apply->Ok,就设置好了,就相当于将python3.7和pycharm关联在一起了,pycharm将使用python3.7解释器。
10.准备一个qq群,群名称为"auto测",群备注为"备注测试",然后将代码中的receiver='备注测试'#这里填入接收者的备注名
修改一下,注意是群的备注名称,不是群的名称。
11.注意窗口要单独打开窗口的,像下面图片这样。
12.右键点击运行试一下