dflook / python-minifier

Transform Python source code into its most compact representation
MIT License
583 stars 43 forks source link

Suggestion #25

Open tthn0 opened 3 years ago

tthn0 commented 3 years ago

This:

from pymongo import MongoClient

connection_str = 'connection_str'

cluster = MongoClient(connection_str)

database = cluster['db']

collection = database['col']

document = collection.find()

if document['_id'] == 123:
    print('ok')

By default turns into:

from pymongo import MongoClient as A
B='connection_str'
C=A(B)
D=C['db']
E=D['col']
F=E.find()
if F['_id']==123:print('ok')

But it could easily be more compact to save a few more bytes like so:

from pymongo import MongoClient as A
if A('connection_str')['db']['col'].find()['_id']==123:print('ok')

Also, please make an option to turn into a one-liner for all possible statements! (Separated by semicolons)

Edit to make my previous sentence clearer: although the output size wouldn't change, please add a "one-liner" option to separate statements by semicolons instead of newlines where possible

dflook commented 3 years ago

These are both good ideas!

Currently python-minifier prefers to use newlines where possible instead of semicolons for readability, but I can see how a one-liner would be more useful.

amaank404 commented 3 years ago

how about adding semicolons for the obfuscation, makes it harder for reverse engineering. this reduces the space further in indented blocks because semicolons reduce the requirement to indent in certain locations.

dflook commented 3 years ago

@xcodz-dot Semicolons are already used in indented blocks. Newlines would only be used at the module level, where it makes no difference to the output size.