Python Forum
Can I get some clarification on importing functions from external files.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I get some clarification on importing functions from external files.
#4
import is very different than C #include. #include pulls in code from a header file to be compiled into your module. import creates an object that is an interface to the imported module. When blink calls time.sleep(1), it does the following.

Blink says "Hey there time, can I use your sleep function?". Time says "Sure, whoever you are. Here it is. Have fun."

Importing the same module in multiple scripts is common and very efficient.

Decoupling modules is always good design. main.py should not import time. Only import wat you use directly. Blink needs time, main does not.
wh33t likes this post
Reply


Messages In This Thread
RE: Can I get some clarification on importing functions from external files. - by deanhystad - Feb-25-2023, 08:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  using variables with functions imported from different files. Scordomaniac 3 1,308 May-24-2022, 10:53 AM
Last Post: deanhystad
  importing functions from a separate python file in a separate directory Scordomaniac 3 1,409 May-17-2022, 07:49 AM
Last Post: Pedroski55
  Looking for clarification related to performance Pymon 5 2,099 Apr-04-2022, 04:47 PM
Last Post: deanhystad
  Read Tensorflow Documentation - Clarification IoannisDem 0 1,188 Aug-20-2021, 10:36 AM
Last Post: IoannisDem
  *args implementation and clarification about tuple status amjass12 10 4,136 Jul-07-2021, 10:29 AM
Last Post: amjass12
  Just need some clarification Tonje 3 2,108 Oct-01-2020, 03:52 PM
Last Post: deanhystad
  Global Variables - Some Points Needing Clarification. adt 4 2,999 Nov-30-2019, 01:23 PM
Last Post: adt
  Use Variables Generated from Functions in different files to use on the main file AykutRobotics 3 2,992 Jan-01-2019, 04:19 PM
Last Post: AykutRobotics
  Importing files with Pycharm sylas 3 9,789 Jan-14-2018, 09:31 AM
Last Post: sylas
  Clarification Hammuel 2 2,918 Oct-30-2017, 12:22 PM
Last Post: Hammuel

Forum Jump:

User Panel Messages

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