2015/09/10 「Ansible 入門 #01 (初心者向け) 」の資料です。 ハンズオンの答え => https://github.com/uorat/ansible-handson.git https://atnd.org/events/68155
lambdaは書いても ifや forは書きたくないあなたに あるリストから、ある条件を満たす最初の要素を取り出したい。例えば、適当に並んだ語のリストから4文字以上の長さを持つ最初のものを取り出したい。きわめて簡潔な記述で。 この瞬間に「4文字以上の語がリストに含まれてない場合どうすんの」って返しがギャバンの蒸着よりも速く出てくるのが正しいプログラマです。「あっ、そんなことは考えもしなかった」っていう人はプログラマに向いてないし、ソフトウェアを設計する仕事にも向いてません(才能的な意味で向いていないというより適切な訓練が足りないというべきですが)。 もしリストに 4文字以上の語が含まれていない場合は Noneを返すことにしましょう。 とはいえ、正しいプログラマの傾向を日常生活に持ち込むと疎まれがちなので注意しましょう。→「ねえ、りんご3個買ってきて〜」「・・・」「どうしたの?」「2個しか売
pipの使い方 (2014/1バージョン)¶ 以前 pipの使い方 と いう記事を書いたのですが、これは2011年の1月と、ちょうど3年前です。これ から随分変わったので、ここでもう一度まとめたいと思います。 pip: http://www.pip-installer.org/ ここで述べているpipのバージョンは1.5です。お使いのpipのバージョンが古い場合は pip install -U pip として、更新してください。 警告 大きな変更点: pip 1.5から"pre"や"b"などがバージョンに付いているパッ ケージはデフォルトで検索やインストールの対象からはずされました。その ため、1.5未満のバージョンのpipでインストールしたパッケージが1.5では 入らない場合があります。 --pre を付けることで、これらのバージョンを入れることができます。
僕の周りだけかもしれないですが、国内のWeb受託開発案件は「PHPで作るのが暗黙のルール」ってな勢いでPHP案件ばっかりなのですが、Python大好きな僕としては、何としてでもPythonを使って仕事をしたい! なので頑張って布教活動をしているのですが、中々良い手応えが得られないのが現状です。。 という訳で、改めてPythonを使うメリットとか、安心してクライアントにPythonを進められる理由なんかをまとめてみました。 技術者がPythonを使うメリット 「今までPHPでやってきて何の問題もなかったし、これからPython始める意味なんてあんの?」 ぶっちゃけ、そんなにないですw 結果的に出来上がる物に関しては大差ないですからね。 ただし、開発効率やメンテナンス性は飛躍的に上がると僕は思います。 ライブラリがとても豊富 PHPも沢山ライブラリありますけど、Pythonだっていっぱいあるん
Python用のWebフレームワークであるBottleと、O/Rマッパーのpeeweeを使って、Python Professional Programmingの2章のゲストブックアプリケーションを作ってみた。 試したバージョンは、Python2.7、Python3.3、Bottle0.11.6、peewee2.1.5。 ソースコード guestbook.py # coding: utf-8 import os from datetime import datetime import peewee from bottle import route, get, post, request, run from bottle import template, static_file, redirect, html_escape BASE_DIR = os.path.dirname(os.path.
はじめに 最近、pythonでHTMLテキストをパースすることが必要になった。当初、HTMLパーサとして、BeautifulSoupを利用していた。しかし、しばしばある特定のWebページのパース時に、HTMLParseErrorという例外が発生した。そのため、他のpython用のHTMLパーサを調べた所、lxmlというものがあることを知った。そこで、このlxmlをWindows環境下でインストールしようとしたのだが、かなり手間取った。 この記事では、Windows環境下で、lxmlのインストーラを使用しないで、lxmlをpythonから利用可能にする手順を説明する。 lxmlのインストールが完了した時点で気付いたのだが、最新でないバージョンのlxmlにはWindows用のインストーラが配布されている。そちらを利用すれば、この記事で説明するような複雑な手順なしにlxmlをインストールできると
みんなのIoT/みんなのPythonの著者。二子玉近く160平米の庭付き一戸建てに嫁/息子/娘/わんこと暮らしてます。月間1000万PV/150万UUのWebサービス運営中。 免責事項 プライバシーポリシー Pythonの生みの親Guidoパパのブログエントリを翻訳してみました。「Why explicit self has to stay - なぜPythonのメソッド引数に明示的にselfと書くのか」。Pythonのメソッド引数に書く「self」はしばしば,他言語からのPython移民を中心に「ウザイ」「キモイ」「消えてなくなれ」と攻撃の対象となることが多いのです。GuidoパパはPythonが生まれて10年,もう何度も似たようなことを聞かされ,そのたびに明快な反論を行ってきました。言語の設計者には,技術的な素養はもちろんのこと,情熱と根気,そして我慢強さが必要なんだなあとつくづく思い知
About Chrome Logger is a Google Chrome extension for debugging server side applications in the Chrome console. Most languages include their own logging capabilities, but sometimes it is easier to see your logs right in the browser. Chrome Logger used to be known as ChromePHP. If you are feeling generous, you can donate to help support development. Usage Using Chrome Logger is simple: Install the C
本気でPythonをやりたいならあわせて読みたい「え?君せっかく Python のバージョン管理に pyenv 使ってるのに Vim の補完はシステムライブラリ参照してるの?」 2013-06-23 21:30 おしりに追記しました 2013-06-24 10:00 設定等微修正しました 2013-06-24 15:20 quickrunの設定を修正しました 2013-07-03 14:30 間違い等を修正しました 様々な開発環境を試してきましたが、結局Vimに落ち着いてしまっているAlisueです、どうも。 Vimを最強のPython IDEにするを書いてからかれこれ二年ほどが経ちます。 二年もあると新しいVimプラグインが増えるなどし、先の記事内容では最強ではなくなってしまいました。なのでこの辺でもう一度現在の最強をまとめてみたいと思います。 基本方針 プラグイン関係はすべてNeoBu
Flask http://flask.pocoo.org/ Pythonの軽量Webフレームワークでは代表格の「Flask」が、最新バージョン0.10で、ついにPython 3に対応した。 Armin Ronacher's Thoughts and Writings - New Werkzeug and Flask Releases (2013/6/13) http://lucumr.pocoo.org/2013/6/13/werkzeug-and-flask-releases/ Flaskの作者、Armin Ronacherのこのエントリによると、Python 2.5はサポートから外れて、そのかわりにPython 3.3に対応した、とのこと。その他にも、変更点が詳しく書かれている。 Pythonの有力なWebフレームワークでは、DjangoとPyramidがすでにPython 3に対応し
Python Package Index - memoize https://pypi.python.org/pypi/memoize/ GitHub - sionide21 / memoize https://github.com/sionide21/memoize 「memoize(メモワイズ)」は、Pythonで「メモ化(memoize / memoization)」の効いたプロパティがかんたんに作れるライブラリ。作者はBen Olive。 ウィキペディア - メモ化 http://ja.wikipedia.org/wiki/%E3%83%A1%E3%83%A2%E5%8C%96 <メモ化(英: Memoization)とは、プログラムの高速化のための最適化技法の一種であり、サブルーチン呼び出しの結果を後で再利用するために保持し、そのサブルーチン(関数)の呼び出し毎の再計算を防ぐ手法
2013-05-31 pip-tools keeps your pinned dependencies fresh. あれです。 べんりなやつです。 pip でモジュールは入れたけど、新しいバージョン出てるのか調べるの面倒ですね。 _人人人人人人人人人人_ > そこで pip-tools <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄ pip install pip-tools すると、pip-review と pip-dump の2つのコマンドが入ります。 ↑こんなイメージ。 pip-review pip-review は、インストール済みのモジュールの更新チェック・更新作業をすることができます。 引数を付けない場合は更新チェックだけ。 $ pip-review Django==1.5.1 is available (you have 1.5b1) Pillow==2.0.0 is avai
はてなブログに移行して最初の記事はやはりPythonネタにしました。 はてなブログいいですね。デザインの編集がやりやすくなったのと、Markdownで書けるのが素晴らしいです。 PyCon 2013の動画を見ていたら、素晴らしい"Transforming Code into Beautiful, Idiomatic Python"という発表を見つけたのでそのまとめです。 今どきのPythonコードのベターな書き方を紹介しています。 Transforming Code into Beautiful, Idiomatic Python ... スライドはこちらにありました 結構長くなってしまったので、知ってる項目は読み飛ばしてもらえばと思います。 ループの基本 整数のループ まずは基本のループ。 Cのfor int i=0; i<6; i++をPythonで単純に書くとこうなります。 for
最近、Mockライブラリ http://www.voidspace.org.uk/python/mock/ を使ってみたのでメモ。 このライブラリは、その性質上、動的にメソッドや属性を作成するケースが多く、普通のPythonライブラリのようにイントロスペクションに頼って使い方を調べるのは難しい。本気で使うならまじめにドキュメントを読み込む必要がある。 関数の置き換え テスト中に呼び出される関数をMockで置き換える例。ここでは、関数 myapp.utils.func1() を置き換える。 from mock import Mock import myapp.utils # myapp.utils.func1 を、常に100を返す関数に置き換える myapp.utils.func1 = Mock(return_value=100) 戻り値が定数でない場合は、Mock()にside_effec
テストを書くときに、外部の HTTP API を叩く処理が組み込まれている場合は、何かしらモックが必要です。 どう書くのがスマートなのか良くわからないので色々試してみる 準備するモノ python 2.7.x mock simplejson requests nose covarage テストのデファクト あまりまとまってるのがないので、まとめておきます。 テストランナーは nose または py.test nose はプラグインがステキ py.test はなにやら色々嬉しい事があるらしい モック/スタブは mock テストは unittest (unittest2) カヴァレッジは covarage ? これは良くわからず、基本 Jenkins に食べさせらるタイプで出力できればおk この辺が今のところデファクトでしょうか、ご意見お待ちしております。 mock patch を使うと綺麗に
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く