« first day (2657 days earlier)      last day (2305 days later) » 
00:00 - 20:0020:00 - 00:00

12:47 AM
Cabbage peaches and pears, potato all
 
wim
1:24 AM
Make it so. "Dict keeps insertion order" is the ruling <-- GvR on dict ordering guarantees for Python 3.7
 
Why is it "peaches and pears"?
 
How do you mean?
 
@wim engage!
 
@JennaSloan sopython.com/salad if your asking yourself what it all means
 
Hello, I used this Bokeh code (ideone.com/TsP6gO) to generate this line graph (i.imgur.com/TaEw4Zz.png) displaying the price movement of two cryptocurrency pairs.
As you can see, the blue and orange lines are so far apart that the value and volatility of the orange line isn't visible. I want the graph to be more like this (coinmarketcap.com/currencies/ethereum), where the software determines an appropriate x-axis range for each line, and overlays them. How can I alter the code to do this?
Sorry it's the y-axis not the x-axis
 
1:33 AM
the keyword is "twin axes" and bokeh might not support that github.com/ioam/holoviews/issues/1594
(I've never used it, just a quick google search)
there are a few relevant-looking bits of code on that thread though
 
Why does "pears" mean "gentlemen"?
 
@JennaSloan why does "pear" mean "pear"? ;)
 
Interesting, I'll check it out
 
"Aubergines" would make more sense than "pears"
 
Rhubarb
 
 
1 hour later…
2:58 AM
Evening cabbage
 
3:20 AM
@AndrasDeak Have you revisited my question? There have been a couple more answers since yours, and I'm not really sure which one is more convincing so I haven't accepted anything yet. Also, someone's put a bounty on it.
 
It'd be awkward calling that hook on the C side every time a C-level loop is done with an iterator, though. That'd require a lot more manual fixing than the Python side.
 
wim
4:13 AM
isn't that guy the author of trio?
well, judging by the looks of the PEP, yes ... he's extremely thorough
 
 
4 hours later…
7:52 AM
cbg
 
8:10 AM
Hey Guys,
I'm using pyqt for my GUI application in python.
I used label.setText(str(counter)) in a loop,
sometime its work correctly and show the last counter on the gui,
but some times it doesn't work correctly and doesn't show the last counter.
Its completely random.
but when I resize the form, its update the Gui and show the correct numbers.
 
Don't know if that is your problem, but counter might be a generator, meaning that once it is exhausted it can't be consumed again. Can you make sure that the variable does not get reused and the argument is generated newly on each call?
 
counter is work correctly, when I resize the application windows the label update itself with counter
I think the problem is updating the label
its some time happen but some time doesn't heppen
 
Well I don't know anything about GUIs, so I'll have to pass
 
thank you very much
I used app.processEvents() after changing the label, but it doesn't solve the problem
 
8:32 AM
 
8:57 AM
@davidism umm no, f-strings are compiletime constructs
and they're easy to filter out in AST as they show up as proper attribute accesses unlike the format strings...
FWIW fstrings are safer than format strings and therefore should be always preferred :P
 
Ah, finally an answer. I had wondered if there was any way that fstrings could be used to execute arbitrary code, and couldn't find one. Knowing that they are compiletime constructs gives a full answer to that question.
 
@JennaSloan re salad language, pears etc . I suspect the mood of the moment in salad languages creation was being as random and no logical association as possible. Reminds me of a different game invented by an annoying son to reply "fish" to everything. It quickly become fun to use only the word "fish" but in such intonation as to effectively communicate your response.
 
>>> ast.dump(ast.parse("""f'foo {bar.__class__}'"""))
"Module(body=[Expr(value=JoinedStr(values=[Str(s='foo '), FormattedValue(value=Attribute(value=Name(id='bar', ctx=Load()), attr='__class__', ctx=Load()), conversion=-1, format_spec=None)]))])"
 
cbg all
 
