Python Forum
beginner level Python:- output XLS spreadsheet instead of using tabulate
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beginner level Python:- output XLS spreadsheet instead of using tabulate
#1
I have a python script that uses the 'print tabulate' to output the data in CLI.
I would like an easy way output to XLS workbook using 'xlwt' instead.

This is the working python script that outputs to 'print tabulate'
#!/usr/bin/env python
################################################################################
# _ ____ ___ _____ _ _ _ _ #
# / \ / ___|_ _| |_ _|__ ___ | | | _(_) |_ #
# / _ \| | | | | |/ _ \ / _ \| | |/ / | __| #
# / ___ \ |___ | | | | (_) | (_) | | <| | |_ #
# ____ /_/ \_\____|___|___|_|\___/ \___/|_|_|\_\_|\__| #
# / ___|___ __| | ___ / ___| __ _ _ __ ___ _ __ | | ___ ___ #
# | | / _ \ / _ |/ _ \ \___ \ / _ | '_ ` _ \| '_ \| |/ _ \/ __| #
# | |__| (_) | (_| | __/ ___) | (_| | | | | | | |_) | | __/\__ \ #
# \____\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|\___||___/ #
# |_| #
################################################################################
# #
# Copyright © 2015 Cisco Systems #
# All Rights Reserved. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
# License for the specific language governing permissions and limitations #
# under the License. #
# #
################################################################################
"""
Simple application that logs on to the APIC and displays all
of the Endpoints.
"""
import acitoolkit.acitoolkit as aci
from tabulate import tabulate


def main():
"""
Main Show Endpoints Routine
:return: None
"""
# Take login credentials from the command line if provided
# Otherwise, take them from your environment variables file ~/.profile
description = ('Simple application that logs on to the APIC'
' and displays all of the Endpoints.')
creds = aci.Credentials('apic', description)
args = creds.get()

# Login to APIC
session = aci.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print('%% Could not login to APIC')
return

# Download all of the interfaces
# and store the data as tuples in a list
data = []
endpoints = aci.Endpoint.get(session)
for ep in endpoints:
epg = ep.get_parent()
app_profile = epg.get_parent()
tenant = app_profile.get_parent()
data.append((ep.mac, ep.ip, ep.if_name, ep.encap,
tenant.name, app_profile.name, epg.name))

# Display the data downloaded
print tabulate(data, headers=["MACADDRESS", "IPADDRESS", "INTERFACE",
"ENCAP", "TENANT", "APP PROFILE", "EPG"])

if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
Reply


Messages In This Thread
beginner level Python:- output XLS spreadsheet instead of using tabulate - by haziebaby - Jan-27-2018, 04:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Counting of rows in Excel Spreadsheet dakrantau 2 1,941 Sep-30-2020, 02:27 AM
Last Post: dakrantau
  How do I write a line of code into an excel spreadsheet using Python code? Emerogork 2 3,153 Feb-07-2018, 06:54 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020