Skip to main content

Convert python script into python one-liner

Project description

One-Liner Generator for Python

A simple script that converts python scripts into one-liner.

Install

pip install OLG4P

Usage

python3 -m oneliner [input file] -o [output file]
Or use python3 -m oneliner -h for help.

Example

InputFile:

import random
y,h=0,2
msg='hello_world'
while y<h*2:
    for x in range(len(msg)+2):
        print(random.choice('/\\'),end='')
    y+=1
    if y==h:
        print('\n %s '%msg)
    else:
        print('')

Generated:

[(itertools := __import__('itertools')), (random := __import__('random')), [(__ol_assign_tmp_nxazjlgisn := (0, 2)), (y := __ol_assign_tmp_nxazjlgisn[0]), (h := __ol_assign_tmp_nxazjlgisn[1])], (msg := 'hello_world'), [[[print(random.choice('/\\'), end='') for x in range(len(msg) + 2)], y.__iadd__(1) if hasattr(y, '__iadd__') else (y := (y + 1)), print('\n %s ' % msg) if y == h else print('')] for _ in itertools.takewhile(lambda _: y < h * 2, itertools.count())]]

Limitation

This script requires python3.9+. Many statements are not convertable.
Here are the statements that have already been implemented.

statement example
Expr print((1+1)*2)
Assign a=1
a,b=b,a
AugAssign a*=1
If if a==0: ...
elif a>1: ...
else: ...
For for i in range(10): ...
else: ...
While while a<100: ...
else: ...
Break break
Continue continue
Pass while 1: pass
Import 1 import math
import os,sys
import numpy as np
FunctionDef def func(a,*args): ...
Return return None

Remarks:

  1. 'from-import' is not implmented.

Dependencies

  • CPython >= 3.9

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

OLG4P-0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file OLG4P-0.1-py3-none-any.whl.

File metadata

  • Download URL: OLG4P-0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for OLG4P-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a67d3c39cdef74cb69ab3b1c970d3bfa06a1dc5fa3b764a049a1e3ef54b2fe91
MD5 0cb9b3f017fefc2d1a5baf0b0528f2c6
BLAKE2b-256 784411db54245fd77f74d09e36c8559d835ea43c0bd00653d8436f3ed5caec65

See more details on using hashes here.

Supported by

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