0
I have to find in the question, the email and wpp by the name that is inserted, and I need to put it in a def in task.py for example, I did so so:
import __init__
def encontrar(elemento):
pos_i = __init__.wpp
pos_j = __init__.email
for i in range(len(__init__.agenda)):
for j in __init__.agenda[i]:
if elemento in __init__.agenda[i][j]:
pos_i = i
pos_j = j
break
break
return (pos_i, pos_j)
my init is like this:
import task
agenda = []
contatos = []
nome = input('Digite o nome: ')
wpp = int(input('Digite o número: '))
email = input('Email: ')
contatos = [nome, wpp, email]
agenda.append(contatos)
r = task.encontrar('ana')
print(r)
But make the following mistake:
Traceback (most recent call last):
File "Estrutura de Dados/LIST - Lista de Exercícios/E1/__init__.py", line 1, in <module>
import task
File "Estrutura de Dados\LIST - Lista de Exercícios\E1\task.py", line 1, in
<module>
import __init__
File "Estrutura de Dados\LIST - Lista de Exercícios\E1\__init__.py",
line 12,
in <module>
r = task.encontrar('ana')
AttributeError: module 'task' has no attribute 'encontrar'
The archive init.py will conventionally run when your module is imported, in addition, by your traceback, I would say to replace that
import task
forfrom E1 import task
, if you are inside the folderLIST - Lista de Exercícios
, and then run your file. Another thing, your task.py file is with the wrong method indentation levels from the for loop.– Ronald Rodrigues
Inside the folder
LIST - Lista de Exercícios
has the pycharm task 'E1' with the files, I tried for that other import but it does not work, unresolved Reference E1 and task– Tole
A doubt, in which folder you have your terminal open while calling the python interpreter? The folder where you call it will be considered the root of your project and this will affect your Rts. The pycharm is just an IDE, it would be interesting for you to run out of it to better understand how your project is organized.
– Ronald Rodrigues
It was bad, but I did not understand your question, I always did everything in this folder, including have other examples that call the module in another init and works smoothly
– Tole