Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python equivalents of the common Perl modules?

I need to rewrite some Perl code in python. So I'm looking for the closest modules to what I'm using now in Perl (i.e. with similar functionality and stability):

  • DBI + DBD::mysql
  • LWP::UserAgent
  • WWW::Mechanize
  • XML::LibXML
  • HTML::TreeBuilder
  • CGI::FormBuilder
  • Template::Toolkit

What are the Python equivalents to these?

like image 783
Eugene Yarmash Avatar asked Feb 25 '10 12:02

Eugene Yarmash


2 Answers

DBI + DBD::mysql

  • MySQLdb

LWP::UserAgent

  • urllib (Python STL)
  • urllib2 (Python STL)

WWW::Mechanize

  • Mechanize

XML::LibXML

  • libxml2
  • lxml

HTML::TreeBuilder

  • xml.etree.ElementTree (Python STL)

CGI::FormBuilder

  • cgi and cgitb (Python STL)

Template::Toolkit

  • Template-Python

Note: Items marked above as Python STL are included as part of the Python Standard Library as listed in the Python v2.6.4 documentation.

like image 161
Matthew Rankin Avatar answered Nov 16 '22 08:11

Matthew Rankin


  • All Python database modules use the same API, so either MySQLdb or oursql will work.
  • urllib2
  • mechanize
  • etree or lxml
  • No direct equivalent, but BeautifulSoup and lxml can parse, and etree and lxml can generate.
  • FormEncode
  • Genshi, Jinja2, mako, cheetah, and too many others

urllib2 and etree are in the standard library; the rest are easy enough to get.

like image 22
Ignacio Vazquez-Abrams Avatar answered Nov 16 '22 07:11

Ignacio Vazquez-Abrams