#python-discussion

1 messages · Page 313 of 1

granite wyvern
#

A mix. Until something works may be a while

frigid coral
#

yea built some projects

raw bramble
opal gull
#

very different answers here, first is architecture, second is freestyle, and third is both lol

#

i guess it depends on the person

crisp jay
#

im trying to be more mature (in cs and software engineering) but there is a feeling that i hit a ceiling and cant go further

raw bramble
vale wasp
granite wyvern
#

There’s a tutorial on their website

raw bramble
raw bramble
opal gull
#

but i think ideally, you should get something working first to know what abstractions you need and don't need

frigid coral
raw bramble
opal gull
#

every software has an architecture

raw bramble
#

I bet my software doesn’t

opal gull
#

like rest apis

opal gull
#

just that maybe it isn't good

#

spaghetti code is still, in a way, an architecture

raw bramble
#

Oh I hate spaghetti code

#

All classes at the start, unless they’re not relevant till way later on

#

Functions should try to be in the order in which they will be used

vale wasp
#

That's organization, not architecture.

opal gull
#

i usually follow the "newspaper article" pattern, where the important ideas are at the top, and the more concrete details go at the bottom

#

but yeah that is just organization, not architecture

raw bramble
#

Idk what you mean by architecture then

vale wasp
#

Designing APIs and interactions.

granite wyvern
#

Kind of the hierachy of classes or structures or layers

#

Not the lexical layout of things in your code as such

raw bramble
#

I avoid subclasses because I don't like them

#

I guess that's it

granite wyvern
#

Easily done. Provides you ignore that fact the every one of your classes subclasses object.

opal gull
#

composition over inheritance!

vale wasp
#

Inheritance can be useful.

opal gull
#

most of the time, i only want inheritance because i want shared helper stuff between subclasses
so i usually replace it with the context pattern

granite wyvern
# vale wasp Inheritance can be useful.

I do a fair bit of inheritance, but deep stuff gets harder. Composition using mixins scales sideways fairly well. And composition using embedded things inside the main instance also works fairly well.

raw bramble
#

How do you do composition in Python?

vale wasp
vale wasp
raw bramble
vale wasp
granite wyvern
raw bramble
coarse salmon
vale wasp
# coarse salmon When?

I did a parser for cooklang. I created a base class for the Ingredient, Cookware, and Timing objects since they had enough in common that it made sense to have a base class for them.

opal gull
coarse salmon
granite wyvern
raw bramble
#

I need to start using python again and learn a whole lot more, but I don't have PyCharm or VSC rn 😭

pallid garden
#

just do it

coarse salmon
#

Yea

granite wyvern
raw bramble
raw bramble
#

I use nvim but I don't have any plugins or anything at all, so it's just a fancy text editor for me rn 💔

raw bramble
#

I've installed Lazyvim in the past but it's just so maximalist

#

And I don't really know how to install things for Neovim

pallid garden
vale wasp
granite wyvern
raw bramble
#

Roblox in the big 26 😔

#

To think prime Roblox was 10 years ago

pallid garden
#

i know it uses some fork of lua

raw bramble
#

It uses Luau

opal gull
#

luau is genuinely peak

vale wasp
raw bramble
vale wasp
#

lua is a programming language. Luau is a polynesian party.

raw bramble
#

Ooh they updated their website

vale wasp
crisp jay
raw bramble
#

I really don't want to just download tools and start using them without understanding them

raw bramble
#

I don't really understand how Neovim works, I downloaded it and use it just for the modes. I barely know any commands other than the basic editing ones I need. I want to avoid installing a package manager or anything because all it'll do is introduce me to way too many plugins way too fast which is not what I want

vale wasp
#

.topic

verbal wedgeBOT
#
**What's your favorite PEP?**

Suggest more topics here!

vale wasp
edgy krakenBOT
jade robin
#

how does that help you

fiery yarrow
#

505 695 and 701 gang represent

crisp jay
vale wasp
# jade robin how does that help you

I do a lot of CLI tools. It means that I don't need to import everything that all the commands need, I just need to import what the command run needs.

fiery yarrow
# edgy kraken

wonder how many years multi-pep support for this command has been suggested firT

fiery yarrow
#

yes

crisp jay
#

!pep 1

edgy krakenBOT
fiery yarrow
# verbal wedge

especially as this topic tends to flood the channel fairly quickly with !pep invocations

crisp jay
#

pep is a kinda cool thing,better than the C++ ISO

jade robin
crisp jay
vale wasp
bleak moth
#

Yeah, I import everything I need at the beginning of the file.

vale wasp
#

Lazy imports should also help with circular import issues.

jade robin
#

yeah that was the only point it'll help me i think

#

the literal only library i've loading time issues with is pytorch

pallid garden
jade robin
#

the feeling when when

vale wasp
#

For some things it will probably help with less than half a second of improvement, but that's still faster.

crisp jay
#

is there a way to make 2 different modules that import one thing in common be imported only once?

vale wasp
crisp jay
subtle coyote
#

Why is 2 different modules having a thing in common anyway 😭

vale wasp
#

I think it doesn't parse more than once but it creates objects for each module that imports it, but I'm not 100 sure.

subtle coyote
#

Just make a separate module

pseudo coyote
#

What does parse mean

vale wasp
vale wasp
subtle coyote
vale wasp
subtle coyote
whole snow
#

hey can anyone guide through to learn Python . where do i start and how can i speed up BY using AI.

edgy krakenBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

subtle coyote
#

You don't speed up by using ai when learning

fiery yarrow
#

using llms or any other type of ai is considered very dangerous for newbies like yourself. they're prone to lying, and you're not knowledgeable enough yet to be able to tell when that happens

subtle coyote
#

You learn by struggling

crisp jay
heady basin
#

why are keyword only paramteres not allowed after * parameters?

def foo(*bar, *, baz):
    pass

