Saving the name of a instance of a class in a string variable












1















I have this strange question that im stuck for days. I'm developing a small program using python for maya. (By now I hope you know I'm not a professional programmer. just a side coder to build some internal scripts and tools)



The tool I am building has a lot of UI elements I am creating as classes, which have their own methods.



What I need to do, is to pass an instance of such a class, using a string. I know this is strange and pls let me explain.



I need to implement a drag and drop operation of a widget class, which can pass a message from the source to the destination. the message always gets forcefully (by Maya) gets converted into a string!!!



Class a(object):
def __init__(self, v)
self.v=v

instance=a("important")


normally what I can do is



print (instance.v)


but what happens is during the message exchange process, the instance gets converted to text and I get a string instead of the python object




'<main.a object at 0x000001BB0696CA90>'




which is a string,. and i can't run or query any methods in the actual function..



I know this is very noob. Please advice on how I can convert a class instance saved in a string to a python object so I can call up its methods or query variables..



Thanks again.










share|improve this question




















  • 1





    what happens if you write self.value = v

    – YOLO
    Dec 28 '18 at 19:36











  • yes. my mistake on the question. fixed it. but still the problem still remains!

    – Rasika Jayawardene
    Dec 28 '18 at 19:43






  • 1





    Did you try to serialize and de-serialize the instance of class using Pickle?

    – Kiran Baktha
    Dec 28 '18 at 19:46











  • what is the expected output ?

    – YOLO
    Dec 28 '18 at 19:46











  • i want a way to covert a string which has the name and memory location of the instance into a variable i can actually call on the methods!! From '<__main__.test_class object at 0x000001BB0696CA90>' to a new_instance.v

    – Rasika Jayawardene
    Dec 28 '18 at 20:20


















1















I have this strange question that im stuck for days. I'm developing a small program using python for maya. (By now I hope you know I'm not a professional programmer. just a side coder to build some internal scripts and tools)



The tool I am building has a lot of UI elements I am creating as classes, which have their own methods.



What I need to do, is to pass an instance of such a class, using a string. I know this is strange and pls let me explain.



I need to implement a drag and drop operation of a widget class, which can pass a message from the source to the destination. the message always gets forcefully (by Maya) gets converted into a string!!!



Class a(object):
def __init__(self, v)
self.v=v

instance=a("important")


normally what I can do is



print (instance.v)


but what happens is during the message exchange process, the instance gets converted to text and I get a string instead of the python object




'<main.a object at 0x000001BB0696CA90>'




which is a string,. and i can't run or query any methods in the actual function..



I know this is very noob. Please advice on how I can convert a class instance saved in a string to a python object so I can call up its methods or query variables..



Thanks again.










share|improve this question




















  • 1





    what happens if you write self.value = v

    – YOLO
    Dec 28 '18 at 19:36











  • yes. my mistake on the question. fixed it. but still the problem still remains!

    – Rasika Jayawardene
    Dec 28 '18 at 19:43






  • 1





    Did you try to serialize and de-serialize the instance of class using Pickle?

    – Kiran Baktha
    Dec 28 '18 at 19:46











  • what is the expected output ?

    – YOLO
    Dec 28 '18 at 19:46











  • i want a way to covert a string which has the name and memory location of the instance into a variable i can actually call on the methods!! From '<__main__.test_class object at 0x000001BB0696CA90>' to a new_instance.v

    – Rasika Jayawardene
    Dec 28 '18 at 20:20
















1












1








1








I have this strange question that im stuck for days. I'm developing a small program using python for maya. (By now I hope you know I'm not a professional programmer. just a side coder to build some internal scripts and tools)



The tool I am building has a lot of UI elements I am creating as classes, which have their own methods.



What I need to do, is to pass an instance of such a class, using a string. I know this is strange and pls let me explain.



I need to implement a drag and drop operation of a widget class, which can pass a message from the source to the destination. the message always gets forcefully (by Maya) gets converted into a string!!!



Class a(object):
def __init__(self, v)
self.v=v

instance=a("important")


normally what I can do is



print (instance.v)


but what happens is during the message exchange process, the instance gets converted to text and I get a string instead of the python object




