Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40529 > unrolled thread
| Started by | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| First post | 2013-03-05 06:35 -0800 |
| Last post | 2013-03-05 15:39 -0800 |
| Articles | 20 on this page of 56 — 9 participants |
Back to article view | Back to comp.lang.python
Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 06:35 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 09:11 -0800
Re: Inserting-embedding some html data at the end of a .py file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-05 17:19 +0000
Re: Inserting-embedding some html data at the end of a .py file Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-05 12:25 -0500
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 09:39 -0800
Re: Inserting-embedding some html data at the end of a .py file Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-05 12:45 -0500
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 09:49 -0800
Re: Inserting-embedding some html data at the end of a .py file Dave Angel <davea@davea.name> - 2013-03-05 13:18 -0500
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 10:53 -0800
Re: Inserting-embedding some html data at the end of a .py file Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-05 14:33 -0500
Re: Inserting-embedding some html data at the end of a .py file Dave Angel <davea@davea.name> - 2013-03-05 14:48 -0500
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 10:53 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 09:49 -0800
Re: Inserting-embedding some html data at the end of a .py file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-05 17:53 +0000
Re: Inserting-embedding some html data at the end of a .py file Roland Koebler <r.koebler@yahoo.de> - 2013-03-06 10:00 +0100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 12:04 -0800
Re: Inserting-embedding some html data at the end of a .py file Dave Angel <d@davea.name> - 2013-03-05 16:02 -0500
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 14:49 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 14:49 -0800
Re: Inserting-embedding some html data at the end of a .py file "Michael Ross" <gmx@ross.cx> - 2013-03-05 22:29 +0100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 14:47 -0800
Re: Inserting-embedding some html data at the end of a .py file "Michael Ross" <gmx@ross.cx> - 2013-03-06 00:19 +0100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 15:39 -0800
Re: Inserting-embedding some html data at the end of a .py file "Michael Ross" <gmx@ross.cx> - 2013-03-06 01:06 +0100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 22:12 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 22:12 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 23:48 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 23:48 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-06 15:18 -0800
Re: Inserting-embedding some html data at the end of a .py file "Michael Ross" <gmx@ross.cx> - 2013-03-07 01:25 +0100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-06 22:35 -0800
Re: Inserting-embedding some html data at the end of a .py file Roland Koebler <r.koebler@yahoo.de> - 2013-03-07 09:58 +0100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 01:05 -0800
Re: Inserting-embedding some html data at the end of a .py file Lele Gaifax <lele@metapensiero.it> - 2013-03-07 10:22 +0100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 01:28 -0800
Re: Inserting-embedding some html data at the end of a .py file Lele Gaifax <lele@metapensiero.it> - 2013-03-07 10:50 +0100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 01:55 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 01:55 -0800
Re: Inserting-embedding some html data at the end of a .py file Chris Angelico <rosuav@gmail.com> - 2013-03-07 21:19 +1100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 02:34 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 02:34 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 03:51 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 03:51 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 01:28 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 02:09 -0800
Re: Inserting-embedding some html data at the end of a .py file Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-07 05:28 -0500
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 04:06 -0800
Re: Inserting-embedding some html data at the end of a .py file Chris Angelico <rosuav@gmail.com> - 2013-03-07 23:17 +1100
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 04:06 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 02:09 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-07 01:05 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-06 22:35 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-06 22:42 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-06 22:42 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-06 15:18 -0800
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-05 15:39 -0800
Page 1 of 3 [1] 2 3 Next page →
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 06:35 -0800 |
| Subject | Inserting-embedding some html data at the end of a .py file |
| Message-ID | <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> |
# ==================================================================================================== =============
# return general counter, render the page and print it
# ==================================================================================================== =============
cur.execute( '''SELECT hits FROM counters WHERE URL = %s''', (htmlpage,) )
data = cur.fetchone()
if cur.rowcount:
# open html template
if htmlpage.endswith('.html'):
f = open( "/home/nikos/public_html/" + htmlpage )
else:
f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage )
# render html template and save
htmldata = f.read()
counter = '''<center><a href="mailto:support@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]
template = htmldata + counter
print ( template )
===============================
I'am trying to emven a counter after each .html or .py file thet the user requests, so to keep track how many times the file has been accessed.
The html files appear and work ok, but the .py files appear as documents instead of runnign as cgi scripts.
Can you help please?
[toc] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 09:11 -0800 |
| Message-ID | <bbc2280e-d422-47c1-ace6-871d37910a1b@googlegroups.com> |
| In reply to | #40529 |
Any ideas on hopw to embed some html data at the end of each python script?
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-03-05 17:19 +0000 |
| Message-ID | <mailman.2895.1362503928.2939.python-list@python.org> |
| In reply to | #40544 |
On 05/03/2013 17:11, Νίκος Γκρ33κ wrote: > Any ideas on hopw to embed some html data at the end of each python script? > Write some code. -- Cheers. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-03-05 12:25 -0500 |
| Message-ID | <mailman.2897.1362504357.2939.python-list@python.org> |
| In reply to | #40544 |
[Multipart message — attachments visible in raw view] — view raw
On Tue, Mar 5, 2013 at 12:19 PM, Mark Lawrence <breamoreboy@yahoo.co.uk>wrote: > On 05/03/2013 17:11, Νίκος Γκρ33κ wrote: > >> Any ideas on hopw to embed some html data at the end of each python >> script? >> > http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm > >> > Write some code. > > -- > Cheers. > > Mark Lawrence > > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 09:39 -0800 |
| Message-ID | <fea70537-617e-4694-ace0-65568039e574@googlegroups.com> |
| In reply to | #40529 |
But i did, I just tried this:
# open html template
if htmlpage.endswith('.html'):
f = open( "/home/nikos/public_html/" + htmlpage )
htmldata = f.read()
counter = ''' <center><a href="mailto:support@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]
else:
f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage )
htmldata = f.read()
counter = '''
print '''<center><a href="mailto:support@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]
template = htmldata + counter
print ( template )
=============
But still doens't embed correctly the additional html data at the end of the .py files.....
Do you have an idea?
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-03-05 12:45 -0500 |
| Message-ID | <mailman.2899.1362505528.2939.python-list@python.org> |
| In reply to | #40548 |
[Multipart message — attachments visible in raw view] — view raw
On Tue, Mar 5, 2013 at 12:39 PM, Νίκος Γκρ33κ <nikos.gr33k@gmail.com> wrote:
> But i did, I just tried this:
>
> # open html template
> if htmlpage.endswith('.html'):
> f = open( "/home/nikos/public_html/" + htmlpage )
>
> htmldata = f.read()
> counter = ''' <center><a href="mailto:
> support@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]
> else:
> f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage )
>
> htmldata = f.read()
> counter = '''
> print '''<center><a href="mailto:
> support@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>
> '''
>
remove the extra triple quote. But seriously, in 2013 you are writing html
like the above? That is some awful stuff
> ''' % data[0]
>
> template = htmldata + counter
> print ( template )
> =============
>
> But still doens't embed correctly the additional html data at the end of
> the .py files.....
>
> Do you have an idea?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Joel Goldstick
http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 09:49 -0800 |
| Message-ID | <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> |
| In reply to | #40552 |
What extra triple quote? There are 2 sets of triple quotes the counter's and the print's !! in case htmlpage variable is a .py file i must append a print '''html''' in order for .py code to absorve that code properly no?
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-03-05 13:18 -0500 |
| Message-ID | <mailman.2903.1362507510.2939.python-list@python.org> |
| In reply to | #40554 |
On 03/05/2013 12:49 PM, Νίκος Γκρ33κ wrote:
> What extra triple quote?
> There are 2 sets of triple quotes the counter's and the print's !!
There are 3 pairs of triple-quotes. But one pair is nested inside the
other, so the interpreter will not handle it the way you apparently
want. If you have to use quotes inside quotes, you must either use a
different kind, or escape them. Perhaps you wanted something like:
counter = """
print '''<center> etc....
<td>font ...
'''
""" % data[0]
But this fragment is unreadable to me, so the syntax error is probably
the least of your worries.
>
> in case htmlpage variable is a .py file i must append a print '''html''' in order for .py code to absorve that code properly no?
>
No clue what that sentence fragment means.
'absorve' isn't an English word, and neither 'absorb' nor 'observe' make
any sense.
Perhaps if you posted a complete program, and identified it by name, and
specified the complete environment it runs in, and used English to
describe what should be appended to what, we'd be able to help. As it
is, you've got mixed clues from which that it's both Python 2 and 3,
running Linux or equivalent, and probably runs on a server.
Using symbol names that make sense would also help. 'htmlpage' is
apparently a str representing a filename on disk. 'counter' is not an
integer, but a long string of html. 'data' is apparently a tuple or
list, and the zeroth element is an int. ??
--
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 10:53 -0800 |
| Message-ID | <cc677143-85d3-4ed2-9627-3872725ff1a3@googlegroups.com> |
| In reply to | #40558 |
Let's focus on just the following snipper please: f = open( some_python_file ) htmldata = f.read() counter = ''' print( " <center><a href="mailto:support@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@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.
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-03-05 14:33 -0500 |
| Message-ID | <mailman.2906.1362512049.2939.python-list@python.org> |
| In reply to | #40560 |
[Multipart message — attachments visible in raw view] — view raw
On Tue, Mar 5, 2013 at 1:53 PM, Νίκος Γκρ33κ <nikos.gr33k@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@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@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
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-03-05 14:48 -0500 |
| Message-ID | <mailman.2908.1362512946.2939.python-list@python.org> |
| In reply to | #40560 |
On 03/05/2013 01:53 PM, Νίκος Γκρ33κ wrote:
> Let's focus on just the following snipper please:
Once again, I repeat. Make a fragment that contains enough information
to actually run. Explain in what environment it's running, and what you
hoped would happen. For example, why on earth would you assume that
printing to the console below would write to a file instead? Is some
part of this running as a cgi inside a web server? What is your
environment?
>
> f = open( some_python_file )
>
> htmldata = f.read()
> counter = ''' print( "
Syntax error here. Since the inner string is more than one line, you
will need to use """. See my example last message. This only matters
if you succeed in writing this to a python file.
> <center><a href="mailto:support@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 )
Why should print write to some python file you have open?? Besides you
have the file open for readonly access. So you might use:
f.close()
f = open( some_python_file, "w" )
f.write(template)
f.close()
> =============================
>
> What this snippet tries to accomplish is append the following string
>
> =========================================
> counter = ''' <center><a href="mailto:support@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.
But that's not at all what's inside the counter variable.
> 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.
Don't ever say "it fails". If you can't be bothered to explain in what
way it fails, forget it. Perhaps you're trying to say it prints a
string to the console instead of writing a different string to the
/fullpath/to/some_python_file.py
Or perhaps you're saying it crashed the Windows machine, and killed
power for miles around. Or perhaps you're saying it got an exception
but we won't bother telling you which.
>
> If i try to append that html data to an .html file they are inserted beautifully
Untrue, unless your environment is specified, it certainly did not.
perhaps you were running the program with output redirected to a file,
in which case it lost the earlier version. Or perhaps you were running
it on a web server, and you *think* some file changed because some
obscure thing happened on your browser. What's your environment?
> 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.
>
Easy to do in emacs.
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 10:53 -0800 |
| Message-ID | <mailman.2907.1362512349.2939.python-list@python.org> |
| In reply to | #40558 |
Let's focus on just the following snipper please: f = open( some_python_file ) htmldata = f.read() counter = ''' print( " <center><a href="mailto:support@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@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.
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 09:49 -0800 |
| Message-ID | <mailman.2901.1362506475.2939.python-list@python.org> |
| In reply to | #40552 |
What extra triple quote? There are 2 sets of triple quotes the counter's and the print's !! in case htmlpage variable is a .py file i must append a print '''html''' in order for .py code to absorve that code properly no?
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-03-05 17:53 +0000 |
| Message-ID | <mailman.2900.1362505968.2939.python-list@python.org> |
| In reply to | #40548 |
On 05/03/2013 17:39, Νίκος Γκρ33κ wrote:
> But i did, I just tried this:
>
> # open html template
> if htmlpage.endswith('.html'):
> f = open( "/home/nikos/public_html/" + htmlpage )
>
> htmldata = f.read()
> counter = ''' <center><a href="mailto:support@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]
> else:
> f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage )
>
> htmldata = f.read()
> counter = '''
> print '''<center><a href="mailto:support@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]
>
> template = htmldata + counter
> print ( template )
> =============
>
> But still doens't embed correctly the additional html data at the end of the .py files.....
>
> Do you have an idea?
>
You're doing something wrong.
--
Cheers.
Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Roland Koebler <r.koebler@yahoo.de> |
|---|---|
| Date | 2013-03-06 10:00 +0100 |
| Message-ID | <mailman.2929.1362560416.2939.python-list@python.org> |
| In reply to | #40548 |
Hi,
On Tue, Mar 05, 2013 at 09:39:19AM -0800, Νίκος Γκρ33κ wrote:
> But i did, I just tried this:
>
> # open html template
> if htmlpage.endswith('.html'):
> f = open( "/home/nikos/public_html/" + htmlpage )
>
> htmldata = f.read()
> counter = ''' <center><a href="mailto:support@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]
> else:
> f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage )
>
> htmldata = f.read()
> counter = '''
> print '''<center><a href="mailto:support@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]
>
> template = htmldata + counter
> print ( template )
> =============
>
> But still doens't embed correctly the additional html data at the end of the .py files.....
>
> Do you have an idea?
as someone said: You're doing it the wrong way.
I would recommend to use a template-engine; then you can put the
complete html-design (and some design-control-structures) into
the template (and *not* into the cgi) and fill data into the
template with a python-script.
Roland
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 12:04 -0800 |
| Message-ID | <9af13b75-a7b0-45c9-a801-797989583cd5@googlegroups.com> |
| In reply to | #40529 |
#open html template
if htmlpage.endswith('.html'):
f = open( "/home/nikos/public_html/" + htmlpage )
htmldata = f.read()
counter = ''' <center><a href="mailto:support@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 )
============================================
Yes the aboev code does work if we talk about appending html data to an already html file!
But if the file is some_python.py file then i cannot just append the data.
Actually by appending i dont want to actually insert the data to the end of the .py file, thus altering it but instead run the .py file and print the counter html data afterwards!
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2013-03-05 16:02 -0500 |
| Message-ID | <mailman.2910.1362517358.2939.python-list@python.org> |
| In reply to | #40566 |
On 03/05/2013 03:04 PM, Νίκος Γκρ33κ wrote:
> #open html template
> if htmlpage.endswith('.html'):
> f = open( "/home/nikos/public_html/" + htmlpage )
>
> htmldata = f.read()
> counter = ''' <center><a href="mailto:support@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 )
> ============================================
> Yes the aboev code does work if we talk about appending html data to an already html file!
>
> But if the file is some_python.py file then i cannot just append the data.
> Actually by appending i dont want to actually insert the data to the end of the .py file, thus altering it but instead run the .py file and print the counter html data afterwards!
>
In other words, you're just trying to waste our time. Thanks for
telling us.
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 14:49 -0800 |
| Message-ID | <9096f7d9-288a-4394-8599-d7b87f8e7e01@googlegroups.com> |
| In reply to | #40570 |
Τη Τρίτη, 5 Μαρτίου 2013 11:02:18 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε: > In other words, you're just trying to waste our time. Thanks for > > telling us. Honestly, its not in my intentions to waste your time. I appreciate all the great help you have provided me in all of my questions, i really do. I'am sorry if i sometimes cannot express myself correctly in english, hence i cannot descrive exactly what i want to accomplish. I'am sorry about that but english its not my native language.
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-03-05 14:49 -0800 |
| Message-ID | <mailman.2913.1362523798.2939.python-list@python.org> |
| In reply to | #40570 |
Τη Τρίτη, 5 Μαρτίου 2013 11:02:18 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε: > In other words, you're just trying to waste our time. Thanks for > > telling us. Honestly, its not in my intentions to waste your time. I appreciate all the great help you have provided me in all of my questions, i really do. I'am sorry if i sometimes cannot express myself correctly in english, hence i cannot descrive exactly what i want to accomplish. I'am sorry about that but english its not my native language.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Ross" <gmx@ross.cx> |
|---|---|
| Date | 2013-03-05 22:29 +0100 |
| Message-ID | <mailman.2912.1362520352.2939.python-list@python.org> |
| In reply to | #40566 |
On Tue, 05 Mar 2013 21:04:59 +0100, Νίκος Γκρ33κ <nikos.gr33k@gmail.com>
wrote:
> #open html template
> if htmlpage.endswith('.html'):
> f = open( "/home/nikos/public_html/" + htmlpage )
>
> htmldata = f.read()
> counter = ''' <center><a href="mailto:support@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 )
> ============================================
> Yes the aboev code does work if we talk about appending html data to an
> already html file!
>
> But if the file is some_python.py file then i cannot just append the
> data.
> Actually by appending i dont want to actually insert the data to the end
> of the .py file, thus altering it but instead run the .py file and print
> the counter html data afterwards!
subprocess.checkoutput() ?
if htmlpage.endswith('.py'):
htmldata=subprocess.check_output(...)
counter=...
template=htmldata+counter
http://docs.python.org/2/library/subprocess.html?highlight=check_output#subprocess.check_output
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.python
csiph-web