#python-discussion

1 messages · Page 483 of 1

vale wasp
#

With all the traffic in here, you might be better off opening a help thread.

crisp jay
#

What was the bottleneck of this code?

gleaming knoll
#

the first argument to map has to be a function that will be called with 1 argument, the elements of the iterable
but move_file takes 2 arguments, right? so instead we make a partial application of it, with the destination being the path variable, and only leaving 1 argument to be filled - the file

main swan
#

Btw, you can get lots of program information (like current line number) with !inspect

gleaming knoll
#

!d inspect

edgy krakenBOT
#

The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects. For example, it can help you examine the contents of a class, retrieve the source code of a method, extract and format the argument list for a function, or get all the information you need to display a detailed traceback.

There are four main kinds of services provided by this module: type checking, getting source code, inspecting classes and functions, and examining the interpreter stack.

main swan
#

thx

gleaming knoll
#

!d inspect.stack in particular

edgy krakenBOT
#

inspect.stack(context=1)```
Return a list of [`FrameInfo`](https://docs.python.org/3/library/inspect.html#inspect.FrameInfo) objects for the caller’s stack. The first entry in the returned list represents the caller; the last entry represents the outermost call on the stack.

Changed in version 3.5: A list of [named tuples](https://docs.python.org/3/glossary.html#term-named-tuple) `FrameInfo(frame, filename, lineno, function, code_context, index)` is returned.

Changed in version 3.11: A list of [`FrameInfo`](https://docs.python.org/3/library/inspect.html#inspect.FrameInfo) objects is returned.
gleaming knoll
#

sys._getframe is basically the same thing but more raw

main swan
#

In response to: How do you find this stuff? Years of looking at the docs for no good reason.

vale wasp
main swan
vale wasp
gleaming knoll
#

did the explanation make it any more clear

vale wasp
#

And good docs.

gleaming knoll
#

good docs is innovation is key is not bread
because good docs taste better than key
or.. bread?

vale wasp
#

I don't eat my docs.

gleaming knoll
#

missing out

vale wasp
#

I try not to eat bread too.

gleaming knoll
vale wasp
#

I recommend A Minor.

main swan
#

Also, I write a lot of code and ask other people to revise my code which will almost certainly point you to places in the docs you've never seen before.

#

(Amongst many other benefits)

#

Plus, I program in other languages than Python and pull brain damage from them.

gleaming knoll
vale wasp
main swan
wise cove
#

Hello 👋, I just joined this server, and am learning python as parts of the languages I need to be a game developer

vale wasp
#

Welcome!

wise cove
#

Thanks

main swan
raw bramble
main swan
#

I don't really make games myself, but I make libraries that make game dev easier (see the project showcase for mine and many other projects)

gleaming knoll
vale wasp
raw bramble
#

like syntax i mean

main swan
vale wasp
main swan
raw bramble
gleaming knoll
lunar cobalt
#
def is_under_thousand(number):
    if number == 1:
        return True
    else:
        return is_under_thousand(number - 1)```
vale wasp
cerulean ravine
main swan
lunar cobalt
#
  1. it crashes instead of saying false
cerulean ravine
vale wasp
lunar cobalt
#
  1. Its slow
cerulean ravine
lunar cobalt
#
  1. negative numbers (or 0) also dont return
lunar cobalt
cerulean ravine
cerulean ravine
lunar cobalt
#

and eventually crash because its out of memory?

cerulean ravine
brisk gazelle
lunar cobalt
#

I wasnt actually proposing its a good function

raw bramble
cyan scaffold
main swan
#

Is somebody trying to reinvent some form of Peano arithmetic? Hmmm...

gleaming knoll
raw bramble
#

oh yeah duh 🙄

vale wasp
raw bramble
#

:DDD

crisp jay
#

Or 100000

#

Or 10¹⁶

sharp wadi
#

Guys, can i share something?

vale wasp
sharp wadi
gleaming knoll
# raw bramble haha, no I know what Lambda does, I don't know how it does though
def foreach(iterable, function):
  for value in iterable:
    function(value)

def two_args(x, y):
  if x==9 and y==10: 
    s = 21
  else:
    s = x + y
  print(f"{x} + {y} = {s}")

def example(xs, fixed_y):
  def one_arg(x): two_args(x, fixed_y) # uses fixed_y from parent scope!! yaay closures very coool
  foreach(xs, function=one_arg)

example([9], 10)

does that make it any more clear

cyan scaffold
cerulean ravine
sharp wadi
main swan
cyan scaffold
#

Just share it

lunar cobalt
sharp wadi
cerulean ravine
lunar cobalt
#

If you really want to you could do

try:
under_thousand = is_under_thousand(number)
except RecursionError:
under_thousand = False

cyan scaffold
#

Halting machine problem?

gleaming knoll
#

well, except RecursionError actually works

main swan
gleaming knoll
cerulean ravine
lunar cobalt
cerulean ravine
raw bramble
lunar cobalt
crisp jay
#

@lunar cobalt
try:
under_thousand = is_under_thousand(number)
except RecursionError:
under_thousand = is_under_thousand(number)

upper frost
#

i just installed fedora and PyCharm

lunar cobalt
cerulean ravine
main swan
#
def recursive_lt(x: int, y: int):
    """For non-negative x and y."""
    if x == 0 and y == 0: # They are equal.
        return False
    elif x == 0: # x < y
        return True
    elif y == 0: # x > y
        return False
    return recursive_lt(x-1, y-1)

How can you adapt to negative numbers too?

chilly whale
#

any function that relies on when exactly RecursionError gets raised will have different behavior depending on how many call frames are already on the stack when it gets called

crisp jay
#

How do I disable Copilot on VSC

lunar cobalt
#

how do you change the limit for RecursionError?

chilly whale
#

sys.setrecursionlimit

lunar cobalt
#

thx

gleaming knoll
# main swan ```py def recursive_lt(x: int, y: int): """For non-negative x and y.""" ...

make a wrapper that will
if both are positive do the normal thing
if x negative and y isnt - true, since all negatives are smaller than any non-negatives
if x positive and y negative - false, same logic just switch places
if both are negative, do the lt in the other order since -2 < -1 <-> 1 < 2
checking whether they are negative or positive would be done with some new structural tag in a peano encoding

