I'm implementing the first option discussed in "Marking for deletion in Django", that is, when an object is no longer active, I set a boolean to mark it as inactive.
The specific reason I'm using this method is that although the object is no longer in active use, it may still be referenced and displayed in various records and reporting ...
I have a Python 2.6 web app built on Pylons 0.9.7. The code in my controller only runs the first time a client requests it, which is fair enough, but is there any way I can run some code as soon as the server starts and is ready to accept requests, without waiting until a request is actually received?
...
Four years ago I wrote a Sudoku puzzle solver, and now I'm trying to understand how it works so that I can reuse parts of it for a KenKen puzzle solver. I thought I'd better compactify loops into list comprehensions and pick more self-explanatory names for variables.
There's a class Puz which contains the input puzzle as a list of (8...
Hey everyone,
I'm currently working on a small script that needs to use gtk.StatusIcon(). For some reason, I'm getting some weird behavior with it. If I go into the python interactive shell and type:
>> import gtk
>> statusIcon = gtk.status_icon_new_from_file("img/lin_idle.png")
Pygtk does exactly what it should do, and shows an icon...
I have a program in C++ that uses the cryptopp library to decrypt/encrypt messages.
It offers two interface methods encrypt & decrypt that receive a string and operate on it through cryptopp methods.
Is there some way to use both methods in Python without manually wrapping all the cryptopp & files included?
Example:
import cppEncrypt...
I was playing around making a simple haiku site using sqlalchemy and pylons. It basically takes a haiku, writes it to a database, and displays the haiku. The problem appears when I get the data from the form and try and write it to a database, Pylons give me this error: AttributeError: 'tuple' object has no attribute 'insert' after I run...
I am looking for a solution to programmatically return all available serial ports with python.
At the moment I am entering ls /dev/tty.* or ls /dev/cu.* into the terminal to list ports and hardcoding them into the pyserial class.
...
Hi all,
I'm currently reading Dive Into Python by Mark Pilgrim, and have gotten to the section on inheritance. In section 5.5, Pilgrim mentions the differences between inheriting from the wrapper class UserDict vs inheriting from the built-in dict type.
I'm having trouble understanding why anyone would even bother with the wrapper cla...
I want a fast way to grab a URL and parse it while streaming. Ideally this should be super fast. My language of choice is Python. I have an intuition that twisted can do this but I'm at a loss to find an example.
...
Want to be able to provide a search interface for a collection of objects to be used by passing a list of keyword arguments like so:
playerID = players.search(nameFirst='ichiro', nameLast='suzuki')
Where players.search is defined like so:
def search(self, **args):
ret = []
for playerID, player in self.iteritems():
for key, value ...
If you have to choose a scripting language, why would you choose Python?
...
Hello, I have a Java socket server that is expecting exactly n bytes from some port. I want to write a Python clients that just sends bytes on some port to the Java server.
Since Python does not have primitives, I'm not sure to send exactly n bytes. Any suggestions?
More details:
I have a Java DatagramSocket that takes in n bytes:
Da...
What is that needs to be coded in Python instead of C/C++ etc? I know its advantages etc. I want to know why exactly makes Python The language for people in this industry?
...
It's said that Python automatically manages memory. I'm confused because I have a Python program consistently uses more than 2GB of memory.
It's a simple multi-thread binary data downloader and unpacker.
def GetData(url):
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read() // data size is about...
I'm trying to allow my users to pick which database to open. Each database will have the same schema. For some reason though I can't get my QTableView to populate after I open the database.
I'm paraphrasing the example code but this should give you an idea of what I'm trying to do.
works:
class aMainWindow(QMainWindow, Ui_MainWindow):...
if I have a string in the format of
(static string) name (different static string ) message (last static string)
(static string) name (different static string ) message (last static string)
(static string) name (different static string ) message (last static string)
(static string) name (different static string ) message (last static...
What is the difference between BaseHTTPServer and SimpleHTTPServer?
When and where should i use these?
...
Hi there,
I am interested in your opinions on unittesting code that uses Corba to communicate with a server.
Would you mock the Corba objects? In Python that's sort of a pain in the ass because all the methods of Corba objects are loaded dynamically. So you're basically stuck with "mock anything".
Thanks!
Note:
I believe I have not m...
I want to extract just the file name portion of a path. My code below works, but I'd like to know what the better (pythonic) way of doing this is.
filename = ''
tmppath = '/dir1/dir2/dir3/file.exe'
for i in reversed(tmppath):
if i != '/':
filename += str(i)
else:
break
a = filename[::-...
I want to fetch the title of a webpage which I open using urllib2. What is the best way to do this, to parse the html and find what I need (for now only the -tag but might need more in the future).
Is there a good parsing lib for this purpose?
...