Skip to main content

C++-style IO in Python!

Project description

Pouty: a very silly library bringing weird C++ features to Python since 2022

Do you like Python? Wanna use std::cout in it? No? I didn't ask!

pouty is a Python package that will make you pout with it's ability to use C++ style IO in Python.

FAQ:

  • Is it fast? No.
  • Does C++ I/O even make sense in this context? That's for you to judge.
  • Is it faster than Python's print()? While it may occasionally avoid a string creation or contcatenation, it does so through multiple operator overloads and several function calls + type checks. Therefore, no.
  • Why is C++'s iostream fast? C++ is a compiled language with static typing and function call inlining.
  • Why make this? Because I can.

Example code (examples/test.py):

from pouty.iostream import *;
import random;

std.cout << "Hello, world!" << std.endl

class CustomOutput: #custom operator<< and operator>> overload supported
    is_pouty_stream = True
    def __init__(self) -> None:
        self.x = ref(0)
        pass

    def __lshift__(self, other: any) -> None:
        other << self.x[...]
    
    def __rshift__(self, other: any) -> None:
        other >> self.x

# Python [unfortunately, perhaps fortunately!] does not have implicit reference parameters.
x = ref(0)
std.cin >> x
std.cout << x << std.endl # uses the __str__ method of ref
std.cout << x[...] << std.endl # dereferences the ref and prints the int

x = CustomOutput()
std.cin >> x
std.cout << x << std.endl

x = random.random() #precision is supported too!
std.cout << x << std.endl
std.cout << std.precision(3) 
std.cout << x << std.endl


using_namespace(globals(), "std")
cout << "Hello, world!" << endl # bringing namespace pollution into Python since 2022 :)

from pouty.stdlib.h import *;

printf("%s", "Hello, world!")
printf("%d", 123) #note that precision is not supported yet here (feel free to contrubute it)
puts("Hello, world!")

Installation

pip install pouty

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss the change.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pouty-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

pouty-1.0.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file pouty-1.0.0.tar.gz.

File metadata

  • Download URL: pouty-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for pouty-1.0.0.tar.gz
Algorithm Hash digest
SHA256 88fb779350a3ab06cb77a4317d484912212f49093597b7698726e89f1c82c9a7
MD5 081dd995ebe649fe55976d0ad533e557
BLAKE2b-256 7e8cdf0562a635c94714cd1c033b39a089de2de146d10ed6e93dbad651372898

See more details on using hashes here.

File details

Details for the file pouty-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pouty-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for pouty-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d34c0809c5ab9458e5ebb30af050177fe6b26ec4837a110cda072de35d2b902
MD5 230258cb70f4bf9e209cb7fdba15bd23
BLAKE2b-256 380d7c5f8e316c30e34d3e02a7c1cf0ed68f651175fe0948736a1eb798d5606f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page