Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80936
| References | <CAA+hu4WstWquKEJ3C4AnWqbcNb5Y55G+xmywzF1hhEei9NQi=A@mail.gmail.com> <m4b92h$2dj$1@ger.gmane.org> |
|---|---|
| Date | 2014-11-17 01:41 +0100 |
| Subject | Re: How modules work in Python |
| From | Abdul Abdul <abdul.sw84@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15925.1416184915.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
Dave,
Thanks for your nice explanation. For your answer on one of my questions:
* Modules don't have methods. open is an ordinary function in the module.*
Isn't "method" and "function" used interchangeably? In other words, aren't
they the same thing? Or, Python has some naming conventions here?
Thanks.
On Sun, Nov 16, 2014 at 11:39 PM, Dave Angel <davea@davea.name> wrote:
> 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
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: How modules work in Python Abdul Abdul <abdul.sw84@gmail.com> - 2014-11-17 01:41 +0100
Re: How modules work in Python Larry Hudson <orgnut@yahoo.com> - 2014-11-18 00:14 -0800
Re: How modules work in Python sohcahtoa82@gmail.com - 2014-11-18 12:59 -0800
Re: How modules work in Python Larry Hudson <orgnut@yahoo.com> - 2014-11-18 23:44 -0800
Re: How modules work in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-19 22:32 +1100
Re: How modules work in Python sohcahtoa82@gmail.com - 2014-11-19 11:00 -0800
Re: How modules work in Python Chris Angelico <rosuav@gmail.com> - 2014-11-20 08:50 +1100
Re: How modules work in Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-19 21:32 -0500
Re: How modules work in Python Michael Torrie <torriem@gmail.com> - 2014-11-20 09:53 -0700
csiph-web