import mmap
# write a simple example file
with open("hello.txt", "wb") as f:
f.write(b"Hello Python!\n")
with open("hello.txt", "r+b") as f:
# memory-map the file, size 0 means whole file
mm = mmap.mmap(f.fileno(), 0)
# read content via standard file methods
print(mm.readline()) # prints b"Hello Python!\n"
# read content via slice notation
print(mm[:5]) # prints b"Hello"
# update content using slice notation;
# note that new content must have same size
mm[6:] = b" world!\n"
# ... and read again using standard file methods
mm.seek(0)
print(mm.readline()) # prints b"Hello world!\n"
# close the map
mm.close()
不幸的是,在我的系统上,当我在命令行上执行时,我得到了这些错误。在
^{pr2}$
关于我的系统,Ubuntu Linux on Virtual machine-VirtualBox:user@logger$ uname -a
Linux user-vm 4.15.0-42-generic #45-Ubuntu SMP Thu Nov 15 19:32:57 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
在windows上,使用PyCharm我可以毫无问题地执行这个程序。
但是,在虚拟机Linux上,我得到了这些错误。我错过了什么。在
谢谢。在