mx Oddity in FC3/RedHat ES

Discussion in 'Python' started by Eric Azarcon, Dec 20, 2004.

  1. Eric Azarcon

    Eric Azarcon Guest

    Hello!

    I've installed the mx package from egenix, and I am experiencing pretty
    odd behaviour.

    If I launch python and run the following commands, I get an error:

    >>> import mx
    >>> from mx import *
    >>> mx.DateTime.today()

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    AttributeError: 'module' object has no attribute 'DateTime'


    OK, great. However, if I then ask for help on the mx package first, the
    above command will work.

    >>> help()

    help> modules
    -- list of modules --
    help> mx
    -- displays mx info --
    help> mx.DateTime
    -- displays mx.DateTime info --
    help> --quit help here --
    >>> mx.DateTime.today()

    <DateTime object for '2004-12-20 00:00:00.00' at 984a1b8>

    Any ideas what is going on? Is there a path problem that gets resolved
    by calling help()?

    Note that issuing help(mx) doesn't work. You have to go into help, do
    the modules listing and then ask for mx.

    This same behaviour is displayed on my Fedora Core 3 box running
    mx-2.0.5-3, and on 2 separate machines running RHEL-ES (most recent
    version with updates applied) and egenix-mx-base-2.0.6-py2.2_1.

    Any help would be very appreciated!

    Thanks,

    Eric

    p.s. the background is that I need to use mx because the target boxes
    only have Python 2.2 on them. Using DateTime from Python 2.3 would be
    preferred, but being a newbie, I have no idea how to compile just that
    module from source and install it into 2.2. *sigh*
     
    Eric Azarcon, Dec 20, 2004
    #1
    1. Advertising

  2. Eric Azarcon

    Steve Holden Guest

    Eric Azarcon wrote:

    > Hello!
    >
    > I've installed the mx package from egenix, and I am experiencing pretty
    > odd behaviour.
    >
    > If I launch python and run the following commands, I get an error:
    >
    >
    >>>>import mx
    >>>>from mx import *
    >>>>mx.DateTime.today()

    >

    Well,

    from anything import *

    is bad form for any module unless (like Tkinter, for example) it's been
    specifically designed to support this behavior. Since "the mx package"
    is actually a number of inter-dependent packages you are almost
    guaranteeing trouble here.

    mx is not designed to be imported, it's just a common namespace for a
    number of modules by the same author.

    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > AttributeError: 'module' object has no attribute 'DateTime'
    >

    Try:

    Python 2.4 (#1, Dec 4 2004, 20:10:33)
    [GCC 3.3.3 (cygwin special)] on cygwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import mx.DateTime as dt
    >>> dt.today()

    <DateTime object for '2004-12-20 00:00:00.00' at a0d85e0>
    >>>

    >
    > OK, great. However, if I then ask for help on the mx package first, the
    > above command will work.
    >
    >
    >>>>help()

    >
    > help> modules
    > -- list of modules --
    > help> mx
    > -- displays mx info --
    > help> mx.DateTime
    > -- displays mx.DateTime info --
    > help> --quit help here --
    >
    >>>>mx.DateTime.today()

    >
    > <DateTime object for '2004-12-20 00:00:00.00' at 984a1b8>
    >
    > Any ideas what is going on? Is there a path problem that gets resolved
    > by calling help()?
    >
    > Note that issuing help(mx) doesn't work. You have to go into help, do
    > the modules listing and then ask for mx.
    >

    Well, the help system actually imports the subpackages that live in the
    mx space when you ask for help about them. So that's why doing that
    allows you to resolve those names.

    > This same behaviour is displayed on my Fedora Core 3 box running
    > mx-2.0.5-3, and on 2 separate machines running RHEL-ES (most recent
    > version with updates applied) and egenix-mx-base-2.0.6-py2.2_1.
    >
    > Any help would be very appreciated!
    >

    It's just a matter of using the packages in the intended way.

    > Thanks,
    >

    No problem.

    > Eric
    >
    > p.s. the background is that I need to use mx because the target boxes
    > only have Python 2.2 on them. Using DateTime from Python 2.3 would be
    > preferred, but being a newbie, I have no idea how to compile just that
    > module from source and install it into 2.2. *sigh*


    Well the first thing to try would be dropping it into /usr/lib/python2.2
    and seeing if you can import it without errors. You might actually find
    that the built-in "time" module contains enough date/time functionality
    for your needs if they are simple.

    regards
    Steve
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/
    Holden Web LLC +1 703 861 4237 +1 800 494 3119
     
    Steve Holden, Dec 20, 2004
    #2
    1. Advertising

  3. Eric Azarcon

    Eric Azarcon Guest

    In article <dNBxd.57044$Jk5.33616@lakeread01>, Steve Holden
    <> wrote:

    > from anything import *
    >
    > is bad form for any module unless (like Tkinter, for example) it's been


    Ah, I see. Thank you. Is there any reference, or way for me to
    determine whether something can/should be imported in this manner? As a
    newbie, looking for this information is sorta tough. I only used
    from mx import *
    because i found a reference to doing it this way elsewhere on the web.

    I also use from stat import * to get at the ST_CTIME constant. Is that
    a module that supports this, or is there a better way?

    > >>> import mx.DateTime as dt
    > >>> dt.today()

    > <DateTime object for '2004-12-20 00:00:00.00' at a0d85e0>


    Awesome! Thanks, that's what I needed.

    > Well, the help system actually imports the subpackages that live in the
    > mx space when you ask for help about them. So that's why doing that
    > allows you to resolve those names.


    Makes sense.

    > It's just a matter of using the packages in the intended way.


    Thanks! I tried to look on the egenix website for usage info, but it
    just had API info.

    The odd thing is that Egenix has an EXAMPLES link on their page. If you
    scroll down and look at the actual code examples, you'll see that it
    starts out FROM blah IMPORT *. So, you can understand why I did it that
    way. I prolly didn't do it deep enough (stopped at mx instead of
    mx.blah).

    > Well the first thing to try would be dropping it into /usr/lib/python2.2
    > and seeing if you can import it without errors. You might actually find
    > that the built-in "time" module contains enough date/time functionality
    > for your needs if they are simple.


    My needs are pretty simple. Maybe you can point me in the right
    direction. I need to compare the creation time of a file with a date,
    and determine if I need to delete it. I know how to use stat to get the
    file creation time. I can get the current time. If I subtract the file
    ctime from the current time, how do i turn that delta into days?

    Thanks for all your help!

    Eric
     
    Eric Azarcon, Dec 20, 2004
    #3
  4. Eric Azarcon

    Steve Holden Guest

    Eric Azarcon wrote:

    [...]
    >
    >
    > My needs are pretty simple. Maybe you can point me in the right
    > direction. I need to compare the creation time of a file with a date,
    > and determine if I need to delete it. I know how to use stat to get the
    > file creation time. I can get the current time. If I subtract the file
    > ctime from the current time, how do i turn that delta into days?
    >


    sholden@dellboy ~
    $ python
    Python 2.4 (#1, Dec 4 2004, 20:10:33)
    [GCC 3.3.3 (cygwin special)] on cygwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from stat import ST_CTIME
    >>> from os import stat
    >>> s = stat("xmlpractical.txt")
    >>> s

    (33279, 1407374883881497L, 1410850211L, 1, 544, 513,
    5859L, 1103556876, 1102382453, 1102292631)
    >>> ctime = s[ST_CTIME]
    >>> ctime

    1102292631
    >>> import time
    >>> print "File was created", (time.time() - ctime)/(3600*24), "days ago"

    File was created 14.6398609114 days ago

    Does this do it?

    regards
    Steve
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/
    Holden Web LLC +1 703 861 4237 +1 800 494 3119
     
    Steve Holden, Dec 20, 2004
    #4
    1. Advertising

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. U. George
    Replies:
    4
    Views:
    863
    U. George
    Aug 11, 2005
  2. York

    Run VPython on FC3

    York, Sep 16, 2005, in forum: Python
    Replies:
    3
    Views:
    333
    Artur M. Piwko
    Sep 23, 2005
  3. Jim Van Fleet

    Gem install problem on FC3

    Jim Van Fleet, Mar 7, 2005, in forum: Ruby
    Replies:
    1
    Views:
    99
    Jim Van Fleet
    Mar 7, 2005
  4. Ross
    Replies:
    1
    Views:
    144
    Brian Wakem
    Aug 19, 2005
  5. Mark D Smith

    Template-Toolkit-2.14 fails make on FC3

    Mark D Smith, Aug 27, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    129
    Mark D Smith
    Aug 30, 2005
Loading...

Share This Page