« first day (4004 days earlier)      last day (947 days later) » 

1:26 AM
cbg guys
 
1:54 AM
Does anyone have a link to the documentation on naming rules/conventions for identifiers in python (i..e, ascii + dollar, no leading digit, no spaces etc etc)? Quick google search turns up nothing
ascii+underscore*
 
close but not quite ... i'm looking for something similar to the guidance described in the "variables" section in this doc: https://www.pluralsight.com/guides/python-basics-variables-assignment

but ... more official
 
@cs95 Here is the PEP guildelines on naming conventions python.org/dev/peps/pep-0008/#naming-conventions which i think comes closer to that
 
Hmm, style is one thing, syntax is another. I'm trying to explain why {**mydict, 'new_key': new_val} is more flexible than dict(mydict, new_key=new_val) for somebody trying to add a new key to a dictionary without modifying the existing dictionary (python >= 3.5), and that hinges on me explaining that keyword assignment is limited by the syntax rules of variables/identifiers
 
2:23 AM
perhaps documentation on args and kwargs could help? (w3schools.com/python/…) and (geeksforgeeks.org/args-kwargs-python)
 
uh oh, w3schools link detected
3
It's been so long, I can swear this is in one of my older answers
thanks for the help folks
@MatthewBarlowe scratch that, I think this is the most authoritative source you'll find on the topic. Thanks a bunch!
 
 
1 hour later…
3:43 AM
    import asyncio

    async def count():
        await asyncio.sleep(1)
        print('1')
        await asyncio.sleep(1)
        print('2')
        await asyncio.sleep(1)
        print('3')


    async def main():
        task1 = asyncio.create_task(count())
        await asyncio.sleep(3)
        await task1


    t = time.perf_counter()
    asyncio.run(main())
    t2 = time.perf_counter()
    print(f'Total time elapsed: {t2-t} seconds\n')
Can someone explain what await task1 does? If i comment it out, the program still takes 3s to run, the only difference is 3 is not printed
 
 
2 hours later…
5:23 AM
Hi am i allowed to ask a question in the chat room ?
 
6:14 AM
@astralwolf with await task1 you wait for task1 to return (=run until the end)
 
6:27 AM
@Fahad yeah but it would be better if it's a small question
it should be a small question
 
More importantly it should be in accordance with the rules sopython.com/chatroom
 
yeah
 
7:11 AM
@roganjosh You might like this. "The Skinhead Hamlet is a short 1981 parody of the play Hamlet by Richard Curtis, a co-author of Blackadder". Warning: extremely NSFW.
 
I'm sure Shakespeare would be proud :P
 
@S.Chauhan We aren't fans of w3schools in this room. See chat.stackoverflow.com/search?q=w3schools&room=6
@roganjosh Probably. ;) Shakespeare wrote & performed for everyone, both low class and high class.
 
As long as most of the characters end up dead, it's a success. That's about all I remember from having to study his plays
Also, that w3schools search has made me laugh. Gosh, we really do rail against them (rightly so, but no punches held in this case)
 
He did write comedies too, but yeah, there's a high body count in his dramas.
 
7:27 AM
I'm not a well-read person so my judgement of non-technical literature can't be taken seriously, but I do feel like he should be sued for false advertisement with the term "comedies"
 
IMHO, w3schools deserve no mercy because they intentionally mislead people into thinking that they're connected with the W3C. That's slimy.
@roganjosh Well, they're light-hearted. But I guess the meaning of "comedy" has mutated a bit over the centuries. And also what's considered humorous changes too.
 
I think you'll know that I wasn't being very serious there :P
@toonarmycaptain I didn't really trust any of the links I could find about this (granted it was late and the search frivolous so I didn't put in much effort). I might re-visit it, though, given that it seemingly didn't really happen but got a lot of media attention
 
@roganjosh Sure. Still, tastes in comedy vary a lot, and are strongly connected with culture values. It's interesting to see which British comedies do well in the USA, and which ones just don't translate. I was kind of surprised that Monty Python was successful in America.
 
7:44 AM
I've kinda given up trying to understand that. Shameless, for example, is a show very close to my heart as it's set in Stretford, which neighbours where I grew up. The US then took that, started with the same script for the first episode and then spun it out into something I found insufferable to watch. Not that the later UK seasons were good TV, but the first series is amazing
 
I wonder if kids today would appreciate Norman Wisdom, eg The Early Bird. It's not a brilliant movie, but it is fun, and the opening ten minutes, with virtually no dialogue, is physical comedy at its finest, IMHO.
 
 
2 hours later…
10:11 AM
I am trying to save a (an order preserved) list in python identified by respective keys.
i tried to use shelve, but i fear entire shelve data gets loaded into memory, while trying to fetch via key. what datastore (else) should i look out for ?
 
sqlite3 is a pretty good compromise between features and dependencies IMO.
For smaller cases, just dumping a pickle/json/… per key can work well too.
 
yeah, i did use json-load and json-dump; but i fear the runtime costs
in sqlite3
 
wut?
JSON takes longer than sqlite
 
If you are worried about runtime costs, why are you writing out the data in the first place?
 
They're going to be disk reads, but for JSON you'd need streaming (which, surprising is supported by a library that Aran posted - I can dig it out) but sqlite will allow querying
 
10:18 AM
so i should stick with sqlite3 based unorthodox implemenation of list object retrieval ?
 
I don't know what you're asking at this point
 
i have like many key-value stores; key being unique strings; value being lists
i would like to fetch the same,
 
So that's a one-to-many storage, and that's perfectly fine
Don't store the list as a list, though. Give each value its own row
 
like relational mapping and disintegrating list to individual strings ?
 
I'm not sure I follow "disintegrating" but you can have 1 table of the key with a primary key, and then use that primary key to the values in another table. This depends on the DB tech you're using (it's a bit futile with Redshift)
Or use some NoSQL solution like redis
 
10:29 AM
thankyou, i will check that and update
@roganjosh sorry i am not that familiar with nomenclature of programming operations, so i use made up terms, sometimes people find it odd
 
I do that too on occasion, but you do need to be careful when you do use any programming terms that have definite meanings because it can send other people off on tangents. That said I think I have a grip on what you want to do
I'm gonna bring this point back up:
18 mins ago, by MisterMiyagi
If you are worried about runtime costs, why are you writing out the data in the first place?
Are you looking for hot storage?
 
@roganjosh i am building a database in a one time operation, and would like to deploy the same in an application that reads from it often, so i was concerned about cost if i had to convert json-objject to list object evertime i fetched.
read only database containing key and value as lists ready to be loaded into the application
 
Just to be clear: Are you worrying about an actual observed performance issue, or a hypothetical suspected performance issue?
 
You almost certainly shouldn't be storing JSON in the DB in the first place
 
i am very careful not to prematurely optimize but converting a value post fetching from a sqlite3 record seemed to me little wrong
 
10:42 AM
I am now totally lost
 
sorry
 
Are you parsing a sqlite response back into JSON?
 
no no, i want to have a list when a key is called up
that is my problem statement
 
Right, ok, I'm back on track. "i am very careful not to prematurely optimize but converting a value post fetching from a sqlite3 record seemed to me little wrong
" well, yeah, it could probably be improved by `redis` as I suggested earlier
Otherwise use Sqlite as suggested by MM, with two tables and an index that you can use as a foreign key. But that's not in-memory and I'm coming back to the idea that you are actually trying to prematurely optimise
 
thanks, i will try out the two ideas suggested.
 
10:48 AM
Just fix it with caching! *advice may be outdated due to caching*
 
boo hiss. You realise that I've stuck my neck out on your suggestion? :P It's on you if this blows up their computer!
 
Is there a shortcut in vs code that allows highlighting and/or switch between arguments?
 
@roganjosh Wait, all my DB advice is just parroting what was said before in rooms/6. :P
 
@MisterMiyagi and you know what happened to the parrot, right? (wait, I only know that curiosity kills the cat. Our idioms have space for something parrot-themed)
 
@roganjosh From experience, I would assume the cat killed the parrot. Then played dead to guilt-trip everyone else.
 
10:56 AM
Schrödinger'd
<Imagining Physics blood boiling for my poor attribution>
 
 
5 hours later…
3:36 PM
huh, didnt know there is yet another maintenance
 
3:47 PM
(read right-to-left)
 
3:59 PM
"All of SE will be in read-only mode" *enters chat* Just knew it!
 
 
1 hour later…
5:06 PM
How can I open a html file with default browser by python stript?
 
Anyone knows pandas?
 
webbrowser.open() opens up internet explorer, not the default browser
 
@NeelRayal if you have a question, it's better just to ask, as long as it follows the room rules. Quite a few of us use pandas
 
@NeelRayal The dalmatians of the bear world?
 
@WalidSiddik what is it that you're building that needs to launch a web browser?
 
5:12 PM
cols = ['+', 'ε', '*', '(', ')', 'z', '$']
rows = ['E', 'X', 'T', 'Y', 'F']

df = pd.DataFrame(np.random.randint(0,10, size=(len(rows),len(cols))),
index= rows, columns= cols)
print(df [ ['E', '+'] ] )
Key not in index error
I am trying to build a LL(1) parse table and for some reason I get this key not in index error. I searched SO but to no avail.
 
Just realised that a new laptop means I've lost all my virtualenvs :/ We can rebuild
 
@NeelRayal I think df['+']['E'] does what you want?
 
@roganjosh Just a personal project, I'm making a program that can write HTML and CSS, It would be able to make web pages by configurations given, though it's steal in early stage
It would make a HTML file
so it would be great if the page opens up immediately on browser
 
@Aran-Fey It worked. But I had set index as rows. So how did the rows and cols got exchanged?
 
They didn't? df[x] style indexing always returns a column, so then df[x][y] returns a specific value from that column
You can use df.loc[y][x] instead if you prefer
(How many pandas pros are cringing at my bad advice in the background? Show of hands please)
 
5:24 PM
@Aran-Fey Thanks
 
@Aran-Fey Not sure I could call myself a pro, but I don't see any problems with what you said
 
Close enough for me, I'll consider that a win
 
In fact, I'm impressed you chose to bite on a pandas question :P I've just now got my venv set up but I missed the party
 
I have a sort of passing interested in pandas, so sometimes when an easy question comes along I try my hand at it
 
The one good thing about this new laptop is that it isn't bogged down with my hopeless misunderstanding of macOS and having 5 different python installations. I've detoxed my life
 
5:31 PM
@Aran-Fey actually, you'd probably want to use df.loc[x, y] which is both probably faster and more readable
(or who knows, perhaps two simpler getitem calls end up being faster)
 
Figured there had to be a way to do this with one less pair of braces, thanks
 
it's also safer from a "setting a copy with a view" warning point
 
...is it technically "one fewer"? That sounds wrong
 
it is one fewer, yes
"One pair fewer" might sound better?
 
A bit
 
5:35 PM
df.loc['E']['+'] = 20
print(df)
No "setting a copy..." error
 
not in this case
if the indices are sequences then it might happen I think
"safer" as in "better practice"
bites you in the butt fewer (:P) times
 
I do agree that the syntax with them combined is cleaner, though. But I never pay attention to that warning; it's never been right in my case (I'm perhaps being a little naive and maybe I have been bitten) so I almost always disable it
 
Disable what?
 
pd.options.mode.chained_assignment = None gets rid of the "setting with copy" warning
 
😬
df[['+', '*']][['E', 'T']] = 20  # this warns
 
5:40 PM
I can't think when I've ever used pandas like that
 
you shouldn't, but then you shouldn't see the warning :P
I've definitely been bitten by setting values on a copy (in numpy), so I would bend over backwards to make that helpful warning go away without silencing it
(I've also been bitten by setting values on views...)
 
I should have been clearer sorry; I don't open a script and paste pd.options.mode.chained_assignment = None by default, which I sometimes do with e.g. pd.set_option('display.max_columns', 500), but it definitely is incorrect as a warning in some of my cases so I get rid of it
Or, I'm a terrible person and the warning is still correct but working by fluke
 
*whistles nonchalantly*
I don't know how that warning works, so I can't judge if and how often it can produce false positives.
I mean I'm not even a pandas user, let alone a pandas pro. I'm just here for the popcorn :P
 
My exploration of that warning went as far as finding out how to shut it up on something I was doing in a loop where it was wrong (at least in as far as - the code was doing exactly what I wanted and was stable)
That's also not to say that I don't understand the premise of it, but I mean that I didn't dig into the code to know about false positives
 
6:27 PM
Actually, I've just confirmed that silencing that error bleeds through with importing my package. I definitely shouldn't be doing that.
 
 
2 hours later…
7:59 PM
You can set what browser you want `webbrowser` to use like so
```
>>> import webbrowser
>>> browser = webbrowser.get(using='firefox')
>>> browser.open('file.html')
```
More info can be found here docs.python.org/3/library/webbrowser.html
 
Those docs suggest that it will always prefer the default browser. It seems like the system default isn't what they expect instead?
firefox, for example, would probably fail on my system because I don't have it installed
 
yes i would assume that whatever browser the OP wanted to use they would have installed
But if they feel that a certain browser should be the default and isn't then its probably easier/quicker to just specify the browser they want in the python script itself
 

« first day (4004 days earlier)      last day (947 days later) »