Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36301 > unrolled thread
| Started by | chaouche yacine <yacinechaouche@yahoo.com> |
|---|---|
| First post | 2013-01-06 15:12 -0800 |
| Last post | 2013-01-07 11:14 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Over 30 types of variables available in python ? chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-06 15:12 -0800
Re: Over 30 types of variables available in python ? Duncan Booth <duncan.booth@invalid.invalid> - 2013-01-07 11:14 +0000
| From | chaouche yacine <yacinechaouche@yahoo.com> |
|---|---|
| Date | 2013-01-06 15:12 -0800 |
| Subject | Over 30 types of variables available in python ? |
| Message-ID | <mailman.195.1357514135.2939.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
booleans ints, floats, longs, complexes strings, unicode strings lists, tuples, dictionaries, dictionary views, sets, frozensets, buffers, bytearrays, slices functions, methods, code objects,modules,classes, instances, types, nulls (there is exactly one object of type Null which is None), tracebacks, frames generators, iterators, xranges, files, memoryviews, context managers, These are all listed in this page http://docs.python.org/2/library/stdtypes.html as built-in types. Am I getting anything wrong here ? I'm a bit confused about it. I have never seen so many types in the few programming languages I saw.
[toc] | [next] | [standalone]
| From | Duncan Booth <duncan.booth@invalid.invalid> |
|---|---|
| Date | 2013-01-07 11:14 +0000 |
| Message-ID | <XnsA141722A75E9Bduncanbooth@127.0.0.1> |
| In reply to | #36301 |
chaouche yacine <yacinechaouche@yahoo.com> wrote:
>
> booleans
> ints, floats, longs, complexes
> strings, unicode strings
> lists, tuples, dictionaries, dictionary views, sets, frozensets,
> buffers, bytearrays, slices functions, methods, code
> objects,modules,classes, instances, types, nulls (there is exactly one
> object of type Null which is None), tracebacks, frames generators,
> iterators, xranges, files,
>
> memoryviews,
> context managers,
>
> These are all listed in this page
> http://docs.python.org/2/library/stdtypes.html as built-in types. Am I
> getting anything wrong here ? I'm a bit confused about it. I have
> never seen so many types in the few programming languages I saw.
Instances aren't types (though types themselves are instances): every
object in Python is an instance.
If you want a list of types that exist in your particular copy of Python
then you can print it out easily enough:
------------------------------------------------
def allsubclasses(base):
mod = base.__module__
if mod in ('builtins', '__builtin__', 'exceptions'):
yield getattr(base, '__qualname__', base.__name__)
else:
yield "{}.{}".format(base.__module__, getattr(base,
'__qualname__', base.__name__))
for typ in type.__subclasses__(base):
for t in allsubclasses(typ): yield t
all_types = sorted(set(allsubclasses(object)), key=str.lower)
print(len(all_types))
print(all_types)
------------------------------------------------
That won't show any types that haven't been imported, but it gives me
293 types that are all loaded on startup in Python 3.3 and 150 in Python
2.7.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web