New to Python - Easy way to open a text file
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python - Easy way to open a text file
Hmm.. maybe it'd help if I explained that I'm playing with edna http://edna.sourceforge.net/ I'll play with this simple code: f = open(r'pathToFile) for line in f: # do something with the line of text such as print it. f.close() and this one from Skip: f = open(plainfiles.href, "r") print f.read() and see if I can make a go of it.. I think it's the template portion that is mixing me up.. the template is what's used to create the look of the html on the edna server. Thanks to all who replied so quickly, much appreciated! .\\ax "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > In <[EMAIL PROTECTED]>, kyosohma wrote: > >> I'm not familiar with ezt formats, however reading a text file is a >> breeze. > > This sentence doesn't match the code that follow. It's really simpler > than that ``while`` loop. > >> 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() > > f = open(r'pathToFile) > for line in f: ># do something with the line of text such as print it. > f.close() > > Ciao, > Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python - Easy way to open a text file
nothing is "lame" to me , all help is appreciated :) .\\ax <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Mar 30, 11:39 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> In <[EMAIL PROTECTED]>, kyosohma >> wrote: >> > I'm not familiar with ezt formats, however reading a text file is a >> > breeze. >> >> This sentence doesn't match the code that follow. It's really simpler >> than that ``while`` loop. >> >> > 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() >> >> f = open(r'pathToFile) >> for line in f: >> # do something with the line of text such as print it. >> f.close() >> >> Ciao, >> Marc 'BlackJack' Rintsch > > Yes, the "while" is lame, I admit it. But sometimes you just gotta go > old school! > > Mike > -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python - Easy way to open a text file
Nope. that's not what i mean... Here's a quick run down: edna, is a python mp3 server. (.py) What it does is searches directories for: 1) mp3s 2) jpgs 3) mp3us 4) txt files 5) other folders What I'd like it to do, is upon finding a folder, with a .txt file in it (in my case is probably an album review from AMG), is to take the contents of that text file and display it on the same page as the album, the artwork etc.. I think the gang that has helped me so far, is pointing me in the right direction. I just need to figure out how this template is used. I'll have some time on sunday to play with the "simple" code that they've provided. I will post my results. Thanks again to all who has helped me thus far, .\\ax "Michael Tobis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I think it's pretty clear that we aren't understanding what you mean > by "open a text file and disply its content". > > I conclude that by "edna" you mean this thing: > http://edna.sourceforge.net/ > > I suspect you are not asking a Python question at all. > > Did you try opening > > file:edna-0.6/templates/default.ezt > > in your browser? This will show you the design of your (unpopulated) > template rendered in your browser. > > Notes: > > 1) yes you do need three slashes after "file:" for some reason I've > never comprehended > 2) you will need to replace with your local system > path to the edna directory. (In firefox you can, alternatively, browse > to the file from File->open; Safari will balk at the ezt extension; I > don't know what other browsers will do.) > > If this is more like what your are after, consider that your question > was misleading (and entirely unrelated to Python). The edna miling > list is here: > http://www.lyra.org/mailman/listinfo/edna > > hth > mt > -- http://mail.python.org/mailman/listinfo/python-list
