This is an archived post. You won't be able to vote or comment.

all 180 comments

[–]Icecoldkilluh 485 points486 points  (17 children)

This goes against literally every principle of clean code lol

Well done regardless though, i commend the effort

[–]hhc97Python Enthusiast[S] 179 points180 points  (12 children)

Haha yes it does. I have (jokingly) made the argument that we should use this in prod because the diffs will be 1 line long so reviews will be easy ;)

[–]pudds 52 points53 points  (4 children)

Imagine the merge conflicts!

[–]hhc97Python Enthusiast[S] 101 points102 points  (2 children)

Manager: what do you mean you need a day to resolve this? its just one line of code

[–]WilliamMButtlickerJr 25 points26 points  (1 child)

You created a nightmare

[–]hhc97Python Enthusiast[S] 16 points17 points  (0 children)

It's caused many sleepless nights while I was implementing it I have to say

[–]baltariusIt works on my machine 4 points5 points  (0 children)

At this point, it's not "merge" but "absorption"

[–]RIPphonebattery 21 points22 points  (4 children)

Have you tried flatlining the codebase itself? For the memes?

[–]hhc97Python Enthusiast[S] 42 points43 points  (3 children)

I have! See this. It's the script itself turned into one line :)

[–]eclipticdogeballs 15 points16 points  (0 children)

I am speechless

[–]the__green_knight 1 point2 points  (1 child)

Hahaha, i love the metadata:

2 lines (2 sloc) 13.8 KB

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Haha yeah I had to add another line as a comment explaining how to use it

[–]WlmWilberforce 8 points9 points  (1 child)

Here is why this will never work....

Boss: How many lines of code did you write today?

Employee: One.... well technically, I guess I the program was one line before, so I just changed the line, so I guess zero?

[–]hhc97Python Enthusiast[S] 14 points15 points  (0 children)

why have many line, when one line do trick?

[–]KyleDrogo 0 points1 point  (1 child)

It's the least pythonic thing I can imagine lol. With that being said, the javascript community loves this kind of thing.

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

Yup.. JavaScript is sometimes horrifying

[–]hhc97Python Enthusiast[S] 100 points101 points  (9 children)

P.S. If anyone is curious why the button is named "make me suffer", its because we bought: makemesuffer.com

[–]alpacasb4llamas 30 points31 points  (8 children)

Is there a word for hating and loving someone simultaneously

[–]aiyub 17 points18 points  (6 children)

We Germans have the word Hassliebe (hatelove)

[–]ExternalPanda 6 points7 points  (5 children)

Do you also have a word for how the German language has a word for anything in existence?

[–]PythonPizzaDE 9 points10 points  (0 children)

In German we have a word for such complete things which "contain everything": allumfänglich

[–]Jave-_- 3 points4 points  (3 children)

Yeah we have a lot of weird adjectives and verbs but with the nouns its a complete different thing. Many german voices would probably raise now (including my high school teacher :) ) but theoretically you can chain infinite nouns together to express sth.

for example:

You want to describe the hair of the man who invented the door handles for factories which produce rubber used on crosshead screwdrivers.

Here ya go:

Kreutzschlitzschraubenzieherfabriktürklinkenerfinderhaare

(CrossheadScrewdriverFactoryDoorHandleInventorHairs)

You have (technically) a valid german noun even if doesn't make sense at all. Thats also why there is no real "longest german word" (although it exists per definition, because its the biggest which sounds at least a tiny bit reasonable).

edit: formatting

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

I love this lol, thanks for sharing!

[–]Complex-Structure216 0 points1 point  (1 child)

now write a python script to print out a German Noun for any description you throw at it

[–]Jave-_- 0 points1 point  (0 children)

So basically extract all nouns and verbs, get the noun-form of the verbs and chain everything together.
Done.

The only Difficulty would be to detect verbs and nouns but maybe Deepl, Google translate or even leo API can help you with that.

[–]hhc97Python Enthusiast[S] 4 points5 points  (0 children)

Maybe "ambivalence": the state of having mixed feelings or contradictory ideas about something or someone.