foo(1, 2, 3, baz=4)``` this wouldnt break anything, no?
ionic bluff
vale wasp
vale wasp
subtle coyote
#

Does it work?

heady basin
#

yes its gonna error at function definition

#

but I dont understand why that rule is in place, it can just work, no?

rugged viper
vale wasp
subtle coyote
heady basin
crisp jay
subtle coyote
rugged viper
#

also just use backslashes:

"You can't have a bare *, after *args"

rugged viper
#

i meant *, is valid syntax, just not in that context.

subtle coyote
#

Oh

rugged viper
#

*, <-- this works

vale wasp
subtle coyote
#

Not after

rugged viper
#

*bar, *, baz doesnt work

subtle coyote
#

*args tho

vale wasp
#

.topic

verbal wedgeBOT
#
**In what ways has Python Discord helped you with Python?**

Suggest more topics here!

vale wasp
# verbal wedge

It has shown me new perspectives on things. I have learned some nuances (and things) that I didn't know before.

granite wyvern
granite wyvern
crisp jay
#

i might make a dumb question but is it possible to optimize python bytecode when compiling to it?

#

like what c/c++ compilers does

vale wasp
silver plover
#

Like, as a user, rewriting the bytecode won't get your far

vale wasp
silver plover
#

The point I'm making is that: as a user, you can't 'hand write' optimized code

vale wasp
#

Definitely.

silver plover
#

And that specialization is not at compile time, there's no way to optimize early... afaik with how specialization is instrumented

vale wasp
#

I know. I'm just saying that the core devs have been working hard on performance improvements for everything.

silver plover
#

Yup, I'm just being literal about their question

vale wasp
#

If you understand how certain things are interpreted into the bytecode you might be able to do some things that will result in more optimal bytecode, but I don't think there is a flag you can set (other than to turn the JIT on) that will do optimizations.

silver plover
vale wasp
silver plover
pallid tiger
#

Ah this logo is better then the previous one

dry pike
#

this is the default one

pallid garden
#

not python: is it possible to allow connection to a postgres for only a specific docker container?

ashen cipher
#

mandatory usecase?

pallid garden
#

i dont understand

ashen cipher
#

what's your usecase

pallid garden
#

to use psycopg2 to connect to it from the other container

ashen cipher
#

can you not use them in the same container?

pallid garden
#

well, it's a proof of concept

#

im trying to mimic a network of servers

pallid tiger
dry pike
#

pretty sure this is the default one for the discord server

ashen cipher
ashen cipher
#

yeah

pallid garden
#

seems like a bad network security idea

ashen cipher
#

postgres has oauth

#

erm

pallid garden
#

im just going to do a subnet

peak relic
pallid garden
#

i also added host omop postgres 172.18.0.0/16 md5 to pg_hba

#

but it's not working

peak relic
#

Where are you accessing the postgres container from? The same machine or over the network?

pallid garden
#

another docker container

#

on the same subnet

peak relic
#

Not in a docker-compose.yml setup?

pallid garden
#

the docker bridge is working, im getting (172.18.0.3), port 5432: Connection refused

pallid garden
peak relic
#

If its in a compose setup, then they should already be in the same default docker network. Probably don't need to edit the pg_hba.conf. Just pass the usual postgres credentials

#

example docker-compose.yml

version: '3.8'
services:
  postgres:
    image: postgres:16
    environment:
      POSTGRES_DB: mydb
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypass
    ports:
      - "5432:5432"  # Optional: for host access

  app:
    image: myapp:latest  # Or build: .
    depends_on:
      - postgres
    environment:
      DB_HOST: postgres  # Use service name as hostname
      DB_PORT: 5432
      DB_NAME: mydb
      DB_USER: myuser
      DB_PASS: mypass
pallid garden
#

i have

    networks:
      - testing-subnet
```on both
#

docker network inspect also confirms that both are on the same subnet

peak relic
#

hmm

peak relic
pallid garden
#

i can confirm that i have EXPOSE 5432 on the db dockerfile

#

oh wait

#

let me try to add the -i and -h

peak relic
pallid garden
#

perfect

#

turns out just having it inside the pg_hba.conf is not sufficient

#

you need the -i as well

#

sorry about that friends

mossy sigil
charred tusk
#

EXPOSE “advertises” what port is being sued
But if you don’t add the correct --port flag to docker run then it doesn’t actually expose anything.

charred tusk
pallid garden
#

strange, right?

charred tusk
#

It’s not supposed to

pallid garden
#

docker is just a jester like that

charred tusk
#

Did you define the port in your args or your compose.yaml?

pallid garden
#

this is the CMD: CMD ["postgres", "-i", "-D", "/etc/postgresql/16/main/"]

#

and compose.yaml is unchanged from the current committed file on github

#

to up it im just running sudo docker compose up <db-name>

edgy krakenBOT
#

compose.yml lines 72 to 73

