I have a package that looks like the following
package / __init__.py Modulein the moduledef function (file_name): open (file_name) As with F: # do stuffSomewhere 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.txtmay 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.functionfrom some file outside thepackagedirectory? Can I join?Sorry if my terminology is really ambiguous, then I am actually unfamiliar with the
osstuff.Edit: The exact file setup looks like this:
directory / foo.py package / __init__.py module.py a Other directories / bar.txtand
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