Skip to main content

An easy to use python oneline-icator.

Project description

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

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

lynie-1.0.4.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

lynie-1.0.4-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file lynie-1.0.4.tar.gz.

File metadata

  • Download URL: lynie-1.0.4.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for lynie-1.0.4.tar.gz
Algorithm Hash digest
SHA256 32ec861e2913fb854b50c56e4d700ab5e1162e11960671c72a9e00c9c532a83e
MD5 fbaed465133ac2ec4c2bdc0f9b292bd5
BLAKE2b-256 43676ea2e8260f136eaaa5ed3788c6c10b44ab0bb261072f798a00410e68abaf

See more details on using hashes here.

File details

Details for the file lynie-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: lynie-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for lynie-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ab9df24f219273ffa7e4e1ab5ade149b61f86756201287088f75943f1678b204
MD5 81faadf06e1d0f5f7a20361935ecb151
BLAKE2b-256 1e3e582a819912c35bf7f908585b33e9e33cd37c6b759a0e7f43779c0e074917

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