Thursday, August 20, 2015

Python calling function within a class from another class from Visual Studio

The following example listed below was done using Visual Studio Visual Studio. https://www.visualstudio.com/en-us/features/python-vs.aspx

The scope of this example was create a python file and call a function within a class file from the __init__, the init is the constructor for a class.  Then passing in the variables to set locally within the class file.

PythonApplication.py:
import sys
import pClass

def main():
    print "test"

def anothermain():
    thisClass = pClass.pClass("Lino","39","1")
    #del thisClass # this is how to use the destructor in python
    pClass.pClass.aClass(thisClass)
    print "testing"

if __name__ == "__main__":
    main()
    anothermain()

ClassFile.py:
class pClass(object):
 
    def __init__(self, name,age,net):#,*args, **kwargs):
        self.name = name
        self.age = age
        self.net = net
        self.aClass()
 
    def aClass(object):
        print "Name is %s, age is %s, net worth is %s" % (object.name, object.age, object.net) #(self.name, self.age, self.net)

No comments:

Post a Comment