Reading files in from the proper directory

SMac2347 at comcast.net SMac2347 at comcast.net
Thu Feb 9 15:36:45 EST 2012


On Feb 7, 3:16 pm, Peter Otten <__pete... at web.de> wrote:
> SMac2... at comcast.net wrote:
> > xls_files   = glob.glob(in_dir + "*.xls")
>
> Try changing that to
>
> pattern = os.path.join(in_dir, "*.xls")
> xls_files = glob.glob(pattern)
>
> os.path.join() inserts a (back)slash between directory and filename if
> necessary.
>
> > merge_xls(in_dir="C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS")
>
> If you paste the directory name literal into the interactive interpreter
> you'll be surprised:
>
> >>> "C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS"
>
> 'C:\\Documents and Settings\\smacdon\\Desktop\x009 Aggregate JWS'
>
> "\09" is intrpreted as chr(9). Use a raw string to prevent Python from
> interpreting a backslash as the start of an escape sequence
>
> >>> r"C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS"
>
> 'C:\\Documents and Settings\\smacdon\\Desktop\\09 Aggregate JWS'
>
> or use forward slashes as directory separators.

Disregard my last post, I was able to figure it out, I also had to
cover the out_file file name into a raw string as well. Thanks again
for all the help!!!



More information about the Python-list mailing list