ports:
  - "5432:5432"```
charred tusk
#

This does the actual binding

pallid garden
#

i see, so there is no need to

expose:
  - 5432
#

TIL

charred tusk
#

Not sure
I didn’t even know that could go there

charred tusk
# pallid garden TIL

So imagine you have 8 different Dockerfile(s) that all run their app on port 8080.

In the first you could put ports: 9001:8080
Then in the second put ports: 9002:8080
And so on and so forth

The ports mapping is where you tell Docker what port to get from the host network.

pallid garden
#

so i would go to localhost:9001 to access the first app?

charred tusk
#

Yea

stray field
#

So EXPOSE is like MAINTAINER

#

Completely useless

modest obsidian
#

How do I make a crypto mixer in python

ionic bluff
fallen locust
#

Hi, I’m learning Python with 100 Days of Code. Happy to join 👋

ionic bluff
modest obsidian
#

?

#

You can’t speak proper english

#

Refrain from speaking to me mate

ionic bluff
#

why do i get the feeling this is the same guy talking to himself?

modest obsidian
#

Mixers aren’t illegal

#

do your research before talking

#

Who are you again

#

Ur an attention seeker move

#

Nobody cares about you this enough

#

<@&831776746206265384>

visual juniper
modest obsidian
#

Yes boss, we can talk once you learn proper English

#

Now stop wasting my time

ionic bluff
modest obsidian
modest obsidian
#

Lol this is not what a mixer is but okay

fallen locust
#

Anyone here also doing 100 Days of Code? Would love an accountability buddy.

modest obsidian
#

Mixers are used to obscure the transaction origins, it’s used for privacy matters

#

You obviously don’t know what you’re talking about

visual juniper
#

<@&831776746206265384>

modest obsidian
#

Mixers aren’t illegal in neither the US or EU if no illicit funds are passed through it

modest obsidian
visual juniper
#

we need more mods with eastern timezones

ionic bluff
#

yeah lol

modest obsidian
#

7 moderators online, not one in the chat rn

fallen locust
#

Hi 👋
I’m currently on Day 3 of 100 Days of Code.
I’m serious about building strong Python foundations and moving into AI long-term.
Looking for an accountability partner at a similar level to grow consistently.
Daily check-ins + small weekly projects.
Anyone interested?

modest obsidian
#

Can you please stop coping with the fact that you’re poor @silent spindle

#

We don’t want to hear it

#

you’ve never touched 4f in your life please stop

#

lmfao

visual juniper
kind thicket
#

<@&831776746206265384> ableist troll

modest obsidian
#

Can the moderators get on already?

jagged belfry
#

!mute 1462338246775148691

edgy krakenBOT
#

:incoming_envelope: :ok_hand: applied timeout to @silent spindle until <t:1772348203:f> (1 hour).

modest obsidian
#

👍

modest obsidian
#

What does TLDR stand for

jagged belfry
#

!cleanban 1462338246775148691 troll

edgy krakenBOT
#

:incoming_envelope: :ok_hand: applied ban to @silent spindle permanently.

fallen locust
velvet trout
#
class Hub:
    @staticmethod
    def create(
        kind: type[EventA] | type[EventB],
    ) -> Ticket[EventA] | Ticket[Bundle]:
        return Ticket[?????]()

        #if kind is EventA:
        #    return Ticket[EventA]()
        #else:
        #    return Ticket[Bundle]()

Any idea what to put in it? The comment version works but i want not to repeat.

#

Ticket is Generic over T, where T is EventA | Bundle.

marsh obsidian
#

Guys i won my first high-school microsoft hackathon today.

I am 13 years old

#

I got 300 dolllars and a trip to seattle for the national competition

visual juniper
quartz fulcrum
#

well done

kind thicket
#

and why was it a python program?

marsh obsidian
pallid garden
#

wait, which category does that fall into?

marsh obsidian
marsh obsidian
kind thicket
marsh obsidian
marsh obsidian
kind thicket
quartz fulcrum
velvet trout
ashen cipher
#

okay my brain is confused i need someone sane

how many elements are in my_list[1:2]

quartz fulcrum
ashen cipher
#

alr ty

velvet trout
#

end is exclusive, meaning it won't include the item of end index in the slice

ashen cipher
#

look its midnight my brain doesnt process past first order thinking

quartz fulcrum
velvet trout
#

relatable i am running wild over typing in python.

ashen cipher
#

i could probably work that out but like i dont have the mental capacity at 12:08

pallid garden
ashen cipher
#

lmao

quartz fulcrum
ashen cipher
velvet trout
ashen cipher
#

i forget python has generics now

#

it is way better than typevar or whatever used to happen but i just dont write much python now

cyan scaffold
velvet trout
#

mypy didn't say there was an issue, when i put x = Ticket() reveal_type(x) it says need type annotation... What was bro doing before ? ducky_concerned

velvet trout
tacit tapir
#

anyone else love walrus

velvet trout
#

Overload helps to clarify that passed EventA/B returns Ticket[EventA/Bundle]

velvet trout
#

I love [] type parameterization syntax too

#

feels like am a hacker or something lmao

white knot
#

hi

velvet trout
white knot
#

print("hello")

#

input("how are u")

tacit tapir
velvet trout
edgy krakenBOT
fiery yarrow
#

way to express generics

velvet trout
#

Previous repliers*

cyan scaffold
velvet trout
tacit tapir
#

oh i see i just didnt know thats what it was called

cyan scaffold
tacit tapir
#

nah walrus is goated tho that was like the first new feature that got added when i started using python and i use it all the time

white knot
#

;=

#

why is it the goat

tacit tapir
#

cuz its useful frequently

cyan scaffold
white knot
#

which is more pythonic

velvet trout
# cyan scaffold That doesn't sound right. I feel like it should infer the usage and the paramete...

Opps. Wait, i actually ran this:

class Hub:
    @overload
    @staticmethod
    def create(kind: type[EventA]) -> Ticket[EventA]: ...
    @overload
    @staticmethod
    def create(kind: type[EventB]) -> Ticket[Bundle]: ...

    @staticmethod
    def create(
        kind: type[EventA] | type[EventB],
    ) -> Ticket[EventA] | Ticket[Bundle]:
        t = Ticket()
        return t
        #if kind is EventA:
        #    return Ticket[EventA]()
        #else:
        #    return Ticket[Bundle]()

t1  = Hub.create(EventA)
t2 = Hub.create(EventB)
reveal_type(t1)
reveal_type(t2)
x.py:46: error: Need type annotation for "t"  [var-annotated]
x.py:47: note: Revealed type is "x.Ticket[Any]"
x.py:56: note: Revealed type is "x.Ticket[x.EventA]"
x.py:57: note: Revealed type is "x.Ticket[x.Bundle]"

Is that healthy?

white knot
#

what does overload do. python has method overloading?

golden mortar
tacit tapir
golden mortar
cyan scaffold
velvet trout
cyan scaffold
#

Else why did you care about kind

velvet trout
# cyan scaffold Else why did you care about `kind`

I actually don't care about kind, it only affects generic T of Ticket and i want to statically type that Ticket[T] will have different T type depending upon the kind's type, the comment version was used due to earlier type errors and was working.

#

Is the current code healthy and should be like that given I don't care about kind but for type checking only?

icy quest
#

hi guys

#

has anyone hosted a website with premium features?

white knot
#

why is my algorithm analysis 50hr course finishing in like 30 pages of notes

#

all the topics feel very small

#

like this is one module for example The Control Abstraction- The Optimality Principle- Matrix Chain Multiplication-Analysis, All Pairs Shortest Path Algorithm - Floyd-Warshall Algorithm-Analysis. The Control Abstraction of Back Tracking – The N Queen’s Problem. Branch and Bound Algorithm for Travelling Salesman Problem.

#

thats 4 algorithms and chapter is over

#

am i not learning properly ducky_concerned

burnt cargo
#

I can't speak L

white knot
icy quest
#

yess

#

i wanna host my project with free and premium mode

white knot
#

You already have a website made?

icy quest
velvet trout
#
class Hub:
    @overload
    @staticmethod
    def create(kind: type[EventA]) -> Ticket[EventA]: ...
    @overload
    @staticmethod
    def create(kind: type[EventB]) -> Ticket[Bundle]: ...

    @staticmethod
    def create(
        kind: type[EventA] | type[EventB],
        #x: int
    ) -> Ticket[EventA] | Ticket[Bundle]:
        return Ticket(x)

Well, i actually want to introduce more non related params like x
But mypy yells:

error: Overloaded function implementation does not accept all possible arguments of signature 1  [misc]
error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
icy quest
#

w interview, etc features

icy quest
white knot
velvet trout
cyan scaffold
#

It wouldn't tell you this if the return type and t's type were switched, but why not just match them to the narrow Ticket[EventA] | Ticket[Bundle] from the start?

icy quest
velvet trout
cyan scaffold
velvet trout
#

Should i just go union over Generic ?

velvet trout
#

I am kind of unsure when to use Generics and Unions

cyan scaffold
solemn rain
#

Hi

#

I have one question

visual juniper
#

nice

solemn rain
#

Can I ask

visual juniper
#

you already know that you shouldnt ask to ask

#

you have been here long enough to know to just ask the question

solemn rain
#

i have a zip file now if i share that with my friend who uses windows
The packages inside site package or node modules won't work properly ?
Because i am using Ubuntu

visual juniper
#

send them the source code and have them install depedencies

solemn rain
#

I did try to make them clone the repository
But they don't have a git account and are very new to software development

They just wanted to edit some frontend html css

#

of the project

visual juniper
solemn rain
visual juniper
velvet trout
#

I am thinking of shifting to not using Generic

#

I am spending too much time on fixing this generic

visual juniper
velvet trout
#

And i am not sure what's the correct path

solemn rain
#

They said they want to edit styles

visual juniper
solemn rain
visual juniper
#

i thought this was like , you were selling ur client something

solemn rain
#

No its a group project

visual juniper
#

well , you have multiple options
base line is that , you send just the source code , and the other user sets it up on their end and developes

short solstice
visual juniper
#

you dont send node modules and python modules and stuff liek that

icy quest
#

who sends node modules

#

they are a lot

velvet trout
#

Playing Visual Studio Code ducky_concerned

pallid garden
#

for 80 days

quartz fulcrum
#

why there is a red line on the whole function and still working but says 'Explicit return statement expected'

golden mortar
lament bobcat
#

Is there a self promo section on this server?

gleaming knoll
craggy willow
#

it's for promotion literals

gleaming knoll
#

p-string

#

makes your string bold and annoying

craggy willow
#

ppppppppp

quartz fulcrum
#

lol

#

i was learning about functions calls(call stack) and i think i got the basic i.e. python doesn't forget its top function call.
if there is a nested function inside the function call then python will call that function, does whatever is written in it and comes back the main function..

but they also talked about reuturns, which is not clicking in my mind..can anyone help me with this

craggy willow
#

return leaves a function immediately, back to the surrounding scope

#

with the value after the return

gleaming knoll
#

(to the place where the call was, which is remembered by putting its address on the stack)

craggy willow
#

!e

def main():
    def foo():
        if True:
            return 1
        return 2
    a = foo()
    print(a)
main()
edgy krakenBOT
craggy willow
#

return 2 is never reached in above

quartz fulcrum
#

and what about def foo().
it has no data

gleaming knoll
#

no parameters, you mean? how does that change anything?

quartz fulcrum
#

no code

#

yes

gleaming knoll
raw bramble
#

pass, continue and return all have that same kind of functionality, right?

gleaming knoll
#

pass doesn't do anything to control flow, continue goes to the loop header, return goes to the call address on the stack

craggy willow
#

gotta have the indentity control flow

bronze dragon
quartz fulcrum
#

where the return 2 stands

raw bramble
#

I don’t know proper terminology

gleaming knoll
#

continue stays in the same scope, the loop scope
well, python loops dont have name scopes, but you get the point, the loop.. block

raw bramble
#

Mhm

gleaming knoll
raw bramble
#

How can you use pass outside of just making sure your code doesn’t break when you’ve not implemented something yet like a function?

gleaming knoll
#

you cant, it does not do anything, it is simply a blank statement to put where a statement is expected when you dont have anything better

raw bramble
#

so it’s only purpose is just to stop my code from breaking till I have the energy to finish it

#

🙂

craggy willow
#

there's some interesting uses of pass in if-elif-branches

#
if a:
    pass
elif b:
    do_something()
elif c:
    ...

something like

granite wyvern
gleaming knoll
raw bramble
granite wyvern
gleaming knoll
craggy willow
#

sure, but it's also a more interesting use case of "do nothing" here

raw bramble
gleaming knoll
granite wyvern
craggy willow
#

i used to use something like this for parsing ansi, but not anymore

raw bramble
#

if (a and not b) or (c and not d)
Just looks horrible

fossil steeple
#

i just use dicts to avoid lots of elifs

gleaming knoll
quiet shard
#

is it possible to make a python interpreter using python

visual juniper
#

yes

cobalt flax
#

Isnt pass just for not doing anything?

visual juniper
#

yes

gleaming knoll
# quiet shard is it possible to make a python interpreter using python

kind-of, but the more things you actually reimplement rather than just reuse, the slower it will be
(specially the object model)

and well you'll still need a python interpreter to run your python interpreter written in python, so it wont be self-sufficient, so if thats a goal then it doesnt really work out

velvet trout
pseudo coyote
#

What are classes used for in short

quiet shard
#

to create objects

slow rivet
pseudo coyote
#

What init

quiet shard
#

constructor i think (i don't use python)

nimble isle
#
a = []
b = a.copy()

Is this equivalent to ```py
a = []
b = []
b[:] = a

