Skip to content
← Back to Community
How to use another file in Python ?
Profile icon
PancakeDev

Hi guys !
for a project in Python i need to use many files, but if a function is in the file "english.py", how can i call this function in "index.py" ?

print("Thanks if you give an answer !")

Answered by robowolf [earned 5 cycles]
View Answer
Voters
Profile icon
PratikKharel
Profile icon
PancakeDev
Comments
hotnewtop
Profile icon
robowolf

At the head of index.py do from english import *. Then call the function.

Profile icon
[deleted]

execfile("Your File.py")

Profile icon
PancakeDev

@Harkinian
Yes but i need to import a library or not ?

Profile icon
[deleted]

@DevsOfAnGus

No but
execfile() only works at py2 by the way if you using py3 use this

exec(open('your file.py').read())