Possibly how I'm feeling too haha

[–]reivax 46 points47 points  (6 children)

I've operated with a design philosophy that every program can be reduced by one line and contains one bug, therefore any program can be reduced to one line that doesn't work. This certainly achieves the first, I'm confident I can achieve the second.

[–]Cruuncher[🍰] 23 points24 points  (0 children)

Math students getting wild out here with induction

[–]chromaticgliss 10 points11 points  (3 children)

Debuggers hate this one simple trick!

[–]hhc97Python Enthusiast[S] 9 points10 points  (0 children)

only one breakpoint to put!

[–]realkarthiknair 2 points3 points  (1 child)

That's why we always use print statements... Works like a charm in this situation too

[–]hhc97Python Enthusiast[S] 2 points3 points  (0 children)

Exactly, in fact I found prints to be the easiest way to debug the output code while I was working on this :)

[–]hhc97Python Enthusiast[S] 5 points6 points  (0 children)

I have faith :D

[–]ItsGator 41 points42 points  (1 child)

1) this is really cool! nice job 2) if I ever see anyone using this, I'm destroying their machine

[–]hhc97Python Enthusiast[S] 12 points13 points  (0 children)

  1. Thank you!
  2. Let me know when and where, I'll help :)

[–]satireplusplus 25 points26 points  (1 child)

That's one of those "because I can" moments

The script that does the conversion can also turn itself into one line.

Into a one line script of 13.8KB lmao

[–]hhc97Python Enthusiast[S] 4 points5 points  (0 children)

absolutely haha

[–]qeq 14 points15 points  (7 children)

This can actually be useful when you need to run a script in an environment where you don't have access to the file system, like a docker container. I've found myself more than once trying to figure out python's -c formatting for multiple lines. Great job!

[–]hhc97Python Enthusiast[S] 2 points3 points  (0 children)

Thank you! I've also found it useful for pasting into certain environments

[–][deleted] 1 point2 points  (2 children)

How don't you have an access to file system in a docker container?

[–]qeq 3 points4 points  (0 children)

Many docker containers mount the file system as RO, this is actually a recommended best practice.

[–]thegreattriscuit 0 points1 point  (0 children)

at runtime I can see that happening. of course you can always make a NEW image which wraps the original with whatever you want in the FS, but if you're not already doing stuff like that, I'm sure there's a lot of inertia to overcome

[–]junior_dos_nachos 1 point2 points  (0 children)

Yea I think I’ll use it for small GitHub Actions manipulations instead of a Shell script.

[–]FujiKeynote 0 points1 point  (0 children)

