ドットインストール代表のライフハックブログ
趣味プログラマです、こんにちわ。一応生きてます。 さて、Pythonista各位におかれましてはmoratoriumをエンジョイされていますでしょうか。そろそろライブラリも著名なものはPython3に対応してきましたし、そろそろ本格的にPython3、となっているころ合いですね。というか、Python3に対応してないとちょっと恥ずかしくなってきましたね。 とはいえ、Python2は根強く残るでしょう。というわけでPython2とPython3両方で動くコードを書きましょう。テストも書くのは当たり前ですし、せっかくなのでCIもしましょう。 と私も最近思ったので快適に開発を進めるための環境についてメモです。 github : 言わずもがなですね。 travis : githubと連携してCIできるサービス。P言語にも対応していて、最近アツいです。 tox : 複数のPython処理系でvirt
Requests: HTTP for Humans™¶ Release v2.32.3. (Installation) Requests is an elegant and simple HTTP library for Python, built for human beings. Behold, the power of Requests: >>> r = requests.get('https://api.github.com/user', auth=('user', 'pass')) >>> r.status_code 200 >>> r.headers['content-type'] 'application/json; charset=utf8' >>> r.encoding 'utf-8' >>> r.text '{"type":"User"...' >>> r.json()
I'm an eighteen-year old student from Nepal interested in computers and technology. Twitter Email Github Feed I had some difficulty in grasping how exactly to set up a server when I tried to do so recently, so I decided to write a tutorial that will guide you through the process. Hopefully, this post will help you avoid at least some of the confusion that I encountered. We'll be using Nginx +
悩まなくても良いようにメモ。 作りたいパッケージ(パッケージ名: foo) ファイル構成(置き場所) . ├── README.txt ├── docs ├── foo │ ├── __init__.py │ ├── locale │ └── tests ├── setup.cfg ├── setup.py └── tox.ini シンプルなもの . ├── README.txt ├── foo │ ├── __init__.py │ └── tests ├── setup.cfg └── setup.py 普通にsetup.pyを書く setup.pyにextra_requiersを書く(docs,testing) setup.cfgにextra_requiresのためのaliasを書く
Python 3 の数値をバイト列に変換する方法は bytes([i])*1。いままでとあきらかに違うことを知ったのが発端。 >>> bytes([97]) b'a' ユニコード文字列、バイト列の違いを調査開始。 型の名称とリテラル表記 Python 2.6 は新旧両方の書き方ができるものも。 Python 2.5以前 Python 2.6 Python 3.0 and 3.1 ユニコード文字列型 unicode unicode str バイト列型 str str or bytes*2 bytes 可変バイト列型 (なし)*3 bytearray bytearray ユニコードリテラル u'a' u'a'*4 'a' バイトリテラル 'a' 'a' or b'a'*5 b'a' メソッド メソッド関連は大差ない。 Python 3 では Python 2 の string.maketran
1. PyQtではじめる GUIプログラミング 2011-08-27 Python Conference JP 2011 Ransui Iso Strategic Technology Group / X-Listing Co, Ltd. Copyright (c) 2011 Ransui Iso, All rights reserved. 2. おまえ誰よ? Ransui Iso (磯 蘭水) Work at X-Listing Co, Ltd. http://www.xlisting.co.jp/ Pythonは1998年から使っています。E-Commerceエンジンやサーチエンジンの開 発、Zopeを用いたWebサイト開発、その他色々を経て、今はネット広告配信シス テムについての研究開発をしています。最近はCommon Lispでシステム開発をし ていますが、Pythonもヘビーに使
ほかのプログラミング言語でちょっとよさげなアイデアが採用されているのを見ると、それを自分のお気に入りの言語でも実現したくなってくるものらしく、C# のイベント機構を Python でも実現できないかと考える人は少なくないようです。「c# event python」といったキーワードで検索すると、同様のことを試みたページが少なからず見つかります。以下もそれらと同様の試みのひとつですが、デスクリプタという Python の興味深い仕組みを使い、少し進んだ実装を目指します。 前提 シンプルな実装 より使いやすく 使い方 実装 解説 むすび 参考文献 Python でのイベント機構実装について デスクリプタについて 事項 前提 C# のイベントの概念とそれがどう素敵なのかについての説明は省略します。 シンプルな実装 イベントをクラスとしてシンプルに実装すると、次のようなものになるでしょう。 最後の
Pythonにはじめて触って、いつのまにか1年が過ぎたのですが、一番はまったのは、やっぱりunicodeの扱いだったと思います。 特に、 UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-12: ordinal not in range(128) のようなエラーにはさんざん悩まされました。ここがたとえばrubyなど他の言語と比べてわかりにくいために、Pythonが取っつきにくい言語になっているのではないか、と個人的には思います。 そこで、このエラーに関係するはまりどころとTipsをいくつか列挙してみました。これからPythonに触れられる方の参考になればと思います。 なお、環境はUNIX上のPython 2.4, 2.5を想定しています。 u1はunicode型で、s1はstr型です。s1にどのよ
これはびっくりした。なのでメモ。 i = 123 isinstance(i, int) # => True a = True isinstance(a, int) # => True b = False isinstance(b, int) # => True c = 1 isinstance(c, int) # => True d = 0 isinstance(d, int) # => True えぇー! i = 123 isinstance(i, bool) # => False a = True isinstance(a, bool) # => True b = False isinstance(b, bool) # => True c = 1 isinstance(c, bool) # => False d = 0 isinstance(d, bool) # => False ほっ
この記事は yosida95.com に移動しました。 新しい URL は https://yosida95.com/2011/05/15/194021.html です。 お手数をお掛けしますが、ブックマークの付け替えをお願いします。
ナビゲーション 索引 モジュール | 次へ | 前へ | Python v2.6.2 documentation » Python は簡単に習得でき、それでいて強力な言語の一つです。 Python は高レベルなデータ構造を効率的に実装していて、 オブジェクト指向プログラミングに対しても、単純ながら効果的なアプローチをとっています。 洗練された文法とデータ型を動的に決定する機能、そしてインタプリタであるという特徴から、 Python はほとんどのプラットフォームの幅広い対象領域において、 スクリプティングや迅速なアプリケーション開発のための理想的な言語になっています。 Pythonインタプリタ自体と膨大な標準ライブラリは、ソースコード形式や、 主要なプラットフォーム向けのバイナリ形式で、Python Web サイト http://www.python.org/ から無料で入手でき、かつ無料で
Pythonで文字列のASCII値をリストで返してみた。 seq = "abcdefg" #A lst = [] for s in seq: ord_num = ord(s) lst.append(ord_num) print lst #B print [ord(s) for s in seq] #C print map(ord, list(seq)) #D def f(lst): for s in seq: yield ord(s) print list(f(seq)) 実行結果 [97, 98, 99, 100, 101, 102, 103] [97, 98, 99, 100, 101, 102, 103] [97, 98, 99, 100, 101, 102, 103] [97, 98, 99, 100, 101, 102, 103]
システム開発や保守、運用の現場においてドキュメントは必須のものです。 しかし、ドキュメントの作成・維持には多くのパワーがかかるため、ドキュ メントが存在しない、資料が古いままになっているなどといった現状を多く 耳にします。 本勉強会ではこれらのドキュメントでよく利用される「図」にフォーカスし、 みるみるうちに図を作成できる「blockdiag」をご紹介します。 「blockdiag」はシンプルなテキスト記述からブロック図、ネットワーク図などの 画像ファイルを出力可能なオープンソースの画像生成ツールです。書き やすさ、メンテナンスしやすさを中心にデザインされており、図を作るのに 配置や並べ替えに苦労する必要はありません。 blockdiagのサンプルはこちら このような特徴を持つ「blockdiag」と、シンプルな記述でドキュメントを作成 するツール「Sphinx」を組み合わせることによって
ここ数ヶ月、Google App Engine/Pythonを使い、初めてちょっとしたものを作ってみているのだけど、開発初期から知っておけばよかったなー、と思うノウハウ/tips的なものをずらずらと書いてみる。 基本的な環境設定は、 以前書いた まま。 0. 公式ドキュメントを良く読む 言うまでもなく、だけど、 マニュアル はもちろん、 この辺 の下の読み物も、流し読みだけでもしておいたほうがいい。 datastoreとmodel的なところ 1. key nameを使いこなす key nameは、レコードの作成時に指定できる(RDBでいう)primary keyの別名みたいなもの。primary key自体は自動的で作成されるので開発者が指定できるのはkey nameだけ。 key nameをうまく使うことで、datastoreを使いやすくすることができる。特にdatastore上で"un
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く