[issue1288] dict.fromkeys - Odd logic when passing second dict.fromkeys as value

2007-10-16 Thread Adam Doherty

New submission from Adam Doherty:

Hello:

I'm am trying to conduct some tests on a list of data that checks for
the position of values in list elements using the bisect module.  To
store the results of these tests for output to a template I have build a
dictionary with 47 keys the values of which are dictionaries themselves.
 These inner dictionaries contain 7 keys that initially are valued at
zero.  Looping through the data in my list I check for values from 1 to
47 and if I find the value I am looking for I lookup it's position in
the row using the bisect module.  Using the current value I am looking
for and the position returned from bisect I increase the value in the
matching dictionary key value position by 1. Now for speed I have built
the dictionary using d =
dict.fromkeys(xrange(1,48),dict.fromkeys(xrange(1,8),0)) as this gives
the desired result.  Unfortunately when I run my test for values each
value in the dictionary is listed as the total number of rows in the
data list.  This is not the desired result which is correctly achieved
using:
d = {}
for x in xrange(1,48):
d[x] = dict.fromkeys(xrange(1,8),0)

I have included output from IDLE to demonstrate the problem.

--
components: Interpreter Core
files: problem-report.txt
messages: 56507
nosy: dohertywa
severity: normal
status: open
title: dict.fromkeys - Odd logic when passing second dict.fromkeys as value
type: behavior
versions: Python 2.3, Python 2.4, Python 2.5

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1288>
__>>> from bisect import bisect as bs
>>> from pysqlite2 import dbapi2 as sqlite
>>> conn = sqlite.connect("/home/dohertywa/testdata.db")
>>> data = [row for row in conn.execute("""SELECT f1,f2,f3,f4,f5,f6,f7 FROM 
>>> testtable WHERE strftime('%m', testdate) = strftime('%m', '0001-10-01')""")]
>>> conn.close()
>>> data
[(4, 6, 7, 10, 19, 39, 43), (2, 5, 30, 32, 36, 37, 42), (9, 14, 22, 29, 43, 44, 
46), (1, 13, 15, 18, 27, 32, 40), (2, 7, 19, 28, 31, 38, 45), (1, 2, 27, 33, 
34, 42, 45), (2, 11, 22, 23, 33, 45, 46), (10, 11, 19, 20, 31, 40, 44), (5, 10, 
26, 33, 42, 44, 45), (1, 11, 32, 33, 37, 45, 46), (8, 10, 12, 13, 19, 32, 42), 
(8, 13, 18, 21, 24, 25, 36), (8, 12, 17, 18, 28, 29, 35), (5, 7, 15, 24, 26, 
38, 43), (17, 21, 23, 25, 26, 33, 47), (16, 19, 27, 34, 44, 45, 46), (10, 22, 
31, 35, 40, 43, 46), (7, 15, 23, 25, 27, 37, 40), (1, 7, 19, 23, 35, 37, 45), 
(2, 5, 8, 11, 16, 20, 34), (7, 9, 16, 21, 27, 35, 45), (6, 14, 16, 20, 21, 23, 
37), (3, 10, 16, 18, 21, 37, 47), (8, 19, 20, 23, 27, 40, 44), (5, 9, 10, 14, 
32, 33, 39), (3, 4, 6, 13, 20, 34, 43), (25, 28, 29, 31, 32, 36, 45), (1, 2, 4, 
12, 20, 34, 36), (6, 10, 13, 25, 27, 40, 43), (6, 14, 25, 29, 30, 36, 40), (3, 
4, 5, 6, 41, 42, 45), (6, 19, 24, 25, 32, 34, 43), (5, 9, 10, 18, 20, 23, 46), 
(2, 3, 7, 10, 20, 24, 33), (8, 15, 16, 17, 22!
 , 32, 39), (7, 9, 12, 22, 24, 40, 41), (3, 11, 16, 21, 36, 43, 44), (2, 16, 
17, 31, 34, 36, 38), (10, 16, 18, 23, 35, 36, 46), (3, 14, 25, 31, 32, 44, 45), 
(3, 15, 23, 37, 38, 39, 43), (12, 22, 34, 37, 39, 43, 47), (3, 11, 23, 26, 27, 
28, 31), (1, 16, 18, 21, 31, 40, 42), (7, 24, 26, 29, 34, 42, 47), (3, 4, 9, 
18, 29, 34, 44), (3, 7, 14, 15, 20, 30, 46), (1, 8, 13, 23, 29, 31, 41), (14, 
15, 21, 34, 36, 42, 44), (21, 23, 25, 26, 39, 41, 45), (8, 10, 18, 19, 26, 35, 
42), (10, 15, 25, 30, 33, 40, 44), (2, 21, 23, 27, 29, 33, 41), (10, 16, 23, 
24, 27, 33, 46), (9, 15, 33, 34, 38, 41, 44), (3, 5, 13, 19, 26, 35, 41), (8, 
21, 29, 35, 38, 41, 46), (5, 20, 21, 23, 32, 40, 42), (3, 7, 27, 29, 38, 40, 
43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 0, 3: 0, 4: 0, 5: 0, 6:!
  0, 7: 0}, 22: {1: 0, 2: 0, 3: 0

[issue7144] imp.load_module in thread causes core dump on OSX 10.6

2009-11-04 Thread Adam Doherty

Adam Doherty  added the comment:

Hello:

Having the same issues in a web app I've written. Tested with the
default 2.5 and 2.6 on Snow Leopard and 2.5 on Ubuntu 8.04 (no problems
under Linux)  Replaced the default Python with 2.6.4 from python.org, my
app no longer crashes.

Hope it helps.

--
nosy: +dohertywa

___
Python tracker 
<http://bugs.python.org/issue7144>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com