Tag Archives: Python

Magic Workstation にインポートするオリジナルカードの作成スクリプト

Magic Workstation(MWS)という対戦カードゲームMagic: The Gatheringが出来るソフトがありますが、その機能の一つにオリジナルカードのインポート機能があります。カードの作成方法はテキスト … Continue reading

Posted in Python | Tagged , , , , | 1 Comment

Python: 可変個の引数を受け取る関数

ソースコード #!/usr/bin/python # coding: UTF-8 # 可変個の引数を受け取る関数 # 引数の前に*を付けると、関数内ではタプルとして受け取る def sigma_sq(*nums): # … Continue reading

Posted in Python | Tagged | 1 Comment

Python: CSVファイルに書き込み – csv.writerオブジェクト

試しにチャット履歴をCSVファイルに保存するという場合の例を取り上げます。まぁ実際はメッセンジャーアプリのXMLファイル等をコンバートして保存する例を持ってきた方が良いのかもしれませんが、そうするとコードが長くなり今記事 … Continue reading

Posted in Python | Tagged , , , | 2 Comments

Python: CSVファイルの読み込み – csv.readerオブジェクト

ソースコード #!/usr/bin/python # coding: UTF-8 # CSVファイルの読み込み import csv filename = “table01.csv” csvfile = open(fil … Continue reading

Posted in Python | Tagged , , , | 3 Comments

Python: リスト内包表記(リストコンプリヘンション)をfor文に書き換える

リスト内包表記を知ることでコードのリーディングとライティングを早めることが出来ます(パフォーマンスもfor文より良いです)。そこでリスト内包表記とfor文の書き換え方を以下に紹介。 ソースコード #!/usr/bin/p … Continue reading

Posted in Python | Tagged , , | Leave a comment

Python: lxmlのインストール方法

lxml とはXMLやHTMLを扱うPythonのライブラリの一つです。 lxml is the most feature-rich and easy-to-use library for working with XM … Continue reading

Posted in Python | Tagged , , , | Leave a comment

Python: リストの要素の追加と削除、取出し – append()、extend()、pop()、remove()メソッド

ソースコード #!/usr/bin/python # coding: UTF-8 # リストの要素の追加と削除(取出し) | append()、extend()、pop()、remove()メソッドの使い方 a = [3 … Continue reading

Posted in Python | Tagged , , | Leave a comment

Python: モジュールにテスト関数を定義 – 重複のない乱数(整数MIN以上MAX以下)の生成

ソースコード #!/usr/bin/python # coding: UTF-8 import random def make_randint_list(min, max, cnt, sortflag=False, re … Continue reading

Posted in Python | Tagged , , , , | Leave a comment

Python: 乱数の生成 – random()、randint()、uniform()、seed()メソッド

ソースコード #!/usr/bin/python # coding: UTF-8 # 乱数の生成 | random()、randint()、uniform()、seed()メソッドの使い方 import random # … Continue reading

Posted in Python | Tagged , , , | 3 Comments

Python: テキストファイルの読み込み – read()、readlines()、readline()メソッド

以下の読み込み用テキストファイルを用いて、 text.txt It is meaningless only to think my long further aims idly. It is important to s … Continue reading

Posted in Python | Tagged , , | 2 Comments