FAQ

On 2013-05-24, RVic wrote:
Thanks Steven,

Yes, I see Python isn't going to do this very well, from what I
can understand.

Lets say I have a type of class, and this type of class will
always have two methods, in() and out().

Here is, essentially, what I am trying to do, but I don't know
if this will make sense to you or if it is really doable in
Python: #thanks, RVic

import sys
argv = sys.argv[1:]
ClassIamInstantiating = argv
ClassIamInstantiating.in("something")
x = ClassIamInstantiating.out()

This is pretty easy in Python using the __name__ attribute.


import sys


class A:
  def in(self):
    print("A in")
  def out(self):
    print("A out")


class B:
  def in(self):
    print("B in")
  def out(self):
    print("B out")


classes = {cls.__name__: cls for cls in (A, B)}


ArgType = classes[sys.agrv[1]]


arg = ArgType()


arg.in("test")
arg.out("test")


--
Neil Cerutti

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 4 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedMay 24, '13 at 11:40a
activeMay 24, '13 at 8:23p
posts4
users3
websitepython.org

People

Translate

site design / logo © 2021 Grokbase