473,783 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read a file with open command

I can access to a file with the command:
file_obj = open ( " D:\My documents\Textf ile.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 2539
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\Textf ile.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\Textf ile.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\Textf ile.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********@neu f.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.Pytho n 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\Textf ile.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************ *********@75g20 00cwc.googlegro ups.com>, 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

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

Similar topics

16
6989
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 have tried a few things but no joy what am I missing. Is the another snippet in relation to get_payload to access the body contents print and process to a file. Cheers
8
2350
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
8464
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(), read(), _itelli64(), _lseeki64() with type __int64 Linux/Cygwin: #define _FILE_OFFSET_BITS 64 Use open(), read(), lseek() with type off_t
5
2930
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 shift 24 bits storing in result then printing the result. I thing a while or for loop is needed but I'm not quite sure how to go about it. How do I step through each character in this case and store it for use and passing to another function. ...
9
1738
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 file\n");
1
3443
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. Before: ----------
2
2128
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 questions. The program starts by outputting a simple text information screen: Question Master
9
7385
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 to read was maindata.xml . I cannot however seem to use the gzip module correctly. Have tried the program 2 ways for no success, any ideas would be appreciated. Attempt 1 #!/usr/bin/python
3
2108
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 server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru activesync and are able to acquire an internet connection. The sync for the program occurs thru a...
0
9480
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
10147
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
10083
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
9946
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
7494
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
5379
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
4044
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
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.