A Portuguese translation of the Python functions/modules/packages
Project description
Portugython
Escreva Python em Portugues. Portugython traduz funcoes, tipos e modulos da biblioteca padrao do Python para nomes em portugues.
Instalacao
pip install portugython
Uso basico
from portugython import *
escreva("Ola, Mundo!")
nome = leia("Qual e seu nome? ")
escreva("Ola,", nome)
numeros = Lista([1, 2, 3, 4, 5])
numeros.adicione(6)
numeros.classifique(reverso=Verdadeiro)
escreva(numeros)
pares = filtro(lambda x: x % 2 == 0, numeros)
escreva("Pares:", pares)
resultado = se(tamanho(pares) > 0, "tem pares", "sem pares")
escreva(resultado)
Modulos da biblioteca padrao
Cada modulo da stdlib tem uma versao em portugues que pode ser importada separadamente.
aleatorio (random)
from portugython import aleatorio
aleatorio.semente(42)
n = aleatorio.inteiro_aleatorio(1, 100)
item = aleatorio.escolha(["pedra", "papel", "tesoura"])
lista = [1, 2, 3, 4, 5]
aleatorio.embaralhe(lista)
amostra = aleatorio.amostra(range(50), k=5)
matematica (math)
from portugython import matematica
print(matematica.PI)
print(matematica.raiz_quadrada(16))
print(matematica.fatorial(10))
print(matematica.seno(matematica.PI / 2))
print(matematica.mdc(48, 18))
print(matematica.combinacoes(10, 3))
sistema (os + sys)
from portugython import sistema
pasta = sistema.diretorio_atual()
arquivos = sistema.listar_diretorio(".")
sistema.criar_diretorios("nova/pasta", existe_ok=Verdadeiro)
sistema.renomear("antigo.txt", "novo.txt")
print(sistema.versao)
print(sistema.plataforma)
db = sistema.variavel_ambiente("DATABASE_URL", "sqlite:///app.db")
tempo (time + datetime)
from portugython import tempo
agora = tempo.agora()
print(agora.formatar("%d/%m/%Y %H:%M"))
hoje = tempo.hoje()
print(hoje.ano, hoje.mes, hoje.dia)
dur = tempo.Duracao.de(dias=7, horas=2)
print(dur.total_segundos)
tempo.dormir(0.1)
colecoes (collections)
from portugython import colecoes
# Contagem
votos = colecoes.Contador(["sim", "nao", "sim", "sim", "nao"])
print(votos.mais_comuns(1))
# Fila dupla
d = colecoes.Deque([1, 2, 3])
d.adicione_esquerda(0)
d.adicione_direita(4)
# Pilha
pilha = colecoes.Pilha()
pilha.empurre("a")
pilha.empurre("b")
print(pilha.retire())
# Fila
fila = colecoes.Fila()
fila.enfileire("primeiro")
fila.enfileire("segundo")
print(fila.desenfileire())
# Tupla com campos nomeados
Ponto = colecoes.tupla_com_nome("Ponto", ["x", "y"])
p = Ponto(3, 4)
print(p.x, p.y)
iteradores (itertools)
from portugython import iteradores
# Combinatoria
for combo in iteradores.combine([1, 2, 3, 4], 2):
print(combo)
# Produto cartesiano
for par in iteradores.produto("AB", "12"):
print(par)
# Acumulacao
totais = list(iteradores.acumule([1, 2, 3, 4, 5]))
# Encadeamento
unido = list(iteradores.encadeie([1, 2], [3, 4], [5]))
funcional (functools)
from portugython import funcional
# Reducao
total = funcional.reduzido(lambda a, b: a + b, range(1, 11))
# Funcao parcial
multiplicar_por_3 = funcional.parcial(lambda a, b: a * b, 3)
print(multiplicar_por_3(7))
# Memoizacao
@funcional.cache
def fibonacci(n):
if n < 2:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
# Composicao
dobrar = lambda x: x * 2
somar_um = lambda x: x + 1
dobrar_e_somar = funcional.compor(somar_um, dobrar)
print(dobrar_e_somar(5))
expressao (re)
from portugython import expressao
# Busca simples
m = expressao.buscar(r"\d+", "pagina 42")
if m:
print(m.group())
# Todos os resultados
numeros = expressao.encontrar_todos(r"\d+", "1 mais 2 igual 3")
# Substituicao
limpo = expressao.substituir(r"\s+", " ", "texto com espacos")
# Padrao reutilizavel
email = expressao.Padrao(r"[\w.+-]+@[\w-]+\.[a-z]{2,}")
if email.encontrar("contato@example.com"):
print("Email valido")
Referencia de builtins
Entrada / Saida
| Portugues | Python |
|---|---|
escreva |
print |
leia |
input |
abra |
open |
Tipos
| Portugues | Python |
|---|---|
inteiro |
int |
texto |
str |
decimal |
float |
logico |
bool |
lista |
list |
dicionario |
dict |
conjunto |
set |
tupla |
tuple |
intervalo |
range |
Constantes
| Portugues | Python |
|---|---|
Verdadeiro |
True |
Falso |
False |
Nenhum |
None |
Funcoes de sequencia
| Portugues | Python |
|---|---|
tamanho |
len |
soma |
sum |
maximo |
max |
minimo |
min |
absoluto |
abs |
classificado |
sorted |
reverso |
reversed |
enumerado |
enumerate |
comprimido |
zip |
mapeado |
map |
filtrado |
filter |
Operadores logicos
| Portugues | Python |
|---|---|
nao(x) |
not x |
e(a, b) |
a and b |
ou(a, b) |
a or b |
Funcoes utilitarias
| Portugues | Python |
|---|---|
se(c, a, b) |
a if c else b |
para_cada(f, it) |
list(map(f, it)) |
filtro(f, it) |
list(filter(f, it)) |
reduzido(f, it) |
functools.reduce(f, it) |
Contribuir
- Crie um fork deste repositorio
- Crie uma branch nova a partir de main
- Envie um pull request
Licenca
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
portugython-0.3.0.tar.gz
(44.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file portugython-0.3.0.tar.gz.
File metadata
- Download URL: portugython-0.3.0.tar.gz
- Upload date:
- Size: 44.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43a6d95062fec61767619b570314894dae3a253092479248cf1c7f098aecf939
|
|
| MD5 |
4b5640428d407266727c45436af71bab
|
|
| BLAKE2b-256 |
a8735d61c4a5e6e0c359d595db3fdc4f99f45e3df73e529465586c1ad59a5898
|
File details
Details for the file portugython-0.3.0-py3-none-any.whl.
File metadata
- Download URL: portugython-0.3.0-py3-none-any.whl
- Upload date:
- Size: 49.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13b948b67280879f05989cf2ab5482624a6040cd22eb7645bda94bfb6e8464f1
|
|
| MD5 |
c430fe2675b660825bbbfbda5b19cfb8
|
|
| BLAKE2b-256 |
236f54d761573a633204afe58b950a86b5ee40fc969f8564fc6233678d622037
|