时间:2021-07-01 10:21:17 帮助过:34人阅读
代码如下:
import os
print os.path.split('c:\\Program File\\123.doc')
print os.path.split('c:\\Program File\\')
-----------------output---------------------
('c:\\Program File', '123.doc')
('c:\\Program File', '')
代码如下:
>>> os.path.join('c:\\', 'csv', 'test.csv')
'c:\\csv\\test.csv'
>>> os.path.join('windows\temp', 'c:\\', 'csv', 'test.csv')
'c:\\csv\\test.csv'
>>> os.path.join('/home/aa','/home/aa/bb','/home/aa/bb/c')
'/home/aa/bb/c'
代码如下:
def censor(text,word):
texts = text.split(" ")
for i in range(len(texts)):if texts[i] == word:
texts[i] = "*" * len(word)
return " ".join(texts)
print censor("hey hey hey","hey")