Latest web development tutorials

os.fchdir Python3 () วิธีการ

Python3 OS วิธีการไฟล์ / ไดเรกทอรี Python3 OS วิธีการไฟล์ / ไดเรกทอรี


เค้าโครง

os.fchdir () วิธีการอธิบายไฟล์เพื่อเปลี่ยนไดเรกทอรีการทำงานปัจจุบัน

ยูนิกซ์สามารถใช้ได้บน Windows

ไวยากรณ์

fchdir () วิธีไวยากรณ์เป็นดังนี้:

os.fchdir(fd);

พารามิเตอร์

  • FD - อธิบายไฟล์

ราคาย้อนกลับ

วิธีการนี้มีค่าตอบแทนไม่

ตัวอย่าง

ตัวอย่างต่อไปนี้แสดงให้เห็นถึง fchdir () วิธีการใช้งาน:

#!/usr/bin/python3

import os, sys

# 首先到目录 "/var/www/html" 
os.chdir("/var/www/html" )

# 输出当前目录
print ("当前工作目录为 : %s" % os.getcwd())

# 打开新目录 "/tmp"
fd = os.open( "/tmp", os.O_RDONLY )

# 使用 os.fchdir() 方法修改到新目录
os.fchdir(fd)

# 输出当前目录
print ("当前工作目录为 : %s" % os.getcwd())

# 关闭打开的目录
os.close( fd )

เอาท์พุทโปรแกรมข้างต้นเป็น:

当前工作目录为 : /var/www/html
当前工作目录为 : /tmp

Python3 OS วิธีการไฟล์ / ไดเรกทอรี Python3 OS วิธีการไฟล์ / ไดเรกทอรี