« first day (3125 days earlier)      last day (1815 days later) » 

5:00 PM
if you're building a package, you shouldn't need to mess with sys path
 
I got another question:

If I call `C:\Users\Hendr\Desktop\python>pytest tests/test_processor.py`
is `C:\Users\Hendr\Desktop\python` my current working directory
or
`C:\Users\Hendr\Desktop\python\helper_py` where open is called?

->
E FileNotFoundError: [Errno 2] No such file or directory: 'test/res/unprocessed.list'

Referring to
https://docs.python.org/3/library/functions.html#open
 
i can guess the hitch, which got me a couple days earlier too. if you have an init file present in the current directly, you can no longer import a python script in the current directory directly by name. Just write the foldername.filename instead.
 
Ah so @ParitoshSingh you tell me to set up an ./__init__.py so I can access helper_py/processor.py by import helper_py.processor ?
 
yeah, sorry if i make you repeat yourself, but can you just quickly rewrite folder structure, this time mentioning all init files too?
 
.
./helper_py (has init)
./tests (has init)
I just added these inits, didn't need them earlier
 
5:04 PM
So, the . folder, does that have init? and what is it
 
no init
 
what's the name of the folder you're using . to refer?
you'll have a nicer time with an init and a name for this . folder. it will tie these two together into a single package. alternatively a script in the dot folder importing both helper and tests material
the idea is, you need a link at the . level. (and im tired of writing . at this point :P why dont we give it a name)
 
I never call from . import
 
Hmm, I wrote up a little sample project to prove that guy wrong and that you do need an __init__.py in order for a directory to act like a package, but now that I run it, it seems like he's right???
C:\Users\Kevin\Desktop\deleteme>tree /F .
Folder PATH listing for volume OS
Volume serial number is 00000200 6E1D:CD3F
C:\USERS\KEVIN\DESKTOP\DELETEME
│   foo.py
│
└───pancakes
        bar.py


C:\Users\Kevin\Desktop\deleteme>type foo.py
import pancakes.bar
print(pancakes.bar.troz)
C:\Users\Kevin\Desktop\deleteme>type pancakes\bar.py
troz = "if this gets printed, then pancakes is acting like a package"
C:\Users\Kevin\Desktop\deleteme>py -3 foo.py
if this gets printed, then pancakes is acting like a package
 
All I do is from .profile import Profile in helper_py
@Kevin revoke that downvote :P
 
5:07 PM
@Kevin what you have now is a different kind of package
It's not a ~regular~ package, it's a namespace package
They are different and have different uses
 
Cool, cool.
 
You may need __init__.py in some cases
You don't need __init__.py in other cases
 
Like in 0x45's case, you need it, I assume?
 
Nope
 
ಠ_ಠ
 
5:09 PM
when in doubt, init everything!
 
And namespace packages appeared in Python 3.3, not Python 3
 
ducks and hides
 
I guess I better go and actually read up on this.
 
@ParitoshSingh can you help me with a nice "package structure"
for my
.
./tests
./helper_py
./engine_py

goal is that I can "easily" access everything in this ecosystem
 
the folder at the . level, what name does it have?
 
5:12 PM
as in import helper_py.processor
C:\Users\Hendr\Desktop\Python -> is "."
so yeah. I think I kinda lack a folder LOL
 
ok, rename/make another folder.
something like "myprojectthathaseverything"
(ps. please dont use that name lol)
 
It doesn't matter, because if you run pytest like that, it doesn't add the current directory to sys.path
 
@vaultah can you explain?
 
SMH
thought the root init would fix it
 
5:16 PM
patience. what name did you give to it
the root folder
 
But I still like the way of importing if I had a root __init__ so I think ill give it a shot
myprojectthathaseverything
 
groan
 
:-/
 
well, i chuckled, while regretting my decisions in life at the same time, so that's something
 
myprojectthathaseverything
myprojectthathaseverything/helper_py/__init__.py
myprojectthathaseverything/engine_py/__init__.py
I did not set up an init for root yet
 
