Python论坛  - 讨论区

标题:[python-chinese] How execute a .py in this way?

2005年07月04日 星期一 00:55

Peter Cai newptcai at gmail.com
Mon Jul 4 00:55:45 HKT 2005

If it's a executable file, a ".exe" file, you can launch it in this
way, "xxx.exe < input.txt". The text file "input.txt" will be
considered as the standard input.

But when I use this trick on python, it doesn't work. The only way to
do so is like this "python xxx.py < input.txt". But this method has a
problem, that you have to include the full path of "xxx.py" unless
it's in your current folder even if "xxx.py" is in a folder which has
been include in the eviorment variable "path" on windows. Thus, you
can execute you "py" program anywhere by using the command "xxx.py",
but when you want to use an exsiting file as it's input, you have to
use something like "pythong xxx.py < input.txt".

It's very inconvenient as I tried to make my python programs cowork with vim.

Sorry for my poor english!

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年07月04日 星期一 02:03

ChunLinZhang zhangcl at smmail.cn
Mon Jul 4 02:03:05 HKT 2005

please put #!/usr/bin/env python in the first line

and if you want to take input.txt as the argument, you can refer it at the
program as sys.argv[1]

----- Original Message ----- 
From: "Peter Cai" <newptcai at gmail.com>
To: <python-chinese at lists.python.cn>
Sent: Monday, July 04, 2005 12:55 AM
Subject: [python-chinese] How execute a .py in this way?


If it's a executable file, a ".exe" file, you can launch it in this
way, "xxx.exe < input.txt". The text file "input.txt" will be
considered as the standard input.

But when I use this trick on python, it doesn't work. The only way to
do so is like this "python xxx.py < input.txt". But this method has a
problem, that you have to include the full path of "xxx.py" unless
it's in your current folder even if "xxx.py" is in a folder which has
been include in the eviorment variable "path" on windows. Thus, you
can execute you "py" program anywhere by using the command "xxx.py",
but when you want to use an exsiting file as it's input, you have to
use something like "pythong xxx.py < input.txt".

It's very inconvenient as I tried to make my python programs cowork with
vim.

Sorry for my poor english!
_______________________________________________
python-chinese list
python-chinese at lists.python.cn
http://python.cn/mailman/listinfo/python-chinese


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号