#internals-and-peps
1 messages · Page 82 of 1
Hi all, i would like to share a numpy array between multiprocessing. My intention is to take the frame after it's processsing to django view. Can anyone help on this?. i can share the numpyarray in threads, but in multiprocessing, i cant do it. Kindly help
Hey, see #❓|how-to-get-help
hi guys, how are you? Lately I've been getting more and more curious about Domain Driven Design. Does anyone have experience with that in Python? I'm posting here since I think this is a rather advanced (or just uncommon) topic throughout Python users, but if more are interested in that maybe a #software-architecture/design channel would be worth it in the Topical Chat/Help section. However, I'd love to discuss the matter with anyone who knows about it, and maybe try and implement something together too!
which cloud should I learn if i want to get into machine learning and ds?
Hey guys, can you take a look at #❓|how-to-get-help
I'm not asking for help, though, @undone hare 🤔
Well, see the channel topic, this is about the implementation and the use cases of Python in particular, I’m not 100% sure if it fits the topic, maybe you could try in #python-discussion ?
alright! How about the creation of a topical channel by the way? I mean something like #software-architecture/design where to discuss in general how to structure projects, who may decide if this could be a nice idea @undone hare ?
We did have a channel like that, but it wasn’t very much used, kf you have any suggestion about the community though, feel free to send a message in #community-meta 
thank you!
i've recently figured out how to use asyncio
is there a reason why there's no asynchronous range() function availible in the language?
What would be asynchronous in it?
it just seems strange to me that i'd have to implement something like that myself
oh well i can't do stuff like: -
WAIT NEVERMIND sorry
range just runs a simple calculation to get you an item at a certain index
@spice pecan I didn't know range supported __getitem__--thanks!
can I get users liked pages/follower/(people followed) if I provide login using Twitter API?
It implements the Sequence ABC
@olive marsh that question isn't on-topic for this channel.
@olive marsh look at their API documentation and figure it out
@quiet wasp kind of sounds like appropriate discussion for this channel or #esoteric-python
#python-discussion seems to be focused purely on newbies and doesn't have very much fruitful conversation
anyone know if there has been work on compiling a list of 3.9-supporting frameworks?
l
what is python if __name__ == "__main__" ?
I think I'm good enough with python but to this date I still have no idea what exactly it means, if anyone does please @
@desert peak Thanks
@unkempt rock It means if someone is invoking your script directly, like python -m app or python script.py
or double clicking?
correct
if you execute a script directly, its __name__ is __main__ instead of the module name such as import script or whatever
ok so i understand it someone already answered it in #python-discussion but why do i see it in alot of code bases? from my understanding using it makes no sense ?
because you might want your module to be executable, but you don't want the executable stuff to run on import
what?
there might be usable functions you want to import from your script, but you also want the script to run from the cli
and without that block
thank you very much
it would run that code whenever you import it
ye i get it now thanks, will prolly be using this lots now
it's a good practice to add it so you don't accidentally execute usercode on imports
!if-name-main there is also a tag for it 😄
if __name__ == '__main__'
This is a statement that is only true if the module (your source code) it appears in is being run directly, as opposed to being imported into another module. When you run your module, the __name__ special variable is automatically set to the string '__main__'. Conversely, when you import that same module into a different one, and run that, __name__ is instead set to the filename of your module minus the .py extension.
Example
# foo.py
print('spam')
if __name__ == '__main__':
print('eggs')
If you run the above module foo.py directly, both 'spam'and 'eggs' will be printed. Now consider this next example:
# bar.py
import foo
If you run this module named bar.py, it will execute the code in foo.py. First it will print 'spam', and then the if statement will fail, because __name__ will now be the string 'foo'.
Why would I do this?
• Your module is a library, but also has a special case where it can be run directly
• Your module is a library and you want to safeguard it against people running it directly (like what pip does)
• Your module is the main program, but has unit tests and the testing framework works by importing your module, and you want to avoid having your main code run during the test
wow
not sure I'd word it "has a special case" - it's pretty common @inland acorn
is theres a documentation for this bot?
#bot-commands
it is open-source, and there is the !help and !tags commands
not sure I'd word it "has a special case" - it's pretty common @inland acorn
@desert peak feel free to open an issue on github if you think it should be reworded
!source in #bot-commands @unkempt rock
how is this secure?
i know theres probably checks and stuff but im also sure theres a bypass since you're running untrusted code
idk
just thought i'd point it out
I am not sure of we do it exactly, but here is the project that does it: https://github.com/python-discord/snekbox
It's a Jailed python instance that is limited to a set of modules
only one person has been able to break it
storytime?
and we've patched that already
oh wow
Its basically you Vs Google
yep
It's a Jailed python instance that is limited to a set of modules
@radiant fulcrum limiting the modules is useless and shouldn't be count as security
I mean it is because it limits what you can do lol
how is the bot hosted? some VPS?
you can still rewrite the modules inside the eval'd code using python without any modules
we're sponsored by linode
linode vps yeah iirc
ah, very nice
we don't really limit the modules, do we?
!e
import os
print(os.system('ls'))
You are not allowed to use that command here. Please use the #bot-commands channel instead.
you can use the whole stdlib and the extra modules we've installed
There's no module restrictions, some are just useless in the restricted environment; but this seems more fitting to #community-meta
off-topic but what does meta mean lol
the actual security side of it is Down to NSJail
the discord itself and the things related to it
hi
see the topic in meta
@unkempt rock meta means referring to self, such as us talking about discord and the channel itself and not Python
ah ok
i would assume if someone is aiming to mess with the eval they wouldnt actually break the sandbox rather they'd mess with results that the bot will take and display in channel
i cant say @ everyone? i mean its disabled why i cant say it -_-
there was an incident where the ping got quoted by someone who could
its returned in a embed block and also now is escaped
"an incident" LOL
we have a check for code block escapes, and the result is run thru our normal chat filters
it wasnt from the eval though
Error handling on a different command went ping pong
we have a check for code block escapes, and the result is run thru our normal chat filters
@inland acorn ye i know but there must be a bypass, im 100% sure a string wizard can bypass it
saying a thing or two off topic shouldnt be a crime lol otherwise you would need to end each message with "this is an advanced discussion :)"
ye i know but there must be a bypass, im 100% sure a string wizard can bypass it
@unkempt rock You're encouraged to try and break out (and then tell us how you did it)
alright, this whole conversation has been off-topic, to be fair
how? its python related lool
Yeah, if you want to discuss our bot it should be in either #community-meta or #dev-contrib
Discussion on the use cases, implementation and future of the Python programming language including PEPs, advanced language concepts, new releases, the standard library, and the overall design of the language.
ah ok
anyone think the macro or pattern matching PEPs get adopted for py310? they seem controversial. I also want null syntax
those three things would make python much more ergonomic to me
Are there any current optimization projects for the stdlib that have an idea in mind of what to change, but the person in charge doesn't have the time to do it?
Like how a ton of built in functions were migrated to PEP 590(?) vectorcall calling conventions, but that's still going on on 3.8, 3.9, and 3.10a1 iirc, so I'm wondering if there are optimization projects that need extra manpower/womanpower to finish, but have a clear idea of what they're trying to optimize
Greetings, is there a version of multiprocessing.Pool.starmap that returns an iterator like multiprocessing.Pool.imap and multiprocessing.Pool.imap_unordered do?
It's not crucial, but my tqdm-progress bar depends on it!
@icy tartan that would be a good question for #async-and-concurrency
@boreal umbra ah, thanks. Based on the channel name I expected it to be only about async, not all other forms of concurrency. I stand corrected now that I actually looked at the channel description 🙂
Meanwhile I worked around my issue (in not the most beautiful way) by just rewriting the function to take one argument and unpacking it on the first line.
What’s the controversy about pattern matching? I understand the one over macro, and I even doubt they would be userull in python
some think it brings more problems than it solves
anyways, I got a small design question, basically I have a classic Point class with x and y fields, with overloaded addition to support adding coordinates of points
what should I use for isinstance check there?
isinstance(other, self.__class__) or isinstance(other, __class__)?
self.__class__ or type(self)
whats wrog with this
Let's pretend we're building some library, a graph library, say, but you want the library to be agnostic to whether one uses a networkx.Graph, graph_tool.Graph, or igraph.Graph underneath it all. To accomplish this you build some "universal" Graph that provides a consistent interface to all three Graphs. We don't want to litter the start of each method with a conditional that checks which module we're using -- what we'd like to do instead is set our method the first time it's called to interface with the correct module. So how best to accomplish this? This is a rough draft of what I'm thinking: https://gist.github.com/salt-die/ac6b7e75df258bdd4cff6e259ee50909 . This hack is a decorator/descriptor for each method we intend on implementing. My feeling is that there's something simpler one could be doing also involving descriptors.
how best to provide a consistent interface to similar objects across multiple modules? - graph.py
import random
from random import choice
list = ['Luis', 'B', 'C']
winner = choice(list)
print(winner)
@unkempt rock you don't need to type random.choice just choice because of how you imported it
@unkempt rock #❓|how-to-get-help
Is it frowned upon to use os.system() to run shell commands? sometimes there's just an easier way to do something with the shell and it's handy to have it in the python file.
Shot in the dark... Has anyone used python to create images in GIMP?
!docs subprocess.run @stone mauve
subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs)```
Run the command described by *args*. Wait for command to complete, then return a [`CompletedProcess`](#subprocess.CompletedProcess "subprocess.CompletedProcess") instance.
The arguments shown above are merely the most common ones, described below in [Frequently Used Arguments](#frequently-used-arguments) (hence the use of keyword-only notation in the abbreviated signature). The full function signature is largely the same as that of the [`Popen`](#subprocess.Popen "subprocess.Popen") constructor - most of the arguments to this function are passed through to that interface. (*timeout*, *input*, *check*, and *capture\_output* are not.)... [read more](https://docs.python.org/3/library/subprocess.html#subprocess.run)
@desert peak that's nice to know. Most of the time though I'm just running something simple or in my local bin and usually have os imported so this seems a little heavy for what I do. Thanks for telling me about this though.
Is this a true statement that I wrote?
when people talk about "imperative programming", "object-oriented programming", etc, they're talking about general approaches to language design that can inform the design of a given language to varying extents.
🤷🏽 I'm not sure I would contrast "imperative" alongside "object-oriented" @boreal umbra
Imperative vs. Declarative are approaches to programming. One states you use the language to instruct each stage of the way, the other states you say what you want and the language figures out the implementation details
@desert peak I'm not contrasting specific "x programming" terms, I'm referring to the idea of "x programming" in general.
hey all
UPBGE_XR - Chaos ensued
all possible - https://www.youtube.com/channel/UCBmFB9pknFLUjtNgmlXbleQ - because of peter K - Lord loki, youle, and all the bf devs
high level play thing ready for tinkering
this is win64 - prototype
hook into actions in game engine is polling
import bpy
wm = bpy.context.window_manager
value = wm.xr_session_state.get_action_state(bpy.context, "action_set_name", "action_name", "/user/hand/left#path")
Is this a true statement that I wrote?
@boreal umbra I'd agree with that.
I remember Guido said in an interview that python isn't intended to be a functional programming language, but I don't think he or anyone else contests that functions are a core component of the language
So I interpret that statement to mean that functional programming just wasn't the paradigm that he prioritized.
"functions" and "functional programming language" are relatively unrelated
C has no functional features whatsoever, but has functions, after all
the feature that Python has that's most strongly correlated with functional programming languages is probably functions as first order objects. That's a feature that Python has, and that's rare outside of functional languages.
@crystal kindle wrong channels
don't a lot of mainstream langs have functions as first-order objects?
js has it
java and c++ have lambdas now?
Java and C++ have lambdas, but neither of those have functions as first order objects.
C++ lambdas are functors, not functions - they're class instances, not functions.
Likewise for Java, I believe.
Yeah, Java's the same, from quick googling.
C++ also lets you pass pointers to functions around - but that's not quite the same thing as passing functions around.
lua perl php swift rust go julia according to wikipedia
Is PyCharm Edu just PyCharm Community with the EduTools plugin?
Is PyCharm Edu just PyCharm Community with the EduTools plugin?
@coral tree this is a channel for language discussion; you might want to try #tools-and-devops. thanks!
not the channel
how can i access the "vscode" key itself without knowing the name
in the sense like i want to access the second object inside the json
i want to get the "vscode" as the key for the json
Hi guys i am shrivardhana,I am in 7th grade,I am very interested in python.i finished my python course last week.i am looking forward to do my first project
!projects @unkempt rock and wrong channel
Kindling Projects
The Kindling projects page on Ned Batchelder's website contains a list of projects and ideas programmers can tackle to build their skills and knowledge.
!projects @unkempt rock and wrong channel
@♦ Inheritanc-e#1090 👍
To keep things consistent
Because standards = good
Having the same style accross every code bases is very useful
You can choose to make your code more readable than to follow a standard
Less effort reading the code in my opinion
Also copying code from one code base to another is really easy
You can choose to make your code more readable than to follow a standard
@muted crane the issue is, what's readable for you might not be for someone else. And that leads to fragmentation. It's a lot nicer for everyone to agree on one standard as best possible.
As always, there can be cases where you might have to deviate. One rule i commonly flout is the max characters in one line rule.
But by and large, trying to conform to a standard helps everyone
So I don't have to follow it strictly
But you should as best possible.
Because just imagine this very moment. You're unwilling to learn the standard because "it's slightly different from what you prefer.". In avoiding this step, you're creating this very same problem for everyone else who now have to figure out your way of doing things.
This is why standards help. Consistency helps everyone. And if a standard itself is bad, it should be challenged accordingly.
I see
I do have a suggestion to ease the transition. Most modern editors have some kind of code linter or style analysis
Just turn it on, and eventually your warning messages will annoy you enough that you'll do something about it 😅
I heard of those
Most IDEs can also automagically format your code
I personally didn't learn about standards when I started coding. So I had to go through this transition phase too. Just finding that setting on my editor made it super easy.
warning messages anoying
It sounds harder to code with these settings in addition to the problems you face in the code itself
I don’t find it harder once you’re used to those
Besides, most of them have a reason, and will help you further down the road
For example the “attribute assigment out of __init__” in PyCharm can help you catch some nasty bugs
Honestly, pep8 standards are really well thought and designed
I just didn't know about them enough to appreciate it till I had the warning messages staring me in the face.
what is just silly is demanding sorted imports, but most linters do not do that
i think i will configure my linter to use pep8 standards
It will help me in the future, I think
Yeah, might do that too
Hands down my most favourite one is white spaces around operators.
yes
you generally have the formatter do that
It's neat, yeah
It's one I used to get wrong. It really helped code readibility. (and had the side effect of reducing my tolerance for code that doesn't have these whitespace)
I only use whitespaces, but still do imports on the same line
Same for variable assignments
The line limit is worst than he sorted imports IMO
Besides, I am a weirdo and I like sorted imports
yeah, line limit is also not all that great
It's 24 columns right?
line_limit = 100 or I won’t participate in your project :p
80 cols, 24 would be impossible
79
but generally people go for 100-120
Sounds better
the only reason for 79 are old 80 wide terminals, but that is not relevant in 2020
pep8 sounds harsh
Why would they put a line limit?
overly long lines are bad indeed
they are
At least the code is readable, following all other standards
very bd
if I were reading someone's code I'd rather have to scroll in one direction only
I tend to keep my code thin, but sometimes pop in a one-line double-nested f-string lambda lambda double listcomp for fun
Wrong channel btw
but also, self.adults = [member for member in all_members if member.is_of(self) and member.age > 18] is really no worse than
self.adults = [
member
for member in all_members
if member.is_of(self) and member.age > 18
]
is_of? heh
yeah I never was able to get multiline x-comps to "feel" right
Vertically-spaced code is both meh and alright I guess
I’d rather put ... for ... in ... on one line
It feels weird to code a list comp like this tbh
since it doesn’t make much sense to give an additional line
but honestly my code standards are the weirdest
I generally just write things and run black and isort and autoflake on it
https://github.com/nekitdev/iters.py/blob/master/iters/async_utils.py this is kinda style I’m writing in
i'll give you a gross pep8 violation: https://gist.github.com/salt-die/28ff2564f770b0168af6bbfab8747d5a#file-kivy_custom_console-py-L111
I would say that generally, shorter lines are better, but breaking a line into multiple lines just to satisfy the line length may reduce readability
what does it do
Terminal was blocked on my school's iMac, so I used AppleScript to execute shell scripts instead
lmao
pep8 also doesn't like this, and I have no idea why https://gist.github.com/RocketRace/1672fde83395bfcfea8a50da3aa20676
but yeah, pep8 does not like aligned :
Even though CPython's source code does use alignment like that
and often they're screwed up in some place
CPython's STD is non-PEP8 as hell
CPython is pretty much not PEP8 compliant haha
lmfao
well, it does predate pep8 and changing it is not exactly easy
hey, it gets the whitespace right
supposedly the PRs often introduce bugs
ah
or they are too lazy
It would be... fun haha
I’ll fucking do it
i once made a fake "Downloading Windows" program that made a progress bar appeared and my computer lab teacher got spooked
Wait what does black do?
ast comparison taking hours
Enforce pep8?
pep8 is great (don't send hate!)
I doubt compiling rust will be faster than running flake8 on library
being faster than compiling rust is a really low bar
no?
black, in order to ensure it did not screw anything up, checks if the ast of what it outputs is the same as the input ast
it basically checks if formatted code produces same AST
checksum?
oh
AST comparison is recursive soooooo
you don't really need recursion to compare trees, but IDK if black uses recursion
what is STD at, 250k lines?
250k lines???!!
Long-standing question from me: doesn't automatically PEP8'ing code break PEP8? Because of the "A Foolish Consistency is the Hobgoblin of Little Minds" section
Enforcing pep8 into code can be breaking as far as I concern
yes, it can, which is why you write and test with pep8 already enforced
C:\Users\nekit\OneDrive\Desktop\coding\cpython>black Lib --line-length=79```
oh no
lol
what have you done
FUCK it'll do site-packages as well
Lol
I am at /http/ already
well, see you in a few hours
That might take a while
yes
^ pep8 in action right here
/test/ already
test will take a while
error: cannot format C:\Users\nekit\OneDrive\Desktop\coding\cpython\Lib\test\bad_coding.py: unknown encoding: uft-8
error: cannot format C:\Users\nekit\OneDrive\Desktop\coding\cpython\Lib\test\bad_coding2.py: encoding problem: utf-8``` haha
funny
Haha
Did someone challenge you to use black on CPython libs?
Oh good god
almost the end of the /test/
graphlib is apparently PEP8-compliant
1590 files reformatted, 117 files left unchanged, 7 files failed to reformat.```
Is it done?
git diff | wc -l now
windows
Hahaha