5:18 PM
ok, give it an init
 
cuz ill need to reorganize every import then right?
 
bingo
 
smh
 
you can now use the root folder as reference.
 
soooo
import helper_py.processor or from helper_py.processor import Processor ?
 
5:19 PM
one more level. the root folder name goes first
 
ouch
 
which is why you probably should rename it to something better :P
 
and how would I archive my scenario above
 
uh, now just import off of the root folder's path, should work right?
actually, lmk if it doesnt, curious.
 
Whats the "best" linux dist for development with intellij editors?
 
5:24 PM
Is there a way to get a hold of the current code being executed? I want to run code and print the code I'm running as part of that code's output.
 
@ParitoshSingh didn't refactor it. I think that might be too many dots :P
I'd like to have import helper_py.processor or from helper_py.processor import Processor
when accessing from root
how would that look like
 
hm. no init on root then
 
@piRSquared the inspect module can get the currently executing frame, which you can extract source code from
 
danke
 
if the helper py and processor file does not have any weird imports of their own, you should be able to use it from root
in both ways really*
 
5:28 PM
they have imports in their folders too
processor.py has from .profile import Profile
Next to the processor.py is profile.py
is that an issue?
 
im afraid i do not know for sure, sorry. whenever i have packages mixing imports this closely, i always end up with an init in root which seems to work well enough.
this convo is making me want to go through the docs on imports though. im doing that atm
 
vaultah@base:~/45$ python3 -m pytest tests/test_processor.py -q
.                                                                                                                                    [100%]
1 passed in 0.01 seconds
Spoilers, because this has been going for too long
 
PEP 420*, which introduces implicit namespace packages, does not give a lot of guidance about when it is appropriate to use namespace packages over regular packages and vice versa. Other than "regular packages are a little faster because they're more easily detected". This vexes me.
(*lol)
 
^ an auspicious PEP, indeed
 
5:42 PM
@Kevin as long as it's less perplexing/vexing in KevinScript (tm)? It is going to be released sometime before Python 9, right? :p
 
I have half a mind to make KS' import system just textually prepend whatever file you're importing, like how C does it
 
umm... when did C start doing that?
sounds more like a php approach where everything's functions and they're all available all the time
ahrhghhghghhg.... I mentioned php.... someone... quick... cute kittens|non-mammals needed!
 
Is that not how C works? I thought it was all just file concatenation during the preprocessing step.
 
eugh, php
 
5:51 PM
@Kevin well, in C, most functions are actually named things like strtok or str... in the file they're imported from
(it's not like there's a str.h that contains a, b, c and they get renamed... they're just called stra, strb, strc...)
but then C++ has the using and namespace stuff going on... but haven't done anything serious in that language since 2006 - so... plenty rusty... and from what I've of it, it's looking much more like C# in someways now
 
That fat cat looks devilish.
 
cabbage
 
@lmao don't blame 'em... the mint'n'chocolate one is way better :)
cbg
 
TIL (actually yesterday) the term medoid; the element with the minimum distance to all others -> en.wikipedia.org/wiki/Medoid
idk how I've never heard this term before. but there ya go.
Am a little annoyed it's medoid and not medioid though
 
it's wikipedia, you can just edit it :P
 
6:02 PM
lol
 
Medoid is my favorite 2d exploration platformer. Seamus is a cool guy, he kills aliens and doesn't afraid of anything
3
 
Today's puzzle is rated "boring for most regulars, but hopefully educational for some":
# Create an instance of Bomb without crashing the program.
# Monkeypatching __init__ is not allowed.

class Bomb:
    def __init__(self):
        raise RuntimeError('BOOM')

bomb = ...  # YOUR CODE HERE

assert type(bomb) is Bomb, "You didn't create a Bomb instance, did you?"
print('You win!')
 
Easy win
 
no spoilerino
 
The only code to be written is on the bomb = line?
 
