Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80926 > unrolled thread
| Started by | Dave Angel <davea@davea.name> |
|---|---|
| First post | 2014-11-16 17:39 -0500 |
| Last post | 2014-11-16 17:39 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re:How modules work in Python Dave Angel <davea@davea.name> - 2014-11-16 17:39 -0500
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2014-11-16 17:39 -0500 |
| Subject | Re:How modules work in Python |
| Message-ID | <mailman.15918.1416177570.18130.python-list@python.org> |
Abdul Abdul <abdul.sw84@gmail.com> Wrote in message:
> Hello,
>
> I'm new to Python, and just have a small question, and thought you might have an idea on it.
You should start any new thread with a specification of the
versions of software you're asking about. Since you didn't,
I'll assume python version 2.7, PIL version 1.7, and Linux Ubuntu
version 14.04.
>
> I came across the following example that uses the Python Imaging Library (PIL):
>
> from PIL import Image
> img = Image.open('xyz.jpg')
>
> I know that PIL is a module. And, I think that Image is also a module, especially we are importing it.
PIL is a package, whuch means it's a module containing other
modules., and contains modules such as Image. But that syntax
"from PIL import Image" doesn't tell you that. Any type of name
defined in module PIL can be retrieved by the from
syntax.
The way I can tell is either read the docs, or ask in the interpreter.
from PIL import Image
print type (Image)
<type 'module'>
That from syntax is roughly equivalent to
import PIL
Image = PIL.Image
And the leading capital I would have made me guess it was a class.
Thus I checked, using type ()
>
> I also understood the Image,open() part, as it appears we are using the method open() from the Image module.
Modules don't have methods. open is an ordinary function in the module.
>
> My question is, where did PIL go here?
I don't understand the question. By using the from syntax, you
avoided having PIL in your namespace. If you wanted, you could
have said. import PIL. And used PIL.Image.open()
Can a module have another module inside it?
>
Yes
>
>
--
DaveA
Back to top | Article view | comp.lang.python
csiph-web