Ask coding questions

← Back to all posts
How I supose to use other files? It doesn´t allows me to do it.
Hugoprogramer (0)

When I try to use a comand that I created in another file in the main file it doesn´t work.
Do I need to activate something??
Or use a caracteristic comand?
I use phyton

InvisibleOne (2683)

just import the file

import filename

then you can use functions inside of that file by calling the file name, and then the function name. So if I made a file called and put

def hello():
  print("Hello World!")

inside of it, then in my I could do

import hello_world
hello_world.hello() # "Hello World!" is printed to the console

or I could do this

from hello_world import hello
hello() # "Hello World!" Is printed to the console

Or you can do import os than for example you have a file named do so.system(‘python’)

Ascendancy (1)

For example, you have,,, if you want to run another python script, type in (the original) import and it will run that script.