I am a beginner in python. I have some problems in my learning, I hope I can find the answer here.
I cancel select file dialog and PyCham show file not found error.
# importing openpyxl module import openpyxl as xl from openpyxl import Workbook from openpyxl.styles import Color, PatternFill, Font, Border from openpyxl.formatting.rule import Rule from openpyxl.styles.differential import DifferentialStyle # importing pandas module import pandas as pd from tkinter import * from tkinter import CENTER from tkinter import ttk from tkinter import filedialog from tkinter.messagebox import showinfo from tkinter import messagebox as msg from pandastable import Table from tkintertable import TableCanvas # importing get filename module import ntpath from pathlib import Path # importing numpy module import numpy as np def openFile(): filepath = filedialog.askopenfilename(initialdir='\\Desktop', title='Check Duplicate', filetypes=(('Excel Files', '*.xlsx'), ('All Files', '*.*'))) df = pd.read_excel(filepath) window = Tk() window.geometry('300x300') window.resizable(False, False) button_choose_file = ttk.Button(window, text='Choose File', command=openFile).pack(ipadx=50, ipady=10, expand=True) window.mainloop()Q1: How to use
if,elseto check that is a empty file path withpandasread?Q2: If my select excel filename is
Student_2020_01_05.xlsx(Format: filename_yyyy_mm_dd.xlsx). How toif,elseto check that is valid file name?