Archive for category Python
I think I just figured out how to cure cancer
Posted by Sean Fujiwara in Python on April 14, 2012
class CancerBot extends NanoBot: def onCellIdentified(self, cell): if cell.is_cancer(): self.destroy(cell) bot = CancerBot() bot.run()
All I need is some help with implementation details.
Disabling images in Python Markdown
Posted by Sean Fujiwara in Python on May 5, 2011
Here’s a quick snippet that shows how to disable images (or any extension) in Python Markdown:
import markdown class MyMarkdownExtension(markdown.Extension): def extendMarkdown(self, md, md_globals): del md.inlinePatterns['image_link'] del md.inlinePatterns['image_reference'] my_markdown_extension = MyMarkdownExtension() raw_text = 'This is a test image: ' print markdown.markdown(raw_text, [my_markdown_extension], safe_mode = 'escape')
Edit:
Some processing is disabled through md.parser.blockprocessors instead.
Here are the options for each:
md.inlinePatterns:
'backtick' 'escape' 'reference' 'link' 'image_link' 'image_reference' 'short_reference' 'autolink' 'automail' 'linebreak2' 'linebreak' 'html' 'entity' 'not_strong' 'strong_em' 'strong' 'emphasis' 'emphasis2'
md.parser.blockprocessors:
'indent' 'code' 'hashheader' 'setextheader' 'hr' 'olist' 'ulist' 'quote' 'paragraph'
typeof in python
Posted by Sean Fujiwara in Python, Sample Code on February 18, 2011
I could not find a good way to get the name of a class from an instance with Python on google. It’s simple (but not obvious):
str(type(var))