+8k lines
I do not like that ratio
now
I'm gonna run flake8

aifc, argparse and ast are only ones broken
and abc
also someone used bare except
Now python -m test
make test -j4 maybe?
test_dict -- test_opcodes failed``` huh
AH
I know why
imagine basing your tests off of non-PEP8-compliant code
there are more but I see
nekit is exposing the spaghetti toothpicks that python relies on
never expose the masters like this nekit!!!
Someone here who knows, how to use pyautogui?
@tough narwhal #❓|how-to-get-help
thnx
Hello
RE: formatting CPython - I do not like Black.
I think its rules are wrong - prefer yapf
I wish these highly adopted frameworks would reach a non-beta state, though
then again, I prefer using tabs in my personal projects with spaces for alignment which linters hate
Ah welp
thankfully flake8-tabs exists
it lets me have my own preference on indentation levels without impacting others @undone hare
Interesting, how does it work?
you use tabs for X level of indentation, but if you have a hanging indent for parameters or something, those will be spaces.
some_fn_call(par1,
par2,
par3)
# ⬆ spaces
def fn():
call_thing()
return 5
# ⬆ tabs
I'm still figuring out how to auto-format in this way using yapf, but it's my goal. my vscode config looks like this:
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.renderControlCharacters": true,
"editor.renderWhitespace": "boundary",
"editor.rulers": [80, 100],
not sure how much I like mixing space and tab like that
oh, discord converts the tabs in the msg
With multiprocessing, does one process slowing down (more data to work with) affect other processes?
it can, yes
!resources
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
How random is the random module?
It uses the Mersenne Twister random generator
the answer is usually: "random enough"
@cloud crypt I don't think security matters. People who implement their own crypto have enough knowledge to use the secure forms of entropy.
and Mersenne Twister is meh on its own
@cloud crypt
What do you mean by that? It's used a lot in simulations and statistical modeling.
let me find a nice table of comparison
to begin with, it has a relatively large state buffer (2.5 KiB), is not cryptographically secure, and can take a while to start generating numbers that pass randomness tests
so yeah, we can just say random enough
Well, sure, so don't use it for crypto
What I meant was, the Mersenne Twister is still used a lot in mathematical and statistical simulations and computations
Well, it said on its doc "The pseudo-random generators of this module should not be used for security purposes"
There's some discussion as to whether or not we should switch to other random number generators, but your review of the Mersenne Twister seems a bit one-dimensional.
alright, I should mention advantages, then
iirc mt is slower and requires more memory than other prngs
It has a huge period of 2^19937, which is nice but not something to really aim for
advantages are that its widely used
and k-dimensional equidistribution
My simulation studies have never been limited by the large memory state or speed of the Mersenne Twister
indeed it’s not like
It's widely used and accepted in academic circles, and has decent properties for most simulations
a bad PRNG
However, there may be newer, better alternatives now
Well, it's by no means said that those alternatives will become new standards like the MT is
In academia, that is
what do other mainstream languages use?
i think v8 uses xorshift128+
java uses some shitty lcg
looks like Rust's rand crate can use whatever the OS supports:
https://rust-random.github.io/book/crates.html
Extended documentation for Rust's Rand lib
i think glibc uses a lcg also
ah, here we go:
https://rust-random.github.io/book/guide-rngs.html
this is way nicer than I remember
Extended documentation for Rust's Rand lib
oh
pyproject.toml" file was found, but editable mode currently requires a setup.py based build.
maybe i've missed something
it sounds like your version of pip is outdated or you're using the wrong flags
or setuptools
``sh
pip is > 20, python 3.8, flags - just pip install -e <pkg> , setuptools I'm not familiar with, if it sounds like there's something obvious i should read let me know
$ python -m pip install -U pip setuptools
already had 47.1 installed
it's on v50+ now
what does your pyproject look like?
the toml file?
yes.
why are you trying to pip -e?
no idea, just thought that's how i installed something in editable mode
only messing around with poetry for the first time
indeed
what if i want to give poetry a path?
wait doesn't poetry put it in the venv already
well i have a package, which has a venv, and i want to install that package in another project with a different venv
@magic python if that's the case, then you build and distribute it
god i hate this too
poetry build -f sdist
i'm just going to use setup
I can't help that your dev process is weird 🤷
why would you want multiple packages installed in editable mode?
no worries, at least setup.py does what i expect without magic i don't care if i type a few more lines
: )
You just don't want new magic
no i don't
if you do pip install -U some_module>=3, and you have version 4 installed, but version 5 exists, will pip not upgrade you to 5?
@desert peak what's the point of asking people on the internet if I have to read stuff?
jk, I didn't know about this pep. Thanks!
Can someone tell me if there is something like automated message on chat after joining the meeting on Teams?
not the channel
where then?
!offtopic this would be the proper way to ask
Off-topic channels
There are three off-topic channels:
• #ot0-psvm’s-eternal-disapproval
• #ot1-perplexing-regexing
• #ot2-never-nester’s-nightmare
Their names change randomly every 24 hours, but you can always find them under the OFF-TOPIC/GENERAL category in the channel list.
Which is better performance
zip(itertools.count,iter) or enumerate functions interms of performance
probably enumerate
probably enumerate
@flat gazelle Thanks for the fast reply
the real question is when you want to zip multiple iterables and also enumerate them
you can zip with a count object if you don't want to wrap enumerate around it all
oh, i guess i should've read a few lines up
i would probably still enumerate even if i was zipping a other iterables
you have to do
for i, (a, b, c) in enumerate(zip(d, e, f)): ...
kinda kills the elegance, but is still better than rangelen
I think it conveys the purpose a lot better tbh
@spice pecan conveys it better than rangelen? yes, by a million years, because then all the items you're iterating over are stated and not just one. The parens are weird for me though.
No, as in enumerate(zip(...)) conveys the idea better than zip(itertools.count(), ...)
rangelen being doodoo is a separate topic, though I do agree wholeheartedly
double quotes or single quotes?
double quotes or single quotes?
@unkempt rock it only depends on the string content, if you want to include in the string a single quote, you need to use double quotes, else if you need to include a double quote you need to use single... there are really no other differences
@silk coyote righto
I prefer double quotes for most stuff
I do single most of the time, that feels like the "default" version to me
I do see the merit in double quotes for consistency with other languages
yeah that kind of thing as well
I’ve had troubles accidentally writing 'string' before
I mostly stick to single as a habit, it's consistent with repr and adds less visual noise
i often switch between ' and " as I switch projects
I wonder about dictionary lookups and increments, while checking for keys' existence:
substrings[substring] = substrings.get(substring, 0) + 1
I generally use the pattern above to autoincrement a value associated to a dictionary key, whether it's missing or not.
The one thing that bothers me is that I suspect it performs two lookups.
Is that actually the case?
When I am performing an operation on a mutable object I can rely on setdefault() which returns the object. I can't do that with immutables though.
In C# one uses an out variable to refer to the value one changes:
@unkempt rock couldn't you use defaultdict?
dict.TryGetValue(id, out var currentCount);
dict[id] = currentCount + 1;
@unkempt rock couldn't you use defaultdict?
@boreal umbra Yes. In this case I am limited to built-ins though.
why
Uni assignment.
I hate that.
Yes, I understand. 🙂
It does perform two lookups, yeah
Although using a defaultdict and a += would have to perform one lookup and one assignment (because int is unmutable), which is pretty close to a lookup in term of complexity
So it is almost the same thing
Just way too much verbose, like any uni assignment
__import__('collections').defaultdict only use builtins though
Hehe
Thanks for the answer, @undone hare!
Anytime!
(it's likely they will check the builtins globals for anything imported, in unit tests :-))
Oh god, if it is unit tested, there sure are ways to bypass it
ah yes
you could also just make your own defaultdict, since I don't think they will care about performance. Consider dict.fromkeys though
__import__
if you already know what keys you will need, dict.fromkeys(l, 0) is better than defaultdict
Oh god, if it is unit tested, there sure are ways to bypass it
@undone hare Yes, I am almost certain. I am being an honourable schoolboy though, so far.
Haha, fair enough
you can bypass most unit tests with type('',(),dict(__eq__=lambda*a:True))()
@still hamlet ask in #tools-and-devops
That's so true lak haha
defaultdict is part of the standard of the standard lib, but it is not part of the builtins module
if you already know what keys you will need, dict.fromkeys(l, 0) is better than defaultdict
@flat gazelle Thanks. I am generating keys as I go though, so can't default-add all of them. Nice thinking though.
@flat gazelle what about raising errors
raise type('',(Types,To,Raise),{})()
``` unfortunately, `Exception.__subclasses__()` is unviable
:incoming_envelope: :ok_hand: applied mute to @ripe cobalt until 2020-11-05 18:58 (9 minutes and 59 seconds) (reason: duplicates rule: sent 5 duplicated messages in 10s).
<@&267629731250176001>
omg that was inapropriate
Let me have a look
NSFW image spam
they deleted it immeditely tho
!ban 491716476764553216 NSFW images spam
:ok_hand: applied ban to @ripe cobalt permanently.
Anti-spam filter @smoky vessel
any best practices for developing packages locally? I.e I'm in an enviroment where I every everything but somepackage installed. I want to test out functionality of someModule inside codeToTestPackage.py. I don't want to add sys.path
├── codeToTestPackage.py
└── somePackage
├── init.py
└── moduleX
├── init.py
└── someModule.py
@delicate ermine you can have a setup.py file and use a virtual environment where the package is installed
as a side note, remember to use snake_case_instead_of_camel_case
so I want to test out some new code and this will not be distributed to users
so if I have a setup.py
it will install locally inside that enviroment?
and then I can test?
as a side note, remember to use
snake_case_instead_of_camel_case
@boreal umbra why do python programmers prefer snake case, whilst pretty much every other lang uses camel case lol
we took it from C
it is referenced in pep8 IIRC
most camel case langs take after java, since java is so popular
@strange sky because other languages are ugly and camel case is a primary reason for that. Though if you need an objective reason, a study showed that snake-cased words are slightly faster to read.
Ohh I see, thanks guys
@delicate ermine sorry, I didn't know that you had replied. if you have a setup.py file and you pip install it with the -e flag, the project will always be available for that virtual environment
Question guys. I’m running my python project from the root directory and all the directory paths I’ve coded into my project are relative to the root directory. The problem I’m having is when I run tests in a sub directory (root-dir/tests) it errors out because the relative paths don’t work. Is their a way to change the relative path on my testing directory so it works with all the paths I’ve integrated into my project
because other languages are ugly and camel case is a primary reason for that. Though if you need an objective reason, a study showed that snake-cased words are slightly faster to read.
@boreal umbra do you have this study? sounds interesting lol
I wonder if that study also takes into considderation that some languages concatinate words
I never knew why camelcase syntax is so hated?
like in english you write Bus driver while in norwegian you write busdriver
I still feel like kebab-case-is-best
so maybe the "how you read words" is dependant on your personal language preference
why not just
`allow spaces in identifiers`
i think that would break keywords
If the identifier is enclosed in ` `, it's fine
right, i thought that was a discord f-up
I think some language do that
fortran lets you do that, kotlin too, cl too
why dont you implement that and see how it works out?
If the identifier is enclosed within ` and `, there is no ambiguity
but i would love to test a branch that has this implemented
oh, you mean, implement it in Python
yes, share it, let me compile it and test it
i have changed the grammar of python before, its not very hard, it just a bit time consuming
i got help from #esoteric-python
Well, it will probably take me a whole week to find where the definition of NAME is located 😅
no rush, but if you manage to do so, let me know 😄
CTRL+F NAME

tf did these lemons come from anyways? I love using them, but they're weird.
Wasn't lemon the original owner?
nope
Was it a team?
there was joe and one more, the other one left and joe has been running it ever since with an increasing amount of staff.
also, off-topic.. so lets not continue here
Can we put multiple image with tkinter using URL?
I tried but it seems to be working only for 1 image
Hm, changing the identifier rules might be a little bit more involved than a single line of code
just a little bit
lol
aha, it's this part https://github.com/python/cpython/blob/master/Parser/tokenizer.c#L1381-L1469
async_hacks
o...okay
Nice
Good to know it !
attempt 1 at adding `-ed identifiers, compiling... :pipenv:
cool.. share the fork with me and ill compile and test it tomorrow 😄
aahh. thanks
will that overwrite my already existing cpython fork?
ill just grab the zip 😄
if you fork it, then yes, probably
you can just clone it to some other place
I should probably modify it so that the backticks aren't included in the name, i.e. `hello` is the same as hello
or maybe not
oh, I might just disallow backticked names without spaces
this all probably belongs to #esoteric-python
Another question: whats the point of a controller class?
outside of mvc framework i dont see the abstraction purpose
what’s the point of a controller class where
Sorry outside of the mvc use case some people use it in abstract cases for example authorizationController or something
this question sounds pretty Java
yeah its a java styled language; Dart, im trying to implement it for data authorization meaning some users have authorization of group data sets
in python though ( i am building it a flask api for sharing customer data depending if they are in the group or not )
They're assigning an attribute named store_name to the objects.
What is a pass? anybody
If you mean the Python pass statement, it's a statement that does nothing at all.
^
@stuck imp Let's not dump GIFs on an on-topic channel
@swift imp To be fair though, dataclasses already imply immutability in some form, that being the entire dataclass being frozen
Yeah but maybe I don't care about hashing and I want only want certain fields to be frozen
As such, having one immutable field with other mutable ones is a bit off for me
I dont see how its off, its like making a read-only property except you still get all the boiler plate reduction that dataclasses provide
I can get around it with a descriptor, its just lame to have to do it
Fair enough
Is it possible to de-interpret python code ?
@severe citrus as in, figure out what the source of pyc files was?
Something link how interpreter interpreted it ? what goes behind the see ?
like equivalent C/C++ code.
It compiles to byte code and then interprets the byte code. Were you wanting to read the byte code?
Like I want to under stand. how below code is interpreted ?
my_list =[1,8,15]
g = (x for x in my_list if my_list.count(x)>0)
Maybe dis.dis can help
!e ```
def f():
my_list =[1,8,15]
g = (x for x in my_list if my_list.count(x)>0)
import dis
dis.dis(f)
@raven ridge :white_check_mark: Your eval job has completed with return code 0.
001 | 2 0 LOAD_CONST 1 (1)
002 | 2 LOAD_CONST 2 (8)
003 | 4 LOAD_CONST 3 (15)
004 | 6 BUILD_LIST 3
005 | 8 STORE_DEREF 0 (my_list)
006 |
007 | 3 10 LOAD_CLOSURE 0 (my_list)
008 | 12 BUILD_TUPLE 1
009 | 14 LOAD_CONST 4 (<code object <genexpr> at 0x7f81fb83d2f0, file "<string>", line 3>)
010 | 16 LOAD_CONST 5 ('f.<locals>.<genexpr>')
011 | 18 MAKE_FUNCTION 8 (closure)
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/ejurexijed.txt
You can find the code that's ran for the instructions in https://github.com/python/cpython/blob/master/Python/ceval.c
Anyone seen this yet? Interesting stuff
https://twitter.com/anthonypjshaw/status/1325023688677208065
will it run on Linux?
will it run on Linux?
@grave jolt Hopefully™
will it run on Linux?
@grave jolt AFAIK, yes. On all 3 major platforms
Windows 7, Windows 8, Windows 10
Windows 7, Windows 8, Windows 10
@grave jolt oh, sorry for the confusion. I meant FreeBSD, OpenBSD and NetBSD
Is the tweet about a dotNET Python implementation
Sounds like pyjion to me
@undone hare
is there a way to tell copy.deepcopy to not copy certain objects? I'm having a little issue where something about pptx.enum.shapes.PP_PLACEHOLDER isn't deep copyable and its erking me
actually its pptx.enum.base.EnumValue
Hmm not entirely sure why that would cause an issue, the source code suggests it's just an int subclass
Maybe open a help thread and add the code/output you are getting
Wrong room. Take up a help channel and I'm sure someone should be able to help you. See #❓|how-to-get-help
why does this typecheck?
from __future__ import annotations
from dataclasses import dataclass
from abc import ABCMeta
from typing import *
class User: pass
class Member: pass
class Guild: pass
class BaseEvent(metaclass=ABCMeta):
...
T = TypeVar('T', bound=BaseEvent)
TT = TypeVar('TT', bound=Type[BaseEvent])
Check = Callable[[T], bool]
class Message(BaseEvent):
author: Union[User, Member]
content: Optional[str]
...
class GuildLeave(BaseEvent):
guild: Guild
HandlerCallback = Callable[[T], Awaitable[None]]
@dataclass
class EventHandler(Generic[TT]):
checks: List[Check]
callback: HandlerCallback[TT]
class Bot:
def listen(self, t: TT) -> Callable[[HandlerCallback], EventHandler[TT]]:
def deco(cb: HandlerCallback) -> EventHandler[TT]:
self.add_listener(t, cb)
return EventHandler(checks=[], callback=cb)
return deco
def add_listener(self, t: TT, cb: HandlerCallback) -> None: ...
bot = Bot()
@bot.listen(Message)
async def on_message(event: GuildLeave): # expected this to error because the type of event must be Message
pass
What's doing the type checking? Are you using a static type checker?
Python does not enforce your type hints and annotations on any level by itself
@plain spindle Checked on mypy, doing reveal_type(bot.listen(Message)) outputs this:
main.py:49: note: Revealed type is 'def (def (Any) -> typing.Awaitable[None]) -> main.EventHandler[def () -> main.Message]'
Bit of a shot in the dark but mypy's probably treating the call to add_listener as being passed a type variable instead of a concrete type
@plain spindle HandlerCallback is a generic type alias, why are you using it as a type hint directly?
"AI" is a very broad term, what do you mean?
You can ask about that in #data-science-and-ml
but what kind of lang does it use ?
there's no "language for machine learning"
If you want to do ML in Python, you use Python
I think he means modules, but there is a huge difference between languages and modules 😂
@plain spindle
class Bot:
def listen(self, t: TT) -> Callable[[HandlerCallback], EventHandler[TT]]:
...
^ this is not right if you want to pass the type of the event as the argument. Consider this:
def f(x: int) -> int:
return x
f(int)
this is cleary wrong, right?
You have to do this:
class Bot:
def listen(self, t: Type[TT]) -> Callable[[HandlerCallback], EventHandler[TT]]:
...
Another issue is that you're using HandlerCallaback, which is a generic type alias.
Why is the deco function even accepting a HandlerCallback? If it should accept the event type specified in the type variable, you should just do
class Bot:
def listen(self, t: Type[TT]) -> Callable[[TT], EventHandler[TT]]:
def deco(cb: TT) -> EventHandler[TT]:
self.add_listener(t, cb)
return EventHandler(checks=[], callback=cb)
return deco
...also, you should make HandlerCallback generic on the T bound to BaseEvent, not TT bound to to Type[BaseEvent]
it's a decorator so it accepts a func
that's why it's accepting a HandlerCallback
the HandlerCallback, being an event handler, is what accepts the event type (T) when the event is dispatched, not the decorator
What do you think about the future of Python and Swift, I am kinda excited to see where it goes
Is there something changing in Swift? I thought it's still an ios only language
I think python will still thrive in long term, but it won't be like an exponential growth and rather a steady growth. I've heard of people want to do datascience in swift but that was just speculation when i hear about it
what do you think the best way for telling if a function is defined inside a class or not? this is one hack-y solution, but it's not entirely fool-proof: (given inside a decorator for context)
from collections import Counter
from functools import wraps
from inspect import signature
def run_n(n):
"""Decorator that allows a function or method to only run n times."""
def deco(f):
instance_run_counts = Counter()
@wraps(f)
def wrapper(*args, **kwargs):
# determine if a function was defined in a class
if (params := signature(f).parameters) and next(iter(params)) == 'self':
if instance_run_counts[id(args[0])] < n:
instance_run_counts[id(args[0])] += 1
return f(*args, **kwargs)
elif wrapper.nruns < n:
wrapper.nruns += 1
return f(*args, **kwargs)
wrapper.nruns = 0
return wrapper
return deco
You don't really have much more information at the definition time
probably true, i thought something might exist in inspect or similar that could tell
You could go through the frame but that's even hackier
5. Do not provide or request help on projects that may break laws, breach terms of services, be considered malicious or inappropriate. Do not help with ongoing exams. Do not provide or request solutions for graded assignments, although general guidance is okay.
I have this function and I was wondering whether there was some way to return instead of print
def fib(n):
for i in range(len(funclist := [])+n-1):
(i==(n-2) and print(funclist[i-1]() + funclist[i-2]())) or funclist.append(lambda i=i:funclist[i-1]() + funclist[i-2]() if i>1 else 1)
does that actually work?
feel free to try, but you need python3.8+ due to walrus
also, i think #esoteric-python is a better place for this
thanks, will try there
this might be a silly question but could multi-threading / multi-processing be compared to quantum superposition
because if you think about it, if i wanted to display a progress bar while my program executed a function which it downloaded 5 different files
if i wanted to display only 1 progress bar
that would mean that the progressbar exists in 5 different states which constantly change every millisecond
so if you consider this
progress_bar = Bar(random_value)
time.sleep(0.01)
progress_bar.update() # makes a new random value
this would mean that a random bar for displaying the downloads is a feasible option
because essentially, it is switching between the progress of the 5 different downloads
which are all in different states
well not exactly superposition but it seems very similar
its just on a smaller scale
ps: for those who don't know what superposition is, its a certain object existing in different states at the same time
ehh...not exactly
@feral cedar well what do you disagree with?
sure, i agree, you could make the comparison and it does make sense
Can somebody pm me and help me with something very easy?
lmaooo @feral cedar i know the question isn't directly related to python but i need a justification to place a random progress bar for my multiple downloads
why not just have 5 progress bars though
@feral cedar well thats the issue lol i can have that but its kinda broken because it keeps on glitching due to the values continuously changing on other states of the progress bar
its kinda hard to explain but its the the terminal doesn't know what to do lol
@gaunt osprey you can now use python in Swift
What
I noticed that numpy arrays doesn't support chained comparisons. I assume chained comparisons for native types have a special grammar?
I remember reading the EBNF grammar, chained comparisons are weirdly parsed, but I do not know more about it
a == b == c is the same as a == b and b == c
Python doesn't know the types at parse time, so grammar doesn't affect that
I'm not actually sure if it is interpreted like that
!e
import dis
def f():
return a == b == c
dis.dis(f)
3 0 LOAD_GLOBAL 0 (a)
2 LOAD_GLOBAL 1 (b)
4 DUP_TOP
6 ROT_THREE
8 COMPARE_OP 2 (==)
10 JUMP_IF_FALSE_OR_POP 18
12 LOAD_GLOBAL 2 (c)
14 COMPARE_OP 2 (==)
16 RETURN_VALUE
>> 18 ROT_TWO
20 POP_TOP
22 RETURN_VALUE
Was about to do that
well, the expressions are equivalent
Hmm
@grave jolt :white_check_mark: Your eval job has completed with return code 0.
001 | 3 0 LOAD_GLOBAL 0 (a)
002 | 2 LOAD_GLOBAL 1 (b)
003 | 4 COMPARE_OP 2 (==)
004 | 6 JUMP_IF_FALSE_OR_POP 14
005 | 8 LOAD_GLOBAL 1 (b)
006 | 10 LOAD_GLOBAL 2 (c)
007 | 12 COMPARE_OP 2 (==)
008 | >> 14 RETURN_VALUE
Yeah, it seems to just be an optimized version
I remember reading the EBNF grammar, chained comparisons are weirdly parsed, but I do not know more about it
@undone hare It is actually not much different than any separation (likex (',' x)*), the only thing that is different is the separator can be any of the comparison operators. Later on it is translated to AST as is (left is single value, and all comparators are in a list, and also all of the comparison operators).
comparison: expr (comp_op expr)*
a == a in b
Module(
body=[
Expr(
value=Compare(
left=Name(id='a', ctx=Load()),
ops=[
Eq(),
In()],
comparators=[
Name(id='a', ctx=Load()),
Name(id='b', ctx=Load())]))],
type_ignores=[])
Very interesting, thanks!
Thank you for this
What's the fastest threading?
Anyone have some solid examples of a non-ORM based Repository Pattern in Python? I've got a MONSTER of an older Database.py lib that I want to move to a proper pattern based organization while I also switch over to asyncpg. Any guidance would be wondeful 🙂
@reef egret so you're wanting to construct a wrapper around an old database?
Not exactly - Just to rewrite my existing db lib setup I made (its a giant monolith of a python file)
so what do you mean by "pattern" in this context?
Repository Pattern is a design pattern
in my experience, there's very little discussion of design patterns in the Python community.
👍 gotcha
wasn't sure how much of that translated into Python
If you have say... an Animal and Person class that contained SQL statesments and operations specific to them - but you wanted them to share a DB instance - would you just send the DB instance in as a constructor param?
There are a couple of "patterns" that I guess exist in Python. For example, I like to have class method constructors
so you're not making a new connection for each of them essentially
but I haven't heard people talk about "design patterns" for the high-level architecture of a project.
interesting, Google produced a ton of results they were just all ORM based
is that bad?
nah I just cant use an ORM for speed reasons
ah
sure makes dev easier though heh
asyncpg is pretty sweet though
I'd been using psycopg2 until now
I don't think I have anything else to contribute, but we do have a #databases channel. activity across the server will probably pick up in a few hours.
Also discovered this today - https://pypi.org/project/databases/
sweet thanks @boreal umbra !


@unborn mortar all you need to do is to update your discord.py to 1.5.x (latest) version, along with implementing intents (https://discordpy.readthedocs.io/en/latest/intents.html)
@reef egret Wouldn't it just be easier to use SQL with python?
that's what I'm using atm
took like 5-10 mins to set up
shit nvm, didn't look into that link
lol
Hehe
Any idea on how I can save the configuration I made to my gui application that I made in python
So for example, this gui has theme setting which changes themes, the default theme is dark, if i changed it to white, i want when i close the program to save this configuration, so when i get back, it should be white, and so on for the rest of the settings
not the channel?
Sorry?
@grizzled lichen not the correct channel for that
!warn @grizzled lichen Please do not use #internals-and-peps as a help channel.
:incoming_envelope: :ok_hand: applied warning to @grizzled lichen.
Oh, so now we warn people immediately? If they don't read the description or use the channel properly?
My main discussion here was about something really cool in python
It was about decorator syntax
It looks like there's more than one way to call decorator
For example there's the pie decorator syntax, pie decorator and space
List before def syntax
Why do we really have all this syntax when we could have only one?
Could you list concrete examples of that?
Not really sure what you mean by these pie decorator syntax, pie decorator and space
@classmethod
def foo(arg1,arg2):
...
This the pie syntax
[classmethod]
def foo(arg1,arg2):
...
This is list before def syntax
There is also another variation where the list is after the function definition
huh?
It forms decorators like this
def foo(arg1, arg2) [ complicated(manyArgs=1, notTooUgly='yes'), even_more_complicated(42)]:
...
I'm fairly certain that the latter one is not decorator syntax
It is
How exactly?
Guido made it describing the extent of decorators
Mind linking where?
ah, I mean those are just proposals
So they aren't really in the language?
No
And what do you think about them?
This might just be because of my bias towards the proposal that survived but I do think that the @ syntax makes it clearer what you're actually doing with the function
To be honest, the one that has a list after the function definition looks really cool
I guess it would give more freedom in declaring the decorator?
With the amount of arguments it gives of course
Specifically, decorator application really is just
func = deco1(deco2(func))
```it perfectly makes sense for the decorators to be outside of the function, and to have them be signified by an `@`, which can be read as `apply`
So that's why we chose the one which is commonly used today
You could also consider the flexibility of it, considering that any valid Python expression can be a decorator
For simplicity in reading the code
I guess using the @ syntax also makes it prettier to read , in comparison to the others
I should test on decorators and see how far it can expand with this syntax
!pep 614
Here's a fairly recent one
the [] syntax feels really strange to me, how would that work in a repl?
>>> [1, 2, 3]
[1, 2, 3]
>>> def fn(): ...
...
The proposals state on both the @ syntax and the list syntax does break on the REPL, but it seems like the latter one does break harder
ah true, I guess the @ needs special treatment in the repl already
it needs to wait for what the next line will be
though @deco without a following def is invalid syntax, whereas the list isn't, so I guess that makes it "worse"
I've read that compilation document on proposed decorator syntax before, but I'm so used to the current syntax that I can't really be objective anymore
Most of the alternatives just seem less readable and/or more verbose to me, especially those trying to force it on the def line or adding a level of identation
we have enough indentation problems in python :x
I build web apps, lots of with: indents
with integration_conn:
with db_conn:
with db_crsr:
with A() as X, B() as Y, C() as Z:
do_something()
fyi
@brazen jacinth would that work when one of the latter statements relies on the previous?
I always forget you can compound with statements
I assume there's also code between each statement
sometimes yes, sometimes no @radiant garden
if there's code with each statement, i don't really see a problem
indentation merely seperates blocks
if you need one with the scope of a context manager, i don't see why that is a problem
They create the exact same bytecode
!e
import sqlite3
with sqlite3.Connection() as a, a.cursor() as c:
print(a)
print(c)
You are not allowed to use that command here. Please use the #bot-commands channel instead.
Also got proper implicit line continuation in 3.9 for it
mmm, my sqlite test is no good, it doesn't use a context manager
Also, if you want to keep your code linear instead of separated across different blocks, you might want to give ExitStack a try.
So I never noticed the Python logo is two snakes. That's clever.
Yea took me a while to notice as well
!pep 638
Does anyone know what Macros would gain Python?
@desert peak i worry more confusing code
well that's true of any feature, but my question is pointed.
@desert peak You mean, what advantages it might have?
@grave jolt correct. what advantages does it give Python over its current state?
I read that it can enable features without being built into the language and that interests me a lot
yes, it's for trying out new syntax and semantics for features
for example, pattern matching
or 'do-notation' from haskell
the majority of people will probably hate your new favourite feature, but your personal project or your team might still benefit from it
dreams of all the features
so basically it takes insert feature and generates python-valid code from the symbols to the macro?
like.. what macros do? lol
hm, interesting. so would your source files always have a .pyc then?
what do you mean?
well, just running a python script doesn't result in compilation
I mean, a compiled file
Python source code is first compiled to bytecode, then that bytecode is executed
its very common that your IDE will hide them from the file viewer
that bytecode may or may not be saved to a file
where is logic that determines that? I don't ever see pyc files generated in my projects (though I do see __pycache__)
or 'do-notation' from haskell
when this:
do as result:
x := get_line
y := get_line
print_line("answer is:", x, y)
pure(None)
is transformed to this:
result = get_line.flat_map(lambda x: get_line.flat_map(lambda y: print_line("answer is:", x, y).then(pure(None))))
what is do notation, compiling a block to a single result?
"do-notation" allows you to write a chain like that in an imperative way
it's used in Haskell
sounds like Rust's blocks
let result = {
let x = get_line();
let y = get_line();
println!("the answer is: {} {}", x, y);
None
};
no, that's a different thing
it (#internals-and-peps message) actually gets transformed into a chain like this
it's just building up a data structure
not performing all those operations
I guess do-notation is already implemented in some Rust crate
I guess do-notation is already implemented in some Rust crate
wait there is this do-notation in some Rust crate ! Impressive 😂
I guess you can do something like
with do as result:
do.x = get_line
do.y = get_line
do(print_line("answer is:", x, y))
do(pure(None))
interesting
oh, well, I've got an idea for a package 
oh, well, I've got an idea for a package
oh oh 😈
in the shutil module, on linux specifically, shutil calls os.sendfile() for copying files, why do that when you could just do:
with open(file, "rb") as file:
# write to new file
is it because they need a way to tell when the end of the file has been reached? i.e sent == 0
I'd guess that sendfile is more performant
ah alright. ty
@deft pagoda if called as an instance method, the first argument will have a __func__ attribute pointing to the uninstantiated version. check if args[0].__func__ is f
🐍 class F:
•• def g(self):
•• pass
••
🐍 F().g.__func__
<function F.g at 0x7fca6637b3a0>
🐍 F().g.__func__ is F.g
True
caveat: this may be a CPython impl detail
Please don't tell me I'm imagining a bunch of emoticons in your code
Just a custom repl skin
check out sys.ps1 and sys.ps2 ; )
export a script to PYTHONSTARTUP in your shell and enjoy
I personally have mine set to an ipython-like In [line]:
That being said... I wonder what's the wackiest repl prompt I could realistically work with.
Maybe this idea is closer to #esoteric-python in nature, lol.
@grave jolt wouldn't it be this?
with result as do:
do.x = get_line
do.y = get_line
do(print_line("answer is:", x, y))
do(pure(None))
@radiant garden bruh i didn't even know about PYTHONSTARTUP
i just wrote a virtual env wrapper script which copies my sitecustomize.py file into every venv 
lol
@viral flame @dark granite this is a discussion channel, for questions of this kind I would suggest #❓|how-to-get-help, this is not the proper channel.
@unkempt rock no, because do is the access point, and the resulting expression will be stored in result
actually, to make it threadsafe:
with do as result, h:
h.x = get_line
h.y = get_line
h(print_line("answer is:", h.x, h.y))
h(pure(None))
why are sets left unordered when dicts are ordered?
it would make sense for them to have consistent behaviour right
I don't remember the rationale for making dicts ordered but one did exist and it was meaningful
sets are optimized for fast in checks, and the current best way to do that is with using sets unordered
dicts are ordered because it is an implementation detail of how they are written, and if it were not part of the spec, it would lead unportable code
The reason is that sets work differently behind the scenes and it's not easy to make them remember insertion order while also keeping the flexibility of the set operations
idt the dict optimization applies to sets anyways
Since sets, as a mathemacal construct, don't have an order, it's not a priority to make Python sets retain order
@kunsv Sets use a different algorithm that isn't as amendable to retaining insertion order.
Set-to-set operations lose their flexibility and optimizations if order is required.
Set mathematics are defined in terms of unordered sets.
In short, set ordering isn't in the immedia...
since people would use dict ordering, and then it would not work outside cpython or when cpython decides to switch impls
Although, arguably, I haven't followed later discussion on the topic in, say, the dev mailing list
Maybe there are some new plans now, but I wouldn't hold my breath, as sets being sets is the main priority
dicts are ordered because it is an implementation detail of how they are written, and if it were not part of the spec, it would lead unportable code
@flat gazelle That seems backwards. Like I'm not disputing this but I mean it feels wrong that python got a feature due to one particular implementation currently having that side-effect
it is useful regardless, but it was orginally just an implementation that did not hold when keys get deleted
but it was easy enough to enforce
It was introduced as an implementation detail in Python 3.6, with every warning that it wasn't a part of the specification
If users were opting to rely on a previously unenforced implementation side-effect that was on them surely
Again, I'm not complaining but it just seems a weird justification for adding as a feature
Maybe, although it could also be considered a bit "tone deaf" if you break it in a few years now that is has been something that a lot of people started relying on
"A new implementation meant dicts were ordered, which some users started to rely on so now we are going to make it enforced"
a language should not make it easy to do the wrong thing, and dict order made a lot of things much easier
I think an earlier implementation even had deliberate scrambling of the order to prevent people from relying on that implementation detail
Surely that same logic could be used to justify making anything currently a CPython implementation detail the "standard"
In part, although some things may be far more obscure and far less discussed than this implementation detail
a language should not make it easy to do the wrong thing, and dict order made a lot of things much easier
@flat gazelle Did people previously assume dicts were ordered? I feel like I learned very early dicts were unordered?
The "why don't dictionaries retain order" has been a frequently asked question for a long time before 3.6 introduced it
if you aren't sure, pop open a repl and check, and see that they are, you are not going to question it further
But there are lots of "why don't/doesn't..." questions which won't ever get changed
Just seemed a bit unnecessary to me and I do sort of find it more unintuitive for dicts/sets to have differing order behaviours than to have the same
I think there was a point at which the decision was made that scrambling it on purpose just to not have that order show up was a bit weird as well. I think that was the decision that ultimately led to it being adapted into the language.
Dictionaries are so common and so many people really want their dictionaries to maintain order for some of their features, that once regular dicts did maintain order, people just started using it. And, at that point, you can go back and say "We told you it was an implementation detail" whenever it changes in the future (which could have been years from now), but I don't think that would have gone over well with a lot of users.
I agree that it's not a perfect reason, but it's a reason that makes sense once you're in the situation of having "remembering" dicts
I mean surely the answer to that is don't document it in the first place?
Like, if no-one mentioned they retained order even as an implementation detail would anyone have actually used it?
ive never understood why people wanted dicts to be ordered anyways? its not like you can do dict[0] to pull out the first index
people will rely on the behavior regardless of documentation if it seems consistent
It started to be discussed by a lot of people already, people who are intimately familiar with the implementation
people will rely on the behavior regardless of documentation if it seems consistent
@radiant garden Then people are dumb
It's nice to have and most major implementations did it anyway
One of them even suggested in his Python talk something along the lines of "If you like this, like I do, just start using it! They can't change it then"
that is a bad argument. You do not want magic behavior which is not actually guaranteed
programmers should not have to be smart to write python
I'm not sure who that is aimed at?