main swan
#

(But yeah, it's so fun to think of this stuff. Very Peano-y)

#

Although, using von Neumann ordinals we get the isomorphism between membership and less than

main swan
#

I miss math

gleaming knoll
main swan
gleaming knoll
#

only like the first couple proofs
but i do use lean4 for fun

main swan
#

Ah good. It's fun.

#

I miss that stuff. I need to get back into it, but I'm dedicating the time I have energy to do stuff to my resume lol.

gleaming knoll
#

the last thing i wrote in lean is

def bigO (f g: Nat -> Nat): Prop :=
    ∃c: Nat, c ≠ 0 ->
    ∃x0: Nat,
    ∀x: Nat, x > x0 ->
    f x <= c * g x

theorem bigO.constant_multiplier
  {f g: Nat -> Nat} {m: Nat} (p: bigO f g):
    bigO (fun x => m * f x) g := by
      obtain ⟨c, q⟩ := p
      exists (c * m)
      intro cmnz
      have cnz := (Nat.mul_ne_zero_iff.mp cmnz).left
      obtain ⟨x0, le⟩ := q cnz
      exists x0
      intro x xgtx0
      dsimp
      have fleg := le x xgtx0
      conv => {
        rhs
        conv => lhs; rw [Nat.mul_comm]
        rw [Nat.mul_assoc]
      }
      exact Nat.mul_le_mul_left m fleg

absolute naming

upper frost
#

is pycharm good on 4 gigabites of ram

main swan
chilly whale
gleaming knoll
#

gigabites
heehee

vale wasp
ashen cipher
vale wasp
chilly whale
#

even the heaviest IDE won't use that much RAM. I'd be very surprised if you could get pycharm to use more than 1 GB

gleaming knoll
vale wasp
ashen cipher
#

the system requirements are 8gb with 3gb available for ide processes

main swan
#

If you're worried about resources just use vim or nvim imo.

ashen cipher
#

that's going to be higher than what it needs but it doesnt seem like... a fun time

cerulean ravine
#

@upper frost people will say "just use", but it's not always simple to switch to what they suggest

gleaming knoll
#

sublime would be "just use" and without much bloat

ashen cipher
#

!pypi justuse

edgy krakenBOT
main swan
ashen cipher
gleaming knoll
ashen cipher
#

lambda mentioned

#

@gleaming knoll

teal hare
#

One question for the pro devs here, since im new into python i can do the basic things and make small systems but when it comes to something big i cant remember everything and i have to check Old code or Ask Ai or check Doc, is that normal or i should focus even more into learning these things untill i know everything ?

vale wasp
crisp jay
ashen cipher
gleaming knoll
main swan
#

I remember I had to do some import hacks for my website because I wanted to make it easy for newcomers to add problems to my website.

ashen cipher
#

i think the goal was to model golang-style import?

rare gazelle
#

hello

main swan
#

and then i never touched import again.

ashen cipher
crisp jay
#

Is there a library for adding C include in Python?

#

I want to have the old fun pain

teal hare
main swan
ashen cipher
#

vro wants to deal with linkers

gleaming knoll
main swan
gleaming knoll
#

would watch

main swan
#

^ thumbs up (but I can't)

gleaming knoll
#

i finished watching arifureta yesterday and now im going to watch shield hero
absolute isekai ||slop|| but i like it

main swan
#

Is readthedocs still the way to go for adding docs? Or is there some new player on the block?

vale wasp
#

I use RTD.

main swan
#

Ok. I will probably use that then.

#

Thanks!

ashen cipher
#

i hear there's some drama around mkdocs but that's besidesthepoint

gleaming knoll
timid ember
#

from what i heard, really bad maintaners

ashen cipher
ashen cipher
vale wasp
#

There is some drama there but I don't know what it is. Doesn't affect RTD though - you can use any static site generator to create the docs.

ashen cipher
#

there probably are multiple but it is around the one

main swan
#

Alright. I just need to get some decent modern looking docs for my projects quickly. Not too concerned about controversy atm.

#

(Normally would be tho)

ashen cipher
#

i mean rtd is just a place that hosts your docs :p

#

but yeah rtd is fine last i used them

vale wasp
#

I just realized we're using mkdocs for the docs for the SSG I maintain and I'm kinda wondering why...

dusty ember
vale wasp
main swan
#

SSG?

vale wasp
#

Yes. Yes I did.

dusty ember
#

yoo

vale wasp
#

!pypi render-engine

edgy krakenBOT
dusty ember
#

i love static site generators

main swan
#

oh.

vale wasp
dusty ember
#

i rolled the one my website is running on

vale wasp
#

I use RE for my website.

main swan
#

I need to make my github.io blog too. so. much. writing.

main swan
dusty ember
#

i've got mine running on cloudflare pages

vale wasp
pastel sluice
#

I rolled my own SSG with a WP-like web frontend. It's running on a hosting provider that has done me good for some years but I'm not too crazy about their newer plans. I might migrate when my contract with them comes up.

main swan
#

I have a site that uses render.com (not static) but I don't really want to pay more money haha.

#

especially since I'm not sure anyone would actually read my blog.

dusty ember
#

im doing a rather interesting major refactor right now

ashen cipher
dusty ember
#

finally moving away from sqlite for caching

dusty ember
#

and some other security things cloudflare does?

vale wasp
dusty ember
#

my domain is also managed by cloudflare so it's nicer to just have everything in one place

ashen cipher
dusty ember
#

yeah fair enough

#

i don't think i've set up metrics for my site as it is anyways

main swan
vale wasp
#

Do you care about the metrics?

dusty ember
#

nah not really

vale wasp
ashen cipher
#

wow my site has had 0 page views in the last month

vale wasp
#

I need to post something to my blog. But I don't know what I want to write about.

dusty ember
main swan
pastel sluice
#

Most of what I blog about is doing creative things (like writing my books)

dusty ember
#

there's a project out there that uses a query system to handle caching and incremental rebuilds, which seems interesting

vale wasp
main swan
sacred cypress
silver plover
vale wasp
autumn forge
main swan
sacred cypress
ashen cipher
autumn forge
#

qedisproved

main swan
#

Sel4 is verified and writen in C. So C is safe.

#

C + Coq is confirmed safety.

vale wasp
#

Python is written in C so C is safe?

dusty ember
#

does being C make it safe, or is it being safe that makes it C?

vale wasp
ashen cipher
#

rust is written using llvm which is written in C and C++ therefore C and C++ is safe

ashen cipher
#

yea corrosion not safe

main swan
ashen cipher
#

osha disapproved

main swan
#

I actually need to learn more about LLVM (and related IR) I still don't fully understand why we don't compile to C more often.

#

I mean, I guess function calling conventions are part of the reason...

#

but I feel like there is more to the story.

finite furnace
vale wasp
main swan
ashen cipher
vale wasp
main swan
#

I'm trying to remember the alternative to LLVM that was smaller in size...

vale wasp
main swan
#

I'm thinking of QBE I'll investigate that and see why it's so useful.

silver plover
#

Oh, a spicy takes; 'ARY': always repeat yourself

vale wasp
dusty ember
main swan
#

wait im dumb

#

i misread: Yeah why we use IR as opposed to C for instance?

#

sorry

#

(Btw, i'm looking at SO answers and they're a bit handwavy imo)

thick epoch
#

Does anyone here have a good free Django bootcamp?

chilly whale
lunar cobalt
#

is bool('False') False?

gleaming knoll
chilly whale
#

non-empty strings are truthy

lunar cobalt
#

was hoping they made it special

lunar cobalt
gleaming knoll
#

!repl oops

edgy krakenBOT
#
Read-Eval-Print Loop (REPL)

A REPL is an interactive shell where you can execute individual lines of code one at a time, like so:

>>> x = 5
>>> x + 2
7
>>> for i in range(3):
...     print(i)
...
0
1
2
>>>

To enter the REPL, run python (py on Windows) in the command line without any arguments. The >>> or ... at the start of some lines are prompts to enter code, and indicate that you are in the Python REPL. Any other lines show the output of the code.

Trying to execute commands for the command-line (such as pip install xyz) in the REPL will throw an error. To run these commands, exit the REPL first by running exit() and then run the original command.

gleaming knoll
#

neat thing for small experiments
just keep one open and throw expressions in it when you think of something

gleaming knoll
rotund steppe
#

Explain why the first element of an array or factor is [0]. Can someone help me with this please?
I've always known first element of an array is [0] but now im asked why, i literally dont know

chilly whale
rotund steppe
dusty ember
# main swan i misread: Yeah why we use IR as opposed to C for instance?

my initial take would be because for one, your language might want to be transformed to a format that's explicitly designed to be easy to analyze and work with, so you can implement all of your optimizations and transformations and whatnot without having to deal with an entire other language, like C, and deal with what C allows/doesn't allow.

rotund steppe
gleaming knoll
winged citrus
#

Goodnight chat

chilly whale
#

if you're being asked it about C or C++, there's an actual reason

chilly whale
#

for any other language, it's basically just arbitrary

main swan
rotund steppe
#

i've googled it but im having hard time understanding

rotund steppe
main swan
#

ayyyyyyy

main swan
rotund steppe
#

but yes, in particular, c++ why array starts at 0. I'm studying for finals

chilly whale
# rotund steppe yes, its c++

for C or C++, it's because x[0] on an array is equivalent to *(x + 0). This also lets you write 5[x] in C and C++ instead of x[5], for one of the all time weirdnesses of the language, because *(x + 5) and *(5 + x) are equivalent

winged citrus
gleaming knoll
winged citrus
dusty ember
# main swan i misread: Yeah why we use IR as opposed to C for instance?

also it's worth noting that the C compilers are all going to go to their own IRs anyways (and if it's clang, it'll just be llvm in the end as well). If you want more control over what those specific optimizations and transformations and whatnot are, you probably don't want to just compile down to C

gleaming knoll
rotund steppe
#

can you explain to me like im 5 lol

winged citrus
#

without ai

rotund steppe
main swan
gleaming knoll
winged citrus
#

lol how do u edit so fast

winged citrus
crisp jay
gleaming knoll
winged citrus
#

that was

chilly whale
winged citrus
#

fast.

main swan
winged citrus
#

GOODNIGHT AMIGOS!

rotund steppe
winged citrus
gleaming knoll
dusty ember
rotund steppe
main swan
gleaming knoll
#

ghc core

rotund steppe
gleaming knoll
main swan
chilly whale
crisp jay
rotund steppe
#

btw is this chat strictly dedicated to python or we can discuss other languages as well

half pewter
rotund steppe
#

i cant wait for semester to be over so i can go back to python programming

rare gazelle
chilly whale
rare gazelle
#

one 0 elements

chilly whale
#

there's an implicit "that is"

#

English has a lot of those

#

the 0th element of the array is the one (that is) 0 elements past the start of the array

rotund steppe
rare gazelle
#

oh

rotund steppe
#

i get the intuition behind it but cant quite articulate it

pastel sluice
#

it's a way of saying "how many steps are we taking past the beginning?"

crisp jay
#

Or number

smoky pasture
#

Hello

pastel sluice
#

if we start at the beginning, we take no steps, so the first index is zero

rotund steppe
#

in the simplest way

smoky pasture
#

How can i turn er diagram to table please

chilly whale
crisp jay
chilly whale
#

char can be signed or unsigned in C, it's implementation defined

rare gazelle
#

i think that is an implementation detail

chilly whale
#

"the basic one" could be either 0 to 255 or -128 to 127

rare gazelle
#

a byte is defined as 8 bits, i think so

crisp jay
rare gazelle
#

what you do with those 8 bits is implementation detail

chilly whale
# rotund steppe in the simplest way

mathematically, if there is an array at byte address A consisting of elements that are each of size S, then element N is at byte address A + (N*S)

chilly whale
rare gazelle
fiery yarrow
#

and strictly speaking, an octet is 8 bits. a byte can be any number

crisp jay
chilly whale
rare gazelle
#

interesting, i didn't know that

crisp jay
cerulean ravine
chilly whale
#

I think there are still some extant machines where the minimum addressable amount of memory is 16 bits or 32 bits. They're rare and weird, but I've heard they still exist

cerulean ravine
rare gazelle
crisp jay
#

So a "byte" could be defined as a N group of bits?

rare gazelle
crisp jay
#

Its strange to see byte that isnt 8 bits

rare gazelle
#

oh nvm, i read his sentence wrong (read it again)

#

any amount of bits i suppose

chilly whale
chilly whale
#

in most contexts, "byte" does indeed mean "octet", but it means something different in C and C++

#

they use it to mean the smallest uniquely addressable unit of memory

rare gazelle
#

a unit of memory yes, thats why it doesn't have a defined value

#

char uses 1 byte, if signed it can store a value between -128 to 127

#

if unsigned 0-255

chilly whale
#

at least -128 to 127, and at least 0 to 255

#

possibly more, on weird platforms (like the TMS320C28x)

rare gazelle
#

i see yea

crisp jay
#

64-bit byte what a cursed thing to see

chilly whale
#

it's mostly a historical curiosity that you won't need to deal with if you're writing code for desktop CPUs. The non-8-bit-byte thing only applies to weird special purpose hardware

rare gazelle
#

should've used the term octet

#

although i think most people don't know about this term

twin furnace
#

i must not have it even after downloading pyenv and all of that umm, that exact version of 3.12.13 also isnt there hmhmhmmmm idk what to do

rare gazelle
#

i didn't know byte can be not an octet

hybrid nebula
#

like Java

chilly whale
hybrid nebula
#

uint9_t when

chilly whale
#

no, that'd be int_least8_t

dry yacht
# hybrid nebula like Java

Java has Integer.compareUnsigned, Integer.divideUnsigned, Integer.remainderUnsigned, and Integer.toUnsignedLong. Take it or leave it 🐒

hybrid nebula
lunar cobalt
#

Absolute cinema

theorem AbsoluteTruth:
Given:

Then:
    true
Proof:
    true
dry yacht
hybrid nebula
twin furnace
rare gazelle
twin furnace
#

im also on windows

rare gazelle
#

not a good word play though

twin furnace
#

i used the port too

lunar cobalt
pallid garden
hybrid nebula
pallid garden
lunar cobalt
hybrid nebula
#

and its negation is then true

lunar cobalt
hybrid nebula
pallid garden
#

have you done this?

#

I'm going to be perfectly honest, by the time you are looking for a job, quant firms would have likely moved on to later versions of python

lunar cobalt
#

And then call whichever you need

fiery yarrow
chilly whale
#

yes, you can

#

the size limit mostly comes from the "addressable" part, though, not from the "basic character set" part

#

the big reason why some platforms have bytes that are more than 8 bits is because those platforms don't allow you to address an arbitrary group of 8 bits

sterile topaz
#

What’s python

hybrid nebula
#

I should make a logisim computer with 11 bit bytes

hybrid nebula
sage mural
#

When I use powershell in my flask app this pops up on opening powershell why is this happening?

(Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned) ; (& c:\Users\myself\OneDrive\Desktop\mypp\app_env\Scripts\Activate.ps1)

Please ping on reply

fiery yarrow
#

also why the heck does the iso not make C an open standard 😡

pallid garden
sage mural
#

I was just worried by this part (Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned) ; ty

sage mural
hybrid nebula
sage mural
#

it wasn't always like that

pallid garden
pallid garden
hybrid nebula
pallid garden
#

well it was always like this on windows for me

fiery yarrow
# hybrid nebula $$$

"imma make my own c compiler!"
"alright, what is C exactly"
"why do i have to pay USD$290 to find out what C is sobMeltdown"
"alright i ain't gonna make a compiler"
i bet this kinda process happens fairly often

hybrid nebula
pallid garden
jagged nacelle
charred tusk
fiery yarrow
charred tusk
sage mural
jagged nacelle
sage mural
#

yes when I open powershell

jagged nacelle
#

Im afk I can try to look which extensions I have later

fiery yarrow
#

do you have an extension named code runner by chance

charred tusk
pallid garden
charred tusk
sage mural
#

Nope I don't have runner

#

How did this happen

twin furnace
#

im unfamiliar with this stuff so might as well

#

can always downgrade in the future

charred tusk
#

You should always the use the latest and only look at something else if you have problems

fiery yarrow
pallid garden
ashen cipher
#

guys i need opinions

#

should i still recommend uv in the big 26

twin furnace
fiery yarrow
pallid garden
charred tusk
fiery yarrow
#

uv seems to hate kat for some reason, but it seems fine for everybody else afaik

charred tusk
ashen cipher
charred tusk
ashen cipher
#

pyenv/pip/pipx

twin furnace
ashen cipher
#

the stack

fiery yarrow
sage mural
#

Its just in vscode powershell should I be concerned?

pallid garden
charred tusk
hybrid nebula
#

just use pip, venv and /usr/bin/python3.xx

pallid garden
fiery yarrow
ashen cipher
ashen cipher
#

pdm

charred tusk
twin furnace
charred tusk
#

Poetry still in the toilet only for devs that hate their jobs so they can say “waiting on the lock file” while it takes 30m to generate

hybrid nebula
charred tusk
#

but how

ashen cipher
#

pyenv has conda-style venv

#

and i like it

charred tusk
#

You’re gross

ashen cipher
#

:(

charred tusk
#

Mom! This guy is scary!!

hybrid nebula
sage mural
#

Nevermind I solved it

jagged nacelle
charred tusk
#

What did you see!?

sage mural
#

I accidentally typed 2 things at once I delete the up and down arrow text memory and it went away

jagged nacelle
#

yert huh

charred tusk
sage mural
#

Nope it came back

jagged nacelle
sage mural
#

Let me list every extension or something I am worried

#

C/C++ related
C/C++
C/C++ DevTools
C/C++ Extension Pack
C/C++ Themes
CMake Tools
General / Web
Live Server
Python related
Pylance
Python
Python Debugger
Python Environments

It seems ai written because I took pictures and you can't upload them so I just asked the ai to type them

fiery yarrow
#

code --list-extensions also works from a shell

sage mural
#

when I try that a new window pops up

#

of vsc

fiery yarrow
#

apparently this requires an external shell.
somebody on so lied 😡

jagged nacelle
hybrid nebula
fiery yarrow
half cradle
#

i made a master piece

sage mural
#

@fiery yarrow

Also when I click on powershell highlight it I get

powershell

Process ID (PID): 11508

Command line: …\powershell.exe -noexit -command 'try { . "c:\Users\user\AppData\Local\Programs\Microsoft VS Code\560a9dba96\resources\app\out\vs\workbench\contrib\terminal\common\scripts\shellIntegration.ps1" } catch {}'

Shell integration: Rich

Does this contain any senstive data?

half cradle
#

import random
x=random.randint(1, 6)

if x == 3:
print("you got three")
else:
print("you did not get 3 better luck next time")

edgy krakenBOT
#

Hey @half cradle!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
half cradle
fiery yarrow
hybrid nebula
#

ah OK

fiery yarrow
#

also why is nearly every single program afraid of using % variables for paths

sage mural
#

So everything is okay? I am still confused why it is happening. It happens whenever I open a folder in vscode

#

just same env I would have to try a different env

jagged nacelle
#

@sage mural it seems to be python enviroments extension

#

when I disabled the auto run script removed the policy thing

#

YEAH

fiery yarrow
#

ah, python environments. an extension forced upon users, hated by many, and so eager to break stuff.
lasted on my computer maybe 20 minutes

jagged nacelle
sage mural
#

Okay I worried

#

sorry about that Ty everyone I just never seen it before until a few days ago

jagged nacelle
sage mural
#

I use venv

pallid garden
#

they added this policy to powershell themselves

granite wyvern
#

I'm feeling like an idiot this morning.

The docs for input() say it writes its prompt to stdout.

My testing shows it writing to stderr.

Running interactively, it writes to stdout.

I'm debugging a module which writes "live" status lines, and they go to stderr. So I've got 2 ttys, and I'm sending stderr to the second one so I can do things in the first without affecting the display.

So to exclude my module, I'm running this:

#!/usr/bin/env python3

input("input 0: ")

and to exclude my shell aliases and other gunk I'm running this:

/usr/bin/python3 indemo.py 2>/dev/ttys031

The "input 0: " prompt shows up on the other terminal, which is stderr. Gah!

But interactively:

$ /usr/bin/python3 2>/dev/ttys031
>>> import sys
>>> print("other tty", file=sys.stderr)
>>> input("input 0:" )
input 0:xx
'xx'
>>>

which shows the puython header on the other terminal (surprise!) and also the print to sys.stderr on the other tty:

Python 3.9.6 (default, Aug  8 2025, 19:06:38)
[Clang 17.0.0 (clang-1700.3.19.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
other tty

but is pretty clearly doing the input() prompt to the main terminal, aka sys.stdout. As expected.

WTF?

cerulean ravine
# granite wyvern I'm feeling like an idiot this morning. The docs for `input()` say it writes it...
chilly whale
#

whoa boy, does that ever seem like a bug

#

I think that the prompt should be written to terminal (this is already so on Windows). If only one of stdout or stderr are terminal streams, it should be chosen for output
That's... interesting. I don't think I agree, but it's interesting...

granite wyvern
# chilly whale whoa boy, does that ever seem like a bug

It's a huge bug. There's always been tension between where the prompt (in programmes in general) should go and where it gets sent. Personally I'd often sent to stderr because my programme's output might be going to a pipe or file or whatever - don't want a "plug" bug.

But the docs should be explicit about what it does, or clear that the behavour may vary, and frankly I'm very much for giving it streams for the input and output, like print's file=. To give precise control when precise control is wanted.

granite wyvern
#

I'll roll my own, just print/input(""), for now. But ugh.

rapid harbor
#

is there a general channel??

#

or a promo channel?
I have a friend who is making a game, but wants to promo his server so that he has more people for launch day

pastel sluice
rapid harbor
#

wrong server, I thought this was Pygame

fading notch
#

best modules for nice n simple terminal ui / interface

manic flare
#

I use print… you can do ui in the terminal?

charred tusk
#

!pypi textual

edgy krakenBOT
#

Modern Text User Interface framework

Released on <t:1775380365:D>.

jagged nacelle
#

PyInquirer

charred tusk
jagged nacelle
charred tusk
#

!pypi PyInquirer

edgy krakenBOT
#

A Python module for collection of common interactive command line user interfaces, based on Inquirer.js

Released on <t:1542914535:D>.

fading notch
#

no i mean like these raw classi style ones like one i made , wanna see it ?

jagged nacelle
#

textual looks so good

indigo phoenix
edgy krakenBOT
#

scratch/software/excel/quote-csv.ps1 line 1

Import-Csv .\file.csv | Export-Csv .\file2.csv  -NoTypeInformation -Encoding UTF8```
charred tusk
#

Free and clear
No pesky signatures required

#

You can just use it
No paperwork required

vale wasp
vale wasp
charred tusk
vale wasp
#

.topic

verbal wedgeBOT
#
**What's your favorite use of recursion in Python?**

Suggest more topics here!

vale wasp
craggy trench
# verbal wedge

magic functions that go over nested things and produce some kind of value from it

vale wasp
#

TBH I primarily use recursion for AoC.

charred tusk
#

I’ve used recursion exactly once

#

I needed to extract files in nested zips

vale wasp
#

Outside of school.

#

Nested zips?? What insanity is that???

charred tusk
#

You’re still in school?

vale wasp
#

I'm not in school.

#

Well... I'm in the school of hard knocks, but who isn't?

pallid garden
#

i use recursion even when i shouldnt 🤣

#

(FP)

pseudo thunder
#

guys it is not time to make hack the iran

vale wasp
#

I use recursion all the (I use recursion all the (I use recursion all the time) time) time.

cerulean ravine
pseudo thunder
fiery yarrow
#

it also doesn't really make sense

charred tusk
# vale wasp Nested zips?? What insanity is that???

For $WORK I do commercial printing, so I work with gigantic machines that needed a dedicated file for each color.
$BIGGESTCLIENT’s system has them upload a zip of all the individual per-color TIFF files, and a preview JPG.
When we click download it zips them together to download a single zip, creating the nested zip.

charred tusk
#

ew

fiery yarrow
#

forget not the feathers

vale wasp
#

Unzip them and tgz them.

charred tusk
#

Windows couldn’t do tar until this year

vale wasp
#

You poor thing.

#

Python can do tar.

pallid garden
vale wasp
#

Even on Windows.

charred tusk
#

Yeah but Pillow keeps fucking up the images

vale wasp
fiery yarrow
vale wasp
charred tusk
#

Try explaining that to users

fiery yarrow
sand hornet
vale wasp
pallid garden
fiery yarrow
pallid garden
fiery yarrow
#

go to the spaceclothing store and spacebuy some windbreaker spacepants i guess

pseudo thunder
#

spase...

#

has a stars in is....

pallid garden
#

the same one they used on the parka space probe

vale wasp
#

We've kinda jumped the shark.

pallid garden
#

investigating the fabric of spacetime

pseudo thunder
#

fabric.... make some close....

vale wasp
#

.topic

verbal wedgeBOT
#
**What's your favourite aspect of Python development? (Backend, frontend, game dev, machine learning, ai, etc.)**

Suggest more topics here!

vale wasp
manic flare
pseudo thunder
# verbal wedge

making terrible cli apps repeatedly because I don't know what to build

narrow tiger
#

machine learning right now but I want to branch out into more actual python software instead of hacking away at ML/AI

pallid garden
#

came for the ML, stayed for the python?

narrow tiger
#

Exactly! I came from a fortran/matlab/embedded C world and got wrapped into Python for the ML stuff for an applied math masters and just loved it

pallid garden
#

that's a very different world wow

narrow tiger
#

I like that python is so easy to get started with, like matlab, but also this is free and way more versatile

vale wasp
#

And Python has a great community. Does matlab have a nice community?

narrow tiger
#

I haven't met very many people from the matlab community outside of work settings but they seem nice

#

dont care as much about the language though

#

just a tool to get them from point A to point B, seems like python people care more overall philosophically and problem solving-wise

fiery yarrow
#

matlab's dedicated array elementwise syntax is kinda neat and sometimes i wish other languages supported it more

pallid garden
#

i actually used matlab over python for my qm classes

vale wasp
pallid garden
#

it's just a lot easier when you only care about the results

vale wasp
narrow tiger
#

Seems like a good reason though, easier to do matrix computations and vectorize things

vale wasp
#

Not every language is suited to every task.

fiery yarrow
#

type hints for qm must be like
foo: Particle[¯\_(ツ)_/¯, ¯\_(ツ)_/¯]

narrow tiger
#

hahaha

pallid garden
#

i want to learn qiskit

narrow tiger
#

same, that sounds like fun. On my list once I finish my masters

pastel sluice
half pewter
#

does a function act as an observer or nah?

#

def foo:
if random.randint(1) == 0...

charred tusk
pallid garden
#

they were the one who recommended me

dry pike
silver plover
vale wasp
pastel sluice
fiery yarrow
#

is ruby the place with dhh

vale wasp
charred tusk
#

Yes

vale wasp
narrow tiger
#

off the rails feels like a great pun

pseudo thunder
#

"We have parted ways with our Executive Director, our PR agency, our CFO, and concluded several contractor engagements." insane opener

dry pike
pseudo thunder
charred tusk
charred tusk
vale wasp
#

As I said, "Ruby off the Rails"

crisp jay
manic flare
fiery yarrow
dry pike
vale wasp
vale wasp
#

David Hamburger Helper

pseudo thunder
#

David Has Horses

pastel sluice
#

Oh dear god

#

(that's my reaction to reading this material)

vale wasp
crisp jay
#

Imagine a language entire image being entitled to a framework made by a guy and he starts to talk shit

charred tusk
#

Dog here
Dog forsook them long ago

vale wasp
pseudo thunder
#

Linus Torbjorn, the maker of linerx

half pewter
#

I haven't written python for a week

#

because that would be too long

granite wyvern
dry pike
#

how do you unpack a nested dictionary?

#

what is the result?

#

flattening?

half pewter
#

use dataframes for that

granite wyvern
edgy krakenBOT
#

lib/python/cs/debug.py line 886

@ALL```
half pewter
#

was just about to ask if there's something cheaper than pl/pd for tabulating data

granite wyvern
manic flare
#

.topic

verbal wedgeBOT
#
**What are you currently working on in Python?**

Suggest more topics here!

dry pike
#

I made myself an easier way to make UML class diagrams with Graphviz

#

using python to generate the dot file

manic flare
# verbal wedge

Well, I got a longer term project where I’m making a game with some more complicated stuff, but I got a small project where I’m making a small td game

#

Just got bored amid my bigger one

half pewter
#

giving bs4 and regex some actual attention, trying to hack a .gov website for their public access flat files

swift sparrow
# verbal wedge

A setup for automatically laying out environment textures for 3d models!

half pewter
#

(not breaking any rules, ftp is just blocked on my network)

granite wyvern
nova breach
#

How much of code of Discord is written in Python?

steady rain
#

(I know it says elixir--it mentions how they use python in the article)

unique sandal
#

hello, I was wondering if u guys have any pdf books about python or sites that I could get resources from?

edgy krakenBOT
half pewter
#

Some of Al Sweigart's more advanced books are also free.

pallid garden
calm scroll
#

From peoples experience here, how long did it take you to become somewhat fluent in python? This means being able to solve rigorous problems with minimal to no help

harsh anchor
#

define rigorous

wise yarrow
#

I feel like the ability to solve X type of problems isn't really indicative of python fluency

steady rain
robust ledge
calm scroll
# harsh anchor define rigorous

Well not per say rigorous but such that you know what you are looking at, ex you look at a random piece of code and be able to understand what’s happening rather than have no clue

jade robin
#

what's python (/jk)

slow rivet
#

Well that depends on the code, there's some really confusing python code out there

chilly whale
#

I remember having a lot of trouble wrapping my head around references and deep vs shallow copies the first time around...

swift sparrow
swift sparrow
#

I look back at code I wrote years ago that's pretty bad, but also got the job done so I guess it was good enough at the time

robust ledge
#

Code that works is what is needed.

#

I get to see code I've written 2-6 years ago now running in prod. Makes me wince, but I can't argue that it works.

tight cloud
#

i find the VS code so confusing to use

swift sparrow
pallid garden
raven urchin
#

hello beautiful people!

calm scroll
granite wyvern
swift sparrow
calm scroll
#

I still struggle with a lot of dunder methods etc

swift sparrow
#

if you're reading other code and not understanding, it should be an issue of "I don't know why they wrote that" and not "I don't even understand what that line is doing"

granite wyvern
calm scroll
#

Im hoping cs50 clears up any confusion i have I’ve heard good things

tight cloud
swift sparrow
#

if you know all the syntax, then just start coding

calm scroll
#

I’m on week 3 I been doing a week per day

swift sparrow
#

you should be doing a week per week

bronze dragon
#

you're doing the problem sets too, I hope?

swift sparrow
#

it's not a race

calm scroll
swift sparrow
#

your goal now should be to write as much code as possible. Solve problem sets, write toy code, build projects, etc

chilly whale
tight cloud
calm scroll
#

Are there places where I can get project ideas

swift sparrow
#

Go and solve dozens of problem sets, you will improve much quicker than watching more videos

granite wyvern
granite wyvern
edgy krakenBOT
#
Kindling Projects

The Kindling projects page contains a list of projects and ideas programmers can tackle to build their skills and knowledge.

bronze dragon
tight cloud
granite wyvern
calm scroll
drifting hill
#

Is there are good LLMs or ML algorithms for trading and all that or is that too advanced for LLMs right now? I just got into ML and feel it could be a good tool for trading, but I'm also ignorant in the space right now

granite wyvern
tight cloud
granite wyvern
#

So when the guess is correct, set a flag to say so. Make the while loop honour the flag.

calm scroll
#

@swift sparrow another question is sometimes I find it difficult to understand python documentation, how this you get past this barrier

chilly whale
swift sparrow
calm scroll
bronze dragon
grim axle
bronze dragon
#

don't try to understand everything just yet. focus on extracting useful information.

swift sparrow
#

Yeah, a lot of it requires you to have the full programmer vocabulary

tight cloud
swift sparrow
#

so if there's words you don't understand, it might be worth following that rabbit hole to learn the terminology

granite wyvern
slow rivet
bronze dragon
#

IDLE doesn't have the greatest ergonomics for nested blocks -- probably something to do with that

calm scroll
#

That’s probably a huge obstacle for a lot of ppl starting out im guessing

pallid garden
torpid sparrow
#

yall need to containerize your apps

#

its more smoothie if you do docker compose watch

swift sparrow
granite wyvern
torpid sparrow
#

hot reloading all ur stuff together

swift sparrow
torpid sparrow
#

just use a terminal and docker compose, even if it's just tests for a script in a container*

tight cloud
#

oh nvm i fixed it myself

bronze dragon
calm scroll
#

repr(object, /)¶
Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(); otherwise, the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a repr() method. If sys.displayhook() is not accessible, this function will raise RuntimeError.

This class has a custom representation that can be evaluated:

such as something like this
I have no idea what’s going on

tight cloud
#

i formed sentences and i found that i used break earlier so it made the program not continue then i added break after the condition is met and so when the condition isnt met the python reads from above again

swift sparrow
#

Do you know what a string is? Do you know what an object is? Do you know what printable means?

bronze dragon
swift sparrow
#

123 is an object. "abc" is an object. True is an object

tight cloud
#

oh ok thanks

calm scroll
steady rain
swift sparrow
chilly whale
# tight cloud whats an object

if you've learned what data types are, then objects are just the things that have those types. "hello" is an object whose data type is str, 123 is an object whose data type is int, etc

calm scroll
bronze dragon
swift sparrow
chilly whale
#

yes, but we probably don't need to get into that now 🙂

swift sparrow
tight cloud
#

how can i edit my VS code layout so that the place where i put codes comes on left and the output screen comes on right

swift sparrow
bronze dragon
swift sparrow
#

can you tell us what part of the repr documentation you don't understand specifically? Any words you don't understand?

#

I remember struggling with repr but it was more of a "I don't understand why we would use this"

granite wyvern
bronze dragon
#

just trying things in a REPL is underrated. but you should learn to read docs, so this is not a substitute.

calm scroll
swift sparrow
calm scroll
#

At the end it’s saying that I can modify what repr returns by defining this method? Which I’m guessing is some kind of dunder method

swift sparrow
#

so if I had a string "1 + 1", python could evaluate it and return 2

swift sparrow
#
A class can control what this function returns for its instances by defining a __repr__() method
bronze dragon
calm scroll
#

I understanding everything other than printable representation

bronze dragon
#

"printable" just means what it literally says -- "can be printed"

granite wyvern
bronze dragon
swift sparrow
#

do you know what the output of this program will be? What happens when we print custom class objects?

tight cloud
#

can i change the output of how i want it like i earlier made a game and the output seems very congested

swift sparrow
calm scroll
#

I might be wrong

tight cloud
#

but how do i do so that it prints from a new line or after some spaces the output rn is :
pokemon game
charizard
pikachu
scizor
press enter to continue
missed
enemy HP: 100
dmg dealt 6
player HP: 94
press enter to continue
dmg dealt 14
enemy HP: 86
dmg dealt 50
player HP: 44
press enter to continue
missed
enemy HP: 86
dmg dealt 17
player HP: 27
press enter to continue
dmg dealt 28
enemy HP: 58
dmg dealt 44
player HP: -17
you lost

swift sparrow
#

!e

class Car:
    pass

car_object = Car()
print(car_object)
edgy krakenBOT
chilly whale
#

for understanding repr, it's probably best to just look at examples

swift sparrow
#

like the one I'm about to show 🙂

#

if we want to control how our custom object is printed, we have two dunders we can use

#

__str__ and __repr__

swift sparrow
#

!e

class Car:
    
    def __str__(self):
        return "A shiny new car!"

car_object = Car()
print(car_object)
edgy krakenBOT
swift sparrow
#

simply by defining __str__, we have overridden how our object is displayed when printed

calm scroll
#

I see

swift sparrow
#

but, this isn't always the case

#

__str__ is only used if our object is printed directly

#

but, if our object was contained inside something else, like a list for example, it reverts back to the ol' memory print

#

!e

class Car:
    
    def __str__(self):
        return "A shiny new car!"

print([Car(), Car(), Car()])
edgy krakenBOT
swift sparrow
#

we can actually see this happening with the string class too

#

!e

print('123')
print(['123'])
edgy krakenBOT
swift sparrow
#

ever noticed how strings don't display their '' when printed, but they do when they are inside a list?

swift sparrow
#

that's because we are seeing the repr of the string here

swift sparrow
#

!e

text = 'abc'

print(text)
print(repr(text))
edgy krakenBOT
swift sparrow
#

a common way to think about the difference in __str__ and __repr__ is that __str__ is for the user, and __repr__ is for the programmer

swift sparrow
#

let's look at an example of a slightly more detailed class

#

!e

class Card:

    def __init__(self, rank, suit):
        self.rank = rank
        self.suit = suit

    def __str__(self):
        return f'{self.rank} of {self.suit}'


card = Card('Ace', 'Spades')
print(card)
edgy krakenBOT
swift sparrow
#

when printed, this card just shows a simple print about our card's rank and suit

calm scroll
#

Yep

swift sparrow
#

but if that was printed in a list, it would be super confused

#
[Ace of Spades]
#

if this was my output, well what am I even looking at?

#

I want to know that I have a list of "card objects"

#

so this comes back to the eval note in the docs

#

in __repr__, we typically want to return a string that could eval back into our object

#
Card('Ace', 'Spades')
#

in that case, this is how we created our object

#

so the returned string would look something like

"Card('Ace', 'Spades')"
#

but, we want it to be able to display whatever its actual rank/suit is

#

!e

class Card:

    def __init__(self, rank, suit):
        self.rank = rank
        self.suit = suit

    def __str__(self):
        return f'{self.rank} of {self.suit}'

    def __repr__(self):
        return f'Card({self.rank!r}, {self.suit!r})'


card = Card('Ace', 'Spades')
print(card)
print([card, card, card])
edgy krakenBOT
swift sparrow
#

so now have a look at the difference between how our object looks when printed directly vs. how it looks when contained in a list

#

Much more useful to us as the programmer to see what we have

swift sparrow
#

Thank you for coming to my TED repr talk

calm scroll
swift sparrow
#

np! Ultimately it's really up to you how you want to visualize your instances

#

but those are the rough guidelines to keep in mind

#

if you only have __repr__ and no __str__, then __repr__ will be used in place when printing the object

slow rivet
#

(I do think rusts naming for the same concept gives a much clearer distinction here as well, they call it Display and Debug)

#

Because both str and repr return a string that's a representation of the object :/

sterile topaz
#

-# age is just a number, unless you define it as a string

dry pike
#

ts not tuff vro

pallid garden
tame vapor
#

you cant define ages with two digits in a single character brainmon

tame vapor
kind thicket
exotic solstice
#

btw age is a word and not a number

dry pike
#

number is a word

tame vapor
tame vapor
#

a word is 32 bits

tame vapor
bronze dragon
tame vapor
pallid garden
#

but what if my great-great-great-great-great-great-great-grandma is 256 years old

kind thicket
tame vapor
kind thicket
tame vapor
pallid garden
kind thicket
dry pike
#

I'm End of Transmission Block years old

tame vapor
#

what would it mean to have negative age thinkmon

pallid garden
#

dammit recursive

kind thicket
#

though now, I want to define age as a system of equations

flat root
#

Hi everyone, I'm new here.

#

I just joined, because i got curious about learning python.

quartz fulcrum
#

hello

flat root
#

I have no programming knowledge. Where do I start?

bronze dragon
edgy krakenBOT
flat root
#

Cool! Thanks!

twin furnace
#

ooo I just got an acceptance letter from the University of Wisconsin-Madison! Idk how cracked the school really is, nor if I wanna go there but I'm happy cause the campus is awesome 🏌🏼‍♀️

placid moth
brittle grail
somber mulch
brittle grail
#

who knows but great project

somber mulch
#

People have already built it, I guess.

brittle grail
rapid mulch
#

I’m importing os and my terminal won’t display color

granite wyvern
#

Do you mean your terminal can't display colour, or you expect colour and it's not showing up?

rapid mulch
#

I expect color

granite wyvern
#

The os module doesn't provide any colour features.

#

So, what're you doing which should be coloured.

rapid mulch
#

I would told os.system(“”) is a ‘fix’ for terminals that don’t display color

granite wyvern
#

The empty string?

rapid mulch
#

Yeah

granite wyvern
#

os.system passes a command to your shell to be executed.

#

Passing "" should do precisely nothing.

rapid mulch
#

😭

ocean ridge
#

u want colorful terminal text??

rapid mulch
#

Yes

#

Health bar

granite wyvern
#

There are escape sequences which render text in colour honoured by most modern terminals. See:
https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text. The terminal interprets these sequences as command...

ocean ridge
#

i have an old prohect doing that lemme open and give u easily

granite wyvern
#

There are python packages for rendering text in colour.

rapid mulch
#

Package..?

granite wyvern
#

!pypi rich

edgy krakenBOT
#

Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal

Released on <t:1775982240:D>.

granite wyvern
#

Things you can pip install

rapid mulch
#

Oh

granite wyvern
#

py -m pip install rich

rapid mulch
#

What’s the different between pip3 and -m

ocean ridge
#

@rapid mulch Colorama is easier

from colorama import Fore, Back, Style, init
init(autoreset=True)
print(Fore.RED + "Red txt")
print(Fore.GREEN + "GREEN txt")
print(Fore.WHITE + Back.RED + "white txt in red bg")
granite wyvern
#

!pypi colorama

edgy krakenBOT
#

Cross-platform colored terminal text.

Released on <t:1666665382:D>.

rapid mulch
#

Rlly bad mindset if I wanna learn something new rn

granite wyvern
ocean ridge
granite wyvern
#

We recommend the -m pip incantation.

ocean ridge
#

Style isnt needed my bad. ihad it in my project imports ad forgot to delete it

rapid mulch
ocean ridge
granite wyvern
rapid mulch
#

Colorama would also hopefully work lemon_happy

#

I don’t know what’s wrong with mine, 0 errors and it just doesn’t print