python

Is it worth using Python's re.compile?

Is there any benefit in using compile for regular expressions in Python? h = re.compile('hello') h.match('hello world') vs re.match('hello', 'hello world') ...

How can I install the Beautiful Soup module on the Mac?

I read this without finding the solution: http://docs.python.org/install/index.html ...

Python object.__repr__(self) should be an expression?

I was looking at the builtin object methods in the Python documentation, and I was interested in the documentation for object.__repr__(self). Here's what it says: Called by the repr() built-in function and by string conversions (reverse quotes) to compute the “official” string representation of an object. If at all possible, ...

What are the benefits of using Python for web programming?

What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web? ...

How can I test that I have a Python module successfully installed?

I tried to install beautifulsoup. I get such an error: <-- snip --> raise MissingSectionHeaderError(fpname, lineno, line) ConfigParser.MissingSectionHeaderError: File contains no section headers. file: /Users/Sam/.pydistutils.cfg, line: 1 'install_lib = ~/Library/Python/$py_version_short/site-packages\n' I get an similar error as I run ...

A SuggestBox for wxPython?

Is there a widget for wxPython like the SuggestBox in Google Web Toolkit? It is basically a magic text box that can invoke some code to come up with suggestions relevant to whatever the user has entered so far. Like the search box on Google's web page. If such a widget isn't already floating out there, I'd appreciate a sketch of how I m...

What does this Python message mean?

ho-fe3fdd00-12:~ Sam$ easy_install BeautifulSoup Traceback (most recent call last): File "/usr/bin/easy_install", line 8, in <module> load_entry_point('setuptools==0.6c7', 'console_scripts', 'easy_install')() File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/setuptools/command/easy_install.py", line...

How do I create a list of Python lambdas (in a list comprehension/for loop)?

I want to create a list of lambda objects from a list of constants in Python; for instance: listOfNumbers = [1,2,3,4,5] square = lambda x: x * x listOfLambdas = [lambda: square(i) for i in listOfNumbers] This will create a list of lambda objects, however, when I run them: for f in listOfLambdas: print f(), I would expect that i...

What are some of the tools used to edit Python files?

I am just a beginner and want to know how to edit Python files. Which applications are used to edit Python files? Thanks for the help in advance. Related questions: Poll: Which Python IDE/editor is the best? What is the best WYSIWYG GUI editor for Python? What IDE to use for Python What IDE would you recommend for Python development? ...

What is the best way to handle a bad link given to BeautifulSoup?

I'm working on something that pulls in urls from delicious and then uses those urls to discover associated feeds. However, some of the bookmarks in delicious are not html links and cause BS to barf. Basically, I want to throw away a link if BS fetches it and it does not look like html. Right now, this is what I'm getting. trillian:D...

Does python have an equivalent to Java Class.forName()?

I have the need to take a string argument and create a class in python. In Java, I would use Class.forName().newInstance(). Is there an equivalent in python? Thanks for the responses. To answer those who want to know what I'm doing: I want to use a command line argument as the class name, and instantiate it. I'm actually programmi...

What is the practical difference between xml, json, rss and atom when interfacing with Twitter?

I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project. Specifically the practical difference between using JSON or XML is something I'd...

Advice regarding IPython + MacVim Workflow

I've just found IPython and I can report that I'm in deep love. And the affection was immediate. I think this affair will turn into something lasting, like the one I have with screen. Ipython and screen happen to be the best of friends too so it's a triangular drama. Purely platonic, mind you. The reason IPython hits the soft spots with...

What is the best way to geotag jpeg-images with python?

I have coordinates from some source and want to tag my jpg files with them. What is the best python library for writing geotags into exif data? ...

Writing a simple "Rock Paper Scissors" game bot

I need help with a python game im working on (I just started learning Python about 3 days ago, so I'm still a nOob =) This is what I came up with: import random from time import sleep print "Please select: " print "1 Rock" print "2 Paper" print "3 Scissors" player = input ("Choose from 1-3: ") if player == 1: print "...

Is there a fast way to generate a dict of the alphabet in Python?

I want to generate a dict with the letters of the alphabet as the keys, something like letter_count = {'a': 0, 'b': 0, 'c': 0} what would be a fast way of generating that dict, rather than me having to type it in? Thanks for your help. EDIT Thanks everyone for your solutions :) nosklo's solution is probably the shortest Also, tha...

Is there a Python news site that's the near equivalent of RubyFlow?

I really like the format and type of links from RubyFlow for Ruby related topics. Is there an equivalent for Python that's active? There is a PythonFlow, but I think it's pretty much dead. I don't really like http://planet.python.org/ because there's lots of non-Python stuff on there and there's very little summarization of posts. ...

PYTHONSTARTUP doesn't seem to work

Hi, I'm trying to use the PYTHONSTARTUP environmental variable. I set it to be "c:\python25\pythonstartup.py" in My Computer --> Advanced etc., and it doesn't seem to work. Opening IDLE doesn't run the script, although it recognized the variable: >>> import os >>> os.environ['PYTHONSTARTUP'] 'c:\\python25\\pythonstartup.py' >>> I'm ...

Your most unpythonic code snippet

I am an experienced developer new to python, and still catching myself writing correct but unpythonic code. I thought it might be enlightening and entertaining to see small examples of python code people have written that in some way clashes with the generally preffered way of doing things. I'm interested in code you actually wrote rat...

What does "pythonic" mean?

exact duplicate: http://stackoverflow.com/questions/58968/what-defines-pythonian-or-pythonic I have no python experience at all. Help me to understand this term. Please provide code examples and explanations as to what makes a particular sample "pythonic" and why. ...