Manipulating MySQL Sets
Dave Angel
davea at ieee.org
Sun Dec 13 16:35:30 EST 2009
Victor Subervi wrote:
> On Sun, Dec 13, 2009 at 12:10 PM, Carsten Haese <carsten.haese at gmail.com>wrote:
>
>
>> Victor Subervi wrote:
>>
>>> I need to get at the individual elements of the set (that which is
>>> between the single quotes).
>>>
>> It's not quite clear what you mean by "get at the individual elements",
>> so I'll just show you a couple of things you can do to a set, and maybe
>> one of them comes close to what you need:
>>
>>
>>>>> from sets import Set
>>>>> aSet = Set(['Small', 'Extra-small', 'Medium'])
>>>>>
>> Do something for each element:
>>
>>
>>>>> for element in aSet:
>>>>>
>> ... print element
>> ...
>> Small
>> Extra-small
>> Medium
>>
>> Convert the set to list:
>>
>>
>>>>> list(aSet)
>>>>>
>> ['Small', 'Extra-small', 'Medium']
>>
>> Test membership in the set:
>>
>>
>>>>> 'Small' in aSet
>>>>>
>> True
>>
>>>>> 'Banana' in aSet
>>>>>
>> False
>>
>> Carsten, thank you (once again ;) for your patience. I didn't know I had to
>>
> import something.
> Thanks again,
> V
>
>
Have you bothered to find the help file for your particular version of
Python? In Windows, it's a .chm file, a compiled help file, but I'm
sure the same information is available on other distributions.. Anyway,
sets was a module introduced in Python 2.3, and deprecated in Python
2.6, where it's replaced by the built-in type set. So the answer of
whether you need to import or not depends on what version you're running.
In Python 2.5, it's (untested)
import sets
data = sets.Set(mylist)
In Python 2.6 it's
data = set(mylist)
The name datetime is both a module and a class.
import datetime #import the module
obj = datetime.datetime() #use the class within the module you
just imported
You can find the same information online, at least for version 2.6:
Sometimes I'll use google to find stuff specifically on python.org,
typing the following at the google serarch prompt::
datetime site:python.org
the first link in the results page is:
http://docs.python.org/library/datetime.html
which is the online version of the 2.6.4 help
Other useful links for the 2.6.4 documentation:
http://docs.python.org/modindex.html to search for modules
http://docs.python.org/genindex.html to search for anything
Each of these pages has a "quick search" option. For example, I found
the following page:
http://docs.python.org/library/stdtypes.html#set
DaveA
More information about the Python-list
mailing list