« first day (4272 days earlier)      last day (659 days later) » 

8:03 AM
x = "[{'fullName': 'cwm2 testuser2', 'userName': 'cwm2_testuser2@abc.com'}, {'fullName': 'cwm3 testuser3', 'userName': 'cwm3_testuser3@abc.com'}]"
y = json.loads(x)
I get this err for second line: json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
 
Well, as the error says... JSON strings must be enclosed by double quotes.
Whatever you have there, it's not JSON.
 
How I do I convert it to list without replcing those single quotes to double quote manually?
 
ast.literal_eval would work for the string shown.
Whether it will work for all of them is impossible to tell from just one example.
 
Thank you, @MisterMiyagi
 
 
3 hours later…
11:21 AM
Hi guys, does anybody know if there is a way to associate django urls with their counterpart in js? Because currently if one is refactored the other side might be dangling. With the python functions you can easily show the link between urls and functions, but not for the js side
 
Not a solution to your problem, but can't you check that mapping in CI, to at least see when something dangles? Or is that not maintainable?
 
12:03 PM
@Hakaishin In flask you'd use url_for and render it into the template using Jinja2. I'm assuming the django template renderer would also have a similar thing
 
@AndrasDeak--СлаваУкраїні yeah that's kinda what we do know, but it's cumbersome and error prone
@roganjosh It does, but pycharm doesn't understand it. Also we don't use it too consistently.
 
But if you rendered it into a template with this the renderer will shout? I can't do much to help if you don't use the specific system consistently. I'm also not sure how any IDE would be able to make a connection like that
 
@roganjosh I mean yeah, we should probably use this consistently, but if the IDE doesn't understand it, I'm not sure what the big use is of using it. If it would understand it I would be more inclined to use it always
 
I've lost track of what "it" is
 
hm...it can be whatever you want it to be?
 
12:11 PM
The django equivalent of url_for. Since the template has to go through the backend, it would crash at runtime trying to generate the URL so you can't have dangling URLs
 
@roganjosh Oh ok, that is veeery neat to know and def a good reason to always use url_for
 
Work has made it mandatory to watch The Inside Man. I'm now half way through and our reluctant social engineer's feelings are clouding his ability to execute the mission. Edge-of-the-seat stuff. The characters are at least better developed than whatever the meat blobs were on the screen in the final GoT season
 
@Hakaishin I'm curious how you're doing this. Scanning the js files for strings that look like paths?
(where "this" is "checking for dangling url mappings in CI" (where "CI" is "continuous integration"))
 
12:34 PM
If you're looking for all url_for calls inside a jinja2 file, I wonder if you could iterate over the AST instead of the file's raw contents... Environment.parse looks promising
 
1:01 PM
url_for finder, v0.99: pastebin.com/raw/g5MhEeGb. Good for finding dangling paths before runtime.
"Now do it for the django template renderer", you say. No, I'm spent. I've already got one foot in the boat that will take me to the Undying Lands.
 
1:14 PM
That's a pretty nifty piece of kit!
Well, I've finished The Inside Man. If you're going to subject employees to mandatory training videos on cyber security, it's probably the best it could possibly get. So many plot twists; quite the rollercoaster.
 
The Django template system also has an AST you can search through, but there's no find_all function, so you have to write your own version. Not too bad since there are only like four kinds of node.
I considered writing one, but then I imagined the reader saying "Now do it for django.extensions.engine_with_bells_and_whistles, which has 127 different kinds of node". It is written: if you give an imaginary reader a cookie...
 
2:15 PM
@roganjosh Uh cool, gotta watch that one
The title of the movie brought of the movies all the presidents men and inside job, but it's neither :D
@Kevin integration tests and a list of urls which gets queried
not really exciting
 
It really is unlikely to teach you anything you didn't already know, it's more for people outside of IT. It just happens that our training system tracks every employee to make sure we went through the whole 1st season
 
lol
 
2:41 PM
An XY problem, or possibly a UVWXYZ problem:
#objective: for a given string which is a valid template for str.format, find the indices of all curly brackets that indicate a replacement field
s = "A: {} B: {x} C: {y[0]} D: {z[q]} E: {z[}]} F: {{not a field}}"
#.......^^....^.^....^....^....^....^....^....^................... i.e. these ones.

#proof that this is a valid format string
print(s.format(1, x=2, y=[3], z={"q":4, "}":5})) #A: 1 B: 2 C: 3 D: 4 E: 5 F: {not a field}

#desired output:
goal = [(3, 4), (9, 11), (16, 21), (26, 31), (36, 41)]
I can get closer with sanitized_s = s.replace("{{", "<<").replace("}}", ">>"); print([idx for idx, c in enumerate(sanitized_s) if c in "{}"]), but z[}] continues to vex me
Urgency level: near zero. While I do need to examine some template strings in my real code, I know with 100% certainty that the "broken" approach will work perfectly on my real inputs, which will never change. Devising a bulletproof approach is only a fun diversion.
 
So, basically you are looking for matched and unmatched wiggly things?
In {{{Δ}}, which one is the field?
 
Basically. But note that the left curly bracket of {z[}]} should not consider its match to be the right curly bracket inside the square brackets.
 
