« first day (3138 days earlier)      last day (1803 days later) » 

12:54 AM
Haha @ParitoshSingh which guy are we talking about here?
 
 
1 hour later…
2:05 AM
cbg
 
 
1 hour later…
3:09 AM
rbrb
 
3:43 AM
-2
Q: Multiple plotting using loops in python

binzI have x data as: x_data:[[-210.99],[210.666],[553.211],[123.332],.....[234.121]] If I have n columns then y1,y2,...yn should be plotted with x_data so that within one graph n data can be visualized. I am also using slideshow for visualizing a clear view of each column data. For appearing data...

 
4:04 AM
@binz crqzy indentation, is this not a duplicate of stackoverflow.com/questions/21300603/…?
(no particular inssight, just my first google hit)
 
 
2 hours later…
6:01 AM
cbg
(almost forgot)
 
6:14 AM
The idea that the signature of a function should depend on user input appears deeply flawed. What are you actually hoping to accomplish? See also XY Problem. — tripleee 8 secs ago
am I missing something there? ^
 
@U9-Forward they asked here first
 
6:36 AM
@tripleee I'mnot sure it's inherently wrong but they could just use an iterable-valued input, not even splats needed
For instance you pick points in a GUI, then a callback that does something with the points sort of has a signature depending on the number of points. The actual correspinding python function shouldn't though.
 
variable-length signatures I can understand and live with, but the OP seems to want to define a new function with a suitable signature for the provided input
 
No, I think checkboxes define the signature of another function, probably a callback. They're using matplotlib widgets.
 
read the description
 
aah, messages not ascertaining to the rules of this chat are moved there, understood
 
is this reality or fiction? I guess fiction
 
7:17 AM
@vaultah ^^ :D
 
well from the "89.5" limit and "for humans" hinting to requests, I guess it is fiction
 
cbg
 
                manufacturersInRowI = [(rowI[4].value or "")]
How can I set empty array if rowI[4].value = none?
not using if
 
more details please, like manufacturersInRowI is a list, a pandas dataframe, a numpy array etc etc
 
@QuicoLlinaresLlorens replace "" with []?
 
7:24 AM
and is rowI an object of some sort?
 
@Aran-Fey won't be that a list in a list?
 
ah, I misunderstood
you can't shouldn't do that without an if
 
rowI[4].value or []
 
I mean:
if (rowI[4].value == none) {
  []
} else {
  [rowI[4].value]
}
;)
 
manufacturersInRowI = [rowI[4].value] if rowI[4].value is not None else []
an 'or' wont work here, you have to use ternary or the if else you showed
 
7:27 AM
thanks
 
since it will be a [None]
 
>>> value = 'not none'
>>> value is not None and [value] or []
['not none']
>>> value = None
>>> value is not None and [value] or []
[]
 
I stand corrected
 
did he meant 'none' as in a string, or None as in NoneType?
 
NoneType
I think @Arne response is correct
 
7:29 AM
Correct but don't use that
Are you allergic to ifs?
 
hahaha
it was just to have it in one line
 
conditional expressions are on one line
And one-liners are overrated
Write readable code
 
emphasis "which can be read by others"
 
-2
Q: Multiple plotting using loops in python

binzI have x data as: x_data:[[-210.99],[210.666],[553.211],[123.332],.....[234.121]] If I have n columns then y1,y2,...yn should be plotted with x_data so that within one graph n data can be visualized. I am also using slideshow for visualizing a clear view of each column data. For appearing data...

please help to fix thsi
 
8:05 AM
@binz One of the problems here is the tagging. I don't use any of the GUI libraries like tkinter or pyqt but I assume you're using one (maybe neither of those) but you've not added a tag for it. "graph" and "multiple columns" are far less meaningful than the libraries you're using
 
8:16 AM
stackoverflow.com/questions/56208075/… was "No MCVE" and now the title is edited to say "solved" but with no solution
 
there's an EDIT at the bottom with a purported solution
(not anymore, I rolled it back)
 
The proposed solution was kinda beyond pointless. It's not raising an exception presumably because the code it triggers runs in a loop. You can't have view functions that don't return
 
not with that attitude
 
I'll do better to sweet talk my libraries in future :)
 
