练习
有一个文件,文件名为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. Mysql 监控 支持 mysql 多实例自动发现以及主从监控

    在[/usr/local/zabbix327/bin] 目录下新建python文件,并增加执行权限,如下: #!/usr/bin/env /usr/bin/python # _*_ coding:ut ...

  2. 第四章 四种List实现类的对比总结

    1.ArrayList 非线程安全 基于对象数组 get(int index)不需要遍历数组,速度快: iterator()方法中调用了get(int index),所以速度也快 set(int in ...

  3. maven mvn Failed during checkstyle execution

    maven 命令默认强制使用checkstyle, 造成 命令运行失败 并报错: Failed during checkstyle execution 关闭checkstyle,命令如下: mvn [ ...

  4. DIV焦点事件详解 --【focus和tabIndex】​

    添加 tabindex='-1' 属性: 默认:获取不到焦点事件(blur) 1 <div class="wl-product" id="wl-product&qu ...

  5. T-SQL with as 的用法(转) SQL 下的递归查询 SQL2005(CTE) ,SQL2000(Function 递归)

    摘自: http://blog.csdn.net/bluefoxev/article/details/6779794 ------- SQL2005 方法 一.WITH AS的含义     WITH ...

  6. android 创建通知栏Notification

    ///// 第一步:获取NotificationManager NotificationManager nm = (NotificationManager) getSystemService(Cont ...

  7. GoLang中面向对象的三大特性

    有过 JAVA 语言学习经历的朋友都知道,面向对象主要包括了三个基本特征:封装.继承和多态.封装,就是指运行的数据和函数绑定在一起,JAVA 中主要是通过 super 指针来完成的:继承,就是指 cl ...

  8. Cognos与Firefox的那些事

    最近怀着一颗好奇的心装了Win10系统,作为一个Coder,或多或少的这么久以来对于它的兼容性还是秉着一颗质疑的态度.但是一切事情都要敢于尝试,毕竟Win10的用户体验还是很好的.和预料的一样,问题马 ...

  9. python数据库访问

    取得rs,使用,报错 sqlite3.Cursor' object has no attribute '__getitem__' 原因:使用时conn已经关闭了. 解决:用fetchall取出传递回来 ...

  10. Qt5 for Android: incompatible ABI

      I recently installed Qt5 and works like a charm for API 17 and armeabi-v7a.But I added second AVD ...