Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Aug 2008 17:00:10 -0500
From:      "Andrew Gould" <andrewlylegould@gmail.com>
To:        "Chuck Swiger" <cswiger@mac.com>
Cc:        FreeBSD Questions Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: Python script for configuring wifi hot spots on FreeBSD
Message-ID:  <d356c5630808201500x24efaeeanac7295445203312c@mail.gmail.com>
In-Reply-To: <33B2B005-C7DC-46A2-8C75-E7781710B26D@mac.com>
References:  <d356c5630808200844n66270c3ep251e2e38eb777141@mail.gmail.com> <33B2B005-C7DC-46A2-8C75-E7781710B26D@mac.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Aug 20, 2008 at 12:22 PM, Chuck Swiger <cswiger@mac.com> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?d356c5630808201500x24efaeeanac7295445203312c>