python内置函数open用什么打开写模式_Python3.6内置函数(47)——open

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a corresponding file object. If the file cannot be opened, anOSErroris raised.

open()

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

使用指定的模式和编码打开文件,返回文件读写对象。

1、函数功能打开一个文件,返回一个文件读写对象,然后可以对文件进行相应读写操作。

2、file参数表示的需要打开文件的相对路径(当前工作目录)或者一个绝对路径,当传入路径不存在此文件会报错。或者传入文件的句柄。

"""

Python IDLE或shell中切换路径

在Python自带的编辑器IDLE中或者Python shell中不能使用cd命令,那么跳到目标路径呢。

方法是使用os包下的相关函数实现路径切换功能。

import os

os.getcwd() #获取当前路径 #'D:Python36'

os.chdir("D:est") #跳到目标路径下

os.chdir('D:est') #单引号、双引号都可以

"""

>>>

你可能感兴趣的:(python内置函数open用什么打开写模式_Python3.6内置函数(47)——open)