Possible Duplicate:
How to identiy whether a variable is a class or an object
I have a function which accepts 'things' which it calls.
def run_it(thingy):
result = thingy(something)
However, I'd like run_it() to accept both classes and objects/functions, and if it is a class, instantiate it first:
def run_it(thingy):
...
Let's say I need to save a matrix(each line corresponds one row) that could be loaded from fortran later. What method should I prefer? Is converting everything to string is the only one approach?
...
I am writing a crawler. Once after the crawler logs into a website I want to make the crawler to "stay-always-logged-in". How can I do that? Is a client (like browser, crawler etc.,) make a server to obey this rule? This scenario could occur when the server allows limited logins in day.
...
How can you call lpr in Python?
It is not in the sys -module which is surprising.
I aim to use the lpr as follows shown by pseudo-code
10*i for i in range(77):
lpr --pages(i,i+1) file.pdf
...
I'm trying to write my own media player (like Foobar), and I'm having trouble tracking down a Python library that'll play MP3s. I know Pymedia does mp3s, but it looks outdated - the latest installer is for Python version 2.4, and I'm using 2.6. I've never had much success with Pygame, and Pyglet doesn't look like it has too much in the w...
I have declared models in AppEngine's models.py:
class Post(db.Model):
topic = db.ReferenceProperty(Topic, collection_name='posts', verbose_name=_('Topic'))
(..)
class Topic(db.Model):
(..)
last_post = db.ReferenceProperty(Post, collection_name='last_topic_post')
Problem is ReferenceProperty must have Model class but Topic class is u...
From the Scrapy tutorial:
domain_name: identifies the Spider. It must be unique, that is, you can’t set the same domain name for different Spiders.
Does this mean that domain_name must be a valid domain name, like
domain_name = 'example.com'
Or can I name
domain_name = 'ex1'
The problem is I had a spider that worked with...
I'm new to Python (I have been programming in Java for multiple years now though), and I am working on a simple socket-based networking application (just for fun). The idea is that my code connects to a remote TCP end-point and then listens for any data being pushed from the server to the client, and perform some parsing on this.
The da...
This is the code for Spyder1 that I've been trying to write within Scrapy framework:
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
from scrapy.item import Item
from firm.items import FirmItem
class Spider1(CrawlSpider):...
Hi,
I have a string with a floating point number in it, but I can't get JSON to load it as a decimal.
x = u'{"14": [4.5899999999999999, "susan"]}'
json.loads(x, parse_float = decimal.Decimal)
This returns:
{u'14': [Decimal('4.5899999999999999'), u'susan']}
Any idea how I can make it into the actual "4.59"?
...
What are the technical reasons why languages like Python and Ruby are interpreted (out of the box) instead of compiled? It seems to me like it should not be too hard for people knowledgeable in this domain to make these languages not be interpreted like they are today, and we would see significant performance gains. So certainly I am mis...
Hello,
I've been trying to write this spider for weeks but without success. What is the best way for me to code this in Python:
1) Initial url: http://www.whitecase.com/Attorneys/List.aspx?LastName=A
2) from initial url pick up these urls with this regex:
hxs.select('//td[@class="altRow"][1]/a/@href').re('/.a\w+')
[u'/cabel', u'/jac...
hi folks!
I'm trying to bulk generate 4 thumnails for each of around 40k images with sorl-thumbnail for my django app. I iterate through all django objects with an ImageWithThumbnailsFieldFile, and then call its generate_thumbnails() function.
This works fine, except that after a few hundred iterations, I run out of memory and my loop ...
Hi all, I got an issue which is, in my code,anyone can help will be great.
this is the example code.
from random import *
from numpy import *
r=array([uniform(-R,R),uniform(-R,R),uniform(-R,R)])
def Ft(r):
for i in range(3):
do something here, call r
return something
however I found that in python shell, every tim...
I am new to Python and pyparsing. I need to accomplish the following.
My sample line of text is like this:
12 items - Ironing Service 11 Mar 2009 to 10 Apr 2009
Washing service (3 Shirt) 23 Mar 2009
I need to extract the item description, period
tok_date_in_ddmmmyyyy = Combine(Word(nums,min=1,max=2)+ " " + Word(alphas, exact=3)...
What datastructure would you use in Python to represent the internal state of a MineSweeper grid?
Each x,y position will hold a numerical value which represents its current cell state (unexplored, mine, flag, ?).
Should I use nested lists? This seems like the closest thing to a 2D array and it is what I would probably use in any other...
If you used named keys in Google App Engine, does this incur any additional cost? Put another way, is it any more expensive to create a new entity with a named key rather than a randomly generated id?
In a similar line of reasoning, I note that you can ask Google App Engine to give you a set of keys that will not be used by Google App E...
In Ruby on Rails, each model entity has a "validate_on_*something*" hook method, that will be called before the entity is actually persisted to the database. I would like similar functionality in Google App Engine. I am aware that you can do validation on individual Properties by passing arguments to them in their declarations. However, ...
I am following the tutorial on the DJango site, which I previsouly did using Windows XP and everything went fine, but on Windows 7 I get the following error:
sqlite3.OperationalError: unable to open database file
I use the following:
python manage.py sql Blog
Does any one have any ideas what might be wrong. The database file is lo...
Hello,
I'm trying to convert a synchronous library to use an internal asynchronous IO framework. I have several methods that look like this:
def foo:
....
sync_call_1() # synchronous blocking call
....
sync_call_2() # synchronous blocking call
....
return bar
For each of the synchronous functions (sync_call_*), I have...