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.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

pcio-1.1.1-cp313-cp313-win_amd64.whl (16.3 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

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

File metadata

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

File hashes

Hashes for pcio-1.1.1.tar.gz
Algorithm Hash digest
SHA256 78d528885cfe12d66d6ae4b4ce5179d4fbf8bcfd2b34396aaf3bc5f2310f16da
MD5 e571b53e9279f94f61277789d9cebb84
BLAKE2b-256 c694341618155a59d81d7ff93ad5446fc5d835bfb6418b44aa5df31a2ae7e625

See more details on using hashes here.

File details

Details for the file pcio-1.1.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pcio-1.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for pcio-1.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d03c0b641a6ea80e802985c22d7867b58560efd8566b24cb9f7ebc1f4e438f95
MD5 47401c050f3a1ca1a4b2b53efd179391
BLAKE2b-256 013fcd2531b8d85575619b06bbfb718d5f50ea2df6a5fccfff121433d0d6752a

See more details on using hashes here.

Supported by

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