Python Strongly type lists

I am using eclips for python and i am facing a problem. I have many classes with many properties and want a list of objects from one of my declared classes. The problem is:When i am accessing any item from the list, the IDE does not know it's type because in python we do not declare the variable with it's type, so there is no auto complete and i have to go to the class to copy the attribute name. To make idea more clear:

class AutomataBranch(object): def __init__(selfparams): self.Name=""; self.nodes=[]; class LanguageAutomata(object): def __init__(selfparams): self.cfgAutomata=[];#This has AutomaBranch Type

Now in any method in LanguageAutomata class if i wrote: cfgAutomata. Then it wont give me the Name attribute Is there any solution for that?

-------------Problems Reply------------

You shouldn't be writing code to suit your IDE - the IDE is supposed to support you. If you're having trouble with it, then switch. There are plenty of editors that deal with Python properly.

Python is strongly typed and Python lists are too. Your problem come from the fact that Python is dynamically typed. Therefor a var can contain any type, and therefor no IDE can guess what is the type of your parameter, nor give you code completion for the methods.

This is how it is, there is no clean workaround. If it's a problem, then maybe dynamics language is not you predilection tool and you should use something that fit your development style. There are tools for everybody.

I think you mean to say "statically typed" instead of "strongly typed." Python is strongly typed. You just don't know what that type is at compile time.

With that said, you really need to abandon the idea that you're going to find any IDEs that work as well for Python as they do for Java or C#. Python's dynamic typing makes this difficult. In fact, I tend to find that powerful IDEs are more of a burden than a help.

I think I found a good managable solution. Actually it is trivial but may help (I used it now). When I want to access the list then I assign the object which I want to access to a variable ex:

x = AutomataBranch()
x = self.cfgAutomata[i]

The first line is used only to make the IDE knows that x is from AutomatBranch type. After that when I press x then all methods and properties are visualized.

I think it is some how good.

Category:python Views:0 Time:2009-08-17

Related post

  • Why can't python infer types like scala? 2010-10-20

    Possible Duplicate: How to deal with Python ~ static typing? I'm basically a Java programmer with little knowledge of python.I really like the syntax of python and the ease with which a programmer is able to express his idea's but also I'm aware that

  • Enforce strong type checking in C (type strictness for typedefs) 2008-12-17

    Is there a way to enforce explicit cast for typedefs of the same type? I've to deal with utf8 and sometimes I get confused with the indices for the character count and the byte count. So it be nice to have some typedefs: typedef unsigned int char_idx

  • Java Generics - difficulty enforcing strong type checking 2008-12-22

    Here's my code: public class Sequence<T> { protected List<T> sequence = new ArrayList<T>(); public Matrix<OrderedPair<T, ?>> createCartesianProduct(Sequence<?> secondSequence) { Matrix<OrderedPair<T, ?>

  • What is the appropriate way to strongly type the return of a generic function? 2009-03-04

    I'm writing a filter function to return the specific type specified out of a larger collection of supertypes (objects for example). The idea is I give you an enumerable and you return me all the strings for example. you can write it this way without

  • SQL/.NET TableAdapters - How do I strongly-type calculated columns in either the database or the DataSet? 2009-04-27

    We use calculated columns in a few SQL Server 2005 tables which always return data of a specific type (bit, varchar(50), etc...). These tables are consumed by a .NET data layer using strongly-typed datasets and tableadapters, however since the calcul

  • Serialization, attribute to strong type property 2009-07-30

    I have the following xml snippet: <Configuration> <Config name="SendToAddresses"></Config> <Config name="CCToAddresses"></Config> <Config name="BCCAddresses"></Config> </Configuration> What I would like

  • How to cast a Dataset into Strongly Type Object? 2009-07-31

    I get some informations in a Dataset, and i would like to cast it in a strongly type object. For example my dataset have : TableName : tab_data Rows : 1 Columns : Name, FirstName, Address So i created a class like : public class Customer { public Str

  • Strongly type returned JSON using MonoRail 2009-08-14

    I am calling the following method in my controller using $.getJSON() [return: JSONReturnBinder] public object ProfileFields() { var userfields = _profileSvc.GetFields(282); var fields = from f in userfields select new {f.ID, f.FieldName}; return fiel

  • Strongly Type Entity Identifiers 2010-03-01

    When working with service oriented applications we often use system types to identify / query our business entities. IList<Product> GetProductsByUserAndCategoryId(int userId, int categoryId); However we can't prevent developpers to pass another

  • How to strongly type properties in JavaScript that map to models in C#? 2010-04-07

    I'm not even sure if I worded the question right, but I'll try and explain as clearly as possible with an example: In the following example scenario: 1) Take a class such as this: public class foo { public string firstName {get;set;} public string la

  • How do I strongly type criteria when using NHibernate's CreateCriteria method? 2010-07-28

    I'm currently using NHibernate, for the first time, with Fluent NHibernate. I've gotten everything setup nicely, however now I've come to actual doing some data retrieval, it seems to have fallen short. I was expecting NHibernate, to allow me to do s

  • Do Strong Types prevent Buffer Overflow? 2010-09-02

    Do strong types, in this case char prevent buffer overflow? char a[100] char b[100] strcpy(a,unknownFunction); // unknownFunction could overflow b // since its length is unknown strcpy(b,a); // can b still overflow a with its now, // potentially over

  • MVC - Multiple Strong Type object -inside one view 2010-10-25

    After so many years using ASP.Net, I’m still trying to figure out how to achieve the same results using MVC. I have a materpage with a control that is strongly type to something. When I navigate to a view of a different strongly type model ...and cli

  • Is it worthwhile to strongly-type datarows? 2011-02-11

    I have a datarow that I pass around and do things with, and would like to strongly type it, but don't need to strongly-type the table itself. Is there a tool that will autogenerate a strongly-typed row with isnull methods and such? --------------Solu

  • What is Perl equivalent of Python's type() function 2011-03-03

    This question already has an answer here: How do I tell what type of value is in a Perl variable? 5 answers I can do this in Python: >>> type(1) <class 'int'> What's the Perl equivalent? --------------Solutions------------- Perl does n

  • How update only selected fields (anonymouse type-to-strong type) in Entity Framework 2011-03-15

    So in my Entity I have large columns that I dont need in my View. For don't load large columns I use anonymouse type with cast to strong Type _ctx = new hModelContainer(); var skAnonym = from s in _ctx.Sketches where s.SketchStatus.Id == 0 select new

  • Where is the source code for the python 'dict' type? 2011-03-17

    I want to view the source code of the python dict type but i can't find it. I'm looking for python 2.6. --------------Solutions------------- Here is latest python2.6.6 dictobject source code from python svn

  • how to refer to a user control's "strong" type 2011-04-28

    I have code like this which loads a control from an .ascx file, calls some methods of the control, then renders it: Option Explicit Off Sub renderMyControl(p As Page) Dim ctrl as Object = p.LoadControl("path/to/myControl.ascx") ' ... do stuff with ct

  • Django ForeignKey to Generic Python Data Type? 2011-06-18

    I am trying to create a django model which has as one of its fields a reference to some sort of python type, which could be either a integer, string, date, or decimal. class MyTag(models.Model): name = models.CharField(max_length=50) object = (what g

Copyright (C), All Rights Reserved.

processed in 0.082 (s). 11 q(s)