Python目录及正则表达式练习

import re
p = re.compile('(\d+)-(\d+)-(\d+)')
print(p.match('2018-05-10'))
print(p.match('2018-05-10').group())
print(p.match('2018-05-10').group(1))
print(p.match('2018-05-10').groups())
print(p.search('aa2018-05-10bb'))

phone = '123-456-789 #这是电话号码'
p2 = re.sub(r'#.*$','',phone)
print(p2)
p3 = re.sub(r'\D','',p2)
print(p3)

regular_v4 = re.findall(r'[t,w]h','https://docs.python.org/3/whatsnew/3.6.htm')
print (regular_v4)


import os
print(os.path.abspath('.')) #获取绝对路径
print(os.path.abspath('..'))
print(os.path.exists('E:/python_study'))

print(os.path.isfile('E:/python_study'))
print(os.path.isdir('E:/python_study'))

print(os.path.join('E:/python_study/','b/c'))


from pathlib import Path
p = Path('.')
print(p.resolve())

p.is_dir()
q = Path('E:/python_study/a/b/c')
Path.mkdir(q,parents=True)
此条目发表在Python分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Protected with IP Blacklist CloudIP Blacklist Cloud