In Django Design Patterns, the author recommends using zlib.crc32 to mask primary keys in URLs. After some quick testing, I noticed that crc32 produces negative integers about half the time, which seems undesirable for use in a URL. zlib.adler32 does not appear to produce negatives, but is described as "weaker" than CRC.
Is this method...
I am learning Django and I am trying to understand the use of models.py in the project versus the application. It seems from the tutorial examples that I include a model definition in the app, but when I went to apply that knowledge to my own existing database I got stuck.
I took a database that I use (a copy of course) and generated t...
Hello,
Say I have a simple function:
def myfunc():
a = 4.2
b = 5.5
... many similar variables ...
I use this function one time only and I am wondering what is the easiest way to make all the variables inside the function accessible to my main name-space.
Do I have to declare global for each item? or any other suggested ...
I've been developing stuff using ActionScript since AS2,and when AS3 was released i had a bit of a hard time to understand its concepts. Then i realized i had to learn some OOP. I started studying OOP and now i feel i need to take a step further, that's why i chose Python.
Are there any tips/advices/hints or whatever like that to help me...
I've got a Python program that stores and writes data to a file. The data is raw binary data, stored internally as str. I'm writing it out through a utf-8 codec. However, I get UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 25: character maps to <undefined> in the cp1252.py file.
This looks to me like Python i...
I have a dict object. I dumped the data using this:
for alldata in data: # print all data to screen
print data[alldata]
Each field had brackets [] and 'None' values for NULLS and date.datetime for date values.
How do I dump this dict to MySQL table? Thank you!
print data displays something like this :
{'1': ['1', 'K', abc, 'xyz...
'm trying to make a small modification to django lfs project, that will allow me to deactivate products with no stocks. Unfortunatelly I'm just beginning to learn python, so I have big trouble with its syntax. That's what I'm trying to do. I'm using method 'is_variant' returning tru if my product is a sub type. If it is a variant I'm tur...
how do i setup authkit for more authorizer? i want to give certain users admin rights, but only for their own page. thanks
...
Hi,
I am trying to distribute my Python program. The program relies on version 2.6. I went through the distribution documentation: http://docs.python.org/distutils/index.html and what I have figured out so far is that I basically need to write a setup.py script. Something like:
setup(name='Distutils',
version='1.0',
description='Py...
I need some guidance on how to use session objects with SQLAlchemy, and how to organize Unit Tests of my mapped objects.
What I would like to able to do is something like this:
thing = BigThing() # mapped object
child = thing.new_child() # create and return a related object
thing.save() # will also save the child object
In order to a...
There is a python module called "_Qt". PyQt is not what I want. I was wondering if there was any documentation for the _Qt module installed with python as a standard module. I have a mac.
...
I'm trying to put together a simple program that will let me visualize a series of consecutive cuts on a wood panel using a router with a particular cutting head. I'm trying to find a decent geometry library that will give me a shortcut through the CAD-like stuff.
Specifically, I'd like to be able to define a rectangular solid (the w...
Hi, I've been using PGU(Phil's Pygame Utilities) for a while. It has a dictionary called tdata, which is passed as an argument while loading tiles
tdata = { tileno:(agroup, hit_handler, config)}
I'm making a pacman clone in which I have 2 groups : player and ghost, for which I want to collision detection with the same type of tile.
Fo...
Python says I need 4 bytes for a format code of "BH":
struct.error: unpack requires a string argument of length 4
Here is the code, I am putting in 3 bytes as I think is needed:
major, minor = struct.unpack("BH", self.fp.read(3))
"B" Unsigned char (1 byte) + "H" Unsigned short (2 bytes) = 3 bytes (!?)
struct.calcsize("BH") says 4 ...
What is the rationale behind the advocated use of the for i in xrange(...)-style looping constructs in Python? For simple integer looping, the difference in overheads is substantial. I conducted a simple test using two pieces of code:
File idiomatic.py:
#!/usr/bin/env python
M = 10000
N = 10000
if __name__ == "__main__":
x, y = 0...
How can I get the parent(s) object of python class?
...
I want to create an application that runs on the users computer, a stand-alone application, with installation and what-not, but I want the interface to be a browser, either internal and displayed as an OS window or external accessible using the browser (i.e. some http server).
The reason would be because I know a little about Python, bu...
Given a class such as
class MyClass:
text = "hello"
number = 123
Is there a way in python to inspect MyClass an determine that it has the two attributes text and number. I can not use something like inspect.getSource(object) because the class I am to get it's attributes for are generate using SWIG (so they are hidden in .so :)...
Hi,
I want to convert RGB values to HSV using python. I got some code samples, which gave the result with the S and V values greater than 100. (example : http://code.activestate.com/recipes/576554-covert-color-space-from-hsv-to-rgb-and-rgb-to-hsv/ ) . anybody got a better code which convert RGB to HSV and vice versa
thanks
...
Hi all,
I am trying to install the python wrapper for the ANN (approx near neighbors) c++ library: link is http://www.scipy.org/scipy/scikits/wiki/AnnWrapper . I am on Windows 7 32-bit.
Unfortunately the documentation is a bit terse and I am a newbie to programming in general, so I cannot decipher the instructions found within. I hav...