Python3的open()函数的时间复杂性是多少?

2024-04-18 10:05:16 发布

您现在位置:Python中文网/ 问答频道 /正文

Python3的open()函数在附加到文件时的大O表示法的时间复杂性是多少?在

例如,下面的行:with open("HugeDocument.csv", "a") as f


Tags: 文件csv函数aswith时间openpython3
1条回答
网友
1楼 · 发布于 2024-04-18 10:05:16

根据我的理解,open()函数返回一个file对象,它是指向磁盘上实际资源的指针/句柄。因此,open()的复杂性应该是恒定的,因为文件的位置被传递到open(file='abc')函数中。在

https://docs.python.org/3/glossary.html#term-file-object

An object exposing a file-oriented API (with methods such as read() or write()) to an underlying resource. Depending on the way it was created, a file object can mediate access to a real on-disk file or to another type of storage or communication device (for example standard input/output, in-memory buffers, sockets, pipes, etc.).

根据操作类型(如read()readline()seek())、文件大小、系统内存限制和其他文件系统配置,使用file对象执行操作的复杂性会有所不同。在

相关问题 更多 >