delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

If there sint can one rewrite this script to python because htis need to be up quickly? Its my index.pl
Just this an all other perl files i will do myself as i learn, just htis need to be done because it needs to run as we  speak for my web page to work.


Hello, iam just learning Python at the moment because iam switching to Perl, i read  articles over the net at the moment but because my webpage need to be constantly running i would like to ask you if there is an automatic way of doing this.  Isearcht he ent couldnt find any, so iof you have one please tell me.
If there sint can one rewrite this script to python because htis need to be up quickly? Its my index.pl
Just this an all other perl files i will do myself as i learn, just htis need to be done because it needs to run as we  speak for my web page to work.

TOP

please someone help me a bit to get started

TOP

This was the second hit for "perl to python" on Google.  http://wiki.python.org/moin/PerlPhrasebook

TOP

i want automatic conversion not manually, that would take days.

TOP

abstract:

If there sint can one rewrite this script to python because htis need to be up quickly? Its my index.pl
Just this an all other perl files i will do myself as i learn, just htis need to be done because it needs to run as we  speak for my web page to work.


i programmed my whole website bin perl but these days iam making a counter php script for a friend because all his webpages are html ones and he want at the end of his html code to echo a counter values for each webpage.
i wish i could this in perl but i donw know how to embed perl in html and then again the last days i decided to switch from cryptic perl code to a more clarity one, which is python code(that why iam switching from perl to python), clerity code easiest to the mind and to read.
Evenrually i will turn all my php and perl pages to python but iam just new to python and there are enough pages i need to recode.
so i automatic conversion even with flaws could helpo me started.
But then again its essenital to me python code to be able to be embedded in html code or some be able to call python modules from html pages just as i do know with php.
i dont want to use templates just embed pure python code inside html, just like php  does.
can this be donw using python?

TOP

for example this is index.html
Code:
  1. [html lines]
  2. <? include "/home/akis/public_html/MyCounter.php" ?>
  3. ..............
  4. html data.....
  5. ..............
  6. <?
  7. $PageID = 1;
  8. $counter = counter($PageID);
  9. echo "<center><h1>Αριθμός Επισκεπτών: $counter";
  10. ?>
  11. [more html data]
Copy Code
if iam able to turn this php  code to python then i'll quit php and perl and switch entirely to python code.
This is a must for me to eb able to embded python code to html code and to call python modules from html code as well.

TOP

Why you say i should not stick to python?
From what i read it has a very clear syntax and many cababilities, that why Google use it as one of its main languages alogn with C++ and Java.
Can you please show me how to turn the above php lines that are inside html code to python code?
i dont want to use python templates. i wantto abe bale to create with various tools html data and at some points inside the html source to write a few lines of python ocde that make a call to python modules.
Also does python have html generating fucntions?
please give me 1-2 simple exaxples based on my code abovbe, i cant read whole bunch of texts at the monwet, just to see it it can happen!

TOP

As Python was created as a all-purpose language, it isn't embedded between usual HTML like PHP is. Instead (as ManiacDan's tutorials explain), HTML is output with the print statement (which became a function in the 3.x branch, consult your favourite Python reference). So HTML stuff must be put in quotes. Additionally, there are some fundamental syntactical differences you should know if you're learning Python.
python Code:
[url=#top]
[/url]Original
                - python Code
print("[html lines]")

# no need for <? ... ?>
execfile("/home/akis/public_html/MyCounter.py")

# triple quotes to make them work across line breaks
print(""" ..............
html data.....
.............. """)

PageID = 1
counter = counter(PageID)
print("<center><h1>Αριθμός Επισκεπτών:"+counter)

print(" [more html data] ")
  1. print
  2. &#40;
  3. "[html lines]"
  4. &#41;
  5. # no need for <? ... ?>
  6. execfile
  7. &#40;
  8. "/home/akis/public_html/MyCounter.py"
  9. &#41;
  10. # triple quotes to make them work across line breaks
  11. print
  12. &#40;
  13. ""
  14. " ..............
  15. html data.....
  16. .............. "
  17. ""
  18. &#41;
  19. PageID =
  20. 1
  21. counter = counter
  22. &#40;
  23. PageID
  24. &#41;
  25. print
  26. &#40;
  27. "<center><h1>Αριθμός Επισκεπτών:"
  28. +counter
  29. &#41;
  30. print
  31. &#40;
  32. " [more html data] "
  33. &#41;
Copy Code

TOP

So as i understand i have to print form withing a python script any pure html code  i want.
But what if i already have created html files that the only thing missing from them are  a way to print the counter?
i would have to create another python file next to the html file with the same name that will open the html file with an open command save its html contents to a variable and then print it on the screen with a print stetement and then add some python code to make the counter work?
But if this is true i will have to create an extra python file next to an already existing html one?
I'm asking this because i usually use 3rd party tools to create webpages and all i need is some counter to be echoed or some database manipulation.
This way i will have to copye chuncks of html code form my html files and paste print it within my python script. Its a tedious task let alone i will have double amount of files created for every html file of mine.
isnt there an easier way?

TOP

abstract:

If there sint can one rewrite this script to python because htis need to be up quickly? Its my index.pl
Just this an all other perl files i will do myself as i learn, just htis need to be done because it needs to run as we  speak for my web page to work.


Well, one could use some rather complex tricks (e.g. emulating PHP syntax by passing everything between <? ?> to eval() and printing the rest)... but nothing simple, built-in. As I said, Python isn't focused on web scripting like PHP is, everything outside quotes and not trailing a # is source code and evaluated as such.

TOP

Back Forum