Hello,
I have 3 panels and I want to make drags on them.
The problem is that when I do a drag on one this happens:
How can I refresh the frame to happear its color when the panel is no longer there?
MYMESSAGE = "<div>Hello</div><p></p>Hello"
send_mail("testing",MYMESSAGE,"[email protected]",['[email protected]'],fail_silently=False)
However, this message doesn't get the HTML mime type when it is sent. In my outlook, I see the code...
If I have an entity derived from db.Expando I can write Dynamic property by just assigning a value to a new property, e.g. "y" in this example:
class MyEntity(db.Expando):
x = db.IntegerProperty()
my_entity = MyEntity(x=1)
my_entity.y = 2
But suppose I have the name of the dynamic property in a variable... how can I (1) read and write to it, and (2) check if the Dynamic variable exists in the entity's instance? e.g.
class MyEntity(db.Expando):
x = db.IntegerProperty()
my_entity = MyEntity(x=1)
# choose a var name:
var_name = "z"
# assign a value to the Dynamic variable whose name is in var_name:
my_entity.property_by_name[var_name] = 2
# also, check if such a property esists
if my_entity.property_exists(var_name):
# read the value of the Dynamic property whose name is in var_name
print my_entity.property_by_name[var_name]
Thanks...
For formatting a date using date filter you must use the following format :
{{ my_date|date:"Y-m-d" }}
If you use strftime from the standard datetime, you have to use the following :
my_date.strftime("%Y-%m-%d")
So my question is ... isn't it ugly (I guess it is because of the % that is used also for tags, and therefore is escaped or something) ?
But that's not the main question ... I would like to use the same DATE_FORMAT parametrized in settings.py all over the project, but it therefore seems that I cannot ! Is there a work around (for example a filter that removes the % after the date has been formatted like {{ my_date|date|dream_filter }}, because if I just use DATE_FORMAT = "%Y-%m-%d" I got something like %2001-%6-%12)?
Hi all,
I find I've been confused by the problem that when I needn't to use try..except.For last few days it was used in almost every function I defined which I think maybe a bad practice.For example:
class mongodb(object):
def getRecords(self,tname,conditions=''):
try:
col = eval("self.db.%s" %tname)
recs = col.find(condition)
return recs
except Exception,e:
#here make some error log with e.message
What I thought is ,exceptions may be raised everywhere and I have to use try to get them.
And my question is,is it a good practice to use it everywhere when defining functions?If not are there any principles for it?Help would be appreciated!
Regards
More specifically I'm looking for something, perhaps an add-on for firefox, once enabled it logs all of this information as it's passed to and from the server. I'm doing some web scripting and this would be really handy.
If anyone is wondering specifically what I'm doing currently I'm trying to make a script to repost my craigslist ad every 2 days since I handle a few things on there. Might even go so far as to make a simple gui to manage the submissions.
I do suspect this goes against the ToS, for that reason I don't plan to release the code. Besides cl is already bad enough with spam, I'm not trying to contribute further to it, figured I'd say what I'm doing for the sake of being honest though. I don't have any bad intentions with this, just some things I've been trying to sell an ad for my pc repair business. I've been reposting some things for months now and so often I just forget to do it.
Hi everyone.
This question is in continuation to my previous question, in which I asked about passing around an ElementTree.
I need to read the XML files only and to solve this, I decided to create a global ElementTree and then parse it wherever required.
My question is:
Is this an acceptable practice? I heard global variables are bad. If I don't make it global, I was suggested to make a class. But do I really need to create a class? What benefits would I have from that approach. Note that I would be handling only one ElementTree instance per run, the operations are read-only. If I don't use a class, how and where do I declare that ElementTree so that it available globally? (Note that I would be importing this module)
Please answer this question in the respect that I am a beginner to development, and at this stage I can't figure out whether to use a class or just go with the functional style programming approach.
Ok, so I've written some code that, for all intents and purposes, should work:
def checkComments(comments):
for comment in comments:
print comment.body
checkComments(comment.replies)
def processSub(sub):
sub.replace_more_comments(limit=None, threshold=0)
checkComments(sub.comments)
#login and subreddit init stuff here
subs = mysubreddit.get_hot(limit=50)
for sub in subs:
processSub(sub)
However, given a submission that has 50 nested replies like so:
root comment
-> 1st reply
-> 2nd reply
-> 3rd reply
...
-> 50th reply
The above code only prints:
root comment
1st reply
2nd reply
3rd reply
4th reply
5th reply
6th reply
7th reply
8th reply
9th reply
Any idea how I can get the remaining 41 levels of replies? Or is this a praw limitation?
def common_elements(list1, list2):
"""
Return a list containing the elements which are in both list1 and list2
>>> common_elements([1,2,3,4,5,6], [3,5,7,9])
[3, 5]
>>> common_elements(['this','this','n','that'],['this','not','that','that'])
['this', 'that']
"""
for element in list1:
if element in list2:
return list(element)
Got that so far, but can't seem to get it to work! Thanks
let's say I have a list
li = [{'q':'apple','code':'2B'},
{'q':'orange','code':'2A'},
{'q':'plum','code':'2A'}]
What is the most efficient way to return the count of unique "codes" in this list?
In this case, the unique codes is 2, because only 2B and 2A are unique.
I could put everything in a list and compare, but is this really efficient?
I have a folder full of files and i want to search some string inside them. The issue is that some files may be zip,exe,ogg,etc.
Can i check somehow what kind of file is it so i only open and search through txt, php, etc files.
I can't rely on the file extension.
I'm working on a PyGTK app with some Buttons that, when clicked, give a text entry dialog, then set the text on the button to whatever was entered in the box. The problem is that if the text is longer than the button can show, the button changes size to accomodate. How do I keep GTK Buttons from resizing when the text changes?
Currently I have a website on the Google App Engine written in Google's webapp framework. What I want to know is what are the benefits of converting my app to run with django? And what are the downsides? Also how did you guys code your GAE apps? Did you use webapp or django? Or did you go an entirely different route and use the Java api?
Thanks
I am trying some simple c API, where I am using PyCapsule_New to encapsulate a pointer. I am running into segment violation, can some body help me.
mystruct *func1(int streamno, char mode,unsigned int options)
{
char * s;
s=malloc(100);
return s;
}
PyObject *Wrapper_func1(PyObject *self, PyObject *args)
{
int streamno;
char mode;
unsigned int options;
mystruct* result;
if (!PyArg_ParseTuple(args,"icI",&streamno,&mode,&options))
return NULL;
result = func1(streamno,mode,options);
return PyCapsule_New( result,NULL,NULL);
}
i want to find a webapp framework for validation user , store user,
and has ajax Effect of jquery ,
so ,did you know this simply framework ?
thanks
like this page : http: //digu.com/reg
I want get the details of the wave such as its frames into a array of integers.
Using fname.getframes we can ge the properties of the frame and save in list or anything for writing into another wav or anything,but fname.getframes gives information not in integers some thing like a "/xt/x4/0w' etc..
But i want them in integer so that would be helpful for manupation and smoothening join of 2 wav files
My test code is as follows, using threading, count is not 5,000,000 , so there has been data race, but using gevent, count is 5,000,000, there was no data race .
Is not gevent coroutine execution will atom "count + = 1", rather than split into a one CPU instruction to execute?
# -*- coding: utf-8 -*-
import threading
use_gevent = True
use_debug = False
cycles_count = 100*10000
if use_gevent:
from gevent import monkey
monkey.patch_thread()
count = 0
class Counter(threading.Thread):
def __init__(self, name):
self.thread_name = name
super(Counter, self).__init__(name=name)
def run(self):
global count
for i in xrange(cycles_count):
if use_debug:
print '%s:%s' % (self.thread_name, count)
count = count + 1
counters = [Counter('thread:%s' % i) for i in range(5)]
for counter in counters:
counter.start()
for counter in counters:
counter.join()
print 'count=%s' % count
I am having problem getting this piece of code to run. The class is Student which has a IdCounter, and it is where the problem seems to be. (at line 8)
class Student:
def __init__(self):
# Each student get their own student ID
idCounter = 0
self.gpa = 0
self.record = {}
# Each time I create a new student, the idCounter increment
idCounter += 1
self.name = 'Student {0}'.format(Student.idCounter)
classRoster = [] # List of students
for number in range(25):
newStudent = Student()
classRoster.append(newStudent)
print(newStudent.name)
I am trying to have this idCounter inside my Student class, so I can have it as part of the student's name (which is really an ID#, for example Student 12345. But I have been getting error.
Traceback (most recent call last):
File "/Users/yanwchan/Documents/test.py", line 13, in <module>
newStudent = Student()
File "/Users/yanwchan/Documents/test.py", line 8, in __init__
idCounter += 1
UnboundLocalError: local variable 'idCounter' referenced before assignment
I tried to put the idCounter += 1 in before, after, all combination, but I am still getting the referenced before assignment error, can you explain to me what I am doing wrong? Thank you
Edit: Provided the full code I have
I've installed virtualenv and virtualenvwrapper on Windows using easy_install. But mkvirtualenv is missing. I tried to search on my machine but I couldn't find it. I don't know how to solve it. Do you have any idea?
I'm running SQLAlchemy on Jython and trying to connect to a MS SQL database using jTDS with windows authentication. I can query and delete just fine but when I try to insert new values it will hang when I commit.
int 'before add'
session.add(newVal)
print 'after add'
session.commit()
print 'after commit'
I see the first two print statements but not the last. My CPU maxes out and I can't even query the table directly using the MS SQL Management Studio. When I kill the Jython java process I can query again but the new values haven't been added.
Strangely enough I can insert values directly using an SQL command:
insert_sql = "INSERT INTO my_table (my_value) VALUES ('test_value')"
session.execute(insert_sql)
session.commit()
Any ideas what I'm doing wrong?
Is it possible to use a back reference to specify the number of replications in a regular expression?
foo= 'ADCKAL+2AG.+2AG.+2AG.+2AGGG+.+G+3AGGa4.'
The substrings that start with '+[0-9]' followed by '[A-z]{n}.' need to be replaced with simply '+' where the variable n is the digit from earlier in the substring. Can that n be back referenced? For example (doesn't work) '+([0-9])[A-z]{/1}.' is the pattern I want replaced with "+" (that last dot can be any character and represents a quality score) so that foo should come out to ADCKAL++++G.G+.
foo = 'ADCKAL+2AG.+2AG.+2AG.+2AGGG^+.+G+3AGGa4.'
indelpatt = re.compile('\+([0-9])')
while indelpatt.search(foo):
indelsize=int(indelpatt.search(foo).group(1))
new_regex = '\+%s[ACGTNacgtn]{%s}.' % (indelsize,indelsize)
newpatt=re.compile(new_regex)
foo = newpatt.sub("+", foo)
I'm probably missing an easier way to parse the string.
I have a form in which I can input text through text boxes.
How do I make these data go into the db on clicking submit.
this is the code of the form in the template.
<form method="post" action="app/save_page">
<p>
Title:<input type="text" name="title"/>
</p>
<p>
Name:<input type="text" name="name"/>
</p>
<p>
Phone:<input type="text" name="phone"/>
</p>
<p>
Email:<input type="text" name="email"/>
</p>
<p>
<textarea name="description" rows=20 cols=60>
</textarea><br>
</p>
<input type="submit" value="Submit"/>
</form>
I have a function in the views.py for saving the data in the page. But I dont know how to impliment it properly:
def save_page(request):
title = request.POST["title"]
name = request.POST["name"]
phone = request.POST["phone"]
email = request.POST["email"]
description = request.POST["description"]
Now how do I send these into the db?
And what do I put in views.py so that those data goes into the db?
so how do I open a database connection and put those into the db and save it?
should I do something like :
connection=sqlite3.connect('app.db')
cursor= connection.cursor()
.....
.....
connection.commit()
connection.close()
Thank you.
I have the following models in my Django app. How can I from the Team model find all the User objects who have accepted as True in the Membership model? I know I need to use Team.objects.filter(), but I'm not sure how to check the value of the accepted field.
from django.contrib.auth.models import User
class Team(models.Model):
members = models.ManyToManyField(User, through="Membership")
class Membership(models.Model):
user = models.ForeignKey(User)
team = models.ForeignKey(Team)
accepted = models.BooleanField(default=False)
The title says it all. The objective is to have two simple ways to source some code, say func.R, containing a function. Calling R CMD BATCH func.R initializes the function and evaluates is. Within a session, issuing source("func.R") simply initializes the function.
Any idea?