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
#3
(Sep-22-2019, 06:32 PM)ichabod801 Wrote: If the listCWD function definition is not in the if __name__ block, you should be able to run it like this:

import listCWD
whatever = listCWD.listCWD()
Remember, you want the definition outside the if __name__ block, and the actual call to it inside the if __name__ block.

If that does not solve your problem, please post some just enough runnable code to replicate the error, along with the full text of any error message.

Thanks for your reply. i tried what you said above but I got the error message below. i have added a url for all the files to my first post. im not an experienced coder and cant replicate the error with a smaller piece of code.

Traceback (most recent call last):
  File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\returnFileList.py", line 19, in <module>
    whatever = listCWD.listCWD()
AttributeError: 'function' object has no attribute 'listCWD'

(Sep-22-2019, 06:32 PM)ichabod801 Wrote: If the listCWD function definition is not in the if __name__ block, you should be able to run it like this:

import listCWD
whatever = listCWD.listCWD()
Remember, you want the definition outside the if __name__ block, and the actual call to it inside the if __name__ block.

If that does not solve your problem, please post some just enough runnable code to replicate the error, along with the full text of any error message.

I forgot to alter the import statement last time so i tried what you recommended again and it has imported correctly and the function was called but it hasnt returned what i wanted. The output is below. The current working directory was returned but you will notice that the list of items in the directory did not print.

The os module has been imported
The globalVariables module has been imported
The returnCWD module has been imported
The listCWD module has been imported

The Current Working Directory is
 C:\Users\Me\AppData\Local\Programs\Python\Python37-32

returnCWD ran corrrectly

listCWD ran corrrectly
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 PyNovice - Sep-22-2019, 06:57 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 486 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  Why wont this path work one way, but will the other way? cubangt 2 705 Sep-01-2023, 04:14 PM
Last Post: cubangt
  problem in import module from other folder akbarza 5 1,602 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 760 Aug-06-2023, 01:09 AM
Last Post: aupres
  import module error tantony 5 3,587 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,117 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Import a module for use in type hint? Milosz 0 1,525 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 2,880 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 5,436 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  'urllib3' Module not found when import 'requests' spanz 5 10,553 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