Пример #1
0
    def calcular(self, tipo_algoritmo):

        #preferente por amplitud
        if tipo_algoritmo == 1:
            self.algoritmo = Preferente_amplitud(self.entrada,
                                                 self.nodo_inicial,
                                                 self.nodo_meta)
            camino = list(reversed(self.algoritmo.camino_final))
            return camino
        elif tipo_algoritmo == 2:
            self.algoritmo = Costo_uniforme(self.entrada, self.nodo_inicial,
                                            self.nodo_meta)
            camino = list(reversed(self.algoritmo.camino_final))
            return camino

        elif tipo_algoritmo == 3:
            self.algoritmo = Preferente_profundidad(self.entrada,
                                                    self.nodo_inicial,
                                                    self.nodo_meta)
            camino = list(reversed(self.algoritmo.camino_final))
            return camino
        elif tipo_algoritmo == 4:
            self.algoritmo = Avara(self.entrada, self.nodo_inicial,
                                   self.nodo_meta)
            camino = list(reversed(self.algoritmo.camino_final))
            return camino
        elif tipo_algoritmo == 5:
            self.algoritmo = A(self.entrada, self.nodo_inicial, self.nodo_meta)
            camino = list(reversed(self.algoritmo.camino_final))
            return camino
Пример #2
0
 def G(text):
     A = hidden_prompt_func if F else visible_prompt_func
     try:
         echo(text, nl=_B, err=C)
         return A('')
     except (KeyboardInterrupt, EOFError):
         if F: echo(_A, err=C)
         raise Abort()
Пример #3
0
def echo_via_pager(text_or_generator, color=_A):
    B = color
    A = text_or_generator
    B = resolve_color_default(B)
    if inspect.isgeneratorfunction(A): C = A()
    elif isinstance(A, str): C = [A]
    else: C = iter(A)
    D = (A if isinstance(A, str) else str(A) for A in C)
    from ._termui_impl import pager
    return pager(itertools.chain(D, '\n'), B)
Пример #4
0
def get_binary_stream(name):
    A = binary_streams.get(name)
    if A is _A: raise TypeError(f"Unknown standard stream '{name}'")
    return A()
Пример #5
0
def raw_terminal():
    from ._termui_impl import raw_terminal as A
    return A()
Пример #6
0
def getchar(echo=_B):
    A = _getchar
    if A is _A: from ._termui_impl import getchar as A
    return A(echo)
Пример #7
0
def launch(url, wait=_B, locate=_B):
    from ._termui_impl import open_url as A
    return A(url, wait=wait, locate=locate)
Пример #8
0
import A
if __name__ == '__main__':
    a = A.A(A.Node([[2, 8, 3], [1, 0, 5], [4, 7, 6]]),
            A.Node([[1, 2, 3], [4, 5, 6], [7, 8, 0]]))
    print("start:")
    if a.start():
        a.showPath()
    else:
        print("no way")
class A:
    __N=0 # 类的数据属性就应该是共享的,但是语法上是可以把类的数据属性设置成私有的如__N,会变形为_A__N
    def __init__(self):
        self.__X=10  # 变形为self._A__X

    def __foo(self): # 变形为_A__foo
        print('from A')

    def bar(self):
        self.__foo() # 只有在类内部才可以通过__foo的形式访问到.

print(A._A__N) # 0   A._A__N是可以访问到的,但是不合规。
# 这种,在外部是无法通过__x这个名字访问到。为什么呢?看下面,在类中定义时带双下划线的属性都加了 _类名__属性
print(A.__dict__) # {'__module__': '__main__', '_A__N': 0, '__init__': <function A.__init__ at 0x106d32ae8>, '_A__foo': <function A.__foo at 0x106d56158>, 'bar': <function A.bar at 0x106d561e0>, '__dict__': <attribute '__dict__' of 'A' objects>, '__weakref__': <attribute '__weakref__' of 'A' objects>, '__doc__': None}
obj=A()
obj.bar()  # from A  


# 在类内定义,在类外不让使用。那定义有什么用呢?
class Goods:
    __DISCONT = 0.8  # 加了双下划线就被定义成了一个私有的属性
    def __init__(self,org_price):
        self.price = org_price * Goods.__DISCONT # 在内部就使用了

apple = Goods(10)
print(apple.price) # 8.0

\在继承中,父类如果不想让子类覆盖自己的方法,可以将方法定义为私有的
#正常情况
>>> class A:
Пример #10
0
import A
a=A.A(2,3)
a.add()
Пример #11
0
        return code.decode('base64')
    def aa(self):
        return self.__aa();

    def __aa(self):
        return 1;


class B:
    import A

    def a(self):
        A.

a = A()
print(a.aa())
print(params[0])
c = a.aencode(params[0], params[1])
print(c)



#
# print('--------')
#
# js = u"""
#
#             function strencode(input, key)
#             {
#                 //input = windows.atob(input);
Пример #12
0
        self._ID = "Letter # 3"
        self.__password = 3333

    def _method(self):
        print "I'm a method in C starting with one underscore."

    def __method(self):
        print "I'm a method in C starting with two underscores."

    def __repr__(self):
        return "I'm an object in the class C."  # Same for all c's in this class.


# Start of demo code
if __name__ == "__main__":
    a = A()  # Construct an object of type A.
    print "1. Little 'a' is an object in the superclass A. The type of a is:", type(
        a)
    a.method(
    )  # Zero underscore method calls two underscore method, both in class A.
    a._method()  # One underscore method from class A.

    b = B()  # Construct an object of type B.
    print "\n2. Now b is an object in the subclass B. The type of 'b' is:", type(
        b)
    print "The magic 'repr' method converts all b's to the string:", b
    print "Since every B is an A, 'b' can invoke any method from the superclass A."
    print "Below, 'b' invokes 'method', from the superclass. Note it reports itself as an A!!!"
    print "Little 'b', reports itself as an A!"
    b.method()
Пример #13
0
print(officeStaff1.position)

print("pay")
print(officeStaff1.pay)

officeStaff1.calculatePay()

print("pay")
print(officeStaff1.pay)

print(officeStaff1)

# Name mangling demo
print("A's turn")

A = a.A()

# This can be accessed directly even though it shouldn't be
print(A._y)

# This cannot and will cause an error
# print (A.__x)

# To access __x it must be accessed:
print(A._A__x)

# Self demo
print("Self demo")

peter = ProgStaff.ProgStaff(2500)
john = ProgStaff.ProgStaff(2500)
Пример #14
0
def get_text_stream(name, encoding=_A, errors=_D):
    A = text_streams.get(name)
    if A is _A: raise TypeError(f"Unknown standard stream '{name}'")
    return A(encoding, errors)
不同,引发对应类别的方法,而同时又采取不同的行为,简单来说就是,给予不同的对象引发不同的动作
eg:
'This is a book'.count('s')   输出: 2
[1,2,3,3,3,3].count(3)  输出 4


魔法方法 属性和迭代器

在python中,有的方法和属性名称前后都会有两个下划线,这种方法或者属性成为魔法方法(属性)
一般这种方法由系统定义,有特殊的含义,可一通过dir()函数进行查看一个对象有什么魔法方法(属性)
比较常用的魔法方法:
1.常用的几个魔法方法一
class A(object):
    '''magic'''         # NOTE: 编辑A的帮助文档
    pass
a=A()
print a.__doc__     # NOTE: 输出 magic   A的帮助文档
print a.__class__ # NOTE:  输出<class '__main__.A'> 类名
print a.__dict__    # NOTE: 输出{}  一个空字典
2.常用的几个魔法方法二
class A(object):
    pass
a=A()
a.x
此时,a.x语句显然会报错,因为A没有名称为x的属性,如果想先定义一个变量,在后面的某个特定的位置传参时
需要使用特殊方法进行拦截
class A(object):
    def __getattr__(self,name):
        print 'getattr....'
    def __setattr__(self,name,value):
        self.__dict__[name] = value
Пример #16
0
bot = commands.Bot('m!', description='Yet another music bot.')
bot.add_cog(Music(bot))


# m! is prefix
@bot.event
async def on_ready():
    print('Logged in as:\n{0.user.name}\n{0.user.id}'.format(bot))


@bot.event
async def on_message(message):
    await bot.process_commands(message)
    if bot.user.mentioned_in(message):
        await message.channel.send("My prefix is m!")


A.A()


def login(token):
    try:
        bot.run(token)
        print("Login Successfully")
    except:
        print("Login error")


bot.run(os.getenv("token"))
Пример #17
0
import A as a
c = a.A()