|
HumbleBundle is offering a bunch of Python books (mostly newbie/intermediate level) on the cheap - https://www.humblebundle.com/books/python-book-bundle
|
# ? Apr 6, 2017 09:05 |
|
|
# ? May 16, 2024 18:11 |
|
shrike82 posted:HumbleBundle is offering a bunch of Python books (mostly newbie/intermediate level) on the cheap - Seems like a good stack of stuff for up to $15. I checked a couple of the prices on Amazon and they were all at least $20 each, albeit an ebook sometimes isn't as convenient as a paperback
|
# ? Apr 6, 2017 10:40 |
|
The Python documentation says "Long integers are now stored internally either in base 2**15 or in base 2**30": https://docs.python.org/2.7/whatsnew/2.7.html#optimizations What does that mean? I have never seen "base 2 to some power" used before. 2**15 = 32,768 and I really doubt this means that Python uses a base-32,768 number representation.
|
# ? Apr 7, 2017 04:36 |
|
I haven't looked at the implementation and I don't know anything about how such things usually work, but having read that I'd guess that's exactly what it means. With a system that can handle goofy stuff like int("9"*100000) it seems reasonable that it might make sense to convert to some ridiculous base like that so that a 16/32bit int is a digit. My guess would be they only use 15/30 bits of the number so that they can do normal math with the ints, peek at the most/two most significant bits, and handle carrying into the next digit with speed. Uh I guess I can't think of why 30 instead of 31 off the top of my head, but I'm sure there is some good reason. Or I could be totally off base. breaks fucked around with this message at 06:46 on Apr 7, 2017 |
# ? Apr 7, 2017 06:40 |
|
oliveoil posted:The Python documentation says "Long integers are now stored internally either in base 2**15 or in base 2**30": https://docs.python.org/2.7/whatsnew/2.7.html#optimizations The general programming thread is a better place to ask this probably.
|
# ? Apr 7, 2017 14:47 |
|
oliveoil posted:The Python documentation says "Long integers are now stored internally either in base 2**15 or in base 2**30": https://docs.python.org/2.7/whatsnew/2.7.html#optimizations http://stackoverflow.com/questions/9860588/maximum-value-for-long-integer
|
# ? Apr 7, 2017 14:51 |
|
I've been reading Fluent Python based on this thread and Eela6's recommendation. Is there a better/more Pythonic way to do this? I'm parsing 'yum list <package>' for Installed and Available packages.code:
Python code:
|
# ? Apr 7, 2017 20:55 |
|
I'd indent the other conditions and invert the any to get rid of the pass, otherwise it looks fine to me.
|
# ? Apr 7, 2017 21:06 |
|
HardDiskD posted:I'd indent the other conditions and invert the any to get rid of the pass, otherwise it looks fine to me. Fluent Python has got me looking for tricks everywhere! Python code:
|
# ? Apr 7, 2017 22:01 |
|
You can even drop the list brackets within any() as most functions that take an iterable work with a generator expression too in 3.x:code:
|
# ? Apr 7, 2017 22:19 |
|
onionradish posted:You can even drop the list brackets within any() as most functions that take an iterable work with a generator expression too in 3.x: I'm working with minimum python 2.4. I even have to implement my own any. Tigren fucked around with this message at 23:58 on Apr 7, 2017 |
# ? Apr 7, 2017 22:22 |
|
Wouldn't it be better to use a dictionary of allowed strings mapping to their lists? So instead of checking the line is in an allowed string, and then comparing it to those strings again by hand, you can just look up each line in the dictionary and append to its related list, with an if value or try/except bit for handling the missing lines (Or at least use a constant if you're comparing the same string literal multiple times, for your health!)
|
# ? Apr 7, 2017 23:40 |
|
Edit: nevermind I see what you're doing. Carry on.
SurgicalOntologist fucked around with this message at 00:48 on Apr 8, 2017 |
# ? Apr 8, 2017 00:45 |
|
I am completely baffled by this thing I have just discovered. I am loving around with making NNTP proxies (yeah yeah, don't start) and I'm modifying an old package called Papercut which came with a buggy mostly-formed proxy hidden in there as a plugin. The basic idea is that this simply uses nntplib to re-create the requests the server receives and then reformat them back into the raw NNTP packets and send them back. I ran into an issue where articles would become slightly corrupted while doing this. I was making nntplib.NNTP.article() requests. This function returns a 4-tuple, where the 4th item is a list containing the lines in the article. I started comparing this list of bytestrings between raw nntplib requests to the underlying NNTP server vs my proxied server, and found a few lines in a few articles that were subtly different. In particular, if the line bytestring began with the two bytes 2e2e (hex format, 2e==".") both the proxy and the raw NNTP query would receive the line properly, but after being re-sent through the proxy you would lose one of those bytes, making the total string one byte shorter with no other changes. After testing this on a large number of articles I have not found any other corruption at all. Why on earth is the SocketServer.StreamRequestHandler or the nntplib slightly mangling my data when there is a newline followed by two periods? I threw in a loop to add an additional period to any strings starting with two periods...and it worked, no more corruption. Code to pull data and reformat into one long bytestring Python code:
Python code:
RFC977 posted:Text is sent only after a numeric status response line has been sent I guess this answers why I have to do this. The nntplib client has stripped extra periods from the lines, and I need to regenerate them. I guess I don't need to post this, but .
|
# ? Apr 8, 2017 01:02 |
|
What's a good library for drawing an array of pixels? They would change over time (I'm not animating figures, though), and I plan on eventually feeding into some LEDs, but for now I'd rather prototype without wiring up a bunch of LEDs. I've thought of just doing it with Flask + Javascript but I'm wondering if there's some other good solution. I'm semi-willing to use some other language, but Python's the language I use daily so I'd rather just stick with that unless I can't find an adequate solution.
|
# ? Apr 8, 2017 01:23 |
|
Ghost of Reagan Past posted:What's a good library for drawing an array of pixels? They would change over time (I'm not animating figures, though), and I plan on eventually feeding into some LEDs, but for now I'd rather prototype without wiring up a bunch of LEDs. I've thought of just doing it with Flask + Javascript but I'm wondering if there's some other good solution. numpy for the array and matplotlib imshow() to render?
|
# ? Apr 8, 2017 01:44 |
|
Ghost of Reagan Past posted:What's a good library for drawing an array of pixels? They would change over time (I'm not animating figures, though), and I plan on eventually feeding into some LEDs, but for now I'd rather prototype without wiring up a bunch of LEDs. I've thought of just doing it with Flask + Javascript but I'm wondering if there's some other good solution. https://python-pillow.org/ Edit: How many LEDs are you talking about by the way? Are you planning to use Arduino, Raspberry Pi, or something else?
|
# ? Apr 8, 2017 01:45 |
|
huhu posted:https://python-pillow.org/ OnceIWasAnOstrich posted:numpy for the array and matplotlib imshow() to render? praise be to numpy
|
# ? Apr 8, 2017 01:59 |
|
Tigren posted:Fluent Python has got me looking for tricks everywhere! 1) There is a potential future problem that results from the string literals being duplicated in two different places. 2) What happens if package_name is seen before either of the strings? 3) Why is the if any line needed at all?
|
# ? Apr 8, 2017 02:04 |
|
breaks posted:1) There is a potential future problem that results from the string literals being duplicated in two different places. Guess I should have posted more of the code: Python code:
2. package_name won't be seen before either of the strings, but if it is, add_to is set to available to start. 3. So I don't capture lines that don't have one of those three allowed strings. My user will pass in a package_name and get a list of available and installed packages matching that name.
|
# ? Apr 8, 2017 02:10 |
|
You're missing an 's' in the second installed packages line which is not immediately going to cause a problem but should probably be cleaned up. You could turn the last else into an elif and then the any line is redundant. Then your list can be turned into a list of categories instead of a list of categories and package names, and you can solve problem 1 by only having the category names in one place. As someone else suggested that place could also be a dict mapping category names to lists that you will append to.
|
# ? Apr 8, 2017 02:41 |
|
Ghost of Reagan Past posted:32x32 and a Pi for the prototype. We'll see whether a Pi can do what I actually have in mind at the end of the day, but I'll get there when I get there. But on a computer I can have a much higher resolution I'm probably gonna start with that. I'm okay with this taking a lot of iteration and work. Definitely go Python. It works very well with the Pi, if you didn't already know that. If you got money to burn, a guy at my hackspace built a really nice Neopixel 10x10 grid. https://www.adafruit.com/products/1138
|
# ? Apr 8, 2017 03:31 |
|
Tigren posted:3. So I don't capture lines that don't have one of those three allowed strings. echoing the dict suggestion above Python code:
|
# ? Apr 8, 2017 06:39 |
OnceIWasAnOstrich posted:numpy for the array and matplotlib imshow() to render? A uint8 array of dimensions [m, n, 3] works well to represent images on a pixel level. The library skimage (installed by default in anaconda) works well for basic image manipulation as well. E.G: Python code:
Eela6 fucked around with this message at 16:57 on Apr 8, 2017 |
|
# ? Apr 8, 2017 16:54 |
|
Can someone explain to me what's going on here:Python code:
Edit: nvm, it's pretty obvious. Space Kablooey fucked around with this message at 18:31 on Apr 10, 2017 |
# ? Apr 10, 2017 18:25 |
|
At work, I typically deal with small datasets pulled thru financial APIs (100K records at most) that I interact with using numpy/pandas/flat files. I'm hobby tinkering around with IoT stuff on a Raspberry Pi to log metered data (e.g., temperature, humidity, MACs connected to home wifi) as well as logging other stuff. I'm using ThingSpeak and it works well for simple logging. What's a solution for storing something that generates ~3K records every 5 minutes? I'd default to python-sqlalchemy-sqlite with the DB file backed up every day to DropBox. Is there a nicer free(-ish) online solution?
|
# ? Apr 11, 2017 05:07 |
|
Any of you dudes use an assertion library? I've looked at Sure and PyHamcrest and would be interested in alternatives, especially stuff with a different philosophy from those since they are a bit similar. This is for QA work, main goals are informative and readable errors and readability of the assertions themselves wrt less technical people.
|
# ? Apr 11, 2017 05:55 |
|
Temperature and humidity tracking automatically makes me think of a time series database. I haven't used it but I've heard of opentsdb. Or even good old RRDTool. You could probably set up your own service for either of those on a 5/month DigitalOcean server. But then again, maybe a time series database isn't what you want, it's hard to say without knowing what you'll do with the data. No matter what you do I bet the DigitalOcean server idea would serve you well if you're really wanting a cloud/remote thingy. InfluxDB is another good option, I'm pretty sure there's hosted versions of that out there if you didn't want to set up your own server. Then you could do sweet visualizations with Grafana.
|
# ? Apr 11, 2017 06:03 |
|
SurgicalOntologist posted:I don't fully understand the algorithm but the first step is to try to do this with vectors operation. This might not work as written but may only need small tweaks. At least it should illustrate the idea of vectorizing the operation.
|
# ? Apr 11, 2017 11:55 |
|
Explicit is better than implicit...
|
# ? Apr 11, 2017 12:07 |
|
Dominoes posted:Explicit is better than implicit... Wouldn't that necessitate also specifying that the step size is 1, then?
|
# ? Apr 11, 2017 12:18 |
|
Cingulate posted:What's the point of the '0's here? Is this best behavior somehow? You're right, seeing this again I would do it without the 0s.
|
# ? Apr 11, 2017 14:54 |
|
QuarkJets posted:Wouldn't that necessitate also specifying that the step size is 1, then?
|
# ? Apr 11, 2017 16:37 |
|
QuarkJets posted:Wouldn't that necessitate also specifying that the step size is 1, then? Although practicality beats purity
|
# ? Apr 11, 2017 16:40 |
|
Whatever, nerd.
|
# ? Apr 11, 2017 17:37 |
|
[i for i in range(1, 100, 1)]
|
# ? Apr 12, 2017 06:54 |
|
QuarkJets posted:[i for i in range(1, 100, 1)]
|
# ? Apr 12, 2017 10:20 |
|
sorry i meant [_ for _ in range(0,1,1)]
|
# ? Apr 12, 2017 12:17 |
|
No, turn away!
|
# ? Apr 12, 2017 13:08 |
|
|
# ? May 16, 2024 18:11 |
|
QuarkJets posted:sorry i meant i thought you knew that _ is also completely uninformative. i think you meant [unused for unused in range(0,1,1)]
|
# ? Apr 12, 2017 14:06 |