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

Can you give us an example what your data looks like?

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()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.