« first day (3689 days earlier)      last day (1260 days later) » 

1:45 AM
I haven't ventured into a StackOverflow chatroom in quite a while --- is it ok to "advertise" a question I asked a day or so ago and didn't get a response for?

I'm trying to use `mypy` and am running into some difficulty where mypy is saying a particular attribute I've imported from a "sibling" package can't be found, while python accepts the import just fine. The minimal working example requires a few different files/a directory structure, so I've written up a full question here: https://stackoverflow.com/q/64905873/1110928
Welp. Should have read the rules in entirety first; just saw the item about questions needing to be 48 hours old before asking. Sorry; pls disregard the above :(
 
 
4 hours later…
5:47 AM
print('{}{:.>23}'.format(page, title))
how can I format with 23 - length of the page variable?
 
 
1 hour later…
6:50 AM
This is the error I'm getting:
D:\ungoogled-chromium-windows>py build.py
Python 3.7.7
Traceback (most recent call last):
File "build.py", line 220, in <module>
main()
File "build.py", line 134, in main
_test_python2(parser.error)
File "build.py", line 87, in _test_python2
result.stdout.strip()))
AttributeError: 'NoneType' object has no attribute 'strip'
 
@apnorton yes. The rule is basically in place for those who come to whine that no one has answered their question. Since your question doesn't have any action whatsoever and no comments, no votes etc and it is quite on topic and well-asked and so I'd say the 48 hours is not that strict even :D:D:D
@apnorton or you might do it more sneakily: ask about the problem in the chat first next time, and if you do not get an answer but folks think it is interesting you'll say "ok I'll write a question", then link to it: "here" :D
 
 
2 hours later…
8:28 AM
Cbg.
 
Cbg.
 
:)
How are you doing?
 
Pretty well, thanks. You?
 
8:37 AM
That's great, I'm good thanks 👍
Cbg all.
 
hands up if anyone has done a "delete from table_name" and forgotten the where clause recently? coughs
 
SQL?
 
@JonClements Not recently. I have a strict policy of not making the same mistake more than a hundred times ...
8
 
Laurel Holdenweb
 
@holdenweb 100th time lucky? :p
 
8:39 AM
I love software engineering. I have black and flake8 both installed as pre-commit hooks, and now they are fighting about whether a binary operator should be placed before or after the line break for a continuation line. Gonna have to shut flake8 up about that, I'm afraid. Black is canonical.
 
um... what are they considering a line break?
 
Could we add a "SALAD" link on this page, with no destination but a tooltip to explain the mot common terms and linking to the main salad page?
 
@holdenweb ?
 
Lettuce?
 
# essentially, whether it should be
(something and
 something_else)

# or

(something
 and something_else)
An edit to shut flake8 up caused black to fix it back to the state where flake8 again complains W503 line break before binary operator
 
8:47 AM
Does flake8 still have both warnings? One for before the linebreak, one for after the linebreak...
ignore = E501, W503, B008, B011
 
Still? No, flake thinks the operator should go before the line end. Please don't make me look the other three up ... ;-)
 
😂
Is the salad language for the Python room fixed to the current vocabulary, or are we still able to add more to the 'dictionary' ?
 
@holdenweb Then don't look up Line break occurred after a binary operator (W504) either :P
 
Quite:
> Gonna have to shut flake8 up about that, I'm afraid. Black is canonical.
Not sure quite why one is suppressed and the other isn't, but at least they aren't both asserted :P
My scheme to turn Google Docs into blog posts continue to move forwards.
I spent several hours trying to fix what I thought was a gnarly bug in my parser, only to eventually discover it was caused by Docs adding a gratuitous line ending where none was present at the very end.
 
9:03 AM
and something and something_else don't graciously fit in the same line?
are they function calls or ...?
(just wondering because it sounds like you can short circuit earlier than a combined if)?
or maybe use all? depends on the use case I guess
x = ...
y = ...

if x and y:
    ...
