Basically to remove digits from a float to have a fixed number of digits after the dot, like:
1.923328437452 -> 1.923
EDIT: I need to output as a string to another function, not print.
Also I want to ignore the lost digits, not round them.
...
There's a nice plugin for Frog CMS that lets you just type in yourpicture.120x120.jpg or whatever, and it will automatically use the image in that dimension. If it doesn't exist, it creates it and adds it to the filesystem.
http://www.naehrstoff.ch/code/image-resize-for-frog
I was wondering if there's anything like this in Django/Pytho...
Technically it should iterate from 0 to rangeLength outputting the user name of the c[i][0].from_user...but from looking at example online, they seem to replace the brackets with dot notation. I have the following code:
<div id="right_pod">
{%for i in rangeLength%}
<div class="user_pod" >
{{c.i.0.from_user}}
</div>
{% endfor %}
...
Okay, it took me a little while to narrow down this problem, but it appears python is doing this one purpose. Can someone explain why this is happening and what I can do to fix this?
File: library/testModule.py
class testClass:
myvars = dict()
def __getattr__(self, k):
if self.myvars.has_key(k):
return sel...
Just wondering if there is a Python MTA. I took a look at smtpd but they all look like forwarders without any functionality.
...
In the interest of reusing some existing code that was defined as an instance method of a different class, I was tying to do something like the following:
class Foo(object):
def __init__(self):
self.name = "Foo"
def hello(self):
print "Hello, I am " + self.name + "."
class Bar(object):
def __init__(self):
self.name =...
I was looking around, and couldn't find the Python equivalent of browscap (that I've used in PHP to detect what browser a given user-agent string is.
I'm hoping I'm not going to have to write my own.. :P
...
G'day folks. I'm trying to introduce Ruby at work, and a few people are interested. However, I've been asked to present the benefits of Ruby over Python and PHP.
I've broken this down into 2 parts:
1) show Python and Ruby's advantages over PHP;
2) show Ruby's advantages over Python.
The first is easy. I'll explain things like:
Everyt...
I've been trying to find a more pythonic way of generating random string in python that can scale as well. Typically, I see something similar to
''.join(random.choice(string.letters) for i in xrange(len))
It sucks if you want to generate long string.
I've been thinking about random.getrandombits for a while, and figuring out how to c...
I'd like to use os.system("md5sum myFile") and have the result returned from os.system instead of just runned in a subshell where it's echoed.
In short I'd like to do this:
resultMD5 = os.system("md5sum myFile")
And only have the md5sum in resultMD5 and not echoed.
...
What is the simplest way to pick up the RGB color code of the given coordinates? For simplicity let's assume that the screen resolution is 1024x768 and color depth/quality 32 bits. The coordinates are given relative to the upper left corner of the screen. I'd like to get some tips or examples how it can be done with Python.
...
What ready available algorithms could I use to data mine twitter to find out the degrees of separation between 2 people on twitter.
How does it change when the social graph keeps changing and updating constantly.
And then, is there any dump of twitter social graph data which I could use rather than making so many API calls to start ove...
When digging into legacy Python code and writing Python code myself, I often use pylint. I'm also using Clone Digger. I've recently started to use rope, which is a library for automated refactoring.
But I'm looking for something else than rope. I would prefer a tool that just makes suggestions about possible refactorings: names the refa...
Is there a way to generically retrieve process stats using Perl or Python? We could keep it Linux specific.
There are a few problems: I won't know the PID ahead of time, but I can run the process in question from the script itself. For example, I'd have no problem doing:
./myscript.pl some/process/I/want/to/get/stats/for
Basically, I'...
I'm using libxml2 in a Python app I'm writing, and am trying to run some test code to parse an XML file. The program downloads an XML file from the internet and parses it. However, I have run into a problem.
With the following code:
xmldoc = libxml2.parseDoc(gfile_content)
droot = xmldoc.children # Get document root
dchild = d...
EDIT: Issue solved, answered it below. Lame error. Blah
So I upgraded to Django 1.1 and for the life of me I can't figure out what I'm missing. Here is my traceback:
http://dpaste.com/37391/ - This happens on any page I try to go to.
I've modified my urls.py to include the admin in the new method:
from django.contrib import admin
...
I am working for a company that provides customer support to its clients. I am trying to design a system that would send emails automatically to clients when some event occurs. The system would consist of a backend part and a web interface part. The backend will handle the communication with a web interface (which will be only for intern...
I have a Django website as follows:
site has several views
each view has its own template to show its data
each template extends a base template
base template is the base of the site, has all the JS/CSS and the basic layout
So up until now it's all good. So now we have the master head of the site (which exists in the base template), ...
In the test example http://django-rest-interface.googlecode.com/svn/trunk/django_restapi_tests/examples/custom_urls.py on line 19 to they parse the request.path to get the poll_id. This looks very fragile to me. If the url changes then this line breaks. I have attempted to pass in the poll_id but this did not work.
So my question is ...
Let's say I've got an HTML / CSS page with some images in it, and I wanted to generate a PDF from that source in Python - possible?
...