473,769 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exists=false, but no complaint when i open it!?

print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet
\trainingsetunz ipped\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.
Jun 27 '08 #1
10 1693
globalrev wrote:
print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet
\trainingsetunz ipped\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
Jun 27 '08 #2
-----Original Message-----
From: py************* *************** ****@python.org [mailto:python-
li************* ************@py thon.org] On Behalf Of globalrev
Sent: Thursday, May 15, 2008 12:04 PM
To: py*********@pyt hon.org
Subject: exists=false, but no complaint when i open it!?

print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet
\trainingsetunz ipped\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\saft arn\Desktop\Net FlixDataSet\tra iningsetunzi
pped\training_s et\mv_0000001.t xt')
*****

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
Jun 27 '08 #3
On May 16, 2:03 am, globalrev <skanem...@yaho o.sewrote:
print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet
\trainingsetunz ipped\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.
Jun 27 '08 #4

-----Original Message-----
From: py************* *************** ****@python.org [mailto:python-
li************* ************@py thon.org] On Behalf Of Reedick, Andrew
Sent: Thursday, May 15, 2008 12:11 PM
To: globalrev; py*********@pyt hon.org
Subject: RE: exists=false, but no complaint when i open it!?

print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet
\trainingsetunz ipped\training_ set\mv_0000001. txt')

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\saft arn\Desktop\Net FlixDataSet\tra iningsetunz
i
pped\training_s et\mv_0000001.t xt')
Specificially, the \t in '\trainingsetun zipped' and in '\training_set'
were being treated as tab characters. Ignore my comment about '\N ==
N'.
Jun 27 '08 #5
yeah i was unclear but i tested different stuff at the same time.
and flim is not misspelled i just created it and jolted osmething down
and it became flim...

print os.path.exists( 'C:/Python25/myPrograms/netflix/flim.txt')
d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r')
#print d.readline()
print d.read()

d.close() #not necessary?

print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet
\training_set')

i can read flim and exists returns true.

however
print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet')
returns True but
print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet
\training_set') returns False...

i have thourogly checked the filename to be correct and if we assume
it is what could this mean then?
i had a problem one other time when i had renamed a file but windows
didnt rename it compeltely apparently.
Jun 27 '08 #6
when i try to write to the file...

Traceback (most recent call last):
File "C:\Python25\my Programs\netfli x\netflix.py", line 10, in
<module>
d.write('hej du galne kock')
IOError: [Errno 0] Error
Jun 27 '08 #7
On 15 Maj, 19:04, globalrev <skanem...@yaho o.sewrote:
when i try to write to the file...

Traceback (most recent call last):
File "C:\Python25\my Programs\netfli x\netflix.py", line 10, in
<module>
d.write('hej du galne kock')
IOError: [Errno 0] Error
damn i take a break lol.

r+ ldo when open file so i CAN write to it...
Jun 27 '08 #8
>print os.path.exists( 'C:\Users\safta rn\Desktop\NetF lixDataSet
>\training_set' ) returns False...

i have thourogly checked the filename to be correct and if we assume
it is what could this mean then?
i had a problem one other time when i had renamed a file but windows
didnt rename it compeltely apparently.
It's escape characters again.

You're asking for
'C:\Users\safta rn\Desktop\NetF lixDataSet\trai ning_set', but Python
interprets that as 'C:\Users\safta rn\Desktop\NetF lixDataSet
raining_set', which probably doesn't exist.

The first example works by accident because backslash plus the first
letter of each folder in your path happens to not match any of Python's
string formatting characters.

Use forward slashes or double up the backslashes to stop this happening.

Cheers,

Drea
Jun 27 '08 #9
On May 15, 12:07 pm, globalrev <skanem...@yaho o.sewrote:
On 15 Maj, 19:04, globalrev <skanem...@yaho o.sewrote:
when i try to write to the file...
Traceback (most recent call last):
File "C:\Python25\my Programs\netfli x\netflix.py", line 10, in
<module>
d.write('hej du galne kock')
IOError: [Errno 0] Error

damn i take a break lol.

r+ ldo when open file so i CAN write to it...
That traceback doesn't provide much help ("[Errno 0] Error"...), but I
remember that one time I got it when trying to write to a file opened
for reading. Make sure you're opening the file for writing (passing
"w" as the second argument to open(), or "wb" if you're writing binary
data). Also, as everyone keeps pointing out to you, watch out for
backslash scapes -- double the slashes ("\\", that really means a
single \ to Python), use forward slashes ("/", perhaps not the most
elegant solution, but it always works), or put an "r" next to the
string (r"your\path" ). The last form is the easiest, but it only works
if you're typing a literal; you'll eventually need to double slashes
(e.g., for replacing something in a string: s.replace("/", "\\")).

Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6694
by: Jason Charalambides | last post by:
I set a program to automatically load values from a temporary file. However, there is a chance that the specific temporary file "C:\Temp\TU.tmp" may not exist at all. In that case I want that specific routine to be skipped. I guess this is a simple If (that file exists) Open "C:\Temp\TU.tmp" For Input As #3 etc....... Else GoTo
2
8271
by: Alex | last post by:
Hi Everybody, I am new to Oracle. I just installed the Oracle9i (personal edition) on my Window XP system. I am trying to simply run some basic SQL commands using SQLPlus. After entering userid (system) password(manager) and Host String (my global database name), I am getting the following error and it does not logme in: can not run the service.
15
114212
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
0
1598
by: ITALstudio s.r.l. | last post by:
Hy, In my application I create instances of windows forms into different AppDomain. If I repeat 5 times the following sequence: - Creating AppDomain; - Creating instance of windows form into AppDomain;
7
19117
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not have the necessary permissions. One hack could be to check for length and that would throw a FileNotFoundException ...but there is got to be a better way!
2
2738
by: Anasi | last post by:
Hi, I have a problem with a rule that is updating a oracle 10 database. The rule is expected to check if ther is a invoice number then take the highest of them, and if there isnt any, then choose the reference number instead. The problem is, sometimes the table shipordart doesnt contains any rows and then "nothing" should happen. But now i get a error message. ORA-01407: cannot update ("E768"."SHIPORD"."INVOICENO") to NULL I have tried...
1
2039
by: HemantSa | last post by:
Session exists when i close browser in firefox...is there any way to remove the session if i open the new browser instance.... Regards, Hemant Sandbhor
10
2284
by: sitko | last post by:
Hi, I'm a VB programmer, and was wondering, is there a way to check and see if a file exists in straight C? In VB the code is: File.Exists(strDir & "filename.txt") 'returns a boolean true if it exists, false if not Thanks,
7
4556
by: Cirene | last post by:
I installed the RTM version of Visual Studio 2008 today. Initially when I would open any of my 2005 projects (.NET 2.0) it would simply open them. Now the Visual Studio Conversion Wizard is showing up everytime. Why is this and how can I bypass this? Thanks!
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.