Size of list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ernesto

    #1

    Size of list

    for line in PM_File_Handle. readlines():
    PM_fields = line.split(';')

    # Is there a way to get the size of PM_Fields here ?
    # Something like

    size = PM_fields.size( )

    # I could not find this attribute in the python docs. Thanks

  • limodou

    #2
    Re: Size of list

    6 Feb 2006 08:32:18 -0800, Ernesto <erniedude@gmai l.com>:[color=blue]
    > for line in PM_File_Handle. readlines():
    > PM_fields = line.split(';')
    >
    > # Is there a way to get the size of PM_Fields here ?
    > # Something like
    >
    > size = PM_fields.size( )
    >
    > # I could not find this attribute in the python docs. Thanks[/color]

    try:

    size = len(PM_fields)

    --
    I like python!
    My Blog: http://www.donews.net/limodou
    NewEdit Maillist: http://groups.google.com/group/NewEdit

    Comment

    • Ernesto

      #3
      Re: Size of list

      Thanks !

      Comment

      • Schüle Daniel

        #4
        Re: Size of list

        >>> lst = [1,2,3][color=blue][color=green][color=darkred]
        >>> len(lst)[/color][/color][/color]
        3[color=blue][color=green][color=darkred]
        >>> lst.__len__()[/color][/color][/color]
        3

        in genereal all objects which implements __len__
        can be passed to built-in function len[color=blue][color=green][color=darkred]
        >>> len[/color][/color][/color]
        <built-in function len>

        just to give one example how this can be used
        [color=blue][color=green][color=darkred]
        >>> class X(object):[/color][/color][/color]
        .... def __len__(self):
        .... print "this instance has __len__"
        .... return 100
        ....[color=blue][color=green][color=darkred]
        >>> x=X()
        >>> len(x)[/color][/color][/color]
        this instance has __len__
        100[color=blue][color=green][color=darkred]
        >>> x.__len__()[/color][/color][/color]
        this instance has __len__
        100

        hth, Daniel

        Comment

        Working...