I have a list of strings - something like
mytext = ['This is some text','this is yet more text','This is text that contains the substring foobar123','yet more text']
I want to find the first occurrence of anything that starts with foobar. If I was grepping then I would do search for foobar*. My current solution looks like this
for...
Can anyone give me an example on how to use http://code.google.com/p/streamhtmlparser to parse out all the A tag href's from an html document? (either C++ code or python code is ok, but I would prefer an example using the python bindings)
I can see how it works in the python tests, but they expect special tokens already in the html at w...
Hi,
I use python 2.5, i like to replace certain variables in a txt file and write the complete data into new file.
i wrote a program to do the above,
from scipy import *
import numpy
from numpy import asarray
from string import Template
def Dat(Par):
Par = numpy.asarray(Par)
Par[0] = a1
Par[1] = a2
Par[2] = a3
Par[3] ...
Trying to run this file in eclipse
class Try:
def __init__(self):
pass
def __del__(self):
print 1
a=Try()
raw_input('waiting to finish')
and pressing the stop button without letting the program finish doesn't print "1", i.e the del method is never called. If i try to run the script from the shell and do ctrl-c\sys....
I try to customize behavior of sys.excepthook as described by the recipe.
in ipython:
:import pdb, sys, traceback
:def info(type, value, tb):
: traceback.print_exception(type, value, tb)
: pdb.pm()
:sys.excepthook = info
:--
>>> x[10] = 5
-------------------------------------------------
Traceback (most recent call last):
File...
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python 2.5.2 (r252:60911, Aug 8 2009, 17:18:03)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> import operator
Traceback (most rece...
What does it do, in Python 3.0? There's no documentation on the official Python website and help("nonlocal") does not work, either.
...
This is somewhat related to this question. Let's say I have a package that I want to deploy via rpm because I need to do some file copying on post-install and I have some non-python dependencies I want to declare. But let's also say I have some python dependencies that are easily available in PyPI. It seems like if I just package as a...
I'm looking for a library that let's configure/write special python block, something like ruby block and/or C-macros.
...
I am compiling numpy myself on Windows. The build and install runs fine; but how do I list the currently enabled modules .. and modules that are not made available (due to maybe compilation failure or missing libraries)?
...
I currently have a Python set of n size where n >= 0. Is there a quick 1 or 2 lines Python solution to do it? For example, the set will look like:
fruits = set(['apple', 'orange', 'watermelon', 'grape'])
The goal is to pick 2 random items from the above and it's possible that the above set can contain 0, 1 or more items. The only w...
Now don't get me wrong, I'm not exactly a Python fan, but when you see a Tk directory inside of the python directory you kinda expect... Well Python. And yeah, I get that Tk came from TCL, but if I had to write a TCL to use Tk, I'd forget TK existed and use a completely different tool box. (The popularity of this combination completely ...
Hi,
can one write sth like:
class Test(object):
def _decorator(self, foo):
foo()
@self._decorator
def bar(self):
pass
This fails: self in @self is unknown
I also tried:
@Test._decorator(self)
which also fails: Test unknown
If would like to temp. change some instance variables
in the decorator and th...
I'm having problems with my own modules overriding built in Python ones (specifically the logging module). Here's my project layout:
run.py
package/
__init__.py
logging/
__init__.py
...
run.py
from package import main
main()
package/__init__.py
from __future__ import absolute_import
import...
Hi all,
I have some code in Python where I'll have a bunch of classes, each of which will have an attribute _internal_attribute. I would like to be able to generate a mapping of those attributes to the original class. Essentially I would like to be able to do this:
class A(object):
_internal_attribute = 'A attribute'
class B(object...
Python's doctest module has a section for advanced API. Has anyone found a particular use for this API?
A quick look at the API structure (from the docs):
list of:
+------+ +---------+
|module| --DocTestFinder-> | DocTest | --DocTestRunner-> results
+------+ | ^ +---------+ ...
I'm looking for a way to find out the class structure at a glance for django. Is there a link to an overview of it?
...
I'm about to start a fairly large project for a mid-sized business
with a lot of integration with other systems (POS, accounting,
website, inventory, purchasing, etc.) The purpose of the system is to
try to reduce current data siloing and give employees role-based
access to the specific data entry and reports they need, as well as to
rep...
I am parsing a webpage which has Unicode representations of fractions. I would like to be able to take those strings directly and convert them to floats. For example:
"⅕" would become 0.2
Any suggestions of how to do this in Python?
...
I was wondering if there was anything similar like Mechanize or BeautifulSoup for PHP?
...