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.2.0.tar.gz
(41.2 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.2.0.tar.gz.
File metadata
- Download URL: portugython-0.2.0.tar.gz
- Upload date:
- Size: 41.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02716662e2ce751016147fa40a5a0f8f7c6c2d6d5bcf7cf4214391cdfdfea8ea
|
|
| MD5 |
7f40ee48d4fae6b005ec97d4bc672d78
|
|
| BLAKE2b-256 |
9b1fe877245ea98d2e519119b55549ebc887a613a632e3a3ed625acb52737b6e
|
File details
Details for the file portugython-0.2.0-py3-none-any.whl.
File metadata
- Download URL: portugython-0.2.0-py3-none-any.whl
- Upload date:
- Size: 47.3 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 |
fd506f9aec827273aee0b781a36b008c6d21d8a9e279a8af038cdfb62cada26e
|
|
| MD5 |
1040bac13b1ff2b750cfb2c2ca9653b0
|
|
| BLAKE2b-256 |
8bbd4091a9d9e1885dc16a0717f9899d3990404a2d6a50b8a3c7ad498c1380ee
|