练习
有一个文件,文件名为output_1981.10.21.txt 。下面使用Python: 读取文件名中的日期时间信息,并找出这一天是周几。将文件改名为output_YYYY-MM-DD-W.txt (YYYY:四位的年,MM:两位的月份,DD:两位的日,W:一位的周几,并假设周一为一周第一天)

#coding=utf-8
import os, re, datetime
filename = "output_1981.10.21.txt"
s=re.search("(\d{4})\.(\d{2})\.(\d{2})",filename)

y=int(s.group(1))
m=int(s.group(2))
d=int(s.group(3))
date1=datetime.date(y,m,d)
w=date1.weekday()+1
W=str(w)

newfilename=filename.replace('.', '-').replace("txt", W+".txt")
print newfilename

regular expression 练习的更多相关文章

  1. [LeetCode] Regular Expression Matching 正则表达式匹配

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  2. myeclipse中导入js报如下错误Syntax error on token "Invalid Regular Expression Options", no accurate correc

    今天在使用bootstrap的时候引入的js文件出现错误Syntax error on token "Invalid Regular Expression Options", no ...

  3. [LeetCode] 10. Regular Expression Matching

    Implement regular expression matching with support for '.' and '*'. DP: public class Solution { publ ...

  4. No.010:Regular Expression Matching

    问题: Implement regular expression matching with support for '.' and '*'.'.' Matches any single charac ...

  5. Regular Expression Matching

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  6. 【leetcode】Regular Expression Matching

    Regular Expression Matching Implement regular expression matching with support for '.' and '*'. '.' ...

  7. 【leetcode】Regular Expression Matching (hard) ★

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  8. grep(Global Regular Expression Print)

    .grep -iwr --color 'hellp' /home/weblogic/demo 或者 grep -iw --color 'hellp' /home/weblogic/demo/* (-i ...

  9. 66. Regular Expression Matching

    Regular Expression Matching Implement regular expression matching with support for '.' and '*'. '.' ...

  10. Jmeter组件4. Regular Expression Extractor

    位置:Post-Processors - Regular Expression Extractor 所谓的Post-Processors直译为后处理器,意思是在域内所有Sampler执行完后才会执行, ...

随机推荐

  1. scala 学习笔记三 闭包

    闭包是一个函数,返回值依赖于声明在函数外部的一个或多个变量. 闭包通常来讲可以简单的认为是可以访问一个函数里面局部变量的另外一个函数. 如下面这段匿名的函数: val multiplier = (i: ...

  2. file not found app文件

    昨天svn迁移.然后又一次check out之后编译遇到这个错误. Ld Build/Products/Debug-iphonesimulator/wiseCloudCrmTests.xctest/w ...

  3. Exception in thread "main" java.lang.ClassCastException: $Proxy13

    Exception in thread "main" java.lang.ClassCastException: $Proxy13原因:业务层实现了接口 解决:方法一:切面配置事务 ...

  4. 创建线程安全的单例(ARC或 非ARC)

    一:创建 宏 文件 SynthesizeSingleton.h SynthesizeSingleton.h #if __has_feature(objc_arc) // ARC Version #de ...

  5. wepy - 与原生有什么不同(事件更改)

    对于repeat,详情见官方文档 <style lang="less"> .userinfo { display: flex; flex-direction: colu ...

  6. 算法笔记_186:历届试题 高僧斗法(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 古时丧葬活动中经常请高僧做法事.仪式结束后,有时会有“高僧斗法”的趣味节目,以舒缓压抑的气氛. 节目大略步骤为:先用粮食(一般是稻米)在地 ...

  7. VB中如何修改treeview的背景色

    改变 TreeView 的背景    Private Declare Function SendMessage Lib "User32" Alias "SendMessa ...

  8. MongoDB和关系型数据库简单对比

    MongoDB 是一个跨平台的,面向文档的数据库,提供高性能,高可用性和可扩展性方便. MongoDB 工作在收集和文件的概念. 数据库:数据库是一个物理容器集合.每个数据库都有自己的一套文件系统上的 ...

  9. hmac库 密钥相关的哈希运算消息认证码

    # -*- coding: cp936 -*- #xiaodeng #python 2.7.10 #HMAC是密钥相关的哈希运算消息认证码,HMAC运算利用哈希算法,以一个密钥和一个消息为输入,生成一 ...

  10. repr

    >>> import datetime >>> today=datetime.datetime.now() >>> today datetime. ...