is not much different from
>>> ast.dump(ast.parse("""'foo ' + format(bar.__class__)"""))
"Module(body=[Expr(value=BinOp(left=Str(s='foo '), op=Add(), right=Call(func=Name(id='format', ctx=Load()), args=[Attribute(value=Name(id='bar', ctx=Load()), attr='__class__', ctx=Load())], keywords=[])))])"
nothing eval going on there.
 
9:07 AM
@JennaSloan .. as was explained to me when I first came here asking similar questions, salad language is generally not used wih any serious frequency or uptake, except with hello and good bye, sometimes abbreviated rbrb an cbg. Yet it is there for those wanting to play with it.
hope it helps from a green bean, rbrb.
 
jjj
10:00 AM
cabbage people
 
cbg
 
Hey does anybody here use Django?
 
@nobism Just ask what you meant to ask.
 
Are migrations in Django just used for when you run tests? Or when your app is running in production, are migrations used somehow by Django?
 
10:13 AM
@cᴏʟᴅsᴘᴇᴇᴅ I like it how hpaulj's answer came after mine, makes fewer remarks and only those I made myself, yet it has more score than mine. Then again if I wanted to optimize for score I'd have omitted all disclosures of uncertainty and pretend to be the source of all knowledge
Anyway, I always suggest not accepting anything as long as there's a bounty, since accepts reduce "visibility" and work against the bounty
 
10:38 AM
Cabbage!
 
cbg
 
@nobism Migrations are needed to be run if you are dealing with a database. That's how Django's code syncs with the DB.
to put it in simple terms.
Perhaps you should read more about database migrations first.
So yes, if your tests require any of the underlying models, then your tests would setup a separate test DB and run your migrations on it, before running the tests.
 
 
2 hours later…
1:06 PM
Hey all. I have a minor question, not sure I feel like it's enough for an actual post. Is it okay to post questions in chat? Or is it against some rule?
 
Hi. Please read the rules and find out sopython.com/chatroom
 
Thanks, got it :)
 
I'm trying to use tkinter (python 3) to create a display only GUI which shows what appears to be scientific data in a cool way. (Seriously, this is just for appearance's sake, no real daata here).
I was hoping to find various already existing widgets to do that, saving me work. However searching online I found fairly little and since I am new to python I rather not write them myself if possible.

So my main question, do you know a package I could use, or where to find code for, or where to browse, such widgets?
 
while I can't help you, I just want to note that this question would actually be off topic on the main site :)
 
1:16 PM
I thought so. Which is why I refrained from asking it there. However, I just found out stack overflow has a chat, and figured it may be more casual.
Please let me know if this is inappropriate here as well!
 
No, I'm sure it's fine :)
worst thing that could happen is that nobody will be able to help
 
Which would just mean I'll have to practice more python and write them myself ;) I guess I'll manage.
 
there are a few regulars here who know tkinter, which is probably step 0
 
can anybody tell how the "map" function will work in python? and how it is different from the threads?
 
@AchillesRamNakirekanti very
have you read the documentation?
 
1:20 PM
i have written a code who which bfs for each node.. i compare with map and without map ,, both are giving the same time to execute it
 
I'm afraid you'll have to be more specific, especially since there are many modules implementing map methods/functions
 
psuedocode:
def function_bfs(G, x):
//does bfs on x as root
G #is a graph
V = [1, 2, 3.....] # all vertices of G
map(lambda x:function_sssp(G, x), V)
 
please delete that for now and read sopython.com/wiki/…
 
could you please explain me? @AndrasDeak
 
explain what?
 
1:29 PM
using map and without usingmap .. both giving the same time.. to execute the bfs for each node
 
Hey Guys,
I'm using pyqt for my GUI application in python.
I used label.setText(str(counter)) in a loop,
sometime its work correctly and show the last counter on the gui,
but some times it doesn't work correctly and doesn't show the last counter.
Its completely random.
but when I resize the form, its update the Gui and show the correct numbers.
I think the problem is updating the label
I used app.processEvents() multitime after changing the label, but it doesn't solve the problem
 
