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.1.0.tar.gz
(23.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.1.0.tar.gz.
File metadata
- Download URL: portugython-0.1.0.tar.gz
- Upload date:
- Size: 23.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 |
fba3827c5379af8874eaa106cdac2161ce9ba4736790e2429b9cbfe3d7790a52
|
|
| MD5 |
e9ba1e78d6d8271f2e5885567717a038
|
|
| BLAKE2b-256 |
c22a7547675559e7f3f5a2c2d50ab382bc9e2ed8c74e77326ed2d8ead0f368fc
|
File details
Details for the file portugython-0.1.0-py3-none-any.whl.
File metadata
- Download URL: portugython-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.5 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 |
7897742e4e8a09e215ddb4f26f43ed1db6a5ba8d928d26f8de60c2dbabb93f91
|
|
| MD5 |
ce423e0ae2a91c20637c47f1bd54f569
|
|
| BLAKE2b-256 |
95071ef00ddbfdc0a941fac30466412226f037a959cf68518c0c3d2d6f3b5b1b
|