user2137498
user2137498

Reputation: 31

Making a variable accessible for any other module

I am a new user in Python, I have been following this web page and it has helped me a lot. At this moment I am trying to solve an issue of a variables that can´t be accessed from other modules.

Modelu1.py
Texto = ' string'
textoMayus = texto.upper()

print textoMayus 

cadena = textoMayus.split () 

moduel2.py
import entrada
size = len(cadena)

When I run the moduel2.py python gives me this error: NameError: name 'cadena' is not defined

How can I declare a variable taht can be accessible from any other module...

Thanks!!

Upvotes: 3

Views: 110

Answers (1)

BrenBarn
BrenBarn

Reputation: 251373

When you do import entrada you import the module, not the names inside it. You can either do:

import entrada
size = len(entrada.cadena)

or

from entrada import cadena
size = len(cadena)

You should read the Python tutorial to learn the basics of module importing in Python.

Upvotes: 7

Related Questions