|
Suspicious Dish posted:If that code is exactly as is, why get all this data just to throw it out? I'm assuming that your column list comes from somewhere else, like from the user. What I would do is only fetch data as required: Column list is hardcoded. The program is just academic scrap code that's helping me learn python, so it saves me the time of having to retype the symbols into the list when I want to inspect different relationships. And now I know that a discontinuous slice is apparently a oxymoron in python terminology!
|
# ? Oct 26, 2012 20:37 |
|
|
# ? Jun 13, 2024 03:46 |
|
Yeah, then the way you're doing it now is fine.
|
# ? Oct 26, 2012 20:40 |
|
tef posted:From a brief inspection, here are some things you'll want to change. This is wrong, StandardError is for built in exceptions to subclass, not for third party exceptions to subclass. From the Python Docs: [1] Exception: All built-in, non-system-exiting exceptions are derived from this class. All user-defined exceptions should also be derived from this class. StandardError: The base class for all built-in exceptions except StopIteration, GeneratorExit, KeyboardInterrupt and SystemExit. StandardError itself is derived from Exception. Basically the only time you should inherent from anything but Exception as a User is if you're trying to make a specialized form of a standard exception (e.g. KeyError). [1] http://docs.python.org/2/library/exceptions.html Comrade Gritty fucked around with this message at 01:13 on Oct 29, 2012 |
# ? Oct 29, 2012 01:10 |
|
Yep, someone shouted at me for that on irc too. I can't recall why I started doing that but it was probably being lazy.
|
# ? Oct 29, 2012 04:07 |
|
tef posted:Yep, someone shouted at me for that on irc too. I can't recall why I started doing that but it was probably being lazy. there's some "best practice" boilerplate that mentions that try-catches in the form of: code:
code:
Scaevolus posted:Since Python 2.5, KeyboardInterrupt and SystemExit inherit from BaseException, to no get caught by except Exception:. Ah, living in the past I see. thanks Lurchington fucked around with this message at 05:13 on Oct 29, 2012 |
# ? Oct 29, 2012 04:45 |
|
Lurchington posted:So KeyboardInterrupt and SystemExit don't get caught unintentionally. That's my guess for how that started Since Python 2.5, KeyboardInterrupt and SystemExit inherit from BaseException, to no get caught by except Exception:.
|
# ? Oct 29, 2012 05:00 |
|
I just spent the past hour or two looking for a workable api for google voice in python. pygooglevoice is currently not working, which is too bad.
|
# ? Oct 29, 2012 19:21 |
|
Minor elegance question. I have a routine that I want to try N times before giving up, and I'm not seeing how to make the loop "pythonic". Here's what I ended up with:Python code:
Python code:
Python code:
|
# ? Oct 30, 2012 02:23 |
|
Stabby McDamage posted:Minor elegance question. I have a routine that I want to try N times before giving up, and I'm not seeing how to make the loop "pythonic". Here's what I ended up with: edit: missed the part about wanting to distinguish between attempt count and good result...
|
# ? Oct 30, 2012 02:28 |
|
Python code:
Python code:
Lurchington fucked around with this message at 02:31 on Oct 30, 2012 |
# ? Oct 30, 2012 02:29 |
|
Bingo, perfect. I forgot all about that.
|
# ? Oct 30, 2012 04:10 |
|
Is anyone aware of a pre-existing synchronized priority queue implementation for gevent? I'm writing a Nagios->Graphite perfdata forwarder and I want to make sure that new files coming in on the inotify greenlet are given priority over old files lingering in the spool (queued on a different greenlet). Edit: Never mind, it seems that gevent has an undocumented priority queue that I found by going through queue.py Vulture Culture fucked around with this message at 19:27 on Oct 30, 2012 |
# ? Oct 30, 2012 15:01 |
|
Stabby McDamage posted:Bingo, perfect. I forgot all about that. for-else is a rather obscure construct. I'd just use that while. while True with bailout is widely accepted as idiomatic implementation of do...while in Python.
|
# ? Oct 30, 2012 16:26 |
|
Yeah, I try to avoid for...else like the plague, as it doesn't do the thing most people would expect.
|
# ? Oct 30, 2012 16:28 |
|
PiotrLegnica posted:for-else is a rather obscure construct. I'd just use that while. while True with bailout is widely accepted as idiomatic implementation of do...while in Python. I don't think I like the while True more than for-else, but I'd definitely feel obligated to link to the docs in a comment everytime I used a for-else..
|
# ? Oct 30, 2012 16:59 |
|
Misogynist posted:Is anyone aware of a pre-existing synchronized priority queue implementation for gevent? I'm writing a Nagios->Graphite perfdata forwarder and I want to make sure that new files coming in on the inotify greenlet are given priority over old files lingering in the spool (queued on a different greenlet). Something like this?
|
# ? Oct 30, 2012 19:27 |
|
Captain Capacitor posted:Something like this?
|
# ? Oct 30, 2012 20:45 |
|
How many of you have worked with libguestfs and Python? I wrote a function that is supposed to push a file into the root of a qcow2 image formatted as NTFS, but it seems to barf upon it trying to work with the image.Python code:
code:
|
# ? Oct 30, 2012 21:00 |
|
Hey guys, I'm just starting out in Python and I went and downloaded version 3.3. Now when I look at Pygame it has only support for version 2.7 There are some documentation to get it running in 3.x, but I can't make heads nor tails of this. I'm running OSX 10.8.2 and it looks even harder to get it going than just using windows. I'm very new to all this. Is there anything I can use that's like Pygame that will work in 3.3 for OSX? Or is there a way I can get Pygame to work for 3.3? I looked around and found Pyglet, but it's last update was back in July for an alpha. Pygame2 was last updated in 2010. I mainly wanted to use Python for it's ease in game development if wanting to get Pygame didn't tip you off.
|
# ? Oct 31, 2012 11:35 |
|
Do you need python3 for anything in particular? 2.7 is still maintained and a lot of things aren't python3 compatible yet (despite it being years since release).
|
# ? Oct 31, 2012 11:43 |
|
Lord Windy posted:Hey guys, I'm just starting out in Python and I went and downloaded version 3.3. Now when I look at Pygame it has only support for version 2.7 Early on when I was first attempting to learn how to make games I attempted several times to use pygame, I failed each time. I found it difficult to get working, and once working, difficult to do stuff with. I switched to action script + flixel and had a much easier time and actually made some basic games. To me the only benefit to using pygame, is that your using python. If your interested in making games I would suggest using something like action script + flash develop + flixel or something. Also if you use those you can share your creations much omre easily. This guy has a lot of good stuff: http://www.photonstorm.com/archives/1200/flash-game-dev-tip-6-setting-up-flashdevelop-and-flixel-for-the-first-time
|
# ? Oct 31, 2012 11:47 |
|
The Gripper posted:Do you need python3 for anything in particular? 2.7 is still maintained and a lot of things aren't python3 compatible yet (despite it being years since release). Probably not to be honest. I have no idea what it added, I just picked it because it was the latest release and the main website. I'm very surprised that nobody has moved over to 3.x, especially considering how popular things like pygame seems to be. It's looking likely that I should just roll back to 2.7 in that case. PastaSky posted:Early on when I was first attempting to learn how to make games I attempted several times to use pygame, I failed each time. I found it difficult to get working, and once working, difficult to do stuff with. quote:First things first. You need to be using Windows. FlashDevelop IS coming for OS X soon. You can also run it under Parallels. And there are builds in development that you can download from the forum, but I’m not covering it here. Sorry if that excludes you. You’re welcome to come back and join us at the point where we integrate Flixel, as that will still be relevant to you. EDIT: I like the idea of it, I'm just constrained to OSX
|
# ? Oct 31, 2012 11:54 |
|
It changed a lot of language features and has added some things, but people generally consider it as a parallel version of python instead of a straight-up "new, improved version". Sticking with 2.7 is no problem, and if you're relying on third-party libraries or potentially might rely on them in the future you're better off currently on 2.7 for compatibility reasons. And it probably sounds like a lovely thing to say, but Python really isn't ideal for making games. Pygame is the best-of-the-bunch for python-based frameworks, but I imagine most people pick it for reasons like "hey, I want to make a game in Python" rather than "hey, Python+Pygame is the easiest way to make a game". I guess it depends on your goals though, if you want to learn python and making a game is your idea then go for it, it's definitely an application type that will teach you a lot. If your goal is to make games in general, I'd strongly suggest alternatives like flash/actionscript3 (FDT is a free, eclipse-based IDE that works on OS X) or even Unity3D if you want a more fleshed out engine/workspace and a huge community, though it takes a lot of the general engine-creation tasks away from you.
|
# ? Oct 31, 2012 12:07 |
|
Lord Windy posted:Probably not to be honest. I have no idea what it added, I just picked it because it was the latest release and the main website. I'm very surprised that nobody has moved over to 3.x, especially considering how popular things like pygame seems to be. This might be useful, but may also be more work than is warranted. http://dev.mothteeth.com/2011/10/how-to-install-flashdevelop-on-osx-with-bridge/
|
# ? Oct 31, 2012 12:29 |
|
I'd welcome any recommendations for choosing something else other than Python, I just recalled using Python in highschool when I competed in small competitions online. We used something like Pygame, but it was made by the University that was hosting this and was really just a very easy script to make windows appear and clicks register without us having to think on it much. I also went to Uni (different uni) to do games programming (I think you can tell this wasn't a very good course). We learnt C++ from the start there and SFML (I'm pretty sure) for 2d stuff. I did alright with that, I was a little slower than other people but I understood the concepts just right and I made a roguelike that got me a High Distinction. But then we moved onto 3D programming too quickly in my opinion, and I couldn't keep up with the math that I needed to learn and ended up leaving the course. I still don't know what a quaternion is and why I couldn't just use a matrix instead Now it's a few years later and I want to wet my feet again and just learn at my own pace. All I need is something that very simply helps me open a window, gives me an easy way to load up images/audio and registers clicks and button presses. That just gives me the ability to work out the rest myself. I'd just go back to C++, but honestly it feels way to large and cumbersome for what I want to do so I've just gone shopping for something else. Python+Pygame just seemed to hit what I wanted and this tutorial gave me a crash course in what I needed to do to get the basics of what I wanted to open.
|
# ? Oct 31, 2012 12:31 |
|
Then yeah, python 2.7 + pygame sounds like a good fit for you overall, then. Just install 2.7 and don't worry about 3.3 at all!
|
# ? Oct 31, 2012 12:36 |
|
Lord Windy posted:I'd welcome any recommendations for choosing something else other than Python, I just recalled using Python in highschool when I competed in small competitions online. We used something like Pygame, but it was made by the University that was hosting this and was really just a very easy script to make windows appear and clicks register without us having to think on it much. Python is a great language, but pygame is probably not the best way to go about what you want. As Gripper suggested http://fdt.powerflasher.com/ will work, and if you choose to use flixel (which I would suggest to get into the "making games" part fast) you should be able to get it working in FDT. I found this which may be useful: http://active.tutsplus.com/tutorials/mobile/android-game-frogger-flixel/
|
# ? Oct 31, 2012 12:51 |
|
The Gripper posted:Do you need python3 for anything in particular? 2.7 is still maintained and a lot of things aren't python3 compatible yet (despite it being years since release). Conversely, a lot of things are Python 3 compatible now, and it's at the point that you should use 3 by default and then revert to 2.7 if necessary. The recent change to docs.python.org reflects this -- the Python developers rightly consider 3.3 to be what you should use unless you have a good reason not to. I understand needing to use 2.7 for PyGame (if you're even going to use PyGame), but I'm a bit confused by the lack of 3.3 builds at its download page. 3.1 and 3.2, yes, but no 3.3 yet.
|
# ? Oct 31, 2012 14:02 |
|
So speaking of writing games in python, I've been wrestling with some options for my own project. pygame grossed me out, so I've been working with pyglet. In addition to a typical gameplay area (rendered using pyglet), portions of my game's UI will lend themselves to using a UI framework (I'm thinking PyQT) for things like a simple bitmap editor screen, sliders and fields for customizing units, etc. Would it be terribly complex to combine a pyglet-rendered game area within a PyQT window? Am I better off just making my own custom UI controls in pyglet?
|
# ? Oct 31, 2012 22:42 |
|
I've got twelve data points that I need to use to create a piecewise-linear curve with several thousand points. Is this problem too simple for there to be a numpy/scipy function that already does what I want?
raminasi fucked around with this message at 22:17 on Nov 1, 2012 |
# ? Nov 1, 2012 21:13 |
|
GrumpyDoctor posted:I've got twelve data points that I need to use to create a piecewise-linear curve with several thousand points. Is this problem too simple for there to be a numpy/scipy that already does what I want? numpy.interp is what you're looking for. For more options other than linear interpolation you may want to consider scipy.interpolate.interp1d Python code:
|
# ? Nov 1, 2012 21:28 |
|
I just finished my first legitimate (non-toy) Python project, Metricinga, a daemon that forwards Nagios/Icinga performance data to Graphite. Would anyone mind taking a minute to look over my code and tear it apart so I can write better code?
|
# ? Nov 1, 2012 21:41 |
|
Modern Pragmatist posted:numpy.interp is what you're looking for. For more options other than linear interpolation you may want to consider scipy.interpolate.interp1d I read that page and decided that it didn't do what I want literally right before I posted. I think the example with the sine curve confused me or something.
|
# ? Nov 1, 2012 22:23 |
|
Misogynist posted:I just finished my first legitimate (non-toy) Python project, Metricinga, a daemon that forwards Nagios/Icinga performance data to Graphite. Would anyone mind taking a minute to look over my code and tear it apart so I can write better code? I personally would find it a bit annoying if I had to consult a few different places for logging output (sys.stderr output versus whatever is given). Just a personal nitpick. Also it seems that there's no place to specify log files anyway.
|
# ? Nov 1, 2012 23:01 |
|
Captain Capacitor posted:I personally would find it a bit annoying if I had to consult a few different places for logging output (sys.stderr output versus whatever is given). Just a personal nitpick.
|
# ? Nov 2, 2012 01:26 |
|
Misogynist posted:I just finished my first legitimate (non-toy) Python project, Metricinga, a daemon that forwards Nagios/Icinga performance data to Graphite. Would anyone mind taking a minute to look over my code and tear it apart so I can write better code? Some nitpicks: Python code:
Python code:
Python code:
Python code:
Python code:
Python code:
In stop() you call str(err) twice, the second time it will always already be a string. In run(), your finally block has a "shutdown successfully" message. If joinall throws some other non-expected error, that message will be false. See the following regarding string formatting: http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting And this regarding your use of file vs. open: http://stackoverflow.com/questions/112970/python-when-to-use-file-vs-open
|
# ? Nov 2, 2012 02:07 |
|
Titan Coeus posted:
I guess I should be happy that many of your concerns focused on someone else's code, though. I'll still fix it up to be less... 2002. Titan Coeus posted:
Titan Coeus posted:
Titan Coeus posted:I'm not sure about send_metric(self, metric). If you have no internet connection, this is going to loop indefinitely. You should probably set some limit (20?) on the number of failed attempts. I do need a more graceful way of deleting the files only after the metrics are sent. Propagating control messages down several layers in gevent (or anything) is frustrating. Titan Coeus posted:In run(), your finally block has a "shutdown successfully" message. If joinall throws some other non-expected error, that message will be false. Titan Coeus posted:See the following regarding string formatting: http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting Vulture Culture fucked around with this message at 04:00 on Nov 2, 2012 |
# ? Nov 2, 2012 03:58 |
|
I've finally come up with another small project to practice my python on. It involves mutagen (Basically I'm going to set something to rename .mp3 files based on the idv3 tag info). My question is this: I generally use Windows and the mutagen only has a tarball zip file. I'm still pretty stupid on linux, is there a way to add the module in windows? Edit: I'm a loving retard, that's all. Gothmog1065 fucked around with this message at 00:17 on Nov 3, 2012 |
# ? Nov 2, 2012 19:27 |
|
In pygame, is there really no way to treat the analog triggers (edit: on a 360 controller) as separate axes? I know SDL supports it. It seems like triggers are basically unusable with it this way.
|
# ? Nov 5, 2012 02:09 |
|
|
# ? Jun 13, 2024 03:46 |
|
Bunny Cuddlin posted:In pygame, is there really no way to treat the analog triggers (edit: on a 360 controller) as separate axes? I know SDL supports it. It seems like triggers are basically unusable with it this way. That's a limitation (in my opinion a deliberate crippling) of the 360 controller. Officially, the way to read the triggers as separate axes is to use the XInput library. Brief searching doesn't turn up a Python wrapper for XInput, only this post on interfacing with XInput using ctypes. There's also this DirectInput driver for the 360 controller. Haven't tried it myself, so I can't vouch for it. And obviously you wouldn't ask your users to install it.
|
# ? Nov 5, 2012 02:33 |