Brian Granger skrev:
> Here is the actual error and the path names that seem to be problematic:
>
> In [1]: import tempfile
>
> In [2]: f = tempfile.NamedTemporaryFile()
>
> In [3]: f.name
> Out[3]: 'c:\\docume~1\\admini~1\\locals~1\\temp\\tmpfydqw_'
>
> In [4]: f.write('pass\n')
>
> In [5]: %run $f.name
> ERROR: File `c:docume~1admini~1locals~1temptmpfydqw_.py` not found.
>
Perhaps you can use something like this to get the full pathname first.
I would probably choose the first approach because ctypes is a
dependency of pyreadline which most users of ipython would have anyway.
But pywin32 is not.
using either of these solutions you can do
In [7]: import win32api, tempfile
In [8]: f = tempfile.NamedTemporaryFile()
In [9]: f.name
Out[9]: 'c:\\docume~1\\jstenar\\lokala~1\\temp\\tmp3xrtkk'
In [10]: win32api.GetLongPathName(f.name)
Out[10]: 'c:\\Documents and Settings\\jstenar\\Lokala
inst\xe4llningar\\Temp\\tmp3xrtkk'
In [11]: get_long_path_name(f.name)
Out[11]: u'c:\\Documents and Settings\\jstenar\\Lokala
Inst\xe4llningar\\Temp\\tmp3xrtkk'
In [12]: win32api.GetLongPathNameW(f.name)
Out[12]: u'c:\\Documents and Settings\\jstenar\\Lokala
inst\xe4llningar\\Temp\\tmp3xrtkk'
Brian Granger skrev: NamedTemporaryF ile() 1\\admini~ 1\\locals~ 1\\temp\ \tmpfydqw_ ' 1admini~ 1locals~ 1temptmpfydqw_ .py` not found.
> Here is the actual error and the path names that seem to be problematic:
>
> In [1]: import tempfile
>
> In [2]: f = tempfile.
>
> In [3]: f.name
> Out[3]: 'c:\\docume~
>
> In [4]: f.write('pass\n')
>
> In [5]: %run $f.name
> ERROR: File `c:docume~
>
Perhaps you can use something like this to get the full pathname first.
The code below was based on a function from /svn.participat oryculture. org/svn/ dtv/tags/ Democracy- Player- 0.9.1.1/ tv/platform/ windows- xul/platformuti ls.py>
<https:/
import ctypes windll. kernel32. GetLongPathName W e.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p,
_GetLongPathName = ctypes.
_GetLongPathNam
ctypes.c_uint ]
def get_long_ path_name( path): create_ unicode_ buffer( 260) e(path, buf, 260)
buf = ctypes.
rv = _GetLongPathNam
if rv == 0 or rv > 260:
return path
else:
return buf.value
or using win32api (which is not a standard library but comes with pywin32)
import win32api GetShortPathNam e (path_name)
win32api.
I would probably choose the first approach because ctypes is a
dependency of pyreadline which most users of ipython would have anyway.
But pywin32 is not.
using either of these solutions you can do
In [7]: import win32api, tempfile
In [8]: f = tempfile. NamedTemporaryF ile()
In [9]: f.name 1\\jstenar\ \lokala~ 1\\temp\ \tmp3xrtkk'
Out[9]: 'c:\\docume~
In [10]: win32api. GetLongPathName (f.name) \jstenar\ \Lokala r\\Temp\ \tmp3xrtkk'
Out[10]: 'c:\\Documents and Settings\
inst\xe4llninga
In [11]: get_long_ path_name( f.name) \jstenar\ \Lokala r\\Temp\ \tmp3xrtkk'
Out[11]: u'c:\\Documents and Settings\
Inst\xe4llninga
In [12]: win32api. GetLongPathName W(f.name) \jstenar\ \Lokala r\\Temp\ \tmp3xrtkk'
Out[12]: u'c:\\Documents and Settings\
inst\xe4llninga