Skip to main content
# Overview

PyScanner is a Java-like input scanner.

This is very useful for reading input for programming contests such as ACM ICPC, Topcoder, Google Code Jam, and Facebook Hacker Cup.

# Installation

easy_install PyScanner

And then in your python3 module include:

from scanner import Scanner

# Examples

The following example allows to read a float from stdin:
```python
# Input:
# 3 0.5
sc = Scanner()
x = sc.next_int()
y = sc.next_float()
type(x) is int # True
type(y) is float # True
x + y # 3.5
```

The following code allows to read until EOF and obtain int types:
```python
# Assume input is:
# 10 20 30
# 40 50 60
sc = Scanner()
sum = 0
while sc.has_next():
sum += sc.next_int()
sum # 210
```

The default input stream is sys.stdin. However, it is possible to read from a file or even a string:
```python
sc = Scanner(file='data.txt')
# do stuff
sc.close()
```

```python
sc = Scanner(source='some string to use as input')
```

The scanner can also use string delimeters other than whitespace.
```python
sc = Scanner(delim=',')
```

By default, the scanner does a str split. If forced, a regex pattern can also be used. As expected, the latter method is slower:
```python
content = '1 fish 2.5 fish red fish blue fish
sc = Scanner(source=content, delim='\S*fish\S*', force_regex=True)
sc.next_int() # 1
sc.has_next() # True
sc.next_float() # 2.5
sc.next() # red
sc.next() # blue
sc.has_next() # False
```

# Usage
TODO: example using the Scanner vs. standard Python way.

# License

[THE BEER-WARE LICENSE](https://tldrlegal.com/license/beerware-license)

Metadata

Release files for PyScanner 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for PyScanner 1.0.3
File Interpreter ABI Platform Actions
PyScanner-1.0.3-py3.3.egg Legacy Egg format - - Details for PyScanner-1.0.3-py3.3.egg

Release files / PyScanner-1.0.3-py3.3.egg

Download URL PyScanner-1.0.3-py3.3.egg
Size 5.8 kB
Tags Egg
SHA-256 checksum
How to use checksums
bde3555225c4a12fc22885cb5d65a4eea82ef1be0307a70aef799371fcb6d890
BLAKE2b-256 checksum
How to use checksums
ee50446a75033832e5d3a3bbc2f20a4fea3cc3de1da5965677563aa440dfe81f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for PyScanner 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page