4 Replies - 432 Views - Last Post: 08 August 2012 - 03:59 PM Rate Topic: -----

#1 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,689
  • Joined: 13-March 10

Scoping question

Posted 08 August 2012 - 03:30 PM

So, lets say we have the following:


import logging

class Test(object):

    def __init__(self):
        logging.basicConfig(filename = "", level = logging.INFO)
        #some rubbish insert here
               
        
        
a = Test()
logging.info("FINITO Runnito")



The logging bit has been initialized inside the class and when i used it outside the class, it did not complain. It run and saved the log to the file. My question is: is the logging part present all over the current .py file and whether when im doing all the "logging.basicConfig()..." <-- am i actually creating a logging object or i am just getting the module ready to work.

Is This A Good Question/Topic? 0
  • +

Replies To: Scoping question

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2117
  • View blog
  • Posts: 3,242
  • Joined: 21-June 11

Re: Scoping question

Posted 08 August 2012 - 03:43 PM

You're not creating a logging object. If you were creating a logging object, that object would be local to __init__ and you would not be able to use it on line 12.

What is happening is that you're calling the function basicConfig of the module logging. After calling that function the logging system is initialized and you can use the other functions of the logging module (no matter where you call them from).

So as you suspected, you're just getting the module ready to work.
Was This Post Helpful? 1
  • +
  • -

#3 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,689
  • Joined: 13-March 10

Re: Scoping question

Posted 08 August 2012 - 03:46 PM

So just to make it clear, there is no notion of a logging object. It's just the case of initialize the stuff necessary to get it working and make use of it?
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2117
  • View blog
  • Posts: 3,242
  • Joined: 21-June 11

Re: Scoping question

Posted 08 August 2012 - 03:47 PM

Yes.

Or more accurately: There is a notion of Logger objects, but you're not using them in your code.

This post has been edited by sepp2k: 08 August 2012 - 03:48 PM

Was This Post Helpful? 1
  • +
  • -

#5 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,689
  • Joined: 13-March 10

Re: Scoping question

Posted 08 August 2012 - 03:59 PM

ok. i will check that out. thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1