![]() ![]() For example, when we imported the greetings.py file earlier, we created a greetings module object and namespace containing the names of the objects defined in the file - hello_world and hello_world_squamish - which we can access using dot notation, e.g., greetings.hello_world() and greetings.hello_world_squamish(). The important point to make here is that when a module is imported using the import statement, a module object is created and it has its own namespace containing the names of the Python objects defined in the modules. Namespaces are created at different moments, have different lifetimes, and can be accessed from different parts of a Python program - but these details digress from our discussion, and we point interested readers to the Python documentation to learn more. The other names bounded by double underscores are objects that were initialized automatically when we started the Python interpreter and are implementation details that aren’t important to our discussion here but can be read about in the Python documentation. In the output above, we can see the names of the three objects we have defined in this section: a, hello_world, and greetings. For example, the code below, run in a Python interpreter, creates an integer object and a function object mapped to the names a and hello_world, respectively: We can find the type of a Python object using the type() function. ![]() ![]() For example, integers and functions are kinds of Python objects. We’ll begin this chapter by exploring some of the lower-level implementation details related to what packages are, how they’re structured, and how they’re used in Python.Īll data in a Python program are represented by objects or by relations between objects. Along the way, we’ll demonstrate key concepts by continuing to develop our pycounts package from the previous chapter. The chapter finishes with a discussion of what package distributions are, how to build them, and how they are installed. We then discuss some more advanced package structure topics, such as controlling the import behavior of a package and including non-code files, like data. We begin with a discussion of how modules and packages are represented in Python and why they are used. This chapter now goes into more detail about what a Python package actually is, digging deeper into how packages are structured, installed, and distributed. Chapter 3: How to package a Python provided a practical overview of how to create, install, and distribute a Python package. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |