Re: [Python-Dev] [Python-checkins] cpython (2.7): Fix closes Issue12529 - cgi.parse_header failure on double quotes and

2011-10-20 Thread Senthil Kumaran
On Thu, Oct 20, 2011 at 07:17:10AM +1000, Nick Coghlan wrote:
> NEWS entry? (same question for the later _sre fix)

Added. Thanks for catching this.

For some reason, I had slight doubt, if those issues were NEWS worthy
items.  IIRC, devguide recommends that a NEWS entry be added for all fixes
made, but still had a suspicion, if we unnecessarily add up too many
entries to NEWS.

Thanks,
Senthil

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Generate Dynamic lists

2011-10-20 Thread Asif Jamadar
So I'm trying to generate dynamic choices for  django form. Here i'm usig 
formset concept (CODE is mentioned below)



Suppose i have list called criteria_list = ['education', 'know how', 
'managerial', 'interpersonal', ]



now i need to generate choices as follows



list1 = [('education', 1), ('education', 2), ('education', 3), (''education' , 
4) , ('know how', 1) ('know ho', 2), ('know ho', 3), ('know ho', 4)]



list2 = [('education', 1), ('education', 2), ('education', 3), (''education' , 
4) , ('managerial', 1) ('managerial', 2), ('managerial', 3), ('managerial', 4)]



