Python Forum
do you have an idea to optimize this code[recursion]]?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
do you have an idea to optimize this code[recursion]]?
#1
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)

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I multithread to optimize a groupby task: davisc4468 0 674 Jun-30-2023, 02:45 PM
Last Post: davisc4468
  do you have an idea for optimizing this code? netanelst 3 1,309 May-22-2022, 10:30 AM
Last Post: snippsat
  Optimization using scipy.optimize KaneBilliot 3 1,867 Nov-30-2021, 08:03 AM
Last Post: Gribouillis
  Using curve_fit to optimize function (TypeError) Laplace12 4 2,453 Aug-30-2021, 11:15 AM
Last Post: Larz60+
  is there a way to optimize my checking system? GalaxyCoyote 4 2,717 Oct-13-2019, 09:18 AM
Last Post: perfringo
  cannot import scipy.optimize.Bounds larkypython 2 7,120 May-05-2019, 04:09 AM
Last Post: larkypython
  Optimize unittest loading Nazz 3 2,484 Mar-05-2019, 11:59 AM
Last Post: Nazz
  optimize choices in multiple if ---: statements Pedroski55 2 2,856 Dec-25-2018, 05:06 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020