Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
from module import function
#3
Your codelooks weird. What is the name of this file? Is it test3.py?

You use "import" to import a module so you can use the resources in that module. Python comes with a bunch of standard libraries (math, intertools, types, pprint, datetime, io, sys, tkinter, …) If my graphical user interface program uses tkinter, the top of the fill will have a line like this:
import tkinter
Then I can use functions from that module like:
window = tkinter.Tk()  # Make top level window for program
You can write your own modules and import them in other modules as well. It looks like this program is trying to import fcn_b from module test3 (file test3.py) However, the following code immediately defines a new fcn_b, so what was the point of the import? It is also unusual to see an import statement that isn't at the top of the file.

What does test3.py look like?
Reply


Messages In This Thread
from module import function - by krishanu21 - Apr-21-2020, 07:58 PM
RE: from module import function - by Larz60+ - Apr-21-2020, 08:13 PM
RE: from module import function - by deanhystad - Apr-21-2020, 08:24 PM
RE: from module import function - by buran - Apr-22-2020, 10:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  import a function from another file using relative path paul18fr 6 3,748 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  is import cointegration_analysis a recognized module mitcht33 1 1,204 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 11,558 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 1,442 Aug-06-2023, 01:09 AM
Last Post: aupres
  import module error tantony 5 5,179 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,965 Sep-21-2022, 01:34 PM
Last Post: snippsat
  How to import file and function in another folder SriRajesh 1 5,741 Dec-18-2021, 08:35 AM
Last Post: Gribouillis
  Import a module for use in type hint? Milosz 0 2,108 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 4,422 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 9,107 Jun-22-2021, 10:38 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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