从其他包访问主包 [英] Access main package from other package
问题描述
我想从另一个软件包访问主软件包,但这是不可能的,因为主文件不在目录中.我已经尝试将主文件放在目录中,但是当我尝试导入它时,出现此错误:
import "../main" is a program, not an importable package
I want to access the main package from another package, but this is impossible because the main file isn't in a directory. I already tried putting the main file in a directory, but when I try to import it I get this error:
import "../main" is a program, not an importable package
之所以要这样,是因为我有一个tcp服务器和一个Web服务器可以一起工作. Web服务器可以通过主软件包获取tcp服务器,而tcp服务器可以通过主软件包获取webserver.
The reason that I want this because I have a tcp server and a webserver that work together. The webserver can get the tcp server via the main package and the tcp server can get the webserver via the main package.
我已经使它可以与Web服务器和tcpserver互相读取(中间没有主程序包),但是我想将应用程序的某些部分放在一个地方.
I already got it working with the webserver and tcpserver reading from each other(without the main package in the middle), but I want to keep some parts of the application at one place.
我想要的东西(通过主包装)是否可行?还是只是愚蠢.
Is the the thing I want possible(Via the main package)? Or is it just stupid.
推荐答案
您不能import
main
软件包.任何共享代码都应放在单独的程序包中,可以由main
(和其他程序包)导入.
You cannot import
the main
package. Any shared code should go in a separate package, which can be imported by main
(and other packages).
这篇关于从其他包访问主包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!