More openpyxl learnings

Continuing our journey through Automate the Boring Stuff with Python's excel lessons, we came across the get_column_letter and column_index_from_string openpyxl functions. When attemtping to import the functions, we were given the following error:

 >>> import openpyxl
fr
>>> from openpyxl.cell import get_column_letter, column_index_from_string
Traceback (most recent call last):
  File "<pyshell#8>", 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' (C:\Users\james\AppData\Roaming\Python\Python37\site-packages\openpyxl\cell\__init__.py)
>>> get_column_letter(1)
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    get_column_letter(1)
NameError: name 'get_column_letter' is not defined
>>> 
=============================== RESTART: Shell ===============================
>>> import openpyxl
f
>>> 
=============================== RESTART: Shell ===============================
>>> import openpyxl
>>> from openpyxl.cell import get_column_letter
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    from openpyxl.cell import get_column_letter
ImportError: cannot import name 'get_column_letter' from 'openpyxl.cell' (C:\Users\james\AppData\Roaming\Python\Python37\site-packages\openpyxl\cell\__init__.py)

Well, apparently the Automate the Boring Stuff with Python is a little out of date now!  According to a StackOverflow contributor,

The function get_column_letter has been relocated in Openpyxl version 2.4 from openpyxl.cell to openpyxl.utils.
The current import is: from openpyxl.utils import get_column_letter
The .utils instead of .cell directory worked. 

No comments:

Post a Comment

Web Development: Organizing Files and Folders

When you begin to build your website, it's a very clever idea to organize  your files and folders efficiently. You should have: A ...