« first day (4373 days earlier)      last day (561 days later) » 

6:31 AM
@roganjosh i m assuming things like creating a new fastAPI, flask, django projects, etc.
 
 
2 hours later…
8:20 AM
Oh hey - it's Bobby G!
 
8:34 AM
Hi, Python use ".odt" file. add an attachment and extract text or object content. write content more modified using python script.
everyone help me !.
 
8:46 AM
Odt is just a zipped folder with xml files in it, similar to .docx
so extract it, edit it, then zip it up again, there also might be a library out there that already does most of this automatically, I mean libreoffice does have a python API if you want to guarantee producing documents that it can deal with
 
 
1 hour later…
10:15 AM
thankyou @PeterT
 
10:32 AM
@Riya I think there is some template for those kinds of things (or snippet, etc). Wouldn't be surprised if there a plugin for it that already exist
 
10:58 AM
@Aran-Fey I'm really glad you mention Jedi being bad, since I think the same. I feel like I'm unsure though if PyLance is better than it is, since I once found similar quirks that Jedi have, but I guess it is what it is.
@metatoaster where did you get that image from? (guessing it's from a python's book, but curious about the title, etc). Just curious since it make things a bit clearer for me
 
11:18 AM
Question editted, please review: https://stackoverflow.com/questions/67127591/install-python-shout-module-in-windows-10-python-version-3-9
+ 200 reputation.
 
11:31 AM
@ChrisP It looks like you basically edited your own answer into the question, which isn't exactly a great idea.
That invalidates your answer, and frankly makes the question somewhat nonsensical as well since it requires a back-and-forth between the question and answer to figure out what exactly is the failure point.
 
11:50 AM
@NordineLotfi Python: the Full Monty, section 4.2.3, page 10.
I'd have to read the section to be sure, but I don't think that image is accurate. A function inside a class body can't see names that are local to the class body.
a = 1
class Fred:
    b = 2
    def func(self):
        c = 3
        print(c) #works; the function can see its own scope
        print(a) #works; the function can see the scope that contains the class
        print(b) #fails; the function can't see the class scope

Fred().func()
 
Isn't that what the images illustrate?
 
Possibly. I will squint at the picture more.
I see. I wasn't paying proper attention to the "semantic structure" and "syntactic structure" labels. The image is correct if the left diagram represents the "is indented within" relationship of the program's literal text, and if the right diagram represents the "is visible to" relationship of the scopes.
 
rejoices
 
@Kevin I knew about the relationship of Monty Python and the language, but never heard about this "book". nice :o
 
12:08 PM
morning cabbages, folks!
 
@Riya to my knowledge there isn't any plugins for convenience for Flask (there may be plugins for the other two, not sure). I do a lot of flask dev in it though, and it does have jinja2 support via a plugin. The rust-analyser is pretty full-blown for that language and it does all sorts of "fancy" so it's definitely beyond possible that such things do exist for e.g. django. Not sure what one for fastapi would look like
Although rust-analyser is still flagging printin!("Hello world!"); as a syntax error :/
YMMV :P
Oops, println! even. Silly phone making it an actual error that it should be complaining about
 
12:39 PM
@inspectorG4dget cbg!
 
Heya puppy! it's been a while. Potato?
 
@inspectorG4dget mostly banana - potato?
 
@JonClements Slightly peas by the current data integration task, laurel. But otherwise banana. Looking forward to the long weekend (Canadian Thanksgiving on Monday)
anything exciting happen this week?
 
Not really... ?
UK hasn't tanked the pound again just yet...
 
yeah... how's Truss doing? John Oliver roaster her pretty heavily not long ago
 
12:55 PM
I don't think even John Oliver could give her a harder time than her reality
 
well... she did inherit quite the mess
 
(Although "eat yam Bob" has to be my favourite take down to date)
 
hahahaha! that was a fun episode
 
@inspectorG4dget yeah, err, there's inheriting a mess and trying to handle that and, well, whatever the hell you'd call what happened.
She did a bare except:. Shame. Shane. Shame.
 
@roganjosh I do believe my morning's been made!
 
1:15 PM
How's Truss doing? She's making Boris Johnson look good :p
 
1:44 PM
@JonClements well, at least she's accomplishing something somewhat impossible
 
"accomplishing something"... that's err... remarkably kind hearted of you :p
 
making Boris look good ain't easy... :P. Them yams take some serious talent there's a word for this in some language that I don't know of
 
oh there's words for 'em... but I'd have to ban you from chat if you used 'em :p
what's the data integration task involve? Any interesting tech stacks?
 
