« first day (3552 days earlier)      last day (1379 days later) » 

12:17 AM
@Aran-Fey Why would you...need to make that an abstract method? I can imagine making a compliant subclass without an __init__ method, but not a reason for enforcing one..
 
I believe the only reason is "I don't know what I'm doing"
 
 
1 hour later…
1:23 AM
Guys, I need some guidance, as I don't know how to properly approach the matter in hands... I had a 800-line python code that would access functions defined inside the code. At the start, I had my global variables, aswell as 3 arrays representing user input (which I'm building atm).
Now I need to run this code on different user inputs, from a json feed from web javascript from my forms on website. To do so, I learned I should make my code a function, so it would receive userinput as function parameters, and return an output. OK
But when I tried to make my code itself a function, I realized I had a full-on scope problem, because now variables and arrays were not global, so when accessing other functions variables were not defined...
How should I approach this? Should I define nested functions inside main function, or something like that? Never dealth with such a problem!
 
1:57 AM
@PedroSpinola Use SOLID Principles - do not use global variables if at all avoidable (I use like 2 in the last year) - also second link if other is inaccesable
building small scripts? Use Python like glue to make some amazing connections. Need to build full architecture? Such as what you describe - its time to break out true classes and really get to work on the design
 
2:14 AM
How would I sort a list such that one particular value is always first, and the rest are sorted alphabetically?
 
@jigglypuff if that's what you need - make a dictionary of lists would seem a good idea but without an MVCE I would be (and am) guessing at the best implementation
 
my_list = ["c", "k", "d", "a"]
# outputs:
["k", "a", "c", "d"]
# if "k" is my special value that I always want first
 
@jigglypuff okay, so what if there are two "k"s (for whatever K stands for) in this case I would think it stands for "KEY" hence dictionary but the question remains what have you tried and where is it not working
 
assume there's 1 k only
mate im just askin for suggestions, there are a million ways of doing it but I want to do it the most pythonic way
 
the most pythonic way would be the way which is least complicated for the use-case (and its potential scaling). Which, again, would depend on what your trying to do
 
2:27 AM
remove from array, sort array, some array method to insert k at first position? @jigglypuff
 
However, this question of sorting with an exclusionary starting letter would be a good place to start
A quicksort is what I would recommend in a general sense
 
@LinkBerest thanks for answer for my question man, but this kinda knowledge is way out of reach to me atm, I have never built a class in any programming language. This script I mentioned just sorts lists based on SQL data, and return a dictionary, nothing fancy :P
I think you might be trying to talk to @jigglypuff
I'm talking about the SOLID Principles thing you recommended
 
Ah, whoops
 
sorted(my_list, key=lambda x: (not x.startswith("k"), x)), this works with the link you sent, thanks
 
Either way: your answer is learn them or build unmaintainable spagetti code (I say this from experience: learn solid concepts, build a solid design idea, implement it - saves you massive pain later)
Hint: the biggest part is learning to properly inherent between functions (that ABC library they meantion)
@PedroSpinola For instance - I love the Python Ninja's answer on using dataclasses to track inventory items and this is something that is a base for how I build full data structures for handling (and analyzing) results from databases
 
2:45 AM
@LinkBerest look what I wrote to better picture my problem: pastebin.com/DCGXBpVk
Do you think it's a correct solution?
I tried to make a separate function for "main", but I had scope problems all over. So I thoughht of that.
 
@PedroSpinola No, use a class (an abstract) then inheret it and modify it when needed. A dataclass looks like a good idea for this but any class would work - using globals can lead to a lot of problems vs. proper inherentance.
^ technically at this point I would actually draw (on a whiteboard or chalkboard) the classes or data structures I think I need and then connect them where their is overlape (removing the repeated code by adding inheritance) until I come up with a good design
 
alright, gonna read on those, it ain't immediately obvious to me on why a class should be adopted, but after reading I'll think I have a better grasp on it all - I'm quite a begginer
 
yep but this is how you grow :)
Once I was a beginner too (it was Cobol and Java but same concept) and growth took a lot of struggle and work - so enjoy it. If your lucky it never stops ;)
@PedroSpinola if you wan to know from a software engineering perspective (regardless of language) why DRY is so important - there is a really good discussion on that in another stack
 
3:23 AM
/me waves to @thefourtheye (been a while - I linked to your answer on caching with recursion in one of my lectures and a lot of students said it helped (just fyi :)
 
 
2 hours later…
5:41 AM
35 messages moved to MetaPython
 
JBJ
when I've an object of the parent class, how do I use that to access the child class methods in python
 
6:01 AM
@JBJ do you mean instance methods of the child class?
 
@JBJ That sounds like the logic of your program is a bit upside-down, according to the Liskov Substitution Principle. A parent class doesn't know about its children's methods, and it can have many children.
 
sounds like you need to pull a child-method into your parent class...
 
JBJ
One of the API methods that I use is returning me an object... like Wrapper, but I need to access the ListWrapper methods to get the items in it.
 
@JBJ Ok. Can you create a ListWrapper instance by passing a Wrapper instance to ListWrapper() ?
 
JBJ
classpywinauto.controls.uia_controls.ListViewWrapper(elem)
Bases: pywinauto.controls.uiawrapper.UIAWrapper

The method I call returns me UIAWrapper, but to get the data I need the ListViewWrapper..

Note: I'm novice python programmer... my questions may be silly
 
6:09 AM
You might be able to call a ListWrapper method, passing a Wrapper instance to the method. But in general that kind of thing isn't safe, because the parent might not have attributes or methods that the child method expects to exist.
@JBJ I assume you're using this pywinauto. Sorry, I don't know much about Microsoft Windows, so I have little motivation to study those docs. But maybe someone else here is familiar with that API...
 
6:33 AM
@LinkBerest Glad my answer helped. Thanks for sharing. You made my day :-)
 
@thefourtheye how you doing evil twin!? :p
 
Puppyyyyyyyyyy, I am good. How are you? :-)
 
Oh same old same old... :)
 
Is lockdown still in effect there?
 
Still certain things - but on Saturday the restaurants, cafes and pubs were allowed to open up and stuff... but I don't think people are that optimistic it's going to last that long before some beep happens and stuff has to shutdown again...
 
6:58 AM
I think we have to accept this as the new way of life.
Hope we get a vaccine soon.
 
@thefourtheye NOOOooooo.... :'(
fingers crossed either for the vaccine or the virus mutating itself into oblivion.
 
Think I read somewhere they may have found a potential instance of the "bubonic plague" in China or something...
Ahhh here - bbc.co.uk/news/world-asia-china-53303457... apparently we're fine with dealing with that one though...
 
2020 is really like a video game and months are like the levels. As we progress, it becomes tougher :'(
 
@cs95 Fun fact: the way viruses mutate themselves into oblivion is to become too lethal. If they kill the host too quickly, then they can't replicate and spread. This is...not exactly what want we want to hope for, at least not in the short term. :-)
 
I kinda hope this "video game" doesn't end up being Resident Evil...
 
7:08 AM
these germs are smarter than we give them credit for.
 
Evolution is fun.
 
Mind you... I s'pose "Resident Evil" style would be more "exciting" than just plain frustrating
 
@CodyGray have you played pokemon?!
 
Nope
I prefer playing real world molecular virology
 
well, I'm sure you'd enjoy it, you can evolve all the pokemon you want. Pokemon Go is free to play and they're now making it so you can play indoors!
(* this is not paid endorsement)
 
7:13 AM
The only computer game I've really ever played has been Tetris
 
Note to self: Do not accept game invitations from Cody Gray :D
 
Haha. Yeah, that's one thing I would not be good at recommending.
That and Python frameworks.
 
practice makes you perfect!
 
Speaking of games, I am addicted to PubG Mobile.
 
My housemate is similarly, to Clash Royale. I usually hear game sounds coming from the restroom when they're inside.
personally never saw the appeal
 
7:20 AM
@cs95 I thought I am the only one who plays from the restroom :D
 
@CodyGray ummm.... and look where your "playing" has got us all - good job - well done :p
 
Well, they can't all be wins
 
Were you sitting playing the board game Pandemic one day and thought - "I hate board games, they're so boring, I'm a molecular biologist - let's see if I can't make this much more exciting..." :p
 
I have actually never played that board game
Haven't found a board game that beats Risk yet
 
Don't put ideas in their mind, my evil Twin :D
 
7:30 AM
Oh good point... they've already done enough damage :p
 
 
1 hour later…
8:43 AM
Is mypy in any way official? Trying to argue the validity of an annotation because mypy rejects it.
 
9:05 AM
isn't it similar to cpython, like a reference implementation?
given a quick google search I can't find any sources for that claim though
 
same problem here. I've assumed it to be the reference, but there's no source for that.
 
9:27 AM
search mypy's github issues on any specific annotation type checking problems might turn up something
 
Lol "This document is not update to day, please check the source code for documentation". Thanks anyways I guess :D
 
9:43 AM
@metatoaster That was a good hint. Turns out they want to support the annotation, the PR is just not accepted yet.
 
10:04 AM
Alright, after an hour of PEP spelunking: I conclude that typing is a mess.
from __future__ import annotations just breaks runtime typing, hard.
 
Hey guys just curious if I need to earn back the ability to ask questions can i earn it back by editing other peoples questions also
 
@Kwsswart Not an expert, but the help pages suggest only your own questions count.
No idea why that page is self-referential, by the way.
 
@MisterMiyagi Hmm thanks just trying to sort this out I don't even have a question lol I am just really wanting to sort it
 
10:36 AM
I imagine editing only matters so that the edited version gets upvotes
 
10:49 AM
Hello
How do I break this image having multiple images in one and access using index in pil?
 
0
Q: Pillow: splitting a spritesheet into seprate images

Lord_Zane 55I have a spritesheet with sprites of 40x30 each, and I'm trying to split it up into indivdual sprites named from 0-number_of_sprites from PIL import Image from os import mkdir mkdir("assets/icons") sheet = Image.open("assets/icons.png") count = 0 for x in range(12): for y in range(97): ...

 
user13415013
11:16 AM
New here.
Im Nerd, From Nepal.
Nice to meet guys, hope you are having good days :) .
 
11:53 AM
@nerd welcome!
 
user12867493
I'm trying to remove Python from my Mac, I followed the steps here but it still exists. Any ideas?
 
user12867493
dmanokhin@MacBook-Air bin % python --version
Python 2.7.16
 
Does mac not rely on a system python?
I'm only familiar with debian-like linux distros where removing system python is fatal
> Do not attempt to remove any Apple-supplied system Python which are in /System/Library and /usr/bin, as this may break your whole operating system.

NOTE: The steps listed below do not affect the Apple-supplied system Python 2.7; they only remove a third-party Python framework, like those installed by python.org installers.
@Daniil from that post ^
are you sure that python is not the system python?
Python 2.7 is the default system Python on recent systems, while on 10.6.4 it was 2.6 and 2.7 was user-installed. DO NOT UNINSTALL 2.7 FROM A RECENT OS X SYSTEM. — Martijn Pieters ♦ May 31 '16 at 15:08
so please elaborate on your situation
 
user12867493
It probably is the 2.7 version default, I really want to remove it though as it often conflicts with Python 3
 
It can't conflict. Always use python3 or a virtualenv.
 
12:15 PM
Do not remove python2 from your mac!
Seriously.
If you think there is a conflict between the system python2 and any other python, seek help to fix the conflict. Do not attempt to solve it by removing python2.
 
What kind of conflict are we talking about? Inputting python in the terminal starting python 2 instead of python 3?
 
@MisterMiyagi then again it would be educational ;)
 
Yeah, about as educational as a broadsword to the face. ^^
Now I feel like rereading my entire PTerry collection again... :/
 
@MisterMiyagi do it!
Always the right choice
That reminds me, I should finish that book... I haven't really read since full remote started
 
12:34 PM
I've read a lot, but did lend most of my old collection to other people before this all started.
At the moment, it's kinda difficult to go around collecting what's due...
 
@MisterMiyagi ebooks FTW
 
1:34 PM
Any of you guys know why comtypes.client takes so long (around 30 seconds) to create a single PDF from a docx file and/or how to do it faster?
 
1:54 PM
@JamesMcIntyre if it's using comtypes ( Office dll) it will likely be slow because of the external call
Compare it to using Export in word itself (on same size PDF) and if it's comparable then that is the bottleneck
Also word adds a lot of metadata to PDFs it creates so it's a lot slower than other APIs for this in general
 
@LinkBerest Thanks for your responce. I've just attempted to time saving as PDF in word and it's faster than I can can time (at most one second) :/
(this was the same file template)
Currently I'm doing:
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(os.getcwd() + "/PDFs/" + str(line[13]) + ".docx")
doc.SaveAs(os.getcwd() + "/PDFs/" + str(line[13]) + ".pdf", FileFormat=wdFormatPDF)

doc.Close()

Are you saying there is a better way of doing this?
(before the above, I've got wdFormatPDF = 17)
 
is there a canonical explaining for-else?
 
2:14 PM
@MisterMiyagi not that I recall... what about something like this ?
 
@JamesMcIntyre Try DispatchEX instead of CreateObject might help speed a bit but otherwise that looks fine
There are faster ways but that doesn't mean better (all of them require more overhead to work with Windows - currently I pipe or open a Powershell instance to do this)
 
Just to clarify, are you saying I can try replaying?:

word = comtypes.client.CreateObject('Word.Application')

with

word = comtypes.client.DispatchEX('Word.Application')

I will try this in a moment, it's currently working through my sample of 40 again and so will be done in anouther 15 minutes
 
Yeah DispatchEX will open a new instance of the loaded word app (rather than trying to open it or trying to use the same instance first) so it is usually faster
You can read more in this msn article
 
2:57 PM
That's brought it down to around 20s. Thanks @LinkBerest!

I don't quite get why it's so much slower than native VBA which does it in around 1s but I'm doing it in Python rather than VBA because VBA isn't robust enough and kept breaking and your DispathEX method has reduced my time by 33% which is really going to help. Thanks very much!
 
Cause VBA is built in to the app. VB, C#, or PS would all also be faster because the have more direct ties with the comobjects (with .Net libs) then Python does
 
3:19 PM
Anybody know why this code dpaste.com/25ZD8YJ doesnt seem to work when running in the terminal? trying to set the test server for internal errors emailing through to localhost
the terminal sort of allows entering it into but after it just sort of freezes
 
@Kwsswart I don't think it's supposed to go into the background. If you see it "freeze" it might still work. Check the actual functionality instead.
open localhost:8025 in a browser for instance
 
@AndrasDeak I have i have gone into the app and forced a error and it isn't displaying any errors... the tutorial explains it will act as if receiving the email and display the 'email' in the terminal
 
OK, just making sure you're not trying to debug a problem that isn't there. Others who know web stuff would probably benefit from some explanation of what you're exactly doing, how you "forced an error" and from where to where emails should be sent, and what tutorial you're following etc.
 
docs.python.org/3.9/library/abc.html#abc.ABCMeta.register Can someone provide bigger picture of what "Register subclass as a “virtual subclass” of this ABC. " does?
benefits, or usefulness of this?
 
@VisheshMangla it's presumably useful when you need the functionality it implements
 
3:32 PM
@AndrasDeak well forcing the error I am basically doing the error as instructed in the mega tutorial and I have a username field set as unique and I am changing a username to a username that is already in the database
the idea is that it will send an email with the error report along with the stack trace
 
@Kwsswart that's a lot of things I don't know how to put together with the smtpd server thing, but as I said I don't know web stuff. I'll defer to the others who do to help you out.
 
thanks man Just trying to run the tests to see if i did something wrong along the way
 
 
1 hour later…
4:40 PM
This was working for me before (re my earlier messages) but randomly it's giving me this error without any code changes (I've even tried restarting my computer).

Any idea what's going on here?:

AttributeError: module 'comtypes.client' has no attribute 'DispatchEX'
 
4:57 PM
@Kwsswart It won't have frozen, it will be listening on the port, no?
There's not enough info to help you. You haven't shown your configuration of your Flask app to actually make use of this server. It won't just catch your app errors by default
 
5:41 PM
:49850739
@roganjosh dpaste.com/2R3B1ZA here is one part and the other dpaste.com/3WYGR43
thats the config files i am using
the __init__ file also has import logging
from logging.handlers import SMTPHandler
 
You're running the smtp server in another terminal, right?
Since you said it "sort of freezes" I'm wondering whether you just ctrl + C'd that and then started running your flask server in the same window
 
@roganjosh I am doing it in a seperate terminal
 
And you've sent the test email from the chapter that introduced flask-mail?
 
6:00 PM
i push enter it sort of doesnt do anything, doesnt let me type anything
 
Enter on what? That's for running the smtp server. From the links you gave me, it looks like you've skipped a big chunk of stuff
 
Im on the part: Sending Errors by Email
 
Aha, sorry, I was looking at the wrong section
Honestly, not sure how to debug this. I assume you set all of the required env-vars that come a bit further on in the chapter, or put them in .env?
 
yeah set the env vars
 
I don't suppose anyone knows of a happy-medium in how VSCode auto-closes HTML tags? I've found a few answers from a couple of years ago that tell me how to disable them, but I don't want that. I like the feature if I'm, say, creating a table from scratch. I hate the feature if I go back and, say, decide to bold some text. The only option seems to let it auto-complete in that case and then ctrl-z, which sucks
Maybe I can set a hotkey that is return + ctrl Z in one go, but it'd be nice if there was a plugin that handled sane behaviour
 
6:29 PM
@roganjosh I have done all the sets in that chapter and still i am not sure why its not working... maybe I did something wrong in the code?
 
@Kwsswart It's going to be too many stabs in the dark for me, sorry. I have a lot on currently and I'm not sure I'd be giving helpful suggestions. If it's not crashing outright with a traceback that can help me pin it down, I'm stuck currently
 
6:44 PM
@roganjosh thanks anyway man will research it a bit
 
I'm losing my mind, I'm debugging an issue that disappears if I comment out the line unused1, unused2 = some_string.split('.') ;_;
 
6:59 PM
Losing or lost?
 
@JamesMcIntyre Is word open? You cannot call dispatch if word is not open (or at least the Office launcher thingy running in the background <- search for "open word in background" or "keep word open in background" for the actual name of this as I forgot). That is what was causing the slowdown in your earlier code - it takes a while to open Word (if you need to open word - you would have to use your other method but make sure to open it early in the execution due to this)
@roganjosh you could probably do something with "editor.quickSuggestions" in the configuration file not sure of a specific way to do that with just html tags though
meaning you're most likely correct that a keybinding is probably as close to that "happy-medium" as your going to get for a while
 
@wwii Lost. Good news is, I found it again. Bad news is, I feel very stupid.
The line of code was actually unused1, unused2 = some_string.partition('.'). That's right, I wasted 3 hours hunting down a ValueError that was staring me in the face.
 
s'all good, it happens to the best of us sometimes :)
 
7:44 PM
@LinkBerest <grumble grumble> I suspect you're right. It's those book-ends that appear round the auto-complete </div> (middle tag in screen shot) that made me think we should just be able to hit backspace, with it targeting the thing it just added.
VSCode knows what it just did. VSCode just don't care.
 
8:09 PM
seeking recommendations/ manually migrate to DataScience.SE stackoverflow.com/questions/62782978/…
 
@Aran-Fey - some_string.split('.') ;_; is the ;_; documented anywhere?
 
@smci heh didn't realise it'd turned into a HNQ, but it's definitely a dupe of something. I closed it with this
 
nevermind..
 
Yes, it is documented as the tears of sadness I shed everytime I see an un-answerable question.
In [1215]: ;_;
Out[1215]: ''
 
9:20 PM
Tkinter Question:
Can i use a frame inside a canvas (with create_window method) which is not in a root window, (it's inside TopLevel window)?
 
Huh? If the frame is in a Toplevel, then it can't be in the canvas.
Or are you saying that the canvas is in a Toplevel? That doesn't matter
 
9:48 PM
self.song_title = tk.StringVar(value=self.filename)
#self.song_title.set(self.filename)
self.preview_frame = ttk.Frame(self.metadata_window)
self.preview = ttk.Entry(self.preview_frame,textvariable=self.song_title,width=30)
self.preview.grid(row=0,column=0)
self.preview_frame.grid(row=0,column=0)
Is there something wrong with the above code?
I can't set Entry default value.
self.filename isn't empty.
print(self.song_title.get())
Works.
 
> Note that the [StringVar] constructor takes an optional widget argument, but no value argument; to set the value, call the set method
 
Yes i try to use the set method (comment in line 2).
No difference.
 
Then I don't see any problems
 
I found it
But i don't know how to fix it.
I changed ttk to tk in both Frame and Entry Widgets and default values appeared.
It's seem's that theme delete Entry default value.
Any idea?
I use the blue theme from ttkthemes module.
The instance is maked directly from MainMenu.
Is that something i must change?
 
10:08 PM
Jun 14 at 18:25, by Andras Deak
@ChrisP with your track record you are required to come with an MCVE when you ask for help. Have the shortest amount of code necessary to reproduce your issue, with a clear problem statement and question.
 
 
1 hour later…
11:21 PM
I have a flask website (on localhost for the moment) with a javascript form with multiple dynamic inputs. I need to get these input values so I can run a custom python function using them as parameters, and then return output of this function in a different page on the website. I'm not using wtf-forms, just plain js. I have never done something like this, and I can't allow users to be able to see inside the python function.
My function and my form are ready, but I didn't built connection between them yet. Is json a good way to go to extract/return data from/to website? Any advice before I start?
 
11:35 PM
If you want to show the output on a different page, then all you need is a form and a submit button. The browser will send a POST request and render the response. You only need JS and JSON if you want to display the result on the same page
 

« first day (3552 days earlier)      last day (1379 days later) »