fossil steeple
fossil steeple
pseudo coyote
#

Thanks

fossil steeple
#

it like defines how you should make the instance and like what vars it should have and stuffs

fossil steeple
# pseudo coyote Thanks
class Foo:
  def __init__(self, name, age):
    self.name = name
    self.age = age

john = Foo("John Doe", 22)

like this

gleaming knoll
nimble isle
pseudo coyote
solemn rain
nimble isle
fossil steeple
nimble isle
#

it's a slice

#

but it slices the whole list

solemn rain
nimble isle
fossil steeple
#

@pseudo coyote check bot commands

solemn rain
gleaming knoll
# nimble isle but how do i tell the time complexity from that

the time complexity is obviously the same, but the exact time it takes will be slightly different (just because they go through slightly different code paths to end up doing the same copying loop), but it doesnt matter
imo copy is more direct to understand so use that
or atleast b = a[:] rather than empty initialize and then slice assign

nimble isle
#

...?

quiet shard
#

forget what i said because its not python

fossil steeple
#

<@&831776746206265384> @wise yarrow be messing

wise yarrow
# nimble isle basically the same as `[0:-1]`

!e not that, you can't really describe None for the stop argument with an integer in a way that works for any list, tho for fixed sizes the length works

a = [1, 2, 3]
print(a[:], a[0:-1], a[0:3])
edgy krakenBOT
wise yarrow
#

