-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_30.py
More file actions
43 lines (32 loc) · 1023 Bytes
/
05_30.py
File metadata and controls
43 lines (32 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'''
Pattern Matching & Substitution
Regex
'''
import re
txt = 'My email is janedoe@example.com and my friends email is john@example.com'
new_txt = re.sub(r'\b[\w.-]+@[\w.-]+\.[\w.-]+\b', 'redacted', txt)
print(new_txt)
import sqlite3
# Connect to the database (or create it if it doesn't exist)
conn = sqlite3.connect('example1.db')
c = conn.cursor()
# Create the users table
c.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL
)
''')
# Optionally, insert some sample data
c.execute("INSERT INTO users (name, email) VALUES ('Jane Doe', 'janedoe@example.com')")
c.execute("INSERT INTO users (name, email) VALUES ('John Smith', 'johnsmith@example.com')")
conn.commit()
# Select and print all data from the users table
c.execute("SELECT * FROM users")
rows = c.fetchall()
for r in rows:
with open('customers.txt', 'a') as file:
file.write(f'New Data: {r}\n')
# Close the connection
conn.close()