Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Christopher Reimer Newsgroups: comp.lang.python Subject: Re: Differences between Class(Object) and Class(Dict) for dictionary usage? Date: Wed, 27 Apr 2016 19:49:15 -0700 Lines: 56 Message-ID: References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> <57217A2B.4060709@icloud.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 2Cx2TzHtO75Y9xPcPFT+6wo8+GmWSoMqxQmlJiQY+cmA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(1,': 0.09; 'below).': 0.09; 'dict': 0.09; 'funny,': 0.09; 'subject:Object': 0.09; 'instead.': 0.15; 'subject: \n ': 0.15; '(2,': 0.16; '(8,': 0.16; '1))': 0.16; '2))': 0.16; 'duplicating': 0.16; 'guessing': 0.16; 'handling.': 0.16; 'mildly': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'self._state': 0.16; 'storing': 0.16; 'subject:between': 0.16; 'subject:usage': 0.16; 'wrote:': 0.16; '(see': 0.20; 'pass': 0.22; 'bit': 0.23; 'feature': 0.24; 'header :User-Agent:1': 0.26; 'chris': 0.26; 'have,': 0.27; 'pieces': 0.27; 'received:17': 0.27; '(my': 0.29; 'dictionary': 0.29; 'themselves': 0.29; 'code': 0.30; 'supposed': 0.31; 'especially': 0.32; 'received:10.0.0': 0.32; 'subject:) ': 0.32; 'michael': 0.33; 'instances': 0.33; 'loading': 0.33; 'file': 0.34; 'received:10.0': 0.34; 'could': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'list.': 0.37; 'things': 0.38; 'doing': 0.38; 'itself': 0.38; 'several': 0.38; 'someone': 0.38; 'thank': 0.38; 'means': 0.39; 'data': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'header:MIME- version:1': 0.60; 'your': 0.60; 'charset:windows-1252': 0.62; 'state,': 0.66; 'saving': 0.70; 'stated': 0.70; 'design.': 0.72; '3))': 0.84; '7:00': 0.84; 'header:In-reply-to:1': 0.84; 'subject:Class': 0.91 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-04-28_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1015 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1510270003 definitions=main-1604280038 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 In-reply-to: <57216EA8.4060600@gmail.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=4d515a; t=1461811755; bh=mTiSSz+TThDiiHgPCLKl3A28bdDr/7v6jIntJcc3Pg4=; h=Subject:To:From:Message-id:Date:MIME-version:Content-type; b=oAs49LCJBFVGxnWZyNoAF6jo2CohXZx5NgqDaJYcmVjuIas4EO9tEAVQ3i5vxlzth gdL0BoTQf/nN12nWGYeaQgQuMux2MWe7Smg/Rkh9MlyZV76mhntCo+1ya6iyO6RKhL 2Gc1kaA8tpcuK1rNJSDlKTCI4ol88jPXW30WCSvTglIlRczAw2M6vDZoXRtHAnAj5y u+iKXlVwwRsgazzbNTww8QXWMHl5Xy7UxUDUj4tw8zopWMkslqJWuXxtqENAnXxjxW kjI5LHMbWA37s/pz8nnmIYHz6C7fbLaGdA8XmSB/Aho8VAv9TkbmAqZjSJM/Ym3rTk R34atS5PNVSow== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <57217A2B.4060709@icloud.com> X-Mailman-Original-References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> Xref: csiph.com comp.lang.python:107743 On 4/27/2016 7:00 PM, Michael Torrie wrote: > I am guessing that the reason you are storing state as it's own > dictionary is so that you can pass the state itself to the constructor? Someone said it was bad to store the object itself to file (my original plan) and that I should use a dictionary instead. This is my implementation of that idea. However, saving and loading data is far down my to do list. > I know you've stated reasons for doing things the way you have, but > this self._state dict smells a bit funny, especially where you have > self._state = state, which means that several instances could have the > exact same state object at the same time and strikes me as mildly > un-pythonic and very confusing. "State" is what instances themselves > are supposed to track by design. I recommend you use this feature > rather than duplicating it with your own error-prone dict handling. So far the code is working as designed for new chess pieces (see below). Thank you, Chris R. Rook('white', (1, 1)) @ 2106251742008 Knight('white', (1, 2)) @ 2106251755648 Bishop('white', (1, 3)) @ 2106251755760 Queen('white', (1, 4)) @ 2106251755872 King('white', (1, 5)) @ 2106251755984 Bishop('white', (1, 6)) @ 2106251756096 Knight('white', (1, 7)) @ 2106251756208 Rook('white', (1, 8)) @ 2106251756320 Pawn('white', (2, 1)) @ 2106251756432 Pawn('white', (2, 2)) @ 2106251756544 Pawn('white', (2, 3)) @ 2106251756656 Pawn('white', (2, 4)) @ 2106251756768 Pawn('white', (2, 5)) @ 2106251756880 Pawn('white', (2, 6)) @ 2106251756992 Pawn('white', (2, 7)) @ 2106251757104 Pawn('white', (2, 8)) @ 2106251757216 Pawn('black', (7, 1)) @ 2106251742288 Pawn('black', (7, 2)) @ 2106251742400 Pawn('black', (7, 3)) @ 2106251742512 Pawn('black', (7, 4)) @ 2106251742624 Pawn('black', (7, 5)) @ 2106251742736 Pawn('black', (7, 6)) @ 2106251742848 Pawn('black', (7, 7)) @ 2106251742960 Pawn('black', (7, 8)) @ 2106251743072 Rook('black', (8, 1)) @ 2106251743184 Knight('black', (8, 2)) @ 2106251742120 Bishop('black', (8, 3)) @ 2106251740608 Queen('black', (8, 4)) @ 2106251740496 King('black', (8, 5)) @ 2106251740832 Bishop('black', (8, 6)) @ 2106251741672 Knight('black', (8, 7)) @ 2106251741784 Rook('black', (8, 8)) @ 2106251741896