python oserror 22_如何解决Python OSError:[Errno 22]Linux上的无效参数

该博客介绍了如何在Python中使用mmap模块进行内存映射文件操作,包括读写和更新文件内容。作者在Windows上的PyCharm环境中能够成功运行示例代码,但在Ubuntu Linux虚拟机中遇到了问题。示例代码展示了如何打开文件、映射文件到内存、通过标准文件方法和切片操作读取和更新内容,最后关闭映射。
摘要由CSDN通过智能技术生成

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上,我得到了这些错误。我错过了什么。在

谢谢。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值