Page 2 of 4

Re: Re-import module?

Posted: Fri Nov 21, 2014 12:48 pm
by stijn
pfalcon wrote:Feature you ask for is rarely needed
I beg to differ. Maybe it's just me but I'm used to compiled languages where before running you at least know you won't get syntax errors. With Python however I'm only a beginner and the amount of times I have to restart a complete session becasue of some syntax or other error in the code is frustrating and time consuming: for instance I have a script which talks with external hardware which takes 10 seconds to connect with. Which is unfortunate enough, but then I have to redo that for every stupid error made and there's lots of them :]

but adds noticeable overhead to implementation - that's usually a rule for "skip this feature" we used so far. Feel free to argue for a usecase when it's unavoidably needed though
Can't really argue with that. It's more of a nice to have though I guess for some it's more welcome than for others.

Re: Re-import module?

Posted: Fri Nov 21, 2014 2:27 pm
by Architekt
Hi stijn, I have some suggestions for you:

1) Use static source code checker like flake8. Modern source code editors usually has plugins/extensions to integrate them and check you code on save.

2) Use pyboard.py to run and re-run your scripts on pyboard.

3) Use REPL to live debug/change your code running inside pyboard.

If you learn these tools, they should help you develop more effectively.

Re: Re-import module?

Posted: Fri Nov 21, 2014 2:38 pm
by stijn
Hey thanks for the reply, but I'm running on a PC not the pyboard. However static source code checking might indeed come in handy, will try. Thanks for the tip!

Re: Re-import module?

Posted: Sat Nov 22, 2014 12:04 am
by Damien
Is re-importing a module when it changes even possible in CPython? I tried it but it didn't work for me.

Re: Re-import module?

Posted: Sat Nov 22, 2014 12:21 am
by dhylands
Damien wrote:Is re-importing a module when it changes even possible in CPython? I tried it but it didn't work for me.
I did it for plugins in another program. It would detect that the timestamp changed and re-import the plugin (which was in reality a module). I'll dig up the code. I think it used __import__ or something like that.

Re: Re-import module?

Posted: Sat Nov 22, 2014 10:54 am
by pfalcon
Damien wrote:Is re-importing a module when it changes even possible in CPython? I tried it but it didn't work for me.
Few of web microframeworks use that feature to allow "live" code editing. But that's usually done in special "development" mode and not enabled in "production" mode to save the cycles (which is important even for CPython when we speak of (tens of?) thousands of concurrent connections). So yeah, I doubt it's done automagically by CPython itself, rather requires app's involvement. So again, we should just enable people to do re-imports, triggering them would likely stay their own task.

Re: Re-import module?

Posted: Mon Nov 24, 2014 10:27 am
by kfricke
hmho, personal development preferrences should not be expected to alter platform implementation.

Re: Re-import module?

Posted: Tue Nov 25, 2014 1:12 pm
by pythoncoder
I may be missing the point here but isn't the cPython feature under discussion imp.reload? This replaces the Python 2.x reload(module) syntax.

Re: Re-import module?

Posted: Tue Nov 25, 2014 3:00 pm
by stijn
That's indeed the case, see http://stackoverflow.com/a/13121908/128384 and comment on it for example

Re: Re-import module?

Posted: Tue Nov 25, 2014 4:59 pm
by dhylands
And the very end of that thread says that imp.reload() is deprecated and importlib.reload() is the right thing to do.
https://docs.python.org/3.4/library/imp ... lib.reload