import tempfile
import shutil
temp_ = tempfile.mkdtemp()
class ListView_(Screen):
def Image_(self, path):
global image_file_path
file_path = shutil.copy2(path[0], temp_)
in python 3 file_path output is a "path"
in python 2 file_path output is "None" so how to get the path of the new file in temp directory
shutilcomes with source, so you can look into python 3 version and adapt it.If you compare
shutil.copy2methods for Python 2.7 & 3.4, you'll notice a newreturn dstin the 3.4 version. That's a new feature added, not present in python 2.the interesting lines for you in
shutil.copy2method are:It means that if
temp_is a directory, then target is the directory / basename of the source, else leave it as is, so after this code,dstis always a target file name, andopen(dst,"wb')will work.so to make your code compatible with python 2 & 3 (which is a good thing when it's possible), you can emulate that by using a ternary expression to compute the actual filepath target, then use it directly in
shutil(why passing a directory again ?):