Spr: The Ramblings Building Cocoa GUIs in Python with PyObjC, Part One / Jun 11, 2008 Introduction Building GUIs for Apple OS X traditionally meant you would code in Objective C. To overcome this issue people have made programming bridges to allow development in other languages. PyObjC is the project that enables Python programmers to take advantage of Cocoa, Apple's development environment. I rec
Pythonのリスト内包表記の細かい動作がようやく分かってきたので、ブログに書いておく。 参考にしたページ Python のリスト内包表記 | すぐに忘れる脳みそのためのメモ Pythonリスト内包表記文法 低速マスター - a2c.get.diary 基本 Google先生に聞いたら詳しい説明が出てくるので、簡単に。 リスト内包表記は、下記のように書くとリストが作れる記法です。 >>> [x for x in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]これだけだと微妙ですが、例えば >>> [x*x for x in range(10)] [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] とべき乗のリストを作ってみたり、 >>> [x for x in range(10) if x % 2 == 0] [0, 2, 4, 6
前回のアルゴリズムイントロダクション輪講の話題、単一始点最短路問題から。詳しくは アルゴリズムイントロダクション第24章 単一始点最短路問題 - naoyaのはてなダイアリー へ。その中で丁度前回 書いたプリム法と同じく、ダイクストラ法が最小優先度付きキューを使うので、ちょっといじったらかけるのでは?と思って書いてみました。(相変わらずの乱プログラムご容赦...)。対象のグラフは教科書通り。 実装的には、minheap クラスは前回のプリム法と全く一緒。MinPriorityQueue は前回と使い方が違うので一部実装し直し。(といっても relax の周り)。実行するとこんな感じになるはずです。 s -> y -> t (8) s -> y -> t -> x (9) s -> y (5) s -> y -> z (7) 教科書のヒープソート (6章) にもあったように、優先度付きキュー
[Home] [Setting up Mac OS X] [Python]: [ファイルを読む] 日本語を使う Pythonで日本語を使う Python 2.4以降では、標準で日本語を扱うことができます。 PythonのソースコードをUTF-8で書くには 日本語を扱うPythonのスクリプトの中では、UTF-8の文字コードを使うのが 楽です。 Mac OS Xのターミナルで日本語を扱う場合は、 ここの「4. Terminalの設定を変える」の 指示に従ってください。 以下、ソースコードの簡単な例を示します。 #!/usr/bin/env python # -*- coding: utf-8 -*- import re jtext = u'子猫が隠れんぼをしています' print 'jtext has', len(jtext), 'Japanese characters.' if re.se
If you've ever done any web programming, or even used a web browser, you've almost certainly heard of HTTP cookies. Cookies are basically key-value pairs that a web server can set for a client's web browser. This lets server programs track what pages a user has visited or what actions the user has performed. Cookies are very useful for implementing things like log-in sessions or shopping carts. A
原文:http://python-history.blogspot.com/2009/04/metaclasses-and-extension-classes-aka.html 原文投稿者:Guido van Rossum Pythonの最初の実装では、クラス自身もファーストクラスオブジェクトであり、変数に入れたり、関数の属性に渡したり、他のオブジェクトと同じように扱うことができた。しかし、クラスオブジェクトを作成するプロセスは、石版に刻まれた手順がごとく、変更することはできなかった。具体的に説明すると、以下のようなクラス定義があったとする。 class ClassName(BaseClass, ...): ...メソッド定義... クラスの本体は、新しく作られるローカル辞書の中で実行される。クラス名、ベースクラスが格納されたタプル、そしてこのローカル辞書の3つが内部のクラス作成関数に渡さ
1. type, isinstance 関数で、変数の型を調べる Python で、変数の中身が、どのクラスに所属するのか、または、関数なのか調べたい。 2.1 組み込み関数 によると、 (装飾は、引用者による) type(object) object の型を返します。返される値は型オブジェクトです。 isinstance(object, classinfo) 引数 object が引数 classinfo のインスタンスであるか、 (直接または間接的な) サブクラスのインスタンスの場合に真を返します。 例えば、「数値」の場合、次のようにして、数値に対して type 関数を適用する。 print type(100) #=> <type 'int'> type 関数の結果を用いて、isinstance 関数の引数に指定した。 print isinstance(100, int)
Define and use abstract base classes for interface verification. Why use Abstract Base Classes?¶ Abstract base classes are a form of interface checking more strict than individual hasattr() checks for particular methods. By defining an abstract base class, a common API can be established for a set of subclasses. This capability is especially useful in situations where someone less familiar with th
>>> dic = {'hoge': 123, 'moge': 456} >>> dic['hoge'] 123 >>> dic['h'] = 666 >>> dic {'h': 666, 'moge': 456, 'hoge': 123} >>> del dic['moge'] >>> dic {'h': 666, 'hoge': 123}
Introduction Python 2.4 decorators are an interesting example of why syntactic sugar matters: in principle, their introduction changed nothing, since they do not provide any new functionality which was not already present in the language; in practice, their introduction has significantly changed the way we structure our programs in Python. I believe the change is for the best, and that decorators
Python3には、2系で作られたコードを3用に変換する案をパッチを生成する2to3というコマンドラインツールが付属してます(本体はlib2to3という標準モジュール群)。たとえば、エンコード引数つきのunicode関数でも、そのままエンコード引数が存在しないstr関数に変えるなど、変換も完璧ではないけれど、たいていのコードは3で動くようになります。 しかし、変換してしまうとそのコードは2系では動かなくなります。ということで、2系でも3でも両方で動くようなコードを書くのはどうすればいいか、を考えてみました。 両方で動くようにするには、ない機能を使うわけには行かないので、どうしても共通部分のみでかかざろうえません。なのでお勧めはできないのですけど、一応両方で動かす前提で書くことを考えてみました。 print 関数風にカッコつき呼び出しにする(ただしprintのみの一行で) print(obj
コンテンツへスキップ 登録は無効化されました。
Python 3が後方互換性を捨ててでも求めたもの:よりPythonicなPythonを目指して(前編)(2/2 ページ) 8ビット文字列からユニコード文字列へ Python 3.0での大きな変更点の1つに、文字列型の変更があります。文字列型がユニコードベースに変更されたのです。 Python 2までは、組み込みのデータ型「文字列型(str型)」は単なる8ビットのデータ列でした。文字列型はASCII文字列を扱うには都合が良いのですが、日本語のように多くの文字集合を持つマルチバイト文字を扱うには不便がありました。 例えば、8ビット文字列では複数バイトで構成される文字列の境界を判別する処理などを自前で行わなければなりません。Pythonはもともと欧米で開発された言語で、日本語や中国語のような言語を扱うことは考えられていなかったのです。 Python 1.6および2.0からは、ユニコード文字列型
What is Python? Python is one of the most popular general-purpose programming language which is used for almost all types of projects ranging from web development to mobile app development. Even though the Python Language is among us for the last 30 years, it grew tremendously in popularity in the last few years due to the advancement of Data Science. Why learn Python? Python is one of the popular
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く