Problems with os.walk

Discussion in 'Python' started by Guest, May 8, 2008.

  1. Guest

    Guest Guest

    Hi everyone

    The following code:

    scriptPath = os.path.dirname(__file__)
    (dirpath, dirnames, filenames) = os.walk(scriptPath)
    print 'dirpath\n'
    print dirpath
    print 'dirnames\n'
    pprint.pprint(dirnames)
    print 'filenames\n'
    pprint.pprint(filnames)

    Fails on the os.walk call with the following error:

    (dirpath, dirnames, filenames) = os.walk(scriptPath)
    ValueError: need more than 1 value to unpack

    Any ideas what could be wrong?

    Thx & greetings
    Dominique

    *****************************************************************************
    This e-mail and any files attached are strictly confidential, may be legally
    privileged and are intended solely for the addressee. If you are not the
    intended recipient please notify the sender immediately by return email and
    then delete the e-mail and any attachments immediately.

    The views and or opinions expressed in this e-mail are not necessarily the
    views of De La Rue plc or any of its subsidiaries and the De La Rue Group
    of companies, their directors, officers and employees make no representation
    about and accept no liability for its accuracy or completeness.

    You should ensure that you have adequate virus protection as the De La Rue
    Group of companies do not accept liability for any viruses.

    De La Rue plc Registered No.3834125, De La Rue Holdings plc Registered
    No 58025 and De La Rue International Limited Registered No 720284 are all
    registered in England with their registered office at:
    De La Rue House, Jays Close, Viables, Hampshire RG22 4BS
    *****************************************************************************
     
    Guest, May 8, 2008
    #1
    1. Advertising

  2. <> writes:

    > (dirpath, dirnames, filenames) = os.walk(scriptPath)


    You're supposed to loop over values in different directories, like
    this:

    for dirpath, dirnames, filenames in os.walk(scriptPath):
    ... handle dirpath with dirnames and filenames ...

    The loop will be executed for each subdirectory (direct and indirect)
    of scriptPath.
     
    Hrvoje Niksic, May 8, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SD
    Replies:
    1
    Views:
    450
  2. pembed2003

    how to walk a binary tree

    pembed2003, Apr 19, 2004, in forum: C++
    Replies:
    7
    Views:
    7,120
    pembed2003
    Apr 20, 2004
  3. Marcus Alves Grando
    Replies:
    7
    Views:
    474
    Marcus Alves Grando
    Nov 14, 2007
  4. Mark Tolonen
    Replies:
    0
    Views:
    558
    Mark Tolonen
    Jun 25, 2009
  5. Gabriel Genellina

    Re: os.walk and os.listdir problems python 3.0+

    Gabriel Genellina, Jun 27, 2009, in forum: Python
    Replies:
    0
    Views:
    466
    Gabriel Genellina
    Jun 27, 2009
Loading...

Share This Page