ラベル Python の投稿を表示しています。 すべての投稿を表示
ラベル Python の投稿を表示しています。 すべての投稿を表示

2008/04/27

pwd, cd, ls in Python


PythonのIDLEでcshのpwd, cd, lsに相当するコマンドが判明しました。
まずおまじないとして,
from os import *
getcwd() ==> pwd
chdir("..") ==> cd ..
listdir (".") ==> ls

osモジュールの中の関数名を調べるコマンドは
dir (os)

ここまで分かれば、後はなんとかなりそうです。

I got Python command same function as pwd, cd, ls of csh.
from os import *
getcwd() ==> pwd
chdir("..") ==> cd ..
listdir (".") ==> ls

dir(os) shows all fucntions in os module. This enable me to find csh equivalent commands.

cd and ls command in Python IDLE


PythonのGUIであるIDLEの中でPythonのプログラムを実行するために、フォルダーを変えて、ファイルを探そうとしたのですが、うまくいきません。WindowsのIDLEの中では次のようなコマンドは使えません。
cd
ls
dir
import os
os.system("dir")

一時間ほど調べたのですが、Webには何も出ていません。結局IDLEのプルダウンメニューを使う以外の方法はないというのが、今日のところの結論です。
IDLE --> File --> Open でソースファイルを開く
Run --> Run Module F5

I cannot use Windows system commands such as cd, ls, dir to look for and run a Python source file . import os, os.system("dir") also cannot be used because a DOS window is opend and closed immdiately after the command finished.

After around an hour, I found I should use IDLE pull down menu to do this. It's easy.
IDLE --> File --> Open
Run --> Run Module F5

2008/04/26

Use Phyton as calculator


Pythonはインタープリタですので簡単な電卓としても使えますが、複素数も扱えるそうです。

Python is an interpreter. It can be used as a simple calculator which can handle complex.

Python document


パイソン2.5.2には日本語のドキュメントは付属していませんが、パイソン2.3.4jp(python234jp-20040927.exe)には日本語のドキュメント(Python234jp.chm)が付いていますので、python234jpをインストールするのも良いアイデアです。異なるバージョンのパイソンはうまく共存できるようです。

Python 2.5.2 doesn't include Japanese document. But, Python 2.3.4jp (python234jp-20040927.exe) includes Japanese document. I installed this just to get the document.