python查找输出文字_Python基础练习,查询文本内容并输出;
1、编写可供用户查询的员工信息表:
1).用户认证(输入用户名,密码)
2).查询关键字:姓名
3).显示ID,name,section,phone
4).员工信息表内容如下:
cat search_name.txt
001wenlong IT12345678
002xiaojun IT12345678
003ankang IT12345678
004xiang IT12345678
脚本如下:#!/usr/bin/python
#-*- coding:utf-8 -*- #输入这一条就可以在Python脚本里面使用汉语注释!此脚本可以直接复制使用;
while True: #进入死循环
input = raw_input('Please input your username:') #交互式输入用户信息,输入input信息;
if input == "wenlong": #如果input等于wenlong则进入此循环(如果用户输入wenlong)
password = raw_input('Please input your pass:') #交互式信息输入,输入password信息;
p = '123' #设置变量P赋值为123
while password != p: #如果输入的password 不等于p(123), 则进此入循环
password = raw_input('Please input your pass again:') #交互式信息输入,输入password信息;
if password == p: #如果password等于p(123),则进入此循环
print 'welcome to select system!' #输出提示信息;
while True: #进入循环;
match = 0 #设置变量match等于0;
input = raw_input("Please input the name whom you want to search :") #交互式信息输入,输入input信息;
while not input.strip(): #判断input值是否为空,如果input输出为空,则进入循环;
input = raw_input("Please input the name whom you want to search :") #交互式信息输入,输入input信息;
name_file = file('search_name.txt') #设置变量name_file,file('search_name.txt')是调用名为search_name.txt的文档
while True: #进入循环;
line = name_file.readline() #以行的形式,读取search_name.txt文档信息;
if len(line) == 0: #当len(name_file.readline() )为0时,表示读完了文件,len(name_file.readline() )为每一行的字符长度,空行的内容为\n也是有两个字符。len为0时进入循环;
break #执行到这里跳出循环;
if input in line: #如果输入的input信息可以匹配到文件的某一行,进入循环;
print 'Match item: %s' %line #输出匹配到的行信息;
match = 1 #给变量match赋值为1
if match == 0 : #如果match等于0,则进入 ;
print 'No match item found!' #输出提示信息;
else: print "Sorry ,user %s not found " %input #如果输入的用户不是wenlong,则输出信息没有这个用户;
上面加了备注的脚本也可以直接使用,这里重新贴一次没有注释的供学习;#!/usr/bin/python
while True:
input = raw_input('Please input your username:')
if input == "wenlong":
password = raw_input('Please input your pass:')
p = '123'
while password != p:
password = raw_input('Please input your pass again:')
if password == p:
print 'welcome to select system!'
while True:
match = 0
input = raw_input("Please input the name whom you want to search :")
while not input.strip():
print 'No match item found!'
input = raw_input("Please input the name whom you want to search :")
name_file = file('search_name.txt')
while True:
line = name_file.readline()
if len(line) == 0:
break
if input in line:
print 'Match item: ' , line
match = 1
if match == 0 :
print 'No match item found!'
else: print "Sorry ,user %s not found " %input
测试图片:
python查找输出文字_Python基础练习,查询文本内容并输出;相关推荐
- python输出文本-Python基础练习,查询文本内容并输出;
1.编写可供用户查询的员工信息表: 1).用户认证(输入用户名,密码) 2).查询关键字:姓名 3).显示ID,name,section,phone 4).员工信息表内容如下: cat search_ ...
- python文件输入符_python基础入门详解(文件输入/输出 内建类型 字典操作使用方法)...
一.变量和表达式 >>> 1 + 1 2 >>> print 'hello world' hello world >>> x = 1 >&g ...
- python文件替换一行_python基础_文件操作实现全文或单行替换的方法
这篇文章主要介绍了关于python基础_文件操作实现全文或单行替换的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 python修改文件时,使用w模式会将原本的文件清空/覆盖.可以 ...
- python exit()什么意思_Python基础学习教程:如何用Python来写pm2.5空气质量查询程序...
今天就教大家用之前有跟大家分享过的python基础学习教程完成首个MVP,如何用CLI(command-line interface,命令行界面)来执行第一个空气质量查询程序. 知识点 如何进行txt ...
- python中return输出字符串_python基础——字符串
Python 字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello W ...
- python turtle库输出文字_python turtle库学习笔记
#绘制时钟#coding=utf-8 importturtle as ttfrom datetime import * #当前日期属于一周的第几天 defWeek(t): week= ["星 ...
- python turtle库输出文字_Python 海龟 turtle 画图讲解 (五):输入/输出文字及鼠标与键盘交互设计...
一.输入/输出文字 在 1. 输出文字 输出文字可以使用 write() 方法来实现,语法如下: def write(self, arg, move=False, align="left&q ...
- Python按键精灵自动化_Python基础:了解Python与pycharm
认识 Python 人生苦短,我用 Python -- Life is short, you need Python 目标 Python 的起源 为什么要用 Python? Python 的特点 Py ...
- python动态时钟代码_Python基础 用Python实现时钟
语言:Python IDE:Python.IDE编写时钟程序,要求根据时间动态更新代码思路 需求:5个Turtle对象, 1个绘制外表盘+3个模拟表上针+1个输出文字 Step1:建立Turtle对象 ...
最新文章
- 使用Docker快速搭建PHP开发环境
- 齐博cms 7.0 漏洞分析
- 2016最热门的PHP框架
- mysql group by 规则_MySQL 中关于 GROUP BY 的问题
- android shpe 三角形_绘制三角形背景的android
- TypeScript入门教程 之 点差算子/散布运算符/...运算符/剩余参数/...参数
- 为什么说“进程是资源分配的单位、线程是调度的单位”?
- JavaScript 字符串与数字的相互转换
- html标签--使用
- C#3 分部方法,简单标记一下
- u2 接口 服务器硬盘,M.2、U.2谁更好?主流硬盘接口都有哪些?
- 腾讯云cdn设置 php,腾讯云CDN缓存过期配置问题详解
- 评价最高影片JAVAlibrary_《鼠胆英雄》:影片烂不烂,观众说了算
- php实训心得体会doc,php实训报告心得体会php实训报告心得体会
- AES-256-CBC 加密解密
- 有一个强大又好看的,赛过Typora,阿里开发的语雀编辑器
- 人脸活体检测调研(留着备用)
- 计算机制图结课论文,计算机辅助设计结课论文.doc
- 水果网站关于我们的纯html的代码_2020年网站建设的报价清单
- IT人员健康信号之眼睛保护
热门文章
- java让服务器停止运行,java调用远程服务器的shell脚本以及停止的方法实现
- 完全复制 mysql,MySQL完全复制表结构
- 统计学、数据分析、机器学习常用数据特征汇总
- String Modification CodeForces - 1316B(规律)
- 黄金连分数(java大法好)
- Perform the Combo CodeForces - 1311C(字符串反转+树状数组)
- codeforces 153d(日期转换)特殊题目
- 用友服务器系统版本低,客户端版本低于服务器端,请升级后再登录
- php 浮点数转字符串,php浮点数和字符串
- libcrypto yum 安装_YUM 安装 VSFTP出错