Skip to content

Commit 38832b4

Browse files
committed
some posts for the forum
1 parent 7b1f080 commit 38832b4

File tree

9 files changed

+60
-0
lines changed

9 files changed

+60
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Be careful when looping over items in a list and deleting them. You
2+
need to make a copy first:
3+
4+
a_tmp = a[:]
5+
for a in a_tmp:
6+
...
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
The following lines will send an e-mail:
2+
3+
4+
import smtplib
5+
from email.mime.text import MIMEText
6+
7+
sender = "your e-mail address here"
8+
receiver = "your e-mail address here"
9+
10+
subject = "python e-mail"
11+
12+
body = """
13+
your e-mail body goes here
14+
"""
15+
16+
msg = MIMEText(body)
17+
msg['Subject'] = subject
18+
msg['From'] = sender
19+
msg['To'] = receiver
20+
21+
try:
22+
smtpObj = smtplib.SMTP('localhost')
23+
smtpObj.sendmail(sender, receiver, msg.as_string())
24+
except SMTPException:
25+
sys.exit("ERROR sending mail")
26+
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
To get your code to beep, do:
2+
3+
print("\a")
File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
We briefly discussed shallow copies in class:
2+
3+
>>> a = [1, 2, [3,4], 5]
4+
>>> b = a[:]
5+
>>> print id(a)
6+
140022054383056
7+
>>> print id(b)
8+
140022054485312
9+
>>>
10+
>>> print a[2]
11+
[3, 4]
12+
>>> print id(a[2])
13+
140022054381760
14+
>>> print id(b[2])
15+
140022054381760
16+
>>>
17+
>>>
18+
>>> a[2][0] = "changed"
19+
>>> print a
20+
[1, 2, ['changed', 4], 5]
21+
>>> print b
22+
[1, 2, ['changed', 4], 5]
23+
24+
notice that the list in the list is not a copy, but they both point to
25+
the same list, so this is shallow in that sense.

0 commit comments

Comments
 (0)