- Plain Mail: an email message with plain text or html content.
- Mail with Attachment: an email message with attached document.
- Alternative Mail Views: you provide a convenient way to email recipients to view your message in plain text or html with optional rich content including images, etc.
Monday, December 3, 2012
How to Send Mail in Python
There are several use cases how you can send an email message using Python:
Labels:
algorithms
,
python
,
wheezy.core
Wednesday, November 28, 2012
How to ship eggs with pyo files only in Python
There is sometimes a need to ship python egg distribution with pyo files only. There is confusion using bdist_egg command since it doesn't have any options to do that; instead, you can instruct install_lib command. Here is what you need in setup.cfg file:
[install_lib] compile = 0 optimize = 2 [bdist_egg] exclude-source-files = 1Issue the following command to build egg.
python setup.py -q bdist_eggNote, the egg file has only python byte code optimized module files (look at dist directory). You can read about compiled modules here.
Labels:
python
,
setuptools
,
tricks
Tuesday, November 20, 2012
Python Web Frameworks Excessive Complexity
Cyclomatic (or conditional) complexity is a metric used to indicate the complexity of a source code. In this post we will take a look at web frameworks source code and estimate excessive complexity, something that is beyond recommended level of 10 (threshold that points to the fact the source code is too complex and refactoring is suggested). Here is a list of web frameworks examined:
- bottle
- cherrypy
- circuits
- django
- falcon
- flask
- pyramid
- pysi
- tornado
- turbogears
- web.py
- web2py
- webapp2
- wheezy.web
hg clone https://bitbucket.org/akorn/helloworld cd helloworld/04-pep8 && make env upThe make file has a target for mccabe metric, so issue make mccabe.
Thursday, November 15, 2012
Lazy Attribute in Python
A lazy attribute is an attribute that is calculated on demand and only once. Here we will see how you can use lazy attribute in your Python class. Setup environment before you proceed:
$ virtualenv env $ env/bin/pip install wheezy.coreLet assume we need an attribute that is display name of some person Place the following code snippet into some file and run it:
from wheezy.core.descriptors import attribute
class Person(object):
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
self.calls_count = 0
@attribute
def display_name(self):
self.calls_count += 1
return '%s %s' % (self.first_name, self.last_name)
if __name__ == '__main__':
p = Person('John', 'Smith')
print(p.display_name)
print(p.display_name)
assert 1 == p.calls_count
Notice display_name function is decorated with @attribute. The first call promotes function to attribute with the same name. The source is here.
Labels:
algorithms
,
python
,
wheezy.core
Thursday, November 8, 2012
Duck Typing Assert in Python
People who come from strongly typed languages that offer interfaces often are confused by lack of one in Python. Python, being dynamic typing programming language, follows duck typing principal. Here we will see how programmer can assert duck typing between two Python classes. Setup environment before proceed:
$ virtualenv env $ env/bin/pip install wheezy.coreLet play a bit with duck test `looks like`. Place the following code snippet into file `test.py`:
from wheezy.core.introspection import looks
class IFoo(object):
def foo(self):
pass
class Foo(object):
def bar(self):
pass
assert looks(Foo).like(IFoo)
Labels:
algorithms
,
python
,
wheezy.core
Subscribe to:
Posts
(
Atom
)

