本文整理汇总了Python中marshal.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: remove_duplicates_randomized
def remove_duplicates_randomized():
try:
docs = m.load(open('../input/reuters/docs.p','rb'))
docs_paths = m.load(open('../input/reuters/docs_paths.p','rb'))
except:
print 'No serialized file...'
path = "../input/reuters/output"
dirs = os.listdir(path)
docs = []
docs_paths = []
for d in dirs:
dirpath = os.path.join(path,d)
files = os.listdir(dirpath)
docs += files
files = [os.path.join(dirpath,f) for f in files]
docs_paths += files
m.dump(docs,open("../input/reuters/docs.p","rb"))
m.dump(docs_paths,open("../input/reuters/docs_paths.p","rb"))
d = Counter(docs)
no_keys = len(d.keys())
counter = 0
docs_arr = array(docs)
for doc in d.keys():
counter += 1
if counter % 100 == 0:
print "processed %d of %d"%(counter,no_keys)
if d[doc] > 1:
indices = list(where(docs_arr == doc)[0])
# randomly remove the duplicates
for i in range(len(indices)-1):
idx = choice(indices)
indices.remove(idx)
os.remove(docs_paths[idx])
开发者ID:vseledkin,项目名称:Deep-Belief-Nets-for-Topic-Modeling,代码行数:35,代码来源:reuters.py
示例2: get_code
def get_code(self,fullname):
"""Get the code object for the given module."""
file,pathname,description = self._get_module_info(fullname)
if file is not None:
file.close()
if description[2] == imp.PKG_DIRECTORY:
for (suffix,_,typ) in imp.get_suffixes():
if typ != imp.PY_COMPILED:
continue
initfile = os.path.join(pathname,"__init__"+suffix)
if os.path.exists(initfile):
f = open(initfile,"rb")
try:
f.seek(8)
return marshal.load(f)
finally:
f.close()
return self.get_code(fullname+".__init__")
else:
pathbase = pathname[:-1*len(description[0])]
for (suffix,_,typ) in imp.get_suffixes():
if typ != imp.PY_COMPILED:
continue
codefile = pathbase+suffix
if os.path.exists(codefile):
f = open(codefile,"rb")
try:
f.seek(8)
return marshal.load(f)
finally:
f.close()
source = self.get_source(fullname)
if source is not None:
return compile(source,pathname,"exec")
return None
开发者ID:cloudmatrix,项目名称:signedimp,代码行数:35,代码来源:bootstrap.py
示例3: load_model
def load_model(f_name):
_curpath = os.path.normpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
# For Jython
start_p = {}
abs_path = os.path.join(_curpath, PROB_START_P)
with open(abs_path, 'rb') as f:
start_p = marshal.load(f)
trans_p = {}
abs_path = os.path.join(_curpath, PROB_TRANS_P)
with open(abs_path, 'rb') as f:
trans_p = marshal.load(f)
emit_p = {}
abs_path = os.path.join(_curpath, PROB_EMIT_P)
with open(abs_path, 'rb') as f:
emit_p = marshal.load(f)
state = {}
abs_path = os.path.join(_curpath, CHAR_STATE_TAB_P)
with open(abs_path, 'rb') as f:
state = marshal.load(f)
f.closed
return state, start_p, trans_p, emit_p, result
开发者ID:lol666666,项目名称:jieba,代码行数:26,代码来源:__init__.py
示例4: charge_et_genere_3d
def charge_et_genere_3d(self,fichier):
#print marshal.version
f = open(fichier,'rb')
self.section_catalogue=marshal.load(f)
obj=marshal.load(f)
f.close()
formecentre=self.__salome_genere_section_catalogue()
newvolume=[]
repereglobal= geompy.MakeMarker(0,0,0, 1,0,0,0,1,0)
for a in obj:
ori=geompy.MakeVertex(a[0][0],a[0][1],a[0][2])
fin=geompy.MakeVertex(a[1][0],a[1][1],a[1][2])
nouveaurepere= geompy.MakeMarker(a[0][0],a[0][1],a[0][2], a[2][0],a[2][1],a[2][2],a[3][0],a[3][1],a[3][2])
basesurface=geompy.MakePosition(formecentre[a[4]],repereglobal,nouveaurepere)
newvolume.append(geompy.MakePrism(basesurface,ori,fin))
#for k,v in formecentre.iteritems():
# geompy.addToStudy(v,k)
#for v in newvolume:
# geompy.addToStudy(v,"Volumique")
outshape=geompy.MakeCompound(newvolume)
geompy.addToStudy(outshape,"Volumique")
#geompy.Export(outshape, "/home/fred/asteretude/kuwait/toto.stp", "STEP")
salome.sg.updateObjBrowser(1)
开发者ID:freddupont,项目名称:ogaca,代码行数:26,代码来源:catalogue_beta3.py
示例5: load_original_char_table
def load_original_char_table(selected_files):
"""load char_table from disk"""
if selected_files is None or len(selected_files) == 0:
selected_files = [os.path.join(os.getcwd(), dat_dir, f) for f in os.listdir(dat_dir) if os.path.isfile(os.path.join(dat_dir,f)) and f.endswith('.dat')]
char_table = {}
for datfile in selected_files:
print "load %s" % datfile
inf = open(datfile, 'rb')
try:
text_title = marshal.load(inf)
new_char_table = marshal.load(inf)
# merge new_char_table to char_table
for key, value in new_char_table.items():
if char_table.has_key(key):
char_table[key]['context'] += value['context']
char_table[key]['rating'] = max(char_table[key]['rating'], value['rating'])
char_table[key]['tabu'] = char_table[key]['tabu'].union(value['tabu'])
else:
char_table[key] = value
finally:
inf.close()
return char_table
开发者ID:herrkaefer,项目名称:baby-naming,代码行数:27,代码来源:character_tool.py
示例6: test_floats
def test_floats(self):
# Test a few floats
small = 1e-25
n = sys.maxint * 3.7e250
while n > small:
for expected in (-n, n):
f = float(expected)
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
marshal.dump(f, file(test_support.TESTFN, "wb"))
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(f, got)
n /= 123.4567
f = 0.0
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
n = sys.maxint * 3.7e-250
while n < small:
for expected in (-n, n):
f = float(expected)
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
marshal.dump(f, file(test_support.TESTFN, "wb"))
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(f, got)
n *= 123.4567
os.unlink(test_support.TESTFN)
开发者ID:bushuhui,项目名称:pyKanjiDict,代码行数:32,代码来源:test_marshal.py
示例7: charge_et_genere_3d
def charge_et_genere_3d(self,fichier,exportstl=None):
#print marshal.version
f = open(fichier,'rb')
self.section_catalogue=marshal.load(f)
obj=marshal.load(f)
f.close()
formecentre=self.__salome_genere_section_catalogue()
newvolume=[]
repereglobal= geompy.MakeMarker(0,0,0, 1,0,0,0,1,0)
for a in obj:
#impression du nom de la forme debug
#print a[4]
ori=geompy.MakeVertex(a[0][0],a[0][1],a[0][2])
fin=geompy.MakeVertex(a[1][0],a[1][1],a[1][2])
nouveaurepere= geompy.MakeMarker(a[0][0],a[0][1],a[0][2], a[2][0],a[2][1],a[2][2],a[3][0],a[3][1],a[3][2])
basesurface=geompy.MakePosition(formecentre[a[4]],repereglobal,nouveaurepere)
newvolume.append(geompy.MakePrism(basesurface,ori,fin))
#for k,v in formecentre.iteritems():
# geompy.addToStudy(v,k)
#for v in newvolume:
# geompy.addToStudy(v,"Volumique")
outshape=geompy.MakeCompound(newvolume)
geompy.addToStudy(outshape,"Volumique")
if exportstl!=None:
geompy.Export(outshape, exportstl, "STL_Bin")
salome.sg.updateObjBrowser(1)
开发者ID:freddupont,项目名称:ogaca,代码行数:34,代码来源:catalogue_beta.py
示例8: __init__
def __init__(self, settings):
super(PyborgBrain, self).__init__(settings)
self.log.info("Reading dictionary...")
try:
zfile = zipfile.ZipFile('archive.zip', 'r')
except (EOFError, IOError):
self.log.debug("No archive.zip found to unarchive")
else:
# Unarchive all the files from the zip.
for filename in zfile.namelist():
data = zfile.read(filename)
with open(filename, 'w+b') as data_file:
data_file.write(data)
try:
with open('version', 'rb') as version_file:
content = version_file.read()
if content != self.saves_version:
self.log.error("Dictionary is version %s but version %s is required. Please convert the dictionary.",
content, self.saves_version)
# TODO: use an exception here
sys.exit(1)
with open('words.dat', 'rb') as words_file:
self.words = marshal.load(words_file)
with open('lines.dat', 'rb') as lines_file:
self.lines = marshal.load(lines_file)
except (EOFError, IOError):
self.log.info("Couldn't read saved dictionary, so using a new database.")
self.words = {}
self.lines = {}
self.num_words = len(self.words)
self.num_contexts = sum(len(line[0].split()) for line in self.lines.itervalues())
self.log.debug("Checking dictionary for new aliases...")
for word in self.words.keys():
if word.startswith('~'):
if word not in self.settings.aliases:
self.log.debug("Unlearning alias %r", word)
self.unlearn_word(word)
else:
for alias_word, patterns in self.settings.aliases.iteritems():
for alias_pattern in patterns:
pattern = r'^%s$' % alias_pattern
if re.search(pattern, word):
self.log.debug("Discovered alias %r for word %r, replacing", alias_word, word)
self.replace_word(word, alias_word)
# Unlearn words in the unlearn.txt file.
try:
with open('unlearn.txt', 'r') as unlearn_file:
for word in unlearn_file:
word = word.strip()
if word and word in self.words:
self.unlearn_word(word)
except (EOFError, IOError):
# No words to unlearn.
pass
开发者ID:J0s3f,项目名称:PyBorg,代码行数:60,代码来源:pyborg.py
示例9: test_dict
def test_dict(self):
new = marshal.loads(marshal.dumps(self.d))
self.assertEqual(self.d, new)
marshal.dump(self.d, file(test_support.TESTFN, "wb"))
marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(self.d, new)
os.unlink(test_support.TESTFN)
开发者ID:bushuhui,项目名称:pyKanjiDict,代码行数:7,代码来源:test_marshal.py
示例10: scan_module
def scan_module(egg_dir, base, name, stubs):
"""Check whether module possibly uses unsafe-for-zipfile stuff"""
filename = os.path.join(base,name)
if filename[:-1] in stubs:
return True # Extension module
pkg = base[len(egg_dir)+1:].replace(os.sep,'.')
module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0]
f = open(filename,'rb'); f.read(8) # skip magic & date
try:
code = marshal.load(f); f.close()
except ValueError:
f.seek(0); f.read(12) # skip magic & date & file size; file size added in Python 3.3
code = marshal.load(f); f.close()
safe = True
symbols = dict.fromkeys(iter_symbols(code))
for bad in ['__file__', '__path__']:
if bad in symbols:
log.warn("%s: module references %s", module, bad)
safe = False
if 'inspect' in symbols:
for bad in [
'getsource', 'getabsfile', 'getsourcefile', 'getfile'
'getsourcelines', 'findsource', 'getcomments', 'getframeinfo',
'getinnerframes', 'getouterframes', 'stack', 'trace'
]:
if bad in symbols:
log.warn("%s: module MAY be using inspect.%s", module, bad)
safe = False
if '__name__' in symbols and '__main__' in symbols and '.' not in module:
if sys.version[:3]=="2.4": # -m works w/zipfiles in 2.5
log.warn("%s: top-level module may be 'python -m' script", module)
safe = False
return safe
开发者ID:darthlukan,项目名称:pysys,代码行数:34,代码来源:bdist_egg.py
示例11: test_list
def test_list(self):
lst = self.d.items()
new = marshal.loads(marshal.dumps(lst))
self.assertEqual(lst, new)
marshal.dump(lst, file(test_support.TESTFN, "wb"))
marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(lst, new)
os.unlink(test_support.TESTFN)
开发者ID:bushuhui,项目名称:pyKanjiDict,代码行数:8,代码来源:test_marshal.py
示例12: test_tuple
def test_tuple(self):
t = tuple(self.d.keys())
new = marshal.loads(marshal.dumps(t))
self.assertEqual(t, new)
marshal.dump(t, file(test_support.TESTFN, "wb"))
marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(t, new)
os.unlink(test_support.TESTFN)
开发者ID:bushuhui,项目名称:pyKanjiDict,代码行数:8,代码来源:test_marshal.py
示例13: getIDFScores
def getIDFScores(log = False):
if log:
with open('idf_dict_log', 'rb') as f:
idf_dict = marshal.load(f)
else:
with open('idf_dict', 'rb') as f:
idf_dict = marshal.load(f)
return idf_dict
开发者ID:supermari0,项目名称:cs276pa4,代码行数:8,代码来源:common.py
示例14: read_results
def read_results():
searchresults_file = open(filename1, 'rb')
search_results = marshal.load(searchresults_file)
searchresults_file.close()
searchresults_file = open(filename2, 'rb')
topic = marshal.load(searchresults_file)
searchresults_file.close()
return search_results, topic
开发者ID:garima87,项目名称:IR,代码行数:8,代码来源:part1.py
示例15: read
def read(path):
log.info('Reading entity cooccurrence model from file: %s' % path)
with open(path, 'rb') as f:
cooccurrence_counts = marshal.load(f)
occurrence_counts = marshal.load(f)
return EntityCooccurrence(cooccurrence_counts, occurrence_counts)
开发者ID:Darnok99,项目名称:nel,代码行数:8,代码来源:model.py
示例16: loadCode
def loadCode(path):
f = open(path)
magic = f.read(len(PTLC_MAGIC))
if magic != PTLC_MAGIC:
raise ValueError, 'bad .ptlc magic for file "%s"' % path
mtime = marshal.load(f)
co = marshal.load(f)
f.close()
return co
开发者ID:carmackjia,项目名称:douban-quixote,代码行数:9,代码来源:ptlc_dump.py
示例17: fastLoad
def fastLoad(self, directory):
started = time.clock()
f = open(os.path.join(directory, self.name + '.fastmap'), 'rb')
self._mapFileHash = marshal.load(f)
self._codeSpaceRanges = marshal.load(f)
self._notDefRanges = marshal.load(f)
self._cmap = marshal.load(f)
f.close()
finished = time.clock()
开发者ID:Guillon88,项目名称:stdm,代码行数:9,代码来源:cidfonts.py
示例18: test_buffer
def test_buffer(self):
for s in ["", "Andrè Previn", "abc", " "*10000]:
b = buffer(s)
new = marshal.loads(marshal.dumps(b))
self.assertEqual(s, new)
marshal.dump(b, file(test_support.TESTFN, "wb"))
marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(s, new)
os.unlink(test_support.TESTFN)
开发者ID:bushuhui,项目名称:pyKanjiDict,代码行数:9,代码来源:test_marshal.py
示例19: test_unicode
def test_unicode(self):
for s in [u"", u"Andrè Previn", u"abc", u" "*10000]:
new = marshal.loads(marshal.dumps(s))
self.assertEqual(s, new)
self.assertEqual(type(s), type(new))
marshal.dump(s, file(test_support.TESTFN, "wb"))
marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(s, new)
self.assertEqual(type(s), type(new))
os.unlink(test_support.TESTFN)
开发者ID:bushuhui,项目名称:pyKanjiDict,代码行数:10,代码来源:test_marshal.py
示例20: do_filelog
def do_filelog(self, path):
if path[-2:] != '/*':
path += '/*'
with self.p4_popen('filelog', path) as pipe:
data = marshal.load(pipe)
if data['code'] == 'error':
raise EOFError
else:
yield data
while True:
yield marshal.load(pipe)
开发者ID:dex,项目名称:p4fuse,代码行数:11,代码来源:p4fuse.py
注:本文中的marshal.load函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论