From owner-freebsd-questions@FreeBSD.ORG Wed Aug 20 22:00:15 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 642141065683 for ; Wed, 20 Aug 2008 22:00:15 +0000 (UTC) (envelope-from andrewlylegould@gmail.com) Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.224]) by mx1.freebsd.org (Postfix) with ESMTP id 268968FC31 for ; Wed, 20 Aug 2008 22:00:11 +0000 (UTC) (envelope-from andrewlylegould@gmail.com) Received: by rv-out-0506.google.com with SMTP id b25so1049698rvf.43 for ; Wed, 20 Aug 2008 15:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type:references; bh=cQB6cgn5qfuYi7x4MApFa1Zqr05woQ9L5CKtRenIKoY=; b=vLpC2TZTmC9ViZ9od4dZ51Xpv6lJ7V9CiSJGS9tJrdi9Qee17/sgXJoFlYUBx7Cld7 jbRMMgFaa9E/fDR/MjxPwtkSBY9Xoe0kji/fknoPHHicmwUokwJs4Bb1ptCjjSkn4g+S cmbCRDeHZzWYQlZ9luah5i6H0JO7ucaKl/Vww= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:references; b=SUwxPhW6QAZYRTWh8Ptm5WwLbuSKfVdxcqhZH4dbh7YskvJFgGEWvMYGPu7ANiex8v 9hXNlLfRl9jVv036hQwef97ZdWf1UGACyNTdK5NPloXfxZ8nUPxBkXV018W9ntR9itN1 fS9ur4tCZU+KAmDsaDSlgt8/xZcbT7MhYW/Wk= Received: by 10.140.247.11 with SMTP id u11mr346124rvh.37.1219269610204; Wed, 20 Aug 2008 15:00:10 -0700 (PDT) Received: by 10.140.199.11 with HTTP; Wed, 20 Aug 2008 15:00:10 -0700 (PDT) Message-ID: Date: Wed, 20 Aug 2008 17:00:10 -0500 From: "Andrew Gould" To: "Chuck Swiger" In-Reply-To: <33B2B005-C7DC-46A2-8C75-E7781710B26D@mac.com> MIME-Version: 1.0 References: <33B2B005-C7DC-46A2-8C75-E7781710B26D@mac.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: FreeBSD Questions Mailing List Subject: Re: Python script for configuring wifi hot spots on FreeBSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Aug 2008 22:00:17 -0000 On Wed, Aug 20, 2008 at 12:22 PM, Chuck Swiger wrote: > Hi, Andrew-- > > On Aug 20, 2008, at 8:44 AM, Andrew Gould wrote: > >> 2. I store data in Python dictionaries. When I display the dictionaries, >> the numbered options are not in order and I can't >> figure out how to sort them. This appears to be a cosmetic issue only; >> but it still bothers me. >> > > If you have a bunch of keys that are sortable, you can do something like: > > >>> dict = { 1: 'alpha', 4: 'gamma', 2: 'beta', 3: 'delta' } > >>> keylist = dict.keys(); keylist.sort() > >>> for k in keylist: print k, dict[k] > ... > 1 alpha > 2 beta > 3 delta > 4 gamma > > See http://docs.python.org/lib/typesmapping.html for more details: > > (3) Keys and values are listed in an arbitrary order which is non-random, > varies across Python implementations, and depends on the dictionary's > history of insertions and deletions. If items(), keys(), values(), > iteritems(), iterkeys(), and itervalues() are called with no intervening > modifications to the dictionary, the lists will directly correspond. This > allows the creation of (value, key) pairs using zip(): "pairs = > zip(a.values(), a.keys())". The same relationship holds for the iterkeys() > and itervalues() methods: "pairs = zip(a.itervalues(), a.iterkeys())" > provides the same value for pairs. Another way to create the same list is > "pairs = [(v, k) for (k, v) in a.iteritems()]". > > 3. My knowledge of networking is at a basic level. >> >> I have attached the script -- it is only 4KB. >> > > The mailing list strips off many file attachments. You'd do better to put > your script on a website somewhere, and mail out the URL to it... > > Regards, > -- > -Chuck > > The advice about sorting and keys() did the trick. (Thanks, Chuck!) I have placed an improved hotspot.py at: https://grokwell.org/freebsd/hotspot.py I signed my own certificate, so you'll be getting a warning about that when you visit my server. Again, any advice is welcome and appreciated. Thanks, Andrew