What could I have done to get a better response to my question?
[Why Keras equivalent solution for Google MLCC has a different loss than the TF equivalent?](https://stackoverflow.com/questions/56214268/why-my-keras-equivalent-solution-for-google-mlcc-has-a-different-loss-from-the-t) asked 4 hours ago?
As of now 16 views, no answers, no votes
 
8:27 AM
wait more than 4 hours
 
@AndrasDeak Sure, I will. But why do you think waiting for 4 more hours would get me views/answers?
 
It's quite a niche field and asks for comparison across 2 libraries within it
 
I didn't say wait 4 more hours, I said wait more than 4 hours. You have the main language tag which is the primary reason for low views. I suspect your question is very specific so there are few experts who even click on it.
 
@AndrasDeak Yes that what I wanted to hear. DO you think I should edit it in a way to get more views?
 
I have no idea about the tech you're using, so I can't tell.
 
8:34 AM
@AndrasDeak No issues. Thanks anyway :-)
 
^ closed
 
9:16 AM
cbg
 
@AndrasDeak there's so much salt in there, wow :D
I approve of the writing style
 
9:44 AM
If a packaging tutorial starts off by recommending a package structure like this, is it safe to assume that it sucks?
fancy_game/
    models/
        player.py
        monster.py
    audio/
        mixer.py
        effects.py
    main.py
 
cbg
curious, why say that?
sounds like a perfectly well organized structure to handle a fancy_game no?
or am i missing something
 
Well, fancy_game looks like an importable package to me - and main.py looks like an executable file to me. So that structure is just begging for a "attempted relative import beyond top-level package" error
 
Is it a package without __init__.pys? Or something something namespace packages?
 
i presume the guide will talk about adding* inits (and looks like i need coffee)
 
ah, __init__.pys are added to the subfolders (models and audio) later
and fancy_game isn't intended to be importable
 
9:49 AM
could you link me this guide?
 
so... this'll end up installing a models and a audio package?!
# main.py
import audio.player
 
because that structure is eerily close to how i presume its meant to be done, and im actually creating a structure similar to that atm. if im wrong so far... then i dont know what to do :P
 
^^ now I'm convinced I should close this tab
 
hehe
close as no MCVE
 
it'd be correct (as far as I know) if there was a 2nd fancy_game directory that contained audio and models
fancy_game/
    fancy_game/
        models/
            player.py
            monster.py
        audio/
            mixer.py
            effects.py
    main.py
    tests/
    docs/
^ that's how I structure my projects
 
9:55 AM
and you don't import player from audio
 
well, not like that. More like from ..models import player
 
10:08 AM
I recently got a star on one of my github repos, so I've been re-evaluating if I want to actually properly publish any of my stuff... but I guess I still can't be arsed
 
hm
i think your structure is different only because you're using 1 more level of segregation though, right? as in, if i didn't really have tests or docs prepared, and wanted to get up and running, then your structure and theirs would be kinda comparable? Having said that, i can see that for a proper repo, yours makes sense.
 
@Aran-Fey wondering about making everything, private, eh? ;D
@ParitoshSingh if there's no enclosing fancy_game directory then it's not one package
models and audio would be two sibling packages unless I'm mistaken
 
even if there's an init in the root?
fancy_game/
    models/
        player.py
        monster.py
    audio/
        mixer.py
        effects.py
    main.py
 
I'll let Aran answer that
 
if i had an init in the same level as the main, its a package right?
that's my understanding atleast so far
 
10:12 AM
at least things like setup.py would have to be one level higher, outside fancy_game then
 
that's fine for the most part as far as I can tell, but people often have problems when they put executable files (like main.py) inside importable packages. I'd rather move the main.py outside
 
I guess that's covered by "executable files"
 
i see. looks like i myself actually need to create another level of hierarchy then!
 
note that my packaging instinct is on the level of "one out of two packages I wrote is named with an initial number"
 
@ParitoshSingh you should add that one level in order to associate your project with files that are not part of the python codebase
setup.py is one of them, other usual suspect are things like tooling configurations (mypy, flake, tox, ...), or a folder with scripts that can be useful in conjunction with your project but should not be installed
 