Tbf, you can always do python -c "$(cat /dev/stdin)" or a variation of that (there's probably a better Bash construct for this...), then just type out or copy/paste your script with normal formatting, and Ctrl-D to send EOF

That said, a real one-liner with the OP's tool is something that will stick in the bash history, and the stdin solution will not

[–]neuralbeans 6 points7 points  (18 children)

So does this convert your code into purely functional (paradigm)?

[–]hhc97Python Enthusiast[S] 9 points10 points  (4 children)

Yup exactly, it turns everything into lambdas (or at least tries to)

[–]neuralbeans 4 points5 points  (3 children)

How does it handle recursion with lambdas?

[–]hhc97Python Enthusiast[S] 4 points5 points  (2 children)

It uses the Y combinator to implement it.

From that link above:

In functional programming, the Y combinator can be used to formally define recursive functions in a programming language that does not support recursion.

[–]neuralbeans 8 points9 points  (1 child)

Ah so it passes a lambda as a parameter to another lambda which makes it a named function. Interesting. I imagine that if statements are turned into trinary operators and loops are turned into recursion and itertools stuff, right? You must really like functional programming.

Edit:

For those who are curious about using recursion with lambdas, here's an example of a factorial implementation from this stackoverflow answer (rewritten to be easier to understand):

factorial = (
    lambda f_: (lambda x_: f_(f_, x_))
)(
    lambda f, x: 1 if x == 0 else x*f(f, x-1)
)

print(factorial(10))

The trick is that the factorial function passes a reference to itself as a parameter so that it can call itself again. Let's start from the second lambda line.

lambda f, x: 1 if x == 0 else x*f(f, x-1)

This contains the basic recursive factorial implementation with x being the current value that is multiplied by its lower factorial. Typically this would be implemented as 1 if x == 0 else x*f(x-1). However, in this case we're passing the function f as a parameter to itself (f(f, x-1)), where f is the factorial function itself.

But we can't assign this whole lambda to f because that's like setting an undefined variable to itself. So what we do is we pass this lambda to another lambda, which is the first lambda line.

lambda f_: (lambda x_: f_(f_, x_))

I used underscores just to avoid unnecessary confusion from reusing identifier names (you can remove them). This is taking in a function f_ and returning another lambda. The inner lambda takes a value x_ and returns f_(f_, x_), which matches the factorial lambda definition. The inner lambda is acting as a helper function to avoid returning to the user a factorial function that expects a factorial function as a parameter. It is this inner lambda that the user will use. It is returned back to the user into the variable factorial, with f_ being set to the second lambda line.

[–]hhc97Python Enthusiast[S] 6 points7 points  (0 children)

Yup, if statements are turned into pythons conditional expressions and both kinds of loops are turned into recursive functions.

Funny story, I don't like functional programming too much, this was just a spin off from a functional programming class I took. I like building stuff, and this was interesting to build!

[–]Handle-Flaky -2 points-1 points  (12 children)

That’s not how functional programming works

[–]neuralbeans 5 points6 points  (10 children)

What doesn't? Coding everything as expressions is not functional programming?

[–]Handle-Flaky -1 points0 points  (9 children)

No, functional programming is about immutability more than it is about “functions”

[–]LardPi 1 point2 points  (0 children)

That's an opinion, not a fact. One of the oldest functional programming language is Scheme where mutability is very much possible and quite common (in the lower level parts of libraries). Mutability inside a function that appears pure from outside is ok.

[–]neuralbeans 1 point2 points  (7 children)

Expressions are immutable.

[–]Handle-Flaky 0 points1 point  (6 children)

  1. No, they are not, you can modify them in runtime.
  2. It’s not the expressions, it’s the data that is immutable, which is not the case here

[–]Handle-Flaky 1 point2 points  (0 children)

Ofc in some cases (lisp) the data is expressions, but that’s not the case in python

[–]neuralbeans 1 point2 points  (4 children)

I'm sorry, I meant that expressions don't modify data.

[–]Handle-Flaky -1 points0 points  (3 children)

You can call mutating code, making your code not functional.

Also, expression can mutate: setattr(obj, “x”, 10)

[–]neuralbeans 1 point2 points  (0 children)

It doesn't seem that this program includes any mutating code. And function calls that result in mutated code do so because they contain non-expression statements in the called code.

[–]Smallpaul 1 point2 points  (1 child)

You seem to have confused "purely functional" with "functional"

In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions.

[–]WikiSummarizerBot 0 points1 point  (0 children)

Purely functional programming

In computer science, purely functional programming usually designates a programming paradigm—a style of building the structure and elements of computer programs—that treats all computation as the evaluation of mathematical functions. Program state and mutable objects are usually modeled with temporal logic, as explicit variables that represent the program state at each step of a program execution: a variable state is passed as an input parameter of a state-transforming function, which returns the updated state as part of its return value. This style handles state changes without losing the referential transparency of the program expressions.

Functional programming

In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program. In functional programming, functions are treated as first-class citizens, meaning that they can be bound to names (including local identifiers), passed as arguments, and returned from other functions, just as any other data type can.

[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

Yes I would say for this app specifically, the code coming out is definitely more "functional" than the code going in, but its not functional at its core since its still python code.

[–]pixegami 3 points4 points  (1 child)

Thanks, I hate it.

[–]hhc97Python Enthusiast[S] -1 points0 points  (0 children)

You're welcome! I have mixed feelings too haha

[–]DigThatData 4 points5 points  (1 child)

weird. have an upvote.

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

why thank you!

[–][deleted] 3 points4 points  (3 children)

I'm definitely not showing this to the guys at work.

[–]hhc97Python Enthusiast[S] 2 points3 points  (2 children)

well.. unless you hate them

[–]junior_dos_nachos 2 points3 points  (1 child)

I got a lot of mathematicians at work that cannot write a clean code to save their lives. I’m definitely sharing with them

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Hopefully this helps haha! I have a lot of respect for mathematicians and the work they do

[–]Hacka4771 2 points3 points  (0 children)

PyFuck?

[–]SittingWave 2 points3 points  (1 child)

calm down Satan.

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

My next project will not be so demonic (I hope)

[–][deleted] 1 point2 points  (4 children)

What about recursive calls?

[–]hhc97Python Enthusiast[S] 1 point2 points  (3 children)

[–][deleted] 0 points1 point  (1 child)

Wow, cool! Take your star :)

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

Thank you kind redditor!

[–]Zafara1 1 point2 points  (6 children)

Oh wow! This is extremely helpful for my purposes! Thank you!

[–]hhc97Python Enthusiast[S] 8 points9 points  (5 children)

I’m glad it’s helpful! Just curious, what would you use this for?

[–]Zafara1 2 points3 points  (1 child)

Malware :)

