【问题标题】:How to pass variable from one python script to another如何将变量从一个python脚本传递到另一个
【发布时间】:2014-07-01 20:18:31
【问题描述】:

我的代码有这个结构

class Mapsframe(wx.Frame):

    def __init__(self):
        import application

class Example(wx.Frame,listmix.ColumnSorterMixin):
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs) 
        self.InitUI()

    def InitUI(self):

    def onItemSelected(self,event):

        frame = Mapsframe()

application 是另一个正在运行的python scipt,我想将在def onItemSelected 内部创建的一些变量传递给python 脚本application.py 内部的一个类。有什么想法吗?

【问题讨论】:

    标签: python wxpython python-module


    【解决方案1】:

    您可以向接受参数的 MapsFrame 类添加另一个方法。像这样:

    def take_args(arg1, arg2):
      self.arg1 = arg1
      self.arg2 = arg2
    

    这样,在您的示例类中,您只需这样做:

    def onItemSelected(self,event):
      arg1 = 'foo';
      arg2 = 'bar';
      frame = Mapsframe()
      frame.take_args(arg1,arg2)
    

    【讨论】:

    • 以及如何在脚本应用程序中导入 def take_args 以获取值 arg1,arg2
    • 我需要了解更多关于您正在导入的应用程序的信息。您可以导入与应用程序相关的设置文件,根据参数进行修改,然后运行应用程序。
    • 这是一个 python 脚本,我的类和定义错误,它是 wxpymaps 脚本,我使用 Mapsframe 将其显示到窗口,但我无法在 application.py 中的类中传递变量
    • 好的,那么您想要传递的究竟是什么?我猜是这个文件在这里?github.com/sinapsi/wxpymaps/blob/master/application.py
    • 第 672 行是这个 self.NewPointDialog(coords="38.132329,15.158815") 我稍微更改了代码并有coords="38.132329,15.158815" lat, lon = coords.split(",") name = '' description = '' newMarker = Marker(lat, lon, name, description) self.markers.append(newMarker) newMarker.draw(self, self.pdc) 我只想从其他脚本和这些删除定义后的行在类 PyMap 框架内
    猜你喜欢
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 2011-02-08
    • 2014-05-20
    • 2017-11-07
    相关资源
    最近更新 更多