Форум сайта python.su
$ cat bib.xml
<?xml version='1.0' encoding='utf-8'?>
<!-- biblist -->
<list name = "test">
<item id = "1">
<author>Петров П.П.</author>
<title>Математика</title>
<keywords>ротор, дивергенция</keywords>
<file>./pertov.pdf</file>
</item>
<item id = "2">
<author>Иванов И.И.</author>
<title>Физика</title>
<keywords>закон Ома, закон Кулона</keywords>
<file>./ivanov.ps</file>
</item>
</list>
from django.forms.widgets import RadioFieldRenderer
class MyRadioFieldRenderer(RadioFieldRenderer):
def render(self):
return mark_safe(u'<ul>\n%s\n</ul>' % u'\n'.join([u'%s '
% force_unicode(w) for w in self]))
class MyRadioSelect(forms.RadioSelect):
renderer = MyRadioFieldRenderer
class ActivityForm(forms.Form):
form_kind = forms.ModelChoiceField(queryset = Kind.objects.all(), empty_label=None, widget=MyRadioSelect)
Traceback (most recent call last):
File "c:\Program Files\Python26\lib\site-packages\django\core\servers\basehttp.py", line 280, in run
self.result = application(self.environ, self.start_response)
File "c:\Program Files\Python26\lib\site-packages\django\core\servers\basehttp.py", line 674, in __call__
return self.application(environ, start_response)
File "c:\Program Files\Python26\lib\site-packages\django\core\handlers\wsgi.py", line 241, in __call__
response = self.get_response(request)
File "c:\Program Files\Python26\lib\site-packages\django\core\handlers\base.py", line 142, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)
File "c:\Program Files\Python26\lib\site-packages\django\core\handlers\base.py", line 166, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "c:\Program Files\Python26\lib\site-packages\django\views\debug.py", line 58, in technical_500_response
html = reporter.get_traceback_html()
File "c:\Program Files\Python26\lib\site-packages\django\views\debug.py", line 109, in get_traceback_html
frames = self.get_traceback_frames()
File "c:\Program Files\Python26\lib\site-packages\django\views\debug.py", line 228, in get_traceback_frames
pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
File "c:\Program Files\Python26\lib\site-packages\django\views\debug.py", line 209, in _get_lines_from_file
context_line = source[lineno].strip('\n')
IndexError: list index out of range
for i in objectlist:
self.list.append(i)
class Data(models.Model):
upload_id=models.IntegerField()
disty=models.IntegerField()
partnumber=models.IntegerField()
dealer=models.IntegerField()
city=models.IntegerField()
price=models.FloatField()
quantity=models.IntegerField()
date=models.DateField()
times=[line['date'] for line in Data.objects.values('date').distinct()] #не очень красиво конечно, пожелания принимаются
sales={}
for line in times:
# тут добывание значений, как сделать select sum(price*quantity) from data where date=line; я не разобрался поэтому вложенный цикл итд
#result помещаем вычисленную сумму за месяц
sales[line]=result
return render_to_response('total_sales_common.html', {sales':sales})
</ul>
<ul>
{% for key,value in sales %}
<li>
{{key}}, {{value}}
</li>
{% endfor %}
</ul>
times=[line['date'] for line in Data.objects.values('date').distinct()] #не очень красиво конечно, пожелания принимаются
sales=[]
for line in times:
# тут добывание значений, как сделать select sum(price*quantity) from data where date=line; я не разобрался поэтому вложенный цикл итд
#result помещаем вычисленную сумму за месяц
sales.append([line,reuslt])
return render_to_response('total_sales_common.html', {sales':sales})
</ul>
<ul>
{% for line in sales %}
<li>
{{line.0}}, {{line.1}}
</li>
{% endfor %}
</ul>
try:
import Tkinter
import tkFont
except:
import tkinter as Tkinter
import tkinter.font as tkFont
import ttk
class ToolPanel (object):
def __init__ (self,object) :
self.tp = ttk.Frame (self,object)
self.tp.pack ()
self.listButton = {}
self.bt = []
def NewButton(self,name, cupt) :
self.listButton[name]=cupt
self.bt.Add (Button (self.tp, text = cupt)).pack ()
if __name__ == '__main__' :
root = Tkinter.Tk()
kl = ToolPanel (root)
root.mainloop ()
def getSectionList(self, list=[]):
loclist=[]
for i in self.context.values():
if ISection.providedBy(i):
loclist.append(i)
if loclist != []: list.append(loclist)
if ISection.providedBy(self.context):
self.context.__parent__.getSectionList(list)
else: return list
<span tal:repeat="lst view/getSL">
[<span tal:repeat="sec lst">
<span tal:content="sec/__name__"></span>
</span>]
</span>
<span tal:repeat="lst python:view.getSectionList([])">
[<span tal:repeat="sec lst">
<span tal:content="sec/__name__"></span>
</span>]
</span>
$ cat data.txt
0 1 2
1 0 2
0 -1 2
-1 0 2
$ cat my_figure.py
#!/usr/bin/python
import pylab
from mpl_toolkits.mplot3d import Axes3D
from numpy import *
import numpy
x,y,z = loadtxt('data.txt', usecols=[0,1,2], unpack=True)
print "data from data.txt = ", x,y,z
X, Y = numpy.meshgrid(x,y)
print "X=", X
print "Y=", Y
Z = numpy.array([ [2.1, 2., 2., 2.], [2., 2., 2., 2.], [2., 2., 2., 2.], [2., 2. ,2., 2.] ])
print "Z=", Z
fig = pylab.figure()
axes = Axes3D(fig)
axes.plot_surface(X, Y, Z)
pylab.show()
$ ./my_figure.py
data from data.txt = [ 0. 1. 0. -1.] [ 1. 0. -1. 0.] [ 2. 2. 2. 2.]
X= [[ 0. 1. 0. -1.]
[ 0. 1. 0. -1.]
[ 0. 1. 0. -1.]
[ 0. 1. 0. -1.]]
Y= [[ 1. 1. 1. 1.]
[ 0. 0. 0. 0.]
[-1. -1. -1. -1.]
[ 0. 0. 0. 0.]]
Z= [[ 2.1 2. 2. 2. ]
[ 2. 2. 2. 2. ]
[ 2. 2. 2. 2. ]
[ 2. 2. 2. 2. ]]