Blog Archives for category Python
Python regex Filter
The following example replaces values in a textfile with pyhon. Before
1 2 3 |
username = henk This user 'henk' is active peiter |
Python regex filter script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import re def filter_files(files): read = open(files).read() read = re.sub('username = .*','username = pieter', read) read = re.sub("user '.*?'", "user 'pieter'", read) read = read.replace('peiter','pieter') replace = open(files, 'w') replace.write(read) replace.close filter_files('log.txt') |
After
1 2 3 |
username = pieter This user 'pieter' is active pieter |
Compare csv files Python
Compare csv files with Python I used this script to compare two different SKU CSV lists with python. The script… Continue reading »
Send e-mails in Python
You can use the following script to send e-mails in Python.
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 |
import smtplib import email.utils from email.mime.text import MIMEText from email.mime.application import MIMEApplication from email.mime.multipart import MIMEMultipart msg = MIMEMultipart() msg['Subject'] = 'Test Subject' msg.preamble = 'Multipart massage.\r\n' # E-mail body part = MIMEText("Test body text") msg.attach(part) # E-mail attachment part = MIMEApplication(open("test.pdf","rb").read()) part.add_header('Content-Disposition', 'attachment', filename="test.pdf") msg.attach(part) # SMTP server server = smtplib.SMTP("smtp.testsmtp.com",25) # SMTP debug server.set_debuglevel(True) # Sending try: server.ehlo() server.login("username", "password") server.sendmail('From', ['To'], msg.as_string()) finally: server.quit() |
Python print input data
Basic data printing with python. Data input:
1 2 3 |
name = raw_input("What is your name?") quest = raw_input("What is your quest?") color = raw_input("What is your favorite color?") |
Print input:
1 2 |
print "Ah, so your name is %s, your quest is %s, " \ "and your favorite color is %s." % (name, quest, color) |
Thomson reverse SSID script
This python script can be used to reverse thomson/speedtouch ssids. Later this year I will launch an online version of… Continue reading »