?

#

I haven't even typed anything yet...

gaunt badge
fossil steeple
#

wait maybe it wasn't u then who did htat

fossil steeple
gleaming knoll
#

the bot deleted it

gaunt badge
#

Ah, that was someone else. Our bot deleted it and banned them

fossil steeple
gleaming knoll
#

why would you think stickie do that 😭

fossil steeple
solemn rain
#

Poor stickie

nimble isle
#

can you use complex numbers as keys for a dictionary?

gleaming knoll
#

yes, why not? they are immutable, and consist of hashable parts (floats), so obviously they have a stable hash

harsh swallow
wise yarrow
#

sure, i do it all the time for AoC problems

fossil steeple
winged shale
#

Python as first programming language and what second? Should i learn C (i will need to learn it anyway in school)

nimble isle
wise yarrow
#

anything hashable can be used as a dict key

fossil steeple
fossil steeple
wise yarrow
#

and for stdlib types, if something is immutable it's probably hashable? I can't think of any counterexamples immediately at least

pseudo coyote
#

What does .append do

nimble isle
solemn rain
pseudo coyote
#

Cool

#

How to round to 2 decimals

fossil steeple
solemn rain
#

!d round

edgy krakenBOT
#

round(number, ndigits=None)```
Return *number* rounded to *ndigits* precision after the decimal point. If *ndigits* is omitted or is `None`, it returns the nearest integer to its input.

For the built-in types supporting [`round()`](https://docs.python.org/3/library/functions.html#round), values are rounded to the closest multiple of 10 to the power minus *ndigits*; if two multiples are equally close, rounding is done toward the even choice (so, for example, both `round(0.5)` and `round(-0.5)` are `0`, and `round(1.5)` is `2`). Any integer value is valid for *ndigits* (positive, zero, or negative). The return value is an integer if *ndigits* is omitted or `None`. Otherwise, the return value has the same type as *number*.

For a general Python object `number`, `round` delegates to `number.__round__`.
pseudo coyote
#

Huh

#

I tried that earlier and it didn’t work

winged shale
# timid ember Sure

Kinda off topic but is c, c++, c# almost the same? Like if i learn c will i be easily learn those?

fossil steeple
gleaming knoll
winged shale
#

I see

fossil steeple
winged shale
#

Thanks for the info

gleaming knoll
fossil steeple
gleaming knoll
#

arduino is C++ but you specifically might only be using C stuff

fossil steeple
#

but maybe i'm just mad

wise yarrow
#

there's some syntax similarities, but imo they write completely differently

fossil steeple
#

.topic

verbal wedgeBOT
#
**Have you ever tried making your own programming language?**

Suggest more topics here!

harsh swallow
pseudo coyote
#

What’s the coolest sht you guys have made

pseudo coyote
solemn rain
pseudo coyote
#

No hate

harsh swallow
fossil steeple
# verbal wedge

i made gloop which is a simple interpreter with 5 "gloops", which are:
print the current value
add a gloop to current value
add a gleep to current value
2 more which are same as above ubt instead remove

pseudo coyote
fossil steeple
solemn rain
pseudo coyote
#

Cool

#

What’s an easy game to automate

fossil steeple
#

how does one automate a game

#

do u mean code?

pseudo coyote
#

Yh mb

fossil steeple
pseudo coyote
#

Ooh

#

That’s a good idea

#

And I could use ai aswell to make him smart

#

It*

fossil steeple
#

good luck with

#

that

pseudo coyote
#

No I sleep now it’s 5am

fossil steeple
#

concerning

solemn rain
#

I am going to study travelling salesman problem

#

I saw a small video and i don't understand anything 😞

graceful oracle
#

Fellas what IDE/Code editor do yall use?

craggy willow
junior wraith
#

Hello. How do I use a third party library? I am new to python specifically.

fossil steeple
graceful oracle
gleaming knoll
opal gull
#

vscode is genuinely so peak

graceful oracle
graceful oracle
#

All valid honestly

young flare
graceful oracle
#

:0

gleaming knoll
graceful oracle
#

Ooooh thats nice!

#

Using Linux and Neovim taught me some best practices for python

graceful oracle
#

Oh hell yeah

opal gull
gaunt badge
craggy willow
#

inb4 ed

gleaming knoll
#

who is that one Ed who edits everyone's text
how is he not tired

junior wraith
#

I tried ed with rust once and suffice to say it was not fun

quiet shard
wise yarrow
#

I used to use pycharm, but ever since I've setup neovim for python dev I've been way too used to neovim to switch back

simple willow
junior wraith
#

Anyways, I can't seem to escape vim (on termux)

quiet shard
#

:q

wise yarrow
#

my neovim navigation skills are lacking tho

simple willow
#

I did try neovim on my laptop and I broke it

graceful oracle
simple willow
#

so I went back to IDLE

graceful oracle
graceful oracle
wise yarrow
#

I used IDLE for my first python project in school

#

I'm so glad I never have to use IDLE again

simple willow
#

I do really like IDLE and it does everything I need to do

junior wraith
#

The reason I'm considering hopping on python in the first place is because of the brevity

#

Compared to... c

kind helm
#

I am facing issues in running my python code in visual studio
Which environment to choose for

golden mortar
kind helm
#

The program won't run
The terminal opens, shows the path stays there freezed

junior wraith
#

I kinda want to have fun first before I go fast

nimble isle
#

I wish for loops allowed expression in their assignments: ```py
for x in range(5):
print(x)

