• python模块


    http://blog.csdn.net/pipisorry/article/details/46619179

    re模块匹配规则见:http://blog.csdn.net/pipisorry/article/details/25909899

    python正則表達式进行日志分析

    日志分析时,如果给定的字符串:
    char str = “10.10.1.1 [2015/04/22 +0800] /ab/cd/?test0=123&test2=234 xxxx”; 要从中获取2015/04/22、/ab/cd/和234等值。

    str = “10.10.1.1 [2015/04/22 +0800] /ab/cd/?test0=123&test2=234 xxxx”
    print(re.findall(“d{4}/d{2}/d{2}|/w{2}/w{2}|(?<=test2=)d+”, str))


    用urllib2、re、os 模块下载文件的脚本

    !/usr/bin/env python
    importurllib2
    importre
    importos
    URL=’http://image.baidu.com/channel/wallpaper
    read=urllib2.urlopen(URL).read()
    pat =re.compile(r’src=’#’” //.+?.js”>’)
    urls=re.findall(pat,read)
    fori inurls:
    url=i.replace(‘src=’#’” /code>,”).replace(‘”>’,”)
    try:
    iread=urllib2.urlopen(url).read()
    name=os.path.basename(url)
    with open(name,’wb’) as jsname:
    jsname.write(iread)
    except:

    printurl,”url error”


    将全部文档中不同问题分别汇总到同一个文件里

    def shift():
        '''
        筛选全部人不同问题的答案到相应的文件里
        :return:
        '''
        INPUT_DIR = r'C:UserspiDesktop	xts'
        ANSWER_DIR = r'C:UserspiDesktopanswers'
        if not path.exists(ANSWER_DIR):
            makedirs(ANSWER_DIR)
    
        questions = ['在计科四班度过大学四年是一种如何的体验', '对班上的哪位同学第一印象最深刻,简述原因', '简述让你印象深刻的班上某位同学的一件小事', '想对你的室友说什么', '大学你最遗憾的事',
                     '最难忘或最感动或最想珍惜的一件事或人', '立即要毕业了,此刻的你内心是一种如何的体验', '想对你暗恋or前女友or现任恋人说什么', '(写完后记得将文档重命名加上你的姓名)']
        answer_filenames = [str(i) + '.txt' for i in range(len(questions) - 1)]
    
        for doc_name in listdir(INPUT_DIR):
            print(doc_name)
            doc_full_name = path.join(INPUT_DIR, doc_name)
            # print(doc_full_name)
            open(doc_full_name)
            with open(doc_full_name) as doc_file:
                # file_str = ''.join(doc_file.read().split('
    '))
                file_str = doc_file.read()
                # print(file_str)
                for cur_question, post_question, answer_filename in zip(questions, questions[1:], answer_filenames):
                    patten = cur_question 
    
                相关阅读:
    BPF and eBPF linux
    o-sync-and-o-direct
    linux performance test
    iostat
    MYSQL IO innodb-buffer-pool
    MYSQL file types redo log
    read pread write pwrite open
    CORE DUMP
    linux kernel的中断子系统 softirq
    linux KERNEL 问题
  • 原文地址:https://www.cnblogs.com/zsychanpin/p/7144204.html
Copyright © 2020-2023  润新知