Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Composition question
#1
Hi, I'm testing composition, and I don't understand the output in the log file.

Here is the script:

import os
import time
import logging
import datetime


class Logger:
    logging.basicConfig(filename=datetime.datetime.today().strftime("%Y_%m_%d.log"),
                        format='%(asctime)s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        level=logging.INFO)

    @staticmethod
    def log2file(message):
        logging.info(message)


class Folder:
    _path = ''
    _files = []

    def __init__(self, path):
        if not os.path.exists(path):
            message = "folder does not exist"
            raise TypeError(message)

        self.path = path


class Source:
    def __init__(self, path):
        self.path = Folder(path)
        Logger.log2file("{} as source folder added".format(self.path))


class Destination:
    def __init__(self, path):
        self.path = Folder(path)
        Logger.log2file("{} as source folder added".format(self.path))

class XLSBackup:
    pass


s = Source('/home/kz/a')
The output in the log file is like this:
2020-01-07 10:55:56 <__main__.Folder object at 0x7f4af2ff9390> as source folder added

But I expected this:
2020-01-07 10:55:56 /home/kz/a as source folder added
Reply


Messages In This Thread
Composition question - by kerzol81 - Jan-07-2020, 10:00 AM
RE: Composition question - by buran - Jan-07-2020, 10:21 AM
RE: Composition question - by buran - Jan-07-2020, 11:06 AM
RE: Composition question - by kerzol81 - Jan-07-2020, 11:30 AM

Forum Jump:

User Panel Messages

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