>>> float(1)
1.0
>>> float(1) / 10
0.10000000000000001
>>> 4 + (float(1) / 10)
4.0999999999999996
4 + (float(1) / 10) is expected to be 4.10000000000000001
Is this a kind of bug?
Yet another newbie question..
Let's say I have an user table in declarative mode:
class User(Base):
__tablename__ = 'user'
id = Column(u'id', Integer(), primary_key=True)
name = Column(u'name', String(50))
When I have a list of users identifiers, I fetch them from db with:
user_ids = [1, 2, 3, 4, 5]
users = Session.query(User).filter(User.id.in_(user_ids)).all()
I dislike using in_ because I think I learned it has bad performance on indexed fields
(is that true/false?).
Anyway, is there a better way doing that query?
Thanks!
I will have a set of data (x, y, heading), and I need to animate it in real-time. I am currently using matplotlib to animate (x, y) and it works fine, but I would really like to have some way to indicate heading, ie what direction the object is facing. What would be the best library for this? It seems like PyGame might be able to help me out, but would I have to roll out my own graphing library for it?
Thanks
Lets say I have an application with a structure such as:
System
set date
set name
set something
Other
set death ray target
calibrate
and I want to have "back" and "next" buttons on a page. The catch is, if you're going in via the "wizard", I want the nav path to be something like "set name" - "set death ray target" - "set name". If you go via the Advanced options menu, I want to just iterate options... "set date" - "set name" - "set something" - "set death ray target" - calibrate.
So far, I'm thinking I have to use different URIs, but that's that. Any ideia how this could be done?
Thanks.
I have a model form that I use to update a model.
class Turtle(models.Model):
name = models.CharField(max_length=50, blank=False)
description = models.TextField(blank=True)
class TurtleForm(forms.ModelForm):
class Meta:
model = Turtle
Sometimes I don't need to update the entire model, but only want to update one of the fields. So when I POST the form only has information for the description. When I do that the model never saves because it thinks that the name is being blanked out while my intent is that the name not change and just be used from the model.
turtle_form = TurtleForm(request.POST, instance=object)
if turtle_form.is_valid():
turtle_form.save()
Is there any way to make this happen? Thanks!
Howdy - today a weird problem occured to me:
I have a modle class in Django and added a custom property to it that shall not be saved into the database and therefore is not represent in the models structure:
class Category(models.Model):
groups = models.ManyToManyField(Group)
title = defaultdict()
Now, when I'm within the shell or writing a test and I do the following:
c1 = Category.objects.create()
c1.title['de'] = 'german title'
print c1.title['de'] # prints "german title"
c2 = Category.objects.create()
print c2.title['de'] # prints "german title" <-- WTF?
It seems that 'title' is kind of global. If I change title to a simple string it works as expected, so it has to do something with the dict? I also tried setting title as a property:
title = property(_title)
But that did not work, too. So, how can I solve this? Thank you in advance!
enter code here
I need to open a file for reading and writing. If the file is not found, it should be created. It should also be treated as a binary for Windows. Can you tell me the file mode sequence I need to use for this?
I tried 'r+ab' but that doesn't create the files if they are not found.
Thanks
Ptterb can you post your full code please?
I copied your code.
Added fvidscale_cap to pipeline, with:
self.player.add(self.source, self.scaler, self.fvidscale_cap, self.sink)
gst.element_link_many(self.source,self.scaler, self.fvidscale_cap, self.sink)
From the main program I create a new QWidget, and pass its winId() to Vid constructor.
The widget start loading, but crashes.
The output says:
should be playing
Segmentation fault
i have a function which is a class method, and i want to test a attribute of the class which may or may not be None, but will exist always.
class classA():
def __init__(self, var1, var2 = None):
self.attribute1 = var1
self.attribute2 = var2
@classmethod
def func(self,x):
if self.attribute2 is None:
do something
i get the error
AttributeError: class classA has no attribute 'attributeB'
when i access the attribute like i showed but if on command line i can see it works,
x = classA()
x.attributeB is None
True
so the test works.
if i remove the @classmethod decorator from func, the problem disapears.
if i leave the @classmethod decorator, it only seems to affect variables which are supplied default values in the super-class's constructor.
whats going on in the above code?
After installing the BitTorrent-bencode package, either via easy_install BitTorrent-bencode or pip install BitTorrent-bencode, or by downloading the tarball and installing that via easy_install $tarball, I discover that /usr/local/lib/python2.6/dist-packages/BitTorrent_bencode-5.0.8-py2.6.egg/ contains EGG-INFO/ and test/ directories. Although both of these subdirectories contain files, there are no files in the BitTorr* directory itself. The tarball does contain bencode.py, which is meant to be the actual source for this package, but it's not installed by either of those utils.
I'm pretty new to all of this so I'm not sure if this is a problem with the package or with what I'm doing. The package was packaged a while ago (2007), so perhaps it's using some deprecated configuration aspect that I need to supply a command-line flag for.
I'm more interested in learning what's wrong with either the package or my procedures than in getting this particular package installed; there is another package called hunnyb that seems to do a decent enough job of decoding bencoded data. Mostly I'd like to know how to deal with such problems in other packages.
for st in Traks :
trak = TrakHtml()
trak.hawb = st
url = 'http://etracking.cevalogistics.com/eTrackResultsMulti.aspx?sv='+st
result = urlfetch.fetch(url)
trak.htmlData = result.content
trak.put()
trak.htmlData is a textproparty(). It's giving this error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 29284: ordinal not in range(128)
I have a simple rules/conditions table in my database which is used to generate alerts for one of our systems. I want to create a rules engine or a domain specific language.
A simple rule stored in this table would be..(omitting the relationships here)
if temp > 40 send email
Please note there would be many more such rules. A script runs once daily to evaluate these rules and perform the necessary actions. At the beginning, there was only one rule, so we had the script in place to only support that rule. However we now need to make it more scalable to support different conditions/rules. I have looked into rules engines , but I hope to achieve this in some simple pythonic way. At the moment, I have only come up with eval/exec and I know that is not the most recommended approach. So, what would be the best way to accomplish this??
( The rules are stored as data in database so each object like "temperature", condition like "/=..etc" , value like "40,50..etc" and action like "email, sms, etc.." are stored in the database, i retrieve this to form the condition...if temp 50 send email, that was my idea to then use exec or eval on them to make it live code..but not sure if this is the right approach )
I'm trying to use Eclipse + PyDev for studying OpenGL programming but when I type
from OpenGL.GL import *
from OpenGL.GLUT import *
IDE becomes extremely slow!
Ok. It isn't a smart idea import to much useless things but it's so useful for learning a new library!
Any help?
PS: I use Ubuntu with Eclipse Galileo.
Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there another way to do this?
In PHP you can create form elements with names like:
category[1]
category[2]
or even
category[junk]
category[test]
When the form is posted, category is automatically turned into a nice dictionary like:
category[1] => "the input value", category[2] => "the other input value"
Is there a way to do that in Django? request.POST.getlist isn't quite right, because it simply returns a list, not a dictionary. I need the keys too.
import math
def area(base, height):
'''(number,number) -> number
Return the area of a wirh given base and height.
>>>area(10,40)
200.0
'''
return base * height / 2
def perimeter(side1, side2, side3):
'''(number,number,number) -> number
Return the perimeter of the triangle with sides of
length side1,side2 and side3.
>>>perimeter(3,4,5)
12
>>>perimeter(10.5,6,9.3)
25.8
'''
return (side1 + side2 + side3)
def semiperimeter(side1, side2, side3):
return perimeter(side1, side2, side3) / 2
def area_hero(side1, side2, side3):
semi = semiperimeter(side1, side2, side3)
area = math.sqrt((semi * (semi - side1) * (semi - side2) * (semi - side3))
return area
class sss(webapp.RequestHandler):
def get(self):
url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
self.response.out.write(result.content)
and this view show :
when i change code to this:
if result.status_code == 200:
self.response.out.write(result.content.decode('utf-8').encode('gb2312'))
it show :
so ,what i should do ?
thanks
i have list similar to this
m=[['qw','wew','23','C:/xyz/s.wav'],['qw','wew','23','C:/xyz/s2.wav'],['qw','wew','23','C:/xyz/s1.wav']]
now i want to these files
win=wave.open(m[0][3],'rb')
it is giving error how can i use this in this way...
i want to take the files name from the list
please suggest???
hello
is there any way to get the selected item in a qmenu ?
i want to bind all items in that list to one function and get the item once user click it .
i've been looking for a way to get the item's label or index for 3 days , but couldn't find it .
any ideas ?
thanks in advance
info = {'phone_number': '123456', 'personal_detail': {'foo':foo, 'bar':bar}, 'is_active': 1, 'document_detail': {'baz':baz, 'saz':saz}, 'is_admin': 1, 'email': '[email protected]'}
return HttpResponse(simplejson.dumps({'success':'True', 'result':info}), mimetype='application/javascript')
if(data["success"] === "True") {
alert(data[**here I want to display personal_detail and document_details**]);
}
How can I do this?
I am using pygame and livewires (though I don't think that part is relevant here) to create a game. I've got the game working, but I'm trying to make something akin to a title screen before the game starts. However, it doesn't recognize when I try to make a new line appear. Here is what I have:
begin_message=games.Message(value=""" Destroy the Bricks!\n
In this game, you control a paddle,\n
controlled by your mouse,\n
and attempt to destroy all the rows of bricks.\n
Careful though, you only have 1 life.\n
Don't mess up! The game will start in\n
5 seconds.""",
size=30,
x=games.screen.width/2,
y=games.screen.height/2,
lifetime=500,
color=color.white,
is_collideable=False)
games.screen.add(begin_message)
The message appears on the screen, but the newline doesn't happen, so I can only read the first part of the message. Is there a way to make this message actually appear, or can I not use the 'Message' for this?