jalanb3 wrote:
Context for this question arises from some recent code. In particular the
"replace_line" method, which takes in a regexp to look for, and a replacement
for when it matches.
It is supposed to work for single lines only (we add ^ and $ to the regexp), so
arguments which have '\n'
Thank you Ken for your help answer
On Mon, May 11, 2009 at 8:11 PM, Ken Seehart wrote:
> jalanb3 wrote:
>>
>> def replace_line(pattern,replacement):
>> values = '\n' in pattern and [ pattern ] or []
>> values += '\n' in replacement and [ replacement ] or []
>>
>> Can I later get the name "
On Mon, 11 May 2009, jalanb3 wrote:
[...]
>
> def replace_line(pattern,replacement):
> errors = '\n' in pattern and [ 'pattern' ] or []
> errors += '\n' in replacement and [ 'replacement' ] or []
> values = [ locals()[e] for e in errors ]
> # etc, etc, and eventually:
> print
jalanb3 wrote:
... Given a variable name I can use locals() to get the value
Is there a way to do it the other way round
Given the value, can I get the variable name ?
(1) Yes you can in some cases.
(2) You should not, things do not inherently have a name.
With that prelude:
de
Context for this question arises from some recent code. In particular the
"replace_line" method, which takes in a regexp to look for, and a replacement
for when it matches.
It is supposed to work for single lines only (we add ^ and $ to the regexp), so
arguments which have '\n' in them are not