Skip to main content

Lynie

An easy to use python to oneline-icator.

Support for atleast Python 3.8.7. Unsure for other versions.

Usage

Lynie only has one function that has to be called in order to turn a filename into a single line.

Import lynie, and call lynie.parse_file(filename). It will return the one line in the form of a string. With this string you can write it to a file. Here's a simple example of how you can use it (File: example.py):

import  lynie

filename = "oneline.py"
output_file = "example_output.py"

#Get the one line equivalent of the file
line = lynie.parse_file(filename)

#Write to output file
with  open(output_file,"w")  as  f:
	f.write(line)

Known problems

As of right now, there's a few things Lynie can't do.

  • With
  • Try except
  • While

With is a difficult thing to do as it's impossible to do in a single line. It also doesn't have a single line equivalent.

Try Except Is something that might be possible. However as of right now it's not in Lynie as it's syntax is uncompatible with list comprehensions.

While Is possible by using a recursive function. Though i haven't implemented it yet, it will come soon.


There's also a different problem that Lynie can do, however not perfectly. Starred function arguments is something that i've had problems with, but i haven't found a solution to. def some_function(*list_input, argument=False, argument2=True) Lynie will only be able to see *list_input and completely ignores argument and argument2. This is due to ast not seeing anything past the starred argument. However it will still see kwarg arguments. (*list_input, **kwargs) will work. So you can "Optimize" your code for Lynie to still take those arguments.

def some_func(*inp, output=False):
	if output:
		print(inp)

#Could become something like:

def some_func(*inp,**kwargs):
	#Put the default values in the data dict
	data = {"output":False}

	#Update data with kwargs. Overwriting the default one if 'output' is in kwargs.
	#But keeps the default value if it isn't defined
	data.update(kwargs)

	#Set `output` to the value in the dict
	output = data['output']

	#Rest of code
	if output:
		print(inp)

If you have any other problems, feel free to raise an issue on this github repo.

TODO

  • Change the way the imports work
  • add support for while loops
  • find a way to use try/except

What to use it for

Honestly, i wouldn't know. Though, judging by the fact that you've found this Repo, you already would have some use for it. May that be obfuscation, just for fun, or just to see if it was possible. You're here!

Why

I'm in a discord server where they have daily python challenges, and most people there try to make those challenges in as little code as possible. Or mainly try to do it within one line.

And while doing that, i suddenly realized you could pretty much make anything in one line. So i did some experimenting with it, by turning some of my functions of different modules into a single line. And succeeded with all of them.

Then i had the bright idea to make a module that turns other scripts into a single line. It was a very daunting first few hours. As i had no clue how i was going to even begin doing such a thing. As everything in python would need to be supported, in a way that everyone can use it, not only for my code.

Though, thankfully, my first try worked good. Good enough to have continued it to the point where it is now. There probably are better ways of doing this, however I'm proud enough of myself to have accomplished this to begin with. Maybe later I'll make a better version of it.

Change log

1.0:

Added:
	- Assignments
	- Functions
	- For loops
	- If / Else statements
	- f strings
	- function calls
	- imports
	- lambda functions

1.1:

Added:
	- Example file	
	- Comments

1.2:

Added:
	- Modulo operator

Changed:
	- Example files

1.3:

Added:
	- List comprehension support
	- Description for `parse_file` function.

Fixed:
	- Output for constants
	- Function argument parsing
	- If Else output being a string instead of code
	- Variable assign parsing
	- Function return parsing

1.3.5:

Added:
	- A testing script
	- Folder with scripts to test

Changed:
	- Made Lynie a PIP module
	- Made changes.txt have shorter version numbers
	- _get_args to be more readable

1.4

Added:
	- parse_string function

Metadata

Release files for lynie 1.0.4

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

Source distribution (sdist)

Source distribution for lynie 1.0.4
File Size Uploaded
lynie-1.0.4.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lynie 1.0.4
File Interpreter ABI Platform
lynie-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / lynie-1.0.4.tar.gz

Download URL lynie-1.0.4.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
32ec861e2913fb854b50c56e4d700ab5e1162e11960671c72a9e00c9c532a83e
BLAKE2b-256 checksum
How to use checksums
43676ea2e8260f136eaaa5ed3788c6c10b44ab0bb261072f798a00410e68abaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

Release files / lynie-1.0.4-py3-none-any.whl

Download URL lynie-1.0.4-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab9df24f219273ffa7e4e1ab5ade149b61f86756201287088f75943f1678b204
BLAKE2b-256 checksum
How to use checksums
1e3e582a819912c35bf7f908585b33e9e33cd37c6b759a0e7f43779c0e074917
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

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