This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: execfile does not work with UNC paths
Type: behavior Stage:
Components: Unicode, Windows Versions: Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, stier08, tim.golden
Priority: normal Keywords:

Created on 2010-06-01 14:40 by stier08, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg106841 - (view) Author: stier08 (stier08) Date: 2010-06-01 14:40
execfile() builtin function does not work with UNC paths on Windows platform (Windows 7 x64 has been tested, python 2.6.5)

Since standard IO operations successfully process UNC paths, therefore this behavior of execfile() seems to be a bug.

Code to reproduce (assuming drive c: is present and you have rw permissions)
>>> a=u'\\\\?\\c:\\a.py'
>>> open(a,"w").write("print 'hellow'") # successful write to UNC file 
>>> file(a).read() # successful read from UNC file 
"print 'hellow'"
>>> execfile(a) # ERROR
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: '\\\\?\\c:\\a.py'

See description of UNC naming convention
at msdn http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
at wikipedia http://en.wikipedia.org/wiki/Path_(computing)#Uniform_Naming_Convention
msg106842 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2010-06-01 14:54
Since execfile is basically shorthand for exec (open (filename).read ()),
and since open (filename) *does* support the full range of filepath
syntax on Windows, and since execfile has been removed in py3k in favour
of exec (open ...)), and since Python 2.x is nearing its end-of-life,
I doubt this issue will garner much sympathy.

I haven't actually looked at the code to discover just *why* execfile
doesn't support that style of filename. But is there any reason you
can't use exec (open (...))?
msg106844 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-06-01 15:49
Reproduced on WinXP.
execfile() does not work because it calls the system function stat(); 
this function does accept UNC paths (like \\machine\share\file), but not paths which contain a wildcard character ('?' or '*')

I suggest to remove the leading '\\\\?\\'.
msg106850 - (view) Author: stier08 (stier08) Date: 2010-06-01 17:27
yep exec (open (...)) is OK here thanks
History
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 53115
2010-06-22 08:09:02tim.goldensetstatus: open -> closed
resolution: out of date
2010-06-01 17:27:54stier08setmessages: + msg106850
2010-06-01 15:49:19amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg106844
2010-06-01 14:54:13tim.goldensetnosy: + tim.golden
messages: + msg106842
2010-06-01 14:40:36stier08create