How can I load python script into Html ??

P

PatPoul

I want to do the same thing as
<script language="javascript" src="xxx.js"></script>

but with a python script :
<script language="Python" src="xxx.py"></script>

==================================
if xxx.py :
def mytest():
alert("test")
window.document.write('test')
==================================
and test.html :
<HTML>
<SCRIPT Language="Python" src="xxx.py"></SCRIPT>

<SCRIPT Language="Python">
mytest()
</SCRIPT>
</HTML>
==================================

I always got this error :
NameError : name 'mytest' is not defined

Thx ...
Patrick Poulin
 
S

Steve M

Man, I don't even know where to start. There is no way this will work
if you don't have a web browser that can interpret Python. I don't know
of one, and I don't think anybody wants one because using a browser
that would execute arbitrary Python code provided by the server would
be an obscene security mistake.

Javascript is specifically designed for client-side scripting, whereas
Python is not. You'll have to re-think what you wanted to accomplish,
and if it was just "I prefer coding in Python to coding in Javascript"
then you're basically SOL.

Hope this helps!
 
B

Berislav Lopac

Javascript is specifically designed for client-side scripting

Actually, Javascript's client-side implementation is specifically
designed for client-side scripting. It has originally been envisioned
by Netscape for both server and sclient side scripting.

Berislav
 
X

Xavier Morel

PatPoul said:
I want to do the same thing as
<script language="javascript" src="xxx.js"></script>

but with a python script :
<script language="Python" src="xxx.py"></script>

==================================
if xxx.py :
def mytest():
alert("test")
window.document.write('test')
==================================
and test.html :
<HTML>
<SCRIPT Language="Python" src="xxx.py"></SCRIPT>

<SCRIPT Language="Python">
mytest()
</SCRIPT>
</HTML>
==================================

I always got this error :
NameError : name 'mytest' is not defined

Thx ...
Patrick Poulin
Long story short, no.

The browser needs binding to the language, and either the ability to use
the external interpreter or embed an interpreter, and no browser
currently has that kind of thing.
 
X

Xavier Morel

Shouldn't have hit the "send" button so fast...

Addendum: the script element doesn't have any language attribute, the
attribute you're supposed to use is "type" and it takes the MIME type of
your script as a value.

s/language="javascript"/type="text/javascript"/
 
P

PatPoul

Sorry I was not clear, my setup is functionnal with Pywin32.
Python 2.4 + pywin32

and actually, I can do this kind of script on client side :

<HTML>
<SCRIPT Language="Python">
alert('test')
</SCRIPT>
</HTML>

but I want to include external python script with the HTML tag <SCRIPT>
 
T

Tim Roberts

Steve M said:
Man, I don't even know where to start. There is no way this will work
if you don't have a web browser that can interpret Python. I don't know
of one, and I don't think anybody wants one because using a browser
that would execute arbitrary Python code provided by the server would
be an obscene security mistake.

Internet Explorer will happily do so, if you have the Python Windows
extensions installed, and register the active scripting component that cmes
with it.
 
R

Roger Upole

Using the normail src attribute works for me:

<SCRIPT Language="Python" src="somescript.pys"></script>

Did you register the Python script engine with pyscript.py or
pyscript_rexec.py ?

Roger
 
P

PatPoul

Yes I register Python script.
I see in your exemple that you use file extention pys.
That was why my exemple does'nt work.

Thanks !

Patrick Poulin
 
C

Claudio Grondi

PatPoul said:
Yes I register Python script.
I see in your exemple that you use file extention pys.
That was why my exemple does'nt work.

Thanks !

Patrick Poulin

In this context I have a question:

How can the registering of the Python scripting engine be easily and
completely removed? (i.e. how can I get rid of it when already registered?)

Claudio
 
R

Roger Upole

Claudio Grondi said:
In this context I have a question:

How can the registering of the Python scripting engine be easily and completely removed? (i.e. how can I get rid of it when
already registered?)

Claudio

Run pyscript.py passing --unregister on the command line.

Roger
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top