Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101969
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: importing: what does "from" do? |
| Date | 2016-01-21 07:52 -0700 |
| Message-ID | <mailman.151.1453387942.15297.python-list@python.org> (permalink) |
| References | <n7qpel$a3j$1@dont-email.me> |
On Jan 21, 2016 7:31 AM, "Charles T. Smith" <cts.private.yahoo@gmail.com> wrote: > > What does "from (module) import (func)" do? Approximately equivalent to: import module func = module.func Except that it doesn't bind "module" to anything. > 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 What is utilities? Is it a module on your sys.path? > 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 What makes you think this is caused by circular dependencies? It could be, but you really haven't given us enough information about what utilities is to diagnose that. > would you explain to me why I get this: > > (PDB)hexdump(msg) > *** NameError: name 'hexdump' is not defined Probably because the name 'hexdump' is not defined. > P.S. can I get a list of all the loaded symbols and/or modules? What do you mean by "loaded"? Bound to a name in the main module? In the globals of the current scope? In any module? Try the "dir" or "vars" built-in. You can get a view of all the *cached* modules by looking in the sys.modules dict.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
importing: what does "from" do? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-21 14:20 +0000
Re: importing: what does "from" do? Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-21 07:52 -0700
Re: importing: what does "from" do? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-21 15:12 +0000
Re: importing: what does "from" do? Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-21 08:59 -0700
Re: importing: what does "from" do? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-21 16:30 +0000
Re: importing: what does "from" do? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-21 16:41 +0000
Re: importing: what does "from" do? Steven D'Aprano <steve@pearwood.info> - 2016-01-22 03:22 +1100
Re: importing: what does "from" do? John Gordon <gordon@panix.com> - 2016-01-21 15:31 +0000
Re: importing: what does "from" do? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-21 15:37 +0000
Re: importing: what does "from" do? John Gordon <gordon@panix.com> - 2016-01-21 15:44 +0000
Re: importing: what does "from" do? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-21 15:46 +0000
Re: importing: what does "from" do? John Gordon <gordon@panix.com> - 2016-01-21 15:59 +0000
Re: importing: what does "from" do? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-21 15:53 +0000
Re: importing: what does "from" do? Steven D'Aprano <steve@pearwood.info> - 2016-01-22 03:28 +1100
Re: importing: what does "from" do? Rustom Mody <rustompmody@gmail.com> - 2016-01-21 23:03 -0800
Refactoring in a large code base (was: importing: what does "from" do?) Ben Finney <ben+python@benfinney.id.au> - 2016-01-22 18:54 +1100
Re: Refactoring in a large code base Marko Rauhamaa <marko@pacujo.net> - 2016-01-22 10:29 +0200
Re: Refactoring in a large code base Rustom Mody <rustompmody@gmail.com> - 2016-01-22 01:21 -0800
Re: Refactoring in a large code base Marko Rauhamaa <marko@pacujo.net> - 2016-01-22 12:19 +0200
Re: Refactoring in a large code base Chris Angelico <rosuav@gmail.com> - 2016-01-22 22:19 +1100
Re: Refactoring in a large code base Marko Rauhamaa <marko@pacujo.net> - 2016-01-22 13:54 +0200
Re: Refactoring in a large code base Chris Angelico <rosuav@gmail.com> - 2016-01-22 23:28 +1100
Re: Refactoring in a large code base Marko Rauhamaa <marko@pacujo.net> - 2016-01-22 15:00 +0200
Re: Refactoring in a large code base Chris Angelico <rosuav@gmail.com> - 2016-01-23 00:26 +1100
Re: Refactoring in a large code base Marko Rauhamaa <marko@pacujo.net> - 2016-01-22 15:48 +0200
Re: Refactoring in a large code base Chris Angelico <rosuav@gmail.com> - 2016-01-23 01:09 +1100
Re: Refactoring in a large code base Rustom Mody <rustompmody@gmail.com> - 2016-01-22 04:04 -0800
Re: Refactoring in a large code base Marko Rauhamaa <marko@pacujo.net> - 2016-01-22 14:21 +0200
Re: Refactoring in a large code base Thomas Mellman <tmellman@web.de> - 2016-01-22 12:27 +0000
Re: Refactoring in a large code base Chris Angelico <rosuav@gmail.com> - 2016-01-22 23:34 +1100
Re: Refactoring in a large code base Rustom Mody <rustompmody@gmail.com> - 2016-01-22 05:30 -0800
Re: Refactoring in a large code base Marko Rauhamaa <marko@pacujo.net> - 2016-01-22 15:43 +0200
Re: Refactoring in a large code base Rustom Mody <rustompmody@gmail.com> - 2016-01-22 05:58 -0800
Re: Refactoring in a large code base Chris Angelico <rosuav@gmail.com> - 2016-01-23 01:08 +1100
Re: Refactoring in a large code base "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-22 11:45 +0000
csiph-web