dflook / python-minifier

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

Dictionaries #20

Closed gabermohamed18 closed 3 years ago

gabermohamed18 commented 3 years ago

It has some problems with dictionaries

gabermohamed18 commented 3 years ago

More specifically, with functions that call dictionaries. The error:

Traceback (most recent call last): File "D:\Programming\Projects\project\minified_main.py", line 75, in <module> elif J in Z:i=Z[J];i() TypeError: 'str' object is not callable

dflook commented 3 years ago

Hello @gabermohamed18, can you give an example of the code before minifying?

gabermohamed18 commented 3 years ago

Hello @dflook

def lorem():
    print('lorem')

def ipsum():
    print('ipsum')

user_dict = {'lorem': lorem,  # without braces
             'ipsum': ipsum
             }

user_input = input('>> ').lower()

if user_input in user_dict.keys():
    output = user_dict[user_input]
    output()

This is the simplest way I can demonstrate my point, I know it's a weird way but in case of multiple functions I found it much shorter than putting an if statement for each function or input.

I apologize for late reply but it's kinda my first conversation on github.

gabermohamed18 commented 3 years ago

@dflook I don't know how but it is fixed and the code is running well, thank you for that great tool.

dflook commented 3 years ago

Glad it's working for you!