Problme in python 3.6 with file open!

with open(‘file1.txt’, ‘rb’) as f:
lines = map(transform_complex, f)
arr = np.loadtxt(lines, dtype=np.complex128)

this runs fine in bl 2.79

but in bl 3.6 it cannot find the file in local folder

anyone can help solve this problem

thanks
happy bl

sounds like the working folder isn’t the same between the versions. i believe you can use os.getcwd() to find out if that’s different between the two.

i did the 2 files in the same folder

but giving me an error on the open file some whow
not certain why it does tht in bl 3.6

will try your command
never used that one before

thanks
happy bl

did test and in bl 3.6
it does not recognize anymore the default path to local file

i get folder

Current working directory: H:\Users\Blender-Releases\bl-3.6-lst\blender-3.6.0-windows-x64

which is where the BL exe is located

i used this in bl 2.79

blendfilepath = bpy.data.filepath

print ()
print ('blendfilepath = ', blendfilepath )
print ()

directory = os.path.dirname(blendfilepath)
#starfile = os.path.join( directory , “namefile1.csv”)

starfile = os.path.join( directory , “PR-datain_6.py”)

ts = time()

print ()
print ('directory = ', directory )
print ()
print ('starfile = ', starfile )
print ()

will re test in new file for bl 3.6

very strange !

thanks
happy bl

i’m using the with for open file read mode

with open(‘file1.txt’, ‘rb’) as f:
lines = map(transform_complex, f)
arr = np.loadtxt(lines, dtype=np.complex128)

is there something special about tis new command ?

thanks
happy bl

the getcwd() command? nope. all it does it tells you what that instance of python is using as it’s current work directory. if Blender 2.x was using a different work directory than 3.x, that would explain why Blender 3 wasn’t finding file1.txt, as you did not state an actual path with the open() command. :slight_smile:

how can you do it in bl 3.6 then ?

in bl 2.79 i set the current path and all the open work fine with that new path
but not in bl 3.6 !

thanks
happy bl

works fine for me… if you haven’t done so, you need to import os first:

>>> import os
>>> os.getcwd()
'D:\\Creations\\0065'

(done in blender 3.6 console)

that one is working fine now

i found some weird
not certain i understand why

i change the file name to

f2 = directory + “\” + “file1.txt”

and that works fine with open or the with open file
don’t get why the real file name does not take the current path !

note there should be 2 backslach but even here we see only one !

thanks
happy bl

by the way how doo you close such a file name

tried with f2.close
but did not work !

thanks
happy bl

if you are using with open(f2, ‘rb’) as f then you don’t need to worry about closing, the ‘with’ statement will automatically close the file for you upon exiting the ‘with’ section (the indented parts following). i .think. you could use f.close(), but it’s unnecessary.

if you use something like myfile = open(f2, ‘rb’) then you would indeed need a myfile.close()