我只是试图在python3中创建文件,但是标准答案不起作用

问题描述 投票:0回答:1

简单的任务,遍布网络的答案。我只是无法让他们工作。在macOS上运行以下代码时,出现以下错误消息:

打开错误:[Errno 1]不允许进行的操作:'test_60'

路径错误:[Errno 1]不允许操作:'test_60'

mknod错误:[Errno 1]不允许操作

完整的测试程序如下。我做错了什么愚蠢的事?

#!/usr/local/bin/python3
from pathlib import Path
import os

db_file = "test_60"
#
try:
    open(db_file, 'a').close()
except OSError as e:
    print('open error:', e)
try:
    Path(db_file).touch()
except OSError as e1:
    print('Path error:', e1)

try:
    os.mknod(db_file)
except OSError as e2:
    print('mknod error:', e2)
python-3.x file new-operator
1个回答
-1
投票

数据库没有文件扩展名吗?如果是这样,请将db_file = "test_60"更改为db_file = "test_60.fileextension"

© www.soinside.com 2019 - 2024. All rights reserved.