[web2py] Re: Issue with defaultdict(list)

2018-05-20 Thread Ricardo Cárdenas
Hi Drew and all,

I saw the same exact problem Drew saw with *defaultdict(list)*. For the 
benefit of any future debuggers, I thought I'd document what went wrong in 
our case.

One of the functions in the controller was inappropriately named *list()*, 
thus overriding the definition of *list()* itself. By the time the model 
code was called -- *g = defaultdict(list)* and then 
*g['foo'].append('someValue')* -- it raised the *AttributeError: 'dict' 
object has no attribute 'append'* exception that Drew saw.

This problem would not occur if the controller was not involved - i.e. from 
the Python interpreter.

warm regards,


On Friday, March 16, 2018 at 8:22:06 PM UTC-5, Drew Howell wrote:
>
> After taking a break and working on another section, I finally found what 
> was causing the issue. There was, indeed, an error elsewhere within that 
> controller, which was causing me all the headache. I appreciate your guys' 
> help! Thanks.
>
> On Sunday, March 11, 2018 at 11:14:27 PM UTC-4, Drew Howell wrote:
>>
>> I seem to be having issues getting defaultdict to work within Web2Py. I 
>> am using Web2Py version 2.16.1 (Python 2.7.11).
>>
>> Here is the code in my controller:
>> from collections import defaultdict
>> g = defaultdict(list)
>> g['someKey'].append('someValue')
>>
>> Here is the error I'm getting:
>>
>> File "D:/web2py/applications/fpr/controllers/students.py" 
>> , line 
>> 14, in view
>>  g['someKey'].append('someValue')
>> AttributeError: 'dict' object has no attribute 'append'
>>
>> If I do the same thing in the Python Interpreter, I don't seem to get the 
>> issue.
>>
>> >>> from collections import defaultdict
>> >>> g = defaultdict(list)
>> >>> g['k'].append('v')
>> >>> print g['k']
>> ['v']
>>
>> Am I implementing this wrong or is there some sort of issue with using 
>> defaultdict(list) in Web2Py?
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Issue with defaultdict(list)

2018-03-16 Thread Drew Howell
After taking a break and working on another section, I finally found what 
was causing the issue. There was, indeed, an error elsewhere within that 
controller, which was causing me all the headache. I appreciate your guys' 
help! Thanks.

On Sunday, March 11, 2018 at 11:14:27 PM UTC-4, Drew Howell wrote:
>
> I seem to be having issues getting defaultdict to work within Web2Py. I am 
> using Web2Py version 2.16.1 (Python 2.7.11).
>
> Here is the code in my controller:
> from collections import defaultdict
> g = defaultdict(list)
> g['someKey'].append('someValue')
>
> Here is the error I'm getting:
>
> File "D:/web2py/applications/fpr/controllers/students.py" 
> , line 
> 14, in view
>  g['someKey'].append('someValue')
> AttributeError: 'dict' object has no attribute 'append'
>
> If I do the same thing in the Python Interpreter, I don't seem to get the 
> issue.
>
> >>> from collections import defaultdict
> >>> g = defaultdict(list)
> >>> g['k'].append('v')
> >>> print g['k']
> ['v']
>
> Am I implementing this wrong or is there some sort of issue with using 
> defaultdict(list) in Web2Py?
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Issue with defaultdict(list)

2018-03-12 Thread Leonel Câmara
Drew most likely what's happening is a variation of this

g = defaultdict(list)
g['foo'] = {'id': 1} # this could be any dictionary
g['foo'].append('someValue')

AttributeError: 'dict' object has no attribute 'append'


Note that defaultdict only gives you the default if the key doesn't have a 
value already .

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Issue with defaultdict(list)

2018-03-12 Thread Drew Howell
I think I've narrowed it down to having an error somewhere in my 'students' 
controller.


   1. If I remove all other functions within that controller, it works.
   2. If I create a new controller and only have that function, it works.
   3. If I put the same exact code in another existing controller, it works.
   
I will have do some more testing to figure out where my actual problem 
lies.Will report back with any results.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Issue with defaultdict(list)

2018-03-12 Thread Drew Howell
I am running from source, but still seem to have the issue.

On Monday, March 12, 2018 at 1:55:51 AM UTC-4, Val K wrote:
>
> Hi! 
> If you're Windows user  it's requires to run web2py from source (not 
> web2py.exe) to get modules that are installed on your machine



I was doing some testing and it seems to work perfectly fine when I run it 
from default.py. However, any time I try to run it from the controller I 
need it in, it doesn't work. I even created the "test" function that worked 
for you, and I still get the "AttributeError: 'dict' object has no 
attribute 'append'". This one has really got me scratching my head. 

On Monday, March 12, 2018 at 7:14:59 AM UTC-4, Leonel Câmara wrote:
>
> This controller worked fine for me:
>
> def test():
> from collections import defaultdict
> g = defaultdict(list)
> g['somekey'].append('somevalue')
> return response.json(g)
>
>
>
> You probably have a bug in your view. You can show us the code if you want.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Issue with defaultdict(list)

2018-03-12 Thread Leonel Câmara
This controller worked fine for me:

def test():
from collections import defaultdict
g = defaultdict(list)
g['somekey'].append('somevalue')
return response.json(g)



You probably have a bug in your view. You can show us the code if you want.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.