global name is not defined - error

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

    #1

    global name is not defined - error

    What I want
    ---------------
    I want to create a list of items from a function operating on an array
    of strings


    What I did
    -----------------
    list=["s0","s1"," s2"]
    l=len(list)
    for i in range(l):
    d_list[i]=f.do(list[i])
    print d_list[i]

    Error:
    ------
    global name 'd_list' is not defined
    Python c:\test.py in newClass, line 30

    Please help me out
    thanks
    -a

  • Bruno Desthuilliers

    #2
    Re: global name is not defined - error

    a wrote:[color=blue]
    > What I want
    > ---------------
    > I want to create a list of items from a function operating on an array
    > of strings[/color]

    def func(s):
    return s.upper()

    arrayOfStrings = ['bicycle', 'repair', 'man']

    print "solution 1: with map()"
    print map(func, arrayOfStrings)
    print "solution 2: with list comprehension"
    print [func(s) for s in arrayOfStrings]


    --
    bruno desthuilliers
    python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
    p in 'onurb@xiludom. gro'.split('@')])"

    Comment

    Working...