In some database technologies, for a attribute in a record, you can guarantee uniqueness of that attribute within the entire database. An example of this might be a email_address attribute in a User record. By setting email_address to unique, you guarantee that a particular email address can only appear in one record in the entire databa...
The following key:value pairs are 'page' and 'page contents'.
{
'section-a.html':{'contents':'section-b.html section-c.html section-d.html'},
'section-b.html':{'contents':'section-d.html section-e.html'},
'section-c.html':{'contents':'product-a.html product-b.html product-c.html product-d.html'},
'section-d.html':{'contents':'pr...
In this file, in the function cross_from_below(x, threshold), there is a line that says threshold = threshold. What's the point of this line? Does this do something differently than if this command weren't there?
...
Hello,
I am trying to make the SgmlLinkExtractor to work.
This is the signature:
SgmlLinkExtractor(allow=(), deny=(), allow_domains=(), deny_domains=(), restrict_xpaths(), tags=('a', 'area'), attrs=('href'), canonicalize=True, unique=True, process_value=None)
I am just using allow=()
So, I enter
rules = (Rule(SgmlLinkExtractor(all...
I am beginner in python and facing this problem. So how i can break the below expression in 2-3 lines
totalIncome = (classACost * float(classASeatsSold)) + (classBCost * float(classBSeatsSold)) + (classCCost * float(classCSeatsSold))
Like this.
totalIncome = (classACost * float(classASeatsSold)) +
(classBCost * float(classBSeatsSold...
I'm writing a few unit tests of some code which uses sys.stderr.write to report errors in input. This is as it should be, but this clobbers the unit test output. Is there any way to tell Python to not output error messages for single commands, à la 2> /dev/null?
...
I have strings which look like this one:
"(8, 12.25), (13, 15), (16.75, 18.5)"
and I would like to convert each of them into a python data structure. Preferably a list (or tuple) of tuples containing a pair of float values.
I could do that with eval("(8, 12.25), (13, 15), (16.75, 18.5)") which gives me a tuple of tuples, but I don't ...
Hello,
In the Scrapy tutorial there is this method of the BaseSpider:
make_requests_from_url(url)
A method that receives a URL and
returns a Request object (or a list of
Request objects) to scrape.
This method is used to construct the
initial requests in the
start_requests() method, and is
typically used to conv...
I have a folder full of Windows .URL files. I'd like to translate them into a list of MLA citations for my paper.
Is this a good application of Python? How can I get the page titles? I'm on Windows XP with Python 3.1.1.
...
I'm trying to learn python after spending the last 15 or so years working only in Perl and only occasionally.
I can't understand how to handle the two different kinds of results from the parse method of Calendar.parse() from parsedatetime
Given this script:
#!/usr/bin/python
import parsedatetime.parsedatetime as pdt
import parsedatet...
I'm trying to hide the Terminal when I launch a GUI Tkinter based app, but when I double click the app.py file on OSX, the Terminal window appears. I've tried changing the extension to .pyw and tried launching it with /usr/bin/pythonw, but no matter what, the Terminal window still appears.
I've even tried adding the try/except below,...
I'm writing a client for a group of RESTful services. The body of the REST calls have the same XML structure, given parameters. There are several dozen calls, and I will not be implementing all of them. As such, I want to make them easy to specify and easy to use. The REST methods are grouped by functionality in separate modules and will...
I have a class that contains a member object. I would like to call the member's methods as if they were methods of the container class.
The following example illustrates (however in a different context) what I would like to do.
Suppose we have two classes representing two different kinds of products: Toys and Shoes.
Each class has two ...
Hello spider experts:
I am a newbie trying to achive this simple task by using Scrapy with no luck so far. I am asking your advice about how to do this with Scrapy or with any other tool (with Python). Thank you.
I want to
start from a page that lists bios of attorneys whose last name start with A: initial_url = www.example.com/Attor...
Thanks for any response
...
Let's say I have teh following:
{{Hello|Hi|Hey} {world|earth} |
{Goodbye|farewell} {noobs|n3wbz|n00blets}}
And I want that to turn into any of the following:
Hello world
Goodbye noobs
Hi earth
farewell n3wbz
// etc.
Paying attention to the way the "spinning" syntax is nested. It could be nested a billion layers deep for al...
I'm looking to narrow a query set for a form field that has a foreignkey to the User's table down to the group that a user belongs to.
The groups have been previously associated by me. The model might have something like the following:
myuser = models.ForeignKey(User)
And my ModelForm is very bare bones:
class MyForm(ModelForm):...
So, I'm having some precision issues in Python.
I would like to calculate functions like this:
P(x,y) = exp(-x)/(exp(-x) + exp(-y))
Where x and y might be >1000. Python's math.exp(-1000) (in 2.6 at least!) doesn't have enough floating point precision to handle this.
this form looks like logistic / logit / log-odds, but it's not...
I have cyclical import issues adding some new code to a very large app, and I'm trying to determine which files are the most likely causes for this. It there any way to track which files import which files? I did a bit of looking and found the python trace command, but it's just showing a bunch of activity in the main python libraries.
...
Please take a look at this spider example in Scrapy documentation. The explanation is:
This spider would start crawling example.com’s home page, collecting category links, and item links, parsing the latter with the parse_item method. For each item response, some data will be extracted from the HTML using XPath, and a Item will be fi...