Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'syntax': 0.03; 'output': 0.04; 'append': 0.07; 'f.close()': 0.07; 'redirected': 0.07; 'subject:file': 0.07; 'python': 0.09; "'''": 0.09; 'fails.': 0.09; 'happen.': 0.09; 'inserted': 0.09; 'snippet': 0.09; 'specified,': 0.09; 'template': 0.11; 'assume': 0.11; 'charset:iso-8859-7': 0.15; 'file,': 0.15; 'server,': 0.15; '.py': 0.16; 'beautifully': 0.16; 'crashed': 0.16; 'f.read()': 0.16; 'inserting': 0.16; 'opened.': 0.16; 'run.': 0.16; 'variable.': 0.16; 'string': 0.17; 'wrote:': 0.17; 'certainly': 0.17; 'tries': 0.17; 'version.': 0.17; 'saying': 0.18; 'windows': 0.19; 'changes': 0.20; 'file.': 0.20; 'trying': 0.21; 'do.': 0.21; 'earlier': 0.21; 'skip:= 20': 0.22; 'example': 0.23; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'besides': 0.27; 'environment': 0.29; 'cgi': 0.29; 'obscure': 0.29; 'prints': 0.29; 'quoting': 0.29; 'subject:end': 0.29; 'subject:some': 0.29; 'succeed': 0.29; 'error': 0.30; 'file': 0.32; 'not.': 0.32; 'running': 0.32; 'print': 0.32; 'message.': 0.33; 'subject: .': 0.33; 'subject:data': 0.33; 'to:addr:python- list': 0.33; "can't": 0.34; 'changed': 0.34; 'open': 0.35; 'pm,': 0.35; "won't": 0.35; 'explain': 0.36; 'but': 0.36; 'should': 0.36; 'enough': 0.36; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'subject:-': 0.40; 'end': 0.40; 'your': 0.60; 'lost': 0.60; 'easy': 0.60; 'telling': 0.61; 'different': 0.63; 'ever': 0.63; 'information': 0.63; 'more': 0.63; 'bothered': 0.65; 'received:74.208': 0.71; 'power': 0.74; 'browser.': 0.81; 'received:74.208.4.194': 0.84; 'repeat.': 0.84; 'running,': 0.84; 'url:show': 0.84; '\xc1\xf1\xe9\xe8\xec\xfc\xf2': 0.84; '"it': 0.91; 'fragment': 0.91; 'killed': 0.91; 'skip:/ 30': 0.91 Date: Tue, 05 Mar 2013 14:48:45 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Inserting-embedding some html data at the end of a .py file References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-7; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V02:K0:apERUwzV1izxQrUSFcYWH+5Xq3336qA+7WuLUmQ8BL5 nbiDZAhwTFugtQ7LzKExqHrlpewo7xbIkknuf6ltjL4y5Pv7Cn uwI+ymxI5LbhUbkuWyTSVwPXhw+eoUsC1PxHpCXdY5Ta3Fw6mX I4I4X616PrRcLNn+aOegnGHR+M9hVj8Bpl2nz+u1B1f2Zzh36t wEX+H8jOHFA6edJRnXRBVFbPobM6vj7X6MNmWbfHu8TTEdHvBg zDffVHmPLl5uNaz8p0EfbZJ/5Zo1WRXe5uT6Dcb+kTTzubOqaw jYVIYvCUyoC6tJljWFH5cA+icPvHEYIlDHPUuriXyd9wXvskw= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 86 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362512946 news.xs4all.nl 6890 [2001:888:2000:d::a6]:60234 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40565 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. >
>
> > > " ) > ''' % 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 = '''
>
Αριθμός Επισκεπτών %d
> > > ''' % 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
Αριθμός Επισκεπτών %d