Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/suff.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 5ae390ac6c61 |
| children |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
47100
diff
changeset
|
1 #! /usr/bin/env python3 |
| 274 | 2 |
| 3 # suff | |
| 4 # | |
| 5 # show different suffixes amongst arguments | |
| 6 | |
| 7 import sys | |
| 8 | |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
9 |
| 274 | 10 def main(): |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
4573
diff
changeset
|
11 files = sys.argv[1:] |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
4573
diff
changeset
|
12 suffixes = {} |
|
29107
93c92f20b6bf
Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents:
15930
diff
changeset
|
13 for filename in files: |
|
93c92f20b6bf
Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents:
15930
diff
changeset
|
14 suff = getsuffix(filename) |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
15 suffixes.setdefault(suff, []).append(filename) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
16 for suff, filenames in sorted(suffixes.items()): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
17 print(repr(suff), len(filenames)) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
18 |
| 274 | 19 |
|
29107
93c92f20b6bf
Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents:
15930
diff
changeset
|
20 def getsuffix(filename): |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
21 name, sep, suff = filename.rpartition('.') |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
22 return sep + suff if sep else '' |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
23 |
| 274 | 24 |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
25 if __name__ == '__main__': |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
26 main() |
