Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
Cheat Sheet: Writing Python 2-3 compatible code¶ Copyright (c): 2013-2024 Python Charmers, Australia. Author: Ed Schofield. Licence: Creative Commons Attribution. A PDF version is here: https://python-future.org/compatible_idioms.pdf This notebook shows you idioms for writing future-proof code that is compatible with both versions of Python: 2 and 3. It accompanies Ed Schofield’s talk at PyCon AU
Compile-time type checking Static typing makes it easier to find bugs with less debugging. Easier maintenance Type declarations act as machine-checked documentation. Static typing makes your code easier to understand and easier to modify without introducing bugs. Grow your programs from dynamic to static typing You can develop programs with dynamic typing and add static typing after your code has
このスライドの注意事項/意図 ● 基本的に Python3 を前提にこのスライドを作っています ● Python3の特徴について網羅できてはいません – ググればすぐに見つかるようなものは省いた ● 文字列が全て Unicode になった ● 組み込み関数がジェネレーターを返すようになった ● 標準モジュール名やそのメソッドの命名規則が統一された – Python2 から 3 への移行のノウハウはありません – Python2 と 3 の両対応のノウハウはありません Python3 でプログラミングするときに知っておくと 楽しそうなことを自分なりに調べてきた がんばって調べたけど、間違ってたらごめんなさい
Here are the edits made to this table after its initial publication on 2014-07-07, thanks to reader-submitted corrections: Added Columbia ENGI E1006 (Python), since a current student emailed me about it. Here's an excerpt: "Very few people are required to take the Matlab course [1005] (mostly just a few specific engineering majors), whereas all CS majors, and all engineers in general have to take
Pythonをよく使う人にはよく知ってる人も多いのですが、docoptという便利ライブラリがあります。 docoptはargparseやoptparseのようなコマンドライン引数をパースするライブラリなのですが、その発想がコロンブスの卵なのです。 例えばPython標準のargparseだと、argparseのAPIを組み合わせてパーサを組み立てるわけです。するとパーサと一緒にヘルプも作ってくれて、"program --help"などとすると自動生成されたヘルプを表示してくれるようになります。 しかし、そのAPIを覚えるのが大変で、毎回ドキュメントを読まないと忘れちゃうわけです。 import argparse parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument
!バージョンによって挙動が全然違うので注意してください! 通常 docker は daemon として待ち受けていて、unix domain socket を listen している。実はこの socket に流れるプロトコルは REST/HTTP で、-H option で tcp に bind させることもできて、webサーバになる。仕様は ["Docker Remote API"] (http://docs.docker.io/reference/api/docker_remote_api/) に書いてある。そして各種 language client も存在する。 そんな python client である docker-py のお話。 まずは通常の使い方。 import docker dc = docker.Client() # docker ps dc.containers()
PythonのcollectionsモジュールにはdefaultdictやCounterなどの便利なデータ構造があります。 いくつかメモ代わりに紹介しておきます defaultdict 辞書にキーが含まれない場合のデフォルト値を指定できます。 リストをデフォルトで持つ辞書などが作れます。 defaultdictへの引数としては初期値のものを返す関数を与えます from collections import defaultdict d = defaultdict(list) d['Hello'].append('World') 変わった使い方としては以前別の記事でも紹介しましたが単語にIDを割り振るのに便利です 単語などをIDにマッピングする - 唯物是真 @Scaled_Wurm 以下のようなコードを書くと未知の単語が辞書に与えられたら、その単語に新たなIDを振っていくことができます。 w
去年10月に Python 3 の MySQL ドライバ事情 という記事で次のように書いていました。 多分デファクトスタンダードな MySQLドライバなのですが、現状リリースされている 1.2.4 では Python 3 対応ができていません。 Fork の MySQL-for-Python3 が推奨されます。 最近 MySQL-python の方に Python 3 対応の準備的な Pull Request (古い構文を Python 2/3 両対応の構文に置き換える) がちらほらあり、やっぱり中途半端にメンテされてない Fork より本家に対応してもらわないとなぁということで、エイヤで Python 3 対応してしまって 少し大きめの Pull Request を投げました。 しかし、長年の実績がある本家といえども、個人プロジェクトで、1年に数回しかコミットされてない現状です。 一応、
『るびま』は、Ruby に関する技術記事はもちろんのこと、Rubyist へのインタビューやエッセイ、その他をお届けするウェブ雑誌です。 Rubyist Magazine について 『Rubyist Magazine』、略して『るびま』は、Rubyist の Rubyist による、Rubyist とそうでない人のためのウェブ雑誌です。 最新号 Rubyist Magazine 0064 号 バックナンバー Rubyist Magazine 0064 号 Rubyist Magazine 0063 号 Rubyist Magazine 0062 号 Kaigi on Rails 特集号 RubyKaigi Takeout 2020 特集号 Rubyist Magazine 0061 号 Rubyist Magazine 0060 号 RubyKaigi 2019 直前特集号 Rubyist
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く