x or y x または y の少なくともどちらか 1 つが True なら True それ以外は False x and y x と y がどちらも True なら True それ以外は False not x x が True なら False、 x が False なら True

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. 10.1. os.path — Common pathname manipulations¶ This module implements some useful functions on pathnames. To read or write files see open(), and for accessing the filesystem see the os module. Note On Windows, many of these functions do not
Pythonの文字列置換は、置換の仕方やバージョンによって利用すべきモジュールが異なっており、少しわかりにくいので、Python 2.xでのstrとunicode、3.xでのstrでの置換をまとめます。 文字列による単純な置換 (str.replace) str (2.x) / unicode / str (3.x)のどれでもほぼ同じです。 src = 'I like orange.' dst = src.replace('orange', 'apple') # 'I like apple.' str.replaceの第3引数で置換を行う最大回数を指定できます。 str.replace (2.x) str.replace (3.x) 正規表現による置換 (re.sub) str (2.x) / unicode / str (3.x)のどれでもほぼ同じです。 import re src =
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. Is there a source code level debugger with breakpoints, single-stepping, etc.?¶ Yes. The pdb module is a simple but adequate console-mode debugger for Python. It is part of the standard Python library, and is documented in the Library Refer
コマンドラインで与える引数によってプログラムの挙動を変えたいという場面はよくあります。Python ではコマンドライン引数は sys モジュールの argv 属性に文字列を要素とするリストとして格納されています。そして、リストの先頭要素(sys.argv[0])はスクリプトファイル名となっています。 ソースコード # coding: Shift_JIS import sys # モジュール属性 argv を取得するため argvs = sys.argv # コマンドライン引数を格納したリストの取得 argc = len(argvs) # 引数の個数 # デバッグプリント print argvs print argc print if (argc != 2): # 引数が足りない場合は、その旨を表示 print 'Usage: # python %s filename' % argvs[0]
I am trying to run a program to make some system calls inside Python code using subprocess.call() which throws the following error: Traceback (most recent call last): File "<console>", line 1, in <module> File "/usr/lib/python2.7/subprocess.py", line 493, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) File "/usr/l
Python中心に、日々発生する疑問点や解決策を記録していきます。 内容が間違っていたらゴメンね。 ( このブログは目次を用意しています。記事をお探しの際は、ご利用ください。 ) Pythonを使い始めた頃、Path設定がよくわからなかった。 あるモジュールをインポートして使いたいのだけど、使えない。どうもPathが通っていないようだという事はわかったのだが、Pathと言えばWindowsだと思っていたのでWindows設定を変更していた。でも動かない・・・。 実はPythonの実行マシン内にPath設定を持っていたのでした(笑)。 Path設定について以下、メモ書きします。 Pathの確認とテンポラリなPathの変更 ■ Pathの確認 import sys sys.path 結果確認 >>> import sys >>> sys.path ['', 'C:\\Windows\\syst
I have a Jenkins server running Ubuntu which has been running perfectly fine for as long as I've been using it, and in one of the jobs, it runs a few things under the shiningpanda plugin (a python virtual environment wrapper). At some point today, or over the weekend, the job that uses it started failing, with the main error seemingly being the title, full error reported is > pip install Jinja2 Wh
プログラミング言語 Python の入門書などでは文字コードの変換において Shift_JIS (sjis) に変換するように書いてあることが多いように思う。 その落とし穴について変換例として「高橋大輔 (フィギュアスケート選手)」を例にして試してみる。 main.py ※コードを直接ブログに記載したら文字化けしてしまったので画像にした しかしこのコードはエラーを引き起こす。Shift_JIS のコードに含まれない文字が含まれているからだ。 実行結果 C:\WINDOWS\system32\cmd.exe /c python main.py Traceback (most recent call last): File "main.py", line 3, in <module> b = a.encode('sjis') UnicodeEncodeError: 'shift_jis' co
Windowsで、ちょっとした HTMLファイルの見栄えをブラウザでチェックしたい場合、わざわざ Apacheが起動した物理サーバや仮想マシンにファイルを転送したり、XAMPP を起動するまでもないんだよなぁ、というケースがありますよね。 実は、そういったニーズに簡単に応えることができんです。そう、Pythonならね。 今回はそういう話です(HTMLビューアを使えばいいって話でもありますが。。)。 SimpleHTTPServer を起動 こっからが本番。 例えば、「C:\temp\」に以下のような index.html を置いておきます。 index.html <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>Font Awesome Test</title> <link rel="styleshe
LinkChecker 8.4をインストールするのに、Python 2.6系ではなく Python 2.7系が必要だったため、やっとの思いでインストール。LinkChecker は「sudo /usr/local/bin/python2.7 setup.py install」とすればよかったようなので、Pythonは単にaltinstallするだけで良かったかも知れない...。 手順 参考 CentOS 6.2 に Python 2.7.2をインストールする http://wasure-memo.h-tsk.com/2012/03/centos-62-python-272.html How to install Python 2.7 and 3.3 on CentOS 6 http://toomuchdata.com/2012/06/25/how-to-install-python-2-7
テキストファイルへの書き込み処理はFileオブジェクトの以下のメソッドを用いる。 write() – 文字列を引数に取り、ファイルに書き込む。 writelines() – シーケンス型を引数に取り、ファイルに書き込む。 write() – 文字列を引数に取り、ファイルに書き込む ソースコード #!/usr/bin/python # coding: UTF-8 # 書き込む文字列 str1 = """It is meaningless only to think my long further aims idly. It is important to set my aims but at the same time I should confirm my present condition. Unless I set the standard where I am in any leve
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く