EMP_CHOICES = (
(0,'-- Select --'),
(1,'Good'),
(2,'Average'),
)
class EMPFeedback(models.Model):
user_choices = models.IntegerField(choices=EMP_CHOICES)
Run Code Online (Sandbox Code Playgroud)
如果存储在db中的值为1,则user_choices如何打印相应的user_choices对应的值(即1 == GOOD)
fb = EMPFeedback.objects.get(id=1)
print fb.user_choices # prints 1
print fb.user_choices.EMP_CHOICES
Run Code Online (Sandbox Code Playgroud) 在以下脚本中,我收到一个错误:
语法错误:意外的文件结束
这个错误是什么我可以恢复它?它指向调用函数的行.
#!/bin/sh
expected_diskusage="264"
expected_dbconn="25"
expected_httpdconn="20"
expected_cpuusage="95"
#expected_fd="100"
httpdconn=`ps -ef|grep -i httpd|grep -v grep|wc -l` #httpd connections
cpu_usage=`ps aux|awk 'NR > 0 { s +=$3 }; END {print s}'`
disk_usage=`df -h|awk {'print $2'}|head -n3|awk 'NF{s=$0}END{print s}'`
#db_connections=`mysql -uroot -pexxxxxx -s -N -e "show processlist"|wc -l`
db_connections=6
cld_alert()
{
nwconn=$1
cpu_usage=$2
disk_usage=$3
db_connections=$4
message=$5
`touch /tmp/alert.txt && > /tmp/alert.txt`
date=`date`
echo -e "$date\n" > /tmp/alert.txt
echo -e "$message" >> /tmp/alert.txt
path="/proc/$httpd/fd/";
cd $path
tfd=`ls -l|wc -l`;
sfd=`ls -ltr|grep sock|wc -l`; …Run Code Online (Sandbox Code Playgroud) int a= {1,3,6,7,1,2};
Run Code Online (Sandbox Code Playgroud)
哪种是对以下数组进行排序的最佳排序技术,如果存在重复,则如何处理它们.也是最好的分拣技术....
void BubbleSort(int a[], int array_size)
{
int i, j, temp;
for (i = 0; i < (array_size - 1); ++i)
{
for (j = 0; j < array_size - 1 - i; ++j )
{
if (a[j] > a[j+1])
{
temp = a[j+1];
a[j+1] = a[j];
a[j] = temp;
}
}
}
}
Run Code Online (Sandbox Code Playgroud) t=[]
t.append(("a",1))
t.append(("b",2))
t.append(("c",3))
return render_to_response(t.html, context_instance=RequestContext(request, {'t':t}))
Run Code Online (Sandbox Code Playgroud)
如果我想访问访问django模板中的值t而不使用for循环我该怎么办.我尝试了以下它似乎没有工作
alert('{{t[a]}}');
alert('{{t[c]}}');
Run Code Online (Sandbox Code Playgroud) 在下面的django模板变量中.是否可以通过django模板过滤器删除html标签
{{myvar|safe}}
Run Code Online (Sandbox Code Playgroud)
以下将输出html之类的
<div>sddfdsfsdfsdf sd fsdf sd fsdf </div><a>This link</a><img src="some source" />
Run Code Online (Sandbox Code Playgroud) time1 = "2010-04-20 10:07:30"
time2 = "2010-04-21 10:07:30"
Run Code Online (Sandbox Code Playgroud)
如何将上面的字符串转换为时间戳?
我需要减去上面的时间戳time2-time1.
在我的android项目中,我正在编写一个连接到服务器的程序,下面是我需要使用的库.
但我得到一个错误,说以下无法解决.如何解决此错误?我在Windows上使用eclipse JAVA EE.
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
Run Code Online (Sandbox Code Playgroud) 我有以下命令.无论.user.log文件存在于何处,我们都需要打印父目录(即hht和wee1.)如何做到这一点?
$ cd /nfs//office/ && find . -name '.user.log'
./hht/info/.user.log
./wee1/info/.user.log
Run Code Online (Sandbox Code Playgroud) 如何从排序列表中找到pythonic方式中缺少的数字
a=[1,2,3,4,5,7,8,9,10]
Run Code Online (Sandbox Code Playgroud)
我遇到过这篇文章,但有更简单有效的方法吗?
使用Beautiful Soup模块,如何获取div类名为feeditemcontent cxfeeditemcontent?的标签的数据?是吗:
soup.class['feeditemcontent cxfeeditemcontent']
Run Code Online (Sandbox Code Playgroud)
要么:
soup.find_all('class')
Run Code Online (Sandbox Code Playgroud)
这是HTML源:
<div class="feeditemcontent cxfeeditemcontent">
<div class="feeditembodyandfooter">
<div class="feeditembody">
<span>The actual data is some where here</span>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是Python代码:
from BeautifulSoup import BeautifulSoup
html_doc = open('home.jsp.html', 'r')
soup = BeautifulSoup(html_doc)
class="feeditemcontent cxfeeditemcontent"
Run Code Online (Sandbox Code Playgroud)