Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102147
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: Duplicate Output |
| Date | Wed, 27 Jan 2016 10:12:53 +0100 |
| Organization | None |
| Lines | 43 |
| Message-ID | <mailman.29.1453886008.2338.python-list@python.org> (permalink) |
| References | <56A7BF9A.1070709@verizon.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de u63UFSYdz/ll0JWT+mCOzgDlV4rGAzEAjrZnlTT6KLcg== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'filenames': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'dirnames,': 0.16; 'iteration': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; 'duplicate': 0.18; 'code.': 0.23; 'second': 0.24; 'import': 0.24; 'written': 0.24; 'header:User-Agent:1': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'prints': 0.29; 'subdirectory': 0.29; 'code:': 0.29; 'code': 0.30; 'run': 0.33; 'add': 0.34; 'list': 0.34; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'list.': 0.37; 'doing': 0.38; 'names': 0.38; 'wrong': 0.38; 'files': 0.38; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'skip:n 10': 0.62; 'walk': 0.72; 'stretch': 0.91; 'kate': 0.95 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd8704.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:102147 |
Show key headers only | View raw
Gary Roach wrote:
> Hi
>
> Debian stretch OS
> KDE Desktop
> Code written with Kate
> Run in command line with $python getFileNames.py
>
> Code:
>
> from os import walk
> import subprocess
>
> f = []
> x = ""
> for (dirpath, dirnames, filenames) in walk('.'):
> print(filenames)
>
> This prints [<file list>][<duplicate file list>]
>
> What am I doing wrong or how do I remove the duplicate list.
If there is a second list that list is for a subdirectory of ".". To see
that add
> for (dirpath, dirnames, filenames) in walk('.'):
print(dirpath)
> print(filenames)
to your code. If you only want the names of files in the current directory
you can break out of the loop after the first iteration
> for (dirpath, dirnames, filenames) in walk('.'):
> print(filenames)
break
or use next():
filenames = next(walk("."))[2]
print(filenames)
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Duplicate Output Peter Otten <__peter__@web.de> - 2016-01-27 10:12 +0100
csiph-web