memo in2csv
- エクセルやJSONをCSVに変換できる
- JSONはネストしててもある程度はカラムで対応できる
- 出力先で囲い文字は出せない
- HTMLエスケープしてたらCSV出力がおかしくなる
memo in2csv
Input {"foo": 42, "bar": "less interesting data", "baz": "sdkjhsdf"} Output {"foo": 42, "baz": "sdkjhsdf"}
こういうときは del(.bar)
をつかう
pyenvをアップデートするやつ チュートのとおりにいれたら、pyenv update
が使えるようになって、pyenvをアップデートしてインストールできるPythonを増やせる。
Emacsのshell-commandで以下のようなPythonワンライナーを実行するとUnicodeEncodeErrorが発生した。
(shell-command-to-string "/usr/local/bin/python2.7 -c \"import sys; sys.stdout.write(u'テスト')\"") "Traceback (most recent call last): File \"<string>\", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-8: ordinal not in range(128) " (shell-command-to-string "/usr/local/bin/python3.7 -c \"import sys; sys.stdout.write(u'テスト')\"") "テスト"
今回shell-command-to-stringを使ったけどshell-commandでもcall-process-shell-commandでも結果はいっしょだった。
でも、端末で同じコマンドを実行してもエラーは起きない(文字化けするけど)。
$ /usr/local/bin/python2.7 -c "import sys; sys.stdout.write(u'テスト')" ãã¹ã $ /usr/local/bin/python3.7 -c "import sys; sys.stdout.write(u'テスト')" テスト
いろいろ調べていたら以下のような記載があった(公式ではない)
Python determines the encoding of stdout and stderr based on the value of the LC_CTYPE variable, but only if the stdout is a tty. So if I just output to the terminal, LC_CTYPE (or LC_ALL) define the encoding. However, when the output is piped to a file or to a different process, the encoding is not defined, and defaults to 7-bit ASCII.
はい。 Python2.7での標準出力の文字コードは sys.stdout.encoding
で設定されており、基本はLC_CTYPE/LC_ALL/LANGなどの設定を見てsys.stdout.encoding
の値が設定されているのだが、ttyじゃなくてパイプ/リダイレクトなど別プロセスを経由して結果を出力しようとした場合、文字コードは何も設定されない(3.7ではこの問題は解消されているようだが)
Encoding of Python stdout - Exterior Memory What a Character! | QED and NOM
試しに以下のように出力結果をリダイレクトして別ファイルに出力すると、結果が違う。
$ /usr/local/bin/python2.7 -c "import sys; print(sys.stdout.encoding)" UTF-8 $ /usr/local/bin/python3.7 -c "import sys; print(sys.stdout.encoding)" UTF-8 $ /usr/local/bin/python2.7 -c "import sys; print(sys.stdout.encoding)" > test.out; cat test.out None $ /usr/local/bin/python3.7 -c "import sys; print(sys.stdout.encoding)" > test.out; cat test.out UTF-8
shell-command系関数を実行してシェルスクリプトを実行したときもttyじゃないから、sys.stdout.encodingがNoneになり、よってUnicodeEncodeErrorとなる。
なので、Python2.7での対策は、事前に PYTHONIOENCODING
でstdin/stdout/stderrのエンコーディングを強制すること。
$ export PYTHONIOENCODING=UTF-8; /usr/local/bin/python2.7 -c "import sys; print(sys.stdout.encoding)" > test.out; cat test.out UTF-8
旅をしすぎてタイトルをつけるのがめんどくさなった。
定義はdefadviceだった
OpenCSVSerdeの中身。結構あっさりしている。テストコードもあっさり。
CSV Serde - Apache Hive - Apache Software Foundation
csv-serde/CSVSerde.java at master · ogrodnek/csv-serde · GitHub
なんかいろいろ紹介されているけど、peekでいい気がしている。
sudo add-apt-repository ppa:peek-developers/stable sudo apt update sudo apt install peek
cosmicのリポジトリがないので、 /etc/apt/sources.list.d
の下を修正した。
結果。
dynamodbあたり
dynamodb
: Update dynamodb command to latest versionstepfunctions
: Update stepfunctions command to latest versionsms-voice
: Update sms-voice command to latest versionacm-pca
: Update acm-pca command to latest version今夏にはこんなかんじ
transcribe
: Update transcribe command to latest versioncomprehend
: Update comprehend command to latest versionmedialive
: Update medialive command to latest versionfirehose
: Update firehose command to latest versioncognito-idp
: Update cognito-idp command to latest version読み方が安定しないSerDe
SerDeの読み方は「さーでぃー」だったのか.「さーで」って読んでたわ Hadoopデータプラットフォーム #cwt2013 by @ClouderaJP #cloudera #hadoop http://t.co/E08nDDbZcb @SlideShareさんから
— Takuma Wakamori (@twakamor) May 29, 2014
マネコンをポチポチしてテーブルを作る方法ではOpenSerDeはつくられないし、CSVファイル読み込みだとファイルの中身がダブルクオート囲みだったらデータの出力にダブルクオートが含まれる。 docs.aws.amazon.com
あと、ヘッダー行もデフォルトだと入るので、skip.header.line.countのオプションとかも入れる。 dev.classmethod.jp
そろそろだけど年末は休業したい
elasticbeanstalk
: Update elasticbeanstalk command to latest versionapigatewaymanagementapi
: Update apigatewaymanagementapi command to latest versionec2
: Update ec2 command to latest versionglobalaccelerator
: Update globalaccelerator command to latest versionapigatewayv2
: Update apigatewayv2 command to latest versionsudo cpan install App::Greple::perl # 入っていないやつちょこちょこいれてく sudo cpan install Graphics::ColorNames:WWW sudo cpan install Getopt::EX::Loader sudo apt-get install cpanminus sudo cpanm App::Greple::msdoc greple -Mmsdoc "テスト" *.docx
GitHub - kaz-utashiro/greple: greple: extensible grep with lexical expression and region handling
substrのstartは1から。0じゃない。0なようにみえるけど。
6.9. String Functions and Operators — Presto 0.215 Documentation
ML自体はあって、gmailじゃないぽいし、パッチはgit send-mailだけどForumはあったりする よくわからない