I'm coding some stuff for parsing an excel file with Python. I've just coded what I pasted you. When I compile it, I've got no error (it's great) but when I put an argument (the file), nothing are printed on the screen.
By the way, I've got an answer. My Excel file will be in the same directory of my program. How can I load it in the code? I mean with a function which takes my argument in the argparse.
My code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
from progress.bar import Bar
import argparse
import tempfile
import os
import signal
import time
__license__ = """<snip>"""
#Color class
RED1 = '\033[31m'
AMARILLO = '\033[33m'
BLUE = '\033[94m'
GREEN = '\033[32m'
OTRO = '\033[36m'
BOLD = '\033[1m'
ENDC = '\033[0m'
#Fonctions
def cls():
os.system(['clear', 'cls'][os.name == 'nt'])
cls()
def signal_handler(signal, frame):
print '\n[!] Interrupted by the user!'
exit()
print (time.strftime("%d/%m/%Y"))
logo = AMARILLO + """
/ ___/ | | | | | _ \ | _ \ | | \ \ / / / ___| | | | | / | | | | \ | |
| |___ | | | | | |_| | | |_| | | | \ \/ / | | | |_| | / /| | | | | \| |
\___ \ | | | | | ___/ | ___/ | | \ / | | | _ | / / | | | | | |\ |
___| | | |_| | | | | | | |___ / / | |___ | | | | / / | | | | | | \ |
/_____/ \_____/ |_| |_| |_____| /_/ \_____| |_| |_| /_/ |_| |_| |_| \_|
""" + ENDC
print (time.strftime("%H:%M:%S"))
print logo
#Main
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--file", required=True,help="Excel File to parse")
ap.add_argument("-o", "--output", required=False, help="Store the results in txt file ")
ap.add_argument("-p", "--parsing", required=False, help="Parsing the Excel file")
args = vars(ap.parse_args())
excel = args["file"]
txt = args["output"]
parsing = args["parsing"]
signal.signal(signal.SIGINT, signal_handler)
if excel == 'file':
tipos =="f";
try:
df = pd.read_excel('Pandas-Example.xlsx', sheetname='Sheet1')
bar = Bar('Processing', max=20)
for i in range(20):
print BOLD + "\nExcel file was loaded !" + ENDC
bar.next()
except:
print RED1 + "Unable to load the Excel file! Make sure the f argument is present as environment variables." + ENDC
bar.finish()