Python Forum

Full Version: do you have an idea to optimize this code[recursion]]?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)

 
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.
what is PEP20????
see: https://peps.python.org/ for all PEP's
and: https://peps.python.org/pep-0020/ for 20 The Zen of Python
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.