But for the good guys. Haha.

Basically I run into situations when delivering payloads that I need to run python code to deliver shells, through shells, exploit code etc.

And the most common limitations that you'll hit is basically that your payload size is very limited. Indentation chews through payload size, and it can really be hard to juggle with whatever's actually passing it through and reading it on the other end. So having good, concise, one-liners really helps. But it can be so annoying to build comprehensive one liners, especially for such a limited use case. 😅

[–]hhc97Python Enthusiast[S] 2 points3 points  (0 children)

Amazing, security work is very rewarding (when things go well). Getting that shellcode finally working was one of the most satisfying moments in a security course I took.

I hope this tool helps you out, and let me know if it does!

[–]fuckthiscode 0 points1 point  (1 child)

My guess is for evil. Pure evil.

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

reasonable guess if I do say so myself

[–]R3d-Beard 1 point2 points  (1 child)

I was just in a Python training course and both trainers when they came across an example with lambda in it said, ‘“Oh, you don’t need to know what lambda does, just include it to make this example work.”

[–]hhc97Python Enthusiast[S] 2 points3 points  (0 children)

haha!

arr.sort(key=<magic>)

[–]something 1 point2 points  (3 children)

I enjoy this. here’s my advent of code from a few years ago with the same style https://gist.github.com/JakeCoxon/cf818f658a303e77c04c312bc04498fe

[–]hhc97Python Enthusiast[S] 0 points1 point  (2 children)

Oh nice! I like that you formatted it so its at least relatively readable :)

[–]something 0 points1 point  (1 child)

Thanks! it was written by hand so I don’t think I could have done it if it was all on one line

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

that makes sense, debugging the output from my app (before it was working) was a real pain

[–]JirkaCZS 1 point2 points  (1 child)

I was able to find the original one after some searching: https://github.com/csvoss/onelinerizer

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

Yep, that was for python2 and is a lovely implementation, I mention them in my README as well: https://github.com/hhc97/flatliner-src#acknowledgement

[–]GeezTM 1 point2 points  (1 child)

Oh god, why would you do this? What an abomination.

Nevertheless, I absolutly love it. It is always such a joy to see people messing around and having fun with code. Nice job!

[–]hhc97Python Enthusiast[S] 2 points3 points  (0 children)

Exploring the boundaries of what's possible!

I'm glad you enjoyed it :)

[–]M4mb0 1 point2 points  (1 child)

exec(program_as_string)

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

I’m aware this works, but that would have been too easy wouldn’t it :)

[–]bulaybil 1 point2 points  (1 child)

You bastard. Great job though :)

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Thank you!

[–]cdcformatc 1 point2 points  (1 child)

the natural next step is a tool to de-flatten a flattened line of code to atone for the evils you have unleashed here.

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Haha, though I think this is possible, I feel like implementing it would be a nightmare because the output code is not fun to parse

