Python论坛  - 讨论区

标题:[python-chinese] python 怎样获取文件的物理路径

2006年07月21日 星期五 10:04

鳄鱼 crocodile.liu at 163.com
Fri Jul 21 10:04:14 HKT 2006

在一个文件中,怎样获取这个文件的物理路径?


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

2006年07月21日 星期五 16:26

大熊 bearsprite at gmail.com
Fri Jul 21 16:26:15 HKT 2006

是python脚本中?  print __file__

在06-7-21,鳄鱼 <crocodile.liu at 163.com> 写道:
>
>
> 在一个文件中,怎样获取这个文件的物理路径?
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
茫茫人海,你是我的最爱
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060721/8612e0b3/attachment.htm

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

2006年07月21日 星期五 17:20

鳄鱼 crocodile.liu at 163.com
Fri Jul 21 17:20:24 HKT 2006

 >>> print __file__
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name '__file__' is not defined


大熊 写道:
> 是python脚本中?  print __file__
>
> 在06-7-21,*鳄鱼* < crocodile.liu at 163.com 
> crocodile.liu at 163.com>> 写道:
>
>
>     在一个文件中,怎样获取这个文件的物理路径?
>
>     _______________________________________________
>     python-chinese
>     Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     Subscribe: send subscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Unsubscribe: send unsubscribe
>     to  python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Detail Info: http://python.cn/mailman/listinfo/python-chinese
>     <http://python.cn/mailman/listinfo/python-chinese>
>
>
>
>
> -- 
> 茫茫人海,你是我的最爱
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese



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

2006年07月21日 星期五 18:16

swordsp sparas2006 at gmail.com
Fri Jul 21 18:16:37 HKT 2006

你的问题是"在一个文件中",命令行当然不在文件中了。
你存成test.py运行就知道了。

On 7/21/06, 鳄鱼 <crocodile.liu at 163.com> wrote:
>
>  >>> print __file__
> Traceback (most recent call last):
>   File "", line 1, in ?
> NameError: name '__file__' is not defined
>

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

2006年07月21日 星期五 18:25

IQDoctor huanghao.c at gmail.com
Fri Jul 21 18:25:33 HKT 2006

os.path.abspath()

在 06-7-21,swordsp<sparas2006 at gmail.com> 写道:
> 你的问题是"在一个文件中",命令行当然不在文件中了。
> 你存成test.py运行就知道了。
>
> On 7/21/06, 鳄鱼 <crocodile.liu at 163.com> wrote:
> >
> >  >>> print __file__
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > NameError: name '__file__' is not defined
> >
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
Best regrads,
IQDoctor

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

2006年07月22日 星期六 00:45

Neil chenrong2003 at gmail.com
Sat Jul 22 00:45:40 HKT 2006

print sys.path[0]

这样也可以

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

2006年07月31日 星期一 10:34

fofo qqqeee at gmail.com
Mon Jul 31 10:34:12 HKT 2006

import os
print os.getcwd()

这样也可以

在06-7-22,Neil <chenrong2003 at gmail.com> 写道:
>
> print sys.path[0]
>
> 这样也可以
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060731/6701fe4b/attachment.html

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

2006年07月31日 星期一 10:54

鳄鱼 crocodile.liu at 163.com
Mon Jul 31 10:54:34 HKT 2006

整理一下啦,
import os

print __file__

print os.getcwd()

print os.sys.path[0]


fofo 写道:
> import os
> print os.getcwd()
> 这样也可以
> 在06-7-22,*Neil* <chenrong2003 at gmail.com
> chenrong2003 at gmail.com>> 写道:
>
>     print sys.path[0]
>
>     这样也可以
>
>     _______________________________________________
>     python-chinese
>     Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     Subscribe: send subscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Unsubscribe: send unsubscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Detail Info: http://python.cn/mailman/listinfo/python-chinese
>     <http://python.cn/mailman/listinfo/python-chinese>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese



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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号