Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:43:52+00:00 2026-06-17T13:43:52+00:00

Now I’m attempting bigger programs, I’d like to use the logging module rather than

  • 0

Now I’m attempting bigger programs, I’d like to use the logging module rather than peppering my code with prints. But I’ve fallen at the first. I have a two page program, added the simplest logging stuff I could, and it didn’t work. So, I ran the example, and it worked. I then dribbled my code into the example line by line, until I found what stopped it. A single trivial import of a near-empty module stops the proper logging behaviour.

# import ntu.dummy
import logging
LOG_FILENAME = 'example_15.log'
print 'before basicconfig'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
print 'before log write'
logging.debug('This message should go to the log file')
print 'after log write'

With # import ntu.dummy, the program runs, prints out the debugs, and deposits the expected .log file, with the expected contents, into the program’s folder. This is true from within IDLE, or directly in the OS.

If I remove the # to allow import ntu.dummy to execute, then the program runs, prints my debugs, but no .log file is created, neither in the program’s folder, nor AFAICS in any other location on the machine.

C:\Python26\Lib\ntu\ contains an __init__.py, and this file dummy.py, which has contents …

def bolleaux():
    """ empty function """
    return None

In place of the import ntu.dummy statement, I can have all sorts of other imports, random, Tkinter, os.path, which don’t cause the logging to fail

Help, what’s going on please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:43:53+00:00Added an answer on June 17, 2026 at 1:43 pm

    Doh!

    The ntu package contains many other single function or single class modules, really for ease of testing and updating. Some of these have come from a friend, so I wasn’t familiar with what was in them. As the width of the package was getting unwieldy, He suggested that in __init__.py I put …

    from modname import ClassName
    

    for each module I have in there, which then brings ClassName into the ntu namespace. This means that when I want to use any of the modules, I just use

    import ntu       # instead of import ntu.modname for each module !
    

    And of course, yes, one of his modules does a logging.basicConfig, at the module level before the class definition. So, even though I only import my module, doing so runs __init__, which imports his module, which snafus subsequent use of logging. Commenting out any link in that chain makes logging work properly.

    I’m not sure that using import in the package is such a huge saving, and it lays me open to nasty side effects like this. So I’m going back to importing from packname.modname for all my modules.

    But I will want to use that dodgy module at some time, so will have to make it safer, or get him to make it safer.

    Many thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now All of this code works fine in Firfox but in IE the divs
Now facebook require to have these options when you want to use bulit-in actions
Now I have a long query and I'd like to alternate with such a
Now layout look like this What I want to achieve is this <style type=text/css>
Now, this may be really stupid. But can we deploy a Java Swing Application
Now my folded lines look like this: +-- 123 lines: doSomeStuff();-------------------------- +-- 345 lines:
Now and again I end up with code along these lines, where I create
Now please excuse me if this is a stupid question - BUT... In my
Now I have read and on this but i am just stuck. Any help
Now I have the following MFC SDI application code,this code comes from my view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.