@AchillesRamNakirekanti what is the "without using map" case? Why do you think that map will make it any faster?
 
that means iteratively i executed bfs for each node
i read that map will distribute the code and run parallelly
*code == work
 
you need to take a closer look at what you read and where
you'll also need to have a closer look at what I've written
 
1:34 PM
no
 
1:57 PM
I'd like to ask this room for an opinion on a type of question common to : people drop in, dump (some) of their models and ask how to write a query for some end result. Usually there's no attempt to write such a query by the OP. Too broad? Acceptable? Something in between?
...Or take it to meta?
 
Isn't that what we try to teach newbies? If you don't have code, at least provide conclusive input and output definitions?
I would be afraid that punishing that behaviour will lead to the fallback question code not work; what do?
 
I prefer to close effortless code requests as too broad, with an explanation that OP should write code and we can help fix it
And occasionally generous downvotes for spoon-feeders
 
Both seem valid points, though I side more with Andras Deak's view.
 
2:17 PM
@ArneRecknagel odds are a dozen newbies had already been taught of what OP needs.
And SO is not a tutorial service
 
Well, then I guess we should be glad for people like you who janitor SO into its targeted direction
not sarcastic btw, I realize I am too permissive in regards to that kind of stuff
I even read the map-reduce article and was this close to writing an answer.
 
I'm mostly ok with writing queries for ppl, but the problem is that most of them are slight variations of the same and so the tag is filled with a dozen tailored-to-a-single-situation answers.
 
cbg \o
 
o/ cbg
 
2:35 PM
\cbg/
 
TIL my boss doesn't know any IRC lingo, such as but not limited too: afk, brb, iirc, otoh. I find this surprising because shes been coding for at least 10 years :\ guess you don't need IRC lingo to code.
 
jjj
^ I always find it amusing how unevenly distributed "computer" folklore is
 
@MooingRawr !@#
 
2:53 PM
I learn not to abbreviate things in our company's chat messaging system :\
 
cabbage
 
@jjj Same with memes. There are really obscure memes that even my non-tech friends know, and there are super common and popular memes that even the nerdiest ones don’t know.
A fried of mine didn’t even know about Gangnam Style until recently. How is that possible?!
 
3:13 PM
@MooingRawr haha here it's different: me and my boss are the ones most into IRC vs other, more "fancy" alternatives
 
The major difference between people who started with text based chats (IRC or whatever) and those who started with the modern fancy stuff is the usage of things like “lol” and text smileys vs. obsessive use of reaction GIFs and emojis…
 
^^
preach brother. preach.
 
^ Exhibit A.
 
@idjaw amen
 
I come from the first testament of the internet
I come from the one true internet
/slap
now step away you animoji using heathen
5
 
3:28 PM
Wow, I hate people who would rather use a smiley emoji than the wide variety of text based ones.
So many different options, each with it's own unique feel:
:) =) :-) =] :] =-] and so on
 
The emergence of emojis, in my mind, coincided with software vendors getting their act together WRT support for character sets beyond just ASCII. The younguns can have their fancy smiley face icons if it means I never have to see "����" again
 
I come from the land where � used to mean returning a "we will not support this character ya jerk...please enter only letters from the alphabet!!!!"
I remember those days
when unicode was a joke we can just not take seriously
 
"Please use only normal letters which normal people use"
 
haha
 
jjj
@poke yeah, I had sth similar on my mind: a guy in my work who is quite proficient in C# (afai can tell) shivers on any mention of CLI, and probably does not even know the basiciest basics. This leads to some weird stuff such as designing GUI for simplest programs. But well, if it works for him..
 
3:45 PM
Yeah, I know people like that too.. developers afraid of the CLI.
 
I like CLIs because I don't have to deal with keeping up with GUI frameworks :)
 
4:03 PM
they just better have autocomplete
if they don't, then it's fit for the pit
 
that's the shell's problem :D
 
not necessarily
the shell doesn't know inherently how to autocomplete
you have to provide that implementation in your CLI
 
cbg
 
cbg
 
jjj
cbg!
 
DSM
4:16 PM
cbg!
 
cbg
 
I just wanted to repeat a question here. Which is your favorite editor for python..?
 
marble tablets
 
@ex
@excaza is that really somthing./
 
Going ahead with the obvious: PyCharm
Now rbrb, before I get caught up in the ensuing disussion
 
4:23 PM
it worked for Moses
 
DSM
TFW your intern correctly spots a subtle problem with a business data format :'-)
 
Well actually thats better than the answer I got once I asked someone the same question and he said "PUNCH CARDS"
 
There's no easy way to get a list of all the modules that you could potentially import, right? help("modules") shows them to you but it doesn't hand you an actual list-of-strings.
 
69
Q: Is there a standard way to list names of Python modules in a package?

DNSIs there a straightforward way to list the names of all modules in a package, without using __all__? For example, given this package: /testpkg /testpkg/__init__.py /testpkg/modulea.py /testpkg/moduleb.py I'm wondering if there is a standard or built-in way to do something like this: >>> pack...

?
 
Uh oh, Kevin is wandering into importlib machinery territory. I hope you brought a map, waterproof boots and 2-3 weeks worth of food.
 
DSM
4:34 PM
Hmm. I know how to get project names, not module names.
 
Or how about this: given a string s which is a valid identifier, can I determine whether import [value of s] would succeed, without actually importing it?
 
DSM
You might be able to find out if it's definitely going to fail.
Success would depend on it not raising an exception, and you can't know that until you do it.
 
As long as I can tell whether it raises a ModuleNotFoundError, I'm happy.
I guess I could just search for .py files in the directories of sys.path? Or would that only pick up on built-in modules.
 
DSM
imp.find_module will tell you if the (highest level) module is available.
(I don't know offhand what the importlib equivalent is, guess I'm living in the past..)
 
Just as well, since the question I'm doing this for is tagged Python-2.7
 
4:50 PM
For some reason code.interact() doesn't enable tab completion like the standard Python shell. And venv and virtualenv both mess with site.py in different ways, so it's non-trivial to set up the same behavior. twitter.com/davidism/status/956206374223978496
Exploring this rabbit hole because someone said they "just" want to enable tab completion in the Flask shell like the standard shell. ;_;
 
The deed is done. I worry a little bit that OP is trying to make an inescapable exec() prison, and I'm handing him swiss cheese and praising its qualities as a building material.
 
5:06 PM
Why did you remove my question? Is this room not for asking questions?
 