Does str.format support as much? Hm...
I'd probably go for a mini-parser. You only need to match { }, [ ] and the rest, right?
 
Seems like an error to me
 
s = "A: {} B: {x} C: {y[0]} D: {z[q]} E: {z[}]} F: {{not a field}}"

class Cabbage(string.Formatter):
    def parse(self, fmt):
        stuff = list(super().parse(fmt))
        return stuff

Cabbage().parse(s)

[('A: ', '', '', None),
 (' B: ', 'x', '', None),
 (' C: ', 'y[0]', '', None),
 (' D: ', 'z[q]', '', None),
 (' E: ', 'z[}]', '', None),
 (' F: {', None, None, None),
 ('not a field}', None, None, None)]
Maybe that's a starting point? Not sure...
 
2:54 PM
>>> "{{{x}}".format(x=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Single '}' encountered in format string
I'm surprised by this result. I figured it would crash, but I thought it would complain of a single unmatched "{", not "}".
 
{{ is escaped, { is matched
 
I guess it interprets "{{" as a literal left bracket, "{x}" as a replacement field, and only when it encounters "}" does it notice something's strange.
 
I wasn't aware that unmatched closing } need to be escaped as well. oO
 
I guess I assumed it took a first pass to escape any instances of "{{" or "}}", and then a second pass to find replacement fields. The result is more sensible if you assume a single pass.
 
And I keep forgetting that implicit quotes are added in format fields, ew
 
2:59 PM
Let's be thankful that almost everybody forgets it's possible, or we'd see much more of it :^)
 
Doubt you can resolve that without a full-fledged parser
 
@JonClements Ooh, pretty promising. Nice of Python to give us hooks into its full-fledged parser :-)
I don't know why it split my "F" case in half, but it's easy enough to put them back together. Or I can leave them be, since I'm only interested in the tuples representing nonliterals
 
shrugs... you might be able to wangle something with something in string.Formatter...
 
Guys, I think you should listen to the cute puppy.
 
Wisdom
 
3:06 PM
only the insane do that... @MisterMiyagi I recommend not listening to me... :p
other thought was doesn't jinja or similar templating engines also do this sort of stuff? They might have more exposed parts as to what they identify or something...
 
@JonClements I don't trust you
 
Don't listen to the cute puppy telling you not to listen to the cute puppy!
 
yes, I don't trust him so I'll listen to him
 
Jinja exposes some ast-related goodies, but they say to expect it to change at any time
 
3:17 PM
Renaming TemplateNode to MainNode, that kind of thing
 
3:30 PM
 
4:02 PM
I laughed out loud at "behind one door is a tiger with a gun"
When I build a fiendish labyrinth, the guards won't know whether the other guards are liars or truth tellers, and they'll only know a door leads to a tiger if they put them there that morning.
All of the riddles will be solvable, but you won't be able to look up the answers on Puzzling.stackexchange.com. Bring pencil and paper.
 
4:56 PM
Cbg
 
5:18 PM
@FranciscoMariaCalisto please don't spam chat, and this room in particular
 
One thing that bothers me about the Two Guards Riddle is that some riddle-askers make a distinction between solutions like "ask either guard: are you a liar XOR are you guarding the safe door?" VS "ask either guard: if I asked the other guard if he's guarding the safe door, what would he say?". They might disqualify the former for "asking two questions", yet allow the latter. In my opinion, they're equally valid.
They really should strictly define the grammar of allowable questions, building up from predicate logic. I can't be spending all day guessing how mathy I can get with my reply
 
5:40 PM
@Kevin wonder if you might be overthinking it? Also... I have a strange urge to watch youtube.com/watch?v=2dgmgub8mHw again...
 
Bonus: if you define the grammar carefully enough, I believe you can naturally exclude paradoxical questions that might make a guard's head explode. "Is the answer to this question 'no'?" can't be constructed if you can't assemble peano arithmetic from your starting axioms
@JonClements If the penalty for _under_thinking is being shot and/or eaten by a tiger, then I will gladly overthink
I will also overthink even when there is no penalty, but I digress
 
6:11 PM
Sup guys
I'm heading into a brand-new project where I've got to run a python script and retrieve results in a styled PDF. I'm considering on build the HTML first, then parse it into PDF, is it recommended or is there any other alternative? Thanks in advance
 
I did something like that in C# once. I didn't have to use any HTML, I just defined everything in my code and wrote straight to PDF. I expect that most pdf-writing libraries work that way.
But if you're comfortable writing HTML, and you already know how to turn HTML into a PDF, then I think it's fine to do it that way.
 
6:29 PM
@PedroFernandes Try this: pypi.org/project/reportlab
 
 
1 hour later…
7:51 PM
Hello, i have an issue in pyinstaller. Module Not Found Error from module PyQt5.sip in executable python 3.10 . I search greater than an hour with no fix.
 
 
2 hours later…
10:16 PM
stackoverflow.com/questions/72778385 any possible duplicate for this?
@Kevin to be fair, the penalty for underthinking is, typically, only a 50% chance of being shot and/or eaten by a tiger, not certainty
 

« first day (4272 days earlier)      last day (659 days later) »