<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <a href="https
Step1:  Chapter 12
Step2:  Note the syntax used
Step3:  In this case we wouldn't have to specify where our machine should find the randint() function
Step4:  If we like the randint() method, we might also be interested which other methods are offered in the random package. We can use dir() for this
Step5:  You can also (temporarily) change the names of the functions you import
Step6:  If you want to import the entire module, it works the same way (using the syntax we have already seen above). Changing the name can be useful if we want to shorten it (as shown below).
Step7:  3. Other useful modules
There are plenty of very useful modules out there, so it is a good practice to check if someone has already created a module for a task that you are facing. Here, we'll show
datetime (module to manipulate dates)
requests (module to download the content of a webpage)
3.1 Datetime
Step8:  We can decipher the output ourselves
Step9:  3.2 Requests
Step10:  Don't worry too much about the response
Step11:  Exercise 2
Figure out what the os module does and think about tasks it could be used for.
<ASSISTANT_TASK:>
Python Code:
%%capture
!wget https://github.com/cltl/python-for-text-analysis/raw/master/zips/Data.zip
!wget https://github.com/cltl/python-for-text-analysis/raw/master/zips/images.zip
!wget https://github.com/cltl/python-for-text-analysis/raw/master/zips/Extra_Material.zip
!unzip Data.zip -d ../
!unzip images.zip -d ./
!unzip Extra_Material.zip -d ../
!rm Data.zip
!rm Extra_Material.zip
!rm images.zip
Explanation: <a href="https://colab.research.google.com/github/cltl/python-for-text-analysis/blob/colab/Chapters-colab/Chapter_12_Importing_external_modules.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
End of explanation
import random
print(random.randint(0, 100))
Explanation: Chapter 12: Importing external modules
We use some materials from this other Python course.
Most of the functionality we have used thus far is built into the Python language itself. Now we have also learned how to write our own functions. Often, however, you need to use external modules in your code. A lot of external modules are already available in the Python Standard Library, for a wide variety of tasks. There are also countless third-party providers of Python modules.
At the end of this chapter, you will be able to:
import an entire module
import a specific function from a module
use dir and help to get information about a module or function
import a few commonly used modules: random, datetime, and requests
If you want to learn more about these topics, you might find the following links useful:
* Tutorial: The import statement
* Video: OS Module - Use Underlying Operating System Functionality
If you have questions about this chapter, please contact us (cltl.python.course@gmail.com).
1. Importing a module or a function
Python modules
A Python module is a Python file (i.e., a file ending in .py) which contains function definitions and statements. You can already write one yourself! (More about this in the next chapter.)
Some modules are part of the Python standard library and contain useful functions. You can import these modules and use the functions as explained below.
More on modules can be found here: https://docs.python.org/3/tutorial/modules.html
To use an external module in your code, you need to import it explicitely. Consider, for example, the module random from the standard library, which contains functions for generating random numbers:
End of explanation
from random import randint
print(randint(0, 100))
Explanation: Note the syntax used: using the dot, we indicate that our machine should look for the randint() method inside the random module we just imported. You can import an entire module or import only a specific function in the module. We could also have imported the (single) method we needed as follows:
End of explanation
help(randint)
Explanation: In this case we wouldn't have to specify where our machine should find the randint() function: note that we don't need to use the module random in the function call in this case.
2. Getting help
We might not understand how an external method works, or what input it needs, or what are the output values it returns. In that case, we can use help() (just as we did with functions and methods):
End of explanation
dir(random)
Explanation: If we like the randint() method, we might also be interested which other methods are offered in the random package. We can use dir() for this:
End of explanation
from random import randint as random_number
print(random_number(0, 100))
Explanation: You can also (temporarily) change the names of the functions you import:
End of explanation
import random as rn
print(rn.randint(0,4))
Explanation: If you want to import the entire module, it works the same way (using the syntax we have already seen above). Changing the name can be useful if we want to shorten it (as shown below).
End of explanation
import datetime
print(datetime.datetime.now())
Explanation: 3. Other useful modules
There are plenty of very useful modules out there, so it is a good practice to check if someone has already created a module for a task that you are facing. Here, we'll show
datetime (module to manipulate dates)
requests (module to download the content of a webpage)
3.1 Datetime
End of explanation
help(datetime.datetime.now)
Explanation: We can decipher the output ourselves: the first value is the current year, the second the current month, then day, hour, minute, etc. We can also see what Python tells us about this result:
End of explanation
import requests
a=requests.get("https://tae898.github.io")
print(a.content)
Explanation: 3.2 Requests
End of explanation
# your code here
Explanation: Don't worry too much about the response: it is a format called HTML (which is basically behind all web pages) and one would need to write some more code to extract the useful information from it. But: it is really impressive that we can retrieve any webpage from the web with just three lines of code! If you want to have a quick look at how to extract content, feel free to check out the beautifulsoup module. 
So, how does one find a useful module for a specific task? Answer: Google it ;-)
Exercises
Exercise 1: 
Check which arguments should be supplied to the random.sample() method and what is their intention. Then call this function with different arguments.
End of explanation
# play around here
Explanation: Exercise 2
Figure out what the os module does and think about tasks it could be used for.
End of explanation
<END_TASK>