python编程快速上手之第18章实践项目参考答案(18.4.2)

import pyautogui, time, os, pyautogui

os.chdir(‘C:\\Users\\Administrator\\Python35-32\\test\\kuaisu‘)
guests = open(‘sendMesTo.txt‘)#打开好友名单
for n in guests:
  pyautogui.click(1300, 1, button=‘left‘) #用的是QQ,鼠标移动到屏幕右上角,QQ弹出窗口
  time.sleep(1)
  pyautogui.typewrite(n);pyautogui.press(‘enter‘)   #输入好友名并按Enter
  time.sleep(2)
  if pyautogui.locateOnScreen(‘foundNone.png‘) == None :   #如果没有好友则会弹出搜索窗,如未匹配到搜索窗图片,则输入Hello
    pyautogui.typewrite(‘Hello‘)
    pyautogui.keyDown(‘ctrlleft‘); pyautogui.press(‘enter‘);pyautogui.keyUp(‘ctrlleft‘)
    time.sleep(1)
    print(n)
  else :
    print(‘Not found %s ‘ %n)   #如果匹配到搜索窗图片,则输入 Not found
时间: 2024-07-29 19:52:06

python编程快速上手之第18章实践项目参考答案(18.4.2)的相关文章

python编程快速上手之第10章实践项目参考答案

  本章主要讲了python程序的调试,当程序有BUG或异常的时候,我们如何调试代码找出问题点.其实在本章之前的章节我们做练习的时候都会遇到各种各样的错语和异常,最初当不知道程序哪里出错的情况下不可否认的都使用了print语句进行输出并调试代码.没错print也是调试代码的一种工具,直观简单,便也有缺点,就是调试好后要进行删除,也是件麻烦事,于是就有了本章介绍的assert(断言),logging(日志)以及各种调试工具的出现. 首先来回顾一下python的异常. 一.python常见的异常类型

python编程快速上手之第8章实践项目参考答案

第8章实践项目之疯狂填词 创建一个一个疯狂填词(Mad Libs),程序,它将读入文本文件,并让用户在该文本文件中出现 ADJECTIVE,NOUN,VERB等单词的地方,加上他们自己的文本. 首先准备一个a.txt的文本文件 程序代码如下: #!/usr/bin/env python3.4 # coding:utf-8 # 8.9.2 import re f1 = open('a.txt','r') strf1 = f1.read() print("原文件内容为:") print(s

python编程快速上手之第5章实践项目参考答案

1 #!/usr/bin/env python3.5 2 # coding:utf-8 3 # 5.6.1 4 # 好玩游戏的物品清单 5 # 给定一个字典,包含物品名称和数量,并打印出数量对应的物品 6 7 dict_stuff = {'rope':1,'torch':6,'gold coin':42,'dagger':1,'arrow':12} 8 print("5.6.1参考答案") 9 print('=' * 80) 10 print("给定字典:",dic

python编程快速上手之第3章实践项目参考答案

1 #!/usr/bin/env python 2 # coding:utf-8 3 # write by mfyang 4 # collatz.py 5 # 从用户读入一个值,并判断这个值是不是一个int类型的整数,如果不是给出异常提示 6 # 如果这个值是偶数 那么让这个数//2 7 # 如果这个值是奇数 那么让这个数 ×3 + 1 8 # 通过不断调用函数的返回值 并打印这个返回值 直到这个返回值为1 9 10 num = raw_input("please input a number:

python编程快速上手之第4章实践项目参考答案

1 #!/usr/bin/env python3.5 2 # coding:utf-8 3 # 假定有一个列表,编写函数以一个列表值作为参数,返回一个字条串 4 # 该字符串包含所有表项,之间以逗号和空格分隔,并在最后一个值前插入 and 5 # 要求函数能处理传递给它的任何列表 6 7 # spam = input('please input a list:') 8 # 刚开始想从用户输入进行传递列表方式,但没成功 9 10 # 4.10.1 11 print("4.10.1 answer:&

python编程快速上手之第6章实践项目参考答案

#!/usr/bin/env python3.5 2 #coding:utf-8 3 # 4 # 这个项目主要目的是字符串的处理,简单格式化输出 5 tableData = [['apples','oranges','cherries','banana'], 6 ['Alice','Bob','Carol','David'], 7 ['dogs','cats','moose','goose']] 8 # 要求输出如下: 9 # apples Alice dogs 10 # dranges Bob

python编程快速上手之第10章实践项目参考答案(11.11.2)

#!/usr/bin/env python # -*- coding:utf-8 -*- import os import re import urllib import json import socket import urllib.request import urllib.parse import urllib.error # 设置超时 import time timeout = 5 socket.setdefaulttimeout(timeout) class Crawler: # 睡

python编程快速上手之第15章实践项目参考答案(17.7.1)

#! python3 # resizeAndAddLogo.py - Resizes all images in current working directory to fit # in a 300x300 square, and adds catlogo.png to the lower-right corner. import os from PIL import Image os.chdir('C:\\Users\\Administrator\\Python35-32\\test\\ku

python编程快速上手之第13章实践项目参考答案(13.6.1)

import os,PyPDF2 os.chdir('D:\\My Documents') for folderName, subfolders, filenames in os.walk('D:\\My Documents'): for file in filenames: if file.endswith('.pdf'): pdfFile = open(file, 'rb') pdfReader = PyPDF2.PdfFileReader(pdfFile) pdfWriter = PyPD

python编程快速上手之第15章实践项目参考答案(17.7.2)

#! python3 # Import modules and write comments to describe this program. import zipfile, os from PIL import Image from PIL import ImageFile #os.chdir('D:\\My Documents\\') ImageFile.LOAD_TRUNCATED_IMAGES = True for foldername, subfolders, filenames i