Openpyxl error message. Help! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Openpyxl error message. Help! (/thread-21318.html) |
Openpyxl error message. Help! - Shafla - Sep-24-2019 Hi. I am following some text book lessons. I am trying to convert Column Letters to Numbers and getting the following error message. >>> import openpyxl >>> from openpyxl.cell import get_column_letter, column_index_from_string Traceback (most recent call last): File "<pyshell#82>", line 1, in <module> from openpyxl.cell import get_column_letter, column_index_from_string ImportError: cannot import name 'get_column_letter' from 'openpyxl.cell' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/cell/__init__.py) RE: Openpyxl error message. Help! - buran - Sep-24-2019 https://openpyxl.readthedocs.io/en/stable/usage.html?highlight=get_column_letter#write-a-workbook the import is from openpyxl.utils , not openpyxl.cell from openpyxl.utils import get_column_letter, column_index_from_string RE: Openpyxl error message. Help! - Shafla - Sep-24-2019 thank you. that has worked. I am trying to follow an exercises from a book called Automate The Boring Stuff and although i am following the code accurately it is coming up with errors such as the above. For example yesterday i typed; >>> 'Row ' +str(c.row)+', Column ' + c.column + ' is ' + c.value Traceback (most recent call last): File "<pyshell#67>", line 1, in <module> 'Row ' +str(c.row)+', Column ' + c.column + ' is ' + c.value TypeError: can only concatenate str (not "int") to strwhich was exactly as the book stated,when it should have been; >>> 'Row ' + str(c.row) + ',Column ' + str(c.column) + ' is ' + c.value 'Row 1,Column 2 is Apples' i received the correction here on this forum. is it possible there has been many updates to python since the book was written? RE: Openpyxl error message. Help! - buran - Sep-24-2019 there are updates/changes for sure, but this particular case should be in book's errata. As you can see they have converted the c.row, but not c.column - clear mistake on their part. This is also good example while string formatting is preferred compared to concatenation Note that if c.value was a number (not str - 'Apple') - you should have converted it too RE: Openpyxl error message. Help! - Shafla - Sep-24-2019 so the openpyxl.cell and not utlis as it should is another misprint? RE: Openpyxl error message. Help! - buran - Sep-24-2019 (Sep-24-2019, 07:20 PM)Shafla Wrote: so the openpyxl.cell and not utlis as it should is another misprint?I cannot be so sure in this case. openpyxl is third party package and there may have been changes in their api. If you are curious you may check the changelog. YEP, there was change in the openpyxl API - https://openpyxl.readthedocs.io/en/stable/changes.html#b1-2015-02-18 Quote:Moved ancillary functions and classes into utils package - single place of reference RE: Openpyxl error message. Help! - Shafla - Sep-24-2019 thank you. |