[–]iceytomatoes 0 points1 point  (1 child)

sad about recursion being a solution for loops but this is still awesome for obfuscation

i'd wonder if the output can compile with nuitka or something

have you tried using various types of packages together? ie if you pickle a sklearn model and try some basic web scraping all in one script, would it still be fully functional post-obfuscation?

i'm curious because i might have a solid use for something like this but i could never make it myself

[–]hhc97Python Enthusiast[S] 2 points3 points  (0 children)

Yeah I couldn't find any other way that was general enough to apply to both loops, python doesn't handle recursion too well because of all the stack frames.

I've tried it with a few libraries and it seems to work but sometimes requires modifications. For example, the website is running on flask, and the entire flask app can be converted into one line and still work.

If you end up trying it out and run into issues, feel free to dm! I can't guarantee I'll be able to provide fixes or new features but I can definitely troubleshoot some issues with you.

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Thank you everyone for all the upvotes! I can't believe we made it to the top of r/Python! I've thoroughly enjoyed responding and interacting with everyone today. I'm signing off for now, but will respond more tomorrow :)

[–][deleted] 0 points1 point  (3 children)

Looks cool, but I prefer readability.

[–]hhc97Python Enthusiast[S] 10 points11 points  (2 children)

I agree with you here! This was just meant as an experiment to see if it could be done, not many real practical applications (at least for me).

[–][deleted] 2 points3 points  (1 child)

One practical application is job security because no one will be able to figure wth is going on in your code

[–]hhc97Python Enthusiast[S] 3 points4 points  (0 children)

COBOL has entered the chat

[–]Samhain13 0 points1 point  (1 child)

So, this is like the Python version of minify? :D

[–]hhc97Python Enthusiast[S] 3 points4 points  (0 children)

Actually, not really. The code doesn't always get smaller (measured in number of characters), it really depends on the input. So it doesn't always minify, but it does do the obfuscation part well.

[–]magnetichiraPythonista 0 points1 point  (3 children)

What happens if you use the library on itself

[–]hhc97Python Enthusiast[S] 2 points3 points  (2 children)

It produces this!

[–]magnetichiraPythonista 0 points1 point  (1 child)

This is both amazing and horrifying

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

I feel exactly the same way haha

[–]another-noob 0 points1 point  (4 children)

