« first day (3741 days earlier)      last day (1208 days later) » 

12:18 AM
python Newbie: I have imported turtle but cant get it to work on my vba and pycharm? Did exactly what my instructed did but no result here ... here is my code:
from turtle import Turtle, Screen


timmy = Turtle()
print(timmy)
timmy.shape("turtle")
timmy.showturtle()
timmy.done()


my_screen = Screen()


print(my_screen.canvheight)
my_screen.exitonclick()
 
 
1 hour later…
1:19 AM
Found yet another SO-plagiarist site: Quabr [5.9.10.113]...
 
 
6 hours later…
7:19 AM
@DiyaShetty What do you mean, no result? Is there an error? Does it hang? Is the code not executed at all?
 
cbg-ning
 
7:52 AM
he-ll-o
 
 
1 hour later…
8:56 AM
@Marco There really isn't "the one" intuitive way. What you describe is 3D data (R*C is roughly R^3) which is always lossy to represent in a 2D Plot. What feature of the data do you want to show primarily?
 
9:09 AM
Hello!
 
9:28 AM
one of my recent edits to remove 3.x was rejected by op, op then removes it in a new edit -_-
 
That's kinda fair tbh, making a tiny edit like that and forcing 2 people to review it is just wasting their time
 
you need 2 people to review? I thought any one user with enough rep or OP can accept
 
Yup, it needs to be approved by 2 people. Although there's a workaround where someone can press "accept and edit", then it goes through immediately
 
10:02 AM
Yeah, it's better to make suggested edits substantial
Unless the post is perfect (which it rarely is)
 
noted
 
Random musing of the day: My excitement for PEP 612 is directly proportional to Callable[..., Callable[[Callable[P, Awaitable[T]]], Callable[P, Awaitable[T]]]].
 
Have there been any interesting peps lately?
 
There are some nice PEPs on typing, but whether that counts as "interesting"... :P
 
10:18 AM
typing has been growing in complexity for ages, nothing new there
 
The 3.9 change of making builtin types generic has helped a bit, and the new syntax for unions also makes things simpler.
The most recent typing joke: There's a new Python type checker... implemented in JS.
 
that's... I mean... I don't... why
 
It's by Microsoft, so... ask Guido, I guess. Pyright
 
ah, vscode
 
10:39 AM
from the current PEPs, it seems there's really just typing and pattern matching, plus some CPython internal stuff.
sadly, PEP 603 / frozenmap seems to be, ahem, frozen for the time being.
 
11:26 AM
cbg
 
11:52 AM
cbg!
 
cbg
 
12:20 PM
@MisterMiyagi I'm guessing existing tools have been rejigged for Python, but I know no more than anyone else.
 
12:40 PM
Good guess. Probably re-using some TypeScript things.
Snarking aside, it seems to be pretty good both in terms of functionality and usability. Might be worth a look for all the typing aficionados around here.
 
user13727121
Is NOTE a keyword in Python? I'm using VSCode, I just commented something and put a NOTE: like this, the word "Note" gets highlighted.
 
@AndyK nothing comes up on console..
 
@DiyaShetty ha ha dude
 
Told you I'm a newbie
 
@CoreVisional many IDEs and editors highlight NOTE, TODO and similar to make them findable.
it is not a Python keyword.
 
12:55 PM
@CoreVisional if it were a keyword then it wouldn't be highlighted in a comment
 
user13727121
I see now, thank you @MisterMiyagi and @AndrasDeak
 
4:28 PM
Hi
 
4:39 PM
cbg
 
5:05 PM
how are you @mis
@MisterMiyagi
could maybe help me with this thread:
0
Q: Function in pytest file not able to get PARAMS from conftest file

rel.foo.fightersI have the below test_dss.py file which is used for pytest: import dataikuapi import pytest def setup_list(): client = dataikuapi.DSSClient("{DSS_URL}", "{APY_KEY}") client._session.verify = False project = client.get_project("{DSS_PROJECT}") # Check that there is at least...

 
@A.Man are you question banned?
@A.Man 1. Don't ping random people for help, 2. Don't create sock accounts to get around a question ban cc. @arielma
 
ok
 
5:20 PM
Is there some shorthand for reduce(operator.mul, ...) in recent versions? I know of math.prod but it needs a start value.
Or more generally, are there premade variadic versions of the operators?
 
