Skip to main content

Programming contest input/output module

Project description

PCIO

Input from stdin by format. Values can distrubuted on different lines.

import pcio

# Input two integer numbers as tuple
a,b=pcio.input('ii')

# Input a list of integer numbers
arr=pcio.input(100,'i')

# Input a list of pair float numbers
arr=pcio.input(100,'ff')

# Input one symbol
pcio.input(1)

# Input one line by default
s=pcio.input()

Function raises EOFError on end of file and ValueError if value is not a number.

Input Format Description
i Integer number, skip spaces before number
f Float number, skip spaces before number
w Word, skip spaces before word
c One character as string
l One line as a string
L One line with new line as a string
a All input as one string

Also specialized variants

import pcio

a=pcio.input_int()
b=pcio.input_float()
c=pcio.input_char()
d=pcio.input_word()
e=pcio.input_line()

Print according to the format specified by the first argument.

import pcio

# Print by format
pcio.print("Hello, {}!\n", "world")

# Print a list separated by space and new line
arr=[1,2,3,10,12.2,'a']
pcio.println(arr)
# 1 2 3 10 12.2 a
pcio.println('{:02i}',arr) 
# 01 02 03 10 12 a
pcio.println('{!r}',arr)
# [1,2,3,10,12.2,'a']

If the first argument is not a string then the format '{} {} {}' is used where the number of parentheses is equal to the number of arguments.

Format contain "replacement fields" surrounded by curly braces {}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.

replacement_field ::=  "{" [arg_index] [format_spec] "}"
format_spec ::=  "!" "r" | ":" [align][sign]["0"][width]["." precision][type]
align  ::=  "<" | ">" | "^"
sign            ::=  "+" | "-"
width           ::=  digit+
precision       ::=  digit+
type            ::=  "i" | "d" | "o" | "x" | "X" | "e" | "E" | "f" | "F" | "g" | "G" | "s"

"!r" calls repr() to print.

The meaning of the various alignment options is as follows:

Option Meaning
'<' Forces the field to be left-aligned within the available space (this is the default for most objects).
'>' Forces the field to be right-aligned within the available space (this is the default for numbers).
'^' Forces the field to be centered within the available space.

The sign option is only valid for number types, and can be one of the following:

Option Meaning
'+' indicates that a sign should be used for both positive as well as negative numbers.
'-' indicates that a sign should be used only for negative numbers (this is the default behavior).

width is a decimal integer defining the minimum total field width, including any prefixes, separators, and other formatting characters. If not specified, then the field width will be determined by the content. Preceding the width field by a zero ('0') character enables zero-padding for numeric types.

The precision is a decimal integer indicating how many digits should be displayed after the decimal point for presentation types 'f' and 'F', or before and after the decimal point for presentation types 'g' or 'G'. For string presentation types the field indicates the maximum field size - in other words, how many characters will be used from the field content. The precision is ignored for integer presentation types.

The available types are:

Type Meaning
's' String format. Numbers is converted to the string ('g' or 'd') and precision is ignored.
'd', 'i' Decimal Integer. Outputs the number in base 10. String the 's' format is used instead.
'o' Octal format. Outputs the number in base 8. For float numbers and string the 'g' and 's' format is used instead.
'x', 'X' Hex format. Outputs the number in base 16.
'f', 'F' Fixed-point notation. For strings the 's' format is used and precision is ignored.
'e', 'E' Scientific notation.
'g', 'G' General format.

Select input/output encoding ('utf-8', 'cp1251' or 'cp866').

# Select encoding 
pcio.encoding('cp1251')

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

pcio-1.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

pcio-1.1.0-cp312-cp312-win_amd64.whl (16.2 kB view details)

Uploaded CPython 3.12 Windows x86-64

File details

Details for the file pcio-1.1.0.tar.gz.

File metadata

  • Download URL: pcio-1.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for pcio-1.1.0.tar.gz
Algorithm Hash digest
SHA256 55365b062116ddc00d97ece1f52dc9b9b736d996868d5a5a382e6b99962657dc
MD5 e4da944d2f2c0d6119d0f484c1ec539c
BLAKE2b-256 802090cd6791a148635c12cac9efc87c1577aa0aa30797044c011ceac43dfd0d

See more details on using hashes here.

File details

Details for the file pcio-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pcio-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for pcio-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1001ada6d2ed678cfe856c0fced8797e8e539398bad31dac2deabfacd7faf16e
MD5 22dc7d4624c3fe49592e4b7f58983ad0
BLAKE2b-256 1a1e0fe2420b8fe6343abcf90819f716a1ab4176e2ac3520a93ec7c1fdad345a

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