10:19 AM
i see. I dont really have any of them at all. i suppose the caveat here is that this is meant to be just a way of me organizing our codebase, but every app and interaction is via imports fully under our control.
fwiw, the current "version" of how things were done was basically dumping every single .py file in a single folder.
So, its a...lets just say, "fun" process of trying to break this mess into something easier to manage
 
and, imo most importantly, you can separate your test code from your package, which means that you get the option to test your code as an installed package, and not a bunch of code files somewhere (good way to find path errors), and you don't install you test code (because why should you? it doesn't do anything except potentially cause bugs).
@ParitoshSingh if you don't have users, things are a lot easier of course, and there is no need to think a lot about structure
 
aye, makes sense.
 
why anyone would want users is beyond me
 
single biggest mistake in every projects history, usually
"we had a good thing going, but then we made it accessible"
 
"and now the world is ending"
 
10:32 AM
@wim is the idea that these vulnerabilities only matter for servers, and desktop users are typically not subject to such attacks anyway?
 
the worst part about publishing a project is that you can't arbitrarily change its public interface anymore :(
well, not without disgruntling your user base
 
just have a deprecation cycle with length of 1 minor version
or release major versions often ;)
or release it as public beta where you aren't bound by promises (the first serious suggestion)
 
that's a good idea, actually
 
10:52 AM
Hi guys I have a question
I am able to get unique employee names using np.unique(employee_entries) for instance. Then I plan to use a for loop to actually get a plot for each employee in matplotlib
 
Okay?
 
employee_list = data_agency_array[:,0]
Then I want the x-axis to be the date
And the y-axis be the amount paid for instance
 
Okay.
pyplot has documentation/howto/whatever on plotting with dates
 
Yeah probably gonna have to look it through :/ looks like a long answer
 
yeah, you have to read documentation if you want to use a library
 
10:55 AM
cat = ["bored", "happy", "bored", "bored", "happy", "bored"]
dog = ["happy", "happy", "happy", "happy", "bored", "bored"]
activity = ["combing", "drinking", "feeding", "napping", "playing", "washing"]

fig, ax = plt.subplots()
ax.plot(activity, dog, label="dog")
ax.plot(activity, cat, label="cat")
ax.legend()

plt.show()
 
it's as exhausting as having legitimate reviews on an online auction site etc. etc.
 
Is what I read in the document for categorical plotting, however, the activity strings are true for both cat and dog. But it's not the same in my case
Anyway nvm it's a long thing lol. Gonna go readin and tryin
 
good idea
 
lol didn't realize you were talking about my e-commerce thing
 
the term "e-commerce" eluded me
 
10:59 AM
and the sarcasm
gotta say i love how interactive matplotlib documentation is
 
Yeah, it's nice. Takes some time to get used to the structure but it's pretty good.
 
other libraries drain all my brain juice before i get anything sorted out
trying to decipher everything
 
numpy and scipy are also awesome when it comes to documentation
 