list3 = [('education', 1), ('education', 2), ('education', 3), (''education' , 
4) , ('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3), 
('interpersonal', 4)]



list4 = [('know how', 1), ('know how', 2), ('know how ', 3), ('know how' , 4) , 
('managerial', 1) ('managerial', 2), ('managerial', 3), ('managerial', 4)]



list5 = [('know how', 1), ('know how', 2), ('know how ', 3), ('know how' , 4) , 
('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3), 
('interpersonal', 4)]



list6= [('managerial', 1), ('managerial', 2), ('managerial ', 3), ('managerial' 
, 4) , ('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3), 
('interpersonal', 4)]





How can i achive this in python?



The above all eachh list become the  choices for each form.



Suppose i have formset of 6 forms. Then how can i assign above dynamic 
generates list to the choice field of each form.



I tried by using this following code but no luck





view.py



def evaluation(request):



evaluation_formset = formset_factory(EvaluationForm, 
formset=BaseEvaluationFormset, extra=6)



if request.POST:



formset = evaluation_formset(request.POST)



##validation and save



else:



formset = evaluation_formset()



render_to_response(formset)



forms.py





class EvaluationForm(forms.Form):



value = 
forms.ChoiceField(widget=forms.RadioSelect(renderer=HorizontalRadioRenderer))



class BaseEvaluationFormSet(BaseFormSet):

def __init__(self, *args, **kwargs):

super(BaseEvaluationFormSet, self).__init__(*args, **kwargs)

for form_index, form in enumerate(self.forms):



form.fields["value"].choices = self.choice_method(form_index)

def choice_method(self, form_index):

list = []

item_list = []

criteria_list = []

criteria_length = len(sub_criterias)-1

for criteria_index in range(criteria_length):

counter = 1

if criteria_index == form_index:

for j in range(criteria_length-counter):
x = 1
for i in range(6):
 criteria_list.append((sub_criterias[criteria_index], 
sub_criterias[criteria_index]))

item_list.append((sub_criterias[criteria_index+ 1], 
sub_criterias[criteria_index+1]))

list =  criteria_list +item_list

counter = counter + 1
if x != criteria_length:

x = x + 1



return list
















___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Generate Dynamic lists

2011-10-20 Thread Stefan Behnel

Asif Jamadar, 20.10.2011 20:51:

So I'm trying to generate dynamic choices for  django form.[...]


Note that this is the CPython core developers mailing list. The right list 
for general Python programming related questions is either 
[email protected], or the newsgroup comp.lang.python.


Stefan

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Generate Dynamic lists

2011-10-20 Thread Jacek Pliszka
I believe this is not the correct forum for this as it does not
concern development of Python language itself - you should post to
comp.lang.python. However solutions is relatively simply, try this:

list1,list2,list3,list4,list5,list6 = [ list(itertools.product(i,range(0,4)))
for i in itertools.combinations(criteria_list,2) ]

Best Regards,

Jacek Pliszka

2011/10/20 Asif Jamadar :
> So I'm trying to generate dynamic choices for  django form. Here i'm usig
> formset concept (CODE is mentioned below)
>
>
>
> Suppose i have list called criteria_list = ['education', 'know how',
> 'managerial', 'interpersonal', ]
>
>
>
> now i need to generate choices as follows
>
>
>
> list1 = [('education', 1), ('education', 2), ('education', 3), (''education'
> , 4) , ('know how', 1) ('know ho', 2), ('know ho', 3), ('know ho', 4)]
>
>
>
> list2 = [('education', 1), ('education', 2), ('education', 3), (''education'
> , 4) , ('managerial', 1) ('managerial', 2), ('managerial', 3),
> ('managerial', 4)]
>
>
>
> list3 = [('education', 1), ('education', 2), ('education', 3), (''education'
> , 4) , ('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3),
> ('interpersonal', 4)]
>
>
>
> list4 = [('know how', 1), ('know how', 2), ('know how ', 3), ('know how' ,
> 4) , ('managerial', 1) ('managerial', 2), ('managerial', 3), ('managerial',
> 4)]
>
>
>
> list5 = [('know how', 1), ('know how', 2), ('know how ', 3), ('know how' ,
> 4) , ('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3),
> ('interpersonal', 4)]
>
>
>
> list6= [('managerial', 1), ('managerial', 2), ('managerial ', 3),
> ('managerial' , 4) , ('interpersonal', 1) ('interpersonal', 2),
> ('interpersonal', 3), ('interpersonal', 4)]
>
>
>
>
>
> How can i achive this in python?
>
>
>
> The above all eachh list become the  choices for each form.
>
>
>
> Suppose i have formset of 6 forms. Then how can i assign above dynamic
> generates list to the choice field of each form.
>
>
>
> I tried by using this following code but no luck
>
>
>
>
>
> view.py
>
>
>
> def evaluation(request):
>
>
>
>     evaluation_formset = formset_factory(EvaluationForm,
> formset=BaseEvaluationFormset, extra=6)
>
>
>
>     if request.POST:
>
>
>
>     formset = evaluation_formset(request.POST)
>
>
>
>     ##validation and save
>
>
>
>     else:
>
>
>
>     formset = evaluation_formset()
>
>
>
>     render_to_response(formset)
>
>
>
> forms.py
>
>
>
>
>
> class EvaluationForm(forms.Form):
>
>
>
>     value =
> forms.ChoiceField(widget=forms.RadioSelect(renderer=HorizontalRadioRenderer))
>
>
>
> class BaseEvaluationFormSet(BaseFormSet):
>
>     def __init__(self, *args, **kwargs):
>
>     super(BaseEvaluationFormSet, self).__init__(*args, **kwargs)
>
>     for form_index, form in enumerate(self.forms):
>
>
>
>     form.fields["value"].choices = self.choice_method(form_index)
>
>     def choice_method(self, form_index):
>
>     list = []
>
>     item_list = []
>
>     criteria_list = []
>
>     criteria_length = len(sub_criterias)-1
>
>     for criteria_index in range(criteria_length):
>
>     counter = 1
>
>     if criteria_index == form_index:
>
>     for j in range(criteria_length-counter):
>     x = 1
>     for i in range(6):
>  criteria_list.append((sub_criterias[criteria_index],
> sub_criterias[criteria_index]))
>
>     item_list.append((sub_criterias[criteria_index+ 1],
> sub_criterias[criteria_index+1]))
>
>     list =  criteria_list +item_list
>
>     counter = counter + 1
>     if x != criteria_length:
>
>     x = x + 1
>
>
>
>     return list
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ___
> Python-Dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/jacek.pliszka%40gmail.com
>
>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Generate Dynamic lists

2011-10-20 Thread Oleg Broytman
Hello.

   We are sorry but we cannot help you. This mailing list is to work on
developing Python (adding new features to Python itself and fixing bugs);
if you're having problems learning, understanding or using Python, please
find another forum. Probably python-list/comp.lang.python mailing list/news
group is the best place; there are Python developers who participate in it;
you may get a faster, and probably more complete, answer there. See
http://www.python.org/community/ for other lists/news groups/fora. Thank
you for understanding.

On Thu, Oct 20, 2011 at 06:51:05PM +, Asif Jamadar wrote:
> So I'm trying to generate dynamic choices for  django form. Here i'm usig 
> formset concept (CODE is mentioned below)
> 
> 
> 
> Suppose i have list called criteria_list = ['education', 'know how', 
> 'managerial', 'interpersonal', ]
> 
> 
> 
> now i need to generate choices as follows
> 
> 
> 
> list1 = [('education', 1), ('education', 2), ('education', 3), (''education' 
> , 4) , ('know how', 1) ('know ho', 2), ('know ho', 3), ('know ho', 4)]
> 
> 
> 
> list2 = [('education', 1), ('education', 2), ('education', 3), (''education' 
> , 4) , ('managerial', 1) ('managerial', 2), ('managerial', 3), ('managerial', 
> 4)]
> 
> 
> 
> list3 = [('education', 1), ('education', 2), ('education', 3), (''education' 
> , 4) , ('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3), 
> ('interpersonal', 4)]
> 
> 
> 
> list4 = [('know how', 1), ('know how', 2), ('know how ', 3), ('know how' , 4) 
> , ('managerial', 1) ('managerial', 2), ('managerial', 3), ('managerial', 4)]
> 
> 
> 
> list5 = [('know how', 1), ('know how', 2), ('know how ', 3), ('know how' , 4) 
> , ('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3), 
> ('interpersonal', 4)]
> 
> 
> 
> list6= [('managerial', 1), ('managerial', 2), ('managerial ', 3), 
> ('managerial' , 4) , ('interpersonal', 1) ('interpersonal', 2), 
> ('interpersonal', 3), ('interpersonal', 4)]
> 
> 
> 
> 
> 
> How can i achive this in python?
> 
> 
> 
> The above all eachh list become the  choices for each form.
> 
> 
> 
> Suppose i have formset of 6 forms. Then how can i assign above dynamic 
> generates list to the choice field of each form.
> 
> 
> 
> I tried by using this following code but no luck
> 
> 
> 
> 
> 
> view.py
> 
> 
> 
> def evaluation(request):
> 
> 
> 
> evaluation_formset = formset_factory(EvaluationForm, 
> formset=BaseEvaluationFormset, extra=6)
> 
> 
> 
> if request.POST:
> 
> 
> 
> formset = evaluation_formset(request.POST)
> 
> 
> 
> ##validation and save
> 
> 
> 
> else:
> 
> 
> 
> formset = evaluation_formset()
> 
> 
> 
> render_to_response(formset)
> 
> 
> 
> forms.py
> 
> 
> 
> 
> 
> class EvaluationForm(forms.Form):
> 
> 
> 
> value = 
> forms.ChoiceField(widget=forms.RadioSelect(renderer=HorizontalRadioRenderer))
> 
> 
> 
> class BaseEvaluationFormSet(BaseFormSet):
> 
> def __init__(self, *args, **kwargs):
> 
> super(BaseEvaluationFormSet, self).__init__(*args, **kwargs)
> 
> for form_index, form in enumerate(self.forms):
> 
> 
> 
> form.fields["value"].choices = self.choice_method(form_index)
> 
> def choice_method(self, form_index):
> 
> list = []
> 
> item_list = []
> 
> criteria_list = []
> 
> criteria_length = len(sub_criterias)-1
> 
> for criteria_index in range(criteria_length):
> 
> counter = 1
> 
> if criteria_index == form_index:
> 
> for j in range(criteria_length-counter):
> x = 1
> for i in range(6):
>  criteria_list.append((sub_criterias[criteria_index], 
> sub_criterias[criteria_index]))
> 
> item_list.append((sub_criterias[criteria_index+ 1], 
> sub_criterias[criteria_index+1]))
> 
> list =  criteria_list +item_list
> 
> counter = counter + 1
> if x != criteria_length:
> 
> x = x + 1
> 
> 
> 
> return list
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

> ___
> Python-Dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: 
> http://mail.python.org/mailman/options/python-dev/phd%40phdru.name


Oleg.
-- 
 Oleg Broytmanhttp://phdru.name/[email protected]
   Programmers don't die, they just GOSUB without RETURN.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] memcmp performance

2011-10-20 Thread Richard Saunders
Hi,This is my first time on Python-dev, so I apologize for my newbie-ness.I have been doing some performance experiments with memcmp, and I wassurprised that memcmp wasn't faster than it was in Python.  I did a whole, long analysis and came up with some very simple results.Before I put in a tracker bug report, I wanted to present my findingsand make sure they were repeatable to others (isn't that the natureof science? ;)   as well as offer discussion.The analysis is a pdf and is here:     http://www.picklingtools.com/study.pdfThe testcases are a tarball here:   http://www.picklingtools.com/PickTest5.tar.gzI have three basic recommendations in the study: I amcurious what other people think.  Gooday,  Richie___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] memcmp performance

2011-10-20 Thread Antoine Pitrou

Hello,

> I have been doing some performance experiments with memcmp, and I was
> surprised that memcmp wasn't faster than it was in Python.  I did a whole, 
> long analysis and came up with some very simple results.
> 
> Before I put in a tracker bug report, I wanted to present my findings
> and make sure they were repeatable to others (isn't that the nature
> of science? ;)   as well as offer discussion.

Thanks for the analysis. Non-bugfix work now happens on Python 3, where
the str type is Python 2's unicode type. Your recommendations would
have to be revisited under that light.

Have you reported gcc's "outdated optimization" issue to them? Or is it
already solved in newer gcc versions?

Under glibc-based systems, it seems we can't go wrong with the system
memcpy function. If gcc doesn't get in the way, that is.

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] memcmp performance

2011-10-20 Thread Scott Dial
On 10/20/2011 5:08 PM, Antoine Pitrou wrote:
> Have you reported gcc's "outdated optimization" issue to them? Or is it
> already solved in newer gcc versions?

I checked this on gcc 4.6, and it still optimizes memcmp/strcmp into a
"repz cmpsb" instruction on x86. This has been known to be a problem
since at least 2002[1][2]. There are also some alternative
implementations available on their mailing list. It seems the main
objection to removing the optimization was that gcc isn't always
compiling against an optimized libc, so they didn't want to drop the
optimization. Beyond that, I think nobody was willing to put in the
effort to change the optimization itself.

[1] http://gcc.gnu.org/ml/gcc/2002-10/msg01616.html
[2] http://gcc.gnu.org/ml/gcc/2003-04/msg00166.html

-- 
Scott Dial
[email protected]
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [Python-checkins] cpython (2.7): Fix closes Issue12529 - cgi.parse_header failure on double quotes and

2011-10-20 Thread Nick Coghlan
My take is that a further fix or tweak to something that already has a NEWS
entry for the current release doesn't get a new entry, but everything else
does. "What's New" is the place to get selective.

--
Nick Coghlan (via Gmail on Android, so likely to be more terse than usual)
On Oct 21, 2011 2:46 AM, "Senthil Kumaran"  wrote:

> On Thu, Oct 20, 2011 at 07:17:10AM +1000, Nick Coghlan wrote:
> > NEWS entry? (same question for the later _sre fix)
>
> Added. Thanks for catching this.
>
> For some reason, I had slight doubt, if those issues were NEWS worthy
> items.  IIRC, devguide recommends that a NEWS entry be added for all fixes
> made, but still had a suspicion, if we unnecessarily add up too many
> entries to NEWS.
>
> Thanks,
> Senthil
>
>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] memcmp performance

2011-10-20 Thread Richard Saunders
Hey,> I have been doing some performance experiments with memcmp, and I was> surprised that memcmp wasn't faster than it was in Python.  I did a whole, > long analysis and came up with some very simple results.Paul Svensson suggested I post as much as I can as text, as people would be more likely to read it.So, here's the basic ideas:(1) memcmp is surprisingly slow on some Intel gcc platforms (Linux)        On several Linux, Intel platforms, memcmp was 2-3x slower than         a simple, portable C function (with some optimizations).(2) The problem: If you compile C programs with gcc with any optimization on,      it will replace all memcmp calls with an assembly language stub: rep cmpsb     instead of the memcmp call.(3) rep cmpsb seems like it would be faster, but it really isn't:       this completely bypasses the memcmp.S, memcmp_sse3.S      and memcmp_sse4.S in glibc which are typically  faster.(4) The basic conclusion is that the Python baseline on      Intel gcc platforms should probably be compiled with -fno-builtin-memcmp     so we "avoid" gcc's  memcmp optimization.The numbers are all in the paper: I will endeavor to try to generate a text formof all the tables so it's easier to read.  This is much first in the Python devarena, so I went a little overboard with my paper below. ;)  Gooday,  Richie> Before I put in a tracker bug report, I wanted to present my findings> and make sure they were repeatable to others (isn't that the nature> of science? ;)   as well as offer discussion.>> The analysis is a pdf and is here: >     http://www.picklingtools.com/study.pdf> The testcases are a tarball here:>    http://www.picklingtools.com/PickTest5.tar.gz>> I have three basic recommendations in the study: I am> curious what other people think.___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] memcmp performance

2011-10-20 Thread Stefan Behnel

Antoine Pitrou, 20.10.2011 23:08:

I have been doing some performance experiments with memcmp, and I was
surprised that memcmp wasn't faster than it was in Python.  I did a whole,
long analysis and came up with some very simple results.


Thanks for the analysis. Non-bugfix work now happens on Python 3, where
the str type is Python 2's unicode type. Your recommendations would
have to be revisited under that light.


Well, Py3 is quite a bit different now that PEP393 is in. It appears to use 
memcmp() or strcmp() a lot less than before, but I think unicode_compare() 
should actually receive an optimisation to use a fast memcmp() if both 
string kinds are equal, at least when their character unit size is less 
than 4 (i.e. especially for ASCII strings). Funny enough, tailmatch() has 
such an optimisation.


Stefan

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com