473,396 Members | 1,927 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,396 software developers and data experts.

Read a file with open command

I can access to a file with the command:
file_obj = open ( " D:\My documents\Textfile.txt",'r')

When I now try to read a file with the following command:

file_obj = open ("D:\My documents\File.ods",'r') it doesn't function.
The extension ods is coming from OpenOffice.org Calc.

Why ?

jean-jeanot

Aug 11 '06 #1
11 2512
Hi,
simply use file_obj = open ("D:\My documents\File.ods",'rb') for
opening file in binary access mode, which is required for binary files
on MS Windows.
Honza

jean-jeanot wrote:
I can access to a file with the command:
file_obj = open ( " D:\My documents\Textfile.txt",'r')

When I now try to read a file with the following command:

file_obj = open ("D:\My documents\File.ods",'r') it doesn't function.
The extension ods is coming from OpenOffice.org Calc.

Why ?

jean-jeanot
Aug 11 '06 #2
jean-jeanot wrote:
I can access to a file with the command:
file_obj = open ( " D:\My documents\Textfile.txt",'r')
With a space before the drive letter? I don't think so.
When asking questions, *don't* type what you thought you used,
copy/paste what you actually used.
>
When I now try to read a file with the following command:

file_obj = open ("D:\My documents\File.ods",'r') it doesn't function.
The extension ods is coming from OpenOffice.org Calc.

Why ?
You haven't told us what "it doesn't function" means, so we'll have to
play guessing games ...could be for at least two possible reasons:
(1) .ods files are binary and you didn't specify 'rb'
(2) you really typed "d:\my documents\file.ods" and the \f got
interpreted as a form-feed character. You should *never* type literal
Windows filenames like that. Instead, you have three choices:
(a) "d:\\my documents\\file.ods" # not recommended
(b) r"d:\my documents\file.ods"
(c) "d:/my documents/file.ods"

I'd suggest that you fix *both* of the above problems and try again.

HTH,
John

Aug 11 '06 #3
Sorry, but the access mode is not binary with XP Windows. Finally for
reading the file it is necessary to use a slash or a double backslash.
If the file is a simple textfile, using a backslash is perhaps not
recommended but it is functionning.
Anyway many thanks.Here is the program:
>>file_obj= open ("D:/Mes documents/ADB Anna.ods",'r')
s = file_obj
s.readlines()
Jean-Jeanot

Jan Svec a écrit :
Hi,
simply use file_obj = open ("D:\My documents\File.ods",'rb') for
opening file in binary access mode, which is required for binary files
on MS Windows.
Honza

jean-jeanot wrote:
I can access to a file with the command:
file_obj = open ( " D:\My documents\Textfile.txt",'r')

When I now try to read a file with the following command:

file_obj = open ("D:\My documents\File.ods",'r') it doesn't function.
The extension ods is coming from OpenOffice.org Calc.

Why ?

jean-jeanot
Aug 11 '06 #4
On 11 Aug 2006 09:39:23 -0700, jean-jeanot <je********@neuf.frwrote:
Anyway many thanks.Here is the program:
>file_obj= open ("D:/Mes documents/ADB Anna.ods",'r')
s = file_obj
s.readlines()
Please remember not to top-post :)

Try this
>>s = open ("D:/Mes documents/ADB Anna.ods",'r')
s.readlines()
s.close()
or
>>s = open ("D:/Mes documents/ADB Anna.ods",'r').readlines()
HTH :)
Aug 11 '06 #5
Dear Sybrel,

I am delighted to know that you have been enlighted through my
question.
I am aware of my stupidity and I would say of my ignorance.If all
Python users were not ignorant I suppose the Python group would be
superfluous. I would suggest that if if you think that a question is
supid please do not answer it.In French we say: "There is no stupid
question but answers can be stupid". For the citation of Zappa I am
convinced that when Zappa is speaking of world stupidity he is thinking
to stupidity and wickedness of mankind and not to ignorance.
Anyway the open command with a file having the extension ods must be
used with a slash. But with a double backslash it is functionning too.
In every documentation I posess on Python it is mentioned that an
absolute path in Windows starts with a backslash.Python accepts
platform-specific syntax ( See Python by C. Fehilly , p 306, Python in
a nutshell by Martelli, etc,etc)
Anyway thank you for your answer.

