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 replace a sting using python

I want to replace a string (‘None’) with NULL without quote.

For example:

data  = ('a','None','1','None')

And desired result:

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

result = "'a', NULL, '1', NULL"

Is there a way to get the expected result? Thanks in advance!!

>Solution :

You can use join to build the resulting string:

data  = ('a','None','1','None')
t = ', '.join('NULL' if t == 'None' else repr(t) for t in data)

t is then the string "'a', NULL, '1', NULL".

But I really cannot imagine a real world use case for that…

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