タグ

pythonに関するkotaro-onoのブックマーク (47)

  • How do I install pip on Windows?

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams Collectives™ on Stack Overflow Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives

    How do I install pip on Windows?
  • EmacsWiki: Python Programming In Emacs

    This page collects information for creating a usable Python programming environment in Emacs. Quick startThe quickest way to start is just to open a Python file in Emacs – ‘python-mode’ has a nice feature-set as is – see below for details. Beyond that, as people ask for recommendations fairly often, the following is a reasonable approach: If you already use one of the StarterKits like Spacemacs or

  • python pexpectによるcisco / juniperのCLI automation - 技術メモ

    コンフィグバックアップだけではないマルチパーパス・スクリプト expectライクなpython pexpectで、cisco / juniper 機器のログ採取と設定変更機能を兼ねたwrapperモジュール(pexpect_wrapper.py)を書いてみた(Linux上のpython2.7, pexpect4.0.1環境で確認)。 telnet及びssh対応。また、username: を聞いてきたり、聞いてこなかったり、の応答の違いも自動処理。 IOSの場合、"[confirm]"の文字列に対してEnterで自動応答(ただし、clear系コマンドのみ対象とし、reloadの自動応答は排除)。 JUNOSの場合、コマンドのtypoが発生すると、正規表現によるprompt待ちを狂わせる。typoを検知したらCTRL+Uを送信し、誤ったコマンドの履歴をクリアしてprompt待ちを正常化すること

    python pexpectによるcisco / juniperのCLI automation - 技術メモ
  • VIRTUALENV について

    Python中心に、日々発生する疑問点や解決策を記録していきます。 内容が間違っていたらゴメンね。 ( このブログは目次を用意しています。記事をお探しの際は、ご利用ください。 ) 今回、virtualenv について簡単に触れてみようと思います。 virtualenv については、既にサイトやブログで紹介しているところが多い。私も幾つかの記事を読んでみたが、「どうもイマイチわからない」 という状態だった。 しかし実際に使ってみると、かなり便利だということがわかってきた。このため、『メモ書き+α』 レベルで virtualenv について書いてみる。 virtualenv の機能 virtualenv は Python の仮想環境を提供する。こう書くと、 「あれ、Python の環境自体が仮想ではないの?」 と思う人がいるかもしれない。実は私もそう思いました・・・。 もう少し付け足して書くと

    VIRTUALENV について
    kotaro-ono
    kotaro-ono 2013/09/06
    virtualenv
  • Vimを最強のPython開発環境にする2 - Λlisue's blog

    気で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

    Vimを最強のPython開発環境にする2 - Λlisue's blog
  • Python Exception Handling Techniques

    Open Source Developer, Author, Editor. There’s always room for pie. Error reporting and processing through exceptions is one of Python’s key features. Care must be taken when handling exceptions to ensure proper application cleanup while maintaining useful error reporting. Error reporting and processing through exceptions is one of Python’s key features. Unlike C, where the common way to report er

    Python Exception Handling Techniques
    kotaro-ono
    kotaro-ono 2012/11/27
    Exception Handling Cool Example.
  • Python Basics: Basics of Python Programming

    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

    Python Basics: Basics of Python Programming
    kotaro-ono
    kotaro-ono 2012/10/29
    "with" statement, good usage.
  • How to Write a Spelling Corrector

    One week in 2007, two friends (Dean and Bill) independently told me they were amazed at Google's spelling correction. Type in a search like [speling] and Google instantly comes back with Showing results for: spelling. I thought Dean and Bill, being highly accomplished engineers and mathematicians, would have good intuitions about how this process works. But they didn't, and come to think of it, wh

    kotaro-ono
    kotaro-ono 2012/10/26
    語句補正の実装
  • Python でマルチスレッドプログラミング - trial and error

    こんにちは。 最近いろいろごたついてて、ブログなんか更新してませんが、それなりに充実した生活を送っているのでご心配なくw ところで、今日はいつもどおり Python の話題です。 いま、某 LUG であるプログラムを作っているのですが、その中でマルチスレッドを使えたらなーと思って、ちょっといじってみました。 マルチスレッドが使えると...: 複数の作業を並列して実行できる 一定間隔で何かを実行するような処理を簡単にできて便利。 CPU を有効的に使える などいろいろ利点がありますが、今回は主に 2 番目のものをターゲットにしてみました。 結局、1番目も関わってくるんですけどね。 Python でスレッドを生成するには、threading モジュールを使うのが便利です。 http://www.python.jp/doc/release/lib/module-threading.html こい

    kotaro-ono
    kotaro-ono 2012/10/11
    マルチスレッドのサンプル
  • pexpect - ぱいそにすたん!

    pexpect.py だけ持ち込めば使える pexpect はとても便利. python でごりごりコードが書ける分だけ expect よりも便利! デプロイ、ログ収集と大活躍. 以下、ssh でログインして uname -r の結果だけを拾ってくる例. from sys import stdout, stderr from getpass import getpass from pexpect import spawn, EOF host = raw_input("server: ") id = raw_input("id: ") pw = getpass("%s's password: " % id) c = spawn('ssh %s@%s' % (id, host)) #c.logfile = stderr i = c.expect_exact(['yes', 'assword:

    pexpect - ぱいそにすたん!
    kotaro-ono
    kotaro-ono 2012/08/27
    pexpect の使用例
  • Tkinter 入門: 1. Hello World!

    1. Hello world! 1. 初めに Tkinter は Python の標準的な GUI(Graphic User Interface) ツールです。Python は人気のある言語なので、 GUI Tool としては Tkinter のほかに wxPython, Qt, GTK などがありますが、Tkinter が一番 こなれている感じです。つまり、 動作が安定している。 起動が早い。 プログラムが短くてすむ。 の3つが特徴として挙げられると思います。 Tkinter のチュートリアル はすでにかなり存在しているのですが、Tk が巨大なシステムということも有り、 全てをカバーしたものはありません。この一連の文書では、他のチュートリアルがあまり取り上げていない話題を 中心に取り上げたいと思います。特に、widget を変化させることは他のチュートリアルで取り上げられていないので、

    kotaro-ono
    kotaro-ono 2012/06/17
    Tkinter の使い方がわかりやすい。
  • Learn Python The Hard Way

    The type for this book is set in 18px / 1.5 Adobe Serif, Sans, and Code. Buy Learn Python the Hard Way, 5th Edition When you buy Learn Python the Hard Way, 5th Edition directly from the author, Zed A. Shaw, you'll get access to the digital content for all 60 exercises, plus all 60+ videos that are normally sold separately. You'll also have access to direct help from Zed via Discord chat and live s

    kotaro-ono
    kotaro-ono 2012/03/14
    Pythonの基礎。全部英語。。
  • subprocess – プロセスを生成して連携する - Python Module of the Week

    subprocess モジュールは新しくプロセスを生成して、そのプロセスを扱う一貫したインタフェースを提供します。それは従来からある他のモジュールよりも高レベルなインタフェースを提供します。そして os.system(), os.spawn*(), os.popen*(), popen2.*() や commands.*() のような従来の関数の置き換えを目的としています。 subprocess モジュールと他のモジュールとの比較を分かり易くするために os や popen を使用したサンプルを再作成して紹介します。 subprocess モジュールは Popen とそのクラスを使用する複数のラッパ関数を定義します。 Popen のコンストラクタは新たなプロセス生成を簡単にする複数の引数を受け取り、パイプを経由してその親プロセスと通信します。それは他のモジュールの置き換えられる全ての機能や

    kotaro-ono
    kotaro-ono 2012/03/07
    subprocess モジュールの用法
  • Python標準ライブライリを使い倒す(logging編) - HDEラボ

    Javaにはlog4j、.NETにはlog4netがあるように当然Pythonにもログ機能(以下からloggingとします。)は存在しますが、Pythonの場合は標準ライブラリにすでに組み込まれています。 今回はその機能を使用したサンプルを紹介します。 loggingではいくつかのログ出力方式を指定することが可能ですが、今回はログファイルのサイズ指定とローテート指定の行える「RotatingFileHandler」を使用してサンプルを作成します。 その他のログ出力方式は、Python用ロギング機能 を参照してみてください。 今回は、ログ出力用のプログラムファイル(log.py)と設定ファイル(log.conf)を作成します。 注) 設定ファイルを使用せずにプログラムファイルで設定を行うことも可能ですが、一般的にログ設定ファイルを作成しますので今回は設定ファイルを作成します。 また、logg

    kotaro-ono
    kotaro-ono 2012/03/02
    logging モジュール使い方
  • Pythonの勉強をまったく始められないあなたと私に送る8つのタスク

    Google App EngineでのPythonの勉強と開発は進んでいますか? GAEでPythonを始めるときに知りたい4つのまとめ これを書いた人はというと…まったく進んでいません。 Learn Python The Hard Wayを少し読んだ程度です。 言い訳なんていくらでも出来ますね。 えーっと、仕事が忙しいから、仕事が忙しいから、そして仕事が忙しいから。 しっかり、仕事以外の勉強の時間を取ってやらないと、あっと言う間に置いてかれます。 そして、”新しいことを学ぶ”というのは日々のモチベーションに繋がりますから。 前置きはここまでにして、今日はタイトル通り、 Pythonの勉強をまったく始められないあなたと私に送る8つのタスク を紹介します。 もし、タイトルに期待して、”これさえやればPythonマスターになれる!”と思ってきた方にはごめんなさい。 99%は”Pyt

    kotaro-ono
    kotaro-ono 2012/02/28
    3月内に必ずやりきる!
  • 参考サイト - Pythonのお勉強

    参考になるサイト 全般的なリファレンス、チュートリアル Pythonドキュメント日語翻訳プロジェクト 公式ドキュメントの和訳。3.xと2.x、その他旧バージョン。 インスタント・ハッキング プログラミング経験のない人へ向けた、プログラミング入門用の文章です。変数や条件判断(if-else)、繰り返し(for,while)、関数など、プログラミングの基礎となる知識を学びます。 Python 2.5 Quick Reference Python 2.4 クイックリファレンス Python 2.4 Quick Referenceの翻訳です。 Python 早めぐり Pythonの概要をトップダウンで説明。python の起動方法、スクリプトの書式について説明etcetc。全体像から説明するので、飽きたところでやめられるという利点があります。 Pythonハンディマニュアル クイックリファレンス

    kotaro-ono
    kotaro-ono 2012/02/28
    Pythonのサンプルコードが沢山やでー
  • PythonDecoratorLibrary - Python Wiki

    This page is meant to be a central repository of decorator code pieces, whether useful or not <wink>. It is NOT a page to discuss decorator syntax! Feel free to add your suggestions. Please make sure example code conforms with PEP 8. Creating Well-Behaved Decorators / "Decorator decorator" Note: This is only one recipe. Others include inheritance from a standard decorator (link?), the functools @w

    kotaro-ono
    kotaro-ono 2012/02/24
    Decoratorの公式サンプル。参考になる。
  • ホーム - The Django Book (日本語)

    The Django Book Pythonで書かれているDjango Web framework (日語サイト)に関するをオンラインで公開しています。 このはThe Django BooksがGNU Free Documentation Licenseで無料で公開しているを日語訳として派生したものです。 ライセンスは家のを継承しているため、GNU Free Documentation Licenseです。 現在は以下の3つのがあります(上2つは家サイトへのリンクしています): 1st edition: Apress 出版。Django 0.96対応 (Django 1.0 非対応!) (家サイト:英語)。 1st edition: 無料オンライン。内容は上記出版と同一。Django 0.96対応 (Django 1.0 非対応!) (家サイト:英語)。 NEW:

    kotaro-ono
    kotaro-ono 2012/02/23
    Django日本語訳
  • What are common uses of Python decorators?

    Answer (1 of 36): The short answer is that they help to make our code shorter and clean to look at. They make it easy to control/alter behaviour of other functions with decorators, as they treat functions as objects and allow calling other functions inside a function. This can be achieved otherwi...

    What are common uses of Python decorators?
    kotaro-ono
    kotaro-ono 2012/02/20
    Decoratorの使い方の例
  • pipの使い方 - そこはかとなく書くよ。

    注意 この内容はすでに古くなっています。 pipの使い方 (2014/1バージョン) を参照してください。 pipとは、Pythonにおけるパッケージ管理システムです。easy_installというツールもあるのですが、pipはこのeasy_installを置き換えるものとして開発されています。rubyのgemperlのcpan的な位置づけです。 同じパッケージ管理ツールとしてsetuptools置き換えのdistributeというものもあるのですが、こちらはsetuptools全体を置き換えるものとして開発されており、pipはsetuptoolsの一部であるeasy_installを置き換える形です。 なお、現在のpipのバージョンは0.8.2で、このエントリはこのバージョンを使っています。 なにかおかしい点があれば、ご指摘ください。 > 識者の方々 pipのinstall まずはea

    pipの使い方 - そこはかとなく書くよ。
    kotaro-ono
    kotaro-ono 2012/02/10
    pipの使い方まとめ