Note The SimpleHTTPServer module has been merged into http.server in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3. The SimpleHTTPServer module defines a single class, SimpleHTTPRequestHandler, which is interface-compatible with BaseHTTPServer.BaseHTTPRequestHandler. The SimpleHTTPServer module defines the following class: class SimpleHTTPServer.
こんにちは、初心者です。 適当なニュース記事があったとして、ニュースのカテゴリを推測するみたいな、よくあるやつをやってみました。Python3.3を使いました。 何をやるの? データセットはlivedoorニュースコーパスを使いました。 http://www.rondhuit.com/download.html#ldcc クリエイティブ・コモンズライセンスが適用されるニュース記事だけを集めてるそうです。 トピックニュース、Sports Watch、ITライフハック、家電チャンネル 、MOVIE ENTER、独女通信、エスマックス、livedoor HOMME、Peachy というクラスがあります。 データは、1記事1テキストファイルの形式で、クラス別のディレクトリにいっぱい入っています。 これを学習して、未知の文章に対して、お前は独女通信っぽい、お前は家電チャンネルっぽい、みたいに、分類が
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. 7.9. unicodedata — Unicode Database¶ This module provides access to the Unicode Character Database which defines character properties for all Unicode characters. The data in this database is based on the UnicodeData.txt file version 5.2.0 w
以下の読み込み用テキストファイルを用いて、 text.txt 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 level, I'll be puzzled about what I should do from now on. 以下のメソッドを用いた場合の処理を書いてみます。 read() – ファイルを全て読み込み、その文字列データに対して処理を行う readlines() – ファイルを全て読み込み、1行毎に処理を行う readline() – 1行毎
ファイルの拡張子を取得するには、os.path.splitext(path) を使用します。 import os.path root, ext = os.path.splitext(path) 例 import os.path root, ext = os.path.splitext('C:\\foo\\bar\\test.txt') # root => C:\\foo\\bar\\test # ext => .txt URLでも使えるようです。 import os.path root, ext = os.path.splitext('http://www.example.com/foo/bat/test.txt') # root => http://www.example.com/foo/bat/test # ext => .txt 関連 Python ライブラリリファレンス 6.2 o
PowerShellスクリプティングの第一歩(後編):Windows PowerShellコマンド&スクリプティング入門(3/5 ページ) ここまでは、PowerShellのコマンドレットと演算子のみを利用したコードを紹介してきたが、より複雑なスクリプトを記述するには、条件分岐やループなど、コードの流れを制御するための「制御構文」も必要である。 PowerShellでは、条件分岐構文としてif ~ elseif ~ else、switch ~ case命令、そしてループ構文としてfor、foreach、while、do ~ while命令と、ほかのスクリプト言語でもおなじみの制御構文が一通り提供されている。以下では、これら制御構文の概要と、注意するべきポイントについて解説する。 単純分岐と多岐分岐 まずは、条件分岐構文である。条件を満たした場合にのみ何らかの処理を行いたい、あるいは、A、B
I've successfully converted something of 26 Sep 2012 format to 26-09-2012 using: datetime.strptime(request.POST['sample_date'],'%d %b %Y') However, I don't know how to set the hour and minute of something like the above to 11:59. Does anyone know how to do this? Note, this can be a future date or any random one, not just the current date.
Pythonにはじめて触って、いつのまにか1年が過ぎたのですが、一番はまったのは、やっぱりunicodeの扱いだったと思います。 特に、 UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-12: ordinal not in range(128) のようなエラーにはさんざん悩まされました。ここがたとえばrubyなど他の言語と比べてわかりにくいために、Pythonが取っつきにくい言語になっているのではないか、と個人的には思います。 そこで、このエラーに関係するはまりどころとTipsをいくつか列挙してみました。これからPythonに触れられる方の参考になればと思います。 なお、環境はUNIX上のPython 2.4, 2.5を想定しています。 u1はunicode型で、s1はstr型です。s1にどのよ
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. The datetime module supplies classes for manipulating dates and times in both simple and complex ways. While date and time arithmetic is supported, the focus of the implementation is on efficient attribute extraction for output formatting a
datetime → 書式化文字列 >>> import datetime >>> now = datetime.datetime.now() >>> now.strftime("%Y/%m/%d %H:%M:%S") '2012/01/01 20:29:39' もしくは、新しい形式のformat関数を使ってもできる。 >>> "{0:%Y-%m-%d %H:%M:%S}".format(now) '2012-10-07 08:15:03' Python3.6以降からはフォーマット済み文字列リテラル(f-string)が使用可能なので、それを使うともっとかんたんにかける。 >>> f"{now:%Y-%m-%d %H:%M:%S}" '2012-10-07 08:15:03' その逆。書式化された日付文字列 → datetime >>> import datetime >>> dateti
1. マップ型を実装した辞書 Python において、ハッシュに相当するものはマップ型と呼ばれる。 2.3.8 マップ型 によると、 現在のところは標準のマップ型、dictionary だけです。 インターフェスがマップ型で、その実装が辞書。 ただし、Python ではインターフェイスと言わずに、プロトコルと呼ぶ。 cf. 6.4 マップ型プロトコル (mapping protocol) 2.3.8 マップ型に定義されているメソッドを適当に分類しておく。 最初にマップ型のオブジェクトを作成する。 # 辞書: key は変更不能でなければならない。 persons = {"Tarou" : 20, "Hanako" : 15, "Jiro" : 30} 2. 基本的な操作 # 要素の値をキーで取得 print persons['Hanako'] # 要素の追加 persons['Saburo
前にPythonの勉強を軽くしたものの、短期間で基本的な部分だけをサラッとやったために時間が経ったら忘れてしまってました。 で、久々に何となく書きつつ、 「あ、pythonはeqとかなくて判断する時は==一種類でいいんだったっけ。」 とかうろ覚えのままif文書いてたので if data == None: print 'OK' みたいな文を書いてたんだけど、他の人のコード見てたら if data is None: print 'OK' ってのが出てきて、 「あー!isとかあるんだっけ!」 となり、data == Noneって書き方が間違ってるのかどうか確かめることに。 結果は間違ってるみたいですね。Noneの比較はisを使いましょうと書いてありました。 isと==じゃググっても上手くヒットしなかったんですが、何とかJared Grubb: Python: "is None" vs "==No
Perlではハッシュから存在しないキーで値を取り出そうとするとundefが返ってくる。それを評価してプログラムを書いても動く。 $ perl -w %hash = (foo => 'hoge', bar => 'fuga'); print $hash{baz} ? "あるよ!\n" : "ないよ!\n" ^D ないよ! Pythonの場合、存在しないキーで値を取り出そうとした瞬間にエラーが発生してしまう。 >>> hash = {'spam': 'hoge', 'ham': 'fuga'} >>> print 'あるよ!' if hash['eggs'] else 'ないよ!' Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'eggs' ので、"has_key()"関数で辞書
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く