最近「あー、このディレクトリのファイルをブラウザで開きたいなぁ*1」という時に、 $ python -m SimpleHTTPServer 8080 で簡易HTTPサーバーを起動できることを知り重宝している。8080はポート番号。当然のことながら、この簡易HTTPサーバーで全世界に向けて配信しちゃ駄目ですよ!
出力値をHTMLエスケープする ただし、aタグの使用は許可する aタグであっても、href属性以外の属性は除去する href属性であってもhttp, https以外のプロトコルは除去するという処理を行う必要があり自前でコードを書いてみたのだが、予想通り大変だった。有効なテストケースが思い浮かばないので不安一杯。やはり定評のあるライブラリを使った方がいいだろうか。BeautifulSoupでもlxmlでも上記の要件を満たす処理は書けるが、この場合、html5libのHTMLSanitilizerを使うとよさげ。 html5lib http://code.google.com/p/html5lib/HTML5をうたっているが、ブログ記事に一部のタグ/CSSを許可するといった用途ならば、特にHTML5ということを気にせずに使えると思う。基本的な使い方はドキュメントにある通り。非常に洗練されたAP
Welcome to Fabric’s documentation!¶ This site covers Fabric’s usage & API documentation. For basic info on what Fabric is, including its public changelog & how the project is maintained, please see the main project website. Getting started¶ Many core ideas & API calls are explained in the tutorial/getting-started document:
Ok so I can use an OrderedDict in json.dump. That is, an OrderedDict can be used as an input to JSON. But can it be used as an output? If so how? In my case I'd like to load into an OrderedDict so I can keep the order of the keys in the file. If not, is there some kind of workaround?
Python 3.1/2.7のcollections.OrderedDictやodictをYAMLに変換したい時、 import yaml o = OrderedDict() o['spam'] = 1 o['egg'] = 2 o['ham'] = 3 print yaml.dump(o, default_flow_style=False) で期待する結果は、 !!python/object/apply:collections.OrderedDict - - - spam - 1 - - egg - 2 - - ham - 3 ではなく、 spam: 1 egg: 2 ham: 3 だと思う。それには yaml.add_representer でOrderedDictの変換方法を定義してやればよい。逆に、YAMLのmappingを常にOrderedDictとして扱いたい場合には、yaml
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()
概要¶ これは Google Python Style Guide Revision 2.29 を日本語に訳したものです。 本家ガイドは CC-By 3.0 ライセンス の基で公開されています。また、本ガイドも同ライセンスを継承します。 本家ガイドの著者は以下の通りです。 Amit Patel Antoine Picard Eugene Jhong Jeremy Hylton Matt Smart Mike Shields また、本ガイドの翻訳者は以下の通りです。 Kosei Kitahara 本ガイドに誤植、誤訳があった場合は issue で教えてください。 その他本ガイドに関する問い合わせは、サイト最下部に記載のメールアドレスか @Surgo にお願いします。 はじめに¶ Python は Google で使われている主要なスクリプト言語です。 このスタイルガイドは Python によ
Template Designer Documentation¶ This document describes the syntax and semantics of the template engine and will be most useful as reference to those creating Jinja templates. As the template engine is very flexible, the configuration from the application can be slightly different from the code presented here in terms of delimiters and behavior of undefined values. Synopsis¶ A Jinja template is s
大規模ウェブサービスのプラクティスを紹介している、High Scalability の記事「15 Ways To Make Your Application Feel More Responsive Under Google App Engine」を訳しました。 記事は Java 前提で、私は Python で Google App Engine を使っているのですが、それでも面白いなと思ったので、有効な方法は使っていこうとしています。ついでなので翻訳したものを残しておくことにしました。 軽量な査定用フィードバックサービスを提供している Small Improvements が、Performance issues on GAE, and how we resolved them という素晴らしい記事を書いている。どのようにして、ほとんどのリクエストを 300ms から 800ms でさば
Switching From Other Template Engines¶ This is a brief guide on some of the differences between Jinja syntax and other template languages. See Template Designer Documentation for a comprehensive guide to Jinja syntax and features. Django¶ If you have previously worked with Django templates, you should find Jinja very familiar. Many of the syntax elements look and work the same. However, Jinja prov
This document is for an old version of Python that is no longer supported. You should upgrade and read the Python documentation for the current stable release. 8.18. pprint — Data pretty printer¶ Source code: Lib/pprint.py The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter. If the formatted structures i
本マークアップ記法の完全な詳細は reStructuredText のページに示されています。このテキストは、覚書としての性格の文書です。 "(詳細)" というリンクを辿ると reStructuredText 仕様書を参照できます。 ただし、相対リンクとなっていますので、リンク切れの場合は、 原版の "Quick reStructuredText" から参照してください。 目次 インライン マークアップ バックスラッシュによるエスケープ 章立ての構造 段落 記号つきリスト 番号つきリスト 定義リスト フィールドリスト オプションリスト 整形済みブロック ラインブロック 引用 Doctestブロック 表 区切り線 明示的マークアップ 脚注 出典 リンクターゲット 外部ターゲット 内部ターゲット 間接ターゲット 暗黙ターゲット ディレクティブ 代入参照とその定義 コメント 助けを得たい場合は
このページは、Rubyレシピブック (詳細) をPythonで書こうというたくらみです。内容は当たり前のことばかりですが、たまにしかコードを書かない人間は、こうしたことがわからなくてイライラしてしまいます。10行くらいのプログラムならさっと見てさっとかけるようにするのが目標です。 2008年1月21日19:00 ロボットによる荒らし対策を施しました。 レシピブック作成にご協力いただける方がいらっしゃいましたら、最初にユーザー登録をお願いします。 レシピブックを修正する際は、一度ログインをしてください。ログインすると右肩の部分に編集の項目が現れます。 記述方法は、structuredText もしくはreStructuredText でお願いできればと思います。 WEB上の情報 Python クイックリファレンス日本語訳 pythonライブラリリファレンス pythonチュートリアル Per
Welcome¶ Passlib is a password hashing library for Python 2 & 3, which provides cross-platform implementations of over 30 password hashing algorithms, as well as a framework for managing existing password hashes. It’s designed to be useful for a wide range of tasks, from verifying a hash found in /etc/shadow, to providing full-strength password hashing for multi-user application. As a quick sample
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く