-1

I'm doing a homework assignment and have to create a program that creates a file directory that also uses a catch-exception block. I wanted it to look nice by having the fields all justified so it look like a proper output table, but all of my strings (file names and dates created) have these random apostrophes around them. However, my unjustified string and the justified integer values do not.

My Code:

import os, sys, time

try:
    path="."   
    dirs=os.listdir(path)
except IOError:
    print("Error: can't find file or read data")
else:
    print(repr("FILE").ljust(32), repr("SIZE").ljust(15), repr("DATE CREATED").ljust(30), end=" ")
    print("\n")
    for file in dirs:
        print(repr(file).ljust(30), repr(os.stat(file).st_size).rjust(8), end=' ')
        print("bytes", repr(time.ctime(os.path.getctime(file))).rjust(30))

My Output can be seen here.

  • 1
    Does this answer your question? [Difference between \_\_str\_\_ and \_\_repr\_\_?](https://stackoverflow.com/questions/1436703/difference-between-str-and-repr) – Lambda Fairy Oct 06 '20 at 22:36

1 Answers1

1

Do str(...) instead of repr(...).

>>> repr(123)
'123'
>>> str(123)
'123'
>>> repr("string")
"'string'"
>>> str("string")
'string'
Lambda Fairy
  • 13,814
  • 7
  • 42
  • 68
Gareth Ma
  • 707
  • 4
  • 10