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
  Why doesn't list require global keyword? johnywhy 9 792 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 2,586 Mar-11-2022, 01:50 PM
Last Post: snippsat
  Imports in my first package cuppajoeman 1 1,945 Jun-28-2021, 09:06 AM
Last Post: snippsat
  script with imports works but pytest gives "ModuleNotFoundError"? Hpao 0 1,560 Jun-27-2021, 08:30 PM
Last Post: Hpao
  Help wanted with python imports petros21 3 2,539 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 3,809 Mar-17-2021, 11:57 AM
Last Post: cff
  threading across imports Nickd12 2 2,137 Nov-09-2020, 01:59 AM
Last Post: Nickd12
  refreshing imports seandepagnier 4 2,728 Sep-20-2020, 11:51 PM
Last Post: seandepagnier
  Multimode imports fine as script but not after compiling into exe chesschaser 0 2,402 Aug-13-2020, 01:28 PM
Last Post: chesschaser
  Pattern Require Last Line Print() why? Harshil 4 2,421 Aug-08-2020, 04:54 PM
Last Post: Harshil

Forum Jump:

User Panel Messages

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