#!/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[i]=globalList[i]
                    else:
                                SELF.DATA[i]="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.

7 Replies 7

Please tell me if it is bad [...] it doesn’t work at all

Well, should it work at all? If so then that would pretty clearly imply some measure of "bad" if it doesn't do what it's intended to do.

Is the question you're asking really the question you meant to ask?

Not sure what you mean David tbh. But I’ve came hehe for a healthy discussion.

If this were April 1, I might think that you were playing an April Fools' prank on us.

And are we supposed to guess what the code is supposed to do? Read PEP 8 – Style Guide for Python Code paying particular attention to Document Strings and Naming Conventions.

Python 2 reached EOL in 2020. Consider updating to Python 3.

The wildly inconsistent indentation should certainly be cleaned up.

Additionally, names are important. Variables like a and b and c tell the reader exactly nothing about what those variables are or how they're used. Objects called myclass tell the reader nothing about what those objects are. Functions like DoThing tell the reader nothing. Etc.

If your goal is indeed to "look better" as a programmer then your first step is to write code which other people can read and understand.

few things i can

  • use python3 not python2

  • use pep-8 guidelines

  • proper variable naming, which verbosely tell what this variable suppose to do

  • if possible, later stage maybe, what final outcome you expect for given input, write a test case for it

  • give default argument, when it required

I'm not sure what you're hinting at. It seems you didn't even write that code. You're not asking any specific question about coding. The only question you asked is whether the code is bad (it is), but a yes/no question is usually pointless here.

As a new user here, please take the [tour] and read [ask]. Also, if you want to learn Python, start with a tutorial.

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.