I have a package that looks like the following
package / __init__.py Module
in the moduledef function (file_name): open (file_name) As with F: # do stuff
Somewhere else in a arbitrary directory I have a python file that looks like something
package package import Please. Function ("some_file .txt")
But upon turning it on, it is giving me the
FileNotFoundError: [Errno 2] There is no such file or directory: "some_file. Txt "
.The problem is that the complete path of
some_file.txt
may look likec: \ user \ user \ document \ some_file.txt
, but < Code> package.function Path complete path is something likec: \ user \ user \ document \ package \ some_file.txt
. Is there a way I can create this from which to open the file by callingpackage.function
from some file outside thepackage
directory? Can I join?Sorry if my terminology is really ambiguous, then I am actually unfamiliar with the
os
stuff.Edit: The exact file setup looks like this:
directory / foo.py package / __init__.py module.py a Other directories / bar.txt
and
foo
< P>
Class = "post-text" itemprop = "text">
I think you are missing points.
It is not important that where the source code is, the relative path (and the pure file name is relative path) are always interpreted relative to that directory in the process of program Walks (ie directory, when you type
dragon c: \ path \ to \ my \ python \ code \ code.py
)
No comments:
Post a Comment