Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีดู System Configuration เกี่ยวกับ Open File ใน Python

ใช้ fpathconf(file_descriptor, name) ดู system configuration ของ open file (เฉพาะ Unix) name ระบุค่าที่ต้องการ (เช่น PC_LINK_MAX, PC_NAME_MAX)

ตัวอย่าง

import os, sys
fd = os.open("foo.txt", os.O_RDWR | os.O_CREAT)
no = os.fpathconf(fd, 'PC_LINK_MAX')
print("Maximum number of links to the file: %d" % no)
no = os.fpathconf(fd, 'PC_NAME_MAX')
print("Maximum length of a filename: %d" % no)
os.close(fd)

ผลลัพธ์

Maximum number of links to the file: 127
Maximum length of a filename: 255