surprisingly i never tackled numpy yet but i think i should
given matplotlib uses numpy arrays often
How would you make 3 plots on 1 axes in this simple array?
sample_data = array([[mark, Timestamp('2019-05-07 00:00:00'), 500],[john, Timestamp('2019-05-05 00:00:00'), 750], [kevin, Timestamp('2019-05-05 00:00:00'), 850 ]
Categories are using the name, x-axis is the time, and y-axis is the value
It will be a single dot obviously in this example lol
 
11:17 AM
@Aran-Fey Yeah, like greenlet which hasn't released a version 1.0.0 yet (in 10 years of usage btw), so they aren't bound by things like deprecation cycles or public APIs. It's a real joy to work with them.
 
I'm trying to get my head around the best approach to my problem. I have an inventory app running on some server (Debian) and available across the company network. In our stores we have a cheapo barcode scanner that just writes bardcode numbers to a local file (Windows) and can't do anything else. Somehow I need to link the two (TBC)
 
but yeah, a public beta is a good idea, unless it overstays its welcome
 
The only way I can think of linking them is to have a python script on the Windows PC that starts on boot, reads the file continuously in 1 sec intervals and pushes new numbers to a Flask endpoint. This seems shakey at best. Is there something I'm overlooking?
 
@Arne If I ever release a module for public use, it's definitely going to have a big fat "I suck at programming and will therefore change the public interface at least once a week" disclaimer
 
didn't you release a bunch of browser scripts that quite have quite a few users?
modules can't be too different
 
11:20 AM
userscripts are (for the most part) pretty small projects
and they're used by end users, not by programmers
 
not necessarily* programmers :-p
 
@roganjosh as long as mistakes get fixed on restart, anything seems good enough for windows
(i also don't know a better approach)
 
Pet peeve of the day: Python not making use of any of the classes defined in the io module.
>>> io.BufferedIOBase.__subclasses__()
[]
^ ugh
 
I guessed it was a long shot :(
 
basically, the problem is that the windows machine needs to write/send info somewhere where you have access to it
if the machines are on the same network, you could also perhaps just ask the machine to write to a shared drive of sorts
 
11:29 AM
@roganjosh On a *nix system, you could just wait for file notification events, rather than polling the barcodes file for changes. On Windows, file notification can be a little tricky if the file is on a network drive, but there are some suggestions here: stackoverflow.com/q/182197/4014959
 
You've pre-empted me, PM :) Something has to be better than continuous reading of the file
 
@Aran-Fey "The API for this module is not yet finalised, any suggestions are gratefully accepted".
 
I can use that in addition to the warning, but not as a replacement (:
 
@ParitoshSingh I considered that but I also considered how much people interfere with the shared drive, so someone will inevitably come along and just delete the file.
 
@roganjosh Yeah. If you can't get proper notification to work, it's much cheaper to do a stat call to see if the last modification timestamp has changed. One of the answers on the linked question mentions that technique.
 
11:39 AM
I think that's the way forward and keep the file local and buried away on the PC in stores. Thinking more, I do need to respond to a change; post to an endpoint and on a 200 HTTP code I'll wipe the file
At the expense of having the system split in parts across PCs, at least it removes the burden on the app to monitor the file
 
12:07 PM
What's the frequency at which you need to read the barcodes
 
Barcodes will be scanned at arbitrary intervals, but the person scanning them will expect them to appear on their web interface basically instantly, so 1 second is probably the longest reasonable interval for reading the file
 
barcode readers I worked with had a usb port, and I used to read data over serial port
 
The scanner writes to a local file automatically
 
what kind of a reader is this, what is the interface between windows and the barcode reader, aah so it is automatic, what about a message queue approach
every write will trigger a message sent to an event loop on your linux pc, where the message is recieved, something like rabbitmq, they have a good library in python
aio-pika for async, and pika for synchronous
I am using it to talk to actual hardware in my company
like IO modules etc
or any pub sub approach for that part
 
Not a bad suggestion but I wonder whether that just makes things overly complex
 
12:13 PM
 
What I cannot get around is a script on the PC connected to the scanner; my option then is either for that script to push it to a flask API or pub to a queue
 
the listener can listen to changes in the file
push it to a flask api where, the data goes to a database?
u have a flask webserver running on linux?
 
Why does the x-axis show a huge range for the dates when I only have 1 week worth of dates lol. Can pandas._libs.tslibs.timestamps.Timestamp date types work for matplotlib?
 
It will do once I've written the API, I'm just at the stage of trying to work out the best approach
Yes, the flask application is available across the company network
 
have a linux vm running on windows with that file shared between the two OS
that way you are dealing linux to linux, or just a linux container like a docker
 
12:16 PM
That's even more complicated :/
 
Who’s going to trigger that api call
 
The script running on the local PC that is monitoring the file for changes
 
cbg
 
cbg
 
On windows side, api call, a message over a message queue, both are equivalent in some sorts, the point being is it a temporary thing or a long term solution
 
12:19 PM
It has been a while since I did Windows development, but .NET has an API to monitor the file system for changes
Perhaps the win32 extensions for Python have some access to this
 
I actually switched from flask to message queues in my work to talk to hardware setup, since I can get object persistance if I assume my hardware device as a class
cbg
 
@PaulMcG interesting, I will have a look down that avenue, thanks
@DeveshKumarSingh Flask is integral to the project. The entire system is a web app that needs a user interface
 
Okay so instead of re inventing the wheel you want to use what is available, makes sense
 
The barcode scanning is a crucial, but tiny part of it. Scan an item in stores, it comes up on the screen, you click to either check it in (a delivery) or check it out, so you can keep track of inventory
 
Wonder what does companies like walmart do, they also have barcode scanners and items they need to keep track, perhaps they use cloud
 
12:24 PM
I bet their barcode scanners don't just write the data to a file
 
Yeah, this is a crap £50 thing and I can't do anything about that
 
Can you change the filepath, at least?
 
And I assume only way an item goes out of the store in your case by scanning via that barcode, maybe you are lucky and their is a python library for that scanner lol
 
Yes, I can configure that thankfully :)
 
Or a C/C++ binary you can wrap around python so you have more control than writing to a file
 
12:26 PM
Hi
how to convert jason object into dataframe in python?
 
Use the json library to turn your json data into a native Python object. Then use pandas to turn it into a dataframe.
Hmm, or maybe pandas has its own json support? That would save you a step
 
You can try json_normalize
You haven't said anything about the structure of the JSON so mileage may vary on that approach
 
@roganjosh Maybe if it's really crappy you can inject arbitrary shell commands into the file path.
 
Are we sure this is JSON? Note that the poster's name is "Jason" and is asking about a "jason" object - maybe he is converting himself into a stream of intelligent data, to be perpetually stored in the interwebcloudthing?
 
Jesus Christ it's Jason Bourne
 
12:31 PM
I get that reference
 
@Kevin This sounds like the beginning of a devilish plan, but not one I'd know how to even start implementing
 
Me neither.
 
Oh, well we'll put the World Domination back a bit on the TODO
 
@roganjosh do you happen to know the company/model/make of your barcode scanner
 
Koamtac <some_model_number>. I'm at home today and it's on my desk at work
Look for the cheapest model. That'll be the one
But I think you're probably going out of your way for nothing here. What are you expecting any library to do?
 
12:36 PM
Haha because a part of my job is to have these hardwares from different companies and get them to work on centos linux with python
 
I think the only connectivity it has is bluetooth so it's always going to write to the PC, it's not gonna do anything over a network
 
It would be nice if the manufacturer's webpage provided do_exactly_what_rogranjosh_needs.py as a poorly advertised download, but I'm not optimistic
 
So was thinking maybe a better way, use a library to talk to it etc, but it’s fine
I have used swig to write C extensions and pythonnet to wrap windows dll for python, it ain’t pretty
 
There's a Python wrapper for the win32 api on Pypi, although I always forget its name. Pywin?
 
I think the simplest really is a Flask API. The code that has to run locally checks modified timestamps every second. If it sees a change, it reads the code and pings the API on every cycle until it gets a 200 code, then wipes the file. That code should be simple enough that I can just leave it be on some remote computer and not worry too much
 
12:40 PM
I'd love to install pywin and try it out but apparently SSL is required
Not sure whether pywin is doing some weird nonstandard download approach, or if all pip installs have used ssl in the past and this one isn't working because IT decided to lock down my computer some more
 
Were you trying to inject arbitrary shell commands in file paths again?
 
I could just close Python 3.7 and boot up Python 3.6, where I already have pywin installed, but that seems like a step backwards.
@roganjosh No >_>.... Yes
 
Sure the KISS approach:) but stress test it a lot
 
Well it occurs to me now that there's a really simple race condition in my approach so I'll have to think about that a bit
 
How many scanners are we talking btw
 
12:44 PM
1
 
That’s it 1 scanner and one pc where rest api posts
 
The race condition comes with a failed API call and items still being scanned. I can't just indiscriminately wipe the file on the next successful API call but I can fix that
 
Have some buffer, perhaps a retry count for each succesful api send
 
Ok, I relented and tried it in 3.6. The final code block at timgolden.me.uk/python/win32_how_do_i/… is 100% "works on my machine" certified. (once I add parentheses to the print statement)
 
And save all barcodes you couldn’t send and send them at the end of day just as a backup plan
 
12:47 PM
Determining whether it can monitor a file on a network drive is left as an exercise to the reader
 
@Kevin Not an issue, I will keep the file local on the PC because nothing is safe from meddling on the shared drives. Thanks for testing it out for me :)
 
Today's puzzle is rated exceptional / 10:
# Write a function that fulfils the following criteria:
#
# 1. The function ends with `return None`.
# 2. If `return None` is changed to `pass`, the function's behavior changes.
 
 
correct
maybe the hint was too obvious
 
It was subtle enough that I didn't notice it until after I was already on the right track
 
12:58 PM
that makes it a rather useless hint, I suppose
 
It's like reading a mystery for the second time and you notice that an innocuous choice of words in chapter 1 was actually foreshadowing
 
1:21 PM
I've got half a mind to collect my riddles (and the riddles of other consenting users) into one convenient page on the SoPython wiki. I just need to figure out how to black out code blocks unless they're moused over.
I can already black out plaintext using the .spoiler:not(:hover) selector I stole from the Puzzling Stack Exchange site. But code blocks get a bit mangled by SOPython's markdown engine so it's not so easy to stick them in a span with a class of my choosing
 
Not so exceptional: pastebin.com/kP7ZZSRh
 
May 7 at 9:30, by roganjosh
Is there a use-case for just try/finally? I got picked up in the past for saying that you can't have a try without an except and, true enough, you can just have try/finally, but I can't think of a use
Well, now it is answered :)
 
There used to be, before with
 
Yeah, we determined it was a "poor man's context manager". But my memory was triggered when I saw your code :)
 