jean-Jeanot

Sybren Stuvel a écrit :
jean-jeanot enlightened us with:
I can access to a file with the command:
file_obj = open ( " D:\My documents\Textfile.txt",'r')

Which is the wrong way. Use forward slashes, escape your backslashes,
or use raw strings.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Aug 11 '06 #6
In <11*********************@75g2000cwc.googlegroups.c om>, jean-jeanot
wrote:
Sorry, but the access mode is not binary with XP Windows.
But ods files are binary so you better open them as binary files. Windows
does a "magical" translation of line ending bytes and stops processing a
file if it hits a \x26 byte if the file was opened in the default text
mode.
Finally for reading the file it is necessary to use a slash or a double
backslash. If the file is a simple textfile, using a backslash is
perhaps not recommended but it is functionning.
The slashes don't have anything to do with the content of the file. For
both, binary and text files, you have to escape backslashes in literal
strings or sooner or later you will be bitten by a backslash + character
combination that's a valid escape sequence in literal strings.
>file_obj= open ("D:/Mes documents/ADB Anna.ods",'r')
s = file_obj
s.readlines()
This doesn't make much sense as `ods` files don't contain text lines but
are binary. A ZIP archive containing XML files to be more precise.

If you want to read the raw binary data into memory it's better to use::

file_obj = open('D:/Mes documents/ADB Anna.ods', 'rb')
data = file_obj.read()
file_obj.close()

Ciao,
Marc 'BlackJack' Rintsch
Aug 11 '06 #7
jean-jeanot wrote:
Dear Sybrel,

I am delighted to know that you have been enlighted through my
question.
I am aware of my stupidity and I would say of my ignorance.If all
Python users were not ignorant I suppose the Python group would be
superfluous. I would suggest that if if you think that a question is
supid please do not answer it.In French we say: "There is no stupid
question but answers can be stupid". For the citation of Zappa I am
convinced that when Zappa is speaking of world stupidity he is thinking
to stupidity and wickedness of mankind and not to ignorance.
Ummm, he did not say that your question was stupid. The Zappa quote is
included as part of what we refer to as a 'signature'. In the case of
Sybren Stuvel's posts to this newsgroup, the Frank Zappa quote is included
in every message that he posts. Not just messages that he posts to you.

Secondly, I notice that when you quoted Sybren's message in your reply, your
newsreader attributed the quoted text with: "Sybren Stuvel a écrit :"
Likewise, when Sybren replied to your message, his newsreader attributed
the quoted text with, "jean-jeanot enlightened us with:"

Do you see what I mean? You didn't write "Sybren Stuvel a écrit" because
Sybren was french, did you? Of course, not! Your mail/news application
included that attribution by default. By the same token, Sybren's
mail/news application defaulted to this attribution: 'jean-jeanot
enlightened us with:"

When reading people's responses to your queries, stick to the material that
they actually "write" at the time of the response. Ignore the stuff that
they entered while configuring their respective news/mail reader. Little
items like message signatures and quote attributions are, at best,
reflective of the personality and/or philosophy of the author, and say
nothing of the person receiving the message. :-)

Aug 11 '06 #8

Sorry, I regret my reaction.

Jean-jeanot

AlbaClause a écrit :
jean-jeanot wrote:
Dear Sybrel,

I am delighted to know that you have been enlighted through my
question.
I am aware of my stupidity and I would say of my ignorance.If all
Python users were not ignorant I suppose the Python group would be
superfluous. I would suggest that if if you think that a question is
supid please do not answer it.In French we say: "There is no stupid
question but answers can be stupid". For the citation of Zappa I am
convinced that when Zappa is speaking of world stupidity he is thinking
to stupidity and wickedness of mankind and not to ignorance.

