Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > can i use the browser to show the result of python

Reply
Thread Tools

can i use the browser to show the result of python

 
 
Hacken
Guest
Posts: n/a
 
      09-25-2009
I have write some python script

i want to use browser(IE or FF) to call it, an show the returns!

how to?
 
Reply With Quote
 
 
 
 
Dave Angel
Guest
Posts: n/a
 
      09-25-2009
Hacken wrote:
> I have write some python script
>
> i want to use browser(IE or FF) to call it, an show the returns!
>
> how to?
>
>

You don't say much about your environment, nor the nature of your
script. So my response will be very generic.


If your script writes a valid html/xml/xhtml format to stdout, then you
could put the script onto a web server with cgi enabled, and mark it
executable. Then you could enter the URL for that cgi file into your
browser, and see that generated web page.

Interesting additional gotchas: You need rights to upload (ftp) to such
a server. The server needs to have an appropriate Python available, and
configured to permit cgi access for files with the .py extension.
Further, if the server is Unix, your file must be in Unix text format,
with a shebang line that matches the location of the appropriate version
of python on that particular server.

DaveA

 
Reply With Quote
 
 
 
 
Hacken
Guest
Posts: n/a
 
      09-27-2009
On Sep 25, 6:27*pm, Dave Angel <(E-Mail Removed)> wrote:
> Hacken wrote:
> > I have write some python script

>
> > i want to use browser(IE or FF) to call it, an show the returns!

>
> > how to?

>
> You don't say much about your environment, nor the nature of your
> script. So my response will be very generic.
>
> If your script writes a valid html/xml/xhtml format to stdout, then you
> could put the script onto a web server with cgi enabled, and mark it
> executable. *Then you could enter the URL for that cgi file into your
> browser, and see that generated web page.
>
> Interesting additional gotchas: *You need rights to upload (ftp) to such
> a server. *The server needs to have an appropriate Python available, and
> configured to permit cgi access for files with the .py extension. *
> Further, if the server is Unix, your file must be in Unix text format,
> with a shebang line that matches the location of the appropriate version
> of python on that particular server.
>
> DaveA



Thanks.

but,i do not want to setup a webserver, i think that is so big for
other user.

i just want write my programes in python, and i use Browser to show my
GUI,

can i do that?and how to?

thanks,waitting......
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      09-27-2009
On Sat, 26 Sep 2009 19:05:37 -0700, Hacken wrote:

> i just want write my programes in python, and i use Browser to show my
> GUI,
>
> can i do that?and how to?
>
> thanks,waitting......



In Python 2.6, you can use the webbrowser module.




--
Steven
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      09-27-2009
Hacken wrote:
> On Sep 25, 6:27 pm, Dave Angel <(E-Mail Removed)> wrote:
>
>> Hacken wrote:
>>
>>> I have write some python script
>>>
>>> i want to use browser(IE or FF) to call it, an show the returns!
>>>
>>> how to?
>>>

>> You don't say much about your environment, nor the nature of your
>> script. So my response will be very generic.
>>
>> If your script writes a valid html/xml/xhtml format to stdout, then you
>> could put the script onto a web server with cgi enabled, and mark it
>> executable. Then you could enter the URL for that cgi file into your
>> browser, and see that generated web page.
>>
>> Interesting additional gotchas: You need rights to upload (ftp) to such
>> a server. The server needs to have an appropriate Python available, and
>> configured to permit cgi access for files with the .py extension.
>> Further, if the server is Unix, your file must be in Unix text format,
>> with a shebang line that matches the location of the appropriate version
>> of python on that particular server.
>>
>> DaveA
>>

>
>
> Thanks.
>
> but,i do not want to setup a webserver, i think that is so big for
> other user.
>
> i just want write my programes in python, and i use Browser to show my
> GUI,
>
> can i do that?and how to?
>
> thanks,waitting......
>
>

What I described is all I've done firsthand. But more is possible. And
I've worked on fancier setups, but somebody else did the plumbing.

As Stephen points out, you can use webbrowser module to launch a
browser. So you could write python code to create a web page(s), write
it to a file, then launch the browser using the "file://......"
protocol. That'd be fine for displaying pages that are generated
entirely before launching the browser. But if you want the python
program to get feedback from the browser (which is usually what's meant
by using the browser for a GUI), you're going to have to simulate a
webserver.

That can be done on a single machine using the "localhost" shortcut. I
don't know how to do it, but there is a sample in the 2.6 release of
Python, at least in the Windows version. You run it from the Start
menu->Python2.6->module docs.

The source for the main server is in
c:\Python26\Tools\Scripts\pydocgui.pyw. (though all it does is import
pydoc.py and call it.) Now that particular program's purpose is to
generate and display docs for the python files on the system, but
presumably it's a starting place.

Now, this is the first I've looked at this file, but at line 1967 is a
function serve(), which is commented as the web browser interface. The
function serve() probably has much of what you're interested. In
particular, it contains a few class definitions, including DocServer and
DocHandler, which send data back and forth to the browser, over the
localhost connection.

It looks like it gets its core code from BaseHTTPServer module.

At line 2058 is a function gui(), which is a small tkinter program that
just displays a few buttons and such. That's not what you're asking about.

