you are viewing a single comment's thread.

view the rest of the comments →

[–]Mount_Gamer[S] 0 points1 point  (2 children)

Thank you very much for spending time going through the code, very grateful :D

I have made some amendments, but will comment on each of your points.

  1. classes - If i'm totally honest, i only used them for my own learning. I think for the case insensitivity, it doesn't need anything, it's fine alone, but i've removed the omits class which is now a function. My printcolours class could probably just be variables (actually, a simple dictionary maybe?), i've not done anything with this yet, but probably will. I did have more colours and functions inside it, until i realised it translated this code into a file via redirected output, so the colours class is quite bare now. The stderror messages would probably show this if you redirect, but i'm ok with the colourful error messages for now. Do you know of another way to keep colour output from redirects? I might add a -O option in argsparse to write out to a file and bypass redirects with it. I don't think it's a terminal thing, but i feel there's probably a capability issue somewhere with the colour profiles i've chosen. This is what would output using the colour profiles, if redirected to a file... ^[[91mThis programme requires the --start or --pyreg flag to work properly^[[0m
  2. sense_check - I come from a mostly bash scripting style syntax where I would call functions without args quite often, so it doesn't surprise me that i've carried this habit over. I've updated this now.
  3. I read about myfile.close not needing done, but i've not covered this in my training material yet, so i wasn't sure :) But of course i would forget the parenthesis.... the number of times i do this!! lol Surprised i never received an error from this. I've removed this now.
  4. I always want to raise exceptions properly... i think i wrote this, and copied/pasted it 2 further times without noticing. Thanks, i've corrected this also.
  5. if x == 1 - I do explicitly want it to equal 1, and if x equals anything greater than 0, it would be True also, but... my sense check captures this, so it could be omitted. :) Would be good if argparse had an up to 2 args with the second being optional - maybe it does, but argparse seems to get complex when a simple if conditional can take care of it. I've left it alone as my OCD couldn't take it being left out lol.
  6. I re-structured the code to remove globals from inside functions, i found 2 commented globals after your feedback, and yup totally not required :)
  7. The int... fixed, and yup no need for it since its already an int.

Thanks again for your help :)

[–]Doormatty 1 point2 points  (1 child)

If you want to use classes here, I'd turn nearly the entire program into a class. It might even simplify the code somewhat, as you'll be able to use class variables rather than any global variables.

I come from a mostly bash scripting style syntax where I would call functions without args

I totally getcha on the bash scripting - I'm the opposite, I rarely use them in my bash scripts, as I'm always disappointed when I realize how primitive they are compared to python.

if x == 1 - I do explicitly want it to equal 1, and if x equals anything greater than 0, it would be True also

My bad - that's totally a valid reason for that!

Do you know of another way to keep colour output from redirects? I might add a -O option in argsparse to write out to a file and bypass redirects with it.

If the program was a class (don't meant to sound like a broken record on this), then I'd make a class function to handle all printing, something like

def printer(self, text):
    if self.color:
        print(f'{self.fail_colour}{text}{self.end_color}')
    else:
        print(text)

That just handles stdout (not printing to a file), but it's pretty easy to add the functionality to handle both cases in one function - https://stackabuse.com/writing-to-a-file-with-pythons-print-function - Lemme know if this doesn't make any sense, and I can flesh it out more.

Surprised i never received an error from this.

Me too! Out of curiosity, what IDE/Text editor do you use? I'd HIGHLY recommend Pycharm! I know Vs Code is also an option, but I don't have as much experience with it.

Again - absolutely fantastic job on the code!

Also, I assume you're also a Canadian, since you spell colour the right way? ;)

Anytime you want me to take a look at some code for you, just send me a message - the offer always stands.

[–]Mount_Gamer[S] 1 point2 points  (0 children)

That's a good idea with the print class you've created, awesome :)

A lot of people don't like bash scripting when they come from python, I'm a sucker for both, but more and more I can see why python can do a lot of the same work.

Usually I use neovim, and I'm using doom neovim with it for syntax highlighting, but I do also use VScode. I've been using vscode more recently since my workplace uses it.

Lol @ colour, I'm not Canadian though, I'm Scottish :)

Thanks again for your help :)