quoteIfNeeded

emlib.textlib.quoteIfNeeded(s, quote='', defaultquote='"')[source]

Add quotation marks around s if needed

Parameters:
  • s (str) – the string which might need quoting

  • quote – which quote sign to use. If not given, it will be detected and if not found a default quote is used

  • defaultquote – quote used when autodetection is used and no quote was found

Return type:

str

Returns:

a string where it is ensured that it is surrounded by quote

Example

>>> quoteIfNeeded('test')
"test"
>>> quoteIfNeeded("'foo'", "'")
'foo'