importing: what does "from" do?

Rustom Mody rustompmody at gmail.com
Fri Jan 22 02:03:51 EST 2016


On Thursday, January 21, 2016 at 7:53:07 PM UTC+5:30, Charles T. Smith wrote:
> What does "from (module) import (func)" do?
> 
> Please don't tell me that I shouldn't ask because real programmers
> know not to have circular dependencies ...
> 
> I have no idea what was imported before.  I just want to import hexdump().
> Unfortunately, this does not work:
> 
>   from utilities import hexdump
> 
>     ImportError: cannot import name hexdump
> 
> Now, I shouldn't have a problem because the programmers before me didn't
> understand either, and so just duplicated it everywhere, but I'd really
> like to do it right.
> 
> I would have thought that "from" would allow me to import just one
> symbol.  Now, for all the people just chomping at the bit to tell
> me about circular dependencies, would you explain to me why I get this:
> 
>   (PDB)hexdump(msg)
> *** NameError: name 'hexdump' is not defined
> 
> 
> P.S. can I get a list of all the loaded symbols and/or modules?

You may find this strategy useful:
https://pchiusano.github.io/2015-04-23/unison-update7.html

particularly the section "Limitations of refactoring via modifying text files in place, and what to do instead"

Note it is not python based but the explanation should be useful anyway



More information about the Python-list mailing list