Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modules in Python
#15
Quote:To my above question:
I have the following Folder and file structure:

Folder A
-FolderB
--spam.txt
--read.py
--readSpam.py
-FolderC
--foo.py

There readSpam.py has a function pick() which calls read to read the txt file.

readSpam calls read to read a txt-file in a given format, so with this module i can read spam.txt
If i want to run readspam.py i just have to use the code:
fobj = open("test.txt")
Then i can open the file and read it with read.py

But i want to do this in foo, so i include readSpam in foo and there i call:
result = readSpam.pick()

Now i get the error:
FileNotFoundError: [Errno 2] No such file or directory: 'spam.txt'

But if i put spam.txt in the same folder as foo.py the code works.
So my question is, how do i have to change my code to leave spam.txt in folder B?
To be honest the setup dos not look good,just mind bending Confused
Do you have __init__.py in all folder as you should?
So i guess you could try to give path to "spam.txt"  Folder A/FolderB/spam.txt
Reply


Messages In This Thread
Modules in Python - by Ewkos - May-26-2017, 05:24 PM
RE: Modules in Python - by nilamo - May-26-2017, 06:18 PM
RE: Modules in Python - by Ewkos - May-26-2017, 11:25 PM
RE: Modules in Python - by nilamo - May-27-2017, 04:22 PM
RE: Modules in Python - by Ewkos - May-27-2017, 04:30 PM
RE: Modules in Python - by nilamo - May-27-2017, 05:18 PM
RE: Modules in Python - by Ewkos - May-27-2017, 11:03 PM
RE: Modules in Python - by snippsat - May-28-2017, 02:20 AM
RE: Modules in Python - by Ewkos - May-28-2017, 11:56 AM
RE: Modules in Python - by snippsat - May-28-2017, 12:48 PM
RE: Modules in Python - by snippsat - May-28-2017, 04:37 PM
RE: Modules in Python - by Ewkos - May-29-2017, 12:03 AM
RE: Modules in Python - by snippsat - May-29-2017, 01:41 AM
RE: Modules in Python - by Ewkos - May-29-2017, 07:18 AM
RE: Modules in Python - by snippsat - May-29-2017, 11:56 AM
RE: Modules in Python - by Ewkos - May-30-2017, 07:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to see the date of installation of python modules. newbieAuggie2019 4 1,915 Mar-31-2023, 12:40 PM
Last Post: newbieAuggie2019
  Python modules for accessing the configuration of relevant paths Imago 1 1,514 May-07-2022, 07:28 PM
Last Post: Larz60+
  Python modules to extract data from a graph? bigmit37 5 22,957 Apr-09-2021, 02:15 PM
Last Post: TysonL
  Where to add own python modules in WinPython? HinterhaeltigesSchlaengelchen 1 2,407 Jan-21-2021, 07:45 PM
Last Post: snippsat
  Including modules in Python using sys.path.append JoeDainton123 1 3,084 Aug-24-2020, 04:51 AM
Last Post: millpond
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 3,222 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS
  python modules davy_yg 1 2,119 Sep-25-2019, 03:14 AM
Last Post: metulburr
  Importing Custom Modules in Python 3 Flexico 1 2,698 Aug-24-2019, 08:11 PM
Last Post: snippsat
  Trouble importing modules on a new python version snackman_barry 2 2,678 Jul-12-2019, 11:15 AM
Last Post: snackman_barry
  Import Python Modules zowhair 4 2,950 Jun-27-2019, 06:30 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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