LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-25-2017, 12:56 AM   #1
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 18.04
Posts: 1,893

Rep: Reputation: 69
python


Don't laugh, but I thought, useless as I am at computing, I would try to learn some Python. I have the book 'Automate the Boring Stuff' from Al Sweigart.

I have asked on https://python-forum.io/Thread-using...23494#pid23494
but no one seems to know.

I use Ubu 16.04 and Python 3.5. On page 269 of the book it talks about manipulating Excel files. I keep getting an error when I try this in the interactive shell.

Quote:
>>> anotherSheet.get_highest_row()
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
anotherSheet.get_highest_row()
AttributeError: 'Worksheet' object has no attribute 'get_highest_row'
>>> anotherSheet.get_highest_column()
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
anotherSheet.get_highest_column()
AttributeError: 'Worksheet' object has no attribute 'get_highest_column'
>>>
Other things work, like:

Quote:
>>> import openpyxl
>>> import os
>>> os.chdir('/home/pedro/myPython/examplesPythonworking')
>>> os.getcwd()
'/home/pedro/myPython/examplesPythonworking'
>>> wb = openpyxl.load_workbook('examples.xlsx')
>>> wb.get_sheet_names()
['Sheet1', 'Sheet2', 'Sheet3']
>>> sheet = wb.get_sheet_by_name('Sheet3')
>>> sheet
<Worksheet "Sheet3">
>>> type(sheet)
<class 'openpyxl.worksheet.worksheet.Worksheet'>
>>> sheet.title
'Sheet3'
>>> anotherSheet = wb.get_active_sheet()
>>> anotherSheet
<Worksheet "Sheet1">
>>> sheet['A1']
<Cell 'Sheet3'.A1>
>>> anotherSheet['A1']
<Cell 'Sheet1'.A1>
>>> anotherSheet['A1'].value
1
>>> for i in range(1, 8, 2):
print(i, anotherSheet.cell(row=i, column=2).value)


1 apples
3 bananas
5 peaches
7 chirimoyas
so it is not all gloom and doom. People here at linuxquestions are pretty clued up. Does anyone know why this method won't give me the maximum row or column?
 
Old 08-25-2017, 09:29 AM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Don't know if this will help, but using ipython3 calling get_highest_row() returns a warning:
Code:
In [12]: print(sheet.get_highest_row())
/usr/lib/python3/dist-packages/openpyxl/worksheet/worksheet.py:347: UserWarning: Call to deprecated function or class get_highest_row (Use the max_row property).
  def get_highest_row(self):
41

In [13]: print(sheet.max_row)
41
Does max_row work?
 
Old 08-25-2017, 06:36 PM   #3
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 18.04
Posts: 1,893

Original Poster
Rep: Reputation: 69
You're a genius! Thanks!

Quote:
>>> import openpyxl
>>> wb = openpyxl.load_workbook('/home/pedro/myPython/examplesPythonworking/examples.xlsx')
>>> type(wb)
<class 'openpyxl.workbook.workbook.Workbook'>
>>> wb.get_sheet_names()
['Sheet1', 'Sheet2', 'Sheet3']
>>> sheet = wb.get_active_sheet()
>>> sheet
<Worksheet "Sheet1">
>>> sheet.max_row()
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
sheet.max_row()
TypeError: 'int' object is not callable
>>> str('sheet.max_row')
'sheet.max_row'
>>> str(sheet.max_row)
'7'
>>>
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Python tricks for artists: How to add interactivity to any Python script LXer Syndicated Linux News 0 03-16-2017 06:12 PM
I got error while installing python-tk python-psycopg2 python-twisted saili kadam Linux - Newbie 1 09-05-2015 03:03 AM
LXer: Python wins trademark dispute, rival stops calling itself “Python” LXer Syndicated Linux News 0 03-21-2013 07:40 PM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
LXer: Review: Programming in Python 3: A Complete Introduction to the Python Language LXer Syndicated Linux News 0 01-26-2009 04:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration