Search Results

Search found 2 results on 1 pages for 'golergka'.

Page 1/1 | 1 

  • How do I find out if the variable is declared in Python?

    - by golergka
    I want to use a module as a singleton referenced in other modules. It looks something like this (that's not actually a code I'm working on, but I simplified it to throw away all unrelated stuff): main.py import singleton import printer def main(): singleton.Init(1,2) printer.Print() if __name__ == '__main__': pass singleton.py variable1 = '' variable2 = '' def Init(var1, var2) variable1 = var1 variable2 = var2 printer.py import singleton def Print() print singleton.variable1 print singleton.variable2 I expect to get output 1/2, but instead get empty space. I understand that after I imported singleton to the print.py module the variables got initialized again. So I think that I must check if they were intialized before in singleton.py: if not (variable1): variable1 = '' if not (variable2) variable2 = '' But I don't know how to do that. Or there is a better way to use singleton modules in python that I'm not aware of :)

    Read the article

  • Designing operation (a,b) -> (c,d)

    - by golergka
    I have an operation that I need to design. That operation takes two objects of a certain class X, and returns two new objects of the same class (I may need the originals later). The logic that dictates the selection of this object is contained in class Y. On one hand, I don't want class Y to know details about class X implementation; on the other, I don't want class X to know details about selecting the different objects to perform this operation on. If that was all the problem, I'd just create a static method on class A. However, the methods in language I'm working on return only one object. Also, the operation needs to be robust, and calling operation two times to get C and D respectively isn't possible, as both C & D both rely on a single random number. How should I design such operation? Update: I'm using Obejctive C.

    Read the article

1