Ummm, he did not say that your question was stupid. The Zappa quote is
included as part of what we refer to as a 'signature'. In the case of
Sybren Stuvel's posts to this newsgroup, the Frank Zappa quote is included
in every message that he posts. Not just messages that he posts to you.

Secondly, I notice that when you quoted Sybren's message in your reply, your
newsreader attributed the quoted text with: "Sybren Stuvel a écrit :"
Likewise, when Sybren replied to your message, his newsreader attributed
the quoted text with, "jean-jeanot enlightened us with:"

Do you see what I mean? You didn't write "Sybren Stuvel a écrit" because
Sybren was french, did you? Of course, not! Your mail/news application
included that attribution by default. By the same token, Sybren's
mail/news application defaulted to this attribution: 'jean-jeanot
enlightened us with:"

When reading people's responses to your queries, stick to the material that
they actually "write" at the time of the response. Ignore the stuff that
they entered while configuring their respective news/mail reader. Little
items like message signatures and quote attributions are, at best,
reflective of the personality and/or philosophy of the author, and say
nothing of the person receiving the message. :-)
Aug 11 '06 #9
AlbaClause wrote:
jean-jeanot wrote:
<snip>
Ummm, he did not say that your question was stupid. The Zappa quote is
included as part of what we refer to as a 'signature'. In the case of
Sybren Stuvel's posts to this newsgroup, the Frank Zappa quote is included
in every message that he posts. Not just messages that he posts to you.
First up, I *like* the Frank Zappa signature quote; it has a George
Carlin feel to it and takes a swipe at our overly-protective cultures
[side note: I bought an electric heating pad last night that came with
instructions not to use it in the bathtub! Well, duh!]. But, can you
see where the signature on a response to a tutor list -- where people
are already feeling a bit intimidated and/or inadequate and therefore
may feel a wee bit "stupid" -- might be taken the wrong way?

I have spent many years teaching mathematics and physics in a classroom
setting and have come to realize that, as a teacher, just about
anything I say/do can be blown way out of proportion. So I don't use
sarcasm or "fun" little put-downs and I treat every question as if it
is the most important matter because, to the student, it is. Do I get
tired of answering the same thing over and over? Yes!! Many times I
will ask if the student has read the textbook and, if not, I will
request they give it a try (much in the same way we ask if they have
read any tutorials), but I take Homeric efforts not to offend them and,
to that end, modify my behavior in order to teach them mathematics.

My point is that this is a wonderful service you tutors provide, but
the Zappa signature may not be the best choice for this setting. Most
people will read it and get a laugh (as did I), but how many have taken
it the way jean-jeanot did and walk away feeling insulted? How many
will not post a response expressing their feelings, never post a
question again or, worst case, decide Python is not for them?

Again, I admire this list and those of you you maintain it. These are
just my thoughts. YMMV.

--greg

Aug 12 '06 #10
gs*********@gmail.com wrote:
AlbaClause wrote:
>jean-jeanot wrote:
<snip>
>Ummm, he did not say that your question was stupid. The Zappa quote is
included as part of what we refer to as a 'signature'. In the case of
Sybren Stuvel's posts to this newsgroup, the Frank Zappa quote is
included
in every message that he posts. Not just messages that he posts to you.

First up, I *like* the Frank Zappa signature quote; it has a George
Carlin feel to it and takes a swipe at our overly-protective cultures
[side note: I bought an electric heating pad last night that came with
instructions not to use it in the bathtub! Well, duh!]. But, can you
see where the signature on a response to a tutor list -- where people
are already feeling a bit intimidated and/or inadequate and therefore
may feel a wee bit "stupid" -- might be taken the wrong way?

