Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. rename a class instantiated
Forum Updated to NodeBB v4.3 + New Features

rename a class instantiated

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 4 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FaTr
    wrote on last edited by
    #1

    when I instantiate a class, is it possible to rename the "class instantiated" with another name?

    class MyClass()
        def __init__(self):
    ....
        def method_1()
    ....
        def method_2()
    ....
    
    clasaName = MyClass ()
    className.__name__ = "apple"
    #in order to have as a final result
    apple.method_1()
    

    I have tried the code above but without positive results.
    Thanks in advance
    Fausto

    jsulmJ JonBJ S 3 Replies Last reply
    0
    • F FaTr

      when I instantiate a class, is it possible to rename the "class instantiated" with another name?

      class MyClass()
          def __init__(self):
      ....
          def method_1()
      ....
          def method_2()
      ....
      
      clasaName = MyClass ()
      className.__name__ = "apple"
      #in order to have as a final result
      apple.method_1()
      

      I have tried the code above but without positive results.
      Thanks in advance
      Fausto

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @FaTr Why would you want to do such things?!
      You can't change the name of a variable.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply
      0
      • F FaTr

        when I instantiate a class, is it possible to rename the "class instantiated" with another name?

        class MyClass()
            def __init__(self):
        ....
            def method_1()
        ....
            def method_2()
        ....
        
        clasaName = MyClass ()
        className.__name__ = "apple"
        #in order to have as a final result
        apple.method_1()
        

        I have tried the code above but without positive results.
        Thanks in advance
        Fausto

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @FaTr
        Apart from this being a very odd thing to want to do, it is a Python question nothing to do with Qt. You might look at the accepted solution at https://stackoverflow.com/questions/70655783/change-class-name.

        1 Reply Last reply
        0
        • F FaTr

          when I instantiate a class, is it possible to rename the "class instantiated" with another name?

          class MyClass()
              def __init__(self):
          ....
              def method_1()
          ....
              def method_2()
          ....
          
          clasaName = MyClass ()
          className.__name__ = "apple"
          #in order to have as a final result
          apple.method_1()
          

          I have tried the code above but without positive results.
          Thanks in advance
          Fausto

          S Offline
          S Offline
          StarterKit
          wrote on last edited by
          #4

          @FaTr I suspect that what you try to do is actually not a class re-naming but class inheritance...
          So, could you please explain a bit more what is your ultimate goal that you would like to achieve this way?

          1 Reply Last reply
          0
          • jsulmJ jsulm

            @FaTr Why would you want to do such things?!
            You can't change the name of a variable.

            F Offline
            F Offline
            FaTr
            wrote on last edited by
            #5

            @jsulm yes, it was a really bad idea. I wanted to get the name of the class from an external file.

            1 Reply Last reply
            0
            • F FaTr has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved