|
Reading this blog was really helpful in getting accustomed to the standard library: http://www.doughellmann.com/PyMOTW/ I still use it from time to time for quick reference.
|
# ? May 8, 2012 17:05 |
|
|
# ? May 9, 2024 13:41 |
|
Maluco Marinero posted:https://www.diveintopython.net - Python Beginner Book Dive Into Python was outdated and irrelevant five years ago. There is no good reason to use it now. It has terrible code. It is outright wrong in several sections. For a beginner programmer, Think Python or Learn Python the Hard Way is much, much better. For someone who knows another programming language, but not Python, the Official Python Language Tutorial should be more than fine.
|
# ? May 8, 2012 20:39 |
|
No worries, I was just contributing what I learned with, but that's fair enough.
|
# ? May 9, 2012 00:59 |
|
Got a style question, kind of new to python and trying to make some code that's friendly and sensible. In particular the code relies on struct.unpack to parse a binary model format (for quake FPS games), make some tweaks and then export it back. Python is just right for making the tweaks in the middle easy to script and vary from model to model, but right now I'm building the module which will do the ends. The particular question I have is regarding the way struct.unpack returns a tuple. This is very handy for some of the bigger structures in the model format, using multiple assignment to distil the individual values into variables. When unpack only returns a single value, it still packs it into a tuple, so the naive code which simply assigns the value to a variable ends up getting a tuple containing a number, rather than a number. Although that didn't take long to spot, I can see two ways to store the number within the tuple in my destination variable, and want to know what you think is the more readable/idiomatic: code:
code:
|
# ? May 10, 2012 23:34 |
|
I haven’t really done any coding before, but I’m working on making a real basic touch-typing thing. It shows a word then you type that word in and so on. Right now to input the word you type it then hit Enter. Is there a way to make it so you would type the word then just hit the spacebar instead of enter?
|
# ? May 11, 2012 04:24 |
|
Boonoo posted:I haven’t really done any coding before, but I’m working on making a real basic touch-typing thing. It shows a word then you type that word in and so on. Right now to input the word you type it then hit Enter. Is there a way to make it so you would type the word then just hit the spacebar instead of enter? Are you using a GUI framework? If so, which one? Can you post any source code?
|
# ? May 11, 2012 05:00 |
|
Naw, no gui framework. here's what I have so far. code:
|
# ? May 11, 2012 05:12 |
|
Heavy_D posted:want to know what you think is the more readable/idiomatic: To my brain with all its biases it's way more obvious what the former assigns, so I would say that wins.
|
# ? May 11, 2012 05:15 |
|
Heavy_D posted:To my inexperienced eye I think the former is a bit easier to dissect, but the latter is more consistent with how the rest of the assignments work, so I could go either way... code:
code:
|
# ? May 11, 2012 08:02 |
|
matplotlib question: any idea why the following is happening? What type do I need to make this work? code:
|
# ? May 12, 2012 05:32 |
|
Boonoo posted:Naw, no gui framework. here's what I have so far. Hmm, sorry. I'm not quite sure how to do this with raw_input, but after googling it seems like you could use msvcrt if you're using Windows.
|
# ? May 12, 2012 15:12 |
|
FoiledAgain posted:matplotlib question: any idea why the following is happening? What type do I need to make this work? So you have two problems here. 1) cm.jet(cm) produces the error that you're getting because you're passing the module cm as an input. If you want a jet colormap just use cm.jet 2) You aren't using facecolors correctly. If you go this route, you have to specify a color for each point on the surface. You are trying to provide a colormap. You probably want to do the following: code:
|
# ? May 12, 2012 16:09 |
|
Boonoo posted:Naw, no gui framework. here's what I have so far. This might help you: http://stackoverflow.com/questions/6348952/handling-keyboard-events-in-python
|
# ? May 12, 2012 16:22 |
|
Modern Pragmatist posted:2) You aren't using facecolors correctly. If you go this route, you have to specify a color for each point on the surface. You are trying to provide a colormap. You probably want to do the following: Thanks, this is exactly what I wanted to do. I had copied and pasted code from another project where I was using facecolors (and properly in that case!).
|
# ? May 13, 2012 20:53 |
|
Not sure if this is the right place to post this, but seeing as it is the Python thread, I'll give it a whirl. I'm looking to learn to program in Python, and my company is willing to pay for me to take a course. As such, would anyone have any recommendations for a 3-4 day course that might get me up and running? I've done some google-fu and I've found some potential courses but I have no idea if they are good or absolute crap. Some background, I'm not a harcore programmer but have have always been able to pick things up when I've wanted to, generally for a specific purpose which then falls away after I don't need it any more. Since the company is willing to pay for it, I was hoping to find a course that would give me a solid background. I've already starting reading some books and creating some silly little programs. I would ideally like to find a course that will not be too easy (and therefore waste my time) but not be so hard that I have no idea what's going on. Any advise or suggestions are much appreciated.
|
# ? May 14, 2012 05:06 |
|
The official Python Tutorial isn't half bad if you already know another language.
|
# ? May 14, 2012 05:30 |
|
I'm using pyplot to create a graph of thing_count vs time, where distance between the time points are not even. I would like to create a moving average for the data set, but I don't know enough maths to know where to start. All I know is that my MovingAverage implementation works for an evenly-spaced y-axis, but breaks (has sharp transitions) on window fall-off when uneven.
|
# ? May 14, 2012 15:40 |
|
Coming from someone who is a complete novice, I think learning python the hard way and dive into python are both good for a one-two punch. Learning python the hard way, while the author is clearly insane, has a lot of good examples to work with. The other one is a good reference material (for me, at least). I'm in "writing tons of useless/ugly programs" stage but those tutorials were helpful in getting to this point.
|
# ? May 16, 2012 05:46 |
|
What the hell is with Python's standard library? http://docs.python.org/dev/library/turtle.html http://docs.python.org/dev/library/nis.html http://docs.python.org/dev/library/pipes.html http://docs.python.org/dev/library/formatter.html http://docs.python.org/dev/library/reprlib.html http://docs.python.org/dev/library/sched.html Why are all of these things in Python 3? After the standard library cleanup? We don't have a sane http client, but we have turtle graphics? I'm not mentioning asyncore and multiprocessing because they're the standard things that people pick on.
|
# ? May 16, 2012 07:02 |
|
I'm trying to figure out an elegant solution to a problem I have with NumPy. I have a large array of shape (20, 20, 7, 7, 10), and I want to create another array which has only the last element of the last axis of the previous array, and is thus of shape (20, 20, 7, 7). The mapping a -> b would be b[i,j,k,l] = a[i,j,k,l][-1]. It's easy enough to do with four nested for loops for each of the first four dimensions copying each item individually by index, but is there some command which makes this a one liner? The closest I've come is pre:truth_array = [False]*9 + [True] ranked = big_array.compress(truth_array, axis=9)
|
# ? May 16, 2012 09:03 |
|
sliderule posted:I'm using pyplot to create a graph of thing_count vs time, where distance between the time points are not even. I would like to create a moving average for the data set, but I don't know enough maths to know where to start. How "not even"? In astro, we run into this sort of thing quite often. If you think about it, it makes sense because you often have measurements uneven in time. Two suggestions, depending on your situation. Situation 1 involves doing this moving average piecewise. This would be good if you have say two data runs that are well separated but within the run are finer spaced. Just run the average for each set and then plot those averages. Be sure to propagate your error bars!! Situation 2 involves a situation where say measurement A and B are hours apart and measurement B and C are days apart. You'll have a large timescale, but some areas are finer than others and there's no real clumping like in the first situation. My suggestion in this case is to not do a moving average, but fit a function to your data. Unfortunately, my experiences with the fitting routines in python's scipy are limited. Even then, I'm suspicious that they handle uneven error bars too well. "curve_fit" in scipy would be a decent place to start. Alternatively, MFIT (FORTRAN77) was the greatest fitting routine ever. MPFIT in IDL apparently works very well too, and I know there's a python version of MPFIT.
|
# ? May 16, 2012 13:22 |
|
Suspicious Dish posted:What the hell is with Python's standard library? As often said: quote:The standard library is where modules go to die And it's not even just a stupid catch phrase. Some modules were put there way too early to be mature or even pythonic (oh god, ElementTree, why), but they are used so often and globally it stuck around. I, too, wish there was something more sane available for HTTP; but it's how things go. Just use something that's not in the standard library; it's a safer bet.
|
# ? May 16, 2012 19:03 |
|
xPanda posted:I'm trying to figure out an elegant solution to a problem I have with NumPy. Unless I am misunderstanding, I think a[...,-1] will do what you are asking.
|
# ? May 16, 2012 19:28 |
|
BigRedDot posted:Unless I am misunderstanding, I think a[...,-1] will do what you are asking. Holy crap, it does. drat I love this language. I'm going to go and read up more on advanced indexing. Thanks!
|
# ? May 16, 2012 22:36 |
|
OK, here's something I've been meaning to find out about for a while: can someone point me to a good place to learn about decorators? I literally have no idea what they do or why you'd use them, but I assume they're useful.
|
# ? May 17, 2012 04:31 |
|
MeramJert posted:OK, here's something I've been meaning to find out about for a while: can someone point me to a good place to learn about decorators? I literally have no idea what they do or why you'd use them, but I assume they're useful. I was actually just reading up on them. This article was pretty informative.
|
# ? May 17, 2012 05:16 |
|
MeramJert posted:OK, here's something I've been meaning to find out about for a while: can someone point me to a good place to learn about decorators? I literally have no idea what they do or why you'd use them, but I assume they're useful. http://stackoverflow.com/questions/739654/understanding-python-decorators Has the single best explanation and walkthrough of decorators I've seen yet.
|
# ? May 17, 2012 05:19 |
|
If you're curious about the history of the decorator syntax, it started as a pattern like this:code:
code:
code:
When I see something like this: code:
code:
|
# ? May 17, 2012 06:05 |
|
BigRedDot posted:Unless I am misunderstanding, I think a[...,-1] will do what you are asking. Oh goddamnit, I was working on a solution, thought of this, and just assumed I was misunderstanding the question.
|
# ? May 17, 2012 15:19 |
|
What's the best way to sort a dictionary? I read somewhere that you can convert it into a list and sort the list, but I haven't been able to make it work.
|
# ? May 17, 2012 17:39 |
|
Karthe posted:What's the best way to sort a dictionary? I read somewhere that you can convert it into a list and sort the list, but I haven't been able to make it work. A dictionary in itself is unsorted by nature (being primarily for 'random' lookups, you shouldn't have to care about the order of what's inside). You can feed it into sorted() if you're iterating over it, but there isn't a way to sort a dictionary in place unless you convert it into something else. code:
Reformed Pissboy fucked around with this message at 18:11 on May 17, 2012 |
# ? May 17, 2012 18:06 |
|
Harm Barn Gumshoe posted:A dictionary in itself is unsorted by nature (being primarily for 'random' lookups, you shouldn't have to care about the order of what's inside). You can feed it into sorted() if you're iterating over it, but there isn't a way to sort a dictionary in place unless you convert it into something else.
|
# ? May 17, 2012 18:48 |
|
So I've decided to finally start on Python. I've been meaning to learn it for some time, guess I just never got around to it. Anyway, as a sort of 'learning venture' I want to make a simple IRC bot, one that greets users who enter a channel or something like that, and eventually have a 'google' function, I.E "!google somethingawful" and display the first result's url and description. Is this something a beginner should take up as a 'first project?' What libraries are best for this? I was asking around in #python on freenode and got directed to 'twisted.' Can anyone give a second opinion on using that? Thanks.
|
# ? May 18, 2012 10:31 |
|
River posted:So I've decided to finally start on Python. I've been meaning to learn it for some time, guess I just never got around to it. Anyway, as a sort of 'learning venture' I want to make a simple IRC bot, one that greets users who enter a channel or something like that, and eventually have a 'google' function, I.E "!google somethingawful" and display the first result's url and description. If you don't care about implementing the actual protocol (but rather want to focus on the actual bot functionality), I've made a small Python IRC library. Otherwise, Twisted is good, although a bit much for just beginning programming in Python. It's quite bloated and not newbie-friendly, from my experience. e: Also, for starting out with a language, anything you'd find interesting is a good 'first project'. Interest is key to motivating yourself to keep learning.
|
# ? May 18, 2012 12:14 |
|
I've used Eventlet to make an IRC bot. It was pleasant to use and was a fun project. As a beginner, I wouldn't use Twisted.
|
# ? May 18, 2012 14:29 |
|
Karthe posted:Thanks for the guide, it turned out to be much more simple than I thought. Depending on your usage you might want to use collections.OrderedDict to store the dictionary once sorted (for example if the keys don't change very often), avoiding the cruft of managing a list and a dict at the same time.
|
# ? May 18, 2012 15:23 |
|
Thermopyle posted:As a beginner, I wouldn't use Twisted. As someone who has been using python for a while, I wouldn't use Twisted. Twisted is a bit Did you just tell me to go gently caress myself?. Undocumented at the best of times, out of date documentation at the worst of times.
|
# ? May 18, 2012 16:21 |
|
As someone who has to maintain a Twisted application on a daily basis I concur. Although for a bot I modified for a game here on the forums I just forked CloudBot
|
# ? May 18, 2012 17:27 |
|
Having just written an IRC bot using Twisted, I don't disagree with the above points, but it wasn't really that bad. The documentation could be better, and some parts of Twisted plain don't work, but a lot of Twisted code self-documents and there's very little "magic" under the hood; I found it easy to figure out. I guess what I'm trying to say is, my Twisted experience wasn't completely negative. This was the first I've used Twisted.
|
# ? May 18, 2012 18:14 |
|
|
# ? May 9, 2024 13:41 |
|
Ok, here's a really dumb question. Let's say I wanted to collect all the stats from a page, for example: http://www.nhl.com/ice/playerstats.htm?season=20112012&gameType=2&team=&position=S&country=&status=&viewName=summary#?navid=nav-sts-indiv Right now, the only thing I can think of is setting up a python script to save each page (in this case, 1 through 30), and then just having to figure out how to distill the HTML by hand. I guess "beautifulsoup" would work, but I am looking for tips as to how to do this cleanly and reliably.
|
# ? May 18, 2012 19:50 |