unless x and y are somethings you don't want to keep in scope - that doesn't hurt either
 
 
2 hours later…
10:56 AM
def is_code(para, in_chunk):
    if len(para.elements) == 1:
        text_run = para.elements[0].textRun
        style = text_run.textStyle
        if (
            "weightedFontFamily" in style
            and style.weightedFontFamily.fontFamily == "Consolas"
        ) or (in_chunk and text_run.content == "\n"):
            return True
    return False
 
cbg cbg, long time no see y'all :-)
 
cbg cbg
How the devil are you?
 
Hey @holdenweb, last time we "spoke" you had just taken a new job/mission.
I am well, thank you, you?
 
@JonClements I've already realised (simply by opening my code to scrutiny) that the if should be a return anyway!
 
Question, where can I find the source code for python 2.5?
 
10:59 AM
@ReblochonMasque At Labster? Yup. Finally got the team under control, and next year moving up to be responsible for making sure we have all necessary technical skills. So it's gone well, though not always easily.
@ReblochonMasque In the github repo, tagged as v2.5?
 
I was looking at branches... Let me see if tags work.
 
[They do - I went through the same loop!]
 
How do you search for tags on github?
cbg @AndrasDeak & @Aran-Fey
 
cbg
 
11:57 AM
rbrb
 
cbg
 
user13415013
12:20 PM
Just got message from stackoverflow moderators , deleting 5 question and asking bad question.
cbg
 
12:33 PM
@ReblochonMasque I usually use the url for this
nvm, i thought you meant tags on the repo instead of the release page :D
 
1:13 PM
cbg, can anyone tell my why defaultdict(lambda:[]) does not work the same as dict.fromkeys('123',[]), what am I missing here to understand the difference?
>>> d1=dict.fromkeys('123',[])
>>> d1['1'].append('will be in all keys')
in other words, why cant I see this behavior for a default dict of lists? Shouldn't the [] in the lambda point to the same []?
 
1:32 PM
@python_learner no, it shouldn't
def list_returner():
    return []
^ that is your lambda. Why should it return the same list each time?
 
ok that makes sense, so dict.fromkeys uses the same [] for all the keys then , default dict calls the functions for every key
 
@aadibajpai You can put a {} placeholder inside another {} placeholder to substitute a formatting value. I'm not really sure what you are trying to accomplish here, so here are a couple of examples.
>>> page = 1
>>> title = "The first page"
>>> print('{}{:.>23}'.format(page, title))
1.........The first page
>>> print('{}{:.>{}}'.format(page, title, 23-len(title)))
1The first page
>>> print('{:{}}{:.>23}'.format(str(page), 23-len(str(page)), title))
1                     .........The first page
 
Yes, [] is a given empty list. dict.fromkeys can't do anything else than assign that to each key.
@PaulMcG sounds like they want the two fields to occupy a given size together
 
Ah, this is what they are after (pre-coffee post again):
>>> print('{}{:.>{}}'.format(page, title, 23-len(str(page))))
1........The first page
 
1:41 PM
yup
 
I'd never seen the '.' notation for a string variable before - like an old-time table of contents in runoff
 
the clueless secretary's dotted tabulator
 
2:11 PM
I always have to try those nested format statements to make sure I get the order of the variables right (one of the advantages of f-strings). I guess one working rule-of-thumb would be to track the order of the left-braces.
>>> print(f"{page}{title:.>{23-len(str(page))}}")
1.......Stuff on page 1
I don't know why I am so resistant to using f-strings. They feel javascripty? I'm just a curmudgeon?
I guess its like putting a little implicit "eval" inside an otherwise-harmless print statement. Waiting for the bugs to pop up when an f-string in a log message embeds a function with surprise side-effects.
In that sense, really no different from putting that same function call in the args to str.format(). But at least there, it is obvious that a function is being called. I think I tend to mentally gloss over the contents of strings, because, well, what could be bad about the contents of a string? But now I have to look inside an f-string to see what executable code is lurking there.
 
2:28 PM
anyone have experience with slice here?
 
Yes
 
managed to find a library that do what i planned to make, but the output from a test seems to not display special ascii char the way i want
it's this, tried a test case in the cloned directory:
```
from fileslice import Slicer

r = open('README.txt', 'br')


slicer = Slicer(r)

start = 0
size = 80
fileslice = slicer (start, size) #this is a file like object


print(fileslice.read())
```
 
