Python 脚本碎片
- 基本输入输出 用户名/密码
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Liu Lei
import getpass username = input("username:")
password = getpass.getpass("password:") print(username,password)
备注:
getpass 在pycharm里边不好使哈,自己用别的方式测试
格式化输出
- 三中格式化输出
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# User xxxx username = input("username:")
age = int(input("age:")) #integer
print(type(age),type(str(age)))
password = input("password:")
print(type(password)) info1 = '''
---- info of '''+ username +'''----
Name:'''+username+'''
Pawd:'''+ password info2 = '''
---- info of %s----
Name:%s
Age:%d
Pawd:%s
'''%(username,username,age,password) info3 = '''
---- info of {Name}----
Name:{Name}
age:{Age}
Pawd:{Password}
'''.format(Name=username,
Age=age,
Password=password) print(info1)
print(info2)
print(info3)
备注:格式化输出,字符类型种类参考
格式 描述
%% 百分号标记 #就是输出一个%
%c 字符及其ASCII码
%s 字符串
%d 有符号整数(十进制)
%u 无符号整数(十进制)
%o 无符号整数(八进制)
%x 无符号整数(十六进制)
%X 无符号整数(十六进制大写字符)
%e 浮点数字(科学计数法)
%E 浮点数字(科学计数法,用E代替e)
%f 浮点数字(用小数点符号)
%g 浮点数字(根据值的大小采用%e或%f)
%G 浮点数字(类似于%g)
%p 指针(用十六进制打印值的内存地址)
%n 存储输出字符的数量放进参数列表的下一个变量中
- 非常用格式化,小节
info3 = '''
---- info of {0}----
Name:{1}
age:{2}
Pawd:{3}
'''.format(username,username,age,password)
简单while 循环
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# xxxx
num = 33 count = 0
while count < 3:
guess_num = int(input("input num:"))
if guess_num == num:
print("yes,you got it.")
break
elif guess_num > num:
print("think smaller...")
else:
print("think bigger!")
count +=1
else:
print("you have tried too many times...fuck off")
简单for循环
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# xxxx for i in range(0,10,2):
print("loop",i)
Python 脚本碎片的更多相关文章
- freeswitch嵌入python脚本
操作系统:debian8.5_x64 freeswitch 版本 : 1.6.8 python版本:2.7.9 开启python模块 安装python lib库 apt-get install pyt ...
- python脚本后台运行
问题描述: 环境: CentOS6.4 一个用python写的监控脚本test1.py,用while True方式一直运行,在ssh远程(使用putty终端)时通过以下命令启动脚本: python t ...
- 某互联网后台自动化组合测试框架RF+Sikuli+Python脚本
某互联网后台自动化组合测试框架RF+Sikuli+Python脚本 http://www.jianshu.com/p/b3e204c8651a 字数949 阅读323 评论1 喜欢0 一.**Robo ...
- 动态执行python脚本
前言 存在许多独立的python脚本,这些脚本可能会增加,也可能会减少,现在需要按照某种顺序调度这些程序.在python的standard library中,有一个模块imp可以实现动态的调用ptho ...
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
摘自:http://blog.csdn.net/forandever/article/details/5711319 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本 ...
- SecureCRT中python脚本编写
SecureCRT中python脚本编写学习指南 SecureCRT python 引言 在测试网络设备中,通常使用脚本对设备端进行配置和测试以及维护:对于PE设备的测试维护人员来说使用较多是Secu ...
- Python脚本配合Linux计划任务工作
经常遇到直接运行Python脚本没有问题,但是一放入/etc/crontab之后就歇菜的情况,总结了一下,大致需要注意以下几点: 1. 脚本首行加入#!/usr/bin/env python 2. 脚 ...
- Labview调用Python脚本
Labview程序框图如下: Python脚本如下: #!/usr/bin/env pythonimport sys #Command Line Arguements are stored in li ...
- 使用Runtime.getRuntime().exec()在java中调用python脚本
举例有一个Python脚本叫test.py,现在想要在Java里调用这个脚本.假定这个test.py里面使用了拓展的包,使得pythoninterpreter之类内嵌的编译器无法使用,那么只能采用ja ...
随机推荐
- Windows/Linux用户态监控进程启动事件方法
catalogue . windows wmi监控进程启动 . linux netlink监控进程启动 1. windows wmi监控进程启动 from threading import Threa ...
- layui(三)——laypage组件常见用法总结
laypage 的使用非常简单,指向一个用于存放分页的容器,通过服务端得到一些初始值,即可完成分页渲染.核心方法: laypage.render(options) 来设置基础参数. 一.laypag ...
- Git(使用码云)
使用GitHub时,国内的用户经常遇到的问题是访问速度太慢,有时候还会出现无法连接的情况(原因你懂的). 如果我们希望体验Git飞一般的速度,可以使用国内的Git托管服务——码云(gitee.com) ...
- Django之名称空间
由于name没有作用域,Django在反解URL时,会在项目全局顺序搜索,当查找到第一个name指定URL时,立即返回. project/urls.py urlpatterns = [ path('a ...
- 使用JAVA数组实现顺序表
1,引入了JAVA泛型类,因此定义了一个Object[] 类型的数组,从而可以保存各种不同类型的对象. 2,默认构造方法创建了一个默认大小为16的Object数组:带参数的构造方法创建一个指定长度的O ...
- JS判断是电脑浏览器还是手机端浏览器,并根据不同的终端跳转到不同的网址
<!DOCTYPE html> <html> <script> function browserRedirect() { var sUserAgent = navi ...
- XXE攻防
一.XML基础知识 XML用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言.XML文档结构包括XML声明.DTD文档类型定义(可 ...
- sql库连sql中间库连orcle库增删改查方案
---中间库建立存储过程create procedure Proc_exec@SQL nvarchar(MAX)ASexec(@SQL) GO---web服务器执行语句 --查 select * fr ...
- Cisco Common Service Platform Collector - Hardcoded Credentials(CVE-2019-1723)
Cisco Common Service Platform Collector - Hardcoded Credentials 思科公共服务平台收集器-硬编码凭证(CVE-2019-1723) htt ...
- pyqt5-定时器
定时器的操作方法有两种: 方法一:利用每个对象包含的timerEvent函数 方法二:利用定时器模块 需要 from PyQt5.QtCore import QTimer 方法一:利用每个对象 ...