Python Forum
Best way to make built-in functions available to my module functions?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to make built-in functions available to my module functions?
#1
Recently, there was a question about counting the numbers from a picture of 2 dice. I thought that was interesting, so I fiddled with it.

I import cv2 as cv and numpy as np in the main programme.

I ended up with a few functions of my own for various tasks, so I packed them all in a module called dice_stuff.py, which I import:

import dice_stuff as ds
For example, I have a function:

outline_dice(png_copy, d, np, cv, destination)
which draws a pretty green polyline around each die, once I have the coordinates.

But I found, I had to pass cv and np to the module function ds.outline_dice() because it complained NameError no cv or NameError no np.

I already have cv and np imported in the main part of the programme.

How should I make cv and np available to my module functions?

What is the recommended way to do this? What is "Best Practice"?
Reply
#2
(Oct-28-2024, 04:45 AM)Pedroski55 Wrote: How should I make cv and np available to my module functions?
Simply import cv2 as cv and numpy as np in the dice_stuff module.
Pedroski55 likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Locally run an APK and execute functions using Python KovyJ 0 463 Jan-23-2025, 05:21 PM
Last Post: KovyJ
  Regarding Defined Functions Hudjefa 1 722 Nov-05-2024, 04:59 AM
Last Post: Gribouillis
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 3 8,280 Oct-01-2024, 03:32 PM
Last Post: Alex_Kirpichny
  How do I make functions "interact" with each other? Hudjefa 11 2,343 Sep-09-2024, 01:37 PM
Last Post: deanhystad
  two functions working in a strange way zapad 3 1,370 Jul-19-2024, 10:31 AM
Last Post: Eleanore
  using dir_fd=None in some functions Skaperen 2 1,212 Jun-14-2024, 07:22 PM
Last Post: Gribouillis
  Passing writable arguments to functions. Assembler 11 3,346 Jan-15-2024, 11:32 PM
Last Post: sgrey
  partial functions before knowing the values mikisDeWitte 4 1,682 Dec-24-2023, 10:00 AM
Last Post: perfringo
  Calling functions by making part of their name with variable crouzilles 4 1,849 Nov-02-2023, 12:25 PM
Last Post: noisefloor
  __name__ and __main__ in functions Mark17 3 1,961 Oct-12-2023, 01:55 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020