0

Found this link already:

How can I print literal curly-brace characters in python string and also use .format on it?

Didn't quite get me to where I need to go as I have some crazy characters in this string. I need to be able to keep the outer curly brackets (in the line starting with ':9502...'), while being able to format the {0}.

    try:
    filtered_df['Path'] = \
        filtered_df['Path'].apply(lambda x: '<a href="http://'
                                            + host
                                            + ':9502/analytic/saw.dll?catalog#{"location"%3A"{0}"}" target="_blank">{1}</a>'.format(urllib.quote(x, safe=''), x))

So as you can see, I'm trying to simply change some of my column values in a pandas dataframe to an html link. The issue is the required formatting of the destination link (the portion detailed below):

catalog#{"location"%3A"{0}"}" target="_blank">{1}</a>'.format(urllib.quote(x, safe=''), x))

Suffice to say it's pretty crazy and that's how it has to look to get to where I need to go. The issue is is that it doesn't allow the app to execute as written, so the problem, at least I'm guessing, is that I need to do something about those curly brackets and maybe some of the quotes?

1 Answer 1

3

You escape the curly braces by doubling them up.

'outside{{inside {0}}}'.format('stuff')

'outsid{inside stuff}'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.