Sadly, triple-backticks are not honored in SO chat
 
oh :/
well anyway, the output doesn't print special character the way i want (eg: print \n instead of printing an actual newline)
I tried commenting something that looked like it was doing this in the codebase (between LOC 230-238)
 
We generally prefer only short code snippets - yours might be acceptable if you get rid of the blank lines. Post as a separate message, and mark as "fixed font". There is a link to the code formatting guide on the right hand side of the page.
 
2:33 PM
@PaulMcG alright, will fix that real quick
from fileslice import Slicer
r = open('README.txt', 'br')
slicer = Slicer(r)
start = 0
size = 80
fileslice = slicer (start, size)
print(fileslice.read())
@PaulMcG better? :D
 
yes
 
any advice on what i said earlier?
the output look like something like this:
b':Date: 2018-10-10\n:Version: 0.0.2\n:Authors
with the previously mentioned test case
but i want it to display special character right (eg: \n displayed as actual newlines etc)
 
Try opening the file with just 'r', not 'br'
 
@PaulMcG works :D
 
You were getting back bytes, not str.
 
2:39 PM
so i guess the lines i commented weren't the culprit hmm
I see
 
Looks like a nice module. When I saw the name, I first thought it was going to be a line-by-line slicer for text files.
 
ikr, same here.
I found it because i was searching for an existing implementation of the `dd` tool but in python.
probably might do it since no one did it afaik (it would be a fun endeavor)
I didn't found anything with keywords such as "offset" and "between", etc
So i tried everything i could think of, and "part" seems to have worked in this case (searched on github using Python as lang ofc)
I did tried seeking offset directly in python but it seems to do something weird when trying to print content between two offset (seems more like it move instead of print...)
 
I've only used dd to create files, not slice them.
 
@PaulMcG I mean, I'm mainly trying to print content between two offset here...wait, is it considering slicing?
(I know what slicing is but not sure if it apply here)
 
"Slicing" is as good a term as any, from what I understand you are doing.
 
2:45 PM
I see :o
 
I just never used dd in that way.
 
if i knew, i guess i could have found this faster
@PaulMcG yeah, I'm used in doing this given stuff i saw on Unix SE
there tail/head but it seems kinda meh unless everything is on the same line
while I'm here, i was wondering...any tool anyone would recommend (or module?) to find relation between python file in a project?
would be useful when trying to understand codebase faster when it's not commented much
or when there those kind of messy project that import each other in different file...(saw it happen sometime ago on a github repo)
 
I've written my own before, to scan through a code base and find all the imports. But the resulting graph was pretty unreadable.
 
hmm
would be nice to take a look at it if it's available on a repo :o
 
duplicate - I already voted to close as needs more focus - dup link is in the comments. stackoverflow.com/questions/64944120/…
 
2:54 PM
You could try grepping for the imports, and then converting them to a graphing markup like yuml or PlantUML. If the graph too complex, then you could manually create the interesting subsets from the markup.
@wwii done
 
@PaulMcG that's a good idea yeah :)
@PaulMcG thanks for all the help!
 
@PaulMcG if you only use if= and of= with dd then I'm told one should use cat instead
 
not necessarily...if you're trying to write a whole img to a drive (the whole drive, without any partition and formatted) it would be fine to use `cat` yes.

But if you try to write it to a specific partition, `cat` wouldn't work right (afaik).
That's where `dd` comes in (and it's only the one specific example i thought of, there might be more...)
 
I'm pretty sure cat can write to specific partitions just fine
I was pointed to posts like unix.stackexchange.com/questions/12532/…
 
3:10 PM
slightly off topic, so my apologies, is there a better way than "write files in local, run, test and then paste the entire folder in a VM"?
if I make any change in local I copy paste the entire folder again
 
@python_learner I used to use virtualbox which supports shared folders
Is that your issue?
 
so shared folders is my google term then
I am just using the VM as a different PC, that makes sense?
is git over kill for this? I dont know git other than using Tortoise GIT, my VM has internet access
 
