I am trying to create a number of restricted permutations of a list of items. Each item has a category, and I need to find combinations of items such that each combination does not have multiple items from the same category. To illustrate, here's some sample data:
Name | Category
==========|==========
1. Orange | fruit
2. ...
Hi,
I have original class (DownloadPage) and I need to add just one simple functionality (get_info). What is better approach in OOP?
def get_info(page): # make simple function
...
result = get_info(DownloadPage())
or
class MyDownloadPage(DownloadPage): # make new class with inheritance
def get_info(self): # w...
What is the difference between defer.execute() and threads.deferToThread() in twisted? Both take the same arguments - a function, and parameters to call it with - and return a deferred which will be fired with the result of calling the function.
The threads version explicitly states that it will be run in a thread. However, if the defe...
I'm using the multiprocessing module to do parallel processing in my program. When I'm testing it, I'll often want to kill the program early when I notice a bug, since it takes a while to run to completion. In my Linux environment, I run my program from a terminal, and use Ctrl+C to kill it. With multiprocessing, this causes all the p...
Hi.
I'm trying to build a simple webpage with multiple checkboxes, a Textbox and a submit buttom.
I've just bumped into web programing in Python and am trying to figure out out to do it with CherryPy.
I need to associate each checkbox to a variable so my .py file knows which ones were selected when clicking the 'Start button'.
Can som...
I'm building a test suite for a python site, powered by hudson. Currently, the workflow for a test run looks like:
Pull down the latest version from the repository.
Create a new mysql db and import schema file and some fixture data.
Run tests, largely powered by webtest, which means not needing to run a web server.
Delete mysql db.
...
This is from some code I'm looking at... I think it's some sort of special format string that loads the file at the path into a binary string assigned to data, but I'm not sure as when I try to replicate it all I get is a standard string. Or is it actually a standard string and I'm reading too much into it?
...
I have a python script that makes an attribute table of a raster. This runs through all the rasters that I have which are floats, converts them to ints, then makes an attribute table.
On the first 3 rasters, I get a warning message,
Value range for c:\raster2 exceeds 100000 and number of unique values exceeds 500.
Please use BUILDVAT...
I am attempting to use Sphinx to document my Python class. I do so using autodoc:
.. autoclass:: Bus
:members:
While it correctly fetches the docstrings for my methods, those that are decorated:
@checkStale
def open(self):
"""
Some docs.
"""
# Code
with @checkStale being
def checkStale(f)...
What is the best way to make a variable that works exactly like a bool but prints On or Off rather than True or False? Currently the program is printing: Color: True, whereas Color: On would make more sense.
For the record, I initially tried to make an OnOff class that inherits from bool:
class OnOff(bool):
def __str__(self):
...
I would like a simple way to find and reformat text of the format 'DD/MM/YYYY' into 'YYYY/MM/DD' to be compatible with MySQL TIMESTAMPs, in a list of text items that may or may not contain a date atall, under python. (I'm thinking RegEx?)
Basically i am looking for a way to inspect a list of items and correct any timestamp formats found...
Is it a good idea to code such a script in Python and in which language is handy for fast performance and useful libraries/frameworks for charts?(charts would be created after calculating an expression which is input from the user)
EDIT:It's a web server-side script
...
In Vim, it's a quick 3-character command to change what's inside the current quoted string (e.g., ci"), but is there a simple way to change what type of quotes are currently surrounding the cursor?
Sometimes I need to go from "blah" to """blah""" or "blah" to 'blah' (in Python source code) and I'd ideally like to do it quickly using d...
I have a SQLite/Python code that runs the query command as follows.
def queryDB(self, command_):_
self.cursor.execute(command_)
self.connector.commit() # <---- ???
...
it works pretty well, but I have some questions.
Why connector.commit() is needed? What does it do?
What does cursor.execute() do?
...
A list in lisp is a series of cons cells, but in Python, a native list is a different kind of object. For translating code from lisp to Python, one might simply take lisp lists and translate them to Python native lists. However, this runs into trouble with side effecting cons cells not coming across to the Python code. For example, co...
Hello guys,
I have this table:
class Channel(rdb.Model):
rdb.metadata(metadata)
rdb.tablename("channels")
id = Column("id", Integer, primary_key=True)
title = Column("title", String(100))
hash = Column("hash", String(50))
runtime = Column("runtime", Float)
items = relationship(MediaItem, secondary="channel...
Here is a sample resource file for PythonCard:
{ 'application':{ 'type':'Application',
'name':'Test Sounds',
'backgrounds':
[
{ 'type':'Background',
'name':'Test Sounds',
'title':'Test Sounds',
'position':( 5, 5 ),
'size':( 300, 200 ),
'components':
[
{ 'type':'TextField', 'name':'fldFile...
Hi ,the URL of the problem is ( https://www.spoj.pl/problems/PRIME1/) yeah i did go through some thread about having time limit exceeded. I am using Python 2.6.4 . IDLE . The code is here :
def prime(a):
count=0
for i in range(2,int(math.sqrt(a))):
if(a%i==0):
count=count+1
if(count==0):
return...
Say that I have a C program and it has this line:
int a = 12;
Is the value of 12 bound to 'a' during compile time? Or is the value placed into memory during run time when the scope of the program hits 'a'?
What about programming languages like Python and Ruby?
Are there languages/instances where a value is statically bound to a vari...
Hello,
I have functions like this:
def activate_field_1():
print 1
def activate_field_2():
print 2
def activate_field_3():
print 3
How do I define activate_field_[x] for x=1:10, without typing out each one of them? I'd much rather pass a parameter, of course, but for my purposes this is not possible.
Thanks!
...