« first day (4437 days earlier)      last day (503 days later) » 

1:07 AM
soo dataclass with List populated by list(map())?
 
1:26 AM
@dataclass
class ModbusClient:
  signals: List[MyClass] = field(default_factory=List[MyClass])
  settings: List[InputRangeEnum] = field(default_factory=List[InputRangeEnum])
kicking back:
raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type List cannot be instantiated; use list() instead
type(settings) returns list()
type(settings[0]) returns enum InputRangeEnum
 
1:41 AM
>>>x: List[InputRange] = [InputRange.V_1]
>>>x
[±1 V]
>>>type(x)
<class 'list'>
>>>type(x[0])
<enum 'InputRange'>
>>>x: List[InputRange] = list(map(lambda ir: InputRange.V_1, [1,2,3]))
>>>x
[±1 V, ±1 V, ±1 V]
>>>type(x)
<class 'list'>
>>>type(x[0])
<enum 'InputRange'>
 
 
6 hours later…
7:51 AM
@PaulMcG Long time no see :) How's it going?
 
@imbAF Truncated distribution explains how to deal with the min and max limits on tau. Here's a short demo using Numpy & Matplotlib.
 
8:22 AM
@Elysiumplain Well, as the error says... use a list instead. List[MyClass] is a type, it's not a class that can be instantiated (since list cannot differentiate by its item type).
signals: List[MyClass] = field(default_factory=list)
 
 
2 hours later…
10:10 AM
dataclasses should just create a copy of the default value tbh, then you'd be able to write signals: List[MyClass] = []
 
Wouldn't that require every object implements some copy mechanism?
 
copy.copy works on pretty much everything AFAIK
 
10:58 AM
Hi Guys!
I have a problem with importing a module called 'tokenizations'
The strange thing is, the error I'm getting is: "Unable to import module 'main': No module named 'tokenizations.tokenizations'" So two times the name of the module... I tested with this_module_doesnt_exist and it just printed the name one time... What the issue here?
 
Minimal, Reproducible Example please. I.e. code + traceback
 
Well the code is the import, so >>>import tokenizations and the traceback is whats written in my inital msg
 
It's not full traceback
 
Well then there's something wrong with the tokenizations module
As in, on the inside of the module
 
But it does work on my machine locally, just when I bring it to aws it fails
 
11:08 AM
did you install the module on the aws?
 
Well then either you've installed a different version of the module, or there's something about the environment (OS, installed libraries, etc) that makes it not work there
 
Yes, by zipping my local installation
Okay, thank you, but why does it say that it does not find the module?
 
Maybe if we could see the stacktrace we could figure that out ¯\_(ツ)_/¯
 
[ERROR] Runtime.ImportModuleError: Unable to import module 'main': No module named 'tokenizations.tokenizations'
Traceback (most recent call last):
That's all I see aswell
let me try to find the fulll output
 
tokenizations doesn't seem to exist on pypi, so we can't even look at the code
 
11:13 AM
Yes, its pytokenizations there
 
version 0.8.4 (the latest) seems broken
judging by the code
 
Why does this not work:

subprocess.Popen(executable="path/to/python.exe", args=["script.py"])

But this works:

subprocess.Popen(args=["path/to/python.exe", "script.py"])
I'm just ending up in the Python interactive shell with the first option.
 
