take a break

Fun with Files

I am a little bit short on time tonight but I just want to be able to see if I can figure out one thing. How to get a file open with Python.

I am going through the Dive Into Python book here and I want to see if I can make something slightly useful. In order to be able to do what I want I have to be able to open a file. I tried this a couple of nights ago with limited success (basically the file was never found) so I need to give it another try now...

Update...
Well that was pretty easy. All I needed to do was figure out the files that were available in the directory. I had no idea where things were executing from so I couldn't open the file that I had placed in an arbitrary directory. With a call to the os.listdir(".") (list the files in the current directory) I got the appropiate file list. Then I could do a 'f=open(filename, mode)' to open the file and then a 's=f.read(20)' reads 20 characters from the file. A simple 'print s' prints out what I just read in. Pretty easy.
category: Development posted on Thursday September 30, 2004 at 21:10:35 by: 0xCC

Hello World!

Welcome to IntThree.com. I am in the process of getting this site configured and hope to have some of that done over the weekend. Stay tuned and thanks for visiting. There's more...
category: General posted on Thursday September 30, 2004 at 07:40:00 by: 0xCC