@Kevin If you do figure it out, feel free to include mine
 
1:26 PM
Ok, thanks
 
@roganjosh "poor man" = "pre Python 2.6"
 
@PaulMcG Yeah, it doesn't really require exceptions. I just figured that was a nice subtle way to provide a hint, because without a hint this is basically impossible to figure out if you don't already know the solution
 
I didn't even know what programming was pre-2.7 and Python 3.something was out so old code bases are like cave paintings in my timeline
 
hey i'm tryint to install flask_upload i keep getting this error
ERROR: Command "python setup.py egg_info" failed with error code 1 in C:\Users\Rick\AppData\Local\Temp\pip-install-gh0lgolh\flask-upload\
 
there's probably more to that error
we've had plenty of bad debugging sessions with you so you'll have to do more on your own
 
1:33 PM
 ERROR: Complete output from command python setup.py egg_info:
    ERROR: Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Rick\AppData\Local\Temp\pip-install-gh0lgolh\flask-upload\setup.py", line 56, in <module>
        version=read_version('flask_upload/__init__.py'),
      File "C:\Users\Rick\AppData\Local\Temp\pip-install-gh0lgolh\flask-upload\setup.py", line 50, in read_version
        fd.read(), re.MULTILINE)
      File "c:\users\Rick\appdata\local\programs\python\python37\lib\re.py", line 183, in search
