[Tutor] If os.path.lexists() isn't working properly
Dave Angel
davea at ieee.org
Thu Nov 25 04:35:05 CET 2010
On 01/-10/-28163 02:59 PM, Susana Iraiis Delgado Rodriguez wrote:
> Hello Peter!
>
> I added the line you suggested me and found out that I was just searching
> for the filenames without pointing to a specific directory, so Python took
> its directory (Python26) as default. After that I need to add a '\' to
> separate the path from the filename because it was reading them as a single
> string. But finally it worked nicely! here is the corrected script.
>
> <snip>
> wksht.row(row).write(1, filename)
> n = os.path.splitext(filename)
> p = ruta+'\\'+n[0]+'.prj'
>
Use os.path.join() to combine these nodes. If you use an explicit
backslash you can trigger two problems: 1) Your code won't be portable
to other platforms 2) You could have trouble if one of the components
already has a path separator.
DaveA
More information about the Tutor
mailing list