6:09 PM
yep
 
I find this puzzle neither boring nor immediately obvious
 
til how to write assert o.o
and will learn something interesting by the end of this im sure
 
@Kevin same
 
Oh hey, my userscripts started working again. view spoiler
 
I did it!
(I think?)
 
6:11 PM
@Kevin good thing you put that as a spoiler :P
 
Well the assert doesnt break, so i guess i did it
how spoiler do
 
i presume this is another one of "if you dont know you cant guess it?"
 
vaultah@base:~$ python3 -O program.py
You win!
Works without modification!
 
@alkasm usually you'd use sopython.com/spoiler but it's b0rked atm
 
ic
 
6:14 PM
@vaultah Ha, nice loophole
 
@ParitoshSingh it took me a minute, but just think about the machinery that happens around object creation and initialization
 
Cheesy solution: view spoiler
I award myself zero points
 
i guess it just said no monkey patching init...not no monkey patching globals
 
here we go again... these pesky programmers always trying to bend the rules and find loopholes
 
Code Golf's statute of "yes, yes, you're very clever, but your attempts to circumvent the intent of the challenge is boring to us" applies
There's a backup method of creating spoilers that doesn't require an external service, which is: embed your secret in the alt text of a link.
And this is done with... Backticks? Apostrophes? something like that.
 
6:17 PM
okay, so i dont know what i did but...
 
you can alt in markup?
 
and i dont know how to post
 
Did it worked?
 
I'm 85% sure you can alt in markup.
 
thats pretty high confidence
 
6:17 PM
[text](https://link.com "alt text (or spoiler)")
 
It would be lower if I didn't have multiple memories of doing it before
 
it worked o.o
but i have no clue what i did. i wanna post it
 
@JonClements: Well, chocolate has its own charm :)
cbg
 
testing: a link
 
thats so cool!
Yes, that's the way!
 
@ParitoshSingh ding dong!
 
AFAIK sopython.com/wiki/Userscripts has an up-to-date link to the soChatSpoilerAdd.user.js userscript, if anyone can't be bothered to create spoilers manually.
 
now, i need to read up on what is it i did :P
 
object works too, FWIW
 
6:22 PM
Maybe I'll take a couple minutes to make a bookmarklet-compatible version for the greasemonkeyless
 
@ParitoshSingh I commented on your gist
 
Ooh, I got an idea for a follow-up puzzle (:
but I'll save it for tomorrow :D
 
@vaultah any superclass then
 
bookmarklet complete. No extensions required, just bookmark/run in the usual fashion
 
@alkasm sweet! replied
 
6:28 PM
@alkasm yeah
 
I could see myself working there
There's gratification in developing things you personally use
 
@Kevin 1. cool but 2. i cant figure out how to use it or install it, lol
@cs95 haha i see that all the time when im on SO
 
I'm surprised pornhub isn't advertising here. I know they're hiring to work on their recommendation engine
 
@alkasm he literally linked to an installation wiki page
 
6:31 PM
@AndrasDeak ik
 
then you're on your own :P
 
Why do I know this? Uh, I have friends who applied there
 
you can give me a little more credit than that
@cs95 lol, no one questioned you :P
 
The typical approach is: 1) copy the contents of that page. 2) create a bookmark to some page (example.com or google or whatever). 3) open the bookmark's properties, erase the url, and paste in the copied contents. 4) with chat open, open your bookmarks menu and click the bookmark
 
Just clearing the air :p
@vaultah I get it. Be the change you wish to see
 
6:33 PM
If you're saying "I know how bookmarklets work but I don't know what changes (if any) it made to the page", there should be a "spoiler" button next to "send" and "upload" next to the chat message text box.
 
