I posed this question before. The usual answer is: a file containing Python source code. But you can import .pyc files even after the .py files are been removed, likewise .pyd files. Is a Python module anything that's importable and runnable within Python, that responds to dir( ) etc.? True whether or not said module comes with readable source code. In fact, one could argue a Python module is precisely *not* the readable source code .py file, as that *must* be compiled to byte codes first, and saved in the .pyc. Kirby Ongoing curriculum writing (a window): http://mybizmo.blogspot.com/2011/05/lesson-planning.html
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/03/2011 03:39 AM, kirby urner wrote:
I posed this question before. The usual answer is: a file containing Python source code.
But you can import .pyc files even after the .py files are been removed, likewise .pyd files.
Is a Python module anything that's importable and runnable within Python, that responds to dir( ) etc.?
True whether or not said module comes with readable source code.
In fact, one could argue a Python module is precisely *not* the readable source code .py file, as that *must* be compiled to byte codes first, and saved in the .pyc.
A module is an object like any other:
import os type(os) <type 'module'> a = os.__class__("hello!") type(a) <type 'module'> dir(a) ['__doc__', '__name__']
You can even inherit from it!
import os class MyModule(os.__class__): ... def __str__(self): ... return "hi!" ... a = MyModule("name") print a hi!
Of course, if I ever see that in "real" code, I'd be worried. - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJNv910AAoJEAFAbo/KNFvpohgH/jtY9D/uX+vLnwQHe3kz3fVf egJ3SG/H3SsC/y8iRXpRiG0JvW8EOQ4iL6FqxhMZ0vl9uEj4u7cd1Q7ocrw08Yua KVgjwfUJpFrLBKJzuDep6aThymmFmcpyYMdXC+sccHNklQQCi/kJa5KdK8+a7hvy ZGEa+jBqALzFEBj4DyU1lrCcxUqJ2vPKprP/d+DRv+kgLMd/dTfeolkkOjiM966X aexiV6Sj4MXg/51B9c2pJpZ1rngiRtJjXzagwRZFFpeDyThLCMkWgJcyIfFg4KgX vphjPrn+jRdZKBI1lVHG1dpgyaskvrfxnyRaRtQtpuxVr2K7pgVJmp1+GB2ZmM8= =3bbD -----END PGP SIGNATURE-----
A module is an object like any other:
I agree with you Corey. So those saying a module consists of Python source code are being a bit loose with the term. It's sufficient that it behave in a Pythonic manner. We could have lots of Python modules without source in some collection. Kirby
"Over 30% of the modules you will be importing today were written in either Erlang or Haskell..." That's going to make sense, right? Kirby On Tue, May 3, 2011 at 2:03 PM, Robert <sigzero@gmail.com> wrote:
On 2011-05-03 03:39:52 -0400, kirby urner said:
I posed this question before. The usual answer is: a file containing
Python source code.
If the answer isn't that I am send you an email teach! :)
--
Robert
_______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig
participants (4)
-
Corey Richardson -
kirby urner -
Kirby Urner -
Robert