我是passtime程序员,所以请保持温柔。现在,对于实际问题,我的用户之一遇到了这种奇怪的行为,该行为os.path.join(p1,p2)返回一个相对路径,其中所有斜杠均从中省略p1。像这样(假设这是在python cmd行解释器中完成的):>>import os>>p1 = "/Some/Path/Tosmth">>p2 = "file.ext">>print os.path.join(p1,p2)`然后输出是:>>"SomePathTosmth/file.ext"在加入操作之前,我检查了p1和p2的内容,这正是我所期望的。这是有问题的实际实现,其中包含一些其他调试代码: def __moveMovie(self, src, dst, folder, file_name): try: self.logDebug('__moveMovie(): src=%s | dst=%s | folder=%s | file_name=%s' % (src, dst, folder, file_name)) dest = save_path(dst) file_name = save_path(file_name) if self.getConfig("subfolder") is True: dest = os.path.join(dst,folder) os.mkdir(Utils().encode(dest)) except OSError, e: if e.args[0] == 17: self.logDebug(u'Cannot create folder "%s". It already exists.' % os.path.join(dest)) try: full_dst = Utils().encode(os.path.join(dest,file_name)) self.logDebug('var "full_dst" w/o encode: %s' % os.path.join(dest, file_name)) self.logDebug('var "full_dst" w/ encode: %s' % Utils().encode(os.path.join(dest,file_name))) if os.path.exists(full_dst): pass shutil.move(src, full_dst) self.logInfo(u'Movie "%s" moved to "%s"' % (os.path.split(src)[1], os.path.join(dest,file_name))) self.__movie_queue.task_done() except OSError, e: if e.args[0] == 21: self.logDebug(u'Cannot move "%s" to "%s". "%s" is a directory.' % (os.path.split(src)[1], os.path.join(dest, file_name), os.path.join(dest, file_name))) self.__movie_queue.task_done()
添加回答
举报
0/150
提交
取消