|
JetsGuy posted:I didn't have time before work to check my home computer for that Runge-Kutter, but I promise I'll post it tonight. yeah, and also handles situations where your code happens to blow up. For example, quotes strings that have a comma in them" Also, getting to refer to a refer as a dictionary with keys as the csv header row. Pretty sweet. Thern posted:I just started looking into csv module for something I'm working on, so I'm curious. Is there a reason that you couldn't use the writerows method instead? probably just user writerows unless you need to skip certain lines or something
|
# ? Mar 13, 2013 21:37 |
|
|
# ? May 9, 2024 08:57 |
|
Working on my Runge Kutte here:Python code:
I can't figure out what this means. I know in console I can totally type bx[1,2,1], bx[0,1,0], etc.. and get values out.
|
# ? Mar 13, 2013 22:19 |
|
Thermopyle posted:Hmm, I think I disagree. It seems very clear to me what the comprehension is doing and ever so slightly obtuse what map is doing there. However, I can't say for sure if that is because I use list comprehensions 100 times more than map, or if it's just a difference in the way we understand code we read. Maybe it's just a mental difference in the way we're reading it. This is kind of what I'm talking about : fritz posted:Not a lambda, but:
|
# ? Mar 13, 2013 22:32 |
|
JetsGuy posted:I didn't have time before work to check my home computer for that Runge-Kutter, but I promise I'll post it tonight. You would fail horribly to parse this CSV data: "John", "Doe, Jr.","123 Fake Street Chicago, IL","555-555-5555, ext 5555","I really liked your site, but it seems to break when I upload a csv file containing commas."
|
# ? Mar 13, 2013 23:05 |
|
the posted:Working on my Runge Kutte here: Python code:
|
# ? Mar 13, 2013 23:05 |
|
a lovely poster posted:Because writing the shortest lines possible is not really a goal for most software developers. I would use the first because in the case of someone else editing my code it would be a lot easier to understand. Maybe it's just because I've been doing a lot of functional programming lately, but I always found the operator stuff incredibly clunky. And if you need to chain them, it's basically unreadable.
|
# ? Mar 13, 2013 23:15 |
|
yaoi prophet posted:Maybe it's just because I've been doing a lot of functional programming lately, but I always found the operator stuff incredibly clunky. And if you need to chain them, it's basically unreadable. Yeah, I mean, ultimately the correct answer is to choose the more readable one. If you're working with a team of python developers that lambda is easier for, by all means go for it. I just don't think statement length should really be a factor when you're talking about a difference of five characters. In fact, many times code is better when it's longer.
|
# ? Mar 13, 2013 23:25 |
|
Lurchington posted:yeah, and also handles situations where your code happens to blow up. For example, quotes strings that have a comma in them" DARPA posted:You would fail horribly to parse this CSV data: Both great points. I'm just very used to two types of people handling my code: 1) Me 2) Fellow scientists like me who will also run it from the command line with their own data files I guess it's not great practice, but the codes we hand each other very much tend to require a very specific format, and it's on you if you refuse to read the header and give the routine something else. Personally, I just use tab/space delimiters, but I can see the point in needing commas for datafiles with strings that have any sort of complexity.
|
# ? Mar 13, 2013 23:25 |
|
Just be thankful you never had to parse data from a source that wasn't in your control, and could change format on the whim of the developers in charge of that process, who also felt no obligation to notify you of said changes.
|
# ? Mar 13, 2013 23:32 |
|
Thern posted:Just be thankful you never had to parse data from a source that wasn't in your control, and could change format on the whim of the developers in charge of that process, who also felt no obligation to notify you of said changes. Yeah, I understand what I do is very much "scientific programming" and when I get handed a data file that's a weird delimiter I just run a "replace all" in emacs and *poof* its how I like it. The worst I've had to do is a quick FITS -> ASCII in fv or resurrecting some awful IDL .sav file or something.
|
# ? Mar 13, 2013 23:43 |
|
So do you still need that Runge-Kutter of mine? Because it looks to me like you solved it. I am positive mine wasn't 3d, but I'll post it as promised if you still want it.
|
# ? Mar 14, 2013 02:12 |
|
JetsGuy posted:I didn't have time before work to check my home computer for that Runge-Kutter, but I promise I'll post it tonight. csv.DictReader and DictWriter are awesome.
|
# ? Mar 14, 2013 02:47 |
|
How bad is it to instantiate things in a module? I.e. I have a module that has multiple classes that all need to see an object, and for better or worse it needs to be a singleton. I could either pass the reference around endlessly or just instantiate it in the base namespace and it it'd visible to everything within the module.
|
# ? Mar 14, 2013 04:36 |
|
JetsGuy posted:So do you still need that Runge-Kutter of mine? Because it looks to me like you solved it. I am positive mine wasn't 3d, but I'll post it as promised if you still want it. Not sure. I'm having problems now where my vectors are blowing up, so I'm trying to figure out why that's happening. It's most likely an error in the equation somewhere that I'm not seeing. If you have a pastebin post of your code I'd sure take a look at it, thanks.
|
# ? Mar 14, 2013 04:57 |
|
Thern posted:I just started looking into csv module for something I'm working on, so I'm curious. Is there a reason that you couldn't use the writerows method instead? In this particular case, no, not really, it was just the first example of a map that I had open in the file I was editing at the time. a lovely poster posted:operator.itemgetter(0) looks like a python statement, anyone with two weeks of python would understand what's going on It looks like a function call to me, and it's not at all clear that it's returning something that'll be itself callable. I also do lambdas if I'm doing a sort with a complicated comparison function, forex L.sort(key = lambda x: x[1]/x[2]) to sort a list based on the ratio of two fields.
|
# ? Mar 14, 2013 04:57 |
|
a lovely poster posted:Because writing the shortest lines possible is not really a goal for most software developers. I would use the first because in the case of someone else editing my code it would be a lot easier to understand. My point wasn't that optimizing for line length is a worthwhile goal in and of itself, my point was that I see many advantages to the lambda version and one of them is that it's shorter. I don't agree that the itemgetter version is easier to understand, unless you simply don't know what lambda does, but the idea that you should avoid language features because your coworkers don't understand the language they're using is silly. As fritz mentions, it's also not clear apriori that operator.itemgetter(0) returns a callable object.
|
# ? Mar 14, 2013 05:15 |
|
the posted:Not sure. I'm having problems now where my vectors are blowing up, so I'm trying to figure out why that's happening. It's most likely an error in the equation somewhere that I'm not seeing. If you have a pastebin post of your code I'd sure take a look at it, thanks. Keep in mind this was for a HW assignment almost 7 years ago when I was maybe 2-3 weeks into learning any computer language in a serious manner. I look at this code, and holy gently caress I'd write this much differently nowadays. Also, I had to output every iteration, that's why all the printing. In any case, the basics of it seem to be there... hope it's useful. code:
I can guarantee it works for sin/cos! JetsGuy fucked around with this message at 06:01 on Mar 14, 2013 |
# ? Mar 14, 2013 05:58 |
|
Hey again, Back on page 247 or whatever I asked about a library or module or something for me to expedite the process of making an IRC bot. I decided to go with "ircutils": http://dev.guardedcode.com/docs/ircutils/index.html It was exactly what I was looking for and it's a very small, well-enough documented library and a good enough tutorial to do what you need to do. Just wanted to share here in case anyone from the future searches this old post of mine here looking for how to make an IRC bot. PS: Hi, future goon!
|
# ? Mar 14, 2013 18:27 |
|
Something weird is going on. I have this statement:Python code:
the fucked around with this message at 19:04 on Mar 14, 2013 |
# ? Mar 14, 2013 19:00 |
|
the posted:Something weird is going on. I have this statement: Python code:
|
# ? Mar 14, 2013 19:08 |
|
Xerophyte posted:If you're still initializing using something like Thanks. I've been told that's dangerous to do before. And I should have remembered that.
|
# ? Mar 14, 2013 19:11 |
|
Man some of you guys are so good at reading other peoples code that's just mathematically impenetrable to me, I guess that comes with years of experience. As a self taught programmer though I think I might be hitting a bit of a wall, I have trouble designing efficient algorithms in particular, you good programmers seem to use some mathematical knowledge to make something efficient where I would make a huge set of nested loops. Might not be the thread for it but I realised this while reading this page, can someone recommend a book that contains the maths necessary to be a good programmer but is accessible? Like not necessarily a college student's maths textbook, but more in depth than high school level maths?
|
# ? Mar 14, 2013 19:40 |
|
aeverous posted:Man some of you guys are so good at reading other peoples code that's just mathematically impenetrable to me, I guess that comes with years of experience. As a self taught programmer though I think I might be hitting a bit of a wall, I have trouble designing efficient algorithms in particular, you good programmers seem to use some mathematical knowledge to make something efficient where I would make a huge set of nested loops. Might not be the thread for it but I realised this while reading this page, can someone recommend a book that contains the maths necessary to be a good programmer but is accessible? Like not necessarily a college student's maths textbook, but more in depth than high school level maths? I would really consider checking out edx's introduction to python programming class. https://www.edx.org/courses/MITx/6.00x/2013_Spring/about They go into some pretty good depth regarding popular algorithms and ways to use them.
|
# ? Mar 14, 2013 19:43 |
|
the posted:Thanks. I've been told that's dangerous to do before. And I should have remembered that. If you really think about the Python object model and what = is actually doing, it really helps to avoid making those kind of mistakes. If you aren't clear on it right now, it's going to really bit you in the rear end later.
|
# ? Mar 14, 2013 19:48 |
|
a lovely poster posted:I would really consider checking out edx's introduction to python programming class. I'll second this. I'm a beginning programmer and did this class last year and it was quite good. They do teach a section on Big O notation and efficient coding.
|
# ? Mar 14, 2013 19:51 |
|
What's the idiomatic way for initializing a bunch of variables to the same value without that kind of sharing?
|
# ? Mar 14, 2013 19:55 |
|
yaoi prophet posted:What's the idiomatic way for initializing a bunch of variables to the same value without that kind of sharing? I might do something like Python code:
|
# ? Mar 14, 2013 20:00 |
|
yaoi prophet posted:What's the idiomatic way for initializing a bunch of variables to the same value without that kind of sharing? Python code:
Edit 2: Python code:
Munkeymon fucked around with this message at 22:27 on Mar 14, 2013 |
# ? Mar 14, 2013 20:02 |
|
I am trying to use a statistical test in SciPy but I am not sure I understand how to call it correctly. The test documentation is located here: Fligner's test documentation The following code runs just fine (where vfb_dataList and hsp_dataList are both Python lists): Python code:
Python code:
Python code:
|
# ? Mar 15, 2013 02:33 |
|
Love Stole the Day posted:Hey again, I have a project that I kind of go back to every often that uses this too, I agree it gives you a nice way to build simple IRC bots. Watch out if Python3 support matters to you though, it isn't compatible and doesn't appear to be actively developed any longer.
|
# ? Mar 15, 2013 02:56 |
|
Jose Cuervo posted:I am trying to use a statistical test in SciPy but I am not sure I understand how to call it correctly. The test documentation is located here: Fligner's test documentation Maybe try "center = 'median' "?
|
# ? Mar 15, 2013 03:21 |
|
Let's say I have a timer T that increments in DT and runs while T < TOFF. Like an example would be T = 0, DT = 3, TOFF = 11. So T = 0, 3, 6, 9.. then stops after the next DT. I want to store some values when T is approximately halfway to TOFF, and then stop before the next DT. But I won't know what that exact number is (or it might not get to literally 50% of TOFF). How do I do this? I'm thinking something like: Python code:
|
# ? Mar 15, 2013 03:24 |
|
I'd probably take the interval around [TOFF/2 - DT/2, TOFF/2 + DT/2]. Since this interval is DT across, you'll have exactly one index inside of it:Python code:
|
# ? Mar 15, 2013 03:31 |
|
Can I use numpy.around() to fix that?
|
# ? Mar 15, 2013 03:38 |
|
How about just if (t>toff/2) and (t-dt<toff/2) ? It isn't centered but that shouldn't really matter.
|
# ? Mar 15, 2013 04:29 |
|
fritz posted:Maybe try "center = 'median' "? Yep that worked. Did something in the way the documentation was written point you towards doing that?
|
# ? Mar 15, 2013 04:32 |
|
Jose Cuervo posted:Yep that worked. Did something in the way the documentation was written point you towards doing that? Yeah, the "sample1, sample2, ..." in the documentation suggested you could put in as many arrays as you wanted, so you'd have to pass the other stuff with explicit keywords.
|
# ? Mar 15, 2013 04:41 |
|
aeverous posted:Man some of you guys are so good at reading other peoples code that's just mathematically impenetrable to me, I guess that comes with years of experience. As a self taught programmer though I think I might be hitting a bit of a wall, I have trouble designing efficient algorithms in particular, you good programmers seem to use some mathematical knowledge to make something efficient where I would make a huge set of nested loops. Might not be the thread for it but I realised this while reading this page, can someone recommend a book that contains the maths necessary to be a good programmer but is accessible? Like not necessarily a college student's maths textbook, but more in depth than high school level maths? For me its part experience, part reading this thread, and stack overflow for years. Thinking back, it amazes me how much better I've become (and how much more I have to go). Like I said, looking at the code I wrote when i first was learning, I am shocked at how I coded that then and how I would code it now. Like you, I have no formal training in python (or any other code), I've just had one scientific programming class, but most of the coding I do now I am self taught in. PS - Stack Overflow is great, but can be kind of frustrating at times.
|
# ? Mar 15, 2013 16:04 |
|
I don't really understand how to spot whether I may be writing spaghetti or ravioli code. I want to be a good python programmer, so I have read the most recent PEP and I try to code readable but efficient code. Would anyone mind posting examples of python spaghetti/ravioli code for examples of how not to code? With no formal training but years of experience, I am worried about bad habits that I may not even realize I have
|
# ? Mar 15, 2013 21:20 |
|
|
# ? May 9, 2024 08:57 |
|
QuarkJets posted:I don't really understand how to spot whether I may be writing spaghetti or ravioli code. I want to be a good python programmer, so I have read the most recent PEP and I try to code readable but efficient code. Would anyone mind posting examples of python spaghetti/ravioli code for examples of how not to code? With no formal training but years of experience, I am worried about bad habits that I may not even realize I have For one thing, follow the Coding Horrors thread.
|
# ? Mar 15, 2013 23:09 |