Opening a file in Python using windows.

I

Ishwor

I do have permission toa ccess the file as that file is careted and read my me.
I have read/write access to that location. regards

That shouldn't be really hard. :)
okay imagine you have a file called test.txt in C:\Python24\
now go to the IDLE prompt if you have one or just use Python prompt.
I am assuming you know what they are & how to do them. :) If you don't
then go read some books. :)

There are two basic in-built operations to open a file.
The first one is open & the the obvious other one is called file.
file is just an alias for open.

type these lines in the prompt
['This is test file. :)']

So thats there.. the whole file in a line :).. However remember that
it returns a list for further processing if you want to or just forget
it. if you break up those above line into 2 lines then they become
['This is test file. :)']

So there you have it. The power of Python. The first line opens a file
object & places
the output at certain address in the computer memory & test
*references* that address. The second line (test.readlines()) reads
the actuall stream of bytes from that location. :)

Agreed but the OP does have permission so this assumption doesn't hold!

[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,212
Messages
2,571,102
Members
47,698
Latest member
TerraT521

Latest Threads

Top