Python Forum
do you have an idea to optimize this code[recursion]]? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: do you have an idea to optimize this code[recursion]]? (/thread-37258.html)



do you have an idea to optimize this code[recursion]]? - netanelst - May-19-2022

class y():
    

    def __init__(self, id, d="", indicator="",type="",deleted=False,published_date=0,last_updated=0,reports=[],actors=[],
    malware_families=[''],kill_chains=[''],ip_address_types=[],domain_types=[],malicious_confidence='',labels=[l('',time.time(),time.time())],relations=[]):
        self.id=id
        self.indicator=indicator
        self.type=type
        self.deleted=deleted
        self.published_date=datetime.datetime.fromtimestamp(published_date).strftime("%b %d %Y %H:%M:%S")
        self.last_updated=datetime.datetime.fromtimestamp(last_updated).strftime("%b %d %Y %H:%M:%S")
        self.reports=reports
        self.actors=actors
       # self.recursive_indicator=recursive_indicator()
        self.relations=relations
        self.d=y.recursive_indic6ator(self.relations)
        ix=0
        self.relations=y(y.recursive_indic6ator(indicator))
    def c2(ix,l={}):
        s=y.recursive_indic6ator(l)
        ix=ix+5
        if(ix<55):
            return s
    def recursive_indic6ator(i={},ix=20):
        ix=ix+5
        if(ix<55):
                    return y(i)

 



RE: do you have an idea to optimize this code[recursion]]? - jefsummers - May-19-2022

It's pretty unreadable. Variables and functions should have names that reflect what they are to represent. To quote Pep 8,
Quote:One of Guido’s key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, “Readability counts”.

So really can't help, have no idea what this is supposed to do. Make it readable and you will have more responses.


RE: do you have an idea to optimize this code[recursion]]? - netanelst - May-20-2022

what is PEP20????


RE: do you have an idea to optimize this code[recursion]]? - Larz60+ - May-20-2022

see: https://peps.python.org/ for all PEP's
and: https://peps.python.org/pep-0020/ for 20 The Zen of Python


RE: do you have an idea to optimize this code[recursion]]? - jefsummers - May-20-2022

I get it.
PEPs are Python Enhancement Proposals, but they are much more than that. Certain PEPs have become the standard of Python programming, such as PEP 8, the Style Guide for Python Code (co-written by Guido VonRossum, the "inventor" of Python). PEP 8 therefore is definitely worth spending a few minutes reading and understanding what are the standards for Python programming style. PEP 20 is titled The Zen of Python and is almost Haiku like, going into more depth about style and preferences and is really quick read, but worth it to get some of the thoughts behind Python development.

There are over 3000 PEPs (at least if you go by numbers). So, would spend the time, brief though it may take, to review the ones to which you are referred (8, 20, etc), and then any that look interesting.