RE: log4py confusion

Discussion in 'Python' started by Rob Richardson, Dec 13, 2012.

  1. Thanks for the suggestion, but I don't think that can be it. At least, it's not it on the line you specified. That form, with the target name given as a hard-coded string, is in use in every Python script our company uses. So, set_target() is expecting a file instead of a file name, there must besome implicit conversion going on that creates a file object of the given name before setting the log target to the file.

    On the other hand, it would certainly explain the " 'Unicode' object does not have attribute 'write' " message. A file object would be expected to have an attribute named 'write', while a string object wouldn't.

    The error happens after the target is changed to a file name contained in avariable. Why doesn't that implicit conversion work with a string contained in a variable? Do I have to do an explicit cast of some kind? Or, probably better, I should probably look up how to create a file object so I canpass it in to the set_target() function.

    That's one reason I asked for documentation on log4py: so I could see what methods are available, and what arguments they actually expect.

    Thanks again!


    -----Original Message-----
    From: Python-list [mailto:python-list-bounces+rob.richardson=] On Behalf Of MRAB
    Sent: Thursday, December 13, 2012 2:35 PM
    Subject: Re: log4py confusion

    On 2012-12-13 18:58, Rob Richardson wrote:
    > Greetings!
    > I have finally gotten fed up with all of the Python scripts used in my
    > company that have every parameter hard-coded. I am rewriting one of
    > them to read all of its parameters from an XML file. Then, we can
    > change the XML file to control which database it is using, whether its
    > running in debug mode or not, and various other things. One of the
    > parameters I want the XML file to contain is the name of the script's
    > log file.
    > I have a class named Settings that will contain all the parameters
    > read from the XML file. But if something goes wrong, I want to log
    > it. So, I want to have a Logger object for it to use. I use a
    > hard-coded file name for that. Then, after reading the XML file, I
    > want to create a second Logger object that will be used by the rest of the script.
    > When I try to use the second Logger object, I get an exception
    > complaining that 'unicode' object has no attribute 'write'.
    > The script and the exception messages are below. Can anyone see what
    > I'm doing wrong?

    I think the problem might be that it's expecting a file object, not a file name/path as you have here:


    Rob Richardson, Dec 13, 2012
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. martin f. krafft

    confusion when resetting registers

    martin f. krafft, Aug 18, 2004, in forum: VHDL
    Paul Sereno
    Aug 19, 2004
  2. Peter Hermansson

    Procedures in testbench confusion

    Peter Hermansson, Aug 25, 2004, in forum: VHDL
    Peter Hermansson
    Aug 25, 2004
  3. Rob Richardson

    What replaces log4py under Python 3.2?

    Rob Richardson, Nov 22, 2011, in forum: Python
    Alec Taylor
    Nov 23, 2011
  4. MRAB

    Re: log4py confusion

    MRAB, Dec 13, 2012, in forum: Python
  5. Rob Richardson

    RE: log4py confusion

    Rob Richardson, Dec 13, 2012, in forum: Python
    Rob Richardson
    Dec 13, 2012

Share This Page