5:35 PM
@MisterMiyagi Why wouldn't a start value of 1 be appropriate?
 
Custom class?
 
I was going to say "numpy.arrays" because that is what triggered the thought, but now I realise that operation is fine for them. :/
So, erm, What Andras Said.™
 
np.prod came a lot sooner than math.prod...
 
If multiplication is defined, either there is or is not a unit object. If there is, use that. Otherwise you are hosed.
 
6:04 PM
Cbg all.
I would like to know if anyone in the room has experience with using Python for Robotics?
 
6:24 PM
@CoreVisional No, nothing to do with Python, but many IDEs by convention recognize certain 'special' strings like 'TODO:', etc. I just noticed MM said that already.
 
hey guys. i have question. lets say i have 2 python files. model.py and controller.py. then i import glob module on model.py, do i need to specify it in my main controller.py also? since i want to compile it later to .exe with PyInstaller
 
@MisterMiyagi yeah for toy examples, but won't reduce(operator.mul, ...) still thunk between Python and numpy APIs a lot, it'll be very inefficient on a long list of arrays . Isn't np.prod() what you need?
 
or does it recognize it automatically?
 
@smci I'm not targeting numpy by choice. The issue has arisen on a question where the problem was presented generically, and the OP introduced numpy after the fact.
 
6:40 PM
@lone_coder You need to have the glob name defined in the module you are using it, independent of PyInstaller. At least it would be terrible if pyinstaller changed how names were looked up.
 
6:54 PM
@MisterMiyagi Well I'd use np.prod() on the np stuff, and reduce(operator.mul, ...) on base Python stuff. Not sure whether to write LBYL code, or separate classses, or whatever.
 
you normally don't have ndarrays mingling with native non-scalar types
and I suspect np.prod would even work with lists, due to an automatic conversion to ndarrays
 
 
1 hour later…
7:56 PM
hey guys
someone can help me to make function to pipline using with lambda
 
@arieldomchik please don't ask for help here with fresh questions on the main site as per our rules
 
ok sorry
 
On a side note, pressing logic down to a single line will only make code worse
 
hey guys, is there a good code mapper addon for vscode that includes showing imported functions your using. Trying to organize a big bundle of functions between different so it'd be nice to kind of be able to look at where they are co-occuring in the code
 
8:21 PM
btw, is there a nice way to save %whos DataFrame to a file
 
does anyone know how to handle both stdin and actual files? I already know some template for either of those but don't know one that do both :/
(I'm on Linux)
Mostly so i can pipe string to it through stdin, but also use file as argument when i want to. I tried to use sys.argv from the sys package as file using open() but it obviously wouldn't work
 
@NordineLotfi you'd need sys.stdin
 
hmm, guess it's probably worth it's own question...
@AndrasDeak oh
 
sys.argv is about command line arguments (and it's just a list)
 
8:37 PM
import sys

f=open(sys.stdin)
print(f.read()[::-1])

sys.exit()
 
nope
open('input.txt') <-> sys.stdin
sys.stdin is already a file-like object, just like what open() returns
(and you don't need sys.exit() at the end of a program)
 
@AndrasDeak I once found sys.exit() on a script and ended up using it since then...though it would be better to keep though that was probably just an impression :)
 
@NordineLotfi that's just clutter at the end
 
gotcha
 
import sys
from contextlib import nullcontext

input_path = None  # or some string or path object

if input_path:
    # open file
    context = open(input_path)
else:
    # read from stdin
    context = nullcontext(sys.stdin)

with context as f:
    data = f.read()
that adds the good habit of context managers on top of opening files (when necessary)
if you ignore the context manager part you can do f = open(input_path) in one case and f = sys.stdin in the other case
 
8:42 PM
@AndrasDeak gotcha, i never used context managers before, guess I'll start now :D
 
of course that example will likely hang due to the endless read from stdin :P
 
It doesn't hang, though..?
 
@BožoStojković I mean if you don't attach anything to stdin
it wasn't clear, sorry
 
Ah I see. I was wondering if there was something that I'm missing.
5
A: Python: convert list to generator

Cameron Sparrimport itertools iter_data = itertools.chain(data) like so: In [10]: data Out[10]: [1, 2, 3, 4, 5, 6, 7, 8, 9] In [11]: iter_data=itertools.chain(data) In [12]: iter_data Out[12]: <itertools.chain at 0x1ce8950> In [13]: iter_data.next() Out[13]: 1

Why is this answer using itertools.chain(data).next()? Is that a Python 2 thing?
 
9:01 PM
@BožoStojković yes
 
Oh, ok. Thanks
 
But you don't have to look that deep. The answer is iter(lst)
 
Oh... Awesome!
Can't believe the answer was so simple :P Python ftw
Oh, it's right there in the comment too. Silly me
Also, should've scrolled down.
 
9:16 PM
it's also hidden in the top answer
 
Yeah, that's what I meant by scrolling down :)
And now I know the thing I was looking for is actually called an iterator, not a generator.
 
ah, yes
 
I don't really know what iter() buys you in that example?
 
I just want to use .next()
Oh, in that example
 
@BožoStojković tough luck :P
use next() instead
 
9:21 PM
Oh, I meant next() :P
Gosh, I hope it won't stick
 
 
1 hour later…
10:23 PM
Hey again :P
I created a lib that is used within Jupyter.
The lib accesses a db. How should I provide the db path?
My ideas (code in notebook):
a) MY_DB_PATH = 'XXX'
b) my_lib.config(db='XXX')
 
