On Sat, Apr 23, 2016 at 9:31 PM Christopher Reimer < christopher_rei...@icloud.com> wrote:
> On 4/21/2016 10:25 PM, Stephen Hansen wrote: > > > > Why not, 'color in ("black", "white")'? > > Checkers seems popular around here. What if I want to change "white" to > "red," as red and black is a common color scheme for checkers. Do I > change a single constant variable or replace all the occurrences in the > files? > Why so many files? Python can easily support thousands of lines in a file. If it's just one file any text editor can do a quick find-replace. That said, it's easy to make some global ``red = 'red'``. Some of these constants are shortcuts. Instead of writing slice(0, 16) > or slice(48, 64), and getting the two confused, I write > const['board_bottom'] or const['board_top'], respectively, when I want > to pull the correct set of positions from coordinates list. > Why hide these things in a dict ``const`` instead of just making them top-level variables in the module themselves? ``board_top = slice(48, 64)`` > That said, if you're wanting to share constants across different parts > > of your code, use a module. > Or just use one file to keep things easier. But, yes, I agree a module of constants is appropriate for bigger projects. -- https://mail.python.org/mailman/listinfo/python-list