473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2152
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(see
http://docs.python.org/lib/module-os.path.html)

Jul 18 '05 #3
"Earl Eiland" <ee*@nmt.edu> wrote in message
news:ma*************************************@pytho n.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.SetOriginal(os.path.getsize(os.path.join(I nputDirectory , x)))
y = str(x.split('.')[0]) + '.rk'
print InputDirectory, y
raw_input()
Results.SetArchive(os.path.getsize(os.path.join(In putDirectory, y)))

is executed from the command line with
C:\Documents and Settings\eeiland\Desktop> ..\Thesis\Plan2\Compressor.py
Test_Data\ Test_Output\Results
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(InputDirectory).

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

Traceback (most recent call last):
File "C:\Documents and Settings\eeiland\Thesis\Plan2\Compressor.py",
line 60,
in ?
Results.SetArchive(os.path.getsize(os.path.join(In putDirectory, y)))
File "C:\Python24\lib\ntpath.py", line 229, in getsize
return os.stat(filename).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Book1.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.SetOriginal(os.path.getsize(os.path.join(I nputDirectory , x)))
y = str(x.split('.')[0]) + '.rk'
print InputDirectory, y
raw_input()
Results.SetArchive(os.path.getsize(os.path.join(In putDirectory, y)))

is executed from the command line with
C:\Documents and Settings\eeiland\Desktop> ..\Thesis\Plan2\Compressor.py
Test_Data\ Test_Output\Results
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(InputDirectory).

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

Traceback (most recent call last):
File "C:\Documents and Settings\eeiland\Thesis\Plan2\Compressor.py",
line 60,
in ?
Results.SetArchive(os.path.getsize(os.path.join(In putDirectory, y)))
File "C:\Python24\lib\ntpath.py", line 229, in getsize
return os.stat(filename).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Book1.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.python:
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(InputDirectory, x)
print fid, os.path.exists(fid) Results.SetOriginal(os.path.getsize(os.path.join(I nputDirectory , x))) # replace above
Results.SetOriginal(os.path.getsize(fid)) y = str(x.split('.')[0]) + '.rk' # replace above
y = os.path.splitext(fid)[0] + ".rk"
fid2 = os.path.join(InputDirectory, y)
print fid2, os.path.exists(fid2) print InputDirectory, y # delete above raw_input() # what is this doing? Results.SetArchive(os.path.getsize(os.path.join(In putDirectory, y))) # replace above
Results.SetArchive(os.path.getsize(fid2))
Output upon execution is as follows:
Test_Data\ Book1.rk

Traceback (most recent call last):
File "C:\Documents and Settings\eeiland\Thesis\Plan2\Compressor.py",
line 60,
in ?
Results.SetArchive(os.path.getsize(os.path.join(In putDirectory, y)))
File "C:\Python24\lib\ntpath.py", line 229, in getsize
return os.stat(filename).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Book1.rk'

What am I doing wrong?
Does "Test_Data\Book1.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\\Book1.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.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.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.SetOriginal(os.path.getsize(os.path.join( InputDirectory , x)))
y = str(x.split('.')[0]) + '.rk'
print InputDirectory, y
raw_input()
Results.SetArchive(os.path.getsize(os.path.join(I nputDirectory, y)))

is executed from the command line with
C:\Documents and Settings\eeiland\Desktop> ..\Thesis\Plan2\Compressor.py
Test_Data\ Test_Output\Results
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(InputDirectory).

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

Traceback (most recent call last):
File "C:\Documents and Settings\eeiland\Thesis\Plan2\Compressor.py",
line 60,
in ?
Results.SetArchive(os.path.getsize(os.path.join(In putDirectory, y)))
File "C:\Python24\lib\ntpath.py", line 229, in getsize
return os.stat(filename).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Book1.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
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...
14
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...
16
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:...
9
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 ? ...
3
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...
7
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...
6
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...
3
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...
2
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 : $...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.