1:59 PM
@JonClements sadly no. someone set up an OSINT data collector and set up a brand new RDS instance with a dedicated postgres schema to house the collected data. We actually already had a different RDS instance with a fairly flexible schema capable of holding this data. So now I'm the poor schmuck that has to modify the pipeline to write the data to where it should have been in the first place (the someone is no longer with the org, so it's on me now)
 
sounds sadly familiar :p
 
oh the more of this code I read, the more my eyes bleed. "Standard security practices? What's that? I can totally use Password123$ as the password to this database"
(that's not the actual password, but would have almost been an improvement over what was actually used)
 
The $ would have foiled me. I would have gone !
 
@inspectorG4dget meh... everyone knows they should use "hunter2" as a password... sheesh...
 
@JonClements I'm sorry, what password did you mention? All I could see was *******
 
2:09 PM
YAY! I'm not the only one that remembers that!
 
For DenverCoder: bash.org/?244321
 
2:52 PM
hello!
 
is it me you're looking for?
 
maybe
I have a Flask question
there's something with send_file() that is working weird for me
 
you're all I've ever wanted and my arms are open wide
 
xD
great news then
let me explain my doubt
I have this URL: 127.0.0.1:5000/…
but when I do a send_file(), all parameters from the URL get erased
Am I doing something wrong?
 
how do you request that URL? That URL just looks wrong
 
2:55 PM
please explain it in one message, rather than breaking it up into several messages. Also, here's some information on how to format your code in chat, just in case
 
you'd normally urlencode some get parameters
not try to shove in json into the route itself
 
the URL it's working fine just if I do not use send_file()
I can request its parameters via JS without any problem
 
so that url is not directly in the html code but something internally in flask?
 
exactly
I redirect to that URL from Flask
 
then what kind of "parameters" are we talking about here
 
2:59 PM
it's a dictionaries array
 
How do you pass these "parameters" and from where to where? I don't really know what we're talking about
 
you land in the main page, fill a form and click over send button
I make some checks in the servers a build an array with some info that have to be processed in another page so I serve it via URL parameter
once there I get the variable from the URL, show a message via JS, and send a file to the user
return redirect(url_for("index", params=json.dumps(params)))
and that's how I redirect with the params
params is the dictionaries array that I was talking about
 
any github project which say, why this thing here? , context a project where a lot of folders, with no reference or documentation, orignal developer are gone, git commit are just fix this thing, added xyz thing and all. so basically type hinting for the projects and schema, file structures
 
3:19 PM
What?
@DanielGarcíaBaena this doesn't make sense to me. Why don't you just return the file when they submit the form (assuming it passes checks)
 
because I need to show sometimes an error message and if you do a send_file() you cannot do a render_template() too
I'm reviewing the JSON as PeterT suggested
 
You can do anything you want like that if you use AJAX
I also agree that the URL encoding is messed up there
 
3:37 PM
please, help me understanding this
@app.route("/", methods=["GET", "POST"])
@app.route("/<subtitles_statuses>", methods=["GET", "POST"])
def index(subtitles_statuses=None):
    form = VideoForm(language="en")
    if form.validate_on_submit():
        ...
        return redirect(url_for("index", subtitles_statuses=json.dumps(subtitles_statuses)))
    elif subtitles_statuses:
        print(subtitles_statuses)
it should print a list of subtitles names and if they are or not available but instead it prints: favicon.ico
why?
 
@DanielGarcíaBaena question here, how you differenciate between request type
 
I simplified for readability but I assume I don't need to call request.args.get("subtitles_statuses") here
am I wrong?
I am pretty new with path parameters
 
stackoverflow.com/questions/73963811/… duplicate, didn't have the right tags for hammering
 
@DanielGarcíaBaena ilke, if request.method == 'POST', then do this, and if request.method=='GET' then do this
 
You can't just json.dumps() and hope that it's correctly encoded for URL GET parameters
What makes you think that would be valid? JSON is for JavaScript which just happens to be mostly used for frontend work. Its own data representation isn't naturally valid with URLs
You're probably thinking about the body of POST requests, which can be serialised this way. But not GET requests
That's why all your parameters result in a garbled URL
 
3:57 PM
I see
 
4:22 PM
@DanielGarcíaBaena the favicon.ico request gets send from the browser just by convention
and your route app.route("/<subtitles_statuses>" matches everything that has a single url path segment
so "myhost/test" "myhost/somepage.html" and "myhost/favicon.ico" all match that route
 
I just was realizing that
I must confess I'm currently a bit lost
what I pretend to do is:
1. load form from index
2. user send form and I check if I have everything that he asked for
3. I redirect to index but with a dictionaries array where I can check whether I have a file or not
4. send_file() for available messages and JS messaging for unavailable
it makes any sense?
 
sure "with dictionaries" meaning as GET parameters?
 
the get query parameters should be in request.args
 
so I should no use path parameter but URL parameters
isn't it?
 
4:38 PM
I assume that's what url_for does, doesn't it?
like what is the actual full URL that the browser receives?
 
I think I do not totally understand what's the difference between path and URL parameters
let me give you an example
@app.route("/<subtitle_statuses>", methods=["GET"])
here subtitles_statuses is a path parameter and anytime there is something in that path, as it was happening with favicon.ico, it will be stored in subtitles_statuses
 
sounds right so far from what I understand
 
on the contrary, on localhost/?subitltes_statuses="something"
subtitles_statuses is a URL parameter
and I should use this last type
 
if you want potentially multiple key/value pairs, then yes I'd use the later style. I was colloqually calling them "GET parameters", but I think they're technically "query parameters"
 
why only if I want multiple key/value pairs?
 
4:59 PM
anyway, I'm back where started
if request.method == "GET":
    if request.args.get("subtitles_statuses"):
        subtitles_statuses = json.loads(request.args.get("subtitles_statuses"))
        print(subtitles_statuses)
if request.method == "GET":
    if request.args.get("subtitles_statuses"):
        subtitles_statuses = json.loads(request.args.get("subtitles_statuses"))
        return send_file(some_file)
the first does nothing weird but the second one redirects from localhost?subitles_statuses=whatever to localhost
why?
 
stackoverflow.com/questions/73977137/… add flask tag so I can dupe hammer this
 
let me clarify a little more
 
@davidism it's hammer time
 
thanks :-)
 
5:14 PM
second starts correctly the download but something weird happen with my JS
I have a JS just for console log: works, anytime index.html has finished loading
and it logs works twice with the first function but once with the second
I cannot understand why
 
5:30 PM
On second thought, this question I was complaining about can reasonably just be considered a duplicate. stackoverflow.com/questions/60146275 duplicate of stackoverflow.com/questions/9573244
@DanielGarcíaBaena Well, if the issue is that "something weird happens" with the JS, perhaps the issue is in the JS, and not in the server Python code?
 
stackoverflow.com/q/73977853/198633. OP is asking us to do their homework with no attempt
 
@KarlKnechtel I think it is not because URL lose all parameters when I use send_file()
I assume that's not normal
 
6:09 PM
Hello, i want to make a python script executable (.exe).
Then in another .py script i want to Popen a process with the first .exe, but i am wondering how can i pass input runtime data from .py script to .exe.

I am almost pretty sure that there is a way to do it, but i don't have did something like that in the past.
 
Sure, add command line arguments directly to popen if its just some text, otherwise you can just send data into it with stdin
 
Yes stdin i think is the right aproach.
I want to call functions @ runtime not in the start of execution.
 
sure, you can use .communicate for it
 
Or this:

sprocess.stdin.write('exe_command_1(arg1,arg2,arg3)'.encode())
sprocess.stdin.flush()
 
both should work fine
 
6:15 PM
Nice, i will try to make the two scripts, and i will post a question in SO if i have something to ask.
 
communicate also waits for output, so I guess writing to stdin is better if you want to just communicate one way
 
I want two way communicate for error handling.
 
just for completeness you can always also google "inter process communication" for other ways to do this
i.e. file sockets, normal network sockets , shared memory, etc.
 
The .exe should be like this:
import os
import sys
import shout

x = ""
while(x is not "stop"):
    x = input()
    if x == "stop":
        break
    else:
        exec(x)
where x would be shout call functions with variables
 
Puzzle for fun:

Given a list
```python
lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
```

Find `b` such that

```python
a = 9
b = ???? # You must specify this!
print(lst[a:b:-1])
```

produces

```python
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
```

Whoever can solve this must be a genius!
 
6:31 PM
public void FrobnicateWidget(string widgetId){
    api.FrobnicateWidgets(
        new WidgetFrobnicatorParametersCollection(
            new List<WidgetFrobnicatorParameters> {
                new WidgetFrobnicatorParameter(
                    widgetId:widgetId
                )
            }
        )
    );
}
Some code I wrote today. I feel unclean.
 
@TheRealMasochist b = False-True. It's a fun little trick
 
#the Python equivalent, for those not versed in enterprisey OOP. But it's not quite the same without the `new`s.
def frobnicate_widget(widget_id):
    api.frobnicate_widgets(
        WidgetFrobnicatorParametersCollection(
            list(
                [
                    WidgetFrobnicatorParameter(
                        widget_id = widget_id
                    )
                ]
            )
        )
    )
 
I just committed a similar sin. But in my defense, it's HTML (well, JSX)
 
@inspectorG4dget Does not work.
 
@inspectorG4dget Very philosophical... What does falsehood become when you remove truth from it? It is the sound of one hand clapping, and the taste of a fruit that grows halfway up the Cliff of Certain Doom.
 
6:37 PM
I propose b = print(...)
 
@vaultah Oh my ghost. You are genius!
Is it a bug?
 
The behavior of print is well-defined and exhibits no apparent bugs here
 
@ChrisP Don't use is to compare strings
 
@TheRealMasochist I feel like what's happening here is that it reverse the list basically
don't know why though
 
The behavior of three-argument list slicing is well-defined :-)
 
