Is it possible to do something like this: print 'foo' print 'more foo' print 'I like foo' thing = printed printed = '' print 'bar' print 'more bar' otherthing = printed I want to do this because I want the new line at the end of each line and don't want to put "\n"'s everywhere. Is it possible to do that? Or am I just insane. Zope tells me that 'printed' is a reserved word. Thanks, -Chris -- -------------------------------------------------------------------- Christopher N. Deckard | Lead Web Systems Developer cnd@ecn.purdue.edu | Engineering Computer Network http://www.ecn.purdue.edu/ | Purdue University ---- zlib.decompress('x\234K\316Kq((-J)M\325KM)\005\000)"\005w') ---
The usual idiom for this is: l = [] p = l.append p('foo') p('bar') thing = string.join(l, '\n') Florent Christopher N. Deckard <cnd@ecn.purdue.edu> wrote:
Is it possible to do something like this:
print 'foo' print 'more foo' print 'I like foo'
thing = printed printed = ''
print 'bar' print 'more bar'
otherthing = printed
I want to do this because I want the new line at the end of each line and don't want to put "\n"'s everywhere. Is it possible to do that? Or am I just insane. Zope tells me that 'printed' is a reserved word.
Thanks, -Chris
-- -------------------------------------------------------------------- Christopher N. Deckard | Lead Web Systems Developer cnd@ecn.purdue.edu | Engineering Computer Network http://www.ecn.purdue.edu/ | Purdue University ---- zlib.decompress('x\234K\316Kq((-J)M\325KM)\005\000)"\005w') ---
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 10 http://nuxeo.com mailto:fg@nuxeo.com
From: "Christopher N. Deckard" <cnd@ecn.purdue.edu>
Is it possible to do something like this:
print 'foo' print 'more foo' print 'I like foo'
thing = printed printed = ''
print 'bar' print 'more bar'
otherthing = printed
If you initialize printed to something before you set thing to it, yes. But why?
I want to do this because I want the new line at the end of each line and don't want to put "\n"'s everywhere. Is it possible to do that?
You get a newline at the end of each line... Do you mean you want two? Then do: def mp( this): print this print and use mp 'bar' instead. That way you save a whopping 5 characters per line, so you actually start saving your typing skills after ten lines or so, and you have obfuscated things a lot. Or, you can print """This is a multiline text that spans several lines. Cool Eh?"""
Or am I just insane.
Quite likely yes. :-)
Zope tells me that 'printed' is a reserved word.
Printed? Ah, well, then call it something else. :-) It doesn't do anything in your example above. :-)
Christopher N. Deckard wrote:
Is it possible to do something like this:
printed = ''
Nope. 'printed' is a magical variable created by Python-based Scripts, and they refuse to contemplate using it other than in a read-only context. You can accomplish what you want with the more explicit: from string import join snippets = [] pr = snippets.append pr('a line') pr('another line') ... pr('last line') text = join(snippets, '\n') + '\n' Cheers, Evan @ Zope
participants (4)
-
Christopher N. Deckard -
Evan Simpson -
Florent Guillaume -
Lennart Regebro