[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help needed urgently for running some code!!!!

On Tue, Sep 3, 2019 at 1:38 PM Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Mon, 2 Sep 2019 08:05:14 -0700 (PDT), Spencer Du
> <spencerdu at hotmail.co.uk> declaimed the following:
> >Hi
> >
> >I want to execute
> >
> >"from devicesEmbedded import *": in GUI.py after all code in GUI.py is run. Also how do I make the devicesEmbedded.py reload and run when a txt file is created in the name of "list_of_devices.txt" in the GUI.py python program.
> >
>         Reload is one of the least effective features. Especially when you have
> bound names locally within modules. "... import *" binds names locally.
> Reloading a changed module creates a new module entry in Python's run-time,
> but any local names still refer to the old module contents.
>         Please consider reading the documentation:
> https://docs.python.org/3/library/importlib.html
> """
>  importlib.reload(module)
>     Reload a previously imported module. The argument must be a module
> object, so it must have been successfully imported before. This is useful
> if you have edited the module source file using an external editor and want
> to try out the new version without leaving the Python interpreter. The
> return value is the module object (which can be different if re-importing
> causes a different object to be placed in sys.modules).
>     When reload() is executed:
>         Python module?s code is recompiled and the module-level code
> re-executed, defining a new set of objects which are bound to names in the
> module?s dictionary by reusing the loader which originally loaded the
> module. The init function of extension modules is not called a second time.
>         As with all other objects in Python the old objects are only
> reclaimed after their reference counts drop to zero.
>         The names in the module namespace are updated to point to any new
> or changed objects.
>         Other references to the old objects (such as names external to the
> module) are not rebound to refer to the new objects and must be updated in
> each namespace where they occur if that is desired.
> """
> NOTE the last paragraph. This means you should NOT be using "... import *"
> syntax for anything you might want to have reloaded. Instead use "import
> modulename" and everywhere you access something in that module use the long
> form "modulename.something". This way, when it is reloaded, "modulename"
> will reference the new contents.
>         As for detecting file changes... You will have to periodically check
> the time-stamp (modification time) of the file, and if it changes, reread
> the file.
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
> --
> https://mail.python.org/mailman/listinfo/python-list

Spencer, for the past month (almost) you have been sending "urgent"
requests for people here to write code for you.  You've already
decided what needs to be done, but you haven't really explained what
you want to do.  You don't respond to other's responses for further
clarification, or with your progress.  You basically repeat the same
urgent request.  Please don't do this.  There are many python experts
here who will help you, but getting someone to write your code for you
when you can't really explain what your goal is will get you nowhere,
especially since you claim this is for your job.

To me, its an odd thing to want to do imports depending on a file's
contents.  But maybe its a good idea.  However, you can just import
all of the modules you might expect to need, and ignore if they aren't
present with a suitable try/except block.   Try explaining the bigger
picture of what you are trying to do, and maybe you can gain some
incite into a better way of proceeding.  I'm afraid it looks like you
have been cutting and pasting without understanding what your code's
design is all about.  I could be totally wrong.  good luck

Joel Goldstick