6:41 PM
I guess it is, but I never tried more than two arguments when slicing list
 
print(lst[a:print(''):-1]) is funny!
 
> Some sequences also support “extended slicing” with a third “step” parameter: a[i:j:k] selects all items of a with index x where x = i + n*k, n >= 0 and i <= x < j.
From the data model. Everything Python can do is written down somewhere. Albeit not always in a comprehensible way.
Additional sleuthing may be required to prove that negative numbers are allowed here
 
I found additional information: this also happen when using None for b. eg:
lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a = 9
b = None
print(lst[a:b:-1])
when using b = print() this result in b to be None thus giving the same result
 
With none, it is the same as print(lst[9: :-1])
The correct b should be -1 but it does not work. :-)
 
slice() accepts None for its first and second parameters, so the same is true for a slicing expression
b=-1 requires fewer murky trips through the documentation to prove correct, so I award it one quatloo
 
6:52 PM
Wouldn't any b <= -11 work?
 
# 9 = -1 + 10
# b = -11 + 10 = -1
# Just for fun! Modulo arithmetics
print(lst[-1:-11:-1])
print(lst[9:-1:-1])
 
@0x263A yep, works. I wasn't sure so I stopped manually incrementing b halfway through
 
print(lst[-1:-11:-1]) works.
 
yep, that's what I said :P
 
It is strange print(lst[9:-1:-1]) does not work. :-) It does not obey modulo arithmetics.
If the code base is changed to support print(lst[9:-1:-1]), will there be a catastrophic effect?
 
7:05 PM
Keep in mind that not all programming languages agree on what -1 % 9 should return
@TheRealMasochist It will break backwards compatibility in a small way. As we know from the very painful migration from 2.7 to 3.X, even small breaks in backwards compatibility can cause catastrophes for the next decade.
 
yep. I'm not even surprised when things that are supposed to work a certain way don't anymore because this can always happen. Python isn't an exception (pun intended?)
@TheRealMasochist I wouldn't be surprised if this was taken into account in some big third-party libraries, so yes, huge breaking is expected
 
Thank you all for the discussion. :-)
 
Here is the logic that converts negative slice indices into their equivalent positive form. I chuckled at the comment /* this is harder to get right than you might think */
Python's maintainers are smart guys, so if they think it's hard, it's hard.
 
By the way, print(lst[9:-11:-1]) works!
A crazy behavior.
 
@TheRealMasochist Try this
In [53]: lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [54]: a = 9

In [55]: b = len(lst)*(False-True)-1

In [56]: lst[a:b:-1]
Out[56]: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
@Kevin I'll tell you, but only in a forest where a tree falls when nobody's around to hear it
 
7:15 PM
@inspectorG4dget Your b converges to -11.
 
@TheRealMasochist Line 287 is responsible for that one. -11 is smaller than -1*len(lst), so it gets set to -1.
 
@TheRealMasochist yes it does... and it works
anyone know of a way to transform nested try/except into a chain? kinda like transforming nested else/if into a chain of elifs?
 
... But it happens after stop is usually adjusted into a positive value, so lst[9:-11:-1] still behaves differently than lst[9:-1:-1]
@inspectorG4dget If the exception types are different for each except, then you can put them one after the other, no real work needed
 
@inspectorG4dget using False-True is so cleverly weird that I may start using it
 
@Kevin not quite. I want to try something else if the first thing fails. It's not that I want to handle two different exceptions on the same attempt
 
7:19 PM
try:
    try:
        try:
            foobar()
        except ZeroDivisionError:
            print("oops")
    except ValueError:
        print("Uh oh")
except OutOfCheeseError:
    print("dang")

#the above is mostly equivalent to the below:

try:
    foobar()
except ZeroDivisionError:
    print("oops")
except ValueError:
    print("Uh oh")
except OutOfCheeseError:
    print("dang")
 
@NordineLotfi to be clear, I would never put that in prod because I don't want the next programmer to murder me. That being said, it's so much fun
 
... With the caveat that the upper design will catch exceptions that get raised inside the inner except blocks, and the lower design won't
Ideally you aren't doing dangerous exception-prone things inside your except blocks anyway, so it won't matter whether you're catching them or not
 
You could move that code into a function, then you can use return to bail and keep the indentation shallow
 
try:
    foo()
except Exception:
    try:
        bar()
    except Exception
        try:
            baz()
        except Exception:
            print('uh oh')
 
Oh no, dangerous things inside an except block! Oh well. I already knew we aren't in the ideal world.
 
7:23 PM
try:
    foo()
    return
except Exception:
    pass

try:
    bar()
    return
except Exception:
    pass

try:
    baz()
except Exception:
    print('uh oh')
 
@Aran-Fey iiinteresting - I could make a decorator that takes a list of functions and a callback. That's rather inflexible and kludgy, but it's a good start and in a direction I hadn't previously thought of. Thanks
 
things_to_try = [foo, bar, baz]
for func in things_to_try:
    try:
        func()
        break
    except Exception:
        print(f"Call to {func} failed!")
else:
    print("Ran out of things to try!")
A slightly weird approach
I think I used this one during an Advent of Code
 
@Kevin thanks. This is exactly what I was thinking... but in decorator form. The decorator/function takes foo, bar, and baz as params. But it becomes slightly unwieldy to extend with custom exception handling (everything handles the same exception(s) or I have to specify the exceptions in a separate structure). I wonder how much further I can contort the language
 
Pythons are nothing if not flexible (:
 
is that what makes them ideal companions on planes? I hear they have the power to summon Nick Fury from time to time
 
7:39 PM
Now in decorator form pastebin.com/raw/ArXzWiFd
Custom handling is indeed unwieldy if I try to staple it onto this design
 
@Kevin this is so wonderfully wonderful. I love this. Thanks for building :)
 
Times like this, I think it's valuable to think about more unconventional ways to control program flow. State machines are very customizable, for instance.
 
agreed, and I'd do that in prod. But right now, I'm in pdb and need something lightweight
 
Hypothetical listener: "elaborate upon your last message."
Me: "just don't feel like it."
 
the for loop is what I'm actually using at the moment, but I know that it won't scale. I'm going to try to come up with a more robustier solution for down the road. If I can get that solution into my main tooling repo, then I'd be happy that it'll be helpful
 
7:45 PM
@Kevin You mean you're not in the right state
 
True currently, and almost always true in the general case
 
@Kevin you're right about state machines (or other more powerful structures). Building that will take longer than I care to invest for my current debugging effort. But I do like the idea, so I'm going to try to get it into prod tooling
 
:thumbs up:
 
@inspectorG4dget ah yeah, I didn't mean that for prod either :) But I agree in any cases
I think I would also be infuriated at myself for using this, since even with comments, I would feel really separated from the past self that did that, and also probably forget the "why"
 
I am getting EOFError: EOF when reading a line for this line of code x = input()
The data input is filled with this commands:



p1 = Popen(["msys_shout.exe"], stdin=PIPE, stdout=PIPE,shell=True, universal_newlines=True)
time.sleep(10)

#create icecast connection
p1.stdin.write(b's = shout.Shout()\n')
p1.stdin.flush()
 
7:55 PM
I don't see anything wrong there
 
Sometimes when Popen won't play nice with stdin, I have better luck using communicate
 
8:20 PM
New Flask-SQLAlchemy release has a few dupes coming up, but not enough attention to actually use them as dupes.
thanks :-)
 
8:46 PM
@davidism How recent is the change to the API? Seems strange not to have a duplicate for that already
 
I just released Flask-SQLAlchemy 3 two days ago.
I'm going to delete that link now.
 
 
1 hour later…
10:09 PM
If I have a "Class" that should create two different types of text files, would you structure it like this, with composition?

class Class:
    writer_a: ClassWriterSummary
    writer_b: ClassWriterContent

class ClassWriterSummary:
    pass

class ClassWriterContent:
    pass
 
10:20 PM
not nearly well specified enough to be answerable.
First off: What is a ClassWriterSummary?
second: Why exactly two types of files? What interface do you want Class to expose?
most importantly: what problem are you trying to solve, by not just doing the simplest thing that comes to mind (most likely, just defining two methods write_summary and write_content)?
 

« first day (4373 days earlier)      last day (561 days later) »