Python学习日记之练习代码
# -*- coding:utf-8 -*- number = 23
test=True
while test:
guess=int(raw_input('输入数字'))
if guess==number:
print 'g=n'
elif guess>number:
print 'g>n'
else:
print "g<n"
# -*- coding:utf-8 -*- while True:
s=raw_input('输入任意字符')
if s=='q':
break
print '总长度为',len(s)
print '结束'
# -*- coding:utf-8 -*- def test():
global y,o
y=o+y
o=y-o
y=y-o
y=5
o=7
test()
print y,o
# -*- coding:utf-8 -*- booklide=['1','2','3']
for item in booklide:
print item,
booklide.append('4')
print booklide
del booklide[0]
print booklide zoo=('91','82','73')
print zoo
print len(zoo)
print zoo[2][1]
print '%s'%(zoo[1][1])
# -*- coding:utf-8 -*-
import os
import time
# 需要备份目录
source=['e:\\ppt']
# 存放目录
target_dir="E:\\"
target = target_dir + time.strftime('%Y%m%d%H%M%S')+'.zip'
print target
#rar_command='rar a %s %s'%(target,''.join(source))
rar_command = 'E:\winrar\WinRAR.exe a %s %s' % (target,' '.join(source))
print rar_command
if os.system(rar_command) == 0:
print '备份成功',target
else:
print '备份失败;dfsfgfdfrrggrr'
# -*- coding:utf-8 -*- class school:
def __init__(self,name,age):
self.name=name
self.age=age def tell(self):
print '%s %d'%(self.name,self.age),
class teacher(school):
def __init__(self,name,age,a):
school.__init__(self,name,age)
self.a=a
def tell(self):
school.tell(self)
print '%d'%(self.a)
t=teacher('姓名',20,3000)
t.tell()
# -*- coding:utf-8 -*- test='''\
这是一个测试
测试文件读写
'''
f=file('test.txt','w')
f.write(test)
f.close() f=file('test.txt')
while True:
line=f.readline()
if len(line)==0:
break
print line, f.close()
# -*- coding:utf-8 -*- import urllib url='http://www.163.com'
html=urllib.urlopen(url) #print html.read()
content=html.read().decode('gbk','ignore').encode('utf-8')
print content
# -*- coding:utf-8 -*- import os
import fnmatch
import re
ins="E:\\学习资料\\python"
path=unicode(ins,'utf-8') def finds(path,fnexp):
for root,path,files in os.walk(path):
for filename in fnmatch.filter(files, fnexp):
yield os.path.join(root,filename) for filename in finds(path, "*.html"):
files = open('key.txt', 'a')
alltext = open(filename).read()
p1 = r'视频播放密码为:.*?(?=<)'
pattern1 = re.compile(p1)
matcher1 = re.search(pattern1, alltext) files.write(matcher1.group(0)+'\n')
files.close()
Python学习日记之练习代码的更多相关文章
- Python 学习日记(第三周)
知识回顾 在上一周的学习里,我学习了一些学习Python的基础知识下面先简短的回顾一些: 1Python的版本和和安装 Python的版本主要有2.x和3.x两个版本这两个版本在语法等方面有一定的区别 ...
- Python学习日记 --day2
Python学习日记 --day2 1.格式化输出:% s d (%为占位符 s为字符串类型 d为数字类型) name = input('请输入姓名') age = int(input('请输入年龄 ...
- python学习日记(基础数据类型及其方法01)
数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...
- Python学习日记(一):拜见小主——Python
近日学习Python,特将学习过程及一点心得记录于此. 由于之前做过一个Java爬虫的项目,虽然很长时间没有碰过爬虫,但是小郭同学有一颗不死的爬虫心,哈哈.最近在互联网上找一些电影的时候,有很多电影只 ...
- Python学习日记(二十八) hashlib模块、configparse模块、logging模块
hashlib模块 主要提供字符加密算法功能,如md5.sha1.sha224.sha512.sha384等,这里的加密算法称为摘要算法.什么是摘要算法?它又称为哈希算法.散列算法,它通过一个函数把任 ...
- Python 学习日记(第二周)
从这周开始我就正式学习Python 语言了.以后每周都会有一篇有关于学习Python的见闻与大家分享! Python的安装 学习的第一步首先要有一个运行的环境.所以接下来介绍一下安装的步骤. 通过Py ...
- 从CentOS安装完成到生成词云python学习日记
欢迎访问我的个人博客:原文链接 前言 人生苦短,我用python.学习python怎么能不搞一下词云呢是不是(ง •̀_•́)ง 于是便有了这篇边实践边记录的笔记. 环境:VMware 12pro + ...
- python学习日记(常用模块)
模块概念 什么是模块 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写的代 ...
- python学习日记(函数--装饰器)
楔子 前提,我有一段代码(一个函数). import time def run_time(): time.sleep(0.1) print('我曾踏足山巅') 需求1:现在,我想计算这段代码的运行时间 ...
随机推荐
- 立面图 平面图 剖面图 CAD
http://www.qinxue.com/88.html http://www.xsteach.com/course/2855 前后左右各个侧面的外部投影图——立面图:对建筑物各个侧面进行投影所得到 ...
- linux程序命令行选项的3种风格:unix、gnu、x toolkit
In Unix-like systems, the ASCII hyphen-minus is commonly used to specify options. The character is u ...
- SaltStack学习系列之State安装Nginx+PHP环境
目录结构 |-- pillar | |-- nginx | | `-- nginx.sls #nginx变量(key:value) | `-- top.sls `-- salt|-- init #初始 ...
- 【VBA研究】工作表自己主动筛选模式检測
作者:iamlaosong 用VBA程序处理Excel数据文件.用户的数据文件有时处于自己主动筛选模式,往往导致数据处理不对.为此,须要检測工作表是否处于该模式,假设是,则去掉自己主动筛选.语句例如以 ...
- python内置全局变量
vars()查看内置全局变量 以字典方式返回内置全局变量 #!/usr/bin/env python # -*- coding:utf8 -*- print(vars()) #输出 # {'__bui ...
- VMWare中的Host-only、NAT、Bridge的比較
VMWare有Host-only(主机模式).NAT(网络地址转换模式)和Bridged(桥接模式)三种工作模式. 1.bridged(桥接模式) 在这样的模式下.VMWare虚拟出来的操作系统就像是 ...
- Unix - 文件里构成一个空洞的分析
lseek函数显示地为一个打开文件设置偏移量,文件偏移量能够大于文件的当前长度,在这样的情况下.对该文件的下一次写将加长该文件.并在文件里构成一个空洞,这一点是同意的. 位于文件里但没有写过的字节都被 ...
- tf.float32 implicity
简介 | TensorFlow https://tensorflow.google.cn/programmers_guide/low_level_intro 我们来构建一个简单的计算图.最基本的指 ...
- C++new失败的处理(如果 new 分配内存失败,默认是抛出异常的,但也可以取消异常)
我们都知道,使用 malloc/calloc 等分配内存的函数时,一定要检查其返回值是否为“空指针”(亦即检查分配内存的操作是否成功),这是良好的编程习惯,也是编写可靠程序所必需的.但是,如果你简单地 ...
- ios34---GDC,dispatch_once
// // ViewController.m // 09-掌握-GCD常用函数 // // Created by xiaomage on 16/2/18. // Copyright © 2016年 小 ...