Fix Python – What is the best way to exit a function (which has no return value) in python before the function ends (e.g. a check fails)?

Let’s assume an iteration in which we call a function without a return value. The way I think my program should behave is explained in this pseudocode:
for element in some_list:
foo(element)

def foo(element):
do something
if check is true:
do more (because check was succesful)
else:
return None
do much much mor….

Fix Python – How to send an email with Python?

This code works and sends me an email just fine:
import smtplib
#SERVER = “localhost”

FROM = ‘monty@python.com’

TO = [“jon@mycompany.com”] # must be a list

SUBJECT = “Hello!”

TEXT = “This message was sent with Python’s smtplib.”

# Prepare actual message

message = “””\
From: %s
To: %s
Subject: %s

%s
“”” % (FROM, “, “.join(TO), SUBJECT, TEX….

Fix Python – Why does Python code use len() function instead of a length method?

I know that python has a len() function that is used to determine the size of a string, but I was wondering why it’s not a method of the string object.
Update
Ok, I realized I was embarrassingly mistaken. __len__() is actually a method of a string object. It just seems weird to see object oriented code in Python using the len function on string ob….

Fix Python – Ignore python multiple return value

Say I have a Python function that returns multiple values in a tuple:
def func():
return 1, 2

Is there a nice way to ignore one of the results rather than just assigning to a temporary variable? Say if I was only interested in the first value, is there a better way than this:
x, temp = func()

….