New to Python - Easy way to open a text file

kyosohma at gmail.com kyosohma at gmail.com
Fri Mar 30 18:04:35 CEST 2007


On Mar 30, 10:49 am, "Max Steel" <maxst... at gmail.com> wrote:
> Hey gang, I'm new to python coding.  I'm trying to find the simplest way to
> open a text file (on the same server) and display it's content.
>
> The text file is plain text (no markup language of any kind).
>
> The filename gets found and placed into a variable named [plainfiles.href]
>
> I'm using python to find the text files, and a .ezt template to display the
> list of the files.  But I can't figure out how to read the contents of the
> file, and display it within the same template.
>
> Any help is appreciated.
>
> Thanks in advance,
> .\\axSteel

I'm not familiar with ezt formats, however reading a text file is a
breeze.

f = open(r'pathToFile')
while True:
	line = f.readline()
	if not line: break
	# do something with the line of text such as print it.

f.close()


I suppose you could write it to .ezt? Maybe you need to format each
line before inserting it. I hope this points you in the right
direction anyway.

Mike




More information about the Python-list mailing list