python

python web crawler with thread support

Hello all, these day im making some web crawler script, but one of problem is my internet is very slow. so i was thought whether is it possible webcrawler with multithreading by use mechanize or urllib or so. if anyone have experience ,share info much appreciate. i was look for in google ,but not found much useful info. Thanks in advanc...

Catching a drag exit in Qt?

I've got a custom widget descended from QWidget that I want to be able to drop onto, and while the drag is hovering over the widget I'd like to highlight it to provide a little visual feedback to the user. Seems to me the simplest way to do this would be to highlight when dragEnterEvent is called and unhighlight when the drag exits the...

Advanced PDF Parsing Using Python (extracting text without tables, etc.): What's the Best Library?

I'm looking for a PDF library which will allow me to extract the text from a PDF document. I've looked at PyPDF, and this can extract the text from a PDF document very nicely. The problem with this is that if there are tables in the document, the text in the tables is extracted in-line with the rest of the document text. This can be prob...

Method Resolution Order (MRO) in new style Python classes

In the book "Python in a Nutshell" (2nd Edition) there is an example which uses old style classes to demonstrate how methods are resolved in classic resolution order and how is it different with the new order. I tried the same example by rewriting the example in new style but the result is no different than what was obtained with old s...

Python+Qt, QScrollArea problem: what's wrong with this code?

I have the following code: #!/usr/bin/env python import sys from PyQt4 import QtGui, QtCore class SimfilePanel(QtGui.QWidget): '''This class provides the simfile panel shown on the right side of the main window.''' def __init__(self, parent=None): '''Load song info here.''' QtGui.QWidget.__init__(self, parent) ## Mak...

How to do conditional character replacement within a string

I have a unicode string in Python and basically need to go through, character by character and replace certain ones based on a list of rules. One such rule is that a is changed to ö if a is after n. Also, if there are two vowel characters in a row, they get replaced by one vowel character and :. So if I have the string "natarook", what i...

Decorators on Django Template Filters?

I have a template filter that performs a very simple task and works well, but I would like to use a decorator on it. Unfortunately the decorator causes a nasty django error that doesn't make any sense... Code that works: @register.filter(name="has_network") def has_network(profile, network): hasnetworkfunc = getattr(profile, "has_%...

How should I organize Python source code?

I'm getting started with Python (it's high time I give it a shot), and I'm looking for some best practices. My first project is a queue which runs command-line experiments in multiple threads. I'm starting to get a very long main.py file, and I'd like to break it up. In general, I'm looking for: How do python programmers organize multip...

Do Python Dicts preserve iteration order if they are not modified?

If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups). ...

How do I INSERT INTO t1 (SELECT * FROM t2) in SQLAlchemy?

In SQLAlchemy, how do I populate or update a table from a SELECT statement? ...

What are the advantages and disadvantages of the require vs. import methods of loading code?

Ruby uses require, Python uses import. They're substantially different models, and while I'm more used to the require model, I can see a few places where I think I like import more. I'm curious what things people find particularly easy — or more interestingly, harder than they should be — with each of these models. In particular, if y...

How can you detect if two regular expressions overlap in the strings they can match?

I have a container of regular expressions. I'd like to analyze them to determine if it's possible to generate a string that matches more than 1 of them. Short of writing my own regex engine with this use case in mind, is there an easy way in C++ or Python to solve this problem? ...

Is pickle file of python cross-platform?

I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows. Is is so that python is coss-platform but the pickle file is not. Is there any solution to this one??? ...

Can SQLAlchemy's session.merge() update its result with newer data from the database?

The SQLAlchemy documentation says "session.merge() reconciles the current state of an instance and its associated children with existing data in the database". Does the existing object's state ever get updated by newer data from the database? How? When? ...

python crypt.crypt in ruby?

hi i need this code in ruby I don't know how I write the crypt.crypt method in ruby, any ideas? (I want to simulate the linux comand .htpasswd) import random import crypt letters = 'abcdefghijklmnopqrstuvwxyz' \ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \ '0123456789/.' salt = random.choice(letters) + random.choice(letters) pa...

How to use IPython with IronPython

What is the procedure to get IPython to use IronPython as it's Python interpreter? I know there were previously some issues: http://stackoverflow.com/questions/1160501/what-is-required-to-use-ipython-in-ironpython But now that these issues should be fixed, how do i actually go about this? The install doesn't detect IronPython as a ve...

What's the best python idiom for grouping a list of items into groups of a specific max size?

I want to write a function that takes items from a list and groups them into groups of size n. Ie, for n = 5, [1, 2, 3, 4, 5, 6, 7] would become [[1, 2, 3, 4, 5], [6, 7]]. What's the best python idiomatic way to do this? ...

Pyjamas import statements

I'm starting to use Pyjamas and I'm running into some annoyances. I have to import a lot of stuff to make a script work well. For example, to make a button I need to first from pyjamas.ui.Button import Button and then I can use Button. Note that import pyjamas.ui.Button and then using Button.Button doesn't work (results in error...

Looking for feedback on my program design

I'm aware that SO is for questions but overall the aim is to help people learn so I figured I'd try my hand at sharing some code and asking for feedback on it. I'm looking to create a program that will rely on random numbers, specifically dice. These will be presented in the form of "2D6", "4D10+3", "2D2 + 3D3" and so on and so forth....

Creating a generator expression from a list in python

What is the best way to do the following in Python: for item in [ x.attr for x in some_list ]: do_something_with(item) This may be a nub question, but isn't the list comprehension generating a new list that we don't need and just taking up memory? Wouldn't it be better if we could make an iterator-like list comprehension. ...