本文整理匯總了Python中uos.mkdir方法的典型用法代碼示例。如果您正苦於以下問題:Python uos.mkdir方法的具體用法?Python uos.mkdir怎麽用?Python uos.mkdir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類uos
的用法示例。
在下文中一共展示了uos.mkdir方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: makedirs
# 需要導入模塊: import uos [as 別名]
# 或者: from uos import mkdir [as 別名]
def makedirs(path):
_path = ''
if path[0] == '/':
path = path.strip('/').split('/')
for i in path:
_path += '/' + i
try:
os.mkdir(_path)
except:
pass
else:
path = path.split('/')
for i in path:
_path += i
try:
os.mkdir(_path)
_path += '/'
except:
pass
示例2: mkdir
# 需要導入模塊: import uos [as 別名]
# 或者: from uos import mkdir [as 別名]
def mkdir(self, directory, exists_okay=False):
"""Create the specified directory. Note this cannot create a recursive
hierarchy of directories, instead each one should be created separately.
"""
# Execute os.mkdir command on the board.
command = """
try:
import os
except ImportError:
import uos as os
os.mkdir('{0}')
""".format(
directory
)
self._pyboard.enter_raw_repl()
try:
out = self._pyboard.exec_(textwrap.dedent(command))
except PyboardError as ex:
# Check if this is an OSError #17, i.e. directory already exists.
if ex.args[2].decode("utf-8").find("OSError: [Errno 17] EEXIST") != -1:
if not exists_okay:
raise DirectoryExistsError(
"Directory already exists: {0}".format(directory)
)
else:
raise ex
self._pyboard.exit_raw_repl()
示例3: save
# 需要導入模塊: import uos [as 別名]
# 或者: from uos import mkdir [as 別名]
def save(self):
# Create config_dir if do not exists
try:
uos.stat(self.config_dir)
except OSError:
uos.mkdir(self.config_dir)
with open('{}/{}.json'.format(self.config_dir, self.name), 'w') as fp:
json.dump(self.data, fp)
示例4: mkdir
# 需要導入模塊: import uos [as 別名]
# 或者: from uos import mkdir [as 別名]
def mkdir(path):
try:
uos.mkdir(path)
except OSError as e:
pass
示例5: init
# 需要導入模塊: import uos [as 別名]
# 或者: from uos import mkdir [as 別名]
def init(root_path='/test'):
print("Initializing from {}...".format(root_path))
mkdir('{}'.format(root_path))
write('{}/index.html'.format(root_path), "<html><body>Hello World!</body></html>")
mkdir('{}/foo'.format(root_path))
write('{}/foo/test.txt'.format(root_path), "test")
mkdir('{}/foo/bar'.format(root_path))
write('{}/foo/bar/test.js'.format(root_path), "{'foo': \"bar\"}")
write('{}/foo/bar/test.css'.format(root_path), "html")