Writing to text file to Log Debug prints



  • I changed the code to this and it started to work...

    class Logger():
        def __init__(self,filename):
            self.filename = 'Debug.txt'#filename
            self.isLogging = True
    
        def write(self,msg):
            if self.isLogging:
                print(msg)
                with open('Debug.txt', 'r') as file:
                    print(file.read())
                with open('Debug.txt', 'a') as file:
                    file.write(msg)
                    file.write("\n")
    

    Unsure why adding a read before that write fixed or maybe the pytrack was just in a weird state that finally got cleared but it's working now.


Log in to reply
 

Pycom on Twitter