open an html string in a browser?

Steve Holden sholden at holdenweb.com
Sat Jan 18 15:50:33 EST 2003


"Lance" <lbrannma at cablespeed.com> wrote in message
news:v2j7tdai7bk9a9 at corp.supernews.com...
> Hi All,
>
> I have a zip file containing perhaps 800 html files. I want to use Python
to
> open one of these files in a browser.
> Suppose the filename is myfile.html.
>
> I've tried webbrowser and zipfile. These don't work.
>
Yes they do. They just don't do what you want them to, that's all <wink>.

> The reason is that zipfile.read('myfile.html') returns a string,
containing
> the contents of the file. However, Webbrowser requires a URL (in this case
> the name of an html file).
>
A good analysis of the problem.

> I don't want to save the string from zipfile.read to disk.
>
Ah, so *this* is the *real* problem. You don't want to do what works, you
want to *define* "works" as not needing to write the zip component contents
to disk where the browser couls get at it.

> Any suggestions will be appreciated.
>
Well, I'm not sure that's true, either. But, leaving that aside (for the
moment), I might ask how you would *like* it to work, given that the
webbrowser utility is driving whatever program you have installed as your
default browser. What would you have it do to let the browser know that it's
supposed to look inside a zip file for the content you want it to display?
It would be nice if browsers would be prepared to read their standard input,
so you could pipe the content into it, but offhand I can't think of one that
does.

There are other possibilities, of course, but they involve a good deal of
programming. For example, you woulc write a program with a graphical user
interface (wxWindows and Tkinter both have HTML widgets, IIRC - others I'm
less familiar with probably do too) that allows you to type in the name of a
zip file with the component name somehow also specified, and have it extract
the correct string from the zipfile and write it directly into the HTML
widget.

So, my suggestion would be that you get involved in the standards-making
process for the world-wide web and promote a "zip://" URL scheme that allows
reference to individual files inside a zip archive. Once you've defined the
"zip://" namespace so everyone can agree how it should work it will only be
a matter of waiting for five years or so, and browsers will be able to
handle it universally.

but-you-might-have-guessed-it's-not-an-entirely-serious-suggestion-ly
'rs  - steve
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Bring your musical instrument to PyCon!    http://www.python.org/pycon/







More information about the Python-list mailing list