• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisãof2b96aabd502dccaa3318d52470959d220017cf1 (tree)
Hora2009-06-26 22:56:18
Autorisella
Commiterisella

Mensagem de Log

I added a simple serialization example based on cpickle.

Mudança Sumário

Diff

diff -r c3c3a8f2494c -r f2b96aabd502 Python-codes/cpickle.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Python-codes/cpickle.py Fri Jun 26 13:56:18 2009 +0000
@@ -0,0 +1,36 @@
1+#!/usr/bin/env python
2+import cPickle
3+import scipy as s
4+inFridge = ["ketchup", "mustard", "relish"]
5+print inFridge
6+FILE = open("fridge.txt", 'w')
7+cPickle.dump(inFridge, FILE)
8+FILE.close()
9+
10+#Now I re-read the saved list into another format
11+
12+FILE2 = open("fridge.txt", 'r')
13+inFridgeFile = cPickle.load(FILE2)
14+FILE2.close()
15+print inFridgeFile
16+
17+#Bottom line: via cpickle I can actually store a list into
18+#a particular text file.
19+
20+#The same can be achieved for a numpy array
21+
22+z=s.arange(10)*s.sqrt(s.pi)
23+
24+
25+FILE = open("sci_arr.txt", 'w')
26+cPickle.dump(z, FILE)
27+FILE.close()
28+
29+FILE = open("sci_arr.txt", 'r')
30+z2 = cPickle.load(FILE)
31+FILE.close()
32+print z2
33+
34+
35+
36+print "So far so good"