unable to import os

Fredrik Lundh fredrik at pythonware.com
Fri Oct 7 19:15:54 EDT 2005


"ktxn1020" wrote:

> The script ran well independently using Python's Integrated
> Development Environment version 2.4.1. When it is called from Borland
> C++ Builder 5 with python for delphi version 3.16, it is complained at
> the line "import os", but not at the line "import nt". How can
> I resolve this?

that means that the python path is messed up, so Python cannot
find it's support libraries (usually found under c:/python24/Lib).

I have no idea what "Python for Delphi 3.16" is, so things may be
different for that distribution (if that's what it is).

adding

    import sys
    print sys.path

and comparing that to the actual file structure may help you figure
out what's going on.

> I wonder if there is a built_in command in NT OS specific to get date
> and time of a file. The following command is what I used in my script
> mtime = os.stat(Path + file_name)[os.path.stat.ST_MTIME]

fwiw, that's usually spelled os.path.getmtime in contemporary python.

if you cannot import os, you can use

    mtime = nt.stat("q.py")[8]

but it's probably better to fix the path issue; Python doesn't work well
without the support library.

</F>






More information about the Python-list mailing list