« first day (3745 days earlier)      last day (1186 days later) » 

1:50 AM
cbg all, is it ok to link my python question from code review here? it is almost 48 hours old, I have zero votes and only 22 views there
 
 
8 hours later…
9:33 AM
@roganjosh The docs are feeble on pagination.
 
My best guess from the codebase is that the full query is executed, all results are gathered and then it just yields particular pages to the front end. So I guess the whole result is in memory and it doesn't make any use of LIMIT and OFFSET. Then again, maybe the ORM is being invoked somewhere and I'm just not seeing it
 
 
1 hour later…
11:08 AM
Hey guys anybody here have experience using the Apache Tika library with Python?
 
I'm afraid not. But, how did you find your first interview @Kwsswart?
 
@roganjosh Good man they contacted me for second interview on Monday and asked me to look up a bit about the technologies they are using so busy playing with a few of them to get an idea about them ^^
 
Ah, nice work! :)
 
Thanks ^^ Still quite a process to go through but just going to do my best ^^
 
I've spent some time going through Dash this morning; it's a good job I had to cancel the presentation I was supposed to do last year - I don't really understand how this is apparently easier than just using Flask to only get a subset of functionality... At least this time I have until April to put the presentation together now
Not least because their layout manager is a premium product so if you don't want graphs just dumped all over the page, you're gonna need the Bootstrap library and start using bootstrap via Python. Kinda begs the question of "why not just use Bootstrap?", at least to me
 
12:00 PM
@grumpyp Hello. Please see our room rules. Particularly in regards to posting questions on main and linking here; you should wait at least 48 hours before doing that, if you haven't got a satisfactory answer
 
12:14 PM
Without a python tag it's probably only a matter of time until those 48 hours pass
 
Edited. @grumpyp please make sure that you include the parent tag to questions. That's way more important than saying the specific version of Python and lots more people will be watching the parent tag. Python 2 is obsolete and unsupported now so there's little need to make the distinction of 3.x
Ultimately it's your choice, of course. It doesn't impact anyone else's life on SO, it just alters your chances of getting something answered
 
Hey @roganjosh thanks for your information and many apologize for the breaking of the rules. I got it for the future. Also the hint with the tag, thanks!

Have a good one!
 
No problem. And the same to you :)
 
1:25 PM
@roganjosh I don't believe Django keeps record sets in the session - rather it probably relies on repeating prepared queries with different parameters for each page.
I'm presuming without evidence that OFFSET and LIMIT can be parameterised.
 
1:38 PM
I suspect so, but I couldn't see the pagninator object calling in to anything associated with queries. It at least appeared it was a complete queryset
 
 
1 hour later…
2:57 PM
parametrising offset/limit is of course the wrong approach :(
if the resultset is large
 
3:27 PM
Yes
 
 
3 hours later…
6:20 PM
Looking for some help with regex. I have a large string in which I'd like to replace Damayanti and Damayanti's with \\texttt{Damayanti} and \\texttt{Damayanti's} respectively. However, if the string is already in the format \\texttt{Damayanti}, it shouldn't be modified.
MWE: x = "Damayanti Damayanti's \\texttt{Damayanti}"
In [28]: re.sub(r"\b(Damayanti['s])", r"\\texttt{\1}", x)
Out[28]: "Damayanti \\texttt{Damayanti'}s \\texttt{Damayanti}"
 
Read up on lookarounds
also ['s] is wrong
Hmm, now that I think about it, that's actually surprisingly tricky to do correctly. But the easy solution with two lookarounds will probably also work well enough
 
Ok. Thanks @Aran-Fey. On a related note, I was expecting this regex to replace the first occurrence of Damayanti in the string, but it didn't. Can you explain what's wrong with the regex?

In [33]: re.sub(r"([^{]Damayanti)", r"\\texttt{\1}", x)
Out[33]: "Damayanti\\texttt{ Damayanti}'s \\texttt{Damayanti}"
 
it's because of the ['s] part
 
The character { is explicitly excluded in the pattern and I was hoping it should match "Damayanti"
 
@linuxfan please see our formatting guide for code. It will make it much easier for relevant people to read
 
6:32 PM
Is anyone online?
I want to discuss about modules/packages in Python
 
@linuxfan Yes, { is excluded, but [^{] still only matches if a character other than { is there. So if your string starts with "Damayanti", then [^{]Damayanti can't match there.
Which is why you need lookarounds, not negated character sets
 
@Aran-Fey Ack
 
@sanjarcode if you have a question then it's better to just ask and people will respond if they know the answer and/or feel able to help
 
okay @roganjosh. I wasted two days understanding modules and packages in Python.
My question is: It's just a convention that absolute imports must start from the root folder, which is added to sys.path by PyCharm, isn't it.
I'm asking this because it doesn't work on the terminal, I mean how the hell will python know which directory is the 'root'?

Two questions.
 
6:40 PM
@linuxfan the easiest way to do this is to use a substitution function ^.
then you can have any arbitrary patterns that you pass as-is, for example \\textt*{Damayanti(?:'s)?}|(Damayanti(?:'s))
 
> A quantifier following a lookaround serves no purpose, and can safely be removed from the regular expression
 
then in the function you'll see that if group 1 was matched you wrap, otherwise you return it as is.
 
But I have a capture group in my lookaround, yammit! It has a purpose!
 
you can't capture lookarounds
 
It's a pain to see that so many tutorials online talk of using root as if it's a python requirement, and never mention that it's only a convention. They should teacg is as if you were coding in the terminal, because that is the way apps are started.
 
6:43 PM
they're so-called "zero-width assertions" i.e. they contribute no captures.
@sanjarcode no it is not a convention - at all.
on the contrary.
instead you'd install the python library and the imports would be rooted wherever that is...
 
@AnttiHaapala What's this, then?
>>> re.match(r'(?=(a))', 'a').group(1)
'a'
 
or if all else fails, then you'd modify sys.path
@Aran-Fey hmm :P
so check group 0
 
@AnttiHaapala could you explain more?
I'm in Vscode and it doesn't work. Moreover I found that PyCharm does inject the root folder into sys.path.
 
@Aran-Fey I was thinking on the other side...
vscode = rubbish.
@sanjarcode what it is that you're doing?
 
I was writing a bot
 
6:46 PM
how I do stuff is often I have a virtual environment with all the necessary libraries...
and whatever I am writing is installed into the virtual env with pip install -e as an installable package.
it will automatically do the sys.path thing right...
 
I actually can't think of a way to do this with pure regex... crazy
 
@Aran-Fey I did ^
it is easy to put it in as a pure regex...
it is not easy to use .sub with string replacement.
 
If your sub call requires a python function then it's not pure regex :|
 
wat
of course it is
regular expressions are regular.
this is a most regular expression.
lookaheads/lookbehinds are irregular
 
Okay, I get it now, the top-level script's directory is the root, and it automatically changes name of every module that runs. So this will work irrespective of the editor. Is this correct?
i meant __ name __
* runs inside
 
6:53 PM
If using a substitution function is allowed in "pure regex" then everything can be done in pure regex because you can just do re.sub('', lambda m: <code goes here>, text) :|
 
I'm new to python, actually. I'm surprised that Python chose not to interact with the FileSystem unless explicitly told to do so.
 
@sanjarcode I really don't know what that means
 
@sanjarcode Python will generally do very few things unless you tell it to.
 
Why should software implicitly read files?
 
@Aran-Fey and??
 
6:57 PM
That makes your definition of "pure regex" meaningless
 
@Aran-Fey \\textt*{Damayanti(?:'s)?}|(Damayanti(?:'s)) is a pure regex
substitutions do not have anything to do with regular expressions
 
Sure they do, they support backreferences
 
backreferences are not of pure regexes
pure regexes describe regular languages and backreferences can describe non-regular languages too
 
I mean it could have just added sys.append('.') when . was done and sys.append('..') for .., we wouldn't have to worry about what the top-level script is.
 
7:01 PM
What I mean by "pure regex" is "only regex features are used, no python code". Not "only regular languages can be parsed"
 
@sanjarcode It could also have guessed that when copying two files I intended for their inode mapping to be retained. For some reason, it does not.
By the way, sys.append'ing top-level paths will majorly screw up your modules.
It means that modules can exist with multiple names, each a separate instance with separate members.
 
@Aran-Fey .sub is not related to regular expressions.
it has nothing to do with them. It is just some stuff lifted from sed :P
 
That's the itch I have, Java is very good in this regard.

@MisterMiyagi, I know we should't pollute sys.path. But python could be smart, it can figure out if the module exists. And if it does add it.
 
It's literally wrong to do so.
 
I know
 
7:04 PM
If you have code that does it, it will bite you in the buttocks one day.
 
the thing why regular vs "non regular" expressions are a thing is that...
 
sys.path.append is nice and dandy until your except top.level.Exception handler gleefully ignores on a level.Exception.
 
with regular regular expressions you can compile the expression into a deterministic finite automaton which will match strings in O(N) time.
 
import_statement = 'from ..A import x' # equivalent generated by parser
if 'A' in os.listdir(os.path.abspath('..')):
if (A.x exists) # psuedocode
globals()[A.x] = object A.x

This is better and reduces cognitive load. Plus global is handled internally.
 
> "grep" is a word derived from the command for regular expression searching in the ed editor: g/re/p meaning "Global search for Regular Expression and Print matching lines"
@sanjarcode that's actually a very bad idea.
consider if you write an utility that needs module X...
then you are in some subdirectory Y and
run the utility in there, it sees all the modules lying around there and would import them...
 
7:10 PM
@sanjarcode Are you aware that .. is relative to your CWD? Not the location of the python script? Your users could break your code just by executing it from the wrong directory
 
.... actually that is the case often with Python but FORTUNATELY not for every single case.
 
I know about '..' @Aran-Fey, that can be managed. The code I wrote is more of a pseudocode version.

@AnttiHaapala, well I would call the function recursively, so that namespace addition is specific.

import_statement = 'from ..A import x' # equivalent generated by parser
if 'A' in os.listdir(os.path.abspath('..')):
if (A.x exists) # psuedocode
globals()[A.x] = object A.x
 
At this point this is far too heavy on the "pseudo" for me. No clue what that's supposed to be doing
 
Ok, that's enough of the unformatted code. You're not even trying. See the formatting guide @sanjarcode
 
Sorry, but chatboxb doesn't allow for formatting
@roganjosh, how can I format
 
I'm also not sure why we're even arguing about this. I'm fairly sure everyone agrees that python's import system could be better
 
@sanjarcode maybe using the guide I just linked?
 
Right, no point taking this forward
print('Hello, earth')
Okay, thanks @roganjosh
 
 
1 hour later…
8:42 PM
Does the interpreter have only __name__ at a time, belonging to the file it is executing, or does it save multiple __name__, one for each file that it has executed in the session?
 
9:03 PM
each module has its own __name__
 
9:37 PM
The same name can be defined in many different namespaces. For a given module M, M.__name__ is the name of that module.
 
Whats a good way to document STDIN for a Python CLI? I can take an input file arg which defaults to STDIN and document that but wondering if there's a standard way to do it otherwise?
 
10:33 PM
Thanks a lot for the help @AnttiHaapala, @roganjosh, @MisterMiyagi, @Aran-Fey. I've completely understood the import system in Python. This was my first functional chat on StackOverflow
 
@sanjarcode completely?? could you teach me too :D
 
@sanjarcode could you answer this question then? The poor guy just wants to have aliases for modules, shouldn't be too hard, right? stackoverflow.com/q/65736555/962190
 
11:10 PM
^ That's a good question. There's almost certainly a not terrible answer, but I don't know it. Probably some Beazley talk has the answer.
 

« first day (3745 days earlier)      last day (1186 days later) »