[SOLVED] AttributeError: module 'os' has no attribute 'mknod'

Before training the model, judge whether the file exists according to the storage address of the model file. If the file does not exist, use the os.mknod() method to create an empty file, and then the system will report an error

store_path = base_path + NetType + '.pt'
    if not os.path.exists(store_path):
        print("模型不存在!建立空模型")
        os.mknod(store_path)
    #     os.makedirs(store_path)
    print("模型存储路径:" + store_path)

 Most of the common answers on the Internet are that the Windows system does not support mknod and   there is no problem on the Ubuntu system.

The solution is to use open("xxxx", mode = "w", encoding=None)

store_path = base_path + NetType + '.pt'
    if not os.path.exists(store_path):
        print("模型不存在!建立空模型")
        open(store_path,mode = "w",encoding=None)
    #     os.makedirs(store_path)
    print("模型存储路径:" + store_path)

 The usage of w can be seen in this blog:

(130 messages) Python open file with open() method Chinese meaning and 'r', 'w', 'x', 'a', 'b', 't', '+ ', 'U'_daphne odera�'s Blog-CSDN Blog

报错1: TypeError: an integer is required (got type str)

Add encoding=None or encoding="utf-8" in the open method

报错2:TypeError: open() missing required argument 'flags' (pos 2)

Change from os import open to from io import open

Guess you like

Origin blog.csdn.net/Next_SummerAgain/article/details/129427211