[python-chinese] 路径问题

jinq0123在163.com jinq0123在163.com
星期五 八月 3 10:21:04 HKT 2007


Python 获取程序所在目录
<http://blog.csdn.net/jq0123/archive/2007/07/17/1694893.aspx>
http://blog.csdn.net/jq0123/archive/2007/07/17/1694893.aspx

解决__file__或sys.argv[0]在py2exe下失效的问题。

greenpean wrote:
> os.path.dirname(sys.argv[0])
> ------------------------------------------------------------------------
> ado
> 2007-07-30
> ------------------------------------------------------------------------
> *发件人:* 侯华隆
> *发送时间:* 2007-07-30 18:44:45
> *收件人:* python-chinese在lists.python.cn
> *抄送:*
> *主题:* [python-chinese]路径问题
> 写好的一段程序,涉及到文件读取
> #-------------test.py------------#
> filename = 'xxx.txt'
> f = file( filename )
> f.readline()
> .......
> 在别的程序调用该程序,比如
> exec("python 'c:/xxx/test.py'")
> 提示IOError: [Errno 2] No such file or directory:xxx.txt
> 是路径问题么,应该怎么解决啊,python里有相对路径么?
> 我是python新手
> ------------------------------------------------------------------------
> 侯华隆
> 2007-07-30
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese


-- 
blog: http://blog.csdn.net/jq0123





关于邮件列表 python-chinese 的更多信息