O ponto de vista do __main__ pode te confundir em módulos e pacotes Python

This commit is contained in:
Luiz Otávio
2022-11-05 12:04:34 -03:00
parent 94f262d5ca
commit 239139151f
4 changed files with 20 additions and 12 deletions

View File

@@ -17,7 +17,7 @@
"[python]": { "[python]": {
"editor.defaultFormatter": "ms-python.python", "editor.defaultFormatter": "ms-python.python",
"editor.tabSize": 4, "editor.tabSize": 4,
"editor.insertSpaces": true, "editor.insertSpaces": false,
"editor.formatOnSave": true "editor.formatOnSave": true
// "editor.codeActionsOnSave": { // "editor.codeActionsOnSave": {
// "source.fixAll": true, // "source.fixAll": true,

View File

@@ -1,14 +1,18 @@
from sys import path # from sys import path
import aula99_package.modulo # import aula99_package.modulo
from aula99_package import modulo # from aula99_package import modulo
from aula99_package.modulo import * # from aula99_package.modulo import *
# from aula99_package.modulo import soma_do_modulo # # from aula99_package.modulo import soma_do_modulo
# print(*path, sep='\n') # # print(*path, sep='\n')
print(soma_do_modulo(1, 2)) # print(soma_do_modulo(1, 2))
print(aula99_package.modulo.soma_do_modulo(1, 2)) # print(aula99_package.modulo.soma_do_modulo(1, 2))
print(modulo.soma_do_modulo(1, 2)) # print(modulo.soma_do_modulo(1, 2))
print(variavel) # print(variavel)
print(nova_variavel) # print(nova_variavel)
from aula99_package.modulo import fala_oi, soma_do_modulo
print(__name__)
fala_oi()

View File

@@ -3,6 +3,7 @@
# 'soma_do_modulo', # 'soma_do_modulo',
# 'nova_variavel', # 'nova_variavel',
# ] # ]
from aula99_package.modulo_b import fala_oi
variavel = 'Alguma coisa' variavel = 'Alguma coisa'
@@ -12,3 +13,4 @@ def soma_do_modulo(x, y):
nova_variavel = 'OK' nova_variavel = 'OK'
# fala_oi()

View File

@@ -0,0 +1,2 @@
def fala_oi():
print('oi')