Can someone please look at my script and explain why the data is not being read and entered into my pretty table? Any help is appreciated. Script is below. I am getting an empty pretty table as my output. # Python Standard Library import os from prettytable import PrettyTable myTable = PrettyTable(["Path", "File Size", "Ext", "Format", "Width", "Height", "Type"]) dirPath = input("Provide Directory to Scan:") i f os.path.isdir(dirPath): fileList = os.listdir(dirPath) for eachFile in fileList: try: localPath = os.path.join(dirPath, eachFile) absPath = os.path.abspath(localPath) ext = os.path.splitext(absPath)[1] filesizeValue = os.path.getsize(absPath) fileSize = '{:,}'.format(filesizeValue) except: continue # 3rd Party Modules from PIL import Image imageFile = input("Image to Process: ") try: with Image.open(absPath) as im: # if success, get the details imStatus = 'YES' imFormat = im.format imType = im.mode imWidth = im.size[0] imHeight = im.size[1] #print("Image Format: ", im.format) #print("Image Type: ", im.mode) #print("Image Width: ", im.width) #print("Image Height: ", im.height) except Exception as err: print("Exception: ", str(err)) myTable.add_row([localPath, fileSize, ext, imFormat, imWidth, imHeight, imType]) print(myTable.get_string())
Can someone please look at my script and explain why the data is not being read and entered into my pretty table? Any help is appreciated. Script is below. I am getting an empty pretty table as my output.
# Python Standard Library
import os
from prettytable import PrettyTable
myTable = PrettyTable(["Path", "File Size", "Ext", "Format", "Width", "Height", "Type"])
dirPath = input("Provide Directory to Scan:") i
f os.path.isdir(dirPath):
fileList = os.listdir(dirPath)
for eachFile in fileList:
try:
localPath = os.path.join(dirPath, eachFile)
absPath = os.path.abspath(localPath)
ext = os.path.splitext(absPath)[1]
filesizeValue = os.path.getsize(absPath)
fileSize = '{:,}'.format(filesizeValue)
except:
continue
# 3rd Party Modules from PIL
import Image imageFile = input("Image to Process: ")
try:
with Image.open(absPath) as im: #
if success, get the details imStatus = 'YES'
imFormat = im.format
imType = im.mode
imWidth = im.size[0]
imHeight = im.size[1]
#print("Image Format: ", im.format)
#print("Image Type: ", im.mode)
#print("Image Width: ", im.width)
#print("Image Height: ", im.height)
except Exception as err:
print("Exception: ", str(err))
myTable.add_row([localPath, fileSize, ext, imFormat, imWidth, imHeight, imType])
print(myTable.get_string())
Step by step
Solved in 4 steps with 2 images