Hopefully somebody else has actually used some of this stuff, and can
elaborate.

DaveA


 
Reply With Quote
 
Hacken
Guest
Posts: n/a
 
      09-29-2009
On Sep 27, 12:24*pm, Dave Angel <(E-Mail Removed)> wrote:
> Hacken wrote:
> > On Sep 25, 6:27 pm, Dave Angel <(E-Mail Removed)> wrote:

>
> >> Hacken wrote:

>
> >>> I have write some python script

>
> >>> i want to use browser(IE or FF) to call it, an show the returns!

>
> >>> how to?

>
> >> You don't say much about your environment, nor the nature of your
> >> script. So my response will be very generic.

>
> >> If your script writes a valid html/xml/xhtml format to stdout, then you
> >> could put the script onto a web server with cgi enabled, and mark it
> >> executable. *Then you could enter the URL for that cgi file into your
> >> browser, and see that generated web page.

>
> >> Interesting additional gotchas: *You need rights to upload (ftp) to such
> >> a server. *The server needs to have an appropriate Python available, and
> >> configured to permit cgi access for files with the .py extension. *
> >> Further, if the server is Unix, your file must be in Unix text format,
> >> with a shebang line that matches the location of the appropriate version
> >> of python on that particular server.

>
> >> DaveA

>
> > Thanks.

>
> > but,i do not want to setup a webserver, i think that is so big for
> > other user.

>
> > i just want write my programes in python, and i use Browser to show my
> > GUI,

>
> > can i do that?and how to?

>
> > thanks,waitting......

>
> What I described is all I've done firsthand. *But more is possible. *And
> I've worked on fancier setups, but somebody else did the plumbing.
>
> As Stephen points out, you can use webbrowser module to launch a
> browser. *So you could write python code to create a web page(s), write
> it to a file, then launch the browser using the "file://......"
> protocol. *That'd be fine for displaying pages that are generated
> entirely before launching the browser. *But if you want the python
> program to get feedback from the browser (which is usually what's meant
> by using the browser for a GUI), you're going to have to simulate a
> webserver.
>
> That can be done on a single machine using the "localhost" shortcut. *I
> don't know how to do it, but there is a sample in the 2.6 release of
> Python, at least in the Windows version. *You run it from the Start
> menu->Python2.6->module docs.
>
> The source for the main server is in
> c:\Python26\Tools\Scripts\pydocgui.pyw. *(though all it does is import
> pydoc.py and call it.) *Now that particular program's purpose is to
> generate and display docs for the python files on the system, but
> presumably it's a starting place.
>
> Now, this is the first I've looked at this file, but at line 1967 is a
> function serve(), which is commented as the web browser interface. * The
> function serve() *probably has much of what you're interested. *In
> particular, it contains a few class definitions, including DocServer and
> DocHandler, which send data back and forth to the browser, over the
> localhost connection.
>
> It looks like it gets its core code from BaseHTTPServer module.
>
> At line 2058 is a function gui(), which is a small tkinter program that
> just displays a few buttons and such. *That's not what you're asking about.
>
> Hopefully somebody else has actually used some of this stuff, and can
> elaborate.
>
> DaveA- Hide quoted text -
>
> - Show quoted text -



Thaks both u guys

I find a way to do my work ,but i found a basic webserver is really
necessary.

First,i use webbrowser,Steven recommend,to call the browser open a
html file,my gui,in this html file i make a form and submit a GET
request with the paraments i need

second, i use BaseHTTPServer, to handle the GET request,parse the
request get the paraments i need,
and use these parament to finish my logic

thrid, use BaseHTTPServer make a response to the browser with a
formated html file with my result.

It's not complex like i think,because the BaseHTTPServer is not
complex

Thanks DaveA,a webserver,like you said,is a necessary,&Steven, your
webbrowser.
 
Reply With Quote
 
catafest
Guest
Posts: n/a
 
      10-05-2009
On Sep 25, 12:41*pm, Hacken <(E-Mail Removed)> wrote:
> I have write some python script
>
> i want to use browser(IE or FF) to call it, an show the returns!
>
> how to?


Python script running under web browsers only like:
python + website = django .

 
Reply With Quote
 
Hacken
Guest
Posts: n/a
 
      10-10-2009
On Oct 5, 5:16*pm, catafest <(E-Mail Removed)> wrote:
> On Sep 25, 12:41*pm, Hacken <(E-Mail Removed)> wrote:
>
> > I have write some python script

>
> > i want to use browser(IE or FF) to call it, an show the returns!

>
> > how to?

>
> Python script running under web browsers only like:
> *python + website = django .


u can say that again.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is the result of valid dynamic cast always equal to the result ofcorrespondent static cast? Pavel C++ 7 09-18-2010 11:35 PM
simulation result is correct but synthesis result is not correct J.Ram VHDL 7 12-03-2008 01:26 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
VS app does not show SQL or Access DB result in IE browser. =?Utf-8?B?YmlsZG8=?= ASP .Net 4 11-13-2004 02:31 AM
Can someone show me a code example that stuffs data into a web page and scrpaes the result ? Al Dykes Python 1 11-03-2004 09:12 PM



Advertisments