3 examples of 'convert string to tuple python' in Python

Every line of 'convert string to tuple python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
30def as_tuple(value):
31 '''
32 Smart cast value to tuple by splittng the input on ",".
33 '''
34 if isinstance(value, tuple):
35 return value
36 return tuple(as_list(value))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

223def make_tuple(value):
224 """Return value as tuple.
225
226 >>> make_tuple((1, 2, 3))
227 (1, 2, 3)
228 >>> make_tuple('abc')
229 ('a', 'b', 'c')
230 >>> make_tuple([4, 5, 6])
231 (4, 5, 6)
232 >>> make_tuple(None)
233 (None,)
234
235 """
236 if isinstance(value, tuple):
237 return value
238 if isinstance(value, Sequence):
239 return tuple(value)
240 return (value,)
22def to_tuple(x):
23 return x.as_tuple() if hasattr(x, 'as_tuple') else x

Related snippets