これは何か? pickle でファイル保存できるのとほぼ同じ書き方で保存できる joblib.dump/joblib.load について調べた。 pickle と joblib の比較について。compress を使うと joblib の方がファイルサイズが小さくなる。読み込み速度も変わるかもしれない。 joblib の compress の値は3程度が良いと言われているが、実際調べてると大体3くらいでちょうどいいことが確認できた。 背景 pickleの代わりにjoblibを使って永続化する - 計算物理屋の研究備忘録 joblib.dump/load は pickle とほぼ同じ使い方?ただし compress オプションを指定しないと圧縮してくれないので、圧縮レベルを3くらいにするのがよいとか。 https://t.co/TAvMnIlLO5— Tak (@takaishikawa42
いつものやつです。対応していない値をjson.dumps()に与えるとTypeErrorが発生するやつです。 TypeError 例えばこういうdataclassを定義して。 from dataclasses import dataclass, asdict @dataclass class Point: x: int y: int json.dumpsするとTypeError import json p = Point(x=1, y=2) # TypeError: Object of type Point is not JSON serializable print(json.dumps(p)) default いつもどおりにdefaultを渡してあげる必要があります。ちょっとめんどくさいですが、is_dataclassという関数で調べられるのでどうにかなります。 import json
jsonのencodeエラーについては昔に書いたこの辺を見てもらうとして。 pythonでjson出力する際で対応していない型(e.g. datetime)の値を変換しながら出力したい - Qiita 今回の主題は、json.dumpsに渡すdefaultの関数としてfunctools.singledispatchが有用かもという話。 使いかた singledispatchを利用したモジュールを定義 例えば以下のようなextjsonモジュールを定義してあげる。 extjson.py import json from functools import ( singledispatch, partial, ) @singledispatch def encode(o): raise TypeError("Object of type '%s' is not JSON serializable"
I am trying to crawl the latest reviews from google play store and to get that I need to make a post request. With the Postman, it works and I get desired response. but a post request in terminal gives me a server error For ex: this page https://play.google.com/store/apps/details?id=com.supercell.boombeach curl -H "Content-Type: application/json" -X POST -d '{"id": "com.supercell.boombeach", "revi
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work. Try for free Learn more
C言語、Perl、JavaScript、最近はPythonも。出来上がったものより、プログラムを書くことが好き。あと、スイーツ。 Python2.6でdictionaryをjson文字列化したときに 日本語が\uXXXXとUTF-16な文字列にエスケープさせないようにするのに苦労した。 (忙しい人は、最後の要するに~の部分をご参考に) Pythonでdictionaryをファイルに読み書きするとき、 テキストファイルで一番簡単なのはJSON文字列化する手だろう。 テキストにすると、エディタで編集できるし、diffもとりやすいし、gitやsvn管理した際に履歴も追いやすい。 だけど、JSON文字列化がむずかしい。 日本語が\\uXXXXとUTF-16な文字としてエスケープされてしまう。 これだと日本語部分をエディタで編集できなくなってしまうので、 いろいろ試してみた。 まず、dictiona
PHPでコードを書いててちょっと動作確認したいというときにvar_dumpは本当に便利。元からあるデータ型だろうが、自作のクラスだろうがきれいに整形してすべてのデータを表示してくれる。 <?php $a = array(1, 2, array("a", "b", "c")); var_dump($a); ?> # => array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } 自作クラスのインスタンスでもほぼ同じ形式で表示できる。さて、Pythonではどうかというと from pprint import pprint a = [1, 2, ["a", "b", "c"]] pprint(a) # => [1, 2,
Dumper.py � �� """ A perl Data.Dumper clone for Python Author: simon@log4think.com 2011-07-08 Copyright 2011 Jinyu LIU Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く