pip install flask_upload
that is what i wrote in the command port
@AndrasDeak i'm not that bad , only 2 times that happen
 
flask_upload or flask_uploads?
 
lol sorry that is true
thank you
i remember trying both multiple times but maybe it was a bad connection or something
 
trying to install things with names pulled out of your yam will eventually give you malware
 
@AndrasDeak lol you are right
 
1:46 PM
PyPI lists both Flask-Upload and Flask-Uploads
 
yes, neither maintained very well, I suspect only one of those works for python 3
if only one were valid I suspect pip wouldn't have tried installing a non-existent package
 
flask-uploads is starred in the extension list so it should be maintained
 
Morning all o/
 
perhaps it doesn't need much maintaining
cabbage
 
Well, saying that, I wonder what "approved extension" means practically. Maybe just that it doesn't break stuff but not necessarily that they'll keep it up to date
cbg
 
1:53 PM
Is there anything other than minidom that you all prefer/recommend for xml shenanigans?
 
cbg
 
im confused, code in finally block should run after code in try/except block, no?
 
yeah
but a function can only have one return
and finally strongly promises that it gets executed
that was a TIL for me as well by the way
@ParitoshSingh or are you confused by something else?
 
@biggi_ ElementTree is the preferred XML module, I believe. But XML is so 20th century...
 
@Arne nope, just that. it's a TIL but it doesn't quite satisfy me
Say, how about this
def test():
    try:
        raise Exception
    except:
        try:
            raise Exception
        except:
            return 10
        finally:
            return "innerfinally"
        return 100
    finally:
        return "outerfinally"
 
1:59 PM
let the two finallys fight it out I guess
 
haha. yeah. In this case, a "strongly promised" innerfinally should be hit before an outer one no? Except, the results indicate it uses the outer one.
 

« first day (3138 days earlier)      last day (1803 days later) »