Python horks on WinXP path names

Jerry Hill malaclypse2 at gmail.com
Thu Dec 8 15:45:35 EST 2011


On Thu, Dec 8, 2011 at 3:16 PM, Eric <einazaki668 at yahoo.com> wrote:

> I'm running Python 2.7 on WinXP (ActiveState community version) and
> when I try to do this:
>
> if __name__ == '__main__':
>    root = Tkinter.Tk()
>    root.withdraw()
>    fileNames = tkFileDialog.askopenfilenames()
>    root.destroy()
>    print fileNames
> # windows filename gets
> for fileName in fileNames:
>    print fileName
>    file = open(fileName, 'r')
>    for line in file.readlines():
>            print line.strip()
>
>
> I get this:
>
> C:\Documents and Settings\eric\Desktop\PythonShop>python picker.py
> {C:/Documents and Settings/eric/Desktop/PythonShop/cereal.py}
> {
> Traceback (most recent call last):
>  File "picker.py", line 31, in <module>
>    file = open(fileName, 'r')
> IOError: [Errno 2] No such file or directory: u'{'
>
> That is, fileName is in a form that open() doesn't recognize.  On a
> BSD box the code works fine.  What's going on with the file name and
> how do I fix it?
>

Try replacing your current "print fileNames" line with the follwing:

print type(fileNames), repr(fileNames)

The behavior you're seeing seems to indicate that fileNames is really a
single filename (a single unicode string), rather than a list of file names
(a list containing strings).

I don't know why that would be, but it would be helpful to confirm that
that is, indeed, the problem.

I guess you should also double check that the version of the code you're
running on windows does, in fact, call "tkFileDialog.askopenfilenames()"
rather than "tkFileDialog.askopenfilename()"  The two calls are just one
letter different, but the first one is supposed to return a list, and the
second one is supposed to just return a single string.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111208/61e0b4a2/attachment-0001.html>


More information about the Python-list mailing list