Re: Easy "here documents" ??

2004-12-22 Thread Jim Hill
Fredrik Lundh wrote: >Jim Hill wrote: > >> I'm trying to write a script that writes a script for a rather specialized >> task. I know that seems weird, but the original version was written in >> Korn shell and most of my team are familiar with the way it does things >> even though they don't read

Re: Easy "here documents" ??

2004-12-21 Thread Steve Holden
Fredrik Lundh wrote: Steve Holden wrote: If you would like to use % instead of $, I recommend requesting that feature for Python 3.0: http://www.python.org/cgi-bin/moinmoin/Python3.0 Or use boo - it's probably in there already ;-) weren't you supposed to ask me about it? Aah, right, sorry abou

Re: Easy "here documents" ??

2004-12-21 Thread Fredrik Lundh
Steve Holden wrote: >> If you would like to use % instead of $, I recommend requesting that feature >> for Python 3.0: >> http://www.python.org/cgi-bin/moinmoin/Python3.0 > > Or use boo - it's probably in there already ;-) weren't you supposed to ask me about it? -- http://mail.python.or

Re: Easy "here documents" ??

2004-12-21 Thread Steve Holden
Doug Holton wrote: Bengt Richter wrote: variable1 = 1 variable2 = 2 s = """ v = ${variable1} v2's value is: ${variable2} """ However, Python 3.0 is likely years away. If you want to know how to run code like this today, consult Fredrik Lundh. Or replace ${...} with equally simple %(...)s in

Re: Easy "here documents" ??

2004-12-21 Thread Jim Sizelove
Doug Holton wrote: Bengt Richter wrote: variable1 = 1 variable2 = 2 s = """ v = ${variable1} v2's value is: ${variable2} """ However, Python 3.0 is likely years away. If you want to know how to run code like this today, consult Fredrik Lundh. Or replace ${...} with equally simple %(...)s in

Re: Easy "here documents" ??

2004-12-20 Thread Doug Holton
Bengt Richter wrote: variable1 = 1 variable2 = 2 s = """ v = ${variable1} v2's value is: ${variable2} """ However, Python 3.0 is likely years away. If you want to know how to run code like this today, consult Fredrik Lundh. Or replace ${...} with equally simple %(...)s in the above and be ha

Re: Easy "here documents" ??

2004-12-20 Thread Bengt Richter
On Mon, 20 Dec 2004 18:58:09 -0600, Doug Holton <[EMAIL PROTECTED]> wrote: >> Jim Hill wrote: >> >>> Is there a way to produce a very long multiline string of output with >>> variables' values inserted without having to resort to this wacky >>> >>> """v = %s"""%(variable) > >No, it is currently n

Re: Easy "here documents" ??

2004-12-20 Thread Doug Holton
Jim Hill wrote: Is there a way to produce a very long multiline string of output with variables' values inserted without having to resort to this wacky """v = %s"""%(variable) No, it is currently not possible in Python without the hacks you have seen already. Python is long overdue for simpler st

Re: Easy "here documents" ??

2004-12-20 Thread Nick Craig-Wood
Jim Hill <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > >I prefer this > > > > ... I'll have %(amount)s %(what)s > > ... for $%(cost)s please""" % locals() > > Looks pretty slick. This might just be what I need. > > >Its almost as neat as perl / shell here documents and emacs parse

Re: Easy "here documents" ??