'<main.a object at 0x000001BB0696CA90>'




which is a string,. and i can't run or query any methods in the actual function..



I know this is very noob. Please advice on how I can convert a class instance saved in a string to a python object so I can call up its methods or query variables..



Thanks again.










share|improve this question
















I have this strange question that im stuck for days. I'm developing a small program using python for maya. (By now I hope you know I'm not a professional programmer. just a side coder to build some internal scripts and tools)



The tool I am building has a lot of UI elements I am creating as classes, which have their own methods.



What I need to do, is to pass an instance of such a class, using a string. I know this is strange and pls let me explain.



I need to implement a drag and drop operation of a widget class, which can pass a message from the source to the destination. the message always gets forcefully (by Maya) gets converted into a string!!!



Class a(object):
def __init__(self, v)
self.v=v

instance=a("important")


normally what I can do is



print (instance.v)


but what happens is during the message exchange process, the instance gets converted to text and I get a string instead of the python object




'<main.a object at 0x000001BB0696CA90>'




which is a string,. and i can't run or query any methods in the actual function..



I know this is very noob. Please advice on how I can convert a class instance saved in a string to a python object so I can call up its methods or query variables..



Thanks again.







python maya






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 19:47







Rasika Jayawardene

















asked Dec 28 '18 at 19:27









Rasika JayawardeneRasika Jayawardene

93




93








  • 1





    what happens if you write self.value = v

    – YOLO
    Dec 28 '18 at 19:36











  • yes. my mistake on the question. fixed it. but still the problem still remains!

    – Rasika Jayawardene
    Dec 28 '18 at 19:43






  • 1





    Did you try to serialize and de-serialize the instance of class using Pickle?

    – Kiran Baktha
    Dec 28 '18 at 19:46











  • what is the expected output ?

    – YOLO
    Dec 28 '18 at 19:46











  • i want a way to covert a string which has the name and memory location of the instance into a variable i can actually call on the methods!! From '<__main__.test_class object at 0x000001BB0696CA90>' to a new_instance.v

    – Rasika Jayawardene
    Dec 28 '18 at 20:20
















  • 1





    what happens if you write self.value = v

    – YOLO
    Dec 28 '18 at 19:36











  • yes. my mistake on the question. fixed it. but still the problem still remains!

    – Rasika Jayawardene
    Dec 28 '18 at 19:43






  • 1





    Did you try to serialize and de-serialize the instance of class using Pickle?

    – Kiran Baktha
    Dec 28 '18 at 19:46











  • what is the expected output ?

    – YOLO
    Dec 28 '18 at 19:46











  • i want a way to covert a string which has the name and memory location of the instance into a variable i can actually call on the methods!! From '<__main__.test_class object at 0x000001BB0696CA90>' to a new_instance.v

    – Rasika Jayawardene
    Dec 28 '18 at 20:20










1




1





what happens if you write self.value = v

– YOLO
Dec 28 '18 at 19:36





what happens if you write self.value = v

– YOLO
Dec 28 '18 at 19:36













yes. my mistake on the question. fixed it. but still the problem still remains!

– Rasika Jayawardene
Dec 28 '18 at 19:43





yes. my mistake on the question. fixed it. but still the problem still remains!

– Rasika Jayawardene
Dec 28 '18 at 19:43




1




1





Did you try to serialize and de-serialize the instance of class using Pickle?

– Kiran Baktha
Dec 28 '18 at 19:46





Did you try to serialize and de-serialize the instance of class using Pickle?

– Kiran Baktha
Dec 28 '18 at 19:46













what is the expected output ?

– YOLO
Dec 28 '18 at 19:46





what is the expected output ?

– YOLO
Dec 28 '18 at 19:46













i want a way to covert a string which has the name and memory location of the instance into a variable i can actually call on the methods!! From '<__main__.test_class object at 0x000001BB0696CA90>' to a new_instance.v

– Rasika Jayawardene
Dec 28 '18 at 20:20







i want a way to covert a string which has the name and memory location of the instance into a variable i can actually call on the methods!! From '<__main__.test_class object at 0x000001BB0696CA90>' to a new_instance.v

– Rasika Jayawardene
Dec 28 '18 at 20:20














