dflook / python-minifier

Transform Python source code into its most compact representation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dictionaries

gabermohamed18 opened this issue · comments

It has some problems with dictionaries

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

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

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.

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

Glad it's working for you!