Python3 - 如何从不同的模块访问方法参数

时间:2017-07-23 05:05:51

标签: function parameters

FILE0.py

In [8]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.20.2
pytest: 3.1.2
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.1
xarray: None

FILE1.py

import file1
import file2
"""
main file
somewhere down in the code
"""
file1.makeMove_Maybe1(piece,destination,figureitout)
  

“””          长文档字符串。老板喜欢访问者的方法          而不是直接从其他人调用类方法          码。我无权访问file0(驱动程序)          我确实拥有所有其他文件的权限。   “”“

import file2
class chess-move:
    __init__():
        maybe1 = None
        maybe2 = None

    def MakeMove_maybe1(piece,destination,decision):
        file2.executeMove(piece,destination,holdfingeronit)

    def analyzeOppMove(piece,oldloc,newloc,didIloseapiece):
        code = irrelevant
        """
        code irrelevant it is example anyway
        or just say logic is elsewhere and this was call
        from file0
        """

def makeMove_Maybe1(piece,destination,decision):

FILE2.py

   myMove.MakeMove_maybe1(piece,destination,decision)
  

“””              我想要一个变量HERE              要初始化,并为每次迭代设置为              来自file1的目标变量,无论是来自              在课堂上或课外              请帮助,我无法弄清楚这一点。 OO是新的              对我来说。我也希望代码是正确的。              我也可以删除真正的代码,如果              需要。   “”“

1 个答案:

答案 0 :(得分:0)

真正的问题

上面示例中的

Piece 在我的代码中为 myAgent.siprtp.namedata ,我需要获取路径变量( destination 将示例中的参数转换为File2的类方法。但是该路径已添加到 myAgent 对象中,并且没有来自其类的继承。

我的解决方案

因此File2的类方法( Get_File_From_Path )无法访问我需要的路径。因此,我调用File1中的方法( GetFileFromPath ),其中 myAgent 充当self,上面提到的应该是 myAgent.siprtp.namedata 。当'假'自我创建到File2时,我用它来提取我所需的路径,然后建立备份'正确'自我,因此File2的方法可以使用正确的自我。

希望这是有道理的,并希望这可以帮助某人。