0
1
2
3
4

But you could also do ```py
for x+1 in range(5):
  print(x)
>>> 1
2
3
4
5
junior wraith
#

The joy of actually having a finished piece of software

#

Does this server have a bot that runs python code?

cerulean ravine
nimble isle
#

x + 1 = 0 -> x = -1

golden mortar
cerulean ravine
gleaming knoll
# nimble isle x + 1 = 0 -> x = -1

this is not what your example does, by the way, its not solving for x in x+1, its adding 1 to the value in the iterable and that is what it assigns to x

nimble isle
cerulean ravine
golden mortar
#

!e ```py
print("hello world")

edgy krakenBOT
cyan scaffold
golden mortar
#

But only staff will see the output in this channel

#

Other people using it will have their output redirected to #bot-commands

nimble isle
cyan scaffold
#

No they don't need to solve algebraic equations

#

They need to loop

nimble isle
cerulean ravine
#

it alarms people, but you can do this:

nums = [1, 2, 3]
for nums[1] in range(3):
    print(nums)
cyan scaffold
#

Iterate over items specifically

gleaming knoll
nimble isle
#

they need to determine if every statement in this universe is true or false

cerulean ravine
nimble isle
cyan scaffold
#

Wait are walrus expressions valid on the left hand side of assignments?

gleaming knoll
nimble isle
cerulean ravine
nimble isle
#

yeah that's what I meant to say

cyan scaffold
#

Yeah I just checked

cerulean ravine
craggy willow
#

i've done something like:

for texture[:] in colors:
    display_texture(texture)
gleaming knoll
cerulean ravine
cerulean ravine
craggy willow
#

using a dict is fun

nimble isle
#

would it be confusing for python to bring back the goto from basic?

cyan scaffold
craggy willow
#

it would be if it used line numbers like basic

nimble isle
craggy willow
#

!pypi goto

edgy krakenBOT
#

Urllib object wrapper

Released on <t:1320774534:D>.

gleaming knoll
craggy willow
#

dammit

#

!pypi goto-statement

edgy krakenBOT
#

A function decorator, that rewrites the bytecode, to enable goto in Python

Released on <t:1546111106:D>.

cyan scaffold
#

Oh okay yes I see

craggy willow
#

there we go

#

cursed python

gleaming knoll
#

goto that would go between scopes is cursed, goto in 1 scope is fine
problem is each assignment to a "new" local variable is like a new scope but not really

nimble isle
craggy willow
#

there's been proposals for labeled breaks i think

#

!pep 3136

edgy krakenBOT
gleaming knoll
#

damn that pep is almost as old as i am. its like, 3 weeks short

nimble isle
#

I've occasionally wanted to break out of multiple loops at once.
But in those cases my code's been in a big mess anyway

nimble isle
cyan scaffold
craggy willow
#

i was older than yall when this pep was written

gleaming knoll
#

was? are you no longer older than us? did bro stop aging?

craggy willow
#

😢

#

i was, but am still

gleaming knoll
#

salt die are your parents older than you

craggy willow
#

not yet

cyan scaffold
nimble isle
#

I know someone who's younger than their niece

slow rivet
cyan scaffold
#

Oh

#

Age preservation? Username does check out

gleaming knoll
quartz fulcrum
#

can i ask a non python question here..

what i am doing is very cumbersome

cyan scaffold
#

Look at you FP master

cyan scaffold
slow rivet
edgy krakenBOT
gleaming knoll
cyan scaffold
#

You're more impressive than you realize

craggy willow
#

so not a cleric or druid

amber vine
#

Do you know about antigravity?

gleaming knoll
gleaming knoll
craggy willow
#

prbably not a monk either

mossy sigil
craggy willow
#

but wis is a dump stat everywhere else, so could be anything else

gleaming knoll
#

what class would diogenes be
i want to be that

simple willow
cyan scaffold
craggy willow
#

i feel like monk, but maybe, like, homeless rogue

gleaming knoll
cyan scaffold
verbal citrus
#

what's an FP master

craggy willow
#

well diogenes had like 22 wisdom

opal gull
#

i feel like KISS isn't emphasized enough

cyan scaffold
opal gull
verbal citrus
gleaming knoll
cyan scaffold
#

I'm kidding it stands for functional programming master

jade robin
verbal citrus
#

ah so kinda like those people who spend time speedkubing

split onyx
#

I think none of the software engineering acronyms make seense (e.g., KISS, YAGNI, ...) no one decides things in a vacuum, everything is situational 🙂

opal gull
opal gull
#

most of the time, where do you want to be

gleaming knoll
#

oh sorry, wrong interpretation

verbal citrus
#

lol home is good

opal gull
#

but unfortunately coding outside is ehhh

jade robin
opal gull
split onyx
#

Personally my style (at work) is that I don't like making "big bets" on features or architecture. I push things out ASAP, get feedback and iterate. Eventually your abstractions will no longer fit the direction of your project and then you rewrite (some of) it

gleaming knoll
#

a custom discord client written in grasst, the good brother of rust

solemn rain
#

what is P NP NP HARD NP COMPLETE

opal gull
#

pretty much dont abstract until you need it

gleaming knoll
cyan scaffold
jade robin
#

PPAD is a class too

solemn rain
split onyx
# opal gull so, KISS then?

Yes and no - sometimes you already know that a feature needs to be more complex than your baseline because of certain functional/non-functional requirements, and then you break "KISS" and "YAGNI"

craggy willow
#

tf is yagni

golden mortar
# simple willow No

If you like the simplicity of IDLE, Thonny is also a Python IDE designed for simplicity, but in my opinion superior to IDLE.

split onyx
#

you aint gonna need it 🫠

gleaming knoll
opal gull
split onyx
cerulean ravine
split onyx
#

But yeah, I think a lot of our profession is about predicting the future (with the abstractions we use). I like predicting nothing and then doing rewrites when needed

#

but your organisational culture needs to allow for this ofc

golden mortar
opal gull
#

that's true

split onyx
#

In some places rewriting is an absolute no-go, then I'd do things differently

junior wraith
#

I want to take an input image (.png), split it into a grid, output the images in the grids. Not sure where to start

solemn rain
slow rivet
#

I generally like to do a mix where the architecture is modular and flexible enough to avoid big rewrites, but the actual implementations are as simple as they can be

golden mortar
# solemn rain my university syllabus

These concepts usually come up as part of an introductory course on the theory of computation at uni, and it's a lot easier to explain (P, NP, NP-hard, NP-complete) if you have the foundations from that course.

solemn rain
# gleaming knoll i mean i think the https://en.wikipedia.org/wiki/P_versus_NP_problem page does a...

alright

An answer to the P versus NP question would determine whether problems that can be verified in polynomial time can also be solved in polynomial time. If P ≠ NP, which is widely believed, it would mean that there are problems in NP that are harder to compute than to verify: they could not be solved in polynomial time, but the answer could be verified in polynomial time.

whats the point of verifying output and categorizing them as NP.

The problem has been called the most important open problem in computer science

what problem NP == P ? i cant get that

and what is this NP hard

split onyx
solemn rain
golden mortar
solemn rain
tame vapor
#

guys what is the best GUI framework for python that looks good ? i want to make a simple GUI

gleaming knoll
# junior wraith I want to take an input image (.png), split it into a grid, output the images in...

i'd just like, think how to split the rectangle into a grid of other rectangles, what the bounds of those rectangles would be (which would end up just being dividing into equal pieces with the usual division)
then find a library to load an image into an array and then do this array splitting and then save it back to different pngs
https://stackoverflow.com/questions/5953373/how-to-split-image-into-multiple-pieces-in-python

also, no, the c++ mascot is not a diseased rat named Keith

solemn rain
#

not problems

split onyx
#

But yes, I also try designing things to be modular with simple implementations. Rule of thumb is an interface with an implementation and having none of the modules depend on other ones

junior wraith
golden mortar
jade robin
slow rivet
golden mortar
#

Did you not cover anything about computability?

#

The halting problem?

solemn rain
junior wraith
solemn rain
golden mortar
pallid garden
solemn rain
split onyx
jade robin
#

looking at algorithm classes from the perspective of turing machines often make way more sense

golden mortar
gleaming knoll
craggy willow
solemn rain
cyan scaffold
golden mortar
solemn rain
tame vapor
solemn rain
#

why do we learn that

gleaming knoll
golden mortar
cyan scaffold
golden mortar
#

It's a different task from coming up with the solution from scratch, and it can have a different complexity.

golden mortar
lunar thorn
#

i'm curious. imaging that i have a old keyboard with no customization app. Is it possible to make a app that customize the keyboard keys

gleaming knoll
tame vapor
cyan scaffold
#

I'm sure there are examples on the internet

solemn rain
# gleaming knoll why do we learn anything?

i mean we learn about TC because it helps us to study algorithms but this does not makes sense. we are making sure the answer we got is correct?
we can just look at the output

cyan scaffold
#

You can style tkinter apps with... Styles in themed tkinter. And custom tkinter doesn't look that bad but I figure it's just as rigorous

solemn rain
#

and why do we prove this

golden mortar
#

So some problems have a known non-polynomial complexity for solving the problem, but a polynomial complexity for verifying a solution, like 3-SAT.

gleaming knoll
tame vapor
jade robin
craggy willow
#

what's the time complexity of explaining this problem

golden mortar
golden mortar
#

The output is a path, but you don't know if it's the shortest path or not.

solemn rain
gleaming knoll
solemn rain
#

what do they mean when they say when a problem is hard

craggy willow
#

checking is fast, finding such a path not so

golden mortar
cyan scaffold
golden mortar
jade robin
#

i think general computational hardness just means "more than polynomial"

solemn rain
solemn rain
golden mortar
tame vapor
cyan scaffold
#

You're welcome, thanks

golden mortar
#

So solving an NP-hard problem in polynomial time is a shortcut to proving P = NP

hybrid nebula
tame vapor
#

guys are you talking about semiconductors ? i am just hearing P and NP

hybrid nebula
#

what we want to prove is NP = {}

jade robin
#

