本文整理汇总了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")