Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary computational thinking: python, file editing, and regex

Rating
-
Sold
-
Pages
2
Uploaded on
24-09-2025
Written in
2024/2025

this document contains a summary of the computational thinking lectures. it covers how to open, read, write and close text and csv files with python. in addition, error handling is explained via try-exception constructs and additional blocks such as else and finally. a large part is dedicated to using regular expressions (regex), including repetition operators, groups and choices, predefined classes, special characters and escape characters. substitution with regex in strings is also included. together, these topics form practical building blocks for applying computational thinking in programming tasks such as input and output operations, pattern recognition and automation.

Show more Read less
Institution
Module

Content preview

Samenvatting Hoorcolleges Computationeel Denken

Hoorcollege 11:

Openen en bewerken van tekst bestanden:
fh1 = open(‘myfile.txt’, “r”) # open for reading
fh1 = open(‘myfile.txt’, “w”) # open for writing, remove existing content
fh1 = open(‘myfile.txt’, “a”) # open for writing, keep existing content

fh1.readline() # read single line
fh1.readlines() # read a list of lines
fh1.read(7) # read the next 7 characters
fh1.strip() # strips the file of empty lines

fh1.write(“Hallo World\n”) # write text to file, not explicit newline at the
end
fh1.close() # close a file after use
with open(‘file.txt’, ‘r’) # no closing using with()


Openen en lezen van csv bestanden:
import csv
fh1 = open(‘csv_file.csv’) # open file for reading
ch1= csv.reader(fh1) # create a csv variable from the file handle
regel = next(ch1) # eerste regel
regel[i] # i’e element van de eerste regel

Bewerken van csv bestanden:
ch1 = csv.writer(fh1) # create write file
ch1.writerow(content) # write row and fill with content
fh1.close() # close starting file

Try en except:
try block: tests a block of code for errors
except block: handles the error
else: execute the code when there is no error
finally: executes code regardless of the result

Written for

Institution
Study
Module

Document information

Uploaded on
September 24, 2025
Number of pages
2
Written in
2024/2025
Type
SUMMARY

Subjects

£3.14
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
studiemotion

Get to know the seller

Seller avatar
studiemotion Universiteit Utrecht
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
6 months
Number of followers
0
Documents
7
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions