Home > other >  I want to transfer a number from one file in Python to another file
I want to transfer a number from one file in Python to another file

Time:07-26

Can I, for example, copy this number from one file to another?

inp = int(input("Enter your number:"))

I want to copy the inp to another file and I want to use the number in the other file ,like this

another file:

print("", inp)

Can I do this and thank you.

CodePudding user response:

file1:

input_num = int(input('Enter a number: '))

file2:

from file1 import input_num
num = input_num

CodePudding user response:

You could write it in a function, then import that function in the other file.

input.py

def input_number():
     inp = int(input("Enter your number"))
     return inp

Other file:

from input import input_number

inp = input_number()
print("", inp)
  • Related