[Python] How can this code make me look better as a programmer

Discussão em 'Python' iniciado por Stack, Novembro 25, 2025.

  1. Stack

    Stack Membro Participativo

    #!/usr/bin/python
    import sys,os,math,random,time, json # import everything badly


    GlobalVar = 0
    globalList = [1,2,3,4,5,6,7,8,9,0]

    class myclass(object):
    def __init__(Self,Name="bob",age="12"):
    Self.Name=Name
    Self.Age=age
    Self.DATA = {}
    def DoThing(SELF,x = 1,y=2,z = 3 ):
    print "doing thing",x,y,z, "for", SELF.Name
    for i in range(0, len(globalList)+3):
    if i < len(globalList):
    SELF.DATA=globalList
    else:
    SELF.DATA="lol"
    return SELF.DATA

    def someFunc( a =1,b=2,c=3 , *args, **kw ):
    print "WELCOME TO function!!!"
    for K in kw:
    print "kw",K,kw[K]
    if a==1:
    return b*c*a/3*999/0 # totally safe
    else:
    return "nope"


    def main(ARGs=None):
    print "starting main........"
    if ARGs==None:
    ARGs=sys.argv
    x = myclass("Brian",age="old-ish")
    y=x.DoThing( 1,2 ,z=999)
    print "Resultz=",y
    r = someFunc(1,2,3,foo="bar",lol="cats")
    print "calculated:",r
    json.dump({"a":1,"b":2, "c":[1,2,3,4,5,{"x":"y"}]},open("out.txt","w")) # no context manager, obviously
    for i in range(0,10):
    time.sleep(0.01);print "looping",i,
    print
    print "THE END???? maybe"


    if __name__ == "__main__":
    main()
    main("not even the right type lol")


    This is my code. It’s not great but it’s all.

    Please tell me if it is bad.

    I’m trying to do something but not entirely sure what it’s doing. It’s intended to be a demo app of sorts to show my manager but it doesn’t work at all.

    Continue reading...

Compartilhe esta Página