Skip to content

Latest commit

 

History

History

1-pip-io-modules

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Tuesday - Modules, PIP, IO

Before lesson materials

Mandatory:

Assignment Review

  • open() and parameters r, w, a
  • close()
  • write()
  • read(), readline() and readlines()
  • module and submodule
  • import
  • from
  • help()
  • OS module
  • Requests module

Tasks

  • First of all, you should copy all files to your working directory from
    • 01-io and
    • 02-pip folders
  • You can see all the tasks there, with a prepared skeleton to work in
  • The reason for that is so you can check your work with tests
  • There's a test.py in every corresponding folder, try and run it
  • The only thing matters from here is to get these to pass :)

I/O

my_file = open("file_name.txt", "r")

4 different ways of reading:

my_file.read()

my_file.readline()

my_file.readlines()

for line in my_file:
      print(line.rstrip())

>>> help(str.rstrip)

split()

" ".join()

my_list[start:end:step]

ord('a')

chr(97)

Modules

CSV built-in module

CSV - The Python Standard Library Docs

At first try to use the CSV Library Module to read the contents of otos.csv.

PIP

PIP is a tool for installing packages from the Python Package Index.

pip3 --version /// pip --version

(If you don't have pip, install it! Search for the commands for your operating system)

Install an external package

PrettyTable PrettyTable short tutorial

pip3 install prettytable /// pip install prettytable

Lottery

Print the five most frequent numbers and how many times they have occurred!

References