Python Forum
Do you require imports used in other files?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do you require imports used in other files?
#1
Here is a snippet of code from two files:
# FileA.py
import time
def test():
    time.sleep(1)
    print("Hello")
# FileB.py
import FileA
test()
Will this print an error because FileA uses time, but FileB hasn't imported it? Or will it import time by itself?
Self-taught HTML, CSS, Python, and Java programmer
Reply
#2
Since time is only used in FileA.py, it will not print an error in FileB.
Call test() like this:
# FileB.py
import FileA
FileA.test()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best programming practice for imports Curbie 8 1,900 Oct-16-2024, 02:20 AM
Last Post: Curbie
  Sudden Extremely Slow / Failed Python Imports bmccollum 1 1,307 Aug-20-2024, 02:09 PM
Last Post: DeaD_EyE
  Why doesn't list require global keyword? johnywhy 9 4,295 Jan-15-2024, 11:47 PM
Last Post: sgrey
  Imports that work with Python 3.8 fail with 3.9 and 3.10 4slam 1 3,605 Mar-11-2022, 01:50 PM
Last Post: snippsat
  Imports in my first package cuppajoeman 1 2,553 Jun-28-2021, 09:06 AM
Last Post: snippsat
  script with imports works but pytest gives "ModuleNotFoundError"? Hpao 0 2,177 Jun-27-2021, 08:30 PM
Last Post: Hpao
  Help wanted with python imports petros21 3 3,651 Apr-07-2021, 07:16 PM
Last Post: snippsat
Question How to include Modules not found (conditional imports) in my setup.py when I want to cff 0 4,934 Mar-17-2021, 11:57 AM
Last Post: cff
  threading across imports Nickd12 2 3,109 Nov-09-2020, 01:59 AM
Last Post: Nickd12
  refreshing imports seandepagnier 4 3,944 Sep-20-2020, 11:51 PM
Last Post: seandepagnier

Forum Jump:

User Panel Messages

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