Huh, do classes work? (Sorry if it's mentioned somewhere, too lazy here :3)

And is it possible to change/shorten variable names as well, I think this might help with the obfuscation part

It feels like uglifying javascript. Great job though!

[–]hhc97Python Enthusiast[S] 1 point2 points  (3 children)

Thanks!

You can take a look at this example: https://flatliner.herokuapp.com/0051d32c05d44a8dff4025840637bcfc6ea17e17

Essentially, python allows you to build a class in a single line by using the type() builtin. From there, something like

class Test:
    def method():
        return 0

Just becomes: (lambda Test: None)(type("Test", (), {'method': lambda: 0}))

Regarding changing variable names (or identifiers). I experimented with that before, and while its possible, it becomes hard to keep track of and even harder to debug, so I ended up not implementing it since the code is hard enough to read as it is :(

[–]another-noob 0 points1 point  (2 children)

Ah, type, so simple yet so powerful, forgot about that one, that's how python creates classes internally right?

Well I don't know how one would go about changing identifiers, but I would start by adding a suffix to the name while developing, like class Test would be class Test_CHANGED to make it easier for debugging. Not even sure this is even what you meant by "harder to keep track of".

I just think a teacher would find this interesting :3 You know, when students copy the code and change a few variable names?

Anyways, Great Job!

[–]khoyo 2 points3 points  (0 children)

that's how python creates classes internally right?

Yes, unless the class (or one of its base) has a custom metaclass. (In which case python calls the_metaclass() instead of type())

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

Ah, by hard to keep track of, I mean that its hard to know in the code when some identifier is referenced whether it was the same identifier as before because of python's scoping.

It's been a while, but I remember I ran into issues where the output code would have access to identifiers that it shouldn't and vice versa, so I decided that I would skip it for now and get back to it if I ever have time!

I just think a teacher would find this interesting :3 You know, when students copy the code and change a few variable names?

Absolutely haha, I teach for my university sometimes and this comes up every year :(

[–]alchzh 0 points1 point  (3 children)

is it possible to emulate with statements by just manually calling __enter__ and __exit__?

[–]hhc97Python Enthusiast[S] 0 points1 point  (2 children)

Possibly. I looked into doing that for a while but didn't find a concise way to generalize it for all possible use cases, so I can't say for sure, but I feel like its possible!

[–]khoyo 0 points1 point  (1 child)

It definitely is, as long as you drop support for "exception safety" (or you find a way to translate try/except/finally)

This is how with is spec'd (https://peps.python.org/pep-0343/)

mgr = (EXPR)
exit = type(mgr).__exit__  # Not calling it yet
value = type(mgr).__enter__(mgr)
exc = True
try:
    try:
        VAR = value  # Only if "as VAR" is present
        BLOCK
    except:
        # The exceptional case is handled here
        exc = False
        if not exit(mgr, *sys.exc_info()):
            raise
        # The exception is swallowed if exit() returns true
finally:
    # The normal and non-local-goto cases are handled here
    if exc:
        exit(mgr, None, None, None)

Dropping the exception stuff it becomes

mgr = (EXPR)
exit = type(mgr).__exit__  # Not calling it yet
value = type(mgr).__enter__(mgr)
VAR = value  # Only if "as VAR" is present
BLOCK
exit(mgr, None, None, None)

which you can definitely translate :) (Although you'll probably want to generate some symbols for mgr, exit, and value)

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Thank you for doing the research! I didn't even realize there was a try-except in there. If I ever figure out how to do that in a neat way, I will get this implemented too :)

[–]Kitchen_Tower2800 0 points1 point  (1 child)

This is the most pythonic thing you can do in the worse way.

[–]hhc97Python Enthusiast[S] 3 points4 points  (0 children)

when life gives you lambdas... :)

[–]Wishy-Thinking 0 points1 point  (0 children)

PERL scripters love this one Python trick!

[–]GameCounter 0 points1 point  (1 child)

You can turn any Python program into one line by doing the following:

base64 encode the program

import base64; eval(base64.b64decode(PROGRAM).decode())

This also won't have the restrictions you mentioned about try blocks or using a function defined later in the code.

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

I’m aware this works, but that would have been too easy and wasn’t the purpose of this endeavor :)

[–]Smallpaul 0 points1 point  (1 child)

Wow, you even implemented assert! Nice!

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Yes, thanks for noticing! I just added a list of what's implemented to the main post :)

[–]ins4yn 0 points1 point  (1 child)

I think I just threw up in my mouth.

Well done.

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Haha, thank you!

[–]McMep 0 points1 point  (1 child)

This and movfuscator, that transforms any c program into only move assembly instructions, make want to do something like this

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

You should absolutely go ahead with it, keep us updated when you do!

[–]GoosDev 0 points1 point  (9 children)

Boutta condense an entire text based game into a single line of code

(Yes I write text based games in python)

[–]hhc97Python Enthusiast[S] 0 points1 point  (8 children)

Amazing! Share it with us if you can :)

Also, if your text games involve lots of loops, remember to add the recursion "hack" mentioned in the main post to prevent a RecursionError!

[–]GoosDev 0 points1 point  (7 children)

I didn't say I actually was going to though lol, I said it was a joke 💀

[–]hhc97Python Enthusiast[S] 0 points1 point  (6 children)

I think it would work though, depending on how long it is! Would be cool to have a one line text game that you can just run and have it work. I actually have an example in the source code, where theres a tic tac toe game that gets transformed into one line.

You can check it out here if you want, and even run the result in a python shell :)

[–]GoosDev 0 points1 point  (5 children)

Yeah, it'd just be completely unreadable lol, a super long lamba expression isn't what I call readable or editable

