Create logging filename not work

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
DMD-OL
User
Beiträge: 315
Registriert: Samstag 26. Dezember 2015, 16:21

hey
ich habe mir ein tutorial über logging angeschaut: https://www.youtube.com/watch?v=-ARI4Cz-awo
ich benutzte python 2.7 mit pyscripter 2.6.
im tutorial wird ein logging file erstellt, bei mir jedoch nicht.
kann mir jmd helfen, weshalb das bei mir nicht funktioniert? (--> benutzt der ne andere python version?)
mein code (wie im tutorial):

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging

# DEBUG	    Detailed information, typically of interest only when diagnosing problems.

# INFO	    Confirmation that things are working as expected.

# WARNING	An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’).
#           The software is still working as expected.

# ERROR	    Due to a more serious problem, the software has not been able to perform some function.

# CRITICAL	A serious error, indicating that the program itself may be unable to continue running.

logging.basicConfig(filename = 'Test_Logging.log', level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(message)s')

def add(x, y):
    # Adding Function
    return x + y

def subtract(x, y):
    # Subtract Function
    return x - y

def multiply(x, y):
    # Multiply Function
    return x * y

def divide(x, y):
    # Divide Function
    return x / y

num1 = 10
num2 = 5

add_result = add(num1, num2)
logging.debug("Add: {} + {} = {}".format(num1, num2, add_result))

subtract_result = subtract(num1, num2)
logging.debug("Subtract: {} - {} = {}".format(num1, num2, subtract_result))

multiply_result = multiply(num1, num2)
logging.debug("Multiply: {} * {} = {}".format(num1, num2, multiply_result))

divide_result = divide(num1, num2)
logging.debug("Divide: {} / {} = {}".format(num1, num2, divide_result)
Benutzeravatar
sls
User
Beiträge: 480
Registriert: Mittwoch 13. Mai 2015, 23:52
Wohnort: Country country = new Zealand();

Mal von dem Syntax-Error in der letzten Zeile abgesehen scheint das wohl mit Pyscripter zusammen zu hängen (bei mir funktioniert o.g. Script mit Python 2.7 und 3.7), schau' mal hier: https://stackoverflow.com/questions/172 ... pyscripter

Vielleicht hilft das.
When we say computer, we mean the electronic computer.
__deets__
User
Beiträge: 14539
Registriert: Mittwoch 14. Oktober 2015, 14:29

Also abgesehen von dem gruseligen Code - die log Aufrufe nicht in, sondern nach den Funktionen, Code auf modulebene der ausgeführt wird - funktioniert das wie gewünscht. Ich wette, du führst das über eine IDE aus & bist dir nicht im Klaren, wo das working directory ist. Womit der relative Pfad nicht da ist, wo du denkst, das er ist. Mach ihn absolut, oder such an der richtigen Stelle.

Edit: hast du ja geschrieben, pyscripter. Wie gesagt, working directory beachten.
Antworten