2004-12-20 Thread Scott David Daniels
Jim Hill wrote: Fredrik Lundh wrote: Scott David Daniels wrote: And if you enjoy building insecure stuff, try: def fix(text, globals_=None, locals=None, quote='"'): d = (globals_ or locals or globals()).copy() source = text.split(quote) source[1::2] = (str(eval(expr, d, loc

Re: Easy "here documents" ??

2004-12-19 Thread Keith Dart
Fredrik Lundh wrote: Jim Hill wrote: I'm trying to write a script that writes a script for a rather specialized task. I know that seems weird, but the original version was written in Korn shell and most of my team are familiar with the way it does things even though they don't read Korn. so why

Re: Easy "here documents" ??

2004-12-19 Thread Fredrik Lundh
Jim Hill wrote: > I'm trying to write a script that writes a script for a rather specialized > task. I know that seems weird, but the original version was written in > Korn shell and most of my team are familiar with the way it does things > even though they don't read Korn. so why didn't you te

Re: Easy "here documents" ??

2004-12-19 Thread Fredrik Lundh
Jim Hill wrote: >>And if you prefer not to type so much: >> >>def I(*args): return "".join(map(str, args)) >>def F(v, fmt): return ("%" + fmt) % v > > Not that I don't appreciate the suggestions from masters of the Python > universe, but the reason I'm switching to Python from Perl is for the > re

Re: Easy "here documents" ??

2004-12-19 Thread Jim Hill
John Roth wrote: [Here docs] >I'm not sure why you'd want to do this, though. >It seems like it would be mostly useful in a style >of programming that's quite foreign to the way >Python wants to be programmed. I'm going to try some of the suggestions that others have floated but I think you've re

Re: Easy "here documents" ??

2004-12-19 Thread Jim Hill
Keith Dart wrote: >Jim Hill wrote: >> Is there a way to produce a very long multiline string of output with >> variables' values inserted without having to resort to this wacky > >I was thinking about this. But I can't think of any reason why you would >want to do this in Python. What's wrong wit

Re: Easy "here documents" ??

2004-12-19 Thread Jim Hill
Fredrik Lundh wrote: >Scott David Daniels wrote: > >> And if you enjoy building insecure stuff, try: >> >> def fix(text, globals_=None, locals=None, quote='"'): >> d = (globals_ or locals or globals()).copy() >> source = text.split(quote) >> source[1::2] = (str(eval(expr

Re: Easy "here documents" ??

2004-12-19 Thread Jim Hill
Nick Craig-Wood wrote: >Jim Hill <[EMAIL PROTECTED]> wrote: >> Is there a way to produce a very long multiline string of output with >> variables' values inserted without having to resort to this wacky >> """v = %s"""%(variable) >I prefer this > > ... I'll have %(amount)s %(what)s > ... f

Re: Easy "here documents" ??

2004-12-19 Thread John Roth
"Jim Hill" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] I've done some Googling around on this and it seems like creating a here document is a bit tricky with Python. Trivial via triple-quoted strings if there's no need for variable interpolation but requiring a long, long formatte

Re: Easy "here documents" ??

2004-12-19 Thread Bengt Richter
On Sun, 19 Dec 2004 16:46:34 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Jerry Sievers wrote: > >> It gets uglier though if you want to do this from inside a function >> and have variables from more than one scope interpolated. For that >> you need something that can treat a series of dict

Re: Easy "here documents" ??

2004-12-19 Thread Doug Holton
Jim Hill wrote: Is there a way to produce a very long multiline string of output with variables' values inserted without having to resort to this wacky """v = %s"""%(variable) No, not without the god-awful hacks you've already seen. But it is possible in boo: : http://boo.codehaus.org/ See http://b

Re: Easy "here documents" ??

2004-12-19 Thread Fredrik Lundh
Scott David Daniels wrote: > And if you enjoy building insecure stuff, try: > > def fix(text, globals_=None, locals=None, quote='"'): > d = (globals_ or locals or globals()).copy() > source = text.split(quote) > source[1::2] = (str(eval(expr, d, locals or d)) > for expr

Re: Easy "here documents" ??

2004-12-19 Thread Scott David Daniels
Nick Craig-Wood wrote: I prefer this >>> amount = 1 >>> cost = 2.0 >>> what = 'potato' >>> print """\ ... I'll have %(amount)s %(what)s ... for $%(cost)s please""" % locals() I'll have 1 potato for $2.0 please >>> And if you enjoy building insecure stuff, try: def fi

Re: Easy "here documents" ??

2004-12-19 Thread Fredrik Lundh
Steve Holden wrote: >> here's a rather horrid piece of code that turns a list of dictionaries >> into a single object [that] automatically searches the dictionary chain >> when you ask for attributes (use getattr for non-standard keys). >> >> def flatten_dicts(*dicts): >> root = None >> fo

Re: Easy "here documents" ??

2004-12-19 Thread Steve Holden
Fredrik Lundh wrote: Jerry Sievers wrote: It gets uglier though if you want to do this from inside a function and have variables from more than one scope interpolated. For that you need something that can treat a series of dicts as one.If there's built in functionality in Python for this, I haven

Re: Easy "here documents" ??

2004-12-19 Thread Keith Dart
Jim Hill wrote: I've done some Googling around on this and it seems like creating a here document is a bit tricky with Python. Trivial via triple-quoted strings if there's no need for variable interpolation but requiring a long, long formatted arglist via (%s,%s,%s,ad infinitum) if there is. So m

Re: Easy "here documents" ??

2004-12-19 Thread Nick Craig-Wood
Jim Hill <[EMAIL PROTECTED]> wrote: > I've done some Googling around on this and it seems like creating a here > document is a bit tricky with Python. Trivial via triple-quoted strings > if there's no need for variable interpolation but requiring a long, long > formatted arglist via (%s,%s,%s,

Re: Easy "here documents" ??

2004-12-19 Thread Fredrik Lundh
Jerry Sievers wrote: > It gets uglier though if you want to do this from inside a function > and have variables from more than one scope interpolated. For that > you need something that can treat a series of dicts as one.If there's > built in functionality in Python for this, I haven't discovered

Re: Easy "here documents" ??

2004-12-19 Thread Jerry Sievers
[EMAIL PROTECTED] (Jim Hill) writes: > I've done some Googling around on this and it seems like creating a here > document is a bit tricky with Python. Trivial via triple-quoted strings > if there's no need for variable interpolation but requiring a long, long > formatted arglist via (%s,%s,%s,ad

Re: Easy "here documents" ??

2004-12-18 Thread Nick Coghlan
Jim Hill wrote: Is there a way to produce a very long multiline string of output with variables' values inserted without having to resort to this wacky """v = %s"""%(variable) business? Try combining Python 2.4's subprocess module with its string Templates. Cheers, Nick. -- Nick Coghlan | [EMAI

Re: Easy "here documents" ??

2004-12-18 Thread vincent wehren
Peter Hansen wrote: Jim Hill wrote: I've done some Googling around on this and it seems like creating a here document is a bit tricky with Python. Trivial via triple-quoted strings if there's no need for variable interpolation but requiring a long, long formatted arglist via (%s,%s,%s,ad infinitum

Re: Easy "here documents" ??

2004-12-18 Thread M.E.Farmer
I was curious so I googled , looks like a unix thing :) http://www.faqs.org/docs/abs/HTML/here-docs.html Ok I am with Peter on this , still clueless. What about string replacement. py> x = """ Hello me name is ~NAME~. \n I am ~AGE~ years old.\n ...I live in ~CITY~.\n The city of ~CITY~ i

Re: Easy "here documents" ??

2004-12-18 Thread Peter Hansen
Jim Hill wrote: I've done some Googling around on this and it seems like creating a here document is a bit tricky with Python. Trivial via triple-quoted strings if there's no need for variable interpolation but requiring a long, long formatted arglist via (%s,%s,%s,ad infinitum) if there is. So m

Easy "here documents" ??

2004-12-18 Thread Jim Hill
I've done some Googling around on this and it seems like creating a here document is a bit tricky with Python. Trivial via triple-quoted strings if there's no need for variable interpolation but requiring a long, long formatted arglist via (%s,%s,%s,ad infinitum) if there is. So my question is: