exists = false,但是当我打开它时没有抱怨!? [英] exists=false, but no complaint when i open it!?

查看:51
本文介绍了exists = false,但是当我打开它时没有抱怨!?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

print os.path.exists(''C:\ Users \saftarn\Desktop\NetFlixDa taSet

\trainingsetunzipped\training_set\mv_0000001.txt'')


d = open(''C:/ Python25 / myPrograms / mapexperiments / maps / provinces-of-

sweden.gif'')

d.close()


存在返回false但是当我打开它不会抱怨。怎么来的?


当我试图打开它时,存在的另一个文件返回false为抱怨。

解决方案

globalrev写道:


print os.path.exists(''C:\ Users \saftarn \Desktop \ NetFlixDa taSet

\trainingsetunzipped\training_set\mv_0000001.txt'')


d = open(''C:/ Python25 / myPrograms / mapexperiments /地图/省份 -

sweden.gif'')

d.close()



Ummm 。这些不是相同的文件(除非你有一些奇怪的

NTFS链接正在进行)。


exists返回false但是当我打开它不抱怨。怎么会?



另外,一般情况下,如果你这样做,你很容易出现竞争条件

类似的东西,尽管如此本地C:开车的可能性较小。但

仍有可能。可能更好地将open打开 - 除了

并处理IOError。


TJG


< blockquote> -----原始消息-----


来自:py ***************** ***************@python.org [mailto:python-

li ***************** ********@python.org]代表globalrev

发送时间:2008年5月15日星期四下午12:04

收件人: py ********* @ python.org

主题:exists =是的,但是当我打开它时没有抱怨!?


print os.path.exists(''C:\ Users\saftarn\Desktop\NetFlixDa taSet
\trainingsetunzipped\training_set\mv_0000001.txt'')


d = open(''C:/ Python25 / myPrograms / mapexperiments / maps / provinces- of -

sweden.gif'')

d.close()


存在返回false但是当我打开它时不会抱怨。怎么来的?


另一个存在的文件因为我试图打开它而返回false假设

打开它。

-



由于

反斜杠,你正在成为字符串插值的牺牲品。 (\\\
== newline,\ N == N)。


尝试使用原始字符串r''filename'',而不是''filename'':

打印

os.path.exists(r''C:\ Users \saftarn \Desktop\NetFlixD ataSet \trainingsetunzi

pped\training_set\mv_0000001.txt'')

*****


所传送的信息仅适用于所向的个人或实体它被解决并且可能包含机密,专有和/或特权材料。禁止对除预定接收者以外的个人或实体依赖此信息进行任何审查,转播,传播或其他使用或采取任何行动。如果您错误地收到此消息,请与发件人联系并删除所有计算机中的资料。 GA621


5月16日凌晨2:03,globalrev< skanem ... @ yahoo.sewrote:


print os.path.exists(''C:\ Users \saftarn\Desktop\NetFlixDa taSet

\trainingsetunzipped\training_set\mv_0000001.txt'')


d = open(''C:/ Python25 / myPrograms / mapexperiments / maps / provinces-of-

sweden.gif'')

d.close()


存在返回false但是当我打开它不会抱怨。怎么来的?


当我试图打开它时,另一个存在的文件返回false作为抱怨。



嗯......你正在用os.path.exists测试一条路径,然后打开

a * DIFFERENT *路径。如果你认为你仍有问题,请告诉我们你实际执行的一段很短的代码,并证明问题是



print os.path.exists(''C:\Users\saftarn\Desktop\NetFlixDa taSet
\trainingsetunzipped\training_set\mv_0000001.txt'')

d=open(''C:/Python25/myPrograms/mapexperiments/maps/provinces-of-
sweden.gif'')
d.close()

exists returns false but when i open it doesnt complain. how come?

another file that exists returned false for complained when i tried to
open it.

解决方案

globalrev wrote:

print os.path.exists(''C:\Users\saftarn\Desktop\NetFlixDa taSet
\trainingsetunzipped\training_set\mv_0000001.txt'')

d=open(''C:/Python25/myPrograms/mapexperiments/maps/provinces-of-
sweden.gif'')
d.close()

Ummm. These are not the same files (unless you''ve got some bizarre
NTFS linking going on).

exists returns false but when i open it doesnt complain. how come?

Also, in general, you''re prone to race conditions if you do this
kind of thing, altho'' on a local C: drive that''s less likely. But
still possible. Probably better to wrap the open in a try-except
and handle an IOError.

TJG


-----Original Message-----

From: py********************************@python.org [mailto:python-
li*************************@python.org] On Behalf Of globalrev
Sent: Thursday, May 15, 2008 12:04 PM
To: py*********@python.org
Subject: exists=false, but no complaint when i open it!?

print os.path.exists(''C:\Users\saftarn\Desktop\NetFlixDa taSet
\trainingsetunzipped\training_set\mv_0000001.txt'')

d=open(''C:/Python25/myPrograms/mapexperiments/maps/provinces-of-
sweden.gif'')
d.close()

exists returns false but when i open it doesnt complain. how come?

another file that exists returned false for complained when i tried to
open it.
--


You''re falling victim to string interpolation because of the
backslashes. (\n == newline, \N == N).

Try using a raw string r''filename'', instead of ''filename'':
print
os.path.exists(r''C:\Users\saftarn\Desktop\NetFlixD ataSet\trainingsetunzi
pped\training_set\mv_0000001.txt'')
*****

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA621


On May 16, 2:03 am, globalrev <skanem...@yahoo.sewrote:

print os.path.exists(''C:\Users\saftarn\Desktop\NetFlixDa taSet
\trainingsetunzipped\training_set\mv_0000001.txt'')

d=open(''C:/Python25/myPrograms/mapexperiments/maps/provinces-of-
sweden.gif'')
d.close()

exists returns false but when i open it doesnt complain. how come?

another file that exists returned false for complained when i tried to
open it.

Ummm ... you are testing one path with os.path.exists and then opening
a *DIFFERENT* path. If you think you still have a problem, show us a
short piece of code that you actually executed and that demonstrates
the problem.


这篇关于exists = false,但是当我打开它时没有抱怨!?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