Was able to get the traceback @Aran-Fey:
Traceback (most recent call last):
File "/var/task/main.py", line 9, in <module>
import tokenizations as tk
File "/var/task/tokenizations/__init__.py", line 2, in <module>
from .tokenizations import (
ModuleNotFoundError: No module named 'tokenizations.tokenizations'
 
Yeah, that's the same code I saw. That's just wrong, plain and simple
Dude has no idea how packaging/imports work
 
Ah so the import in init is corrupt?
 
11:19 AM
Yeah. It should work if you change it to from . import
Wait, disregard that. I forgot about the rust part
 
Unable to import module 'main': cannot import name 'get_alignments' from partially initialized module 'tokenizations' (most likely due to a circular import) (/var/task/tokenizations/__init__.py)
That's the new error
 
https://docs.python.org/3/library/subprocess.html
"The executable argument specifies a replacement program to execute. It is very seldom needed. When shell=False, executable replaces the program to execute specified by args."
 
And also as I said it did work on my local machine with the same version
 
Seems like the plan was to compile the rust code into a module, which would be tokenizations.tokenizations. But I can't find anything in the pyproject.toml or elsewhere that would compile a rust module
 
why would it work locally though
 
11:24 AM
You said you copied your local installation into AWS? That might well be the problem
 
Yes exactly
But what would be the alternative?
 
Install it with pip? Can't AWS do that?
 
pip install tokenization?
 
It's a lambda instance
So you basically load your code and your dependencies as a zip package
 
@matszwecja I found the github repo, and it looks like they use a special tool to create .whl files. So it works if you install from the wheel, but not if you install from source
 
11:27 AM
or alternatively docker but I'm trying to avoid this for time reasons
 
I think compiled modules have a .pyo extension? Can you see a tokenzations.pyo file?
Either the compiled rust module wasn't copied over for some reason, or it's not compatible with AWS
 
all I have is .pyc. pyi and .so
 
Try making an .exe and see if that works
 
It's probably the .so then. Does that file exist in AWS?
 
Sorry could you explain that @matszwecja
It does exists in aws
 
11:33 AM
never mind, I just realised that aws is most likely not runnning win
 
Then I've got nothing. You'll probably have to find a way to install/compile it directly on AWS
 
tokenizations.cpython-310-x86_64-linux-gnu.so
The only thing that's not copied is pycache but I guess thats not the problem right?
 
Nah
 
Mhh, alright
Thanks anyway
 
12:13 PM
How long does it take to go from junior dev to mid?
 
12:24 PM
depends
it might be 1 year, might be 3
 
1:08 PM
Job titles have more to do with office politics than anything else, IMO. If you provide value to the company and look good doing it, then you can graduate from "junior developer" at any time
Outside of the office, I don't believe in junior/mid/senior. There is dev and only dev
 
I wish most people working in the HR department thought the same too. Most probably give too much importance to that vs what you actually know and can do/be proficient in.
 
1:49 PM
It's very easy for HR to determine you have 3 years' experience as a dev, and very hard for them to determine how proficient you are at being a dev.
 
Is it possible to check if a string is in a 2D dictionary value and if it doesn't exist make it return false?
I don't want to check if every key exists and set a empty value for this
 
What's a 2D dictionary?
 
Dictionaries within a Dictionary. sort of like a 2D array
 
Like {{1:2}:{3:4}}? That's not possible, you can't have a dictionary as a key for another dictionary
 
{1:{2:3}} perhaps?
 
1:55 PM
A recruiter would immediately know we're all noobs because we still don't ask for MREs
 
No, {1: {2:3}, 2: {2:3}}
 
@Aran-Fey No thanks, I already had lunch.
 
It's easy to check if a string is in {1: {2:3}, 2: {2:3}}. We can tell just by looking at it that it contains only ints, so you should simply always return false
 
...That's was an example of a 2D dictionary.
 
Yes.
 
1:57 PM
What I have is more like {'1': {'1': '#', '2': '#'}, '2': {'-1': '#', '3': '#'}
What if I wanted to get dict['1']['3'] == '#' This returns key error
 
One possible approach is to use get and provide a default argument. If your first get call provides an empty dict, then you can chain a second get call onto it whether the first key exists or not. dict.get("1", {}).get("3")
 
ohmygod I completely forgot about .get... thanks!
 
Another approach is to use collections.defaultdict to construct your dictionary and its sub-dictionaries. Then you're guaranteed not to get a KeyError.
Nested defaultdicts can be a bit of a pain to set up though. I usually just stick with regular dicts.
 
yeah, I recall we talked about something related to defaultdicts. I recall I didn't understand how it worked back then (probably still doesn't, but thankfully I don't have to use it)
 
It's fairly straightforward to mentally model the full behavior of a defaultdict. There's not much arcane logic hidden under the surface, or anything. But if you're juggling multiple defaultdicts, it's easier to forget to carry the 1
 
2:07 PM
You might also consider tuple keys, like {('1', '3'): '#",}
That's nice for things where having only the '1' doesn't make much sense, like laying out things on a grid. '1' would be a column or row, and that's not really meaningful, necessarily.
 
Yeah
 
And from there, if your only characters are '#', then you've overdone a Set of tuples.
 
2D dicts was the first thing I thought of lol (for aoc)
Is it just me or does the spoiler encoder not work
I've clicked Encode several times and I can't check console atm
 
2:24 PM
Yeah, it's been broken for a year or two
 
Damn, I can't even use bookmarklets because my school blocked javascript://
 
wonder why it's broken. Maybe someone in the javascript room could help
 
What's the encoding though?
 
We know the problem. Short answer: it's a web host thing and we can't do anything about it right now
 
got you
btw, does anyone know any way to execute/host python code online? something like jsbin but for python and that also support private paste link?
the only solution I found was to either self-host it on a server or use pythonanywhere with flask/django and a password on a specific page
 
2:31 PM
replit?
 
replit works for execution, but it doesn't support private paste
I looked on their forums
 
What do you mean by private paste ?
 
basically, like on gist.github or jsbin. You can make secret/private paste link that won't be seen/found by anyone unless they receive the link (or manage to bruteforce through all possible links)
I didn't found any python paste site that did this yet :/
I found a bunch for js/html/css though for some reasons
 
Technically tio.run might work?
It's not a full editor though
It's used in codegolf
 
so I am trying today's AOC, dpaste.org/PEYc5 works well for the example, but it fails for the actual one, IndexError, can anyone point me where I am making a mistake
 
2:38 PM
@NordineLotfi Managed to find pythonmorsels.com/paste
@Jake Your code is much cleaner than mine
 
lmao, well, clean only gets me till the example part
 
@12944qwerty hmm, thanks but I think I already know that one. Tested it a few weeks ago but it doesn't have any options for private paste I think
 
I literally had a if or_conditions_here:pass else: do_this
@NordineLotfi It makes a link? pythonmorsels.com/p/2ysx4
 
yes, but it will be found by anyone when using google/other search engine. That's why I said it doesn't support private paste like gist.github or jsbin
 
Gists aren't private either then
You can search up gists just as easily
 
2:48 PM
Hi @roganjosh and everyone
 
Yo
 
@12944qwerty you can use secret gist though. AFAIK you can't find them unless you either bruteforce the URL or you receive the link from someone/find it somewhere
@PaulMcG Hi
 
Cbg
 
I'm reacquainting myself with Docker today, to do some Python dabbling with MongoDB and I don't feel like installing, just easier to pull an image and run a container.
 
I did find that aspect of docker to make my life easier, but the more I looked into it the more I lost the appeal, yaml configs for compose was something I never really found comfortable, would have been way better if it was json
 
2:55 PM
yaml is always a hurdle for me as well, and we use it a fair bit at work to config kubernetes and puppet. I don't intuit some of the structures ("is this a list or a sub-entry?"). I did see a clever way to insert a comment in vanilla JSON the other day.
If you wanted to comment on entry "xyz", precede it with another entry"_xyz", with the comment as the _xyz value.
It looks better than it sounds.
 
{"_xyz":"this is a comment","xyz":"foo"}?
 
Thats it
Whenever I complain about yaml at work, I usually get "yeah, but comments..."
 
I guess the above would work, but wouldn't a client that blindly accepts a json and does something like footer(**response.dict()) break?
 
JSON sent between systems can't have extra junk like that. This would be more for using JSON that is manually crafted like configs. (Of course, then you are probably likely to get errors from strict apps like "Unrecognized parameter: _xyz".)
 
yaml is a superset of json, so nothing is really stopping me from commenting a json in a yaml lmao
 
3:10 PM
I have a couple of new pythonanywhere endpoints for people to try out. One is a keyword search through PEP abstracts (ptmcg.pythonanywhere.com/pep_search). The other is a keyword search through Appendix A of the new Python in a Nutshell, which lists feature changes by Python version 3.7-3.11 (ptmcg.pythonanywhere.com/python_nutshell_app_a_search).
 
@PaulMcG that's pretty nice
btw, since you probably are more used to pythonanywhere than me, do you know if they let you have specific pages of your site to be ignored by scraping bot (eg: Googlebot, etc), so it doesn't get indexed?
wanted to make a private page using them, but only thing I know I could do is use a password for that (using flask/django)
 
if getting a VM for like 5$ a month you can easily find options
 
That's a good question. I have a robots.txt file in mine, but its probably naive of me to think that stops anyone
 
@Jake yeah, I did think of a VM. a VPS/Dedicated server is also something I'm considering, but I'm just exploring free options right now
@PaulMcG oh, nice
I didn't know you could setup a robot.txt file with pythonanywhere
I know most scraper bot can ignore it though, but I don't know if there a better way
 
@PaulMcG is the source in your GitHub?
 
3:22 PM
Yes, but I don't know if I made it public.
I just looked - it turns out I don't have an actual robots.txt file, it is implemented in Python as a fake route, like this:
@route('/robots.txt')
def fake_robots_txt():
    return "User-agent: *\nDisallow: /"
If you want the PEPs data, that is in the littletable repo, in the examples directory.
 
:o thank you!
 
yeah, I wanted to know how, so its a json, I was wondering how you got the data
 
Brett Cannon was asking if the PEP JSON download on python.org could be formatted better (it was a big dict, keyed by PEP id number) - so I flattened it into a list of JSON objects where the id was just another attribute, and added the abstracts.
I should submit it back to python.org....
 
3:46 PM
I've looked for Brett's tweet with the python.org download-peps-metadata-as-json link, but now I can't find it.
 
@PaulMcG the closest I found based on this context is this: i.imgur.com/58DeUxc.png but there nothing there except a profile
maybe it's deleted? I did find this github issues to be related though: github.com/pypa/packaging/issues/383
and maybe this too is related: peps.python.org/pep-0566/#json-compatible-metadata not sure for that one however
 
4:49 PM
Brett sent me the link: peps.python.org/api/peps.json
 
5:36 PM
In numpy you can use np.tril(x)to extract the lower triangular matrix of an array x. However, I am interested in extracting the lower antitriangular matrix, that is, with zeros above the antidiagonal. Is there a way to do this in python?
 
6:17 PM
@schn Transpose the matrix first, tril(), and transpose back? Write a custom function to zero them out manually?
I haven't done much with numpy, but it wouldn't surprise me if chaining builtins is faster than stuff you can implement in userspace.
(theory: builtins could be lazy, and chaining them together will be less abusive on the memory)
 
 
3 hours later…
9:34 PM
Anyone else having issues with the latest release of tox? Since upping to 4.0, we are starting to see these in our build pipeline:
  File "/tmp/tmpw_2jv6x3/python-test-env/lib/python3.9/site-packages/tox/config/cli/parser.py", line 293, in add_color_flags
    if converter.to_bool(os.environ.get("NO_COLOR", "")):
  File "/tmp/tmpw_2jv6x3/python-test-env/lib/python3.9/site-packages/tox/config/loader/str_convert.py", line 90, in to_bool
    raise TypeError(f"value {value} cannot be transformed to bool, valid: {', '.join(StrConvert.VALID_BOOL)}")
TypeError: value  cannot be transformed to bool, valid: , 0, 1, false, no, off, on, true, yes
Problem won't occur when building locally, just in the pipeline >:(
 
Well, there must be a non-printable character in that string then? Sure would be nice if they'd added a !r...
 
Yeah, I just submitted a PR with that.
 
We've gone past not-computer-readable errors and arrived all the way at not-human-readable errors
 
9:58 PM
PR just got merged. Considering that they did 4.0.0 thru 4.0.3 in the past 2 days, a 4.0.4 might come out soon (if they can find it...)
 
10:13 PM
@MisterMiyagi I'm more curious of the encapsulated process - like why when I "default_factory=List[ProperClass]" the List_Typing is now able to generate list() properly... yet "default_factory=List[enumClass]" fails to generate list().
 
Are you sure that works? In python 3.10 I always get that error
 
10:42 PM
tox 4.0.4 released, with my PR included. Now let's see if we can figure out just what is going wrong.
 

« first day (4437 days earlier)      last day (503 days later) »