just read part of it, seems like you might be right but, dd is still needed when doing part of a file (at the very least) or for damaged drives/partition...

As seen in the post you linked: https://unix.stackexchange.com/a/12534/409852
comment under that post does show that you can do it yes, but only using tail+head...which is slower than using just dd.

Probably different case for damaged drives but, I'm not exactly sure so can't speak much about it (beside that dd is probably the better tool for this compared to cat)
 
3:53 PM
@NordineLotfi so you're saying that for touching parts of files dd is useful. And I'm saying that for touching entire files or devices cat should be used instead. Where's the contradiction?
 
@AndrasDeak there isn't any? I did said you were right at the start of my paragraph :D
it was just to add on what you said since the linked post didn't really mentioned it (but other answer there did mention this, as i linked)
 
"you might be right but", emphasis mine :P
@NordineLotfi OK
 
@AndrasDeak right, should have phrased this better
 
4:22 PM
@python_learner shared folders are not a substitute for source code management, whether it is git, hg, svn, etc. I can't tell you how many "little projects" I've done where I've wished (usually after the fact) that I had bothered to set up a repo.
 
@python_learner different use case
Then you'll have to explain the X in XY
But no git repo is overkill. I have a git repo for my lecture notes.
 
@NordineLotfi Looking at this again, it seems a nice enhancement would be to add support for fileslice = slicer[start:end] notation. Just requires implementing __getitem__ in the Slicer class.
 
Something named Slicer should already do that
I guess the dev chose to use __call__ instead.
(would not have been my choice)
 
4:39 PM
@PaulMcG yeah, i thought of changing the annotation but didn't knew where to start (didn't yet examine entirely the codebase yet) :D Thanks for the heads up
@AndrasDeak I see, didn't knew that one either :o
guess I'll try it and see which one perform better for my use case, thanks
 
I guess I will go with git, at the very least I get to learn git
I saw some fun git tutorial in this chat, will search for that
 
@python_learner search for learngitbranching
 
thanks :D
 
you meant this right?
https://github.com/interpretml/slicer
just making sure
 
@python_learner and I suggest reading the Git Parable first
 
4:44 PM
google links me an article by Tom Preston, that one?
I hear people saying, rebase this rebase that, now I can finally understand that
 
@python_learner I think so
@NordineLotfi no, I just meant that what you originally posted should support slices, according to my expectations
slicer(a, b) is less natural in python than slicer[a:b].
 
@AndrasDeak oh, gotcha.
@AndrasDeak yeah it does make more sense
btw, is argparse recommended for adding argument support or is it better to do in pure python? (without any or minimal import)
all the guides i found seems to use argparse
 
4:59 PM
There are some things you can't do with argparse, but if it does what you need... might as well use it
 
@Aran-Fey mind elaborating on the things you can't do with it? just curious
 
It's been too long since I used it, I can't actually think of anything at the moment...
 
5:22 PM
@NordineLotfi are you writing a command line application?
 
@Arne yeah, I am
found sys.arg to be fine since it's a simple use case, didn't try getopt or argparse yet
 
click is a pretty popular 3rd part package for those, I've been using it for a bunch of apps and am quite happy. I'd definitely not roll my own argument parser, unless what you're trying to do is super simple.
 
@Arne didn't heard of that one before! Thanks, I'll check it out :D
 
"click" is a pretty ironic name for a library that creates command line interfaces
 
5:37 PM
armin is a wizard with names, an oxymoron plus cli hidden within it
 
I've gotten used to using argparse. I use this for enums -> choices -> enums.
 
well duh, it has parse in its name ;)
 
Et tu, Andras?
 
I just meant pyparsing... I have only the one executable package and I don't think it has any complicated command line args
 
5:43 PM
No, I liked your comment, even if it did make me snort some coffee through my nose
 
@AndrasDeak The whole API seems a bit misconceived to me, but it would be quite easy to write a sane wrapper for it. I'd have a SliceableFile object to open the base file (takes the same arguments as open) with a slice method to create a new fileslice object.
 
@holdenweb - why a slice method instead of having __getitem__ do it?
 
waffles
 
=)
 
@PaulMcG Even better: my_slice = my_sliceable[15:200]. Good batting, Thinkman.
The interface it currently has truly is antipythonic.
 
5:54 PM
A little trickier, since you can't just use seek, would be to support slices of a text file as if it were an array of strings, one per line (and auto-strip the trailing newline!). Would be nice to get the n'th line as my_sliced_text_file[n]. Would need an internal lazy reader to buffer up lines 0 to n-1 so you don't have to read from 0 every time. Or maybe an lru_cache.
I'm guessing that this must exist already in some PyPI package
 
Guess: "click" => command line interface construction kit.
 
6:07 PM
anyone worked with offset (like a lot)?
I feel like most codebase that use offset in some way always treat the size/end offset the wrong way, eg: use full size of input - 1 to get the whole input

So if the full size of an input was 11 (for the input "helloworld") the size/end offset would be 10 instead of 11...is this normal or?
I can understand that the start of the input is 0 but...I just don't get why the end/size offset is like this
 
>>> len("helloworld")
10
 
uh, how come the tool wc on Unix/Linux report 11? there no newline in my testcase
that's weird
 
$ touch foo_empty
$ wc -c foo_empty
0 foo_empty
$ echo '' >foo_almost_empty
$ wc -c foo_almost_empty
1 foo_almost_empty
>>> with open('foo_almost_empty', 'rb') as f:
...     contents = f.read()
...
>>> print(contents)
b'\n'
 
is EOF a character?
 
that's a newline
@Arne then the proper empty file would have 1 size, so not according to wc
 
6:16 PM
yeah, I scanned the example a tad too quickly
 
DESCRIPTION
       Echo the STRING(s) to standard output.

       -n     do not output the trailing newline
right at the top of man echo
$ echo 'helloworld' |wc -c
11
$ echo -n 'helloworld' |wc -c
10
surprisingly a redirect does the same thing
$ wc -c <<<'helloworld'
11
I ran into the same thing when I tried hashing my email address to find my gravatar hash. The trailing newline messed with the hash.
interesting, according to POSIX a text file has a newline at the end of every line
> 3.206 Line

A sequence of zero or more non- <newline> characters plus a terminating <newline> character.
 
@AndrasDeak yeah i actually run into the same problem except i was doing testing with md5sum and a couple string with fileslicer (used wc a lot so didn't notice...)
 
6:43 PM
so wait, that mean that python is what is adding a newline in this instance...(tried with echo -n like in your example):

Using https://dpaste.com/4EKD28T4K.txt with `0 10`, then `0 9` etc always show `0a` at the end...(used xxd to see the output)
 
@NordineLotfi absolutely not
I don't know what "0 10" and "0 9" refer to here
 
:$ python3 testslice.py 0 8 | xxd
00000000: 6865 6c6c 6f77 6f72 0a hellowor.

:$ python3 testslice.py 0 9 | xxd
00000000: 6865 6c6c 6f77 6f72 6c0a helloworl.

:$ xxd hello # with 'helloworld' without newline
00000000: 6865 6c6c 6f77 6f72 6c64 helloworld
 
"helloworld" has 10 characters if you count them on your fingers
 
@AndrasDeak I'm talking about the added newline i previously mentioned...
@AndrasDeak the start and end/size offset
 
@NordineLotfi the question is what testslice.py does, yes? Which only you can see?
"python" doesn't do anything on its own
 
6:47 PM
@AndrasDeak I linked the file though? dpaste.com/4EKD28T4K.txt
@AndrasDeak I'm aware, I meant that to say "so the code I'm using is the one adding a newline?"
 
@NordineLotfi then yes, if the output has a newline
 
:/ not sure where in the code it is added...
guess it's somewhere in the module codebase hmm
 
@NordineLotfi OK. Which contains a read from a file...
 
@AndrasDeak the file being just 'helloworld' without newline (using your echo -n example previously posted)
 
@NordineLotfi probably a print needs an end=''
 
6:51 PM
Or, if you are just writing single strings, use file.write() instead, which just sends the {bytes,chars} you pass as an argument.
 
7:03 PM
@AndrasDeak add '' on two instance where size= (the end offset) was seen, but still same result as above :/
@holdenweb I think file.write() is already used in the module my code/testcase use hmm
I guess i could use a regex to delete the last newline in any output but, it would be very a ugly hack for longterm usage
 
@NordineLotfi the last line of your snippet. print(...). Make it print(..., end='').
this is a wild goose chase
 
@AndrasDeak wait, then how do i fix this? I never thought the problem would be coming from there o-o
@AndrasDeak lol yeah
 
"""
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Print objects to the text stream file, separated by sep and followed by end. sep, end, file and flush, if present, must be given as keyword arguments.
"""

By default, `print` follows its output with ... a newline!
 
@holdenweb I didn't knew this, Thanks
 
That was rapidly becoming apparent :-)
 
7:16 PM
yeah, ikr
although...
using print(fileslice.read(), end="") seems to delete all newline, even the one that were part of the original output
any way to keep the newline from the original output, without the newline added by print()?
 
@NordineLotfi nope, that works correctly
 
@Aran-Fey yeah, you're right :D checked again with xxd
 
Take a look at repr(fileslice.read()) and you should see the newline if it's there.
 
7:50 PM
@holdenweb that only display it in pdb or ipython right? using vscode but it didn't display it
 
8:24 PM
@holdenweb the problem was exactly that the newline came from outside fileslice.read()
print(fileslice.read()), to be specific. Hence the hunt for a non-existing newline
 
8:45 PM
Figured.
 
@AndrasDeak afaik it was print who was printing the additional \n :D (which i didn't knew)
 
@NordineLotfi Set a breakpoint in vscode then evaluate repr(fileslice.read()) in the debugger. Or haven't you got that far with vscode yet (I don't like it much myself, but I have long-ingrained habits).
 
@holdenweb yeah i do use pdb a lot in vscode...just never thought of setting a breakpoint before (though i do know what it does)
guess that's what make it work?
 
If you use pdb then a call to pdb.settrace() IS a breakpoint.
 
@holdenweb I see
guess I'll use this more often then
 
8:57 PM
breakpoint() itself has been in Python for a little while now
 
It's a great way to find out whether things are as you expect in your program. Debugging is the art of finding out what you don't understand ...
 
(just throwing that out there...)
 
Thanks, didn't know!
 
@holdenweb yeah, I'm usually used to debug a lot in bash (using -x). Still learning in python though
 
TBH I haven't paid a lot of attention to the audit hooks.
 
9:02 PM
though i noticed that, debugging in Python is a lot harder than in say, Bash. (I'm probably biased since i know Bash better than python though)
 
@NordineLotfi generally I find it easier to use ipython and then just enable the pdb mode, so that if exceptions occur, you get an interactive prompt you can work with to look at things...
(that or just use an IDE if you want to that supports such things)
 
@JonClements yeah, didn't use ipython much (not sure how to reset it when using old variable name) but i do use pdb in vscode.
any recommendation for studying someone else codebase though?
something to speed up understanding when there too much code and not enough comments (beside pdb)
 
@NordineLotfi "speed up understanding" I don't think's a thing. Sometimes with programming, or understanding other's code, is more a time and patience thing.
 
@JonClements I meant, other tools for debugging to help understanding large codebase
not saying this as in "explaining codebase", this imply understanding of Python on some degree
 
I'm not aware of any tools that can help you understand things rather than just point out flaws or hint at flaws
 
9:25 PM
@JonClements the latter was more what i was after :)
(pointing flaws/hint at flaws)
 
@holdenweb or which assumption of yours fails
@NordineLotfi heh
 
As so often, you express it better than I do.
 
:')
 
user6568562
9:48 PM
I feel like having a personal and intimate relationship with debugging
 
user6568562
As in what happens in las vegas kind of way
 
user6568562
I miss our old chats of back in the day, what happened to those ?
 
11:43 PM
Is anyone have experience in gRPC AsyncIO
 
@PouyaEsmaeili please don't ask for help here with fresh questions on the main site as per our rules
 

« first day (3689 days earlier)      last day (1260 days later) »