#python-discussion
1 messages · Page 285 of 1
soooo, whats everyone working on these days
I am working on a slot machine
just messing around with some fastapi stuff lately, it's actually sick
I can't use the app properly; it's my first time. Could you please send me a link?
oh sorry to hear that, hope fastapi gets better /j
But it knows that gambling is bad and doesn’t work
get well soon
lol chill, pydantic v2 makes it pretty nice honestly
Ashuh
an sdlc kind of bot for code review similar to github one but for gitlab
wish there was a nicely typed async client for gitlab
I set up my home "lab" (moved from DO to self-hosted (using CF free tier for the dns proxy thingy)), trying to finally get a blog up
I moved, cuz I wanted to get some more cores in case I need 'em and as I found out, the droplet (what DO calls a VPS) pricing is apparently per vcpu and I got like a droplet with 2 vcpus and it said 12 dollars a month, it was 24... anyway, the laptop I'm hosting it on now has a lot more RAM and more CPUs than I would reasonably want to spend to match in a VPS
so that was an adventure, had to set up a VM (I mean, my stack is dockerized, but still, wanted a separate and dedicated server machine), configured a WG tunnel for remote access, had to createa dynamic DNS service (literally what the ISP recommends when asked about a static IP)
fun stuff overall
I wanted to work on the blog system before I moved, but I moved cuz I wanted to have more resources for that blog system
so now trying to finally work on the blog itself
Now i get it.
nice! I host a bunch of home automation stuff on my rpi, surprisingly little resource usage when idle
this is how you got the role
what home automation do you folks have
hmm, I should maybe switch the host OS to Proxmox for that sweet monitoring (and VM management) stuff it comes with
oh esphome
I mainly use home assistant, with a few supporting servers running along side it.
whats the cf tunnel for
accessing all this remotely
I see why not tailscale
lemme find something
I already have a domain with cloudflare, so just easier setup
oh fair enough
no, actually, @shrewd pine
Also a home assistant, with a zigbee network for most things.
I would prolly just go with tailscale for having my devices on a private network
eh, fine, I'll just share a screenshot
thats cool sadly where I live a lot of home stuff isn't really smart so I haven't been able to mess around much
damn 💀
that ai gearbox analogy is actually painful to read lol
ai driven gearbox is such a stretch for a vpn lol
its just a wire guard wrapper (a nice one)
how many servers/nodes do you have btw or are you just running proxmox on pi itself
This is just running the normal pi os on the pi with docker containers
I don't have any built-in smart stuff. I just have smart plug and switches that I bought.
I made a DIY smart oven using a arduino and esphome, that was fun
nice you using home assistant for those or something else
See above
I should probably look into CF tunnel now that I see it mentioned...
cuz currently the flow is this
dynamic dns updates cf's records with my router's current public IP (I need this for anything to work really, but anyway)
when I want to connect remotely, I run a script that gets the origin IP from the CF API because it's behind the CF proxy (orange cloud, so I can't get it from the DNS records themselves), this script then updates my WG config file
then I up the wg if and can finally connect
but yeah, all of this means I have a port being forwarded from the router and the host to which the traffic is being forward to does no filtering of the connections coming in from that port, since I don't know what IP I might be connecting from
I suppose with CF, I could basically lock it down even more
with CF you wouldnt need port forwading at all, its a reverse proxy, and it has the plus of giving you https
I mean, I have HTTPS between CF and origin right now already, but yeah, a tunnel would further simplify things I guess
ah my bad, zigbee is definitely better for local control than wifi stuff
I need help, I am making a hangman game but how do I make it like
Print this
H" _" _ "l o
you can use join with a list comprehension to swap hidden letters for underscores
But how do I do that
I am begginer
basically like ''.join([c if c in guessed else '_' for c in word])
yo
I am readinng this book called Hands-Onn Machine learninng and I just came across this Math formula that I don't understand a single bit of It's called RMSE
I can't properly copy it
root mean square error?
yes
it basically tells you the average mistake your model makes
yeah and since it squares the errors, it punishes big misses way harder than small ones
oh, and the mean absolute error??
mae is just the average error without squaring, so it cares less about outliers
oh, ok
Given a numpy array y that represents the label (that is, the thing the model is supposed to have predicted), and y_pred representing the actual prediction of the model, the RMSE for that specific input would be computed as
np.sqrt(np.sum((y - y_pred) ** 2))
ohhhh , Thanks for the help, appreciate it very much !
you can do something like ''.join(c if c in guessed else '_' for c in word)
I have one more problem, the author often refferences shapes like : outliers are exponentially rare (like in a bell-shaped curve), the RMSE performs
very well and is generally preferred. annd : sometimes called the Manhattan norm because it measures the distance
between two points in a city if you can only travel along orthogonal city blocks.
Hello guys, can I ask, how do you guys learn python? I feel stupid that I always have to google stuff and not remember how to solve problems 🙁
official tutorial is actually great, then just pick a project you like and build it
How about leetcode problems? Like if I can't solve a problem, does that mean I should go back to basics? Or keep on trying?
no
lol that is the correct answer
leetcode is mostly logic puzzles, just check the solution and learn if you're stuck
before doing leetcode , you should learn python a bit , get comfortable with list , string manipulation , using dicts , sets etc
or just not do leetcode ever
Mr. Saul we have some frightening evidnce against u
then the harder problems you want to tackle, u might want to start doing DSA
if only interview process stopped asking about it...
So all those list, string manipulation, better to learn through the official documentation?
But one major problem I face is that there's so many methods to a function?
Like dict. xxx()
You guys get what I'm saying?
https://imgur.com/a/b8jYO34 in vscode I am getting 8 spaces when using tab why is this ? Please ping on reply
how much python do you know so far ? how did you learn it ?
lol just walk out of the interview "get out of here with your leetcode bullshit"
Or is that where I just learna and go
in today's market ? lol
I would not recommend learning the basics through the official docs. The official docs is a reference you use to look stuff up.
Learn the basics from a book or course.
I feel like I know all functions, through university projects and courses.
You don't need to learn all the functions upfront. You learn them as you need them. A book or course will introduce the stuff you need gradually.
How did people originally learn python if not for the documentation? And let's say I'm trying to solve a problem, like random guessing, instead of hard coding it, is it bad that maybe I just found out about the random function?
I see, that's interesting
in all seriousness though, saul is right, interview questions is the only need you're likely to have for leetcode challenges. In my professional experience, it's very rare that you'll need to write an algorithm yourself.
Presumably the people who made Python wrote guides and articles.
if you want to start at 0 , then pick a course / book
if you like youtube , go to corey schafer channel and go through his python playlist
if you like books , use https://automatetheboringstuff.com
and u said you dont remember when to do the dict.stuff() etc , you cant really memorize that , there is no other way than just writing code ,looking it up , doing this over and over again untill you start remembering it subconciously
check your editor.tabSize in vscode, it probably got set to 8, thats huge lol
I feel stupid that I just use what's already available, for example the
import random
Get a random number between 1 and 10
num = random.randint(1, 10)
dont sweat the methods, you only really use like 5 of them daily, for the rest just use autocomplete
Thakn you for the tips
Got it
True2
You don't have to learn how everything works all at once. It's totally fine to build on what others have made before you, and if you're particularly interested, you could look into how something like a random number generator works under the hood.
Autocomplete is the greatest innvention of the 21st century
Everyone has to google things from time to time. Those with more xp maybe a little less but everyone has to check things now and then
you could look into how something like a random number generator works under the hood
Yeah how do we look into something like this
You could try for example reading https://en.wikipedia.org/wiki/Random_number_generation
Random number generation is a process by which, often by means of a random number generator (RNG), a sequence of numbers or symbols is generated that cannot be reasonably predicted better than by random chance. This means that the particular outcome sequence will contain some patterns detectable in hindsight but impossible to foresee. True rando...
yeah i still google basic syntax all the time, it is totally normal
Damn, is this how people learn if they really wanna deep dive into something? I wanna deep dive into stuff constantly but don't know how
I guess it is the way
There's no single way to learn things, but Wikipedia is often a good resource.
You can also just google stuff like explain x code
I see
Alright cool I'm noting that
Where to look depends on what you're studying
realpython.com has tons of great articles on all kinds of Python topics
like , its good to know theory , dive deep
for example , you said about the random number generation , its good to know it
but u dont have to know it at the start , even the person who knows all the theory will do import random unless they have a solid reason to not use it
Thank you I'm looking into this now
You only need to understand some general fundamentals
Like how seeding works and how a PRNG behaves. You don't really ever need to learn to implement one unless you're just curious.
Understood
realpython is sick for deep dives honestly
What are your opinions on full stack developer courses that promises you “to be a full stack developer guarantee” kind of stuff.
I’m always thinking about joining but I’m afraid that I can just learn it all by myself
I don't think it's worth paying for one.
i don't think it's worth the time
yeah, knowing how a LFSR works is usefull, but you dont really need to actually use that yourself
You can indeed learn all by yourself
Alright thank you @pallid garden @golden mortar @past shard for anwsering my questions, appreciate it very much
Hopefully after this I’ll be on a smooth learning path for Python.
Learning Game Development too, which is super fun 😉
eivl did u see i published the spinner program as a package i named it image ultis maybe il add other stuff to the package like an image converter
i did not see, share the full name please
add some install docs and usage docs in the README would you?
add both pipx and uv
no clue how to do that il check what that is right now
i used uv above.. to install clii tools, you use pipx
but uv lets you do that as well
Wait even codeacademy? I've seen huge discounts, and I think that's a red flag
if i just use the command, i expect it not to give an error, thats somethiing you can fix to make it better
have you setup publishing to pypi via github?
i added this on github aswell if that is what u are asking
when you update your code on github, does it automatically publish a new version to pypi?
i dont think so i think i have to do t hat manuallyt
its something you can look into...
Hello
hello
I thought raycast for just for screenshots
Hello
it does loads of things
السلام عليكم ورحمة الله وبركاته
وعليكم السلام
I dont think your suppose to speak arabic though
كل عام وانت بخير
رمضان كريم
علينا وعليكم
but actually stop, its not allowed.
وعلى الجميع يارب العالمين
I wrote an Issue on your github
use english when you are here
@inland karma how to enable the thing where the screenshots are auto copy? (raycast)
are you using the clipboard history?
im not gonna like to use i used chatgpt to write my readme i did change some things its just ive never wrote a readme bbefore so i needed some help
all good for a first draft, just make sure to add a small code example showing how to use it
im publishing the new readme its good now it uv and pipx as requests and usage examples
ye i just did so
i gave 2 examples which is more then enough for a small program
markdown is rich text, you write the format like you do here on discord
yes hi
hi
i am going to quit programming
# or bash commands
rotate-image --help
why
because am not programming
riught gotta add this thanks
saved me 5 minutes of having to delete the dist and egg and rebuilding
i shoul;d put this in usage right?
yes.. and one for install
pipx install image-utils-spin
and for uv
uv tool install image-utils-spin
pipx install image-utils-spin
✅ uv
uv pip install image-utils-spin
``` i did already
excellent
this is installation
technically they can do ```
rotate-image --help/h
```or py script.py --help/-h```
nice, having that entry point makes it feel like a legit tool
usage commands should be litterly true
rotate-image --help/h does not work does it?
ye
il put a comment telling that they can use -h
instead of putting that in the ```bash xd
is there a shorter way to get "string".encode().hex(" ",-2)?
i tried --help/h and i got an error saying unrecofnized argument. with a nice message :
usage: rotate_image [-h] [-i IMAGE] [-r ROTATE] [-s SAVE] [--force] [positional_image] [positional_rotate] [positional_save]
this is what you should have when you only do rotate-image
✅ bash commands
rotate-image --help
or
py script.py --help
you can use -h or --help
good?
Isn't "string".encode() the same as b"string"?
yeah for ascii it is, but encode lets you handle different encodings
yeah, but you didn't explicitly specify an encoding
how to be smart
But I'm pretty sure there's no shorter way than .hex(" ", -2). The alternative I can think of would be with f-strings, slices and str.join...
Hi. I got my friend some libraries via .whl files, but it's not working. would it work if i just sent him my py install's site-packages folder & told him where to put the files?
@inland karma oh you meant by github i should do t his https://pypi.org/manage/account/publishing/
any reason they cant install the libraries from pypi via pip?
wait
no internet on his side
he only has a USB
I think so @inland karma
setup your github as a trusted publisher, and use github actions to publish when you make a new release. yes
and your screenshots are not accessable from the history?
k
I didnt try
wait
once you have done this once, you can use this repo as a guide for any other repo you want to do the same with
nope?
hmm... strange.. maybe we take screenshots differently
how do you take screenshots?
command shift 5
ill charge my macbook, and test
then I tap on the screen
alr
i use all three
my main driver is linux right now
i have two macs, two windows laptops, one linux laptop and two linux desktops
and a bunch of servers in my homelab
why
its better for me to work on
can you give me one laptop 😭
i dont think you live close to me
good answer
joking. who gives his laptop to a stranger 😭
i give away old hardware i dont need
you mean for free?
why on earth would i charge for trash? yeah for free
i have a few lying around! 😄
woh
trash is a strong word, cuz its probably some mans tressure
how long you use a device before you replace it
the string in my code is in a variable
yes, but for me its trash, i have to pay money to deliver it to the dump. hence.. i give it away
around five years
a laptop from 5 years ago is not trash
mine is 4
ill put on coffee and you can come and get some! 😄
m1 pro macbook released in 2021 is definatly not trash
but aren't you cautious of the hdd data
i know how to delete it safely
I dont like to take stuff for free
okk, i don't even give away my broken phone. thinking someone can hack my internal storage data
the phone is not turning on
well, you can do lots of things in this domain to protect your privace, and batteries die after some time unused.
well depending on where you live there are trusted stores that take in electronics and will safely delete stuff and either re-sell it or properly dispose of it
and modern phones has encryption on by default
true i still don't do that
You could sell those at ebay, or use them to run some bots.
i have a home lab, i dont need to reuse old hardware
Wow , that's so cool.
How many pcs do you have in the lab
i have three servers, and one of them is quite large
Wow, so you work from home , right??
yes, but my home lab is my personal stuff
Here's a question i started learning python and my question is what is the best code editor currently i use jupyter
Oh, wow
there is no best editor
its all personal preference
Hmm
if you like jupyter, use that
Ok
I see
vscode, if you plan on using other languages and pycharm if you only use python
every editor has its purpose
For now only python
i have three servers
How many chefs do you have to necessitate 3 servers?
and one of them is quite large
Not sure what one of your waiter's weight has to do with that
(Obviously joking, lol)
some might be better depending on your situation, but there are no best one
😄
vscode is a solid choice if you ever find notebooks a bit messy
Pycharm is great for beginners
i would not say that
I see
but that is up for an argument
preference really
beginners should not be handed easy solution while they are trying to learn
it should be just easy enough to get you started
I liked vscode's simplicity but pycharm has a lot of good resources since it specialise in python
and nothing more
that is why thonny is the editor for beginners, and the editor you should recommend beginners
Oh btw so i used to code in LuaU (roblox programing language) as its a game engine it had like an auto fill option doesn't python have something like that r does only jupyter editor not have that
oh yeah basically every editor has it, just hit tab in jupyter
Hmm it didn't work when i tried let check again
VSCode is good with not a lot of extensions
you usually have to run the cell first so it knows the variables
Well then sublime text is the best EDITOR for beginnners since, it doesn't have any sort of code completion and you have to mannualy run a file
what editor lets you run a file automatically?
it is a very good and popular editor
sublime text is great, but it is not tailored to be a beginner friendly editor
it is just simple out of the box
while thonny is
I mean for beginners too
It is user-friendly and smooth
i dont disagree, im just saying there are only two editors out there that is taileroed for beginners...
one of them is thonny
if you like it will depend on your preferences
and the other
because thats what an editor choice is, personal preferences
pycharm is a specialist tool
thonny is a beginner friendly editor
mu
pycharm is definitely heavy but the debugger is honestly worth it
yes, it has a very good debugger
arguably the best debugger
was?
German for what
oh i see.. its very good, have you use any other?
No, I thought it would be useless
i know german, it is also a word in english, so it looked confusing
try pythons debugger
yes, I got the habit from a friend
the friend - "GOLD GOLD GOLD"
if you put a breakpoint() in your code, python will enter the python debugger automatically for you
PEAK Reference cacth up
Source code: Lib/pdb.py
The module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame. It also supports post-mortem debugging and can be called under program control.
The debugger is extensible – it is actually defined as the class Pdb. This is currently undocumented but easily understood by reading the source. The extension interface uses the modules bdb and cmd.
Chat look at this pattern 668 AK
661*
Yeah, I don't speak ohnepixel
Oh hey evil you’re still awake
Still?
6h15m ago I went to bed when he got here
It's only 1 pm
random question
No need to ask to ask
why are global variables worse than local
broader scope
because its much harder to trace everywhere they are modified
Hard to keep track of
oh
and in general its just easier to reason about a program when you assume a function only touches what you give it
local variables in a huge function is similarly bad
because they takeup the namespace and objects will be having long lifetime.
It also tends to make reusing functions more difficult
it's not really about the namespace or lifetime. Data created and used in functions can also have long lifetimes.
i mean it can like have unwanted things in the namespace. suppose in module B you have a bunch of global variables then in module A when you import module B all these unwanted variables will be available in the namespace
I don't really see that as a strong case against globals
that is true, but it's something like third on the list of reasons to avoid globals
why is the first so much slower than the second?
[i%j or (s:=s+j,n:=n+1)for j in o]
for j in o:i%j or (s:=s+j,n:=n+1)```
because python interpreter got 🤯
Given a large o, the first will reallocate the entire list multiple times
will it?
read-only globals are okay. globals that have their meanings reassigned are hard to keep track of.
you've moved on from caring about low character count to caring about the other thing to not care about: micro-optimization 🙂
It depends I'd guess. If o has a known len then probably not
how much slower is "so much slower" anyway?
(especially micro-optimizing in python)
this is still cause I want it shorter
But I gotta go fast!!
Like no one ever was!
How can I learn the basics like in a hour or 2
!res
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
Harvard’s CS50
basics is very general, and how fast people learn varies
thats not 2hrs
you need to first learn C for 10 years
do you already know programming?
why
that way you can learn the basics of python in 1-2 hours
lmao if you want shorter just use any() or all() instead of building lists
the 2nd completes in 4400ms but the first barely reaches 8000 when I'm looping from 1-10000
i know the syntax i don't call myself a programmar
💀💀💀
What should I learn in !res
can we not do this?
If you're interested in completely unnecessary optimizations I can recommend you this thread on the Together C/C++ Discord: https://discord.com/channels/331718482485837825/1473128500096663714
This is a guy trying to juice out every bit of performance of a simple string-searching program, despite the fact that he's already at his disk's limit of 5 GB/s anyway
!res
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
thats a very good idea
unfortunately idk any c/c++
anything you like
wild
Im new to programming tho
I've been watching a few videos with C recently though and it's quite interesting
How to draw the mona lisa
you mean not learning C or not joking?
you can't
can I use either of them to make my code shorter?
Should I learn lua instead of python?
start with basics
joking about stuff like that in this room isn't a good idea, because there are people who know nothing about programming who may take it on face value. there are better ways to be funny and heplful.
4.4s kinda suggests you're probably doing something inefficient to start with
your wish
The mindset shouldn't be "learn in a certain timeframe", different people take different time. If you really want to learn the language, it will take time
Is it easier
you should not think learning programming takes a short amount of time.
👍
no, programming is hard
I'm getting the divisors of every number up to 10k
easy is a relative term. it depends on the person
python makes learning programming easier
I want to make games
yes learning syntax is easy
If you are a beginner python is the best language but it's still personal preference
like me
feel like this is a bit extreme
How easy
python has pygame but it cannot make 3d games
I've seen this happen way too many times myself.
python syntax is so easy almost like english
bro there is no easier later
its better to start with what you will work on later
for games you can start with pygame, it's pretty chill for beginners
we're here to help people, not to get laughs at the expense of their ignorance. that's how I feel.
So why should I not learn that first
it really is, helps you focus on the logic instead of fighting with symbols
@steady creek it's about as easy to begin learning either language. we're biased, we recommend Python
because its upto you. easy is a relative term i said
Okay!
I think go with assembly
See programming is a combination of problem solving and synntax
??
what?
You can do that quite efficiently
what
I don't think its good to start game development
you are wrong
??
I also want to golf it so instead of doing
for i in range(1,10000)
for j in range(1,i)```
I'm just looping to 10k twice
that's the big slowdown
game dev is one of the best way to learn programming
I don't think assembly will be a good language for someone who doesn’t know anything about programming
also one of the hardest things
and wnats to be a game dev
even simple games like Pong have surprising complexity.
you miss understand him
thats why recommending making a game is a huge mistake
I did not mean it like that
You made pong before?
i thought u said game dev is bad way to learn mb
wait, how did assembly -> game development???
yes, actually - here's a game I developed in Python https://xtaloid.itch.io/xtaloid
better than cod bo7
looks really fun
Mind if I see the source code?
I’ve never made games using Python, only Godot
nah not bad just meant start simple so you dont get stuck
godot is more capable
You're doing quadratic work for no reason and you're complaining about slowness 🥴
I meant to say you should not recommend assembly to someone who wants to get into game development and doesn’t know programming
I don't have the source available casually, sorry
you mean its paid?
I just don't have the source available, that's all.
can we monetize these games in pygame?
yes
where
Yeah it’s literally a game engine, but making a game through Python impresses me alot since it’’s not made for game development
by selling them yourself
Guys,, what do you recommend for daily problem-solving practice?(platforms)
aahhh
All good mate
(actually, this was done through another library, Pyglet, not Pygame)
i'm trying to get the blender package as a portable .whl file, but i dont see any on the install page. Do i have to build it from source or smth?
is "casually" a synonym for "off-hand" 
What are the best tasks for python freelancing in your opinion
The first simple thing is that you only need to loop to the sqrt and then d and n//d are divisors
Oh that’s something new
Link the package
And given you want all divisors in a range you can do even better with sieve based algos
yeah, it's actually been around for a while, and I grew fond of it
I just thought of that too
i thought so
making a script that scrapes upwork and apply for jobs.
Looks like it, yeah
That says it was last updated in 2019 for Python 3.5
I’d try to see if something newer is available
@inland karma https://github.com/rick-rocks123/image_utils i think its pretty solid i think now it automatically updates from git to pypi also uv and pipx are here
you have not done the trusted platform registry on pypi
wdym?
if d is a divisor then n//d is too
what kind of pleasure the code golfers get from making code unreadable 😭
it's fun
so you only need to check d <= n//d for divisor pairs
well, i'm trying to get the blender package used in ursina. Is it required for ursina or not?
what kind of pleasure do golfers get from hitting a ball into a hole
aah maybee but i don't think so
a sense of superiority
same question
Maybe the measurements and calculations in their mind and executing it to prove the calculation is correct
Same like kicking a ball into the top corner of a goal net.
(but the calculation in this case is highly inefficient)
balls and holes, what more can a man wish for
what
wdf
this is not something that will work, what are you really trying to do?
hmm, really thought that would land better
What does unresolved reference mean?
You got it
Sad
Share the code where you're getting the error, and the full error
well you definitely hit it out of the golf course
this is what I got, I'm trying to see if I can get rid of the len
o=range(1,10000)
for i in o:sum(x:=[j for j in o if i%j<1])%len(x)or print(i)```
it basically means you're trying to use a variable that hasn't been defined or imported yet
where do you get this error
evidently I hit it right into an alligator-infested pond where it was promptly chewed up
a friend has a PC with python, but no internet or internet drivers on it, therefore using pip install ursina is completely unviable.
I want to send him the library itself using .whl files via a USB thumbdrive
I just looked up Ursina and I didn’t see Blender in the dependencies
Maybe it’s somewhere else in the tree?
This gets me confuse, how do you read this, this symbols make me feel dumb .
How long did it took you of learning to learn this
it's not meant to be readable, it's meant to be as short as possible
def get_guess(guesses):
guess = input("\nGuess a letter: ").lower()
while guess in guesses:
guess = input("\nGuess a letter: ").lower()
if guess not in current_word: # type(current_word) == str
current_stage += 1 # current_stage (type == int) is unresolved reference
print(f"Wrong! You have {5 - } guesses left!")
i use chatgpt
i have current_stage though!!
phrasing!
this is what we call code golfing
essentially you try to solve a question with the least bytes of code possible
this kind of discussion is probably better-suited to #esoteric-python anyway...
it's in the pypi page?
it's not meant to be representative of daily development
i think codegolfing can be useful skill in obfuscating code.
Oh, I see.
Well that’s something
no one manually obfuscates their code
Where?
there's a whole stack exchange for it
Well
Some poor beginner saps have done it
and the error?
it's a lot easier to read with proper variable names
I will search that up thank you 😉
Damn using symbols to emoji is weird
it's not meant to be a tutorial
Ah, is it suppose to be a game?
that's just where people post their challenges and other people solve it
using AI
kinda, yea
yo
yoo
I got a problem
whats ur problem
pyproject.toml lines 16 to 22
dependencies = [
"panda3d>=1.10.15",
"panda3d-gltf>=1.3.0",
"pillow>=12.0.0",
"pyperclip>=1.11.0",
"screeninfo>=0.8.1",
]```
line 53, in get_guess
current_stage += 1
^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'current_stage' where it is not associated with a value
most answers on cgse use some kind of golf-oriented language anyway. It isn't particularly insightful unless that's what you're into
what??? but I must optimize the production code for storage
e.g. this runs in <200ms, rather than the 4.4s of the quadratic code
lim = 10000
for n in range(1, lim+1):
d = 1
divs = []
while d <= n//d:
if n%d == 0:
divs.append(d)
if d < n//d:
divs.append(n//d)
d += 1
that's right - you don't have current_stage defined in that function, and my guess is it isn't available as a global variable either.
huh...
I defined current_stage earlier!!
I wish I knew how to use a golfing lang
whats that
microcode compiler devs be like:
but you didn't pass it into that function, and you probably didn't define it as a global. pass it into the function
would you like to learn a programming language?
What if I make it global?
How do i do that
wdym?
it would be easier to pass it into the function.
APL
it's pretty crazy what people get up to
and more recommended.
is there a language for golfing
alr.
multiple
yes, there's a programming language
I am trynnna learn lm with this book Hands-On machine learning and I am on the second chapter of the book and while tryinng to create a method to create a test set : ```py
import numpy as np
from zlib import crc32
def test_set_check(identifier, test_ratio):
return crc32(np.int64(identifier) & 0xffffffff < test_ratio * 2 ** 32)
def split_train_test_by_id(data, test_ratio, id_column):
ids = data[id_column]
in_test_set = ids.apply(lambda id_: test_set_check(id_, test_ratio))
return data.loc[~in_test_set], data.loc[in_test_set]
housing_with_id = housing.reset_index()
train_set, test_set = split_train_test_by_id(housing_with_id, 0.2, "index")
damn that looks interesting
my least favourite language I've ever had to use has gotta be prolog
they're often stack or array programming languages, so maybe start with Forth or J?
that shit drove me insane
comes with requires an 800 dollar proprietary keyboard too /hj
there's also uiua, which has a cool website
check your parentheses in test_set_check, you're doing the comparison inside the crc32 call
I am getting an error
that is rather unhelpful, what error are you getting?
Finally doing your job
My problem is solved
did u use AI
Thanks mate, appreciate it.
I might have a look at J, every golfing lang I've looked at before just seems impossible to learn
No why
the /hj is because it actually costs only 400 dollars /s
It's solved
while you're at it, check out the J source
Why is it that my code didnt work but this does? ```py
variable = "hi"
def hi_printer():
print(variable)
hi_printer()
really gives you an insight into the mind of its creator
what was APL useful for if it requires a custom keyboard? were they a lot cheaper back then?
you can read globals fine, but assigning to them makes python think they are local
so like doing -= and +=?
yeah, having assignment in the function body is what makes Python treat it as a local variable
var = var + stuff
it is somewhat unintuitive
adress them as global variable in the functionn
it execute this from right expression
and is the best way to assign a variable within a function making a parameter specifically for that variable to be passed in?
(unless, of course, you declare it to be global)
oh hm
it sees var and it searches for var
dont use globals, it makes it really hard to track
yeah passing it as an argument is way better than using globals honestly
yea use a class
they were cheaper, I think they went for only 300 dollars at the time...
useful? it's literally called a programming language, someone was just having fun (and wanted to make money selling keyboards I guess)
(nowadays, you can of course just change the keyboard layout digitally)
but how do i use globals
you dont
99% of the time you dont need globals
if your function relies on some kind of mutable state, you want to pass that state into the function

then it will be like prop drilling maybe not drilling
mutable stands for something that can be changed
global current_stage
current_stage += 1
print(f"Wrong! You have {5 - current_stage} guesses left!")
``` idk it looks nice
very nice
it's a hack and should be treated as such. you want to pass current_stage into your function and get it back out again. if you have a lot of things that are getting mutated like this, you want to make an object to hold them and work with the object
yeah but my function just wants to change one variable in this scenario
cant hurt too much to use global right?
It's like drugs
you only do this when prescribed
bad habit
solidifies my statement
generally it is proscribed though
do you have an example where its bad?
It makes it so that a variable gets broader scope
look at this
it's not a habit to get into. pass and receive values.
this problem worsens with project size
the more you rely on globals to do anything, the more difficult it becomes to manage your project's state reliably
hm ok
and again, if you're passing a lot of values into a function, that's a sign you may want to contain all that state in an object.
well if you're right i'll do the convoluted thing
What should I learn as a complete beginner (know SOME things) to start
I think you just have to accept the wisdom that global variables are a bad idea
if your project has anything more than a few hundred lines, you are going to accidentally mutate global variables
it's not convoluted
it looks convoluted at first, but it ends up being the better long-term choice.
you just havent learnt it yet
This I can understand
as you build larger projects the choice to avoid global variables will make more sense
this is like saying python is hard because you havent learnt python
Agreed
yeah i shouldnt have that attitude about learning a convention that most programmers use
it's not even a convention
i just started using snake_case with this project im doing actually
it's a common thing to encounter when learning this stuff.
it's objectively easier to read
!d globals
globals()```
Return the dictionary implementing the current module namespace. For code within functions, this is set when the function is defined and remains the same regardless of where the function is called.
Guys I Said what should I learn as a big beginner to start.
!d global
7.12. The global statement
global_stmt: "global" identifier ("," identifier)*
The global statement causes the listed identifiers to be interpreted as globals. It would be impossible to assign to a global variable without global, although free variables may refer to globals without being declared global...
where are people learning globals anyway?
what resource is teaching people about globals
Guysss
there's a lot of archaic and badly written teaching material out there that gets good SEO
!res see the post following mine for some good places to start.
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
im just worried that there might be some chapter on globals lurking somewhere in !res
learn python we suggested you
i hope there isnt
I mean what should I start with
there's discussion of it, but always in the right context.
alright
pick a resource and start with it ,see if it's to your taste.
Read this first #python-discussion message
hey, globals are not inherently bad
Ig tutorials written by ppl who know how to use but dont really understand globals or any bad practice, it kinda gets the job done so they end up using it
globals are fine when they're read-only
the less you mutate what a top-level name points to, the better
even then, it's not really well organized
where would you put them?
Alright
Finally at work
Dammed maintenance decided to do the fire drill literally as I was walking into the building
Time to test the thing
What thing
depends
but i always put them in some namespace
didn't they just test it?
yk a module itself is a namespace too
like the global namespace?
inside a class?
what if it doesn't make sense inside the class
then inside the top level of the module
Uh... I feel like it's been a bit
But we have do them like quarterly
oh, no, I thought the thing was also a fire drill and you wanted to do another one again
Oh, no, I got nerdsniped above

Oh I just realized
Yeah it's a "bring your own Blender"
You have to tell Ursina where Blender is
They're completely seperate
well i'm gonna disable internet rn and do a stress test to see if it's absolutely required
ursina/scripts/_blender_scene_to_ursina.py line 13
blender_executable, blend_file = sys.argv[:2]```
It's not
It's only required if you use the Blender scripts
kay
also i was gonna put modernGL as a .whl file, BUT it seems like it's not available
for py 3.14
i came on here & saw smth about building from source
so should i do that? and if so, how?
Anyone here ever fix an issue in GitHub of a repository?
yeah all the time, you looking to make your first pr or what
yep, definitely, never done it, it sounds fun
nice, best way is finding a repo you use and checking for good first issue tags
Will look forward to it!
feel like im still a noob for it
don't wanna mess other people's codes
honestly everyone starts there, just find a small bug or typo first
Nah I believe Github has something called branches that allows you to not disturb anyone's code
that'd be pretty hard to do
practically impossible
rlly?
Indeeed I agree
yeah you cant actually break anything, the owners have to approve your code first
Yes Sir, they'll also review your code and give comments
makes sense
idk how i didn't thought about that possibility
no worries, we learn!
i need guidance
just ask your question
i have exams in python and am not studying
but what if they need guidance not answers
🙄
i am procrastinating
close Discord
we can't help you with that. that's on you
Colors and RGB Systems, A case study. Image Processing – Basic image processing with inbuilt
functions. Graphical User Interfaces – Event-driven programming, Coding simple GUI-based
programs : Windows, Labels, Displaying images, Input text entry, Popup dialog boxes,
Command buttons, A case study.```
That will be a hard problem
this is what i need to learn
honestly skip the book, just try building a simple game or script instead
earlier chapters i completed in like 10mins because they were basics of python
now here comes graphics
"basic image processing with inbuilt functions"?
what built-in functions are there for image processing?
The longer it takes to start, the longer it takes.
I suppose you could conjure something up with tkinter, I'm sure it has a way to export graphics
but i don't get the panic. i feel overconfident
unless you're expected to parse image files yourself
!d Image
No documentation found for the requested symbol.
ooh
class PIL.Image.Image```
This class represents an image object. To create [`Image`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image) objects, use the appropriate factory functions. There’s hardly ever any reason to call the Image constructor directly.
• [`open()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.open)
• [`new()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.new)
• [`frombytes()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.frombytes)
not builtin ?
nope, gotta install it
PIL? no
so what should i do. should i watch yt on tkinter and turtle or read the boring pdf
Check out https://goodfirstissue.dev/
and it feels outdated too
You should go study
Thanks!
your textbook, to be clear
don't study the Python docs [right now]
am in python discord. so isn't it kind of studying
Not when you're offtopic
you're 🤓
i am going to watch youtube
(edited) 🤓
try coding along while you watch, it'll stick way better than just watching
i don't have a textbook am looking at some pdf notes prepared by my seniors
and it feels outdated
ok
i mean thats my textbook
which is boring
and outdated
and lot of text
less code
honestly just mess around with turtle and draw random shapes, way better than reading text
how to learn __mro_entries__ protocol alongside descriptor precedence rules without confusing myself about normal inheritance?
Hello there
i see, you can just do that, why did you talk about blender?
I am new to this community
I am a python learner
Happy to be here
I am also ready for collectorative projects 😁
cuz it said it was a dependency for blender on the PYPI page. figured later it wasn't required
you can just download all dependencies from pypi and install them offline
Ursina has Blender listed in their README as an optional dependency so they thought it was required
But Ursina only uses Blender in scripts that take the Blender binary as argv[1]
yeah, the blender package has been dead for some time now
but remember to get the right platform and version of all dependencies since you cant rely on pip @hidden laurel
tested all the required packages
mro entries is basically just a hook for resolving bases, keeps it separate from lookup
now i came here to get modernGL from the github page, since there's no version for py 3.14
how to install it from the github directory?
does the git repo have a 3.14 version?
what about the rest of the stuff they asked about?
can't find one
then you cant use 3.14 with moderngl unless you build it from source. but that does not mean you can use an unsupported version
i could build moderngl from source
i mean ok
but i could also use pyopenGL maybe?
then again it feels much harder to set up
i dont know what you are doing
descriptors are just data vs non-data, data ones always win over the instance dict
if you already know how to write opengl code, then it does not matter much, if you dont know, i suggest you use moderngl
right
my friend doesn't
here are ursina and moderngl installed on 3.14
soooo modernGL would be preferable?
right
just remember to get all requirements, and also do the installation on the same platform so you can see what requirements you need
ig win10 amd64 follows the same need as win11 amd64
well, how would i build from source on it?
by using git clone?
correct
remember to do this in a venv, so you dont a mixup with your installed packages
nvm
but ofc, you have to do that on windows, or, distrobute and install from source
yeah, i did that after testing that i could install it
i used setuptools and build to do it
what i mean is
i opened git bash in the folder i wanted to clone it to
didn't work, said i didn't have the correct key
cool, just remember you'll likely need visual studio build tools to compile it
use the https url instead of ssh, way easier if no keys
and siince your using windows, you should just use your windows terminal
only repos you have ownership to, are repos you can clone with ssh @hidden laurel
thats why i shared the https version with you earlier
it's working
nice one, glad it worked out
remember to test the whole install from whl process in a new venv without internet
ima just
pip uninstall everything i have installed already
loops are so op sometimes
you can also just make a new venv
cuz i don't use python much
then a new venv is simplest
how?
just run python -m venv .venv in your folder then activate it
thx
!venv
Virtual environments are isolated Python environments, which make it easier to keep your system clean and manage dependencies. By default, when activated, only libraries and scripts installed in the virtual environment are accessible, preventing cross-project dependency conflicts, and allowing easy isolation of requirements.
To create a new virtual environment, you can use the standard library venv module: python3 -m venv .venv (replace python3 with python or py on Windows)
Then, to activate the new virtual environment:
Windows (PowerShell): .venv\Scripts\Activate.ps1
or (Command Prompt): .venv\Scripts\activate.bat
MacOS / Linux (Bash): source .venv/bin/activate
Packages can then be installed to the virtual environment using pip, as normal.
For more information, take a read of the documentation. If you run code through your editor, check its documentation on how to make it use your virtual environment. For example, see the VSCode or PyCharm docs.
Tools such as poetry and pipenv can manage the creation of virtual environments as well as project dependencies, making packaging and installing your project easier.
Note: When using PowerShell in Windows, you may need to change the execution policy first. This is only required once per user:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
this tags has all the details, iif pandaxxs message is not clear enough, you have to read all of this
all words

in this dummy code, (i am begineer in python) it shows an error for comparing int with lists:
class Student():
def __init__(self, name=None, marks=None):
if name is None:self.name= [str(input("Enter Name: ")) for i in range(1,4)]
else:
self.name=name
if marks is None:self.marks = [float(input("Enter Marks: ")) for j in range(1,4)]
else:
self.marks=marks
def sinfo(self):
print(f"Name:{self.name}")
print(f"Marks:{self.marks}")
def remarks(self):
ko=self.marks
if ko>=90: return "Excellent Work!"
elif ko>=80: return "Almost Perfect"
elif ko>=70: return "Scope for Improvement"
elif ko>=60: return "Needs More Effort"
else: return "Serious Underperformance"
def grading(self):
pass
print(f"Your Grade is:{Student().remarks()}")
@hidden laurel how did you know what dependencies to pick if you did not use a venv already?
something that is true needs to be stated often
Can you share the exact error message?
error
Enter Name: ss
Enter Name: ds
Enter Name: ds
Enter Marks: 98
Enter Marks: 56
Enter Marks: 12
Traceback (most recent call last):
File "c:\Users\Srinjoy\Desktop\Untitled-1.py", line 25, in <module>
print(f"Your Grade is:{Student().remarks()}")
^^^^^^^^^^^^^^^^^^^
File "c:\Users\Srinjoy\Desktop\Untitled-1.py", line 16, in remarks
if ko>=90: return "Excellent Work!"
^^^^^^
TypeError: '>=' not supported between instances of 'list' and 'int'
well.. good luck, im off! ping me if there is anything more i should answer!
self.marks is a list of values, and you are comparing the whole list to a single integer value
Ah, but the error is that you're doing:
self.marks >= 90
```when `self.marks` (or `ko` as you alias it) is a `list`
how do i fix
Depends on what you want to do
try looping through the list and checking each mark one by one
Check if any of the marks are above a limit? Check if all of them? Check the average etc
Also why are you doing range(1, 4) instead of just range(3)?
maybe try sum(self.marks) / len(self.marks) to get the average mark first, yeah that should work
We don't know that they want to get the average though do we?
wuh?
oh wait u can do that...
my school taught python to the absolute basic level so i decided to learn it on my own, guess they didnt even teach the basic of basic 😓
official tutorial is actually really good for catching those small basics
The range function takes 1, 2, or 3 parameters.
range(start, stop, step)
Some examples:
range(5) -> 0 1 2 3 4
range(2, 8) -> 2 3 4 5 6 7
range(0, 10, 2) -> 0 2 4 6 8
the other guy sent a github link to a setup.py or smth.yaml with the given dependencies
run awayyyy
i mean
environment.yaml for Conda?
it's not hard
no i just remember it ended with ml
how frequently do you tell others at your company to stop picking up random USB sticks from the ground and inserting them into company computers?
Could it've been a .toml?
ah
pyroject.toml
That's much better
Open a help therad then 🙂 #❓|how-to-get-help
Also for IDE hinting stuff like this I would recommend you use type-hinting. E.g. if I just put this above the __init__ function:
names: list[str]
marks: list[float]
```then my IDE immediately gives me yellow warning squiggles for the `ko >= 90`, `ko >= 80`, `ko >= 70`, etc. lines with this warning message:
```py
Expected type 'list[float]' (matched generic type 'list[_T]'), got 'int' instead
So this tells us the same thing as your error, but before we even have to run the program
Unfortunately that's literally part of our procedures
to pick up random USBs from the street and plug them in company computers?
At least they stopped putting them in their noses.
We use USB sticks to put datafiles into multi-million-dollar machines
One of the machines is so old it has a floppy->USB converter in it
The department supervisor literally just has a cup of USB sticks in their desk drawer
at that point it might as well be a safety measure to actually use floppy disks instead
oh we have many
I hate USB-sticks. I never need them, until I need them for the most random thing possible, and of course by that point I have no clue where any of them are anymore.
I keep one on my key ring for exactly that reason
- the 2 that I do know of just don't work (properly) anymore
I back up my most important files to usb sticks, which are highly renowned for their long-term data storage reliability
And I'm going to bet they're not standardized (color or style) in some distinctive way, like "ONLY USE RED USB STICKS THAT SAY XYZ"
just random usb sticks gathered from around various conferences probably
I also have two cups of them in my desk because another department's machines demand specific brands/sizes
goes to make a cup of coffee
destroys data worth millions
I actually just did a backup two days ago. My dad had a spare 500 GB HDD from idk when, but it's still using USB 2.0 and it's LOUD
Nope, it's just like, https://www.amazon.com/dp/B0CL45M6HR , so they're all completely assorted
That would trigger me. I'd at least have a clear policy with distinctive USB sticks such that they may only be used in machine A or B.
Do you want a stuxnet? Because that's how you get a stuxnet.
Apparently the drive was built somewhere between 2007-2010
btw i built moderngl from source
you just know that shen is that one lone brick on the right side holding up all the cybersecurity demands of that company
There's a great documentary on the use of unsecured 3d printers and similar devices
how can i test if it works with a simple test .py file?
just try creating a context and printing the info, should show your gpu details if it works
I just watched the original Tron last week
It was nothing like the newer ones
I still need to go back and watch the rest
uhh
How distinctive? I like these
https://www.amazon.com/dp/B096QZLG77
do i make a py file with that? if so, how do i run it from the venv?
Love that. "If it aint a dragon, it aint firing" or something catchier.
activate it first then just run python followed by your filename
activated already
nice, just run import moderngl; ctx = moderngl.create_context(standalone=True); print(ctx.info) in a script
It wouldn't actually fit in the machines -- but I can dream!!
I'd totally buy 6in USB extensions just to use those
I may appropriate company funds on the upcoming April Fools day
could i run from simply typing it in powershell?
yeah just do python -c "insert code here" or just open the repl
When should I start implementing UI (I'm 20 days in learning python)
get the basics down first, then try flet since it's super easy for beginners
UI? UI is a pretty broad concept, it also includes terminal interfaces yk, so, anytime you're using input, you'r implementing a UI
now, maybe you meant GUI... (which is pretty likely) but anyway
does it usually default to openGL 3.3 when the version isn't specified?
You're already implementing a UI whenever you call input.
You're probably explicitly talking about a GUI, i.e. a graphical user interface, no?
If yes, then you don't need to worry about that for now, as learning a GUI framework won't really benefit you in learning Python/programming for now
Have you already done those projects you mentioned?
GUI
yes
What do you mean
Done (I think)
okay guys; i made gambling simulator but there are 5 slots and multiple combos!
It's kinda long, so where can i share it???
drop it in a gist or pastebin so it doesn't flood the chat
Do you have a question about it?
I guess you can open a thread in #1035199133436354600 (read #❓|how-to-get-help if you don't know how) and give it the Code Review tag
uhh its too long by ~770 characters
just put it on a gist and post the link here
how
go to gist.github.com, paste your code, and then just share the link here
has anyone gotten into an argument with their recruiter on the phone screening before? because what just happened to me is genuinely unbelievable…
What happened?
What's float?
!paste
So that everyone can easily read your code, you can paste it in this website:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
I made it at school computer and i send it myself to gmail and i pasted it straight from it, if i didn't notice it would paste it with my FULL NAME.
man oh man, i start the phone screening at around 8:45 AM, and he starts off normal. He then asks me “tell me about yourself” which is standard and i start talking, i know in my head to keep it concise because they’re always busy, so i try to keep it under 30-45 seconds. Not even 10 seconds into me talking, he cuts me off telling me to speed things up…
i said “with all due respect sir, i haven’t even said anything yet and you want me to move on?”
He then asks me about how i used pytorch in my project, and as i’m explaining it to him, he completly shits on me saying “that was very poor implementation”…
Sorry that happened. I'd say its a rare occurrence.
Mind you, he has the github link and was more then welcome to check out the repository for my project.
It's kinda funny just how much quotation marks matter in Python. I had some code using findText on a QComboBox and was like "why isn't this working", and it turns out it was because I instinctively put down "-1" instead of -1. It's always the little things that get you.
i emailed HR instantly withdrawing my application
Quotation marks and spacing are the Big Two deceptively important things, I think.
I dont think you need to declare credit as a global
@steady rain have you ever experienced anything like this???
I had a pair of interviewers laugh at me once, but they were offering at most 60k for that position, so I didn't care.
and I could tell they were probably only going to offer 50k. that's like a poverty wage here.
I hope you also told HR why you were withdrawing it, with details of the interviewer's name and behavior.
i did, it’s astonishing to me how entitled some people can be.
also, isn’t it a senior devs job to tell someone if they’re project is shit or not?
it's possible he was being intentionally difficult to see what you would do, but I still don't approve.
i've had that before, ended up for the better (got much better opportunities which i wouldn't have otherwise)
i came off respectful when he cut me off, i said “with all due respect sir, im not finished, ive only said my university” and then proceeds to shit on my project entirely😢
I would not work for any outfit where the screening process consisted of trying to provoke me into an intemperate reaction.
How do I make it say _e whn u gues a corect leter
For my hangman game
anyways, i’m gonna remove my project from my resume and start working on a new one
if you like the project, keep it. have you shown it here?
hey guys, do you know how can I revert a commit? Im in the github website.
i love the project but i haven’t shared it here.
if you share it here, you can get some friendly assessments
what if someone stole the project 👀
just slap a license on it and you're usually fine
You can only do that through GitHub if you have a pull request for the changes
Wow, that’s very unprofessional of them!
Sorry that happened
oh yeah for hangman just keep a list of underscores and update the index when they guess right
Its depends how he said that. Being direct and honest is not bad, if he has technical reasons and explains them too (estou dizendo em caso que ele não foi cuzão)
https://docs.github.com/en/desktop/managing-commits/reverting-a-commit-in-github-desktop through using this maybe
float is just any number with a decimal point, like 1.5 or 10.0
Thanks for the help!
you want a literal underline under the character? in a terminal?
might need to use ANSI escape sequences then (or rich)
something like this
ANSI_UNDERLINE_TEMPLATE = "\x1b[4m{text}\x1b[0m"
word = "thing"
guessed_letters = {"t", "n"}
for letter in word:
if letter not in guessed_letters:
letter = " "
underlined_letter = ANSI_UNDERLINE_TEMPLATE.format(text=letter)
print(underlined_letter, end="")
print()
