f



logging: AttributeError: 'module' object has no attribute 'getLogger'

Hi all:

Being completely new to Python still (just about a week into it now) I
tried to follow the Python 2.6.5 version documemtation aiming at setting
up a logger as follows:

<code>

import logging

global gPIBLogger

class PIBLogger(object):
    '''
    TODO: classdocs
    '''

    def __init__(self, logFileName):
        '''
        Constructor
        '''
        self.logFileName = logFileName
        self.logger = logging.getLogger('PIBLogger')
        self.logger.setLevel(logging.DEBUG)
        handler = logging.handlers.RotatingFileHandler(self.logFileName, 
                                                       maxBytes=1000000,
                                                       backupCount=9)
        self.logger.addHandler(handler)
        gPIBLogger = self.logger
               
        
def main():
    mylogger = PIBLogger('/tmp/pib.log')
    gPIBLogger.debug(' Hi ')
   
if __name__ == "__main__":
    main()

</code>

When trying to execute main() I get:

Traceback (most recent call last):
  File "/.../src/pib/logging.py", line 37, in <module>
    main()
  File "/.../src/pib/logging.py", line 33, in main
    mylogger = PIBLogger('/tmp/pib.log')
  File "/...src/pib/logging.py", line 23, in __init__
    self.logger = logging.getLogger('PIBLogger')
AttributeError: 'module' object has no attribute 'getLogger'

I double checked and yes, getLogger is there. Why is the interpreter
asking for an "attribute" here ? Any hints on what I am doing wrong ?

TIA!

Regards

  Frank
0
Frank
5/23/2010 1:46:48 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

5 Replies
4569 Views

Similar Articles

[PageSpeed] 54

On 23 May 2010 14:46, Frank GOENNINGER <dg1sbg@googlemail.com> wrote:
> Traceback (most recent call last):
> =C2=A0File "/.../src/pib/logging.py", line 37, in <module>
> =C2=A0 =C2=A0main()

Here's a clue - looks like your own module is called logging. That's
what's getting imported by your import. Try naming your module
something else, and you should be golden.

--=20
Cheers,
Simon B.
0
Simon
5/23/2010 2:04:01 PM
Frank GOENNINGER <dg1sbg@googlemail.com> wrote:

> 
> When trying to execute main() I get:
> 
> Traceback (most recent call last):
>   File "/.../src/pib/logging.py", line 37, in <module>
>     main()
>   File "/.../src/pib/logging.py", line 33, in main
>     mylogger = PIBLogger('/tmp/pib.log')
>   File "/...src/pib/logging.py", line 23, in __init__
>     self.logger = logging.getLogger('PIBLogger')
> AttributeError: 'module' object has no attribute 'getLogger'
> 
> I double checked and yes, getLogger is there. Why is the interpreter
> asking for an "attribute" here ? Any hints on what I am doing wrong ?
> 
You're source file appears to be called logging.py, so when you do 'import 
logging' it just imports itself. The system logging.py has a getLogger 
function, but *your* logging.py doesn't.
0
Duncan
5/23/2010 2:06:22 PM
On May 23, 2010, at 9:46 AM, Frank GOENNINGER wrote:

>
> Hi all:
>
> Being completely new to Python still (just about a week into it now) I
> tried to follow the Python 2.6.5 version documemtation aiming at  
> setting
> up a logger as follows:
>
> <code>
>
> import logging
>
> global gPIBLogger
>
> class PIBLogger(object):
>    '''
>    TODO: classdocs
>    '''
>
>    def __init__(self, logFileName):
>        '''
>        Constructor
>        '''
>        self.logFileName = logFileName
>        self.logger = logging.getLogger('PIBLogger')
>        self.logger.setLevel(logging.DEBUG)
>        handler =  
> logging.handlers.RotatingFileHandler(self.logFileName,
>                                                        
> maxBytes=1000000,
>                                                       backupCount=9)
>        self.logger.addHandler(handler)
>        gPIBLogger = self.logger
>
>
> def main():
>    mylogger = PIBLogger('/tmp/pib.log')
>    gPIBLogger.debug(' Hi ')
>
> if __name__ == "__main__":
>    main()
>
> </code>
>
> When trying to execute main() I get:
>
> Traceback (most recent call last):
>  File "/.../src/pib/logging.py", line 37, in <module>
>    main()
>  File "/.../src/pib/logging.py", line 33, in main
>    mylogger = PIBLogger('/tmp/pib.log')
>  File "/...src/pib/logging.py", line 23, in __init__
>    self.logger = logging.getLogger('PIBLogger')
> AttributeError: 'module' object has no attribute 'getLogger'
>
> I double checked and yes, getLogger is there. Why is the interpreter
> asking for an "attribute" here ? Any hints on what I am doing wrong ?