huh

golden mortar
tame vapor
#

what is P and NP

grim axle
tame vapor
#

huh

golden mortar
#

NP is the class of problems with proofs verifiable in polynomial time.

hybrid nebula
#

got confused

golden mortar
#

We already know it's not empty.

hybrid nebula
#

we want to prove NP \ P = {}

golden mortar
#

I think?

jade robin
#

everything P is already NP

golden mortar
#

yes

hybrid nebula
golden mortar
#

P is a subset of NP

jade robin
#

we know NP is a super set of P, we want to prove if P is the only set NP contains

verbal citrus
# solemn rain yea what i see is that "If every problem in NP can be polynomially reduced to NP...

aight i see i need to jump in, there is decidability and undecidability ...kay? (let's ignore semi-decidibaility for now, that's a special case)

so a problem is one of 2 ...decidable of undecidable..k?

all ez probs (ones that can be solved fast are called P solvable problems)

so these ez probs are all a subset of harder problems called NP problems (gg problems)

now these gg problems have legenedary tier (decidable) and god tier players in them (undedicable)

the undecidable ones are called NP-hard problems, the decidable ones are called np-complete ..

cyan scaffold
#

Deterministic polynomials are a subset of nondeterministic polynomials? Do I have this right?

grim axle
#

e.g. suduko.
although solving it is difficult (NP),
verifying it is rather easy, which usually takes "polynomial time" (P) or less.
like O(n¹), O(n³) or any O(n^k) for example.

verbal citrus
#

decidable just means can the algo give yes or no as an anser to a question

jade robin
#

huh

worn moat
#

Hey everyone 👋
I’m Avi, currently learning Python. I’ve completed the basics (syntax, loops, functions, basic OOP) and now I want to level up from beginner to strong intermediate.
My goal is to get solid in python eventually move towards data science + ML.

jade robin
#

decidability doesn't relate to NP hardness afaik

#

did i misinterpret it all

hybrid nebula
soft coral
jade robin
verbal citrus
gleaming knoll
verbal citrus
#

it's the quintessentional example of an np hard problem

jade robin
#

h u h

#

it's very literally undecidable by computation aka a logical paradox which can't be computed by any algorithm

#

NP hard problems can be computed even if inefficiently

hybrid nebula
gleaming knoll
hybrid nebula
#

using templates etc.

jade robin
hybrid nebula
#

he also made world's best guide to Python

verbal citrus
hybrid nebula
gleaming knoll
#

c++ templates are just a bad functional programming language

hybrid nebula
golden mortar
#

NP-hard problems can't necessarily be computed.

#

Some NP-hard problems can, others can't.

jade robin
gleaming knoll
pallid garden
#

holy shit docker prune Total reclaimed space: 16.25GB

golden mortar
hybrid nebula
verbal citrus
hybrid nebula
#

NP-hard means

for every problem L which can be solved in non-deterministic polynomial-time, there is a polynomial-time reduction from L to H

craggy willow
split onyx
golden mortar
# hybrid nebula what?

NP-hard problems are just problems that can be reduced to from an NP problem in polynomial time. It says nothing about how hard it is to solve.

hybrid nebula
#

every NP problem can be solved by a computer with sufficient memory in sufficient time

golden mortar
#

It could be uncomputable.

gleaming knoll
split onyx
#

The first time it was me being naive and not knowing this was a problem, the second time around I have a grafana setup and alerting but my sendgrid API key had expired in the mean time lol

craggy willow
#

ur mom so small...

hybrid nebula
gleaming knoll
golden mortar
#

In computational complexity theory, a computational problem H is called NP-hard if, for every problem L which can be solved in non-deterministic polynomial-time, there is a polynomial-time reduction from L to H.

steel whale
#

i'm making an image hosting service and i would like to know how i can add verification checks to uploads, to make sure that the received upload isnt a binary file, just an image

golden mortar
golden mortar
#

Just that you can reduce an NP problem to it.

hybrid nebula
#

you can check for well-formed PNGs and remove all unnecessary chunks

hybrid nebula
steel whale
verbal citrus
golden mortar
hybrid nebula
golden mortar
verbal citrus
#

i thought it was...hmmm

hybrid nebula
solemn rain
# verbal citrus aight i see i need to jump in, there is decidability and undecidability ...kay? ...

yea we classify them based on whether it can be solved and verified
the easy problems can be solved in polynomial time so that means its verification is also polynomial

the NP problems like sudoku can be verified easily but its hard to find the answer with some fixed algorithm (but can't we do something like checking all possbilities like bruteforce that solves it)
so that question asked in the wikipedia P vs NP means. "are all NP problems which can be verified P problems" ?

pallid garden
#

apparently you can have decidable problems that are not polynomial time, TIL

craggy willow
jade robin
verbal citrus
#

interesting...

hybrid nebula
steel whale
pallid garden
jade robin
hybrid nebula
jade robin
#

and most of our real systems are finite

hybrid nebula
#

wait

hybrid nebula
jade robin
gleaming knoll
#

the observable universe is finite and i dont think we have systems outside it

hybrid nebula
golden mortar
#

Like, perhaps it's not very interesting, but technically you could reduce for example SAT into the halting problem.

#

So the halting problem should be NP-hard.

jade robin
#

that's stretching the word "reduce"

solemn rain
#

ok computer science is hard

#

i agree

pallid garden
solemn rain
#

NP HARD MAY NOT BE NP SINCE THEY ARE HARD AND CAN BE EXPONENTIAL TIME for verifying

steel whale
#

seems like a more efficient alternative to PIL

raw bramble
#

Does the heat death of the universe not solve the halting problem? Every program will end, whether it’s designed to or not

craggy willow
#

maybe something will warm the universe back up

peak relic
#

Definitely solves cold booting fr

craggy willow
#

a space heater

steel whale
#

so one can die from being too hot

pallid garden
#

they can run their turing machine forever in violation of 2LOTD

steel whale
raw bramble