« first day (3173 days earlier)      last day (1791 days later) » 

2:35 AM
@smci But I have seen quite a few SO users do that, for eg when the answer they wrote matched what was already there, or when the question was deleted and the answer wasn’t doing any benefit there but I don’t want someone to look at the contents now
What should be done to edit such answers to avoid showing their contents
 
2:47 AM
cabbage beautiful pythonistas
 
cbg
 
not much - when I do that, I edit with two dots around a line of white space.
 
3:07 AM
I just do * $ and # but yes yours sounds less spammy
 
3:19 AM
Does anyone have experience with pyinstaller?
I get this traceback error when I try run my compiled executable

`Traceback (most recent call last):
File "site-packages\discord\client.py", line 270, in _run_event
File "<frozen app>", line 285, in on_ready
FileNotFoundError: [WinError 3] The system cannot find the path specified: './cogs'
`
This is the offending line:
`for filename in os.listdir('./cogs'):`
I'm not sure how I'm supposed to get the path in the frozen/compiled state as everything is inside the built .exe
 
 
1 hour later…
4:24 AM
what's the python equivalent of mathematica's findshortesttour?
 
 
1 hour later…
5:49 AM
recbg
 
6:28 AM
cbg
 
7:12 AM
rbrb
 
7:24 AM
Hello al
 
7:39 AM
@DeveshKumarSingh Oh, I wasn't aware that was common practice, sorry I don't know then.
 
7:55 AM
@smci no worries :)
 
8:19 AM
Hi guys
What am I doing wrong in this regex?
def clean_postal_codes(a):
    return re.findall('^[^0-9]|[^DFIOQU]', a)
I am trying to return empty strings when the beginning character is a digit or when there are alphabets 'D', 'F', 'I', 'O','Q','U'
 
8:51 AM
@RaphX Why not use if a[0].isdigit() or not set(a).isdisjoint('DFIOQU'): return '' then?
 
rex = re.compile(r'^[0-9]|[DFIOQU]')
return '' if rex.match(a) else a
 
@yuelongqin re.search
 
@Aran-Fey I understood why you are taking set(a) but when you are doing isdisjoint check with ('DFIOQU') does that implicitly convert the second argument into a set?
 
I don't think so. It just needs to loop over the thing and do a if elem in set: check for each element
 
@DeveshKumarSingh just that people do that doesn't mean it's good practice (cc @smci). There's no point in vandalising your own deleted posts. Whoever can see deleted content knows enough about SO to see revision histories. Vandilizing like that is pointless and distracting.
Just delete what you want deleted and stop worrying about dumb things
 
9:02 AM
Ok as in strings right?@Aran-Fey
 
what ? re.search need search ?
rex = re.compile(r'^[0-9]|[DFIOQU]')
return '' if rex.search(a) != None else a

need change '^[^0-9]|[^DFIOQU]' to r'^[0-9]|[DFIOQU]'
 
If you use rex.match that's like doing str.startswith. It only looks for DFIOQU at the start of the string:
>>> rex.match('xQ')
>>> rex.search('xQ')
<re.Match object; span=(1, 2), match='Q'>
 
cabbage for a bit
 
def clean_postal_codes(a):
    return re.findall('^[^0-9DFIOQU]', a)
you want to exclude digits and letters, not digits or letters
a specific character will always be either a digit or a letter
 
I thought they wanted to check if the string starts with a digit or contains any of DFIOQU?
 
9:13 AM
@RaphX can you give some example input/output?
@Aran-Fey good point
 
9:32 AM
@AndrasDeak okay
 
1 hour ago, by RaphX
I am trying to return empty strings when the beginning character is a digit or when there are alphabets 'D', 'F', 'I', 'O','Q','U'
 
9:47 AM
Here's a fun puzzle I saw yesterday on xkcd. You have a large set S of size n of integers. To make it concrete, let's say the integers are 32 bit signed ints, and there are at least a million of them. What is an efficient algorithm to find an integer not in S? Try to minimize the space requirements, and the time should be O(n).
 
Hi All,
Trying to create a regex to match all function definitions written in assembly but unforchuntily my regex not be able to handle all corner case ...

https://regex101.com/r/cRHVSp/3

regex and examples are saved in above link
 
@AmanJaiswal How is this related to Python?
 
Thanks guys! I got it figured out!@yuelongqin@MisterMiyagi@Aran-Fey
 
Regex is written in python to parse thet file
 
10:23 AM
Hi again guys
I want to find the most commonly occurring substrings within a pandas dataframe column as well as the respective counts
Can anybody direct me what to look at?
 
That won't help because it takes the whole string to get their respective counts @anky_91
Let's say we have a string 'Forest Dr.'
If Dr. is a commonly occuring keyword in a pandas dataframe column called 'address_line' I want this to be displayed and its corresponding count
 
You'd have to know that 'Dr.' is a possible substring. No way anything built-in will do that for you.
Just imagine how many possible substrings there are...
 
It doesn't have to be built in, are there any modules that can do it? @AndrasDeak
 
@AmanJaiswal I think you'll have to give us a bit more background information about your problem... what does an assembly function definition look like and which part of it is your regex supposed to match?
 
10:41 AM
Cbg
 
cbg
 
agreed, no way that can be done. One thing if at all can help is series.str.get_dummies() and then sum probably but can't assure without seeing the data sample.
 
@RaphX do you mean substrings or words? For you, does 'Forest Dr.' contain only 'Forest' and 'Dr.' or also rest and t D?
 
Yeah sorry words are what I meant @MisterMiyagi
 
Is it possible to rewrite this code to use configparser or some other package potentially to achieve the same result?
        for filename in os.listdir('./cogs'):
            if filename.endswith('.py'):
                bot.load_extension(f'cogs.{filename[:-3]}')
If I leave my code as-is then when I try to compile it the path gets broken and my program becomes unable to find the ./cogs directory
 
10:48 AM
rbrb
 
I had the same issue with it being unable to read my config file until I changed to configparser then it worked fine
 
@JBower are you executing it from the parent directory of cogs?
 
@MisterMiyagi Yes/no
the code works fine normally the issue is I'm using pyinstaller to compile it
 
@RaphX what i meant was something like pd.DataFrame({'col':['Dr. Forest','a b']}).col.str.get_dummies(sep=' ').sum() . just guessing
 
so its path gets changed when its frozen
 
10:51 AM
so your question is actually "how do I access data from a pyinstaller application"?
 
Then make the path relative to sys.argv[0] instead of relying on the current working directory
 
Do you think it's possible to recode my for statement so it could possibly be used with configparser cause that was my exact fix for reading another file from a different directory
its just this is a for loop and not opening a specific file straight so I'm not sure how I'd write it
I'm not really sure how to do your suggestion either unfortunately @Aran-Fey
 
I'm pretty sure configparser can't list the files in a directory, so I'm not sure how you'd write it either
path = pathlib.Path(sys.argv[0]).parent / 'cogs'; for filename in path.iterdir():
 
@MisterMiyagi I've been able to use pyinstaller up until now but this is a re-write of my previous code to try and make it neater but in doing so I've broken it up into a lot more files than before so compiling it is proving to be more complicated
@Aran-Fey Thanks! I'll try see how that goes! :)
 
@anky_91 Can you explain how this would work?
 
11:00 AM
@RaphX you can read about it here , not sure if you need this(just guessing since no mcve)
 
:46582623
Ignoring exception in on_ready
Traceback (most recent call last):
  File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\discord\client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "<frozen app>", line 290, in on_ready
AttributeError: 'WindowsPath' object has no attribute 'endswith'
WindowsPath object has no attribute endswith
I'm wondering, how do fstrings work?

This code:
bot.load_extension(f'cogs.{extension}')

Is also loading cogs but its not being given an explicit path so it works
 
11:16 AM
the simplest way to tackle this i'd imagine is to exclusively construct and use full paths. Once you do that, you'll realise the issues, if any, when using pyinstaller instead.
at that point, you can correctly construct the fullpath based off of the correct directory as needed.
 
But I'm not sure what the full path would be?
I can't set it to where it is on my pc right now because that will change when its compiled to executable and also when the exe is moved about or distributed I'd presume?

I've just found out pyinstaller have a module callled
"PyInstaller.lib.modulegraph.zipio.listdir"

Seems to be for working with paths but for zipped files
Maybe/hopefully I'll find another pyinstaller module for working with paths
 
that first sentence really is the main point that you should be focusing on.
You need to understand what the full path will be, and where cogs folder will be located.
It's not pyinstaller at fault here. Making yourself actively think of fullpaths should hopefully lead you to asking the right questions
 
It's like you're still rummaging through your toolbox looking for the right tool to drive a nail into the wall even though we've already pointed at your hammer 5 times
 
My program is workig fine if i don't use pyinstaller to compile it
And I'm not sure how to even work out what the new path would be that's created by pyinstaller
 
indeed. so ask yourself what changes when you use pyinstaller?
that is a better question to be asking.
 
11:26 AM
but the module I mentioned above seems like it would work
as some of the functions use almost the same code as my original code
but presumably works as its by pyinstaller
https://github.com/nortd/driveboardapp/blob/master/deploy/PyInstaller/PyInstaller/lib/modulegraph/zipio.py
@ParitoshSingh Everything changes as it's compiling the entire application, all files and folders into a single .exe
 
does this include the cogs folder?
 
shouldn't matter. AFAIK PyInstaller unzips the whole thing into a temporary directory.
 
@ParitoshSingh It should do yes
 
@Aran-Fey mhm, indeed. the only thing to consider is whether cogs would be available in that temp directory
 
You know what? Since I'm on Windows right now anyway, I'll just try it. And then I'm most likely gonna downvote every single answer on this question.
 
11:36 AM
@JBower Aran kinda gave away the question that i wish you were thinking of. You need to ask yourself where do the files go. that should help you get to the answer easier. if you look at docs you'd find out about the temp folder. and then an SO search should lead you to this answer
@Aran-Fey oh haha. yep, the right answer is buried a couple answers down, but works well.
 
I don't see a right answer there
 
you don't like the methods there? the sys._MEIPASS is set correctly when running it in onefile mode, so you can reliably use it
 
@ParitoshSingh Ooh thank you! Sorry if it seems I haven't tried to look much, I was up till about 5.40am trying to finish my program and get it compiled before I finally gave up to get some sleep so I'm fairly overtired
 
ah, ouch, been there done that. :) I'd highly recommend lots of coffee then, and some breaks if you can afford it
and JUST to be safe, i do not know whether your cogs folder is being included in the temp directory or not. If you find out it's not being added (just run the exe, go to your temp folder, see if it's available there or not), you'd have to exclusively add it using the --add-data flag as shown here . Also, do not use the -w flag though, i've had issues with that, i think it might be broken.
general rule of thumb, fullpaths can help avoid a lot of headaches, so always try to resolve relative paths into fullpaths first. It will save a lot of time and can help figure out the issues easier.
 
Welp, turns out those answers weren't wrong after all
 
11:49 AM
it's a path that pyinstaller guarantees to set correctly. it's mentioned in the docs too
this way you don't even have to rely on currently working directory.
 
And then they release a new version and it breaks
 
yep. but hey, atleast then we can all ready our pitchforks and have a target to blame. :P
 
12:07 PM
haha yeah that's not bad advice! I'm not much of a coffee drinker tbh but feeling like I'm going to need something to keep me going throughout the day lol

Thanks for your help @Aran-Fey @ParitoshSingh pointing me towards the right direction!
The link you shared here worked perfectly as far as I can tell! :)
-https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile
I think on that note I'm going to go take a much needed break haha!
 
cheers
 
 
1 hour later…
1:36 PM
cbg
 
1:52 PM
is it possible to type-annotate a decorator as returning a function of the same signature?
I've tried a TypeVar with a bound of Callable, but PyCharm is complaining it's not callable
C = TypeVar('C', bound=Callable)


def decorate(call: C) -> C:
    @functools.wraps(call)
    def print_call(*args, **kwargs):
        result = call(*args, **kwargs)  # PyCharm: call is not callable...
        print(call, '=>', result)
        return result
    return print_call
 
cbg \o
 
2:25 PM
Can someone explain to me how stackoverflow.com/questions/56738040/… is a duplicate? I honestly don't understand. While I agree that my issue is related, neither is the question the same, nor can I find an answer in the linked post. I'm explicitly asking about 1 worker with a thread-safe object queue.Queue. The linked question is a far more general question and isn't using a thread-safe object.
 
feel free to mention the same in a comment to the question as well. having said that, im not familiar enough with the topic to comment further, apologies.
 
@MisterMiyagi I think it's actually not possible, because Callable won't let you use a TypeVar as its first argument (must be a list). If it weren't for that, using two TypeVars like C = Callable[A, R] should've done the trick.
 
rbrb
 
@finefoot I don't know Flask, so I'm hesitant to re-open your question. But @davidism certainly does know Flask, and may be able to suggest a better duplicate target.
 
You don't ask about an issue in your question, instead you ask "is this code possibly not safe" which is very broad. It all boils down to what's said in the duplicate, which is basically "use constructs that are safe across whatever worker implementation you use." Given that queue.Queue is not the same as gevent.queue.Queue, you're not doing that, so I added some more duplicates. At this point I do not feel like it needs to be reopened.
If you have a specific issue with some code, ask about that issue.
 
2:50 PM
@MisterMiyagi It should be possible. As you've not provided a fully typed example I've used a different example.
 
@Peilonrayz the point is that it is not fully typed
C can be any callable of any signature
 
Then change it the __call__ to do the same.
 
you mean __call__(self, *args, **kwargs) -> Any?
that's pretty meaningless...
let me rephrase that: C has a well-defined but arbitrary signature
 
@MisterMiyagi Then just use decorate(call: Callable) -> Callable.
 
that will again erase all type information about arguments and return types
I did that at first
as @Aran-Fey mentioned, what I want is the equivalent of decorate(call: Callable[AT, RT]) -> Callable[AT, RT]
the best I could do so far was decorate(call: Callable[..., RT]) -> Callable[..., RT]
that erases only part of the type information
 
3:11 PM
Curiously, setting C = TypeVar('C', Callable, Callable) is accepted but discards the type information
 
I thought Generic Protocols worked, but they don't.
class MyCallable(Protocol, Generic[TRet]):
    def __call__(self, *args, **kwargs) -> TRet:
        ...
PyCharm however, does pass through all the type information. Not sure if it would on a larger scale tho.
 
@X4748 that's not valid python syntax
you already asked a C++ question here earlier, I'd rather you didn't add PHP to the list
 
@AndrasDeak So..? It was a NginX syntax...!
@AndrasDeak It wasn't PHP
 
Is your question related to python then?
 
Hmmm.. I think web servers are related to every programming language lol
 
3:24 PM
lol.
What language does your backend use?
 
PHP :))
 
awesome
@X4748 I suggest asking in the PHP room
 
@AndrasDeak Ok... Thanks. (Actually, I did before asking here)
 
@davidism Uff, I'm still reading up on things... The more I read, the more questions arise. 🤦 Thanks for the links, though, of course. :) "use constructs that are safe across whatever worker implementation you use." Naturally, that sounds like the best solution, but a database isn't available in my case. So I thought of using Python objects. To make things safe, I'm using thread-safe queue.Queue and I'm only using 1 worker anyway, so it should be process-safe.
@davidism "If you have a specific issue with some code, ask about that issue" So my specific issue is that I don't know if I've made an error in my reasoning so far. Are my assumptions about non-relevant process-safety correct? Is using queue.Queue enough to prevent race conditions? Isn't that specific enough?
 
3:49 PM
how can I set timeout for each greenlet in gevent.pool.Pool's imap/imap_unordered?
 
4:08 PM
cbg
 
4:40 PM
cbg
 
 
1 hour later…
5:44 PM
4/5 of the latest pandas questions have some form of "loop" in the title :(
and the 5th uses a loop in the question
 
Finally, I got 1 upvote :D Now I can downvote questions
@AndrasDeak After your upvote, someone downvoted my question, so I couldn't unlock downvote privilege at that time
 
Yay
 
cbg
 
6:00 PM
@ParitoshSingh do you use Flask-SQLAlchemy?
For debugging, I'm still half-toying with the idea of a script to graph out deletes on cascade (In terms of how deleting a top-level entry will go through the database). But there's been a lot of negative feedback about flask-sqlalchemy in the past (not related to my plans) so I'm curious whether it's even really used
 
I haven't really got a decent benchmark on whether people are using the wrapper in everyday work, or they just roll their own approach
@AndrasDeak thanks for that, I wouldn't have thought to search in that angle.
@AndrasDeak am I being dumb or can't the list be sorted?
 
6:22 PM
(We use flask-sqlalchemy)
 
That's pretty decent confirmation for me, thank you
 
I won't ask what it confirms, in case it's "only idiots use flask-sqlalchemy" (-:
 
May 2 at 16:33, by Antti Haapala
@roganjosh flask-sqlalchemy is a piece of "#¤ that does integration completely backwards from what za001a needs to do.
The latter part isn't relevant, but I've had a few comments like that from people I will take seriously :)
 
@roganjosh FWIW, in Australia, Cascade is a brewery. They produce a range of beers, as well as apple cider.
 
The lack of a closing quotation mark in that post means the rest of all chat from here to eternity is really just part of a never ending string describing what flask-sqlachemy is a piece of...
 
6:34 PM
@PM2Ring I probably need to "query" them more :P
 
Haha, seriously.
 
But really, I have tables with deletion cascades all over, and it's not easy for me to understand exactly what gets deleted when the parent gets deleted. It seems it can cascade through the DB and super-easy to make make a mistake
 
@PM2Ring )
 
Yet, there doesn't seem to be a recursive tool that shows what exactly gets deleted. That, to me, suggests that I'm doing things wrong.
 
6:42 PM
@roganjosh oops sorry missed this earlier. i personally do not use it. but i am no authority on the matter.
 
A practical example: the highest level is a department in the factory. Each department contains machines, and each machine has a parts list. Deleting the department (and thereby, the machines in it) should not delete parts associated with it e.g. washers that can be used all over the place. This seems like an easy and silly mistake to make
@ParitoshSingh No worries, it was more of a survey because I know you use Flask :)
 
if it helps, the reason i never felt a need to add a layer of abstraction for SQL was because we already had code ready that was interacting with SQLite from python, and so there was never a need to add needless complications. We don't, at the moment atleast, interact with scarier databases so to speak.
So, it was never even something we had to think twice over. Funnily enough, it was also the reason we went for Flask over Django
First impressions were not kind to it, we were looking for as few changes as needed.
 
@ParitoshSingh can totally sympathise with that :) My concern here is in regards to .relationships that have unintended chain-effects
 
finally got my python dupe hammer :)
11
 
My knee jerk instinct would be to just build a kind of pre delete and post delete change tracker*, even though that's probably an inefficient way of doing it compared to something that already exists, if such a thing exists.
@DeveshKumarSingh hey hey, grats! sounds like it's hammer time!
 
6:58 PM
@DeveshKumarSingh Welcome to the club! Please use the Mjölnir wisely. :)
 
@DeveshKumarSingh Finally? You make it seem like you've been waiting long.
 
I mean it took 3 months, thanks guys :)
 
Congrats
 
@roganjosh can this help? Perhaps give SQLAlchemy a try, no Flask SQLAlchemy involved, and see if you can get the event hook to give you what you need. this might also help
perhaps if that does what you want it to, Flask SQLAlchemy may have a version for it too. Or you might as well just use SQLAlchemy at that point
 
@ParitoshSingh I think I can already hook on to Flask-Sqlalchemy and get the cascade params. I'm just doubting myself now on whether there is a better way I think, because I don't understand why it's not a thing already
 
7:06 PM
ah i see
 
@DeveshKumarSingh congratz Devesh
 
@roganjosh you can either be or not be dumb but I can't see any signs that it can be sorted
@DeveshKumarSingh I suggest installing poke's hammer warning userscript
 
7:21 PM
Done! thanks
 
7:46 PM
never knew so had a chatroom. :)
 
SO has a whole chat server, this is just a room for python.
But you were here last year. Welcome back anyway ;)
 
8:04 PM
oh wait, you are right. Time to refresh my memory. Thanks. @AndrasDeak
 
8:18 PM
o/ @harvpan
 
new avatar
 
yes indeed
 
Area of a circle with radius r the wagons. Mhmm.
 
You have to relax the pedantic muscle to understand (-:
 
@piRSquared Circle the wagons?
 
8:24 PM
yes
 
Best said in a John Wayne voice.
 
Not my joke either, but maybe I should credit the source on my profile. Hey, that's a good idea. Now I just have to find the source
 
@piRSquared I'm sorry, Dave, I'm afraid I can't do that.
 
that made my day (-:
 
@piRSquared :)
 
8:36 PM
@piRSquared Good luck with that. It's probably one of those phrases with several variations, and no clear origins. I did find this, though. theresahuppauthor.com/blog/2017/06/28/…
 
Hey, I am studying hash maps in depth on Code Academy. I quote: "*Hash Function*\n A hash function takes a string (or some other type of data) as input and returns an array index as output."
Isn't this incorrect? Depending on the hash function, a hash function can also turn e.g. passwords into strings of a scrambled specific length.
 
the statement is within the context of a hash map where the task of the hash function is to ultimately give you an index in the underlying array
"hash" in general is a broader term that typically maps elements in a set into elements of another set such that small changes in the input will likely lead to large changes of the output, with small (but usually finite) chance of mapping distinct inputs to the same outputs
and then there are cryptographic hashes which are a subclass of hashes
 
Thanks, I knew it, I just wanted someone to confirm it.
 
usual disclaimer: "I think"
PM is not far away so he'll correct me if I'm wrong again ;)
 
Lol - the disclaimer
 
8:52 PM
@AndrasDeak It's close enough. ;) Although a hash function generally returns an (unsigned) integer. And normally the range of those integers is smaller than the size of the domain, so hash collisions are inevitable. But a good hash function tries to minimize the odds of collision with the data that its being used on.
 
thanks
 
@SebastianNielsen Modern cryptographic hash functions used on passwords, or used to verify file integrity, always return an unsigned integer. But that integer may be printed in hexadecimal.
 
Really, I recall that passwords that have been hashed looks a lot more ... random? Like, consisting of all sorts of characters. So, there is no way it is just a "hexadecimal"
Perhaps, I am just misremembering. I just tried a md5 hashing generator, it seems like the result indeed could be a hexidecimal
 
@SebastianNielsen They may also be encoded using base64, so you get a mixture of letters & numbers, and a couple of punctuation marks. But the underlying hash value is still an integer.
 
you can represent an unsigned integer (basically bytes) in arbitrary formats
 
8:57 PM
Yeah, that explains it.
 
@SebastianNielsen Yep. MD5 returns a 128 bit integer. SHA-1 returns a 160 bit integer. SHA-256 gives 256 bits.
Feb 12 at 21:54, by PM 2Ring
FWIW, here's a Python implementation of that SHA-1 pseudocode: https://gist.github.com/PM2Ring/63be1b6f43c77c3b36b19d4190400215
 
Wow, awesome neat little SHA-1 pseudocode! I am going to go through that later this week.
 
In many cases, you want any small change in the input data to produce a large change in the hash value. But there are special hash functions where a small change in the input (hopefully) gives a small change in the hash value. This is useful for testing similarity of documents and images.
@SebastianNielsen Thanks.
Pure Python isn't very suitable for doing arithmetic with fixed sized unsigned ints. It's certainly possible, but the code tends to be a little cluttered.
I posted the core hash functions for a couple of non-crypto hashes here: chat.stackoverflow.com/transcript/6?m=43508804#43508804 And rambled on a little about avalanching, which measures how well a small change in the input data produces a big change in the hash value.
 
Well, I mean, I just want to go through the code to get a sense of what the algorithm is actually doing, so it doesn't really matter that Python isn't a very suitable language for it.
 
9:13 PM
@SebastianNielsen Understood. And that's basically why I wrote that code, so that people who know Python could read how the SHA-1 algorithm works. And to verify that I understood it properly myself. :)
 

« first day (3173 days earlier)      last day (1791 days later) »