Hi,
I am new to Google App Engine,
I have this entites User class -
user_id - integer
user_name - string
password - string
I want to do auto increment for the user_id,How I can 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.
How i can do image crop such in PIL in OpenCV.
Working example on PIL
im = Image.open('0.png').convert('L')
im = im.crop((1, 1, 98, 33))
im.save('_0.png')
But how i can do it on OpenCV?
I wanted to do so
im = cv.imread('0.png', cv.CV_LOAD_IMAGE_GRAYSCALE)
(thresh, im_bw) = cv.threshold(im, 128, 255, cv.THRESH_OTSU)
im = cv.getRectSubPix(im_bw, (98, 33), (1, 1))
cv.imshow('Img', im)
cv.waitKey(0)
But it doesnt work.
I think, i wrong use getRectSubPix. If it true, please explain how i can correctly use this function.
Thanks.
>>> 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?
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???
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've tried to connect to my local machine every time I try and run my program.
I am a nub, so it's probably a simple mistake somewhere.
def connect(self):
self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.conn.connect((self.host,self.port))
That is the code causing the error.
The host and port are defined.
Why is it giving me this error report?
[Errno 10061] No connection could be made because the target machine actively refused it
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?
I think small exercises would be the baest way for me to learn programming. I am the begginer and I am willing to give plenty of time to this.
To explain, to my opinion exercises should be something to write not long programs (10-30lines), to say what the program will print or that is the mistake.
Who can help me and say where to maybe a website with such stuff?
Thanks
I have written some classes in a java project and need to use them in jython code. how to go about it? I tried creating a jar of the java project and adding it to java classpath, even then import class_name doesnt work in jython code.
I've created a Sphinx document using sphinx-quickstart.
Are there any good examples/tutorials about customizing the look? Specifically to modify the header and add a logo.
Are there some projects with downloadable Sphinx docs? I would like to see how they've customized their look.
update: Adding a logo is supported in the default setup, just not particularly well documented. Look in conf.py for the *_logo settings.`
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.
Hiya.
When I install things into a virtualenv using pip I often see the message "UserWarning: Unbuilt egg for setuptools". I always safely ignore it and go about my business and it doesn't seem to cause me any problems.
But I've suddenly been smacked in the face with curiosity, and wondered if someone could explain what it means, exactly?
Also, does the new virtualenv option to use distribute instead fit into all this somewhere? Should I be using that instead, or just ignoring it until distutils2 comes out? (apologies if that's totally unrelated - maybe it should be a new question?)
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'm currently putting the finishing touches to an application for a client, this application sends daily emails to subscribers, is it possible to add custom headers to the email so that certain variables can be tracked, like day number (X-Day-Number) etc...
if data.find('!whois') != -1:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("com.whois-servers.net", 43))
s.send('www.msn.com' + "\r\n")
response = ''
while True:
d = s.recv(4096)
response += d
if d == '':
break
s.send('PRIVMSG ' + chan + " " + response + '\r\n')
s.close()
when I type !whois on the channel, it doesnt do anything, I'm probably doing this wrong. Any help will be appreciate it. Thanks.
Note: There's another socket already connected.
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 writing to many files in a threaded app and I'm creating one handler per file. I have HandlerFactory class that manages the distribution of these handlers. What I'd like to do is that
thread A requests and gets foo.txt's file handle from the HandlerFactory class
thread B requests foo.txt's file handler
handler class recognizes that this file handle has been checked out
handler class puts thread A to sleep
thread B closes file handle using a wrapper method from HandlerFactory
HandlerFactory notifies sleeping threads
thread B wakes and successfully gets foo.txt's file handle
This is what I have so far,
def get_handler(self, file_path, type):
self.lock.acquire()
if file_path not in self.handlers:
self.handlers[file_path] = open(file_path, type)
elif not self.handlers[file_path].closed:
time.sleep(1)
self.lock.release()
return self.handlers[file_path][type]
I believe this covers the sleeping and handler retrieval successfully, but I am unsure how to wake up all threads, or even better wake up a specific thread.
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?
Hello,
I have the following table in the model with a recursive structure (a page can have children pages)
class DynamicPage(models.Model):
name = models.CharField("Titre",max_length=200)
parent = models.ForeignKey('self',null=True,blank=True)
I want to create another table with manytomany relation with this one:
class UserMessage(models.Model):
name = models.CharField("Nom", max_length=100)
page = models.ManyToManyField(DynamicPage)
The generated SQL creates the following constraint:
ALTER TABLE `website_dynamicpage` ADD CONSTRAINT `parent_id_refs_id_29c58e1b` FOREIGN KEY (`parent_id`) REFERENCES `website_dynamicpage` (`id`);
I would like to have the ManyToMany with the page itself (the id) and not with the parent field.
How to modify the model to make the constraint using the id and not the parent?
Thanks in advance
I am trying to index a numpy.array with varying dimensions during runtime. To retrieve e.g. the first row of a n*m array a, you can simply do
a[0,:]
However, in case a happens to be a 1xn vector, this code above returns an index error:
IndexError: too many indices
As the code needs to be executed as efficiently as possible I don't want to introduce an if statement. Does anybody have a convenient solution that ideally doesn't involve changing any data structure types?
How can I list the numbers 01 to 12 (one for each of the 12 months) in such a way so that the current month always comes last where the oldest one is first. In other words, if the number is grater than the current month, it's from the previous year.
e.g. 02 is Feb, 2011 (the current month right now), 03 is March, 2010 and 09 is Sep, 2010 but 01 is Jan, 2011. In this case, I'd like to have [09, 03, 01, 02]. This is what I'm doing to determine the year:
for inFile in os.listdir('.'):
if inFile.isdigit():
month = months[int(inFile)]
if int(inFile) <= int(strftime("%m")):
year = strftime("%Y")
else:
year = int(strftime("%Y"))-1
mnYear = month + ", " + str(year)
I don't have a clue what to do next. What should I do here?
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?