Short answer: Change the name of src/pib/logging.py to something else.

Long answer: When Python hits the line "import logging", it first  
looks in the current directory and imports logging.py, which in this  
case is the file it's already executing. It never finds the standard  
library's logging module.

One way you could have figured this out would be to add this as the  
first line of main():
    print dir(logging)

That would have told you what Python thought the logging module looked  
like, and would have perhaps recognized it as your own.

Cheers
Philip



1
Philip
5/23/2010 2:07:12 PM
Simon Brunning <simon@brunningonline.net> writes:

> On 23 May 2010 14:46, Frank GOENNINGER <dg1sbg@googlemail.com> wrote:
>> Traceback (most recent call last):
>> �File "/.../src/pib/logging.py", line 37, in <module>
>> � �main()
>
> Here's a clue - looks like your own module is called logging. That's
> what's getting imported by your import. Try naming your module
> something else, and you should be golden.

Yep. That was it. Thanks !!

Cheers
  Frank
0
Frank
5/24/2010 9:55:46 AM
Philip Semanchuk <philip@semanchuk.com> writes:

> On May 23, 2010, at 9:46 AM, Frank GOENNINGER wrote:
>>
>> I double checked and yes, getLogger is there. Why is the interpreter
>> asking for an "attribute" here ? Any hints on what I am doing wrong ?
>
>
> Short answer: Change the name of src/pib/logging.py to something else.

Done.

> Long answer: When Python hits the line "import logging", it first
> looks in the current directory and imports logging.py, which in this
> case is the file it's already executing. It never finds the standard
> library's logging module.
>
> One way you could have figured this out would be to add this as the
> first line of main():
>    print dir(logging)
>
> That would have told you what Python thought the logging module looked
> like, and would have perhaps recognized it as your own.

Thanks - learned a lot from your post.

>
> Cheers
> Philip

Cheers
  Frank
0
Frank
5/24/2010 10:00:46 AM
Reply:

Similar Artilces:

PyKota, Python: AttributeError: 'module' object has no attribute '_quote'
Hello everyone, I'm new to linux/suse, but I was given the task to install the print accounting software PyKota. Before that I never even touched a linux system, so I don't have any basic knowlegde at all! Up to now I was able to solve all problems with the help of google, but now I'm stuck. My problem: linux-6n5c:/usr/local/bin # pkusers --add john paul Creation... ERROR: PyKota v1.26_official ERROR: pkusers failed ERROR: Traceback (most recent call last): ERROR: File "/usr/local/bin/pkusers", line 442, in <module> ERROR: retco...

python+libxml2+scrapy AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER'
Hello. Has anybody already meet the problem like this? - AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' When I run scrapy, I get File "/usr/local/lib/python2.7/site-packages/scrapy/selector/factories.py", line 14, in <module> libxml2.HTML_PARSE_NOERROR + \ AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' When I run python -c 'import libxml2; libxml2.HTML_PARSE_RECOVER' I get Traceback (most recent call last): File "<string>", line 1, in <module...

AttributeError: 'module' object has no attribute 'letters'
what does this error mean? i am trying to use mark hammonds win32 package. Traceback (most recent call last): File "aui2.py", line 11, in <module> import win32com.client File "C:\Python25\lib\site-packages\win32com\client\__init__.py", line 12, in <module> import dynamic, gencache, pythoncom File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 24, in <module> import build File "C:\Python25\lib\site-packages\win32com\client\build.py", line 507, in <module> valid_identifier_chars = string.le...

