Inserting-embedding some html data at the end of a .py file

Joel Goldstick joel.goldstick at gmail.com
Tue Mar 5 20:33:59 CET 2013


On Tue, Mar 5, 2013 at 1:53 PM, Νίκος Γκρ33κ <nikos.gr33k at gmail.com> wrote:

> Let's focus on just the following snipper please:
>
> f = open( some_python_file )
>
> htmldata = f.read()
> counter = ''' print( "
>                               <center><a href="mailto:support at superhost.gr">
> <img src="/data/images/mail.png"> </a>
>                               <center><table border=2 cellpadding=2
> bgcolor=black>
>                                           <td><font color=lime>Αριθμός
> Επισκεπτών</td>
>                                           <td><a href="
> http://superhost.gr/?show=stats"><font color=cyan> %d </td>
>                               " )
>                           ''' % data[0]
>
> #render template
> template = htmldata + counter
> print ( template )
> =============================
>
> What this snippet tries to accomplish is append the following string
>
> =========================================
>                 counter = ''' <center><a href="mailto:support at superhost.gr">
> <img src="/data/images/mail.png"> </a>
>                               <center><table border=2 cellpadding=2
> bgcolor=black>
>                                           <td><font color=lime>Αριθμός
> Επισκεπτών</td>
>                                           <td><a href="
> http://superhost.gr/?show=stats"><font color=cyan> %d </td>
>                           ''' % data[0
> =========================================
>
> at the end of the the python script file that it currently opened.
> I'am using the print statemnt inside the triple quoted string so to append
> that html data by inserting a print statemnt but although i have changes
> the type of quoting it still fails.
>
> If i try to append that html data to an .html file they are inserted
> beautifully but inside a .py file they dont.
>
> I just need to append that string after the end of a .py file. that's all
> i want to do.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

print displays to the console.  To write to a file open file in 'append'
mode and write:

with open("test.py", "a") as myfile:
    myfile.write("appended text")



-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130305/7c750ba4/attachment.html>


More information about the Python-list mailing list