zoukankan      html  css  js  c++  java
  • 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:winrarWinRAR.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)+'
    ')
    files.close()
    

      

  • 相关阅读:
    第二十一章 PHP编译安装(centos7)
    第二十章 nginx常见问题
    第十九章 keepalived高可用
    dijkstra
    求逆序对
    A
    P2014 [CTSC1997]选课
    樱花 混合背包
    1401D
    CF1343D
  • 原文地址:https://www.cnblogs.com/mokero/p/6661804.html
Copyright © 2011-2022 走看看