diff --git a/listtocommaseparated.py2 b/listtocommaseparated.py2 new file mode 100644 index 0000000..4a8c693 --- /dev/null +++ b/listtocommaseparated.py2 @@ -0,0 +1,13 @@ +from __future__ import print_function + +data = [2, 'hello', 3, 3.4] + +"""print without creating the whole string""" +print(*data, sep=',') + +"""the print function and the StringIO object""" +from cStringIO import StringIO + +out = StringIO() +print(*data, sep=',', end='', file=out) +print(out.getvalue()) diff --git a/listtocommaseparated.py3 b/listtocommaseparated.py3 new file mode 100644 index 0000000..8a4824e --- /dev/null +++ b/listtocommaseparated.py3 @@ -0,0 +1,11 @@ +data = [2, 'hello', 3, 3.4] + +"""print without creating the whole string""" +print(*data, sep=',') + +"""the print function and the StringIO object""" +from io import StringIO + +out = StringIO() +print(*data, sep=',', end='', file=out) +print(out.getvalue())