Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19974
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| 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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'args': 0.05; 'parser': 0.05; 'specifying': 0.07; 'python': 0.08; '__name__': 0.09; 'desktop.': 0.09; 'folder,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:\\ 10': 0.09; 'skip:\\ 20': 0.09; 'subject:files': 0.09; 'def': 0.13; '"__main__":': 0.16; 'argparse': 0.16; 'output?': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.18; 'purposes.': 0.18; 'wrap': 0.18; 'trying': 0.21; 'file,': 0.21; 'runs': 0.23; 'correct,': 0.23; 'from:addr:web.de': 0.23; 'code': 0.26; 'import': 0.27; 'script': 0.28; 'print': 0.29; 'correct': 0.29; 'skip:p 30': 0.29; 'confident': 0.30; 'invoke': 0.30; 'ran': 0.30; 'changes': 0.30; 'usually': 0.31; 'test': 0.34; 'file': 0.34; 'header:X-Complaints-To:1': 0.34; 'to:addr:python-list': 0.35; 'however,': 0.35; 'trouble': 0.35; 'something': 0.35; 'folder': 0.35; 'received:org': 0.36; 'pull': 0.37; 'skip:" 10': 0.37; 'some': 0.38; 'doing': 0.38; 'should': 0.38; 'files': 0.39; 'flexibility': 0.39; 'subject:from': 0.39; 'put': 0.40; 'change': 0.40; 'to:addr:python.org': 0.40; 'your': 0.61; 'making': 0.64; 'here': 0.64; 'destination': 0.67; 'exact': 0.68; 'confidence': 0.82; 'online,': 0.88; 'from.': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Reading files in from the proper directory |
| Date | Tue, 07 Feb 2012 19:59:05 +0100 |
| Organization | None |
| References | <f3f576e8-e608-4348-b6ee-fe775d9d1021@x19g2000yqh.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p50849bc6.dip.t-dialin.net |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5510.1328641121.27778.python-list@python.org> (permalink) |
| Lines | 43 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1328641121 news.xs4all.nl 6861 [2001:888:2000:d::a6]:37395 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:19974 |
Show key headers only | View raw
SMac2347@comcast.net wrote:
> Hello. I am admittedly a Python novice, and ran into some trouble
> trying to write a program that will pull multiple excel files all into
> one file, with each file on a different sheet.
>
> I am confident most of the code is correct, as the program runs
> without any errors and I found the base of it online, making changes
> as necessary for my own purposes.
That confidence usually evaporates once you write the first unit test ;)
> However, I am having trouble
> specifying the exact directory where my code should be pulling the
> files from. All the files are in the same folder, and I have put the
> folder on my desktop. Am I correct in thinking that I need to change
> the current working directory to this folder in order for Python to
> read in these files, then generate my output? Or should I be doing
> something else?
Do it properly, allow specifying the files on the commandline:
import argparse
def process_files(files, destfile):
# put your real code here
print "merge " + "\n ".join(files)
print "into " + destfile
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("files", metavar="file", nargs="+")
parser.add_argument("destfile")
args = parser.parse_args()
process_files(args.files, args.destfile)
If you have standard locations for sources and destination you can wrap your
python script into a little batch file containing something like
python \source\path\*.xls \dest\path\merged.xls
and invoke that to get both flexibility and convenience.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Reading files in from the proper directory SMac2347@comcast.net - 2012-02-07 10:14 -0800
Re: Reading files in from the proper directory Dave Angel <d@davea.name> - 2012-02-07 13:40 -0500
Re: Reading files in from the proper directory SMac2347@comcast.net - 2012-02-07 11:03 -0800
Re: Reading files in from the proper directory Peter Otten <__peter__@web.de> - 2012-02-07 19:59 +0100
Re: Reading files in from the proper directory SMac2347@comcast.net - 2012-02-07 11:13 -0800
Re: Reading files in from the proper directory John Gordon <gordon@panix.com> - 2012-02-07 20:00 +0000
Re: Reading files in from the proper directory Peter Otten <__peter__@web.de> - 2012-02-07 21:16 +0100
Re: Reading files in from the proper directory SMac2347@comcast.net - 2012-02-09 12:32 -0800
Re: Reading files in from the proper directory Peter Otten <__peter__@web.de> - 2012-02-09 22:07 +0100
Re: Reading files in from the proper directory Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-02-09 23:05 -0500
Re: Reading files in from the proper directory SMac2347@comcast.net - 2012-02-09 12:36 -0800
Re: Reading files in from the proper directory John Gordon <gordon@panix.com> - 2012-02-07 19:46 +0000
csiph-web