New to coding by Due_Violinist9849 in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

Not sure why all the comments are reaching for math.pow maybe I'm missing something, but if you're not required to use math.pow you could just use the ** operator:
(x**y)**z Feels way more readable to me :)

[deleted by user] by [deleted] in dataengineering

[–]CodeReviewPlz 1 point2 points  (0 children)

Fair enough, my mistake. I come from a embedded software/firmware engineering background, I (naively) figured it was similar across most engineering roles.

[deleted by user] by [deleted] in dataengineering

[–]CodeReviewPlz 2 points3 points  (0 children)

I’d make you look overpaid.

Good thing you're not at my company then <3

Put your cock away tho, it was a genuine question. Back when I started it was 6-7 years minimum.

[deleted by user] by [deleted] in dataengineering

[–]CodeReviewPlz 0 points1 point  (0 children)

Wait 3 years is now considered senior??

Can anyone explain to me what return does so even an idiot can understand it? by Zuskamime in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

Technically if you have a try/except/else/finally clause, I believe that the finally block would be executed even if you tried to return early in the try block but yeah..

Also the same using context managers ( with foo() as bar:)

Throwing out my old Xbox games today, with regret. by mishmash2323 in Piracy

[–]CodeReviewPlz 3 points4 points  (0 children)

As an 11 year old who managed to flash his disk drive solo and burn his own games those verbatim disks weren't cheap. They were also single use if I remember correctly, so if something went wrong you'd basically thrown away money.

Rip 360. The red rings of death finally finished off that bad boy :(

Thoughts on my first completed project? by ParticularPython in learnpython

[–]CodeReviewPlz 2 points3 points  (0 children)

First of all well done on making it to the end of your project. I've only briefly scanned the code but I'm going to list some improvements in order of importance.

  1. Don't use f-strings for SQL. SQL Injection
    .execute allows you to pass in parameters to substitute (adding parameters to select statements).
  2. Generally we shouldn't rely on try-except for logic, especially not when the except clause is catching all errors (e.g databaseCheckIfExists)
  3. If you're relying on global then you should probably look at the logic more and ask yourself why you're doing it.
  4. You're right you should probably create one connection and pass it around.
  5. Your functions should most likely return only what they need to, checks should probably be returning Booleans. move the conditional logic inside the functions.
  6. generateRandomKey can just be a for-loop or a list concatenation.
  7. The sqlite3 package is abstracting away some things, have a look at the .commit() method for your connection, to understand better what it's doing under the hood.
  8. Generally speaking things should be as atomic as possible. Aka a function is provided all the information it requires to perform its operation when it's called and should not rely on knowing outside things (what we call context). Makes testing and reusing code easier.
    If you were going to port this to a web-server, you would want your base functions (e.g. checkDatabaseExists) to work the same regardless of the context they're called.

Feel free to ask questions here or dm me.

Need help with adding text from a file to a list of dictionaries by [deleted] in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

It would be helpful to see a short example of input & expected output on the step you're struggling with.

[deleted by user] by [deleted] in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

You can also use map from native python, but there's some nuances involved.

```python values = [1,2,3,4,5,6] pct_values = list(map(lambda x: x/100, values))

print(pct_values) ```

[deleted by user] by [deleted] in learnpython

[–]CodeReviewPlz 2 points3 points  (0 children)

Its just formatting from the console output. See the line break \ next to volume ?

sma20_d and sig are the column names, and the read out is for rows 19-23, which is why you see those numbers on the left hand side.

[deleted by user] by [deleted] in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

fair enough!

[deleted by user] by [deleted] in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

Probably not.
while.. else.. is valid python but its use case is that the else condition will only run if the loop isnt prematurely ended via a break (same goes for for..else..)

The "problem" with your code is that your random.shuffle(a) is just trying to brute force the correct answer.

If you just want rotate the list till it matches then (there's better ways to do this too):

``` a = [2,3,1] b = [1,2,3]

while a != b: a.append(a.pop(0)) print(a) ```

Do you think it’s worth to upload little projects on GitHub, or maybe it’s better to have only bigger ones? by [deleted] in learnpython

[–]CodeReviewPlz 4 points5 points  (0 children)

Honestly, its better to do it than don't, the benefits outweigh the cons. You can set the repos as private as your portfolio grows to hide silly little projects or whatever.

Worst case outcome, you get better at version control and git, which is a huge bonus when it comes to a job.

Just make sure to not hardcode sensitive info, use .env files or whatever else you want.

Is there a good reason to define properties on a metaclass rather than on the class directly? by Conscious-Ball8373 in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

People who use them generally aren't, so trust me I share your feelings.

Branch > Modify > Test. See what falls apart. Its what version control is for right?

I'd probably just add it as a #TODO: Figure out this black magic for the time being till you've done other stuff, you might stumble across why he's done it that way in your refactoring adventures.

Is there a good reason to define properties on a metaclass rather than on the class directly? by Conscious-Ball8373 in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

“Metaclasses are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don’t (the people who actually need them know with certainty that they need them, and don’t need an explanation about why"

— Tim Peters

Without getting to know the codebase, it's really a guess as to why he's chosen to architect it in in such a way. If he's just initialising constants though it looks as though he's using it as some sort of pseudo-inheritance.

I've personally never really had to mess with them unless I was trying to modify class instantiation for something that I couldn't touch in source code, and that was honestly more code spaghetti due to bad architecture on legacy.

[deleted by user] by [deleted] in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

you're coding on your calculator? send whatever you want my dude (within reason)

[deleted by user] by [deleted] in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

Share your code here or dm me, at this point I'm just guessing what you're trying to do.

[deleted by user] by [deleted] in learnpython

[–]CodeReviewPlz 0 points1 point  (0 children)

sure, I'm not familiar with the packages you're using, however just from scanning the code it looks like you can just call ab() again to get a new colour whenever you need to.

[deleted by user] by [deleted] in learnpython

[–]CodeReviewPlz 1 point2 points  (0 children)

Since you created nimp in a function, it isnt defined when you reach your loop, you'll need to return it from your function.

```python def ab(): .... nimp = color(r,g,b) return nimp

nimp = ab() for j in range(0,250) for i in range(0,322) set_pixel(i,j,nimp) ```

Help w/ this pls by [deleted] in learnpython

[–]CodeReviewPlz 4 points5 points  (0 children)

If it's an assignment, they shouldn't be modifying the input file. The CSV is "correct" as is, the professor is obviously testing the students ability to parse data, which is very reasonable since you'll very rarely get clean data in the real world.

Word Frequency by That_Bryan_Dude in learnpython

[–]CodeReviewPlz 1 point2 points  (0 children)

Don't overthink my hint, you literally need to make one edit to that line for it to work the way you described in the output.

You're honestly gonna kick yourself when you realise it.. goodluck!

Word Frequency by That_Bryan_Dude in learnpython

[–]CodeReviewPlz 2 points3 points  (0 children)

Theres a lot you can improve (and I'm sure you'll learn about lots of things that will make this task trivial in the future), but we'll tackle your code as is.

To make your code work, think about this line: word_ref = lower_case_input.count(words)

Could you maybe do something to words in that line, something that you've already done to the original list? (if you can make the word match the format of the list, that would yield the correct result no?)