2
、
\D
匹配任何非数字字符;它相当于类
[^0-9]
。
3
、
\s
匹配任何空白字符;它相当于类
[ \t\n\r\f\v]
。
4
、
\S
匹配任何非空白字符;它相当于类
[^ \t\n\r\f\v]
。
5
、
\w
匹配任何字母数字字符;它相当于类
[a-zA-Z0-9_]
。
6
、
\W
匹配任何非字母数字字符;它相当于类
[^a-zA-Z0-9_]
。
创建文件夹:
import
os
import
shutil
def
buildfile
(echkeyfile)
:
if
os.path.exists(echkeyfile):
#
创建前先判断是否存在文件夹,
if
存在则删除
shutil.rmtree(echkeyfile)
os.makedirs(echkeyfile)
else
:
os.makedirs(echkeyfile)
#else
则创建语句
return
echkeyfile
#
返回创建路径
#
传入的参数是需要创建文件夹的路径,比如我想在
D
盘下创建一个名字为
newfile
的文件夹,则
传入参数为
r’ D:
\
newfile’
。同样,返回的参数也是
r’ D:
\
newfile’
写入文本
1
:
import
codecs
def
write_txt
(txt, path)
:
f = codecs.open(path,
'a'
,
'utf8'
)
f.write(str(txt))
f.close()
#
传入参数为
txt
,
path
;
txt
为需要写入的内容,数据类型为字符串,
path
为写入的内容,数
据类型为字符串。
#
传入的
path
需如下定义:
path= r’ D:
\
text.txt’