Windows 中 os.path.join 的不可预测结果 [英] Unpredictable results from os.path.join in windows
问题描述
所以我想做的是以
os.path.join('C:\path\to\folder', 'filename').
**实际代码是:
filename = 'creepy_%s.pcl' % identifier
file = open(os.path.join(self.cache_dir, filename), 'w')
其中 self.cache_dir 是使用 configobj 从文件中读取的(返回字符串),在特定情况下是 '\Documents and Settings\Administrator\creepy\cache'
where self.cache_dir is read from a file using configobj (returns string) and in the particular case is '\Documents and Settings\Administrator\creepy\cache'
第一部分是从配置文件中返回的,使用 configobj.第二个是 2 个字符串的串联,例如:'file%s' % name
The first part is returned from a configuration file, using configobj. The second is a concatenation of 2 strings like: 'file%s' % name
当我使用安装的 python 解释器在 windows 中通过控制台运行应用程序时,我得到了预期的结果
When I run the application through the console in windows using the python interpreter installed, I get the expected result which is
C:\\path\\to\\folder\\filename
当我在 Windows 的可执行文件中捆绑相同的应用程序和 python 解释器(相同版本,2.6)并运行该应用程序时,结果是
When I bundle the same application and the python interpreter (same version, 2.6) in an executable in windows and run the app the result is instead
C:\\path\\to\\folderfilename
关于可能是什么问题的任何线索,或者什么会导致输出中的这种不一致?
Any clues as to what might be the problem, or what would cause such inconsistencies in the output ?
推荐答案
我昨天弄明白了.像往常一样,当事情看起来很奇怪时,解释很简单,而且大多数时候都涉及到你是愚蠢的.
I figure it out yesterday. As usual when things seem really strange, the explanation is very simple and most of the times involve you being stupid.
长话短说,dist-packages 中有一些以前安装的剩余部分.捆绑的解释器从那里加载了模块,但是当我从终端运行 python 脚本时,加载了当前目录中的模块(较新版本).因此,不可预测"的结果.
To cut a long story short there were leftovers from some previous installations in dist-packages. The bundled interpreter loaded the module from there , but when i ran the python script from the terminal , the module (newer version) in the current dir was loaded. Hence the "unpredictable" results.
这篇关于Windows 中 os.path.join 的不可预测结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!