Python: Difference between revisions

 
(2 intermediate revisions by the same user not shown)
Line 67: Line 67:
# Format to two decimal places
# Format to two decimal places
print(f"Accuracy: {accuracy:.02f}%")
print(f"Accuracy: {accuracy:.02f}%")
# Format an int to 2 digits
print(f"Size: {size:02}%")
</syntaxhighlight>
</syntaxhighlight>


Line 178: Line 181:
import re
import re
my_regex = re.compile(r'height:(\d+)cm')
my_regex = re.compile(r'height:(\d+)cm')
my_match = myReg.match("height:33cm");
my_match = my_regex.match("height:33cm");
print(my_match[1])
print(my_match[1])
# 33
# 33
Line 366: Line 369:
import os
import os
import threading
import threading
from concurrent import futures
from concurrent.futures import ThreadPoolExecutor, as_completed
from concurrent.futures import ThreadPoolExecutor


executor = ThreadPoolExecutor(max_workers=os.cpu_count())
executor = ThreadPoolExecutor(max_workers=os.cpu_count())
Line 383: Line 385:
   my_futures.append(future)
   my_futures.append(future)


while len(my_futures) > 0:
for future in as_completed(my_futures):
  future = my_futures.pop()
   future.result()
   future.result()
executor.shutdown()
executor.shutdown()