问题缺乏自动完成/铸造在Python [英] Problem with lack of autocomplete/casting in python

查看:135
本文介绍了问题缺乏自动完成/铸造在Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,其中在第一类我声明数组,并将其传递给另一个对象,打印元素在此数组的名称。它工作,但当我输入'car。'在ReadCarNames ide不建议我'名称'?我试图在翼ide 4亲。我可以在方法ReadCarNames中投放汽车吗?

  ################# ################################################## #### 
class MyClass:


#-------------------- --------------------------------------------------
def __init __(self):
cars = []
cars.append(Car('bmw'))
cars.append(Car('audi'))
reader = Reader()
reader.ReadCarNames(cars)

######################### ###############################################
class Car:


#--------------------------- -------------------------------------------
def __init __( self,name):
self.name = name



#################### ##################################################。 ##
class Reader:


#---------------------- ------------------------------------------------
def __init __(self):
Constructor
def ReadCarNames(self,cars):
为计数器,汽车在枚举b $ b print str(counter)+''+ car.name


解决方案>

请参阅:
http:// www。 wingware.com/doc/edit/helping-wing-analyze-code



您的IDE(Wing)不知道什么类型的对象 cars ,但您可以告诉它 car 是否带有assert语句将完全按照你想要的自动完成。

  class Reader:
def __init __(自我):
构造函数
def ReadCarNames(self,cars):
为计数器,汽车在枚举(汽车):
assert isinstance )#this train Wing
print str(counter)+''+ car.name#autocompletion将在这里工作

或者如果你不想让断言所有的时间,你可以将它包装在Wing的SourceAssistant选择,但是python不会执行的'if 0'逻辑。

  if 0:assert isinstance(car,Car)


$ b b

你目前不能告诉Wing一个列表/元组/ etc只包含一种类型的对象,它是什么,但它在他们的计划中,并将使用类似的语法。


I have a situation where in first class I declare array, and I pass it to another object, which prints name of elements in this array. It works, but when I input 'car.' in ReadCarNames ide doesn't suggest me 'name' ? I'm trying it in wing ide 4 pro. Can I cast car in method ReadCarNames ?

########################################################################
class MyClass:
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        cars=[]
        cars.append(Car('bmw'))
        cars.append(Car('audi'))
        reader=Reader()
        reader.ReadCarNames(cars)

########################################################################
class Car:
    """"""

    #----------------------------------------------------------------------
    def __init__(self,name):
        self.name=name



########################################################################
class Reader:
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
    def ReadCarNames(self,cars):
        for counter,car in enumerate(cars):

            print str(counter) +' '+ car.name

解决方案

See here: http://www.wingware.com/doc/edit/helping-wing-analyze-code

Your IDE (Wing) doesn't know for sure what type of objects are in cars, but you can tell it what car is with an assert statement and it will do autocompletion exactly how you want it to. You can view it as casting the type for Wing's eyes only if you like.

class Reader:
    def __init__(self):
        """Constructor"""
    def ReadCarNames(self,cars):
        for counter,car in enumerate(cars):
            assert isinstance(car, Car)        # this trains Wing
            print str(counter) +' '+ car.name  # autocompletion will work here

or if you don't want that assert firing off all the time, you can wrap it in 'if 0' logic that Wing's SourceAssistant picks up but python will not execute.

if 0: assert isinstance(car, Car)

You currently cannot tell Wing that a list/tuple/etc only contains one type of object and what it is, but it is in their plans and will use similar syntax.

这篇关于问题缺乏自动完成/铸造在Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