Python Forum

Full Version: Openpyxl error message. Help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
https://openpyxl.readthedocs.io/en/stabl...a-workbook

the import is from openpyxl.utils, not openpyxl.cell
from openpyxl.utils import get_column_letter, column_index_from_string
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 str
which 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?
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
so the openpyxl.cell and not utlis as it should is another misprint?
(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/stabl...2015-02-18
Quote:Moved ancillary functions and classes into utils package - single place of reference
thank you.