Please read our room rules (I know you've been told to before): sopython.com/chatroom. Format your code. Use a paste site for large blocks of code.
 
https://pastebin.com/xxu6cida
Is the exception, must be str, not bytes occurring because of the decode() method? Shouldnt the decode() method convert the bytes back to string characters?
 
Hmm, what line number does the error occur on? Let's see a stack trace.
 
What exception? See stackoverflow.com/help/mcve. Which is also in the room rules now.
Why not try stepping through with a debugger? You could confirm exactly what the data was and what call raises the exception.
 
If you're thinking "I can't provide a stack trace because my code doesn't display a stack trace because I catch the error", that is a problem that can be solved fairly straightforwardly... ;-)
 
5:13 PM
Huh, didn't even notice the except Exception anti-pattern. Just had to tell someone not to do that on the main site too.
Where does that pattern keep coming from?
 
It kind of makes sense if you're inside a while loop and explicitly want the behavior of "on any kind of failure, keep iterating anyway".
I do occasionally see it in contexts where it just prints some uninformative message and quits right away, which is almost completely indefensible
 
Don’t catch exceptions unless you are prepared to actually handle them…
 
At least print the whole traceback not just the error message.
 
"I print a generic 'failed' message because I don't want the tech-illiterate end-users to see a stack trace and panic" is a valid use-case but it would be better to log the error somewhere else rather than just throw it away
 
*sigh*
 
5:22 PM
 
That helped, thanks.
 
5:36 PM
scans room....frowns.....sees bunny and kitty...smiles.
re-cbg
 
cbg idjaw
 
Hey all. So I have a question over SQLAlchemy. Trying to review how to connect to a database but I think I may not have enough information from the person who set the DB up. Before I go ask them I wanted to see if anyone could show me a good example of a connection string for a MS SQL DB.
 
I just notice that was a picture of a bunny and a kitty, I just assumed it was two bunnies since I saw the larger bunny :\
 
Right now all I was given was the name of the instance but not sure how that relates to the connection string. Im use to an IP or hostname to connect to.
 
5:40 PM
@davidism Yeah I have looked over that one. I think its because I just dont have the url or IP to connect to that I am confused.
 
Then it sounds like you know exactly what you need.
 
:40953279 Thanks for pointing that out. Definitely looked like two bunnies.
@davidism I think so, just trying to confirm. Thanks for the help
 
wim
(speculation patches "are COMPLETE AND UTTER GARBAGE")
 
oh boy, a new Linus rant.
I need to get a coffee for this
 
5:43 PM
I give up I'm just going to take a break... sigh
 
No your good. I caught that. I read you post before you deleted and thought it was okay.
I knew I was going to catch those comments first after I asked
Based on the questions asked today on the python tag I feel like I just need to learn pandas for the pure purpose of knowing it. Seems every other question is about pandas.
 
wim
@AshishNitinPatil That's wrong, and bad advice.
 
Which part?
Integration tests would need the migrations to be run before testing right?
> If the database does not exist, it will first be created. Any migrations will also be applied in order to keep it up to date.
 
wim
The test database is created in the current state of the models
 
Ooh, so it doesn't use the old migrations at all?
 
wim
5:57 PM
The migrations are generally a no-op
And it's a very common speed-up to the slow django test-runner to disable the migrations during test
Unless you use a persistent test db or need data fixtures in there first (both of which are generally a bad idea in practice) you don't want to run the migrations.
 
Oh okay, my bad. TIL.
thanks
 
wim
@AshishNitinPatil you took that quote out of context
it's talking about when used with the test --keepdb option
 
I don't know the full context, but I generally don't run migrations when testing Flask apps. I do test the migrations though, I have one test that runs all the upgrades then all the downgrades. Doesn't catch all the errors that could occur when migrating real data, but it's a good sanity check.
 
wim
^ Yep, testing the migrations themselves is another story, but don't run them for every test - it slows things down terribly.
 
6:01 PM
@nobism Kindly refer to the above messages and ignore my earlier comments.
 
wim
@davidism do you put the test db in a container? or use local services
 
I use a locally running postgresql, but set up a separate test database.
 
wim
Yeah that's what I did previously. Moved to doing it with docker-compose now, it's working well
 
Standing up Docker each time seems a bit slow. Haven't had time to try it yet.
 
wim
it is slightly slower, but not a deal breaker
the benefit is you no longer need to ensure the service is set up on local and CI in the same way
 
6:04 PM
@wim can you give a good reference link for this?
 
wim
not bad when it's just postgresql, but if you also want to test against mysql, and then have other services like elasticsearch etc ... ugh, it can become a headach
@AshishNitinPatil No, just experience
 
I think zzzeek uses Docker to stand up all his test databases (and versions) for SQLAlchemy.
 
cool, will search around. thanks anyway
 
longtime cabbage, all
 
@davidism Hey follow up to the DB question from earlier. So the DBA that set up the DB for me isnt helping too much on getting me a URL. He simply said the instance and server have the same name? Would that to you mean the instance name is the URL?
 
DSM
6:15 PM
@inspectorG4dget: hey, g4dget!
 
hey DSM! How's life?
 
@ZackTarr Sounds like you should sit down with that person and ask them to show you exactly how to connect from your machine, then use the same information.
 
DSM
@inspectorG4dget: cold and wet, lately. :-) Good apart from that.
 
