Error in chapter 12, which produces the following "TypeError: 'generator' object is not subscriptable" for the code below.
>>> import openpyxl
>>> wb = openpyxl.load_workbook('example.xlsx')
>>> sheet = wb.active
>>> sheet = wb.active
>>> sheet.columns[1]
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
sheet.columns[1]
TypeError: 'generator' object is not subscriptable
>>>
RESOLUTION:
Create a list for the sheet.colums:
list(sheet.columns)[1] to overcome the generator error - outdated method since python 2 apparently.
Showing posts with label openpyxl. Show all posts
Showing posts with label openpyxl. Show all posts
Trouble Using Pip and Installing Openpyxl
Openpyxl is, according to Automate the Boring Stuff with Python, supposed to be a handy python library which allows programmers to use python programs with Microsoft excel sheets.
But first you need to install pip on your machine.
What is pip?
The first difficulty I had was getting pip to work through my command line. I resolved that issue using paths - as described in this video (https://www.youtube.com/watch?v=Jw_MuM2BOuI).
The next issue I had was with installing openpyxl itself (which you need pip to do). I received the following error:
Eventually, I found a solution on stackoverflow, which suggested using the following:
But first you need to install pip on your machine.
What is pip?
"Pip is a package manager for python packages. A package contains all the files you need for a module. Modules are Python code libraries that you can include in your project". - W3 schools.
The first difficulty I had was getting pip to work through my command line. I resolved that issue using paths - as described in this video (https://www.youtube.com/watch?v=Jw_MuM2BOuI).
The next issue I had was with installing openpyxl itself (which you need pip to do). I received the following error:
"Could not install packages due to an EnvironmentError: [Errno 13] Permission denied:"
"Consider using the `--user` option or check the permissions"
Eventually, I found a solution on stackoverflow, which suggested using the following:
This worked.python -m pip install --user openpyxl
Subscribe to:
Posts (Atom)
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 ...
-
When you begin to build your website, it's a very clever idea to organize your files and folders efficiently. You should have: A ...
-
&& (AND) || (OR) ! (NOT) If you were to find out if two values were true or false, you would use AND. For something to be tr...
-
What are the meanings of the various types of averages in datasets? Mean == the "centre" ("center") of a dataset. ...