code: def calculateit(func, base, n, tofile):
      """Writes first n base-digits of a mpmath function to file"""
      prec = 100
      intpart = libmp.numeral(3, base)
      if intpart == 0:
          skip = 0
      else:
          skip = len(intpart)
      print("Step 1 of 2: calculating binary value...")
      prec = int(n * math.log(base, 2)) + 10
      t = perf_counter()
      a = func(prec)
      step1_time = perf_counter() - t
      print("Step 2 of 2: converting to specified base...")
      t = perf_counter()
      d = libmp.bin_to_radix(a.man, -a.exp, base, n)
      d = libmp.numeral(d, base, n)
      step2_time = perf_counter() - t
      print("\nWriting output...\n")
      if tofile:
          out_ = sys.stdout
          sys.stdout = tofile
      print("%i base-%i digits of pi:\n" % (n, base))
      print(intpart, ".\n")
      display_fraction(d, skip=skip, colwidth=10, columns=5)
      if tofile:
          sys.stdout = out_
      print(
          "\nFinished in %f seconds (%f calc, %f convert)"
          % ((step1_time + step2_time), step1_time, step2_time)
      )
  
file_path: sympy/examples/advanced/pidigits.py
imports: from mpmath import libmp, pi
  import math
  import sys
  from time import perf_counter
label_desc: Use image node_id 2 for calling a global function with example usage: calculateit(func, base, n, tofile) without return types