473,782 Members | 2,513 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
10 1694
Em Thu, 15 May 2008 19:20:58 +0200, Andreas Tawn escreveu:
>>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
Hint: standardize the way you write paths in python:

import os.path
def _p(*x):
return os.path.normpat h(os.path.expan duser(os.path.j oin(*x)))

(in my system)

In [10]: print _p('abcd.txt')
abcd.txt

In [11]: print _p('~/abcd.txt')
/home/hdante/abcd.txt

In [12]: print _p('~/abcd/efgh.txt')
/home/hdante/abcd/efgh.txt

In [13]: print _p('~', 'abcd', 'efgh.txt')
/home/hdante/abcd/efgh.txt

Jun 27 '08 #11

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
114213
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
2285
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
9479
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,...
0
10311
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7492
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
5378
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
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
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.