Python3 (3.6.5)でオレオレモジュールを作成してインポートしようとした際に結構ハマったのでメモ importの基本 import <module>キーワードでモジュールをインポートする import math print( math.pi ) # => 3.141592653589793 モジュールのメソッドはmodule.methodで実行する from <module> import <method> でインポートするとモジュール名を都度記述しなくてもメソッドの呼び出しができる from math import pi, sqrt print( sqrt(9) ) # => 3.0 from ... import ...でインポートする際にメソッド名が被ると、後からインポートしたものが有効になる from math import pi from my_modules impo
Taking care of business, one python script at a time Introduction It is difficult to write a python script that does not have some interaction with the file system. The activity could be as simple as reading a data file into a pandas DataFrame or as complex as parsing thousands of files in a deeply nested directory structure. Python’s standard library has several helpful functions for these tasks
Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems. Path classes are divided between pure paths, which provide purely computational operations without I/O, and concrete paths, which inherit from pure paths but also provide I/O operations. If you’ve never used this module before or just aren’t sure which cl
はじめにPython3.3 までは、 「あるディレクトリ以下に存在するテキストファイルの一覧を取得して、それぞれを開く」 という処理に、以下の 3 つのライブラリを使う必要がありました。 ファイルパス操作 os.pathファイルの一覧取得 glob.globファイルを開く openしかし、Python3.4 以降であれば、これらを すべて 標準ライブラリpathlibに一任 することができます。 これによって、ファイル操作処理における 書きやすさ・読みやすさが向上 し、それぞれのライブラリの使い方をわざわざ調べる時間や、 ライブラリ間の微妙な仕様の違いに苛まれる心配から解放されます。 今回は、 「../datasets/foo/bar以下に存在するテキストファイルをすべて取得して、内容を表示したい」 という目標に対して、pathlib を利用しない場合、pathlib を利用する場合のコー
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く