本文整理汇总了Python中simplejson.dump函数的典型用法代码示例。如果您正苦于以下问题:Python dump函数的具体用法?Python dump怎么用?Python dump使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dump函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: update_notified
def update_notified(jobs):
with open(filename, 'r') as f:
data = simplejson.load(f)
for job in jobs:
data['jobs'][job]['notified'] = True
with open(filename, 'w') as f:
simplejson.dump(data, f)
开发者ID:legoktm,项目名称:matilda,代码行数:7,代码来源:notify_users.py
示例2: run
def run(self, options, **kwargs):
config_file = os.path.join(options.app_path, "wsgid.json")
f = self._open_config_file(config_file)
s = f.read()
cfg_values = {}
if s:
cfg_values = simplejson.loads(s)
# Copy the values
self._override_if_not_none("wsgi_app", cfg_values, options.wsgi_app)
self._override_if_not_none("debug", cfg_values, options.debug)
if options.workers > 1:
self._override_if_not_none("workers", cfg_values, options.workers, convert_func=int)
self._override_if_not_none("keep_alive", cfg_values, options.keep_alive)
self._override_if_not_none("chroot", cfg_values, options.chroot)
self._override_if_not_none("no_daemon", cfg_values, options.no_daemon)
self._override_if_not_none("recv", cfg_values, options.recv)
self._override_if_not_none("send", cfg_values, options.send)
self._override_if_not_none("mongrel2_chroot", cfg_values, options.mongrel2_chroot)
# Custom config command options
if options.no_debug:
cfg_values["debug"] = str((not options.no_debug))
# Rewrite the config file
f.seek(0)
f.truncate()
simplejson.dump(cfg_values, f, indent=" ")
f.close()
开发者ID:lwc,项目名称:wsgid,代码行数:29,代码来源:config.py
示例3: sync
def sync(self):
"""Synchronise and update the stored state to the in-memory state."""
if self.filepath:
with open(self.filepath, "w") as serialised_file:
simplejson.dump(self.state, serialised_file)
else:
print "Filepath to the persistence file is not set. State cannot be synced to disc."
开发者ID:benosteen,项目名称:ofs,代码行数:7,代码来源:storedjson.py
示例4: generate_top
def generate_top():
from collections import defaultdict
import simplejson as json
import operator
from_product = defaultdict(lambda: 0)
results = defaultdict(lambda: 0)
for product in cols['product'].find().sort('_id', -1):
for k in product.keys():
from_product[k] += 1
product_keys = dict(from_product)
for w in list(product_keys.keys()):
jieba.add_word(w, tag='nz')
progress = 0
for comment in cols['mobile_comment'].find(projection={'content': 1}):
c = comment['content']
words = jieba.analyse.extract_tags(c, topK=20, withWeight=False, allowPOS=('ns', 'n', 'nz'))
for w in words:
results[w] += 1
progress += 1
if progress % 100 == 0:
print('Current Progress: ', progress)
sorted_x = reversed(sorted(dict(results).items(), key=operator.itemgetter(1)))
json.dump(
list(sorted_x),
open('sorted_mobile.json', mode='w', encoding='utf-8'),
ensure_ascii=False,
indent=2
)
开发者ID:PaulMrzhang,项目名称:jd-comments,代码行数:28,代码来源:main.py
示例5: test_tuple_array_dump
def test_tuple_array_dump(self):
t = (1, 2, 3)
expect = json.dumps(list(t))
# Default is True
sio = StringIO()
json.dump(t, sio)
self.assertEqual(expect, sio.getvalue())
sio = StringIO()
json.dump(t, sio, tuple_as_array=True)
self.assertEqual(expect, sio.getvalue())
self.assertRaises(TypeError, json.dump, t, StringIO(),
tuple_as_array=False)
# Ensure that the "default" does not get called
sio = StringIO()
json.dump(t, sio, default=repr)
self.assertEqual(expect, sio.getvalue())
sio = StringIO()
json.dump(t, sio, tuple_as_array=True, default=repr)
self.assertEqual(expect, sio.getvalue())
# Ensure that the "default" gets called
sio = StringIO()
json.dump(t, sio, tuple_as_array=False, default=repr)
self.assertEqual(
json.dumps(repr(t)),
sio.getvalue())
开发者ID:All4Gis,项目名称:instagram2qgis,代码行数:25,代码来源:test_tuple.py
示例6: editfile
def editfile(fn, password):
filetype = aespckfile
if ".json" in fn:
filetype = aesjsonfile
db = filetype.load(fn, password)
f = tempfile.NamedTemporaryFile()
json.dump(db, f, indent=2)
f.flush()
mtime = os.path.getmtime(f.name)
while True:
subprocess.call([os.getenv("EDITOR") or "editor", f.name])
if os.path.getmtime(f.name) == mtime:
print "Not updated"
break
try:
f.seek(0)
db = json.load(f)
filetype.dump(fn, db, password)
break
except Exception, e:
print "Error in json"
print e
print "Try again (y/n)? ",
input = raw_input()
if not input.lower().startswith("y"):
break
开发者ID:talvinder,项目名称:pyWebCash,代码行数:26,代码来源:editdbfile.py
示例7: main
def main(argv):
data, lang = argv[-2:]
f = myStore.load(data)
lang = f.newSymbol(lang)
it = {
"rules": asGrammar(f, lang),
"tokens": tokens(f, lang),
"first": sets(f, lang, EBNF.first),
"follow": sets(f, lang, EBNF.follow),
}
if "--pprint" in argv:
from pprint import pprint
pprint(it)
elif "--yacc" in argv:
toYacc(it)
elif "--ply" in argv:
toPly(it)
else:
import simplejson # http://cheeseshop.python.org/pypi/simplejson
import sys
start = it["rules"][0][0]
print "SYNTAX_%s = " % start,
simplejson.dump(it, sys.stdout)
开发者ID:Mchockalingam,项目名称:swap,代码行数:26,代码来源:gramLL1.py
示例8: outputDashboard
def outputDashboard(self):
log.debug("Creating dashboard")
dirname = self.config.get('main', 'dashboard_dir')
if not os.path.exists(dirname):
# Copy in the rest of html
shutil.copytree('html/dashboard', dirname)
shutil.copytree('html/flot', '%s/flot' % dirname)
shutil.copytree('html/jquery', '%s/jquery' % dirname)
filename = os.path.join(dirname, 'testdata.js')
fp = open(filename + ".tmp", "w")
now = time.asctime()
fp.write("// Generated at %s\n" % now)
fp.write("gFetchTime = ")
json.dump(now, fp, separators=(',',':'))
fp.write(";\n")
fp.write("var gData = ")
# Hackity hack
# Don't pretend we have double precision here
# 8 digits of precision is plenty
try:
json.encoder.FLOAT_REPR = lambda f: "%.8g" % f
except:
pass
json.dump(self.dashboard_data, fp, separators=(',',':'), sort_keys=True)
try:
json.encoder.FLOAT_REPR = repr
except:
pass
fp.write(";\n")
fp.close()
os.rename(filename + ".tmp", filename)
开发者ID:mnoorenberghe,项目名称:graphs,代码行数:33,代码来源:analyze_talos.py
示例9: write
def write(self, filename, auto=False, data={}):
"""
Write the graph to scene file.
:param str filename: file to save.
:param bool auto: file is an autosave, don't set it as the current scene.
:param dict data: dictionary of graph data.
:returns: current scene name.
:rtype: str
"""
# callbacks
self.graphAboutToBeSaved()
if not data:
data = self.snapshot()
fn = open(filename, 'w')
json.dump(data, fn, indent=4)
fn.close()
if auto:
self._autosave_file = filename
# don't set the current autosave filename as the scene, use the parent filename
filename = filename[:-1]
# callbacks
self.graphSaved()
return self.setScene(filename)
开发者ID:mfessenden,项目名称:SceneGraph,代码行数:29,代码来源:graph.py
示例10: main
def main(inputPtnPath,outputPath):
start_time = datetime.now()
model, table = projizz.readPrefixTreeModelWithTable("./yagoPatternTree.model","./yagoPatternTree.table")
properties = projizz.buildYagoProperties({})
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
t = 0
result = []
for filename in os.listdir(inputPtnPath):
if ".json" in filename:
result.append(pool.apply_async(filterFunction, (t,filename,inputPtnPath,model,table,copy.deepcopy(properties) )))
t += 1
pool.close()
pool.join()
for res in result:
r = res.get()
for rela in r:
for ptnId in r[rela]:
if not ptnId in properties[rela]:
properties[rela][ptnId] = {"total":0,"support":0}
properties[rela][ptnId]["total"] += r[rela][ptnId]["total"]
properties[rela][ptnId]["support"] += r[rela][ptnId]["support"]
json.dump(properties,open(outputPath,"w"))
diff = datetime.now() - start_time
print "Spend %d.%d seconds" % (diff.seconds, diff.microseconds)
开发者ID:Open-IOT,项目名称:master-research,代码行数:32,代码来源:yago.pattern.statistics.py
示例11: generateShowsAndSave
def generateShowsAndSave(self):
f = open('../../xml/tv3shows.json', 'w')
for show in self.getMainMenu():
# Load and read the URL
f2 = urllib2.urlopen(EPISODE_URL % (show['url']))
text = f2.read()
f2.close()
key = show['Title']
try:
showkeys = self.KNOWN_TV3_SHOWS[key].keys()
print 'Updating ' + show['Title']
self.KNOWN_TV3_SHOWS[key]['']
except:
print 'Adding ' + show['Title']
self.KNOWN_TV3_SHOWS[key] = {}
self.KNOWN_TV3_SHOWS[key]['Title'] = show['Title']
REGEXP = '<div id="content" style="background-image: url\((.*?)\)">'
for mymatch in re.findall(REGEXP, text, re.MULTILINE):
fanart = mymatch
self.KNOWN_TV3_SHOWS[key]['Fanart_Image'] = fanart
S.dump(self.KNOWN_TV3_SHOWS, f, indent=4)
f.close()
开发者ID:Beirdo,项目名称:VODieR,代码行数:25,代码来源:TV3Scraper.py
示例12: main
def main(inputPath,outputFileName):
properties = buildProperties("../naive_model/PbR/")
start_time = datetime.now()
result = []
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
t = 0
for filename in os.listdir(inputPath):
if ".json" in filename:
partAns = copy.deepcopy(properties)
result.append(pool.apply_async(findAnwser, (t,filename,inputPath,partAns, )))
t += 1
pool.close()
pool.join()
for res in result:
r = res.get()
for m in r:
properties[m]["tp"] += r[m]["tp"]
properties[m]["tn"] += r[m]["tn"]
properties[m]["fp"] += r[m]["fp"]
properties[m]["fn"] += r[m]["fn"]
print "start write out to %s" % (outputFileName)
json.dump(properties,open(outputFileName,"w"))
diff = datetime.now() - start_time
print "Spend %d.%d seconds" % (diff.seconds, diff.microseconds)
开发者ID:Open-IOT,项目名称:master-research,代码行数:31,代码来源:treeEval.py
示例13: display_matching_trips
def display_matching_trips(request, trip_id=None, lib=None):
"""Make a request to the BV server to find matching trips. Format the
output to be read by javascript clientside code.
"""
def to_json(trip):
return [get_trip_dict(t) for t in trips]
trip_search_type = int(request.POST['trip_type'])
results = lib.search_trip(trip_id=trip_id, **unicode_to_dict(request.POST))
trip_demands = results['trip_demands']
trip_offers = results['trip_offers']
trip = results['trip']
if trip_search_type == TRIP_OFFER:
trips = trip_demands
else:
trips = trip_offers
response_dict = {
'authenticated': is_bvoauth_authenticated(request),
}
if not trip_id:
response_dict['trips'] = to_json(trips)
else:
response_dict['trip_demands'] = to_json(trip_demands)
response_dict['trip_offers'] = to_json(trip_offers)
resp = HttpResponse()
simplejson.dump(response_dict , resp, ensure_ascii=False, separators=(',',':'))
return resp
开发者ID:bisonvert,项目名称:bv.client,代码行数:30,代码来源:views.py
示例14: savemsgstore
def savemsgstore():
try:
f = open('generalmessage.json','w')
json.dump(generalmessagestore,f)
f.close()
except:
pass
开发者ID:Applied-Duality,项目名称:KV78Turbo-OVAPI,代码行数:7,代码来源:kv78turbo-api.py
示例15: update
def update(self):
"""
"""
params = {'key': yeti_config.get('threattracking', 'google_api_key')}
# , 'includeGridData': 'True'} - we don't want to do that. 200Mo file.
base = "https://sheets.googleapis.com/v4/spreadsheets/" + yeti_config.get(
'threattracking', 'sheet_key')
self.api = hammock.Hammock(base, params=params)
if False:
r = self.api.GET()
if r.status_code != 200:
raise requests.ConnectionError(
'Return code for {query} is {code}'.format(
query=r.request.url, code=r.status_code))
sheets = r.json()['sheets']
json.dump(sheets, open("actor.sheets.json", "w"))
else:
sheets = json.load(open("actor.sheets.json", "r"))
# print(pprint.pformat(sheets))
for s_p in sheets:
s = s_p['properties']
title = s['title']
if title in ['Home', '_Malware', '_Download', '_Schemes',
'_Sources']:
continue
size = s['gridProperties']
# print(title, size['columnCount'], size['rowCount'])
actors_list_info = self.each_sheet_work(s)
self.create_entities(title, actors_list_info)
return
开发者ID:raymundl,项目名称:yeti,代码行数:31,代码来源:threattracking.py
示例16: updateDagNodes
def updateDagNodes(self, dagnodes, debug=False):
"""
Update the networkx nodes and links attributes from scene values.
:param dagnodes: list of dag node objects.
:type dagnodes: list
"""
if type(dagnodes) not in [list, tuple]:
dagnodes=[dagnodes,]
for dag in dagnodes:
log.debug('Graph: updating dag node "%s"' % dag.name)
nid = dag.id
if nid in self.network.nodes():
#self.network.node[nid].update(dag.data)
dag_data = json.loads(str(dag), object_pairs_hook=dict)
nx_data = self.network.node[nid]
nx_data.update(dag_data)
if debug:
# write temp file
filename = os.path.join(os.path.dirname(self.autosave_path), '%s.json' % dag.name)
fn = open(filename, 'w')
json.dump(dag_data, fn, indent=4)
fn.close()
开发者ID:mfessenden,项目名称:SceneGraph,代码行数:25,代码来源:graph.py
示例17: build_tooltool_manifest
def build_tooltool_manifest():
def key_sort(item):
item = item[0]
if item == 'size':
return 0
if item == 'digest':
return 1
if item == 'algorithm':
return 3
return 4
basedir = os.path.split(os.path.realpath(sys.argv[0]))[0]
tooltool = basedir + '/tooltool.py'
setup = basedir + '/setup.sh'
manifest = 'clang.manifest'
check_run(['python', tooltool, '-m', manifest, 'add',
setup, 'clang.tar.bz2'])
data = simplejson.load(file(manifest))
data = [{'clang_version' : 'r%s' % llvm_revision }] + data
out = file(manifest,'w')
simplejson.dump(data, out, indent=0, item_sort_key=key_sort)
out.write('\n')
assert data[2]['filename'] == 'clang.tar.bz2'
os.rename('clang.tar.bz2', data[2]['digest'])
开发者ID:mshal,项目名称:mozilla-central,代码行数:25,代码来源:build-clang.py
示例18: gen_data
def gen_data(self, fname):
"""
:fname : input file, every line means a single data
:rtype : List[List[float]]: data matrix
"""
lines = [ self.langConvHandler.convert(line.strip().lower()) for line in codecs.open(fname, "rb","utf-8") if len(line) > 6]
# lines = list(set(lines)) # remove duplicates
logging.info("number of data %d " % len(lines))
cut_lines = [" ".join(jieba.cut(line)) for line in lines]
# transform to tfidfVec
tfidfVec = TfidfVectorizer(max_features = 3000)
tfidf_data = tfidfVec.fit_transform(cut_lines)
tfidf_data = tfidf_data.toarray()
# save origin text
with open("./output/origin_lines.txt", "wb") as fw:
json.dump(lines, fw)
# save vectorize data
np.save("./output/tfidf.corpus.npy", tfidf_data)
self.lines = lines
self.tfidf_data = tfidf_data
开发者ID:jkmiao,项目名称:textcluster,代码行数:27,代码来源:cluster_text.py
示例19: putJsonIntoFile
def putJsonIntoFile(fname, jdata):
if fname and isinstance(jdata, dict):
path = os.path.join(os.getcwd(), fname)
f = open(path, 'w+')
jdata['time'] = int(time.time())
json.dump(jdata, f)
f.close()
开发者ID:monitisexchange,项目名称:Monitis-Linux-Scripts,代码行数:7,代码来源:rabbitmq_monitor.py
示例20: write
def write(self):
path = os.path.join(os.path.dirname(__file__), '..',
'ionize', 'Database', 'ion_data.json')
print(path)
with open(path, 'w') as ion_file:
json.dump(self.data, ion_file,
sort_keys=True, indent=4, separators=(',', ': '))
开发者ID:lewisamarshall,项目名称:ionize,代码行数:7,代码来源:create_database.py
注:本文中的simplejson.dump函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论