User Tools

Site Tools


public:it:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
public:it:python [2021/02/19 12:54] philpublic:it:python [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
  
-https://stackoverflow.com/questions/18114560/python-catch-ctrl-c-command-prompt-really-want-to-quit-y-n-resume-executi 
-https://stackoverflow.com/questions/37669883/disabling-pyc-files-in-production 
-https://dev.to/boris/using-yaml-to-manage-python-configurations-1j9c 
- 
-==== Chunking ===== 
- 
-<code> 
-adding = set() #of many things 
-i = iter(adding) 
-while True: 
-  chunk = list(islice(i, 10)) 
-  if not chunk: 
-    break 
-  else: 
-    print(",".join(chunk)) 
-</code> 
- 
-===== Memory Usage with decorators ===== 
-==== memory_profiler ==== 
-  * https://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended 
- 
-Install: 
-<code> 
-python3 -m pip install memory_profiler 
-</code> 
- 
-Set the function decorator ''%%@profile%%'' on any function you want to test. 
-<code> 
-@profile 
-def my_func(arg1): 
-  # do stuff 
-</code> 
- 
-Run your code like this: 
-<code> 
-python3 -m memory_profiler helloworld.py 
-</code> 
- 
- 
-You get output like this: 
-<code> 
-Line #    Mem usage  Increment   Line Contents 
-============================================== 
-                               @profile 
-          5.97 MB    0.00 MB   def my_func(): 
-         13.61 MB    7.64 MB       a = [1] * (10 ** 6) 
-        166.20 MB  152.59 MB       b = [2] * (2 * 10 ** 7) 
-         13.61 MB -152.59 MB       del b 
-         13.61 MB    0.00 MB       return a 
-</code> 
- 
- 
-===== Timing functions with decorators ===== 
-  - [[https://realpython.com/lessons/timing-functions-decorators/|Source]] 
- 
-<code> 
-import time, functools 
- 
-def timer(func): 
-  """Print runtime of decorated function""" 
-  @functools.wraps(func) 
-  def wrapper_timer(*args, **kwargs): 
-    start_time = time.perf_counter() 
-    value = func(*args, *kwargs) 
-    end_time = time.perf_counter() 
-    run_time = end_time - start_time 
-    print(f"Finished {func.__name__!r} in {run_time:.4f} secs") 
-    return value 
-  return wrapper_timer 
- 
- 
-@timer 
-def dostuff(): 
-   # does stuff 
-</code> 
public/it/python.1613760899.txt.gz · Last modified: 2021/02/19 12:54 by phil