AttributeError: 'module' object has no attribute 'urlopen'
Hey, I am trying to run the following example from diveintopython import urllib sock = urllib.urlopen("http://diveintopython.org/") htmlSource = sock.read() sock.close() print htmlSource I have Python 2.3.3 but when i run the above code I get the following error: raceback (most recent call last): File "urllib.py", line 1, in ? import urllib File "/home/shalen/programming/python/tutorials/py/urllib.py", line 2, in ? sock = urllib.urlopen("http://diveintopython.org/") AttributeError: 'module' object has no attribute 'urlopen' Anyone knows how to fix this and why I am getting this error? Thanks Dont ~ ~ ~ ~ __________________________________ Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools dont bother wrote: > import urllib > sock = urllib.urlopen("http://diveintopython.org/") > htmlSource = sock.read() > sock.close() > print htmlSource > > I have Python 2.3.3 but when i run the above code I > get the following error: > > raceback (most recent call last): > File "urllib.py", line 1, in ? > import urllib > File > "/home/shalen/programming/python/tutorials/py/urllib.py", > line 2, in ? > sock = > urllib.urlopen("http://diveintopython.org/") > AttributeError: 'module' object has no attribute > 'urlopen' > This is a name cl...

AttributeError: 'module' object has no attribute 'pack'
Dear List, I have a freshly installed opensuse 11.2 and I am experiencing the following problem with the module "subprocess": sampsa@linux-912g:~> python Python 2.6 (r26:66714, Feb 3 2009, 20:52:03) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/subprocess.py", line 404, in <module> import p...

AttributeError: 'module' object has no attribute '__path__'
I am using Jupyter notebooks, with Python 3.4. The error below references t= he Anaconda distribution package. This error occurred quite precipitously (= only 2 minutes before I was able to import the modules). I am using Windows= 7. My path in the console uses Python27. I also have python 34 as well. I = am not sure where to start modifying the path and fear that I will break my= initial setup. I welcome feedback on next steps. --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) ...

AttributeError: 'module' object has no attribute 'fork'
Hi, Code: import os, time def child(pipeout): zzz = 0 while True: time.sleep(zzz) msg = ('Spam %03d' % zzz).encode() os.write(pipeout, msg) zzz = (zzz+1) % 5 def parent(): pipein, pipeout = os.pipe() if os.fork() == 0: child(pipeout) else: while True: line = os.read(pipein, 32) print('Parent %d got [%s] at %s' % (os.getpid(), line, time.time())) parent() Output: Traceback (most recent call last): File "C:/Python34/pipe1.py", line 17, in <module>...

AttributeError: 'module' object has no attribute 'HTTPSHandler'
Hi I built and installed python 2.5 from source and when I do this: opener = urllib2.build_opener(SmartRedirectHandler(), DefaultErrorHandler(), urllib2.HTTPSHandler()) I get this error. AttributeError: 'module' object has no attribute 'HTTPSHandler' What should I do? ...

AttributeError: 'module' object has no attribute 'setdefaulttimeout'
I get those errors when I run: /usr/local/bin/SquidClamAV_Redirector.py -c /etc/squid/SquidClamAV_Redirector.conf ################## Traceback (most recent call last): File "/usr/local/bin/SquidClamAV_Redirector.py", line 573, in ? redirector = SquidClamAV_Redirector(config) File "/usr/local/bin/SquidClamAV_Redirector.py", line 145, in __init__ self.__start_urlhandler__() File "/usr/local/bin/SquidClamAV_Redirector.py", line 454, in __start_urlhandler__ urllib.socket.setdefaulttimeout(self.timeout) AttributeError: 'module' object has no attribute 'setdefaulttimeout' ################# the line that is the problem looks like this: ############# urllib.socket.setdefaulttimeout(self.timeout) ############# from the global sintax: ############## def __start_urlhandler__(self): """ create the urlhandler object """ # set timeout urllib.socket.setdefaulttimeout(self.timeout) self.urlhandler = urllib.URLopener() if self.proxy != {}: self.urlhandler.proxies = self.proxy self.urlhandler.addheaders = [('User-agent', ModuleName + ' ' + str(version))] ############## can you give me a hint with this matter? adrian wrote: > urllib.socket.setdefaulttimeout(self.timeout) > AttributeError: 'module' object has no attribute 'setdef...