@Kevin to be more clear (sorry I wasn't originally), the example on the wiki page works for me, but yours just does nothing for me.
OH
I was uh...not..trying it on the so chat page....
 
If I was a better js dev, it would work on any page. Alas!
 
Also "bookmarklet" is such a cute name. Also I had no idea this was a thing you could do.
 
It's a nice little QOL feature.
 
Well that's an error message I haven't seen before...
>>> ...(*...)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ellipsis object argument after * must be an iterable, not ellipsis
 
6:36 PM
I only know they exist because on chat.SE some rooms (math, physics, and maybe latex) need mathjax support, and one alternative for that are bookmarklets
 
interesting, i just have mathjax installed so dont think about it. hows the math chat room?
 
@Aran-Fey wait, you can instantiate an Ellipsis with non-empty args??
@alkasm no idea, I went to physics for a week
 
nah, ellipsis isn't callable. The error message is a mess
 
After which you knew all of physics, and no longer required the site
 
@Aran-Fey ah :(
 
6:38 PM
"Ok, I've gathered enough data to form a Grand Unified Theory, laterz"
 
>>> object(*...)
TypeError: type object argument after * must be an iterable, not ellipsis
 
you'll get the same for any type..TypeError: NoneType object argument after * must be an iterable, not ellipsis edit: Andras wins this race..
 
>>> object()(*...)
TypeError: object object argument after * must be an iterable, not ellipsis
wat
Oh, I get it. Still weird.
 
I guess it kinda makes sense
 
works with non-iterable splats, like (*None)
 
6:40 PM
In [18]: None(*5)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-f3f27ef07a95> in <module>
----> 1 None(*5)

TypeError: NoneType object argument after * must be an iterable, not int
yea
 
Disappointed that the error message of object()()()(*...) isn't object object object object argument after * must be an iterable, not ellipsis
 
lol
 
hah
 
maybe you need to nest it
>:)
 
>>> class Foo:
...     pass
... Foo.__name__ = 'object object object object'

>>> Foo()(*None)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-394-bc3163188e9c> in <module>
----> 1 Foo()(*None)

TypeError: object object object object object argument after * must be an iterable, not NoneType
 
6:43 PM
lol!!
 
I suppose python just generates the error message for func(*arg) as f"{type(func)} object argument after * must be an iterable, not {type(arg)}". Definitely had a major "wat" moment at first though
 
For some reason I thought it would try to detect it at parse time and use some kind of wacky backtracking to deduce the "name" of the expression
 
 
1 hour later…
7:54 PM
This person needs a direction but my mind is too broken to point stackoverflow.com/q/56029163/2336654
 
yup, you got it
 
8:22 PM
Can you make an existing object be a different type than it was created as?
 
yes
 
Follow up question: How?
 
Yes, just assign to obj.__class__
 
^
that's why some people say that python is strictly speaking not strongly typed
 
though that has restrictions
>>> f.__class__ = int
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __class__ assignment only supported for heap types or ModuleType subclasses
 
8:24 PM
I just got Fey'd
so is there another way that gets around that?
obj = object()
obj.__class__ = int
 
i saw that! gasps
 
(-:
 
Surprisingly detailed and informative blog post on the bulletin about data and stuff
 
I always thought __class__ was implemented as some kind of descriptor, but apparently not?
>>> class Klass: pass
...
>>> obj = Klass()
>>> '__class__' in vars(obj)
False
>>> '__class__' in vars(Klass)
False
>>> '__class__' in vars(type)
False
Where the heck is that implemented? Is it in __getattribute__ and __setattr__?
 
'__class__' in obj.__dir__()
# True
if that helps
 
8:35 PM
>>> '__class__' in vars(object)
True
forgot type is a subclass of object...
 
commute home rbrb
 
rbrb home
 
is it possible to customize slice from the slice's point of view, or only the object to be sliced?
 
1) IDK 2) what do you mean? 3) you can subclass slice
 
I have to cut out regions of an array sometimes and img[y:y+h, x:x+w] is annoying to write out when x, y, w, h are longer variable names and sometimes require calling methods to access
would be supercool if I could just make objects that I can pass into getitem, but I can customize how my objects get sliced
like if I could do arr[point1: point2] and the point objects could be customized in such a way to break out into [pt1.y: pt2.y, pt1.x: pt2.x]
 