2 Answers
2






active

oldest

votes


















0














How about writing a method for your class which returns the string?



class A(object):
def __init__(self, v):
self.v = v

def getV(self):
return self.v


Result:



>>> Instance = A('important')
>>> print(Instance.getV())
important
>>> Instance.getV()
'important'


If that doesn't work maybe you could write a printV() method...






share|improve this answer































    0














    Well.. pickeling worked!! i just wanted a way of creating a string from an instance and using the string to make the reference to the instance again.!! thanks, @kiran Baktha!



    i just did



    beforetransfer = pickel.dumps(instance)


    and at the recieving end



    aftertransfer = pickel.loads(beforetransfer)


    thanks community!! you guys are amazzing!!






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963416%2fsaving-the-name-of-a-instance-of-a-class-in-a-string-variable%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      How about writing a method for your class which returns the string?



      class A(object):
      def __init__(self, v):
      self.v = v

      def getV(self):
      return self.v


      Result:



      >>> Instance = A('important')
      >>> print(Instance.getV())
      important
      >>> Instance.getV()
      'important'


      If that doesn't work maybe you could write a printV() method...






      share|improve this answer




























        0














        How about writing a method for your class which returns the string?



        class A(object):
        def __init__(self, v):
        self.v = v

        def getV(self):
        return self.v


        Result:



        >>> Instance = A('important')
        >>> print(Instance.getV())
        important
        >>> Instance.getV()
        'important'


        If that doesn't work maybe you could write a printV() method...






        share|improve this answer


























          0












          0








          0







          How about writing a method for your class which returns the string?



          class A(object):
          def __init__(self, v):
          self.v = v

          def getV(self):
          return self.v


          Result:



          >>> Instance = A('important')
          >>> print(Instance.getV())
          important
          >>> Instance.getV()
          'important'


          If that doesn't work maybe you could write a printV() method...






          share|improve this answer













          How about writing a method for your class which returns the string?



          class A(object):
          def __init__(self, v):
          self.v = v

          def getV(self):
          return self.v


          Result:



          >>> Instance = A('important')
          >>> print(Instance.getV())
          important
          >>> Instance.getV()
          'important'


          If that doesn't work maybe you could write a printV() method...







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 28 '18 at 20:32









          jorijnsmitjorijnsmit

          589421




          589421

























              0














              Well.. pickeling worked!! i just wanted a way of creating a string from an instance and using the string to make the reference to the instance again.!! thanks, @kiran Baktha!



              i just did



              beforetransfer = pickel.dumps(instance)


              and at the recieving end



              aftertransfer = pickel.loads(beforetransfer)


              thanks community!! you guys are amazzing!!






              share|improve this answer




























                0














                Well.. pickeling worked!! i just wanted a way of creating a string from an instance and using the string to make the reference to the instance again.!! thanks, @kiran Baktha!



                i just did



                beforetransfer = pickel.dumps(instance)


                and at the recieving end



                aftertransfer = pickel.loads(beforetransfer)


                thanks community!! you guys are amazzing!!






                share|improve this answer


























                  0












                  0








                  0







                  Well.. pickeling worked!! i just wanted a way of creating a string from an instance and using the string to make the reference to the instance again.!! thanks, @kiran Baktha!



                  i just did



                  beforetransfer = pickel.dumps(instance)


                  and at the recieving end



                  aftertransfer = pickel.loads(beforetransfer)


                  thanks community!! you guys are amazzing!!






                  share|improve this answer













                  Well.. pickeling worked!! i just wanted a way of creating a string from an instance and using the string to make the reference to the instance again.!! thanks, @kiran Baktha!



                  i just did



                  beforetransfer = pickel.dumps(instance)


                  and at the recieving end



                  aftertransfer = pickel.loads(beforetransfer)


                  thanks community!! you guys are amazzing!!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 28 '18 at 20:45









                  Rasika JayawardeneRasika Jayawardene

                  93




                  93






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963416%2fsaving-the-name-of-a-instance-of-a-class-in-a-string-variable%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Mossoró

                      Error while reading .h5 file using the rhdf5 package in R

                      Pushsharp Apns notification error: 'InvalidToken'