AttributeError: ' ' object has no attribute ' '
I am using Ubuntu 12.10, and Python 2.7.3, GNU Radio Companion v3.6.3. I get the this error in terminal: in __init__ self.wxgui_waterfallsink2_0.set_callback(wxgui_waterfallsink2_0_callback) File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", line 54, in __getattr__ return getattr(self._hb, name) AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback' I have been getting this error in multiple programs. So what is stopping the program here? There is no Attribute .set_callback obviously. But where is t...

'is not' or '!='
A newbie question to you; what is the difference between statements like: if x is not None: and if x != None: Without any context, which one should be preferred? IMHO, the latter is more readable. On 2014-08-18 21:35, ElChino wrote: > A newbie question to you; what is the difference between statements > like: > if x is not None: > and > if x != None: > > Without any context, which one should be preferred? > IMHO, the latter is more readable. > "x == y" tells you whether x and y refer to objects that are equal. "x is y" tells you whether x and y actually refer to the same object. In the case of singletons like None (there's only one None object), it's better to use "is". "ElChino" <elchino@cnn.cn>: > A newbie question to you; what is the difference between statements > like: > if x is not None: > and > if x != None: Do the following: take two $10 bills. Hold one bill in the left hand, hold the other bill in the right hand. Now, the bill in the left hand "is not" the bill in the right hand. However, the bill in the left hand "==" the bill in the right hand. > Without any context, which one should be preferred? > IMHO, the latter is more readable. In almost all cases, both tests would result in the same behavior. However, the "is not" test is conceptually the correct one since you want...

'^=' and '~='?
Hello, What is the difference between '^=' and '~='? Thanks, Duckhye ...

AttributeError: 'Attributes' object has no attribute 'saveFile'
Not sure how to explain, but I'll try my best. I'm making a GUI with wxGlade. The GUI has windows that open when the "Next Page" button is pushed; the button also pickles the information that is input into the frame at the same time. The saveFile name is autocreated based on the data entered by the user in the first frame. Each frame that is created is a new class, e.g. the first frame that opens is "CharInfo", which opens the frame "Attributes". The pickling works for the first frame but doesn't work for the ones after. Apparently the saveFile at...

AttributeError: 'module' object has no attribute 'DatagramHandler' (ubuntu-8.10, python 2.5.2)
$ ~/devel/ice/snoip/freespeech$ python Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import logging >>> logging.DatagramHandler Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'DatagramHandler' >>> That is odd since the documentation says there is DatagramHandler for module logging On Mon, Dec 29, 2008 at 4:08 AM, Tz...

AttributeError: 'Or' object has no attribute 'as_independent'
Traceback (most recent call last): File "testcsv.py", line 17, in <module> print(sy.solve([x^2+x+1-t, x^3+x^2-t], x)) File "C:\Python27\lib\site-packages\sympy\solvers\solvers.py", line 902, in so lve solution = _solve_system(f, symbols, **flags) File "C:\Python27\lib\site-packages\sympy\solvers\solvers.py", line 1434, in _ solve_system i, d = _invert(g, *symbols) File "C:\Python27\lib\site-packages\sympy\solvers\solvers.py", line 2422, in _ invert indep, dep = lhs.as_independent(*symbols) AttributeError: 'Or' object has no attribute 'as_independent' Code: import csv as csv import os import numpy as np import sympy as sy #from sympy import solve, Poly, Eq, Function, exp from sympy import * from numpy import * from numpy.linalg import * from sympy.polys.polyfuncs import interpolate from sympy import Function, dsolve, Eq, Derivative, sin, cos from sympy.abc import x f = sy.Function('f') x = sy.Symbol("x") t = sy.Symbol("t") print(sy.solve([x^2+x+1-t, x^3+x^2-t], x)) print(sy.solve((x^2+x+1-t, x^3+x^2-t), x)) On 2/13/2014 4:03 AM, wilsonmonde@gmail.com wrote: > Traceback (most recent call last): > File "testcsv.py", line 17, in <module> > print(sy.solve([x^2+x+1-t, x^3+x^2-t], x)) > File "C:\Python27\lib\site-packages\sympy\solvers\solvers.py", line 902, in so > lve ...

'module' object has no attribute 'ssl'
Hi, I have Red Hat Linux 3.2.3-54 and Python 2.4.3 (the original version downloaded from python.org) and I'm using httplib to make a request to an external server, this is the code I'm using: import httplib https = httplib.HTTPSConnection('216.220.59.211', 7989) https.debuglevel = 1 body = buildXML(data) try: https.request('POST', '/Messenger/XMLMessenger', body) response = https.getresponse() response = response.read() https.close() except: response = None import traceback traceback.print_exc() return response And I get the following...

When I do from lxml import etree I've this error : AttributeError: 'module' object has no attribute 'BytesIO'
Hi, I'm on Ubuntu 8.04.1 I've installed lxml with easy_install lxml command. Now, when I load etree I've this error : $ python Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from lxml import etree Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lxml.etree.pyx", line 40, in lxml.etree (src/lxml/ lxml.etree.c:119415) AttributeError: 'module&#...

weird exception : AttributeError: 'module' object has no attribute 'logException'
I am running a script (summary.py) which is calling the method logException in another module ( pytool). Yesterday, ard 18:50, all of a sudden summary.py was throwing the exception : AttributeError: 'module' object has no attribute 'logException' What I did to fix it was to delete the compiled version of the pytool and run again. And it worked again. I am now trying to understand what happened, working with the network admin to see who modified the direcory where pytool is stored. But do you have any idea of what could have happened? All the imports are working, but no method could be called on the compiled files. Thanks for your help, N. ...

ATTRIBUTE ERROR: 'module' object has no attribute 'ssl'
I am getting the following errors: File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in _send_output self.send(msg) File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in send self.connect() File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 1073, in connect ssl = socket.ssl(sock, self.key_file, self.cert_file) AttributeError: 'module' object has no attribute 'ssl' Thank You in Advance johnny wrote: > I am getting the following errors: That is *one* error. > > File "H:\xampp\xampp\xam...

v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal'
Hi, I try to run a terminal emulation using Python+Gtk+Vte. Before develop my own sources, i'm testing some examples like this ; http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20terminal.html But when i try to run, i get this message error; v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' I'm using ubuntu 9.10 karmic. I've installed (apt-get) python-gtk, /2, -dev, libvte... Anyone know if there's a bug on this using karmic, or i must to download and compile gtk/vte from sources? thanks, S...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal''''''''''''''
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; _____________________________________________________ SELECT "criteria" FROM "criteria" WHERE "criteria" UPDATE/APPEND "field selections" RecordSource "qryExample" = above text strings" _______________________________________________________________________ When i am running a SELECT query in this manner it works fine with no problems, and accepts the values of specified linked for...

AttributeError: 'list' object has no attribute 'lower'
On page 77 of the book natural language processing with Python, we have such an exercise: The polysemy of a word is the number of senses it has. Using WordNet, we can determine that the noun doghas seven senses with len(wn.synsets('dog', 'n')). Compute the average polysemy of nouns, verbs, adjectives, and adverbs according to WordNet.http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html I wrote the following function to solve it. However, it pops up "AttributeError: 'list' object has no attribute 'lower'". Quite confused, I supposed [synset.lemm...

AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'
------=_Part_1122770_31157900.1360876583037 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit I am using ubuntu 12.10 and python version 2.7.3. i run the following command in terminal: matt@matt-Inspiron-1525:~$ python -m trace --count -C . op25_grc.py Here is the output with an error: Imported legacy fsk4 Using Volk machine: ssse3_32 Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _...

AttributeError: 'function' object has no attribute 'split'
PathList= string.split(FullPath, "/") is generating the above error message. when I run my script, but works just fine from the python command line! What gives? "Earl" <eee@nmt.edu> wrote in message news:11e5f362.0405060845.16fff0f8@posting.google.com... > PathList= string.split(FullPath, "/") is generating the above error > message. when I run my script, but works just fine from the python > command line! What gives? Somehow you've bound the name "string" to a function e.g. >>> def string(): .... return 'help' ...

Web resources about - logging: AttributeError: 'module' object has no attribute 'getLogger' - comp.lang.python

Resources last updated: 3/8/2016 5:17:24 AM