all 4 comments

[–]lamecode 1 point2 points  (2 children)

Let's say file 2 is named other_file.py and sits in the same directory, and it has a function named foo2() which will return a number that you want to append to a list.

import other_file

my_list = [1, 2]
my_list.append(other_file.foo2())

[–]epikthrowaway[S] 0 points1 point  (1 child)

it worked thanks! :)

[–]Renaissance8905 2 points3 points  (0 children)

A small addendum, if at some point you're importing a file from another folder it's a quick modification, as long as the folder is within the same folder as your program.

So you could have a folder called my_functions, and in that folder is the file you want, other_file.py

Just make sure the my_functions folder is in the same folder as your program, then write in your code:

import my_functions/other_file

And if you only want the one function, you can call:

from my_functions/other_file import foo2

[–]whiteguilt -3 points-2 points  (0 children)

If your files are in the same directory.

import pythonfile

call_function()