61ee86d7-8624-495a-b09e-3ace792f56a7
prompter
How do I use modules in python?
c2801585-ce76-4ab1-8bc5-1b076cf830d6
61ee86d7-8624-495a-b09e-3ace792f56a7
assistant
A module in python can contain variables, functions, classes, etc. To use these definitions inside a module, it must be first imported using the keyword `import`. The definitions can then be accessed with the module name and the dot `.`. For example, the following program finds the square root of 16 with `math` module:
```python
import math
print(math.sqrt(16))
```
A module can also be renamed. For example:
```python
import math as mt
print(mt.sqrt(16))
```
Sometimes only several definitions in a module is used, and they can be specifically imported:
```python
from math import sqrt
import math.pi
print(sqrt(16))
print(pi)
```
You can also import all definitions in a module at once:
```python
from math import *
print(sqrt(16))
print(pi)
```


As a open source project, there are many Python modules besides those built-in ones, and they need to be installed before importing. One of the commonly used installer program is **pip**, which can be used to install modules from the command line:
```
python -m pip install PackageName
```
Modules can have various requirements, and it is recommended to check the details in advance such as the Python version requirements. Some modules also provide the install commands on their websites. There are many ways of building a python environment for coding and module management with different management systems, code editors, or IDEs, and you can take some time to research, decide, and set yours up before starting on Python.
ba3aa127-b47e-4c24-b4c8-2ccd8c633bd3
c2801585-ce76-4ab1-8bc5-1b076cf830d6
prompter
Is there a python module that I can use to get the current date and time?
d92b08e5-a315-43b8-ada2-a6ac28833f5e
ba3aa127-b47e-4c24-b4c8-2ccd8c633bd3
assistant
You can use the ```datetime``` module for that. Try this out in a Python terminal.

```python
>>> import datetime
>>> now = datetime.datetime.now()
>>> now
```