Ah, silly me. Why the heck would the tests require any migrations to be run?! (Since there are no changes to the underlying models, assuming we don't need the test DB to be persistent) *facepalm*
 
Yeah thats the plan. he just hit me with the "sorry I dont know anything about python" comment. Over here like I dont need you to write it just give me an IP. But thanks for helping
 
6:17 PM
eek! Ottawa's not all that better off, to be honest
 
wim
@excaza gosh, that accepted answer is terrible :( :(
 
DSM
@iG: remind me again. Are you still working on your degree or did you jump to the Real World already?
 
@DSM still working on becoming a Pretty Huge Dumbass
but the time draws near, that I might ask for a ref/reco from someone here
btw, I have a question about print(...). Suppose I have a function that reads data from a file, and I print some logging messages before I call that function. Suppose also that the function prints progress as it reads the file (example coming up):
def loadData(infilepath):
    with open(infilepath) as infile:
        answer = []
        for progress, row in csv.reader(infile):
            if not progress % 10000:
                progress = str(progress)
                print(progress, '\b'*len(progress), sep='', end='', flush=True)
            answer.append(doSomethingTo(row))
    return answer

print("Loading Data... ", end='', flush=True)
loadData('path/to/file')
 
wim
you probably want \r not \b
 
now, see that '\b'*len(progress) in loadData? I hate that. Normally, while writing a progress reporter, I'd replace that with a print(progress, '\r', end='', flush=True). But I can't in this case because of that print("Loading Data... ", end='', flush=True) line outside the function
 
wim
6:27 PM
so put "Loading Data... " into the progress message
while you're at it, make it a context manager which is the better way to do this
with progress_bar(...) as bar:
    # do stuff
    bar.update(...)
 
is there a way to not do that? Because while Loading Data... is a static string, the actual message is not
 
@AndrasDeak Personally I think that is a little unfair to you. Fortunately I don't look at vote counts when deciding what answer I prefer
 
wait what?! what is that context manager? I've never seen it before. If you mean "turn loadData into a context manager", how do I do that?
 
morning cbg, folks
 
cbg cold!
 
wim
6:29 PM
honestly just use a library, they already figured out all these kind of gotchas in progressbar2
you're re-inventing the wheel
 
Apparently that progressbar package doesn't install on python >.> (only pythoff)
 
cbg
use tqdm
@cᴏʟᴅsᴘᴇᴇᴅ meh
 
Noice, at least tqdm installed.
 
@wim to be fair it was 2009, it was just the first thing I found
 
@wim I'm looking at progressbar2 right now. There doesn't seem to be a way to display numbers - just an actual progressbar. Am I missing something?
 
wim
6:40 PM
read the docs. it's extremely configurable.
 
cbg all! anyone have any good links for some really solid regex courses? Maybe bonus points if its also semi python-centric?
 
wim
@cᴏʟᴅsᴘᴇᴇᴅ incorrect. I use it on 3.6 all the time.
 
@cᴏʟᴅsᴘᴇᴇᴅ it plays nicely with pandas too
well, claims to do so
pypi lists progressbar2 up to 3.5
 
wim
tqdm is good too. progressbar2 is more lightweight.
 
@wim I must be more tired than I thought. I am unable to find the option I need. Do you think you could whip up an example?
 
6:42 PM
@wim I tried installing it on python3.6 and it threw a Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-8l6qz2m5/progressbar/ at me
 
May be a mac thing
 
wim
what version of pip are you using
it should download the .whl, not the .tar.gz
 
works fine for me on debian
 
wim
if it doesn't collect the progressbar2-3.34.3-py2.py3-none-any.whl then your pip is fecked
 
6:44 PM
9.0.1. That could be it
I haven't upgraded since forever
 
wim
hm, nope, 9.0.1 is latest
 
Lol, then that means I have upgraded recently. Can't for the life of me remember when
 
wim
well, the latest version of pip is from 2016
 
Eh, I'm an idiot. I was pip installing progressbar and not progressbar2
 
plot twist: progressbar2 is the one that supports python 3
 
6:46 PM
Yeah, it worked
 
wim
the world of python packaging is a slow moving beast
 
hope you don't sudo pip install anything :P
 
plot plot twist, yum still python2. good luck wiring things for python3 and wanting to use yum
but I guess that is what the system python that you never should use is for
 
wim
@idjaw that seems completely unrelated
 
yes sorry....
 
wim
6:47 PM
yum will install python3 distributions from .rpm no problem
 
I jumped in and saw things being installed an python 2 and 3 and ranted about yum
I'm not talking about that
I'm saying that if your python command itself defaults to 3 it won't work
 
wim
oh
 
but nevermind...this is unrelated...don't want to derail
 
wim
if your python command defaults to 3 then your computer is probably broken in 1000 different ways
there is some crazy distro that does that. arch linux maybe.
 
yeah. I was getting creative with a wild centos deployment
found that out. It was fun
 
6:50 PM
Can confirm, python starts python 3 on Manjaro. Computer doesn't seem broken though.
 
I believe Ubuntu's python also defaults to 3
 
wim
> Intel is going with an opt-in approach—future processors will be able to reveal to the kernel that Spectre protections are present but disabled by default, and need to be enabled by the operating system.
 
At least 16.04
 
wim
wtf
 
DSM
@coldspeed: I don't think that's right. I run 16.04 in my vbox, and /usr/bin/python is 2.7.
 
6:55 PM
@wim isn't that the reason why Linus says that it's BS?
 
yeah my 16.04 defaults to 2 when I run python
 
Okay, it must be. I've seen it on someone else's ubuntu that way, and they could've just as easily aliased it
 
pyenv is the best damn thing to have ever happened to anyone using multiple pythons in their setup
 
> What this does not mean:
/usr/bin/python will point to Python 3. No, this is not going to happen (unless PEP 394 advocates otherwise, which is doubtful for the foreseeable future). /usr/bin/python and /usr/bin/python2 will point to Python 2.7 and /usr/bin/python3 will point to the latest supported Python 3 version.
 
0
Q: Using ProgressBar to Display Value Instead of Bar

inspectorG4dgetPart of my python program is to load the contents of a (csv) file into a list. Since this file is large, I'd like to add some progress data about it. This is what I'm doing right now: def loadFile(infilepath): answer = [] with open(infilepath) as infile: for progress,row in enume...

 
wim
6:58 PM
@AndrasDeak yeah, slimy
how many suits in the meeting where they made that decision
 
Some distros like Arch made python mean python3, which is why PEP 394 was written in the first place.
 
wim
11 mins ago, by wim
there is some crazy distro that does that. arch linux maybe.
 
DSM
I think I said something snarky once about Arch users and only remembered later that davidism might be one of them. Sorry, davidism! :-/
 
he can be your exception that proves the rule
 
7:03 PM
:|
 
re-cbg just saw a homework dump type question getting an answer ... I should have had a longer lunch :\
 
wim
hah, I thought they disregarded the PEP. I feel less snark knowing that it was the other way around
Good on them for pushing the envelope. If you're not living on the edge you're taking up too much space.
@inspectorG4dget let me get this straight, you want "Loading Data ... " to be printed before entering the loading context, and you want the progress bar to be displayed on the same line as the "Loading Data ..." string?
 
@wim correct
basically, I'm wondering if print(...) knows where it started in the sys.stdout buffer, so that I can use some escape sequence to go back to that point. I know \r won't, but perhaps there's something else... like a \R?
 
7:18 PM
How about \r and reprinting the "Loading Data" part?
Or am I misunderstanding?
 
DSM
g4dget mentioned earlier than in the real case the "Loading Data" part isn't static, I think.
 
wim
@AndrasDeak apparently that would take too much refactoring
but you're right, that's the simple common-sense approach
 
@DSM iscorrect
54 mins ago, by inspectorG4dget
is there a way to not do that? Because while Loading Data... is a static string, the actual message is not
 
DSM
Honestly I'd just live with the "\b" ugliness and wrap the whole thing up in a cm like wim suggested. As long as the ugly parts are localized and isolated, I can live with a few.
 
@inspectorG4dget Your question doesn't explain what the problem is with the code you posted. Which part of it doesn't work correctly? Or are you just looking for better alternatives?
Oh, you made it a question specifically about progressbar. My bad.
 
wim
7:24 PM
@inspectorG4dget I refuse to believe you read the contents of the curses link in the ~1 minute between me posting it and you replying. Why don't you try it yourself first, and if you haven't figured it out yet you can ask again after attempting. — wim 1 min ago
don't usually get spoonfeed requests from 50k+ rep users
 
@Rawing well, Wim mentioned that progressbar was the way to go, so I asked it specifically about progressbar. But in all honesty, I'm just looking for a better solution than '\b'*len(mystring)
 
wim
sorry to be harsh, but seriously man ... give some effort!
@DSM it's fundamentally broken to do it like that
you need to wrap streams, else the bar interferes with e.g. logging output or anything else writing on the stream
 
Then you're mistaken about my abilities in reading and extrapolating from data to ingest content
 
wim
unless you can guarantee you have exclusive access on the stream, it's really complex and difficult to get right.
 
7:39 PM
@wim ah, I see, thanks
I missed what DSM noted
 
@AndrasDeak sorry, I just saw this
 
it's fine :)
 
I guess part of me wonders whether print(...) internally knows where it started in the stdout buffer. That would make sense, given that I should be able to query sys.stdout.tell() Whoa! I can't. Why is sys.stdout unseekable, when '\r'and '\b' work as (limited) seekers?
Not sure I understand the explanation
 
naive guess: \r and \b are relative while .tell() would be absolute?
 
that seems to make sense, and one can make the claim that stdout can't be seek'd to previous lines. But from what I've read, it seems to be more of a "minimalism" thing
 
7:52 PM
Fun fact: Python is horribly unsuitable for executing Ackermann's function.
 
... which is probably why output is buffered until \n is seen
heya Martijn! Long time
 
wim
do you know what TTY means?
it's a freaking teletypewriter
 
I know some of those words
 
wim
to seek means you have to pull the paper out of the machine and get the white-out
 
def ackermann(m, n):
    if not m: return n + 1
    if not n: return ackermann(m - 1, 1)
    return ackermann(m - 1, ackermann(m, n - 1))
 
wim
7:55 PM
>>> import sys
>>> sys.stdout.isatty()
True
so, good luck with that (you can wrap the streams, but seriously, just refactor your stuff)
 
oh?! I always read that as "is at ty" and wondered "what the heck is a TY?"
 
not a linux user? :)
 
So ackermann(0, <anything>) is fine. ackermann(1, 0 - 998) is generally fine too.
 
wim
^ sys.stdout
 
rofl! not enough of a wizard. Systems was never my thing (I just knew enough to get by) - AI/algo all the way
 
7:57 PM
@MartijnPieters the fact that the wikipedia articles makes good use of uparrow notation suggests that there are few languages well suited for that function
 
argh! I might just have to live with the horrible UX and use a new line to display progress...
 
@AndrasDeak youtube.com/watch?v=i7sm9dzFtEI will tell you that a modern PC with any language is ill suited..
 
hehe :) thanks, I'll take a look
 
alright, rhubarb folks. Catch y'all later :)
 
rhubarb
 
7:59 PM
Thanks for all the helpmagicks :)
 
00:00 - 20:0020:00 - 00:00

« first day (2657 days earlier)      last day (2305 days later) »