亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2359 | 回復(fù): 6
打印 上一主題 下一主題

文件內(nèi)容和列表的映射模塊 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2012-08-21 09:26 |只看該作者 |倒序?yàn)g覽
我想問下,Python里有沒有提供這樣一個(gè)模塊:

1. 能把文件按照數(shù)據(jù)行映射到一個(gè)數(shù)組里去。(這個(gè)原生的Python可行)。
2. 對(duì)這個(gè)數(shù)組的修改,能夠自動(dòng)到更新到文件里去,而無需顯示的用寫的方法來同步。
3. 應(yīng)該不是mmap這個(gè)模塊

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2012-08-21 09:33 |只看該作者
回復(fù) 1# zhuyubei
不用mmap怎么實(shí)現(xiàn)?


   

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2012-08-21 09:49 |只看該作者
mmap是字節(jié)形式的映射。當(dāng)然對(duì)它進(jìn)行包裝是可以實(shí)現(xiàn)這樣的功能的。也就是說,沒有直接提供這樣的包是嗎。

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2012-08-21 10:33 |只看該作者
回復(fù) 1# zhuyubei
沒明白你的需求,感覺沒啥要包裝的。
  1. with open("d:/hello.txt", "wb") as f:
  2.     f.write("Hello Python!\n")
  3. with open("d:/hello.txt", "r+b") as f:
  4.     map = mmap.mmap(f.fileno(), 0)
  5.     print map.readline()
  6.     print map[:5]
  7.     map[6:] = "\nworld!\n"
  8.     map.seek(0)
  9.     print map.readline()  
  10.     print map.readline()
  11.     map.close()
  12.    
復(fù)制代碼

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2012-08-21 10:52 |只看該作者
回復(fù) 4# 106033177


    謝謝您的回復(fù)。我再好好把mmap的文檔看下。謝謝!

論壇徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46處女座
日期:2013-10-24 14:25:01酉雞
日期:2014-04-07 11:54:15
6 [報(bào)告]
發(fā)表于 2012-08-21 12:53 |只看該作者
  1. import mmap

  2. # write a simple example file
  3. with open("hello.txt", "wb") as f:
  4.     f.write(b"Hello Python!\n")

  5. with open("hello.txt", "r+b") as f:
  6.     # memory-map the file, size 0 means whole file
  7.     map = mmap.mmap(f.fileno(), 0)
  8.     # read content via standard file methods
  9.     print(map.readline())  # prints b"Hello Python!\n"
  10.     # read content via slice notation
  11.     print(map[:5])  # prints b"Hello"
  12.     # update content using slice notation;
  13.     # note that new content must have same size
  14.     map[6:] = b" world!\n"
  15.     # ... and read again using standard file methods
  16.     map.seek(0)
  17.     print(map.readline())  # prints b"Hello  world!\n"
  18.     # close the map
  19.     map.close()
復(fù)制代碼

論壇徽章:
2
CU大;照
日期:2013-04-17 11:46:28CU大;照
日期:2013-04-17 11:46:39
7 [報(bào)告]
發(fā)表于 2012-08-22 23:56 |只看該作者
不能用 pickle、shelve 么?
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP