Forums

Nested string substitution bug?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Nested string substitution bug?

Postby themaniac » Thu Jan 01, 2009 6:59 am

Code: Select all
dict={'a1':'b'}
list=['a']
print   dict['[list[0]]1'] # prints 'b'
print '[dict['[list[0]]1']]' # gives compiler error: Expecting more string contents or the end of string after the bracketed expression.


Now, I know what I want the second print statement to do. Is the fact that it doesn't do what I want a bug or a feature?
themaniac
 
Posts: 28

Re: Nested string substitution bug?

Postby Charles » Thu Jan 01, 2009 1:46 pm

I don't consider it a bug. Switch your nested quotes from ' to "

And if interpolated expressions get too complicated, consider breaking them out as much for readability as anything else:
key = '[list[0]]1'
print '[dict[key]]'
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Nested string substitution bug?

Postby themaniac » Thu Jan 01, 2009 4:07 pm

I should have said that I did try both combinations of ' and " before posting with similar results. And the substitution is part of a list comprehension, so intermediate variables aren't possible (though I can obviously work around).
themaniac
 
Posts: 28


Return to Discussion

Who is online

Users browsing this forum: No registered users and 63 guests