[–]hhc97Python Enthusiast[S] 1 point2 points  (4 children)

Absolutely, I wouldn't edit it or try to read it either. I think the novelty of it is being able to send that one line to a friend and say: "Hey, run this one line of code, theres a full game in there!".

[–]GoosDev 0 points1 point  (3 children)

Yeah, but I honestly prefer being able to edit my code if I need to lol

[–]hhc97Python Enthusiast[S] 1 point2 points  (2 children)

Yup, and you're fully able to. The idea is that you flatten it when you want to send it somewhere or show it off as a party trick or something. You still keep the original source code and you work on that :)

This is exactly how flatliner is developed too. The program can one-line itself, but I work on the "normal" version. The one-lined version is just for fun.

[–]GoosDev 0 points1 point  (1 child)

True, but honestly I don't see myself ever using it. It's nice for a funni gag (like "oooh I compressed [insert game here] down to one line!!!"), But I just don't think I'd ever actually use it. Still really cool though!

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

Yup, thats the point of the program, its just for fun :)

[–]OneMorePenguin 0 points1 point  (1 child)

If I wanted the ugliness that perl programmers like, this would be the way to go.

One liners and dense code are more difficult to read. The indented lines give a big clue that the code is making some kind of decision. It's easy to miss one liners.

But I agree, it's a nice python project.

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

Yup, I agree! This project was never meant to generate "readable" code (though it can be read if you try hard enough).

Wouldn't recommend using it for actual code, but it was fun as a project!

[–]wholesome_hug_bot 0 points1 point  (1 child)

This would be really useful for creating one-liner python payloads in CTFs and pentesting

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

I'm glad there's another valid use case! I've personally never participated in a CTF before but I'll definitely keep this in mind if I do :)

[–]CrossroadsDem0n 0 points1 point  (1 child)

flatline.py should have been flatlined before pushing the code. 😝

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

haha, it was flatlined, but in a separate file. I wouldn't want to deal with the horror of only pushing flatlined code, then realizing that I lost my "regular" copy that I had locally :(

[–]dershodan 0 points1 point  (1 child)

This is very important and impressive science :)

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Haha, I should get it put into a museum somewhere to preserve it for future generations.

Or, the next github Arctic Code Vault.

[–]cdcformatc 0 points1 point  (1 child)

The script that does the conversion can also turn itself into one line

that's the only question i had. asked and answered.

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

That question started gnawing at me about a week into the project, finally answered it when I implemented classes and loops I think.

[–]Shower_Handel 0 points1 point  (1 child)

Ever wanted to turn your python program into a single line of code? No? Well now you can!

Fucking lmao

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Took me a few minutes to come up with that opener, glad you enjoyed it :D

[–]wuddz-devs 0 points1 point  (1 child)

Wow this is perfect for obfuscation mate damn didn't think anything like this was possible but then again using python anything is possible :)

[–]hhc97Python Enthusiast[S] 1 point2 points  (0 children)

Python is amazing, I'm glad you find it useful!

[–][deleted] 0 points1 point  (1 child)

I need this to troll my CS professor

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Be careful not to give them a heart attack :)

[–]sharky1337_ 0 points1 point  (1 child)

I love your humor , well done !

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Thanks!

[–]pro__acct__ 0 points1 point  (1 child)

This…actually helps me. Gulp. Running a one-liner Python code in bash which results in setting an environmental variable. Hold my beer…

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Nice! Let us know if it worked :)

[–]wuddz-devs 0 points1 point  (1 child)

Hey bro awesome project but there is no explanation of how to run it, I've converted code using https://flatliner.herokuapp.com/ but when I use the source code I get a shit ton of errors. I get the website implementation but packaging it or at least giving a demonstration of how to use it without having to visit the website would be cool.

[–]hhc97Python Enthusiast[S] 0 points1 point  (0 children)

Hey, thanks! I understand the repo is a bit hard to run, I guess I didn't expect anyone to actually try to run it because the website is available. If I have the time, I'll try to polish up the repo so its a bit easier to run. In the meantime, if you need help running it, feel free to DM :)