|
Lumpy posted:You can write your own ModelManager to handle hooking up the ORM to a remote DB. We are in the process of writing a Django app that uses a custom ModelManager coupled with SQLAlchemy to use a (*shudder*) Azure Cloud MSSQL store for our data.
|
# ? Jan 13, 2014 00:33 |
|
|
# ? May 31, 2024 01:46 |
|
Thanks for the recommendation of Think Python some time ago. Working through one of the exercises (using some syntax not yet covered in the text) I came up with this as part of my solution:code:
|
# ? Jan 13, 2014 03:08 |
|
To me that looks practically unreadable. The good thing is that the docstring explains what's going on. When I find an undocumented comprehension that looks like that buried in someone's code I want to strangle them.
|
# ? Jan 13, 2014 04:33 |
|
KICK BAMA KICK posted:Thanks for the recommendation of Think Python some time ago. Working through one of the exercises (using some syntax not yet covered in the text) I came up with this as part of my solution: One-liners are fine if they're easy to comprehend, but this one is pretty complex. One-liners are not good if I'm afraid that it looks easily breakable, which this one does (even if it isn't) Even if you wanted to keep this as a one-liner, I'd suggest breaking the logic into several more lines (it's already 2 lines, technically)
|
# ? Jan 13, 2014 04:44 |
|
I'd pull the sorted(...) out of the comprehension, but otherwise think it's fine. The problem isn't asking for the final result to be a tuple, btw (the example results are lists and returning a tuple make zero sense there).
|
# ? Jan 13, 2014 05:31 |
|
unixbeard posted:I need to read a bunch of excel files in python, just reading no writing/creation. It seems like there are a few packages, xlrd and openpyxl, before I dive in does anyone have opinions or advice for/against either of them? I needed to do some quick work and xlrd was slick, easy to learn.
|
# ? Jan 13, 2014 10:26 |
|
KICK BAMA KICK posted:Thanks for the recommendation of Think Python some time ago. Working through one of the exercises (using some syntax not yet covered in the text) I came up with this as part of my solution: It's not that bad but I'd pull the sorted(...) step out of the comprehension and put it on its own line.
|
# ? Jan 13, 2014 15:12 |
|
Dren posted:It's not that bad but I'd pull the sorted(...) step out of the comprehension and put it on its own line. Even just reformatting would make it easier to read, e.g. code:
|
# ? Jan 13, 2014 18:13 |
|
I have an issue with Heroku. However, I can't replicate the error on my end. I suspect that something is erroring out on Heroku's end, but I can't get a stacktrace from them. All that happens is a 500 error. I heard about the logging module, and was hoping that it could help me by just printing out a trace to the console, as if you set "-v" flag or something. How do I do this?
|
# ? Jan 13, 2014 23:39 |
|
Pollyanna posted:I have an issue with Heroku. However, I can't replicate the error on my end. I suspect that something is erroring out on Heroku's end, but I can't get a stacktrace from them. All that happens is a 500 error. My guess would be directory permissions since it seems that you're dynamically writing HTML files (?). Design decisions aside, you should be able to use the following to print your own stack trace after the IOError is encountered: Python code:
|
# ? Jan 14, 2014 01:36 |
Little test program:code:
code:
I have a function that generates a bunch of CoolObjects and returns a list, but as I'm generating them I don't want to add them to the list if a duplicate is already in there. Is overriding __eq__ the correct way to handle 'x in somelist' and 'x not in somelist' behavior?
|
|
# ? Jan 14, 2014 02:17 |
|
C code:
But you might want to define __hash__ and use sets if your objects are immutable.
|
# ? Jan 14, 2014 04:36 |
|
Regarding that question I asked last week when everyone was like, "You're looking for asynchronous I/O"- I've been reading a bunch on that, and I think I'm learning something. However, pretty much everything I can find--especially beginner guides--frames the issue as one of dealing with slow I/O processes. I have the opposite problem: an extremely fast input process. The use case is that either (a) something should run every time new data comes in, or (b) something needs to reference only the most recent piece of data (b will be far more common than a). I will never have a situation where I'm waiting for data to come in. I don't doubt, of course, that asyncio can handle this (whether the proposed 3.4 library or the concept in general), I'm just having trouble thinking about it since everything I've read seems to be "how to elegantly get your program to block until your input comes in". Instead, I want to repeatedly ask for input (which requires calling a specific function over and over), but do so in the background without turning every program using this API into one big loop. There's plenty of jargon I haven't figured out yet, but I don't know where to look--I don't feel like I've found the trail. Any suggestions for further reading?
|
# ? Jan 14, 2014 05:03 |
|
What is the reason for string.find() to return -1 on failure? That leads to this unexpected output:code:
|
# ? Jan 14, 2014 08:13 |
In case it's at position 0:code:
|
|
# ? Jan 14, 2014 08:29 |
|
fletcher posted:In case it's at position 0: So why doesn't it return None if it's not found?
|
# ? Jan 14, 2014 08:41 |
|
Opinion Haver posted:So why doesn't it return None if it's not found? The code would still be wrong, since both 0 and None would be false. Better to find the bug early. .find() isn't usually what you want. If you want to check if it's there, use 'in'. If you need to know the position, use .index(), which raises an exception if it's not there. code:
|
# ? Jan 14, 2014 10:04 |
|
FoiledAgain posted:What is the reason for string.find() to return -1 on failure? That leads to this unexpected output: You shouldn't be using string.find() for substring checks anyway, use in. If you wanted to use string.find(), then you could instead search for a less than 0 index code:
|
# ? Jan 14, 2014 10:59 |
|
SurgicalOntologist posted:Regarding that question I asked last week when everyone was like, "You're looking for asynchronous I/O"- I've been reading a bunch on that, and I think I'm learning something. However, pretty much everything I can find--especially beginner guides--frames the issue as one of dealing with slow I/O processes. I have the opposite problem: an extremely fast input process. The use case is that either (a) something should run every time new data comes in, or (b) something needs to reference only the most recent piece of data (b will be far more common than a). I will never have a situation where I'm waiting for data to come in. Can you give more details about the exact problem you're trying to do? What is the network input is used for? Is this a command line program or a GUI? What GUI framework?
|
# ? Jan 14, 2014 13:39 |
|
Suspicious Dish posted:Can you give more details about the exact problem you're trying to do? What is the network input is used for? Is this a command line program or a GUI? What GUI framework? I'm interfacing with a motion capture device, in an application using pyglet (actually I'm writing more of a framework that interfaces this and other equipment together using pyglet, it's the same problem more or less but I'd like the resulting API to be clean if possible). The device supplies position, angle, velocity, etc that will be used to update objects on the screen. Most commonly, the 3D position will be projected onto the plane of the screen. Basically I'm using a motion capture device to make a big touchscreen. The device has an API with this example code: code:
This is strange, just tested this now: once I register the event with pyglet, even calling tracker.mainloop once causes the program to block. Not sure why that would happen. Edit: I figured it out. The device fills the buffer if mainloop isn't repeatedly called, and so when I'm testing in the command line as opposed to a script, there could easily be a lot of data waiting. But it wouldn't have actually blocked forever. So I guess I just need to call mainloop faster than the data is coming in, and my program won't block. (Lightbulb) All this callback stuff with pyglet is pretty much asynchronous I/O already, isn't it? SurgicalOntologist fucked around with this message at 17:14 on Jan 14, 2014 |
# ? Jan 14, 2014 16:34 |
|
QuarkJets posted:find always returns an integer, which is nice. Yeah, but you could still do this: code:
|
# ? Jan 14, 2014 20:02 |
|
I have a short, stupid question I've come across. The exercise solution for this suggest using multiple if statements, but a while loop seemed like it would also sort of work. For some reason this piece of code will only run 3 times. As soon as heads or tails gets to two it stops. Is it possible to use the and inside of the while statement, or am I missing something? I see why this method is bad in practice, as the for loop will execute the full 10,000 times even after the while conditions are met. I just want to know why the while statement isn't working. code:
|
# ? Jan 14, 2014 22:32 |
|
It's because you want an OR. If heads is 2 and tails is 0, your while condition will stop being true (2<=1 AND 0<=1 evaluates to FALSE), and thus will break out of the while loop.
|
# ? Jan 14, 2014 22:39 |
|
Could you also do something like this? while any( (heads, tails) <= 1)): I can't offhand remember if comparing to a list will do what I hope, or even if "any" is actually a Python function. (I don't have a PC at hand to test right now.) Computer viking fucked around with this message at 23:04 on Jan 14, 2014 |
# ? Jan 14, 2014 23:02 |
|
Okay, I think I see what you're saying. While can take a boolean value as a trigger. I was looking to drop out of the loop when both statements evaluated to FALSE using the and, but it is seeing it as a single statement.
|
# ? Jan 14, 2014 23:03 |
|
handbandit posted:Okay, I think I see what you're saying. While can take a boolean value as a trigger. I was looking to drop out of the loop when both statements evaluated to FALSE using the and, but it is seeing it as a single statement. pre:T <= 1 T > 1 H <= 1 T F H > 1 F F code:
|
# ? Jan 14, 2014 23:13 |
|
Hey dudes, I'm wondering if y'all know a way to serve a generated text-based file directly from a web server for download, without saving it as a file first. I have this code, where HttpResponse is a Django object, and xml is an xml ElementTree. Python code:
|
# ? Jan 15, 2014 17:44 |
|
Dominoes posted:I've unsuccessfully experimented with using ET's toString function. What has been unsuccessful? Are you unable to get a string from elementree or unable to create a response with it. It is possible you are using ET.tostring() on the ElementTree instead of an Element. Python code:
|
# ? Jan 15, 2014 18:15 |
|
OnceIWasAnOstrich posted:What has been unsuccessful? Are you unable to get a string from elementree or unable to create a response with it. It is possible you are using ET.tostring() on the ElementTree instead of an Element. edit: You nailed it brother. Python code:
Dominoes fucked around with this message at 19:30 on Jan 15, 2014 |
# ? Jan 15, 2014 18:44 |
|
I can't say I am that familiar with Django so FileWrapper may do something that I am not aware of (maybe it streams the file? but you aren't using a streaming HttpResponse), but it seems like wrapping a wrapper of a string is excessive. HttpResponse can be easily created with just a plain string since are already keeping the whole thing in memory at some point.
|
# ? Jan 15, 2014 19:41 |
|
Has anyone here done Shift-JIS decoding/encoding? I have a .bin file encoded with Shift-JIS (Japanese text), and I want to read each byte and translate them to UTF-8 or UTF-16. What I was thinking of was looping through it with file.read(1), then decoding/encoding the selected bytes (if that makes any sense). Would this work? Cause so far I just get strings like '/x00/xac' and I don't know how to change that to readable text. Has this been done before? Should I be reading one or two bytes at a time? What final encoding should I use? How I do
|
# ? Jan 15, 2014 19:47 |
|
OnceIWasAnOstrich posted:I can't say I am that familiar with Django so FileWrapper may do something that I am not aware of (maybe it streams the file? but you aren't using a streaming HttpResponse), but it seems like wrapping a wrapper of a string is excessive. HttpResponse can be easily created with just a plain string since are already keeping the whole thing in memory at some point.
|
# ? Jan 15, 2014 19:53 |
|
Is it possible to get the current Windows sound volume via the Windows API libraries? I'm good at Python but bad at Windows and I'm getting conflicting information on doing it from the Googletron.
|
# ? Jan 15, 2014 20:46 |
|
Luigi Thirty posted:Is it possible to get the current Windows sound volume via the Windows API libraries? I'm good at Python but bad at Windows and I'm getting conflicting information on doing it from the Googletron. https://stackoverflow.com/questions/18112457/python-change-windows-7-master-volume ? pywin32 or https://pypi.python.org/pypi/WMI/ are probably your best bets if you can find the Windows APIs for audio volume. Apparently the Windows audio volume APIs are cryptic and poorly documented. Good luck!
|
# ? Jan 15, 2014 21:04 |
|
I have a bunch of data that looks like this:code:
with basically a bunch of entries one after another all on one line from the website. I want to parse this data to get playername, game type, etc. I know I should use the JSON library to accomplish this. The page I get the code from has a bunch of HTML on it as well. Is it okay to use the json.load on the html, or should I strip that from it first? I'm not really entirely sure where to begin solving this problem, and am a bit confused by the JSON documentation. Any tips or hints would be greatly appreciated.
|
# ? Jan 15, 2014 21:06 |
|
BeefofAges posted:https://stackoverflow.com/questions/18112457/python-change-windows-7-master-volume ? gently caress that, nevermind. I don't need to know the volume that badly. Phiberoptik posted:I have a bunch of data that looks like this: You need to get it down to just the JSON data if you want to load it into a JSON library. The HTML will make it barf. You could try clever applications of .split() on the raw page to try to get just the JSON separated out. Luigi Thirty fucked around with this message at 21:13 on Jan 15, 2014 |
# ? Jan 15, 2014 21:10 |
|
Phiberoptik posted:I have a bunch of data that looks like this: Is there a different API or endpoint you can call that will just give you the JSON without any HTML? Trying to parse the JSON out of a bunch of HTML sounds like you're doing it wrong.
|
# ? Jan 15, 2014 21:40 |
|
Phiberoptik posted:I have a bunch of data that looks like this: Once you've isolated the data as a string, run json.loads() to turn it into a dict.
|
# ? Jan 15, 2014 21:40 |
|
Pollyanna posted:Has anyone here done Shift-JIS decoding/encoding? I have a .bin file encoded with Shift-JIS (Japanese text), and I want to read each byte and translate them to UTF-8 or UTF-16. What I was thinking of was looping through it with file.read(1), then decoding/encoding the selected bytes (if that makes any sense). Would this work? Cause so far I just get strings like '/x00/xac' and I don't know how to change that to readable text. Has this been done before? Should I be reading one or two bytes at a time? What final encoding should I use? How I do How big is the file? You shouldn't read individual bytes for this -- these character encodings are standard in Python and you shouldn't even begin to reimplement them. You can do this line by line or (if the file's small enough) by reading the entire file into memory. I'm curious about the .bin extension -- does the file only contain Shift-JIS text? If so, you can probably do Python code:
Lysidas fucked around with this message at 22:14 on Jan 15, 2014 |
# ? Jan 15, 2014 22:11 |
|
|
# ? May 31, 2024 01:46 |
|
Phiberoptik posted:I have a bunch of data that looks like this: Are you sure there isn't anyway to grab that data from the server without the HTML? If that's dynamic data on an HTML page then I wouldn't be surprised if the page uses JavaScript to load the JSON from through some specific URL on the server.
|
# ? Jan 15, 2014 22:15 |