Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass curly bracket ({) as a string in f-string python?

due to these bracket { and } in Hourly Status','{',''),'}','') causing the syntax error in query .How to pass these bracket as string in a f-string format?

query = f"""Select fd.serial_number,txidkey,cast(replace(replace(data->>'Hourly Status','{',''),'}','') as text) as description,TO_TIMESTAMP(TIME/1000+19800) as date_time,time,total_min from filter_data fd , total_sum ts
where fd.serial_number = ts.serial_number
and time between {yesterday10PM*1000} and {today6AM*1000}'''

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

just use double curly braces {{:

query = f"""\
Select fd.serial_number, txidkey, cast(\
replace(replace(data->>'Hourly Status','{{',''),'}}','') as text) \
as description,TO_TIMESTAMP(TIME/1000+19800) as date_time,time,total_min \
from filter_data fd , total_sum ts \
where fd.serial_number = ts.serial_number \
and time between {yesterday10PM*1000} and {today6AM*1000}
'''

You can also read about formatted strings here:

https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading