Ask coding questions

← Back to all posts
How to use another file in Python ?
PancakeDev (3)

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 (549) [earned 5 cycles]
View Answer
Comments
hotnewtop
robowolf (549)

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

Harkinian (1)

execfile("Your File.py")

PancakeDev (3)

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

Harkinian (1)

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

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