8:47 PM
you can customize getitem in a custom subclass...
that's the only way you can make indexing do something funky
 
yea...but subclassing numpy arrays never sounds like a good idea.
 
usually not
but if you only overwrite getitem that way it might even work
 
It's very limited, but you can implement __index__
>>> class MyIdx:
...  def __index__(self):
...   return 3
...
>>> 'abcdefg'[MyIdx()]
'd'
 
Okay, so, I could create an indexer object that I can pass my slices into, I guess..
 
the problem is [point1:point2] will always be translated to [slice(point1, point2)]
 
8:49 PM
right
 
class A(list):
    def __getitem__(self, item):
        if isinstance(item, slice):
            item = slice(item.start, item.start + item.stop, item.step)
        return super().__getitem__(item)

a = A([*range(20)])

a[10:5]
# [10, 11, 12, 13, 14]
 
I guess I could make a function that takes in point1 and point2 and then returns the slices
 
@alkasm well yeah, but that's not that cool
 
no, it isnt. :P
 
Wow! I'm in a rut with the * This was unnecessary A([*range(20)]). Should have been A(range(20))
 
9:00 PM
has anyone ever seen parsing an exception message to provide the correct input?
 
input to what?
 
to correct your program, i guess i should say
i was playing around with boolean indices for numpy arrays, and saw this since my boolean array had the wrong dims:
----> 1 bigger_arr[inds] = 5

IndexError: boolean index did not match indexed array along dimension 0; dimension is 10 but corresponding boolean dimension is 5
and I'm just thinking how amazing it would be to parse that message and pad a boolean array accordingly
by amazing I mean amazingly bad. but it would be hilarious nonetheless to see
 
In the face of ambiguity refuse the temptation to guess. I think that indexing used to work in older numpy (padding with False values)
 
oh really? interesting.
 
9:04 PM
nice
 
there were very few intentional uses and a lot of subtle bugs with the old behaviour
 
i couldnt remember either way
yea for sure
alright well back to "normal" programming I guess..
 
Ha! @alkasm
class A(np.ndarray):
    @staticmethod
    def funky(slc):
        if isinstance(slc, slice):
            start, stop, step = slc.start, slc.stop, slc.step
            slc = slice(start, start + stop, step)
        return slc

    def __getitem__(self, items):
        try:
            it = iter(items)
        except TypeError:
            return super().__getitem__(A.funky(items))
        else:
            return super().__getitem__(tuple(map(A.funky, items)))

a = np.arange(100).reshape(10, 10)
 
not too bad of a modifier
The reason why I was interested in it from the slice's perspective instead of the object's is because I'm not the one creating the arrays (most of the time), OpenCV is and is returning them to me as np.arrays. So re-wrapping them just for indexing is like, might as well make a function to return the indexes I want.
 
9:32 PM
You can see from the example. If you've got the array a then it's just a.view(A)[1:2, 3:4]
 
Oh!
well thats interesting
 
going home rbrb
 
Hello. Please make some sense.
 
That was not a Chicken Teryaki but pure magma sorry
 
9:52 PM
Reminds me of a Facebook post earlier - a seagull fell into a pot of curry and became orange. "Gull friend in a korma, I know, I know, it's serious". The pun is strong
 
I just got the same fortune in my fortune cookies two days in a row. What are the odds of that?
 
if the factory prints in batches and logistics ships in batches and a restaurant buys in batches...maybe larger than you'd expect
 
Must be good to eat there two days in a row, wonder how many unique fortunes are floating around
 
I eat out almost every day for lunch. And Chinese at least twice a week.
 
10:57 PM
Hello all
i am trying to have python3 in my mac to point to python3.7 and not 3.6
does anyone know how to do that?
 

« first day (3125 days earlier)      last day (1815 days later) »