I have spent many years teaching mathematics and physics in a classroom
setting and have come to realize that, as a teacher, just about
anything I say/do can be blown way out of proportion. So I don't use
sarcasm or "fun" little put-downs and I treat every question as if it
is the most important matter because, to the student, it is. Do I get
tired of answering the same thing over and over? Yes!! Many times I
will ask if the student has read the textbook and, if not, I will
request they give it a try (much in the same way we ask if they have
read any tutorials), but I take Homeric efforts not to offend them and,
to that end, modify my behavior in order to teach them mathematics.

My point is that this is a wonderful service you tutors provide, but
the Zappa signature may not be the best choice for this setting. Most
people will read it and get a laugh (as did I), but how many have taken
it the way jean-jeanot did and walk away feeling insulted? How many
will not post a response expressing their feelings, never post a
question again or, worst case, decide Python is not for them?

Again, I admire this list and those of you you maintain it. These are
just my thoughts. YMMV.

--greg
This is getting a little off-topic, but my feeling is that if you're unable
to discern the difference between the substance of the message, and the
"personal style" of the author (eg: quote attributions and/or signature
lines) then you probably shouldn't be attempting to code in Python or any
other structured language.

A newsgroup post is quite structured -- just as a Python script is -- there
is the header, which contains the subject, the sender, the recipient, and
other protocol information; and the text body. The text body is also quite
structured. The text body can contain a quote from a prior message, the
added comments that make up the substance of the message, and a
signature/tag line. If a person has great difficulty in differentiating
the various parts of a newsgroup message, then perhaps structured
programming languages are not for them.

Perhaps we should begin a new message passing convention. One where the
substance of the post is contained within braces -- like C/C++ code? Just
kidding! LOL

--
--
There are several things that I will never be:
* I will never be attracted to females.
* I will never enjoy the company of others.
Exactly how these realities bode for my enemy, is not of my concern.

Aug 12 '06 #11
gs*********@gmail.com wrote:
[snip]
My point is that this is a wonderful service you tutors provide, but
the Zappa signature may not be the best choice for this setting.
This is *not* the tutor list.
>Most people will read it and get a laugh (as did I), but how many have taken
it the way jean-jeanot did and walk away feeling insulted? How many
will not post a response expressing their feelings, never post a
question again or, worst case, decide Python is not for them?
<humour>
Possibly one, were he still alive: St Aloysius "of whom it is said in
the book of the monk Eustachius that when he heard a man breaking wind
with deafening noise he immediately burst into tears and could only be
consoled by prayers" [from "The Good Soldier Švejk ..." by Jaroslav
Hašek [tr. Parrott (the Sir Cecil variety, not the Norwegian Blue)]]
</humour>

Cheers,
John

Aug 13 '06 #12

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

Similar topics

16
by: Chuck Amadi | last post by:
Sorry to bovver you again (again) here's script. I still can't see why the get_payload() doesn't produce the plain text message body of an emails in the testwwws users mailbox. As you can see I...
8
by: nephish | last post by:
Hey there. i want to set a variable to represent the last line of a text file how do i do that? or even better, how do i create a list of the lines of a text file?
6
by: Rolf Schroedter | last post by:
(Sorry for cross-posting). I need to access large files > 2GByte (Linux, WinXP/NTFS) using the standard C-library calls. Till today I thought I know how to do it, namely for Win32: Use open(),...
5
by: Pete | last post by:
I having a problem reading all characters from a file. What I'm trying to do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want to && with a mask 0xFF000000 then >> right...
9
by: Carramba | last post by:
#include <stdio.h> int main( void ){ char cQuit = 'a'; char cKommando , artistNamn , skivansNamn , cChar; int cK ; FILE *pekaFile; printf( "l - for read file\n"); printf( "s - for writte...
1
by: Chua Wen Ching | last post by:
Hi there, I have some problems when reading XML file. 1. First this, is what i did, cause i can't seem to read "sub elements or tags" values, so i place those values into attributes like this....
2
by: sani8888 | last post by:
Hi everybody I am a beginner with C++ programming. And I need some help. How can I start with this program *********** The program is using a text file of information as the source of the...
9
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying...
3
by: ninjamonkey | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.