Python Forum
When I import a Module it wont run
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When I import a Module it wont run
#1
Hello, I have 4 files. They are:

globalVariables.py - this stores variables that are used in other modules
returnCWD.py - this has a function that returns the current working directory
listCWD - this has a function that prints a list of all items within the current working directory
returnFileList - this file imports the 3 files above and runs the function from returnCWD.py and
the function from listCWD.py

My problem
In order to import the listCWD module I had to add this piece of code
if __name__ == '__main__':
to the listCWD function in the listCWD.py file to prevent the listCWD.py file from running on import
but this code then prevents me from calling the listCWD function.

Can anyone help with this. I have attached a url link to the files.
My 4 python files within a folder

Thanks in advance to anyone who takes the time to help out.
Reply


Messages In This Thread
When I import a Module it wont run - by PyNovice - Sep-22-2019, 06:30 PM
RE: When I import a Module it wont run - by buran - Oct-14-2019, 12:31 PM
RE: When I import a Module it wont run - by buran - Oct-14-2019, 03:28 PM
RE: When I import a Module it wont run - by buran - Oct-14-2019, 04:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  is import cointegration_analysis a recognized module mitcht33 1 451 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  Why wont this path work one way, but will the other way? cubangt 2 693 Sep-01-2023, 04:14 PM
Last Post: cubangt
  problem in import module from other folder akbarza 5 1,496 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 736 Aug-06-2023, 01:09 AM
Last Post: aupres
  import module error tantony 5 3,511 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,091 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Import a module for use in type hint? Milosz 0 1,499 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 2,837 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 5,361 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  'urllib3' Module not found when import 'requests' spanz 5 10,370 Jan-06-2021, 05:57 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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