Function attributes are automatically generated by Python for you. These attributes perform the following tasks or contain the following information:
-
__builtins__: Contains a listing of all the built-in attributes that are accessible from the package. Python adds these attributes automatically for you.
-
__cached__: Tells you the name and location of the cached file that is associated with the package. The location information (path) is relative to the current Python directory.
-
__doc__: Outputs help information for the package, assuming that you’ve actually filled it in. For example, if you type os.__doc__ and press Enter, Python will output the help information associated with the os library.
-
__file__: Tells you the name and location of the package. The location information (path) is relative to the current Python directory.
-
__initializing__: Determines whether the package is in the process of initializing itself. Normally this attribute returns a value of False. This attribute is useful when you need to wait until one package is done loading before you import another package that depends on it.
-
__loader__: Outputs the loader information for this package. The loader is a piece of software that gets the package and puts it into memory so that Python can use it. This is one attribute you rarely (if ever) use.
-
__name__: Tells you just the name of the package.
-
__package__: This attribute is used internally by the import system to make it easier to load and manage packages. You don’t need to worry about this particular attribute.
Some of these entries, such as __name__, also appeared in the package listing. However, you might be curious about some of the other entries. For example, you might want to know what __sizeof__ is all about. One way to get additional information is to type help(“__sizeof__”) and press Enter. You see some scanty (but useful) help information.
Python isn’t going to blow up if you try the attribute. Even if the shell does experience problems, you can always start a new one. So, another way to check out a package is to simply try the attributes. For example, if you type MyLibrary.SayHello.__sizeof__( ) and press Enter, you see the size of the SayHello() function in bytes.
Unlike many other programming languages, Python also makes the source code for its native language libraries available. For example, when you look into the Python33Lib directory, you see a listing of .py files that you can open in IDLE with no problem at all.
Viewing the content directly can help you discover new programming techniques and better understand how the library works. The more time you spend working with Python, the better you’ll become at using it to build interesting applications.
Make sure that you just look at the library code and don’t accidentally change it. If you accidentally change the code, your applications can stop working. Worse yet, you can introduce subtle bugs into your application that will appear only on your system and nowhere else. Always exercise care when working with library code.