Skip to content Skip to sidebar Skip to footer

Python To Get File Name And Open In Another Script

I have a one.py as: one.py def file_save(): f = th1.asksaveasfile(mode='w', defaultextension='.txt') filename = f.name I have another file two.py where i need to open 'fi

Solution 1:

One.py:

def file_save():
    f = th1.asksaveasfile(mode='w', defaultextension=".txt")
    filename = f.name
    return filename;

Main.py:

from one import file_save
withopen(file_save,'w'):
   print('hello')

In Python, you cannot access a variable in a function unless it is returned.

Edit:

Try

f = open(file_save, 'w')
print('hello')

Post a Comment for "Python To Get File Name And Open In Another Script"