question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle writing tuples

See original GitHub issue

I am working with spatial data and the shape format for a point is an x, y tuple. In the worksheet class, the write method tries all of the options to write this tuple and falls through to the part where it tries a float. With my code I get a TypeError instead of a ValueError and the application busts without trying the string style. I commented out the float casting and it doesn’t bust on write_row but then raises a separate error when you close the workbook.

Traceback (most recent call last): File “<string>”, line 1, in <module> File “C:\Python27\ArcGIS10.2\lib\site-packages\xlsxwriter\workbook.py”, line 246, in close self._store_workbook() File “C:\Python27\ArcGIS10.2\lib\site-packages\xlsxwriter\workbook.py”, line 448, in _store_workbook xml_files = packager._create_package() File “C:\Python27\ArcGIS10.2\lib\site-packages\xlsxwriter\packager.py”, line 140, in _create_package self._write_shared_strings_file() File “C:\Python27\ArcGIS10.2\lib\site-packages\xlsxwriter\packager.py”, line 266, in _write_shared_strings_file sst._assemble_xml_file() File “C:\Python27\ArcGIS10.2\lib\site-packages\xlsxwriter\sharedstrings.py”, line 53, in _assemble_xml_file self._write_sst_strings() File “C:\Python27\ArcGIS10.2\lib\site-packages\xlsxwriter\sharedstrings.py”, line 83, in _write_sst_strings self._write_si(string) File “C:\Python27\ArcGIS10.2\lib\site-packages\xlsxwriter\sharedstrings.py”, line 95, in _write_si string = re.sub(‘(x[0-9a-fA-F]{4})’, r’_x005F\1’, string) File “C:\Python27\ArcGIS10.2\Lib\re.py”, line 151, in sub return _compile(pattern, flags).sub(repl, string, count) TypeError: expected string or buffer

is there a way to successfully store tuples or is it expected that I format them how I want them before writing them to the sheet?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
steveohcommented, Sep 3, 2014

I am using

def convert_tuple(value):
            if not isinstance(value, tuple):
                return value

            return str(value)

row = map(convert_tuple, row)
worksheet.write_row('A2', row)

I figured this might be your response. I would have just hoped for a better error message.

0reactions
steveohcommented, Sep 4, 2014

That looks awesome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python - Tuples - Tutorialspoint
A tuple is a collection of objects which ordered and immutable. Tuples are sequences, just like lists. The differences between tuples and lists...
Read more >
Python Tuples - W3Schools
Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, ......
Read more >
Python Tuple (With Examples) - Programiz
A tuple is created by placing all the items (elements) inside parentheses () , separated by commas. The parentheses are optional, however, it...
Read more >
Tuples in Python - GeeksforGeeks
Python Tuple is a collection of objects separated by commas. In some ways, a tuple is similar to a list in terms of...
Read more >
Tuples in Python | Python Tuples with Examples - Scaler Topics
The parenthesis in the above syntax is optional and hence a tuple can also be created without writing the parenthesis.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found