#๐ pls rate my code
211 messages ยท Page 1 of 1 (latest)
@young bay
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
main ```py
import time
from threading import Thread
import Modules.DataModule as DataModule
import Modules.UtilsModule as UtilsModule
def playtime() -> None:
stats = DataModule.get_stats()
while True:
time.sleep(1)
stats["time_spent_listening"] += 1
def main() -> None:
DataModule.load_data()
playtime_thread = Thread(target=playtime)
playtime_thread.start()
UtilsModule.check_for_mode()
UtilsModule.handle_users_input()
input()
if name == 'main':
main()
You managed to package it into a wheel file or exe?
why not push it to your Github and share the repo?
good idea
gimme 1 sec
actual like a few min
is this how im supposed to do it?
https://github.com/GrawityFals/Grawify/tree/main
im not used to github yet
its not but its a start
so what did i do wrong?
When I see anyone who uses global, I go ewww
https://github.com/GrawityFals/Grawify/blob/main/Grawify 1.0 Release/Modules/DataModule.py#L23-L24
Grawify%201.0%20Release/Modules/DataModule.py lines 23 to 24
global settings
global stats```
!global
When adding functions or classes to a program, it can be tempting to reference inaccessible variables by declaring them as global. Doing this can result in code that is harder to read, debug and test. Instead of using globals, pass variables or objects as parameters and receive return values.
Instead of writing
def update_score():
global score, roll
score = score + roll
update_score()
do this instead
def update_score(score, roll):
return score + roll
score = update_score(score, roll)
For in-depth explanations on why global variables are bad news in a variety of situations, see this Stack Overflow answer.
๐ฏ
so i was thinking
insted of using globals
what if i made a function for that?
like you ask and it returns that
or changes
would that be better?
I don't understand why you would make it a function. Its already a function. You just need to pass it in as a parameter/arg
but i was thinking i was told
i shouldnt put things in outer most scope
or is it global scope
you can put things in outer scope
ok
no thats not why I don't like it
if i change something that is send as a parameter will it create a new copy of that or just change it
I don't understand
so you said pass as parameter right
so if i change that like idk setings[dsds] ) = sasas
will it create a new version of settings
or update the old one
I dont think you understand what you're asking. There's no "version" when you pass them in as parameters
They're the same
Why call the function here? https://github.com/GrawityFals/Grawify/blob/main/Grawify 1.0 Release/Modules/PlaySongsModule.py#L129
Grawify%201.0%20Release/Modules/PlaySongsModule.py line 129
play_random_song_you_have_not_played()```
yes
so
when a song finishes
it doesnt return anything
and it just calls itself
so its like a loop
my logic
dont ask why i did that in play_random_song_you_have_not_played func and not in play_random_song func
Which is gonna be challenging if you ever need to write unit tests
that bad?
In this function, you could just move both of the return string and just put them outside of the if else statement https://github.com/GrawityFals/Grawify/blob/main/Grawify 1.0 Release/Modules/UtilsModule.py#L8-L21
im from lua we do that alot there
Grawify%201.0%20Release/Modules/UtilsModule.py lines 8 to 21
def convert_seconds_into_hours_minutes_and_seconds(seconds: int) -> str:
if seconds >= 3600:
h = seconds // 3600
m = (seconds % 3600) // 60
s = seconds % 60
string = f"{h} hours, {m} minutes and {s} seconds"
return string
else:
m = seconds // 60
s = seconds % 60
string = f"{m} minutes and {s} seconds"
return string```
oh yep i see that
Do you unit test in Lua?
๐๐ฉ๐๐ฎ ๐๐ฃ ๐ฉ๐๐ ๐ก๐ค๐ค๐ฅ ๐๐๐๐๐๐๐๐๐๐: https://snu.socratica.com/python Unit tests are a way to make sure your code is correct. Python comes with a built-in unit test framework that makes it easy to write a lot of tests for your software. In fact, many engineers will write a series of tests before they begin coding. This approach is called โtest driven...
The "music" files you have in your Songs folder... I think you should replace them with public licensed music files.
You don't wanna get suspected for copyright
I get it. Just replace them with public licensed ones
exactly
timestamp?
This?
its just math
its i in math
what i?
i = square root of -1
ok but why j?
but that's not the point of the video
the point of the video is to test your function continuously works as you develop new features or expand existing functions
j is a complex number
Where? there's no tests.py file
yea
It helps as time goes by, new Python upgrades, new versions to libraries, etc. You can quickly test which new version breaks your current which functions
I'll take your word for that
Theres no requirements.txt file?
whats that?
do you know what you need to pip install all the time?
requirements.txt file helps so you don't have to guess
pip freeze > requirements.txt is a quick way to set it up
Then push that text file to Github
i do that in pycharm or cmd?
Then later, in another computer or whatever, you can pip install -r requirements.txt
oh ok
I can see that your script uses these
https://github.com/GrawityFals/Grawify/blob/main/Grawify 1.0 Release/Modules/PlaySongsModule.py#L4-L5
Grawify%201.0%20Release/Modules/PlaySongsModule.py lines 4 to 5
from mutagen.mp3 import MP3
from audioplayer import AudioPlayer```
i got it
ye thats it
hey it put alot of things i dont use here:
altgraph==0.17.4
audioplayer==0.6
certifi==2024.8.30
Grawify @ file:///C:/Users/Ziga/OneDrive/Desktop/Grawify/dist/Grawify-1.0-py3-none-any.whl#sha256=b4b6c9873f8ec0ec67b28a08a0a14bc2870cc8ace0bf1d1682f2542e1955c640
mutagen==1.47.0
packaging==24.1
pefile==2024.8.26
playsound3==2.2.2
pyinstaller==6.10.0
pyinstaller-hooks-contrib==2024.8
pywin32-ctypes==0.2.3
setuptools==75.1.0
I guess remove the ones you don't need
alright thats all of the faults I can find in your code. 5/10 its good practice project.
thats decent
Thats up to you
depends
or that certifi
!pip certifi
thats a packaging lib
just imagine if there's another dev and they clone your repo. Do you want them to install that to help work on new features with you?
why would they?
they wouldnt
ok
If they wanted a music player, theres hundreds of other options
wdym?
again, thats up to you. Do you believe certifi or pyinstaller lib is required to install in order to continue working on your Grawify project or not?
If its not, delete it
If it is, keep it.
ima keep it then
this is it then ig:
audioplayer==0.6
certifi==2024.8.30
Grawify @ file:///C:/Users/Ziga/OneDrive/Desktop/Grawify/dist/Grawify-1.0-py3-none-any.whl#sha256=b4b6c9873f8ec0ec67b28a08a0a14bc2870cc8ace0bf1d1682f2542e1955c640
mutagen==1.47.0
pyinstaller==6.10.0
pyinstaller-hooks-contrib==2024.8
Probably don't need this Grawify @ file:///C:/Users/Ziga/OneDrive/Desktop/Grawify/dist/Grawify-1.0-py3-none-any.whl#sha256=b4b6c9873f8ec0ec67b28a08a0a14bc2870cc8ace0bf1d1682f2542e1955c640
Did you also fix the global thing?
i deleted em
Make a new one
that takes a while
ye
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ pls rate my code