10:36 PM
Please don't ping people unsolicited with your questions
How you provide the credentials to the DB is up to you. Typically you can put them in a .env file that is not included in your repo (using .gitignore) and then load them into the environment at runtime. I actually really dislike Jupyter so I don't know how much of a hassle that is.
 
Got ya, sorry.
 
@roganjosh
Thanks, I will consider that idea. It feels pretty clean!
Why do you dislike Jupyter btw? It's a good learning tool in my opinion. Maybe not so much for professionals?
 
Because I generally look beyond just data exploration but actually the system I want to deploy, so I'd rather something explodes as-a-whole vs. individual cells throwing errors
 
does anyone know how to sort numbers from the output of print() but without it being a list?
(in natural order)
most solution i tried or seen were only using list :/
and i only need to sort the output of print() in this case
 
10:50 PM
Lots of my colleagues use Jupyter for data exploration but it says nothing of productionising a solution
 
@NordineLotfi the output of print is None
 
@NordineLotfi what is your code?
 
sounds very much like an XY problem
 
@AndrasDeak then there no way? wanted to emulate what i usually do with the sort command on linux when i pipe strings with numbers in it
@roganjosh don't have any at the moment, but trying things out
 
I don't think he suggested there was no way
 
10:52 PM
@NordineLotfi use a list after all?
 
@AndrasDeak so i have to transform/format what print() output in a list then?
 
collect things you would print in a list, only print after sorting
 
@NordineLotfi I strongly suggest you start coding on it and come back with an example where things aren't working for you after you've implemented some approaches
 
@roganjosh yeah, i did try stuff but i don't have a concrete example yet :)
 
Making that example will help solidify the issues/misunderstanding you have :)
 
11:21 PM
hmm, different question but, is there an equivalent or a way to make readlines work with print()?
trying to make:
my_list = open("filename.txt").readlines()
but without the need of using the open() part, so i can use the output of another function/or print()
 
I don't follow at all
 
"Python file method readlines() reads until EOF using readline() and returns a list containing the lines"

But i want to do this on either a function (that return/print some values) or print(var) directly, instead of using open() like the above example...
 
But nothing in that code prevents you from passing things between functions. open() creates a file object; you could pass that elsewhere. readlines() gives you a list that you can also pass around
 
@roganjosh so open() doesn't just work on file? :O
 
I didn't say that
I was referring to your specific line of code
 
11:28 PM
oh
essentially I'm using a tuple, but trying to format it to a list
 
You need an example. I suggested it earlier. Please make it.
 
alright
 
@NordineLotfi you need open() to... open a file. If you don't want to open a file you don't need open(). See my earlier example to you that either opened a file or used stdin. Once you have f in the context manager you can do f.readlines(), as long as f is a file-like object that has this method.
But yeah, your requirements and confusion are not clear at all.
 

« first day (3741 days earlier)      last day (1208 days later) »