I'm trying to understand how the whole thing in Python works. I want to ask the user for "ID" and then to read from a .py file with the "ID" name.
for example: the user insert "361" and the code will open "361.py" and get variables from that file
I'm trying to understand how the whole thing in Python works. I want to ask the user for "ID" and then to read from a .py file with the "ID" name.
for example: the user insert "361" and the code will open "361.py" and get variables from that file
Mainfile:
import ID_361
a = input('Enter Code: ')
if a =='361':
ID_361.ID_361()
ID_361:
def ID_361():
print('OK')
The files have to be in the same directory!
But can you say for what you need it? It gives way more easier ways
Better:
Mainfile:
import IDs
a = input('Enter Code: ')
if a =='361':
IDs.ID_361()
elif a =='362':
IDs.ID_362()
elif a =='363':
IDs.ID_363()
IDs:
def ID_361():
print('OK 361')
def ID_362():
print('OK 362')
def ID_363():
print('OK 363')
Pros: You only have 2 files and not like 100 which makes it clear