473,714 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error sending path to Win OS

os.path.getsize (Inputdirectory + '\\' + Filename) works, but
os.path.getsize (Inputdirectory + '\\' + Filename.split( '.') + '.ext')
Fails reporting "no such file or directory
InputDirectory\ \Filename.ext".
os.path.getsize (Inputdirectory + r'\' + Filename.split( '.') + '.ext')
generates a syntax error.

Earl Eiland

Jul 18 '05 #1
7 2171
Earl Eiland wrote:
os.path.getsize (Inputdirectory + '\\' + Filename) works, but
os.path.getsize (Inputdirectory + '\\' + Filename.split( '.') + '.ext')
Fails reporting "no such file or directory
InputDirectory\ \Filename.ext".
No, that should be a TypeError. This will be easier if you copy and
paste your Python session instead of making stuff up.
os.path.getsize (Inputdirectory + r'\' + Filename.split( '.') + '.ext')
generates a syntax error.


'r"\" is not a valid string literal (even a raw string cannot end in an
odd number of backslashes). Specifically, a raw string cannot end in a
single backslash (since the backslash would escape the following quote
character). Note also that a single backslash followed by a newline is
interpreted as those two characters as part of the string, not as a
line continuation.'

http://docs.python.org/ref/strings.html
--
Michael Hoffman
Jul 18 '05 #2
To generate path names take a look at os.path.join(se e
http://docs.python.org/lib/module-os.path.html)

Jul 18 '05 #3
"Earl Eiland" <ee*@nmt.edu> wrote in message
news:ma******** *************** **************@ python.org...
os.path.getsize (Inputdirectory + '\\' + Filename) works, but
os.path.getsize (Inputdirectory + '\\' + Filename.split( '.') + '.ext')
Fails reporting "no such file or directory
InputDirectory\ \Filename.ext".
os.path.getsize (Inputdirectory + r'\' + Filename.split( '.') + '.ext')
generates a syntax error.

Earl Eiland


Use the language provided os.sep rather than trying to code your own which
will be incorrect when the code is run on a different platform.

$ python
Python 2.1 (#15, May 4 2004, 21:22:34) [MSC 32 bit (Intel)] on win32
Type "copyright" , "credits" or "license" for more information.
import os
dir(os) .... os.sep '\\' os.pathsep ';' os.linesep

'\r\n'
Jul 18 '05 #4
A couple of you commented that I should be using os.path.join.
Accordingly, I rewrote my code. Unfortunately, I still have the same
problem. the following code snippet

Results.SetOrig inal(os.path.ge tsize(os.path.j oin(InputDirect ory , x)))
y = str(x.split('.' )[0]) + '.rk'
print InputDirectory, y
raw_input()
Results.SetArch ive(os.path.get size(os.path.jo in(InputDirecto ry, y)))

is executed from the command line with
C:\Documents and Settings\eeilan d\Desktop> ..\Thesis\Plan2 \Compressor.py
Test_Data\ Test_Output\Res ults
Test_Data\ Book1.rk, where InputDirectory (in the above snippet) =
'Test_Data\' (I've also tried 'Test_Data', with the same results).

x (in the above snippet) is an element of the list generated by
os.listdir(Inpu tDirectory).

Output upon execution is as follows:
Test_Data\ Book1.rk

Traceback (most recent call last):
File "C:\Documen ts and Settings\eeilan d\Thesis\Plan2\ Compressor.py",
line 60,
in ?
Results.SetArch ive(os.path.get size(os.path.jo in(InputDirecto ry, y)))
File "C:\Python24\li b\ntpath.py", line 229, in getsize
return os.stat(filenam e).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Boo k1.rk'

What am I doing wrong?

Earl
On Sat, 2005-03-12 at 15:16, Michael Hoffman wrote:
Earl Eiland wrote:
os.path.getsize (Inputdirectory + '\\' + Filename) works, but
os.path.getsize (Inputdirectory + '\\' + Filename.split( '.') + '.ext')
Fails reporting "no such file or directory
InputDirectory\ \Filename.ext".


No, that should be a TypeError. This will be easier if you copy and
paste your Python session instead of making stuff up.
os.path.getsize (Inputdirectory + r'\' + Filename.split( '.') + '.ext')
generates a syntax error.


'r"\" is not a valid string literal (even a raw string cannot end in an
odd number of backslashes). Specifically, a raw string cannot end in a
single backslash (since the backslash would escape the following quote
character). Note also that a single backslash followed by a newline is
interpreted as those two characters as part of the string, not as a
line continuation.'

http://docs.python.org/ref/strings.html
--
Michael Hoffman


Jul 18 '05 #5
A couple of you commented that I should be using os.path.join.
Accordingly, I rewrote my code. Unfortunately, I still have the same
problem. the following code snippet

Results.SetOrig inal(os.path.ge tsize(os.path.j oin(InputDirect ory , x)))
y = str(x.split('.' )[0]) + '.rk'
print InputDirectory, y
raw_input()
Results.SetArch ive(os.path.get size(os.path.jo in(InputDirecto ry, y)))

is executed from the command line with
C:\Documents and Settings\eeilan d\Desktop> ..\Thesis\Plan2 \Compressor.py
Test_Data\ Test_Output\Res ults
Test_Data\ Book1.rk, where InputDirectory (in the above snippet) =
'Test_Data\' (I've also tried 'Test_Data', with the same results).

x (in the above snippet) is an element of the list generated by
os.listdir(Inpu tDirectory).

Output upon execution is as follows:
Test_Data\ Book1.rk

Traceback (most recent call last):
File "C:\Documen ts and Settings\eeilan d\Thesis\Plan2\ Compressor.py",
line 60,
in ?
Results.SetArch ive(os.path.get size(os.path.jo in(InputDirecto ry, y)))
File "C:\Python24\li b\ntpath.py", line 229, in getsize
return os.stat(filenam e).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Boo k1.rk'

What am I doing wrong?

Earl
On Sat, 2005-03-12 at 15:16, Michael Hoffman wrote:
Earl Eiland wrote:
os.path.getsize (Inputdirectory + '\\' + Filename) works, but
os.path.getsize (Inputdirectory + '\\' + Filename.split( '.') + '.ext')
Fails reporting "no such file or directory
InputDirectory\ \Filename.ext".


No, that should be a TypeError. This will be easier if you copy and
paste your Python session instead of making stuff up.
os.path.getsize (Inputdirectory + r'\' + Filename.split( '.') + '.ext')
generates a syntax error.


'r"\" is not a valid string literal (even a raw string cannot end in an
odd number of backslashes). Specifically, a raw string cannot end in a
single backslash (since the backslash would escape the following quote
character). Note also that a single backslash followed by a newline is
interpreted as those two characters as part of the string, not as a
line continuation.'

http://docs.python.org/ref/strings.html
--
Michael Hoffman


Jul 18 '05 #6
On Mon, 14 Mar 2005 06:54:02 -0700, Earl Eiland <ee*@nmt.edu> declaimed
the following in comp.lang.pytho n:
A couple of you commented that I should be using os.path.join.
Accordingly, I rewrote my code. Unfortunately, I still have the same
problem. the following code snippet
print os.getcwd() #verify what the current directory IS.
fid = os.path.join(In putDirectory, x)
print fid, os.path.exists( fid) Results.SetOrig inal(os.path.ge tsize(os.path.j oin(InputDirect ory , x))) # replace above
Results.SetOrig inal(os.path.ge tsize(fid)) y = str(x.split('.' )[0]) + '.rk' # replace above
y = os.path.splitex t(fid)[0] + ".rk"
fid2 = os.path.join(In putDirectory, y)
print fid2, os.path.exists( fid2) print InputDirectory, y # delete above raw_input() # what is this doing? Results.SetArch ive(os.path.get size(os.path.jo in(InputDirecto ry, y))) # replace above
Results.SetArch ive(os.path.get size(fid2))
Output upon execution is as follows:
Test_Data\ Book1.rk

Traceback (most recent call last):
File "C:\Documen ts and Settings\eeilan d\Thesis\Plan2\ Compressor.py",
line 60,
in ?
Results.SetArch ive(os.path.get size(os.path.jo in(InputDirecto ry, y)))
File "C:\Python24\li b\ntpath.py", line 229, in getsize
return os.stat(filenam e).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Boo k1.rk'

What am I doing wrong?
Does "Test_Data\Book 1.rk" EXIST (ignore the double \ in the
message, that's just Python's escaping of the slash, as that is what
would be needed for you to type it in a Python statement:
x = "Test_Data\\Boo k1.rk"
The os.path.exists( ), along with the os.getcwd() call, should show where
it is looking, and if the file is there.

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.com/> <

Jul 18 '05 #7
Earl Eiland <ee*@nmt.edu> wrote:

A couple of you commented that I should be using os.path.join.
Accordingly, I rewrote my code. Unfortunately, I still have the same
problem. the following code snippet

Results.SetOri ginal(os.path.g etsize(os.path. join(InputDirec tory , x)))
y = str(x.split('.' )[0]) + '.rk'
print InputDirectory, y
raw_input()
Results.SetArc hive(os.path.ge tsize(os.path.j oin(InputDirect ory, y)))

is executed from the command line with
C:\Documents and Settings\eeilan d\Desktop> ..\Thesis\Plan2 \Compressor.py
Test_Data\ Test_Output\Res ults
Test_Data\ Book1.rk, where InputDirectory (in the above snippet) =
'Test_Data\' (I've also tried 'Test_Data', with the same results).

x (in the above snippet) is an element of the list generated by
os.listdir(Inp utDirectory).

Output upon execution is as follows:
Test_Data\ Book1.rk

Traceback (most recent call last):
File "C:\Documen ts and Settings\eeilan d\Thesis\Plan2\ Compressor.py",
line 60,
in ?
Results.SetArch ive(os.path.get size(os.path.jo in(InputDirecto ry, y)))
File "C:\Python24\li b\ntpath.py", line 229, in getsize
return os.stat(filenam e).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Boo k1.rk'

What am I doing wrong?


My guess would be that Test_Data\Book1 .rk does not exist from the point of
view of the directory where the script is running this. You might do this:
print os.getcwd()
os.system('dir ' + InputDirectory)
just to prove that you are where you think you are.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #8

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

Similar topics

1
5033
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
14
3887
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the maxRequestLength parameter of the <httpRuntime> section and that works as expected. What I want is to enforce a max file size but haven't been able to trap the error thrown when the file is too large and that's where I could use some help.
16
2955
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In: http://www.mywebsite.org/WebResource.axd?d=5WvLfhnJp5Lc8WhQSD4gdA2&t=632614619884218750 -------------------------------------------------------------------------------- System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. at...
9
1629
by: Michael Tissington | last post by:
After converting from 6.0 to 2005 when I try to Compile my project I'm getting a LINK error Error 1 fatal error LNK1181: cannot open input file " ?/.obj" Any ideas how to fx this please ? -- Michael Tissington http://www.oaklodge.com
3
7724
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce value for the UserName token. Is it possilbe at all to do this from VBScript (or jscript?)? I know I will be limited with what I can do with the SOAP message. Eg/ can't sign/encrypt it etc. Thanks,
7
6862
by: news | last post by:
Recently our mail from our e-commerce site has been rejected by AOL due to an IP block because someone was using our PHP scripts to send spam. Well, I got that fixed. But our legitimate auto-generated e-mails are getting "deferred" by AOL now with an error: Deferred: Bad file descriptor I can't find anything on their support site about this, nor Googling. Any ideas?
6
2313
ak1dnar
by: ak1dnar | last post by:
Hi, I am creating script to download some files using download dialog box.First time i tried to use ajax for this, but i failed. So i went through this way, By Using this function i am going to submit the Data to process to PHP. JS Function: function file_down(fid) { window.location = "download.php?fid="+fid; }
3
2395
by: raj200809 | last post by:
when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message 550-5.7.1 the ip you’re using to send mail is not authorized" i have configure smtp server put 127.0.0.1 ip in relay and also put 127.0.0.1 ip in connection. using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing;
2
6357
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $ ../glibc-2.5/configure --prefix=/mnt/new/Mars/glibc_HQ_test/GLIBC/ install/ --with-__thread --enable-kernel=2.6.11 --enable-shared
0
8808
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
9177
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
9077
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
9021
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...
0
7954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4465
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...
1
3159
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
2524
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.