Skip to content
← Back to Community
Getting variables contained in other python files
Profile icon
f1ash

How can you get status of a variable defined in another python file.
Such as:
In main.py you have :
password = input("enter password")
then i have a password or list of passwords in another python file called passwords.py

How would you print the password defined in another file?
and how would use the if then statement to get a list of passwords and find out if it is on the list?

Voters
Profile icon
Prarambh
Profile icon
yanovsky
Profile icon
anushamaheshwari
Profile icon
f1ash
Comments
hotnewtop
Profile icon
replitcode

do this...

from passwords import variable print(f'{variable}')

or you can do this

from passwords import * print(f'{variable_you_want}')

and the last way is this

import passwords print(f'{passwords.variable}')
Profile icon
RahulChoubey1

@replitcode Why use the f-string if you only need the variable?

Profile icon
Prarambh

@replitcode ayo listen I don't think you will respond cause I am typing this in 2022 but It does not work it just says ''from command import *' used; unable to detect undefined names
'

Profile icon
replitcode

@Prarambh i'm still active. the reason it doesn't work is because it was deprecated as a function. also my partner that use to co-run this account was the one that wrote this. thanks for letting me know though.