0

Yo,
im new to Python and have been working on a personal project but can figure out how to save data to a file then read it in another program. im might have the writing down but cant tell bacause i cant read it. Iv been trying to work it out for a few days now and am getting a little frustrated *sigh*. thanks for any help

3
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by katharnakh
0

Yo,
im new to Python and have been working on a personal project but can figure out how to save data to a file then read it in another program. im might have the writing down but cant tell bacause i cant read it. Iv been trying to work it out for a few days now and am getting a little frustrated *sigh*. thanks for any help

i think this should work out. follow the following syntax, and modes, now i think u'll able to read it.

open(filename, mode)-->returns file object
modes--> 'r' read
'w' write
'a' append
'r+' R/W

'b' append this to any of the above to open the binary file.(allowed only in Windows)

>>> f=open('/tmp/workfile', 'w') >>> printf

#this will print whole file content.

following are the other options which u may need.
fileobj.read(no. of bytes) if no. of bytes is not specified then defaultly reads the whole file.
.readline(no. of bytes)--> reads the file in line-by-line and returns a list containing lines as the item of list.
returns empty string if the end of file is reached.

.write(string/variable)--> if EOF is reached returns None

.tell()--> tells the current position of the file pointer.

.seek(offset, from-what)--> moves the file pointer to offset + from-what position, if from-what is not specified then fp is seek from start.

.close()

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.