[Python-3000-checkins] r56781 - in python/branches/py3k-struni/Demo: cgi/cgi2.py classes/Dbm.py metaclasses/Enum.py newmetaclasses/Enum.py pdist/cmdfw.py pdist/cmptree.py pdist/cvslib.py pdist/rrcs.py pdist/server.py scripts/ftpstats.py scripts/markov.py scripts/newslist.py threads/Coroutine.py tix/samples/OptMenu.py tkinter/guido/AttrDialog.py xml/elem_count.py xml/roundtrip.py
skip.montanaro
python-3000-checkins at python.org
Mon Aug 6 23:07:54 CEST 2007
Author: skip.montanaro
Date: Mon Aug 6 23:07:53 2007
New Revision: 56781
Modified:
python/branches/py3k-struni/Demo/cgi/cgi2.py
python/branches/py3k-struni/Demo/classes/Dbm.py
python/branches/py3k-struni/Demo/metaclasses/Enum.py
python/branches/py3k-struni/Demo/newmetaclasses/Enum.py
python/branches/py3k-struni/Demo/pdist/cmdfw.py
python/branches/py3k-struni/Demo/pdist/cmptree.py
python/branches/py3k-struni/Demo/pdist/cvslib.py
python/branches/py3k-struni/Demo/pdist/rrcs.py
python/branches/py3k-struni/Demo/pdist/server.py
python/branches/py3k-struni/Demo/scripts/ftpstats.py
python/branches/py3k-struni/Demo/scripts/markov.py
python/branches/py3k-struni/Demo/scripts/newslist.py
python/branches/py3k-struni/Demo/threads/Coroutine.py
python/branches/py3k-struni/Demo/tix/samples/OptMenu.py
python/branches/py3k-struni/Demo/tkinter/guido/AttrDialog.py
python/branches/py3k-struni/Demo/xml/elem_count.py
python/branches/py3k-struni/Demo/xml/roundtrip.py
Log:
remove most uses of list(somedict.keys()) in Demo scripts
Modified: python/branches/py3k-struni/Demo/cgi/cgi2.py
==============================================================================
--- python/branches/py3k-struni/Demo/cgi/cgi2.py (original)
+++ python/branches/py3k-struni/Demo/cgi/cgi2.py Mon Aug 6 23:07:53 2007
@@ -14,7 +14,7 @@
print("<h1>No Form Keys</h1>")
else:
print("<h1>Form Keys</h1>")
- for key in list(form.keys()):
+ for key in form.keys():
value = form[key].value
print("<p>", cgi.escape(key), ":", cgi.escape(value))
Modified: python/branches/py3k-struni/Demo/classes/Dbm.py
==============================================================================
--- python/branches/py3k-struni/Demo/classes/Dbm.py (original)
+++ python/branches/py3k-struni/Demo/classes/Dbm.py Mon Aug 6 23:07:53 2007
@@ -12,7 +12,7 @@
def __repr__(self):
s = ''
- for key in list(self.keys()):
+ for key in self.keys():
t = repr(key) + ': ' + repr(self[key])
if s: t = ', ' + t
s = s + t
@@ -32,7 +32,7 @@
def keys(self):
res = []
- for key in list(self.db.keys()):
+ for key in self.db.keys():
res.append(eval(key))
return res
Modified: python/branches/py3k-struni/Demo/metaclasses/Enum.py
==============================================================================
--- python/branches/py3k-struni/Demo/metaclasses/Enum.py (original)
+++ python/branches/py3k-struni/Demo/metaclasses/Enum.py Mon Aug 6 23:07:53 2007
@@ -42,7 +42,7 @@
self.__name__ = name
self.__bases__ = bases
self.__dict = {}
- for key, value in list(dict.items()):
+ for key, value in dict.items():
self.__dict[key] = EnumInstance(name, key, value)
def __getattr__(self, name):
@@ -80,7 +80,7 @@
s = s + '(' + string.join([x.__name__ for x in self.__bases__], ", ") + ')'
if self.__dict:
list = []
- for key, value in list(self.__dict.items()):
+ for key, value in self.__dict.items():
list.append("%s: %s" % (key, int(value)))
s = "%s: {%s}" % (s, string.join(list, ", "))
return s
Modified: python/branches/py3k-struni/Demo/newmetaclasses/Enum.py
==============================================================================
--- python/branches/py3k-struni/Demo/newmetaclasses/Enum.py (original)
+++ python/branches/py3k-struni/Demo/newmetaclasses/Enum.py Mon Aug 6 23:07:53 2007
@@ -20,7 +20,7 @@
def __init__(cls, name, bases, dict):
super(EnumMetaclass, cls).__init__(name, bases, dict)
cls._members = []
- for attr in list(dict.keys()):
+ for attr in dict.keys():
if not (attr.startswith('__') and attr.endswith('__')):
enumval = EnumInstance(name, attr, dict[attr])
setattr(cls, attr, enumval)
Modified: python/branches/py3k-struni/Demo/pdist/cmdfw.py
==============================================================================
--- python/branches/py3k-struni/Demo/pdist/cmdfw.py (original)
+++ python/branches/py3k-struni/Demo/pdist/cmdfw.py Mon Aug 6 23:07:53 2007
@@ -104,9 +104,7 @@
c = c.__bases__[0]
if docstrings:
print("where subcommand can be:")
- names = list(docstrings.keys())
- names.sort()
- for name in names:
+ for name in sorted(docstrings.keys()):
print(docstrings[name])
if self.PostUsageMessage:
print(self.PostUsageMessage)
Modified: python/branches/py3k-struni/Demo/pdist/cmptree.py
==============================================================================
--- python/branches/py3k-struni/Demo/pdist/cmptree.py (original)
+++ python/branches/py3k-struni/Demo/pdist/cmptree.py Mon Aug 6 23:07:53 2007
@@ -89,7 +89,7 @@
else:
print("same mtime but different sum?!?!", end=' ')
print()
- for name in list(lsumdict.keys()):
+ for name in lsumdict.keys():
if not list(rsumdict.keys()):
print(repr(name), "only locally", end=' ')
fl()
Modified: python/branches/py3k-struni/Demo/pdist/cvslib.py
==============================================================================
--- python/branches/py3k-struni/Demo/pdist/cvslib.py (original)
+++ python/branches/py3k-struni/Demo/pdist/cvslib.py Mon Aug 6 23:07:53 2007
@@ -223,15 +223,12 @@
f.close()
def getlocalfiles(self):
- list = list(self.entries.keys())
+ entries_keys = set(self.entries.keys())
addlist = os.listdir(os.curdir)
for name in addlist:
- if name in list:
- continue
if not self.ignored(name):
- list.append(name)
- list.sort()
- for file in list:
+ entries_keys.add(name)
+ for file in sorted(entries_keys):
try:
e = self.entries[file]
except KeyError:
@@ -257,19 +254,17 @@
print('-'*50)
def keys(self):
- keys = list(self.entries.keys())
- keys.sort()
- return keys
+ return sorted(self.entries.keys())
def values(self):
def value(key, self=self):
return self.entries[key]
- return list(map(value, list(self.keys())))
+ return [value(k) for k in self.keys()]
def items(self):
def item(key, self=self):
return (key, self.entries[key])
- return list(map(item, list(self.keys())))
+ return [item(k) for k in self.keys()]
def cvsexists(self, file):
file = os.path.join("CVS", file)
Modified: python/branches/py3k-struni/Demo/pdist/rrcs.py
==============================================================================
--- python/branches/py3k-struni/Demo/pdist/rrcs.py (original)
+++ python/branches/py3k-struni/Demo/pdist/rrcs.py Mon Aug 6 23:07:53 2007
@@ -71,11 +71,9 @@
x.unlock(fn)
def info(x, copts, fn):
- dict = x.info(fn)
- keys = list(dict.keys())
- keys.sort()
- for key in keys:
- print(key + ':', dict[key])
+ info_dict = x.info(fn)
+ for key in sorted(info_dict.keys()):
+ print(key + ':', info_dict[key])
print('='*70)
def head(x, copts, fn):
Modified: python/branches/py3k-struni/Demo/pdist/server.py
==============================================================================
--- python/branches/py3k-struni/Demo/pdist/server.py (original)
+++ python/branches/py3k-struni/Demo/pdist/server.py Mon Aug 6 23:07:53 2007
@@ -101,9 +101,7 @@
def _listmethods(self, cl=None):
if not cl: cl = self.__class__
- names = list(cl.__dict__.keys())
- names = [x for x in names if x[0] != '_']
- names.sort()
+ names = sorted([x for x in cl.__dict__.keys() if x[0] != '_'])
for base in cl.__bases__:
basenames = self._listmethods(base)
basenames = list(filter(lambda x, names=names: x not in names, basenames))
Modified: python/branches/py3k-struni/Demo/scripts/ftpstats.py
==============================================================================
--- python/branches/py3k-struni/Demo/scripts/ftpstats.py (original)
+++ python/branches/py3k-struni/Demo/scripts/ftpstats.py Mon Aug 6 23:07:53 2007
@@ -106,9 +106,7 @@
n = len(title)
print('='*((70-n)/2), title, '='*((71-n)/2))
list = []
- keys = list(dict.keys())
- keys.sort()
- for key in keys:
+ for key in sorted(dict.keys()):
n = len(str(key))
list.append((len(dict[key]), key))
maxkeylength = 0
@@ -128,8 +126,7 @@
n = len(title)
print('='*((70-n)/2), title, '='*((71-n)/2))
list = []
- keys = list(dict.keys())
- for key in keys:
+ for key in dict.keys():
list.append((-len(dict[key]), key))
list.sort()
for count, key in list[:maxitems]:
Modified: python/branches/py3k-struni/Demo/scripts/markov.py
==============================================================================
--- python/branches/py3k-struni/Demo/scripts/markov.py (original)
+++ python/branches/py3k-struni/Demo/scripts/markov.py Mon Aug 6 23:07:53 2007
@@ -87,7 +87,7 @@
return
if debug: print('done.')
if debug > 1:
- for key in list(m.trans.keys()):
+ for key in m.trans.keys():
if key is None or len(key) < histsize:
print(repr(key), m.trans[key])
if histsize == 0: print(repr(''), m.trans[''])
Modified: python/branches/py3k-struni/Demo/scripts/newslist.py
==============================================================================
--- python/branches/py3k-struni/Demo/scripts/newslist.py (original)
+++ python/branches/py3k-struni/Demo/scripts/newslist.py Mon Aug 6 23:07:53 2007
@@ -172,10 +172,9 @@
createpage(p[1:], tree, p)
return
- kl = list(tree.keys())
+ kl = sorted(tree.keys())
if l > 1:
- kl.sort()
if indent > 0:
# Create a sub-list
f.write('<LI>'+p[1:]+'\n<UL>')
Modified: python/branches/py3k-struni/Demo/threads/Coroutine.py
==============================================================================
--- python/branches/py3k-struni/Demo/threads/Coroutine.py (original)
+++ python/branches/py3k-struni/Demo/threads/Coroutine.py Mon Aug 6 23:07:53 2007
@@ -127,7 +127,7 @@
if self.killed:
raise TypeError('kill() called on dead coroutines')
self.killed = 1
- for coroutine in list(self.invokedby.keys()):
+ for coroutine in self.invokedby.keys():
coroutine.resume()
def back(self, data=None):
Modified: python/branches/py3k-struni/Demo/tix/samples/OptMenu.py
==============================================================================
--- python/branches/py3k-struni/Demo/tix/samples/OptMenu.py (original)
+++ python/branches/py3k-struni/Demo/tix/samples/OptMenu.py Mon Aug 6 23:07:53 2007
@@ -40,7 +40,7 @@
# global variables "demo_opt_from" and "demo_opt_to". Otherwise
# the OptionMenu widget will complain about "unknown options"!
#
- for opt in list(options.keys()):
+ for opt in options.keys():
from_file.add_command(opt, label=options[opt])
to_file.add_command(opt, label=options[opt])
Modified: python/branches/py3k-struni/Demo/tkinter/guido/AttrDialog.py
==============================================================================
--- python/branches/py3k-struni/Demo/tkinter/guido/AttrDialog.py (original)
+++ python/branches/py3k-struni/Demo/tkinter/guido/AttrDialog.py Mon Aug 6 23:07:53 2007
@@ -112,7 +112,7 @@
def addchoices(self):
self.choices = {}
list = []
- for k, dc in list(self.options.items()):
+ for k, dc in self.options.items():
list.append((k, dc))
list.sort()
for k, (d, c) in list:
@@ -260,7 +260,7 @@
classes = {}
for c in (self.classes,
self.addclasses[self.klass]):
- for k in list(c.keys()):
+ for k in c.keys():
classes[k] = c[k]
self.classes = classes
@@ -273,7 +273,7 @@
def update(self):
self.current = {}
self.options = {}
- for k, v in list(self.configuration.items()):
+ for k, v in self.configuration.items():
if len(v) > 4:
self.current[k] = v[4]
self.options[k] = v[3], v[2] # default, klass
Modified: python/branches/py3k-struni/Demo/xml/elem_count.py
==============================================================================
--- python/branches/py3k-struni/Demo/xml/elem_count.py (original)
+++ python/branches/py3k-struni/Demo/xml/elem_count.py Mon Aug 6 23:07:53 2007
@@ -15,7 +15,7 @@
self._attrs = self._attrs + len(attrs)
self._elem_types[name] = self._elem_types.get(name, 0) + 1
- for name in list(attrs.keys()):
+ for name in attrs.keys():
self._attr_types[name] = self._attr_types.get(name, 0) + 1
def endDocument(self):
@@ -23,11 +23,11 @@
print("There were", self._attrs, "attributes.")
print("---ELEMENT TYPES")
- for pair in list(self._elem_types.items()):
+ for pair in self._elem_types.items():
print("%20s %d" % pair)
print("---ATTRIBUTE TYPES")
- for pair in list(self._attr_types.items()):
+ for pair in self._attr_types.items():
print("%20s %d" % pair)
Modified: python/branches/py3k-struni/Demo/xml/roundtrip.py
==============================================================================
--- python/branches/py3k-struni/Demo/xml/roundtrip.py (original)
+++ python/branches/py3k-struni/Demo/xml/roundtrip.py Mon Aug 6 23:07:53 2007
@@ -22,7 +22,7 @@
def startElement(self, name, attrs):
self._out.write('<' + name)
- for (name, value) in list(attrs.items()):
+ for (name, value) in attrs.items():
self._out.write(' %s="%s"' % (name, saxutils.escape(value)))
self._out.write('>')
More information about the Python-3000-checkins
mailing list