On Mon, Aug 22, 2011 at 4:39 PM, Miki Tebeka wrote:
> You can check if there is a "non-allowed variable" and then return HTTP error.
> if set(form) - set(allowedVariables):
> print('Status: 406\n\n')
> raise SystemExit()
>
I'd be disinclined to do this; ignore unrecognized query variables,
On Aug 22, 9:39 am, Miki Tebeka wrote:
> HTH
Yes it helps, thank you!
-- Gnarlie
http://Gnarlodious.com
--
http://mail.python.org/mailman/listinfo/python-list
> Is there an easy way to limit updates to
> ONLY variables in the allowedVariables dict?
allowedVariables = ['eeny', 'meeny', 'miny', 'mo']
form = cgi.FieldStorage()
safe_input = dict((key, form.getvalue(key)) for key in allowedVariables)
> And in addition, maybe return an error so the attacke
In my last post I learned of the necessity of filtering CGI input, so
what I want to do is set a dict of allowable variable names:
allowedVariables = {'eeny':None, 'meeny':None, 'miny':None, 'mo':None}
# Set up a FieldStorage object:
import cgi
inputVariables = cgi.FieldStorage()
for name, value
csv file that would have the form
id var1 var2
123 4 3
157 2 0
i looks like the dict.update looks almost there but i can't get it to
work properly, can anyone offer any advise?
result=dict((key,(dict1.get(key,None),
dict2.get(key,None)))
for key i
Thanks Raymond,
That's a neat trick, i'll look into learning more about this
Mike
--
http://mail.python.org/mailman/listinfo/python-list
Thanks Diez,
This is almost perfect!
Is there a way to ensure each list has two elements, even if one of
them is blank?
Mike
--
http://mail.python.org/mailman/listinfo/python-list
gt; dict3 = {123:[4,3],157:[2,0],234:[5,5],456:[3,3],567:[2,0]}
>
> As later on i want to write a csv file that would have the form
>
> id var1 var2
> 123 4 3
> 157 2 0
>
> i looks like the dict.update looks almost there but i can't get it to
> wor
a csv file that would have the form
id var1 var2
123 4 3
157 2 0
i looks like the dict.update looks almost there but i can't get it to
work properly, can anyone offer any advise?
res = {}
for d in dict1, dict2:
for key, value in d.iteritems():
res.setde
would have the form
id var1 var2
123 4 3
157 2 0
i looks like the dict.update looks almost there but i can't get it to
work properly, can anyone offer any advise?
--
http://mail.python.org/mailman/listinfo/python-list
In article <[EMAIL PROTECTED]>,
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>
>What do other people find? Do you find use for dict.update()? What other
>idioms do you use for combining dictionaries?
My company's code relies heavily on d.update() -- it's ext
>> def create_request(url, headers):
>> headers.update(DEFAULT_HEADERS)
>> req = urllib2.Request(url, None, headers)
>> # ...
>> return req
>>
>> but of course this second example does the Wrong Thing, replacing
>> explicit headers with default values.
>
> There's a second code s
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> dict1.update(dict2) is of course equivalent to this code:
>
> for key, value in dict2.iteritems():
> dict1[key] = value
>
> Note that it replaces values in dict1 with the value taken from dict2. I
> don't know about other people, but I more often
urllib2.Request(url, None, headers)
# ...
return req
but of course this second example does the Wrong Thing, replacing
explicit headers with default values.
What do other people find? Do you find use for dict.update()? What other
idioms do you use for combining dictionaries?
Christopher Subich wrote:
> Peter Otten wrote:
>>
>> def add_freqs3(freq1, freq2):
>> total = dict(freq1)
>> for key, value in freq2.iteritems():
>> try:
>> total[key] += value
>> except KeyError:
>> total[key] = value
>> return total
>>
>
> U
Christopher Subich wrote:
> Peter Otten wrote:
> >
> > def add_freqs3(freq1, freq2):
> > total = dict(freq1)
> > for key, value in freq2.iteritems():
> > try:
> > total[key] += value
> > except KeyError:
> > total[key] = value
> > return total
>
Peter Otten wrote:
>
> def add_freqs3(freq1, freq2):
> total = dict(freq1)
> for key, value in freq2.iteritems():
> try:
> total[key] += value
> except KeyError:
> total[key] = value
> return total
>
Untested, but replacing the try/except pair
OK, I ran Peter's add_freq3 and it ran four times on really large
dictionaries in about 3000 seconds. So I'd say that at a minimum
that's ten times faster than my original function since it ran all
last night and didn't finish.
Much obliged, Peter!
-Greg
On 12/14/05, Gregory Piñero <[EMAIL PRO
Yes, that makes sense. I can't wait to run it tonight. Sorry I can't
give you the running time of my original function as it never finished
:-(
I'll report back the running time of the new function though, assuming
it finishes ;-)
Thanks again,
-Greg
On 12/14/05, Peter Otten <[EMAIL PROTECTE
Gregory Piñero wrote:
> Here's a question about your functions. if I only look at the keys in
> freq2 then won't I miss any keys that are in freq1 and not in freq2?
No. As I start with a copy of freq1, all keys of freq1 are already there.
There is probably a loop involved, but it in Python's un
Gregory Piñero wrote:
[top-posting rearranged]
> On 12/14/05, Peter Otten <[EMAIL PROTECTED]> wrote:
>
>>Gregory Piñero wrote:
>>
>>
>>>def add_freqs(freq1,freq2):
>>>"""Addtwowordfreqdicts"""
>>>newfreq={}
>>>forkey,valueinfreq1.items():
>>>newfreq[key]=value+freq2.get(key,0)
>>>forkey,valueinfre
Thanks Peter, those are some really good ideas. I can't wait to try
them out tonight.
Here's a question about your functions. if I only look at the keys in
freq2 then won't I miss any keys that are in freq1 and not in freq2?
That's why I have the two loops in my original function.
-Greg
On 1
Gregory Piñero wrote:
> def add_freqs(freq1,freq2):
> """Add two word freq dicts"""
> newfreq={}
> for key,value in freq1.items():
> newfreq[key]=value+freq2.get(key,0)
> for key,value in freq2.items():
> newfreq[key]=value+freq1.get(key,0)
> return newfreq
> A
Hey guys,
I thought I'd throw this out there since everyone loves optimization
questions (it's true, check out the number of replies to those type of
questions!)
Right now I have a function shown below. I want to combine two
dictionaries and add the values together where-ever there is overlap.
24 matches
Mail list logo