« first day (3912 days earlier)      last day (1259 days later) » 
00:00 - 10:0010:00 - 23:00

00:11
@NordineLotfi Did it set off any bells? ;p
 
5 hours later…
05:22
Hi guys.
I came here some time ago asking for Python help for my game. I'll like to ask some few questions because I don't know how to proceed. I have made a Python downloader that downloads stuff from the internet for the game. First, we unpack the files in the games directory. These files include some code that was written in C++ and turned into a DLL. When the game starts, it checks if the files are there. If not, it calls the DLL and the DLL starts my auto-updater. The game files are then downloaded and unpacked and then the exe is started again. The person dealing with the C++ code has made som
 
2 hours later…
07:04
@holdenweb @Kevin memcmp could do this, but no popular implementation does. It's not worth the performance cost to speed up this pathological case. The reason you're seeing such extreme efficiency in string comparisons is because memcmp is stupidly fast. The gnulibc version in particular is wickedly optimized, dropping down to assembly for the inner loop so it can vectorize the character comparison using SIMD instructions.
@holdenweb Optimization is done for common cases, not uncommon ones. Introducing a possible branch misprediction at the start of a call to memcpy is... not an optimization.
For a discussion of that optimized memcmp that you couldn't find, see: stackoverflow.com/a/21106815
@Kevin Hmm... That implies you think that C, and especially C++, are extremely clean languages. :-)
@CodyGray I could accept that.
@Dave How are you "calling" a DLL? This does not make sense. DLLs are not meant to be executable.
@Dave But, the answer to your question seems to be that the C++ code should support a callback function that your Python code would call into whenever there is an update to the progress/percentage.
07:30
@Dave This sounds as if the DLL functions are executed in the same process as Python. So "just" add another DLL function that takes the download process. (Though I'm not entirely sure why C++ is needed for the downloading part – this seems to be the least suitable part of a game to optimise.)
07:46
The whole description makes very little sense to me. Either the description is hard to understand, or the design is bad.
Building an auto-updater for a Windows application is quite trivial.
cbg
guys does anybody know a way I have alot of data in which some symbols like "ñ" are in form as "España" and Qué is "Qu&eacute" how could I rectify all of this is there a library that will convert them
You might want to google "Mojibake".
is the data already like that, or is that only happening when you read it
Either way, figure out what encoding your data actually has.
because yeah, Miyagi nailed it, this is a common issue when you get the encodings wrong
07:52
@MisterMiyagi What's described isn't Mojibake....
so either you, or someone upstream when this data is being made, messed up on encodings
Those are just HTML-escaped.
Hmmm thanks I will have to try figure the encoding
@CodyGray how would you unescape them
ñ == ñ
With a look-up table designed for that purpose... the same way an HTML parser parses them.
hm, could try html.unescape then
07:54
311
Q: Decode HTML entities in Python string?

jkpI'm parsing some HTML with Beautiful Soup 3, but it contains HTML entities which Beautiful Soup 3 doesn't automatically decode for me: >>> from BeautifulSoup import BeautifulSoup >>> soup = BeautifulSoup("<p>&pound;682m</p>") >>> text = soup.find("p").string >>> print text &pound;682m How ca...

Yes.
Except it's deprecated. :-)
@CodyGray Right, thanks for clearing that up. I'll make another round to the coffee pot.
Thanks for that
that seems to work
Feel free to swat at me if we're not allowed to onebox...
youre fine!
Andras does the swatting around here.
07:55
besides, it might be amusing trying to see someone swat at ya :P
I would not have felt the need to give Andras explicit permission.
@CodyGray I'll let it slide just this once
Hmm. He came after saying his name only twice. I think something is broken.
only twice? more like it took more than once, AD is getting slow :P
08:03
The spirits just keep getting stronger. Old Bloody Mary was so hard of hearing, you had to call her name thirteen times.
Haha.
ha! i knew something amusing would happen with the swatting
I thought the link was either disabled or didn't even show up.
no, implementing something special would've been too much work
08:05
Also fun to try: kicking yourself.
I don't know if the UI displays the error message, or if you need to send a POST event.
you can do that on mobile
well, you can't
It tells you to take a long walk instead?
Why is it so ugly!
Which part do you mean?
08:09
The whole thing...
Your screen is like red with rage.
that's the twilight blue light filter
The entire thing is that same ugly color as deleted posts.
Oh. That applies to screenshots? That seems like a bug...
it looks fine when you're looking at the screen in a dimly lit room
@CodyGray probably, but I take screenshots once every supermoon
If I were posting a bug report it would be that enabling filtering for the notification screen makes the undisableable "battery is charging" screen glow red
Each time a perigee syzygy occurs? That's still three or four times per year.
... yes, exactly as often
08:14
Huh, interesting. I'm not nearly as periodic.
I wonder, does that count all of the screenshots taken accidentally?
Good point, those happen a lot more often
Google says that the blue light filter appearing on screenshots is a bug of the Samsung A50.
possible
Please dont crosspost fresh questions from the main site to this chatroom as per our room rules
A "confusion matrix"; how appropriate. :-)
08:26
@TonyBrand what Paritosh said
08:50
@AndrasDeak Ah yes, I vaguely recall talking to you about it before...unless this was about moderator kicking themselves? close enough :P
The UI isn't displayed for a mod to kick themselves. I haven't tried whether it works.
Style question is it good practice to use list comprehensions to apply function to each item on list if function returns a dict back? i.e.
[sort_data(content) for content in file]
or is it generally better to just doa normal for loop
@CodyGray sad that this will get deprecated (using 3.9 so I guess I'm safe for now :/). I'm aware I could do something similar like you mentioned (using a lookup table, etc) but the main problem I faced when trying to decode HTML entities was when: 1. there more than one layer of HTML entities. 2. some of those HTML entities are actually part of the content of the page (eg: in code/precode tag, etc)
what would you suggest? :)
A "lockup" table is something different :-)
Ah, yeah. No, I wouldn't roll-your-own.
meant lookup table, but yeah :D
what would you recommended then? :o
08:55
I actually think I may have misread the answer.
It looks like they're deprecating the function in a different package.
@CodyGray I see. either way, I'm still unsure how to handle the two case I mentioned...but I guess I'll figure out something at some point hmm
Where are you getting this input from? Is it actually HTML?
If it's HTML, then I think you just need to use an HTML parser.
yeah, it is HTML
@CodyGray any in mind? beside html2text of course (and beautifulsoup/lxml)
If it were just a string containing HTML-encoded entities, then I might say it's not worth the added complexity of an HTML parsing library. But if you have HTML, then it makes perfect sense. Anything else is going to be inherently less elegant and much buggier.
@Kwsswart very bad form
08:58
Ah, no. I can't make any specific recommendations. I've never used a Python library in my life.
1. comprehension with side-effects, 2. creating a list only to throw it away
@CodyGray yeah, true
I wouldn't even know what HTML parsing library to recommend in my native languages.
@AndrasDeak then is better to use map(func, list) or a normal for loop
?
@Kwsswart if the func mutates the input then not even map. Use a loop.
the map would be lazy so you'd still have to do something like list(map(func, lst)) and discard the result
09:00
@AndrasDeak ok I see and last question what if a function were to be made to use each value in the list to create a dictionary and then save the data to a jsonlines file, would it still be best to use a for loop?
@AndrasDeak Is that just your opinion, or is that normal Pythonic style to avoid a mapping function when it mutates the input? A lot of languages and people seem to prefer a "transform" or "map" function that applies a functor to an entire range, even when it's mutating.
@CodyGray Thanks for the reality check though, that's much appreciated :)
I personally find the normal for lop far more readable.
just curious as I am noticing so many way to do the same thing, but looking for whats the best practice
@Kwsswart you would call the function once using the whole list, would you not?
unless you explained the situation inaccurately
foo(lst_of_stuff) that creates a dict and exports it, right? No map needed.
@CodyGray not so sure about map, but sure about comprehensions. And semantically there's little difference between the map and a comprehension here, so I'd say probably normal pythonic style.
09:02
@Kwsswart Not entirely similar, but I recall having a similar situation where I wanted a dict but some function only returned a list as result...I learned that you could just use a list/dict comprehension since it take less code (although not sure if it's faster per se)
@AndrasDeak you would call the function using each element of said list as the param so if you have 10 items it would call 10times
@Kwsswart why?
Don't you want to end up with a single dict?
So. Many. SO. Questions. about converting a list to a dict...
I'm sure they're all unique and beautiful.
No because each item would open to separate link and within that link collecting different information, normally just use for loops to do it and works
09:04
@Kwsswart that doesn't answer my question
but "normally just use for loops and it works" sounds like the outcome of this discussion ;)
without at least a half-MCVE I have no idea what you're really talking about so I can only speak in general terms
Lol essentially the list is seeds, that I use to open and then with the information within that seed i create a dict and save it to jsonlines essentially each seed is different register lol
Seeds? Like the kind you use for growing plants?
@AndrasDeak probably lol just sort of a general question in hwat is the best practice when wanting to use each element in a list as a param to a function
@Kwsswart you said "what if a function were to be made to use each value in the list to create a dictionary and then save the data to a jsonlines file". Now it seems that one function uses one value to create a dict.
@Kwsswart you're again being ambiguous
"each element in a list as a param to a function" sounds like foo(*lst_of_things)
@Kwsswart hold on, I missed the "returns a dict back" part
you never reflected on my "if it mutates" comments, which are crucial
If I don't want to run an entire module when I import it, where do I place: if __name__ == "__main__":?
09:09
If you want the actual return value from the functions, both the list comp and the map will be fine. But then why do you ignore half my messages explaining why this is bad for something that's not what you're doing?
Does it even make sense to place it before the imports?
Not my intention to be ambiguous :/ essentially have a list of urls that I am opening and collecting the data and saving it.... the question is is it best to use dpaste.com/4JHUB9VD3
@Pherdindy bottom
@Pherdindy no
@Pherdindy I seen some codebase placing it at the bottom sometimes, although I'm unsure why anyone would do that
@AndrasDeak thanks so usually it is placed above most of the code, but below the imports?
09:10
@Pherdindy no, bottom
aaaalll the way at the bottom
I see, that explain why then; Thanks for the indirect answer :P
(I always wondered why too so I guess this is good timing)
anything else in the module global namespace should be function/class definitions and constants, or things that should run anyway before the __main__ part kicks in
if there's code in the global namespace that should run after the __main__ guard then your're probably doing something wrong
but what does that actually do? I mean does it really serve any purpose if you don't plan on using your script/program as import somewhere?
@NordineLotfi no, but it's good form anyway if you might end up importing it
@AndrasDeak I see I get what you mean by bottom now. So I have to make sure the variables do not have the same name with other modules
09:12
@AndrasDeak I see; fair enough :)
if you're only running the script then it's unnecessary
@Pherdindy not sure what you mean... and I'm too scared to ask for examples
@Kwsswart so again, your dpaste has 1. "sort" function calls, which normally do in-place things in python, and 2. you're not doing anything with the return value of the functions, which is in line with in-place things. Now make a decisive claim before saying anything else: does your function return something new, or does it mutate the input and return None?
Is it placed at the bottom because that way it is never executed, the parser still sees it?
That seems logical.
If I have a variable called path_string in the current module and I import a module with a variable also called path_string
@CodyGray it's always executed when the script is being run directly by python, as opposed to the module being imported
@AndrasDeak returns a dict of new information
09:15
@AndrasDeak So, if it's always executed, why does it matter if it goes at the bottom or elsewhere? I'm sorta confused.
execution happens from the top down as you'd expect, so the guard would be executed last. But normally this is the only thing being "run" as a script, everything else are imports and definitions normally
@Pherdindy Namespaces.
@CodyGray because you'd be looking for it at the bottom
you put things where they belong
Oh, I see.
I like to have all of my imports/usings/etc. at the top. But that's just me. In non-Python languages.
and the if it needs will be logic in the module global scope, of which there's very few normally
it just sticks out like a sore thumb if you don't put it at the bottom
09:16
I guess the parser/interpreter will run things from top to bottom, so it'll probably get there at some point...
@CodyGray those are at the top
what we're talking about is basically a call to main()
(when there's a main() which is not very often)
Oh, so like a call to the module's initialization function?
Wow, Python can't call that for you automagically? :-)
to run anything in the module
ugh, let me write up a small example
@CodyGray isn't that the same for other compiled langs? eg: C. I recall there some steps to take prior to using your code as header/import/libraries afaik
def hello(target):
    """Say hello to my little target."""
    print(f'Hello, {target}.')

if __name__ == "__main__":
    hello('world')
Python modules are very often imported. You don't want to put hello('world') in the global namespace, because importing this module would run that too.
So you put imports and definitions and "constants" in the module scope, but things get actually get executed goes in a __main__ guard.
09:19
@NordineLotfi Uhh... Yeah. In certain cases where a library needs to be initialized first, then it'll export an initialization function that you must call from your application's code. But C doesn't do anything for you "automagically".
If you have another module you can do from hello_module import hello; hello('potato') without getting a 'hello world' print. While still being able to do python hello_module.py.
@CodyGray right, so I guess it's similar in that (specific) spirit to Python :D Interesting
Oh, I've seen this extreme ugliness before.
Stringly-typed main functions. What'll they think of next?
Is it a common thing to actually have multiple imports to the same package between modules?
For instance I do import pandas in the current module
But then I have a module that I created before that also has import pandas
I know it is not a big deal but do people take note of that lol
That sounds like something that would be quite common.
09:21
@Pherdindy How would you use pandas without importing it?
@CodyGray I guess that's the designer's take on "simple" being applied here, but maybe they have different reasons beside that
Isn't standard practice to make each module fully self-contained? That means you'd have to import a module if you were going to use it.
I mean if I import my own module that already imported pandas
Is it better to remove it in the current module
@NordineLotfi Yes, and it's spelled "hack".
@Pherdindy of course not
always import the modules you need directly
If this helps you sleep: each module is imported only once, everything else during an interpreter session is a dict lookup
09:22
@CodyGray that pretty much sum up plenty of codebase/project in the Python ecosystem haha (not that it's always a bad thing per se, it kinda depends)
if import pandas takes 15 seconds then the second import pandas is "instantaneous" (in python time scales)
Ohh I see makes sense
@AndrasDeak everything else during an interpreter session is a dict lookup that's news to me. Guess I'll be able to sleep better at night now
@AndrasDeak 15 seconds? Holy...
I only had the need to use if __name__ == "__main__": now since i'm making a GUI
09:23
@NordineLotfi Specifically, sys.modules
@CodyGray never seen that actually
And importing the modules without it will run the module automatically as you say
@AndrasDeak Just wanted to give me that heart attack. I see.
@Pherdindy indeed
@CodyGray did it work?
Nah, I just shook my head in disbelief.
"Sounds about right", I muttered.
better luck next time!
09:25
So when importing modules, I have to make sure I do not have variables between modules that have the same name right?
Takes a while to wake up sleeping pandas.
And they usually want to be fed first, before they start working, so you have to find some bamboo...
Like when path_string = "C:\Desktop" for module1 and path_string = "C:\Desktop\Folder" for module2
It can possibly mess things up?
@Kwsswart sorry, I missed this message in the flurry. If it returns a new dict then you should use the map or the list comp.
@Pherdindy no, if you import correctly
i.e. don't do from module import * and you'll be fine
> Namespaces are one honking great idea -- let's do more of those!
@Pherdindy but using backslashes in a path without using raw string literals will mess you up one day
I see i'll probably take a look at the topic again
@AndrasDeak wouldn't they need a dict comprehension since they wanted a dict out of one of the list result (afaik)? although I guess they both support similar syntax anyway
09:27
Right lol I usually use r or fr when dealing with path strings
@Pherdindy prefer import module2 as mod; mod.do_thing() or from module2 import name1, name2, only import what you need.
Just use forward slashes in your paths. They work cross-platform.
@NordineLotfi no, the result is a list of dicts
@CodyGray yup
@AndrasDeak oh I see. Thanks for the heads up
for a dict comp you need keys which aren't there
09:28
> Flat is better than nested.
indeed
@CodyGray even for functions?
@NordineLotfi just ignore him
Don't @ me, I didn't make up these rules!
09:29
that's mostly about indentation and scoping :P
What?
Really?
I was mostly asking because I questioned the use of nested functions in the same class
it specifically doesn't apply to namespaces
(that was yesterday though)
Nested functions are an anti-pattern for sure, if you ask me.
09:30
@NordineLotfi yes, nested functions, nested classes, nested comprehensions etc. are best avoided
global bucket of names should also be avoided
There are uses for nested classes in languages that have actual scoping rules and access restrictions.
python has some scoping rules for classes... but you wouldn't like it :D
nobody does
Maybe I would like it, then?
doubt it, it's silly
@AndrasDeak even in this specific case?
09:31
see "Name resolution ignores class scope" at sopython.com/wiki/Common_Gotchas_In_Python
My issue is if I have an imported module with path_string = "C:\Desktop" variable before if __name__ == "__main__": and below if __name__ == "__main__": uses the path_string. If the module that imported it has path_string = "C:\Desktop\Folder" before I call the imported module, then it will mess things up right?
@NordineLotfi depends. It's usually a coin toss for me. If I have a helper function I usually put it in the global namespace (after all it might be helpful elsewhere). The main exception for me are things like interpolating or fitting functions that are used in a call to scipy.optimize.curve_fit and friends. Those are lambdas or nested functions defined right above. But this is pretty subjective. And it rarely comes up in your code. Do what you think is most readable.
@Pherdindy what would it mess up and how?
@NordineLotfi Nested functions seem to have nothing whatsoever to do with limiting the scope of your variables. In fact, passing the variables as arguments to a function is even cleaner than having a nested function automatically inherit all variables above it.
Can you put together a 15-line dpaste with two example modules to show what you have in mind?
@CodyGray I thought closures were cool
The imported module would be using the wrong path string. But I suppose that means I probably didn't structure the modules well
09:34
@Pherdindy why would it be?
@AndrasDeak I confess I don't know the difference between closures and lambdas. Is there a difference?
@AndrasDeak Thanks, very insightful
import module2 won't magically overwrite your path_string unless you do from module2 import *. When you do import module2 you get module2.path_string. Hence namespaces being great.
@CodyGray yeah, that's what I usually do myself :D that's also why I was questioning it earlier yesterday
@CodyGray what's a lambda?
09:36
@AndrasDeak You literally just used the term "lambda" in your message a few lines above. How can you not know what it is?
@AndrasDeak I see that makes sense I always thought it was just plain path_string which would make it a pain to coordinate between modules.
@CodyGray I think they're asking you so that you will notice for yourself what it is? At least I wouldn't be surprised if that was the reason this was asked (unless I'm wrong)
My admittedly rudimentary understanding is that closures refer to the mechanics of binding values (names) in an enclosing scope. Lambdas (and regular functions) display this behaviour. A lambda is a callable (a function), a closure is a concept.
I don't think Andras is much of a Socrates. But, I, too, could be wrong.
@Pherdindy that's why I asked for a specific example. I can't tell how confused you are, and having something concrete helps. Heck, if you put together an example you'd see yourself that names don't pop out of nowhere.
09:37
If he wants to play that game, I'll happily start giving correct but irrelevant answers. Like: "it's an emerging variant of SARS-CoV-2, also known as lineage C.37".
@CodyGray with noobs I often am
@AndrasDeak AH! that explain why you were going that way with me when I first met you here...
but at least, this gave me the push I needed, so I didn't really mind anyway
@AndrasDeak right lol I get it now time to get the button of the gui linked
@CodyGray since you're here, I thought I'd ask: do you perhaps know/used ncurse/curse libraries before?
Is that because you assume the noobs don't know where the hemlock is?
@NordineLotfi I know ncurses quite well, and I've used many things that use it. But I've never personally written an application using it.
09:41
Cody's not the type to curse
he's a gentleman of sorts
That's...wrong.
@CodyGray I see :o I'm trying to write my own clone of less(1) in python. Right now got a modified text editor in curse working as text viewer, so it kinda work fine. Wanted to ask some stuff about curse which is why I asked :D
Is it not "curses"?
People call pandas "panda" and that also gets under my skin
09:42
@AndrasDeak yeah, I just forget about the s sometimes
@AndrasDeak Recently, I've been seeing/hearing a lot of people call it "Window" instead of "Windows". That is really getting my goat.
import panda's
grocer's apostrophe, nice
Appropriately, Eats, Shoots & Leaves has a panda on its cover.
09:44
pretty sure someone would have tried importing it that way
@NordineLotfi Gotta say I've never really found a use for the actual *nix tool less, so a Python clone of it seems even less useful. But OK.
@CodyGray LOL, I see what you did there. Honestly, I made this for a lot of reasons, but one of them was that when I searched for a Python clone of coreutils and moreutils, none of them were implementing less(1) so...and if you're a long time Linux user like me, you would know just how much less(1) can be useful at times :P
barely?
I use it to read logs which... is not a lot of things
I use it for other things myself, although I admit those "other things" still consist of..reading/viewing text
but still
the real question is why you'd reimplement it in python, but people always reimplement everything for no reason so I haven't asked this yet
09:49
as said, there lot of reasons so trying to explain them here probably won't be the right place/time :P
oh yeah, all the reasons
I guess I should make a readme or something
carry on
popcorn cbg... don't mind me, just keep in talking folks...
09:50
How's your case insensitiviser doing, Miyagi?
Works fine. Locked it up in the basement with all the other frankenmodules I've made over the years.
Publishing it properly would be a bit insensitive, I guess.
I just don't see how it's any better than opening a text editor to read stuff, and scrolling with Page Up/Down.
If said text editor were Visual Studio, then yeah. I could read an entire document in the time it takes the behemoth to start up.
But when the text editor is probably just Nano or Vi... No point.
The way I see it, less is just a way to avoid an emacs vs vim fight.
Specifically for logs I prefer less over vim because the cursor being able to move in the screen is just an unnecessary degree of freedom. And page down is for the weak.
@MisterMiyagi Except it secretly concedes the fight to vim, because it uses the same keybindings. Doh.
09:53
I don't know; less (GNU) has certain problem itself, especially if you use it a lots
I want to be able to downarrow to go down one line and then uparrow to go up one line. Vim can't do that.
@NordineLotfi You should use it less.
@CodyGray Works as intended. ;)
one example is, when you use it with a syntax highlighting like pygment, it will lag horribly even on small codebase (60-100 LOC) but if it's implemented in python, it wouldn't be too slow depending on how it's made
@CodyGray It's harder than it sounds for me I'm afraid
Less with syntax highlighting?
you really should just use vim
09:55
What the heck.
I know, you used "everything" and they didn't work
yes, I did said I was using less more than you think I was
The version of less implemented in C is too laggy, so you think you're going to speed it up by writing it in Python? Am I reading this correctly?
and I'm not the only one who use less with syntax highlighting btw (ask on UL)
@NordineLotfi you know how billions of flies eat poop? Well... ;)
09:56
@CodyGray as said, it depend on how it's made/managed. I can't deny it won't be as fast as the C version (I'm an advocate of speed myself) but...when it works, it works
@AndrasDeak A good way to solve that problem is to use nano.
But sure, if you use less in ways it was never intended then I understand you want to change it
@CodyGray nah, no
@AndrasDeak I don't know; I guess it's hard to contemplate on when you never used it extensively like I did :) At the end of the day, it's just a tool so It's probably fine
yeah, this is definitely "you do you" territory
@CodyGray nano and vim don't really have huge file support, even if you disable all the bells and whistle (only editor I know that truly has that support is Joe's editor)
less does too but it doesn't edit text
(for now)
09:58
define "huge"
more than 100GB
Now explain why anyone would have a file that size.
@CodyGray ssssh
just let him do it
who knows; just look around on some UL post where people need to edit a specific thing on a specific file that has that size
between four walls
09:59
I can't deny I wanted to do that myself, but, I guess it depends
Maybe you should sit down for this...
@NordineLotfi it wont even be close, btw, just keep that in mind. C will destroy python in terms of speed.
There are lots of people on the Internet with wrong ideas.
00:00 - 10:0010:00 - 23:00

« first day (3912 days earlier)      last day (1259 days later) »