|
If it's an input file, I would personally shove all of that on a single line if it needs to be. I only worry about "pythonic" crap inside my .py files. I'd probably do something like: code:
|
# ? Mar 26, 2012 21:34 |
|
|
# ? May 9, 2024 10:56 |
|
FoiledAgain posted:This will write a new file that cuts out all the junk. Then you could just get the pairs cleanly from there. Not sure if this is what you want, or how "pythonic" it is, but it works and I don't contribute often enough in this thread for what I get out of it: This is much better than the weird C-in-Python implementation I was hacking away at. Thanks!
|
# ? Mar 26, 2012 22:22 |
|
Bazanga posted:Worked perfectly when I added a holder.append(line) to the else block in the "if multiline:" block. It wasn't appending the current line to the holder object before writing so it was missing the final parts of the multilines. Oh yeah, that's a problem! I see I forgot to strip away extra slashes in that block too. Glad it's what you wanted though.
|
# ? Mar 26, 2012 22:38 |
|
JetsGuy posted:Hey bro, week has been rough, as I anticipated. I'm gonna get to this sometime this weekend though. I figured this out. So, to prevent matplotlib from using scientific notation on an axis, do this: code:
|
# ? Mar 27, 2012 21:04 |
|
I was playing with lambda just because it came up in the thread, and I was comparing this:code:
code:
|
# ? Mar 28, 2012 01:50 |
|
Guys, come on. The real purpose of lambda is to let us obfuscate code just like the Perl people. The official FAQ literally supports this.
|
# ? Mar 28, 2012 02:05 |
|
super_chair posted:Guys, come on. The last one (with quicksort) is actually impressive in it's obfuscation.
|
# ? Mar 28, 2012 03:29 |
|
FoiledAgain posted:I was playing with lambda just because it came up in the thread, and I was comparing this: Yes. That is the point of a lambda function. When you use it it creates a function object WITHOUT executing it. That's why it's important for Tkinter callbacks, where you want to provide a function object to the GUI and allow the GUI to execute it, but you don't want to write a stand-alone function. To get the results you'd expect you'd just do: code:
code:
|
# ? Mar 28, 2012 03:31 |
|
I'm having an issue with httplib and, apparently, the proxy I must use. It first manifested when trying to use PIP, but also appears to be preventing Dropbox for linux from working also. Anything that uses httplib gets a "Network is unreachable" error. http_proxy and similar environment variables are all set and work with other programs. This is when using pip from the terminal. Even specifying the --proxy option does not help. code:
code:
code:
|
# ? Mar 28, 2012 05:41 |
|
Does anyone know where I can find an installer for mysql-python on the mac. I'm starting to go grey remembering why I sometimes loving hate python on this platform. Since like 90% of everything I or everyone else I know who uses python usually interacts at some point with python, this should be standard bloody library, to be honest. Seriously. e: Aw gently caress it. I know whats wrong. Mysql in XAMPP installs in its own little bubble. Argh. Apple, please can we have an anointed official mysql duck monster fucked around with this message at 12:45 on Mar 28, 2012 |
# ? Mar 28, 2012 12:25 |
|
Friends don't let friends use mysql (fwiw most of the python developers I know on osx use a linux vm, or connect to a linux box, instead of the slow tortuous painful death that is installing packages on osx for python)
|
# ? Mar 28, 2012 12:28 |
|
tef posted:Friends don't let friends use mysql quote:(fwiw most of the python developers I know on osx use a linux vm, or connect to a linux box, instead of the slow tortuous painful death that is installing packages on osx for python) Normally I develop on sqlite3 and deploy to mysql or if I'm feeling like a lazy oval office on an intranet job sqlite3. But I'm needing to do some stuff with jasper reports re some data from a django job and dear loving god making jasper talk to sqlite3 is like pulling teeth. Apple seriously needs to adopt apt-get , or anoint brew or something as its official distro thingo. Actually apt get would be the bomb. That poo poo never fails me on debian. With that said: gently caress fink!
|
# ? Mar 28, 2012 12:48 |
|
tef posted:(fwiw most of the python developers I know on osx use a linux vm, or connect to a linux box, instead of the slow tortuous painful death that is installing packages on osx for python) I've actually thought about doing this, too. Glad to know I'm not crazy. yum is so awesome and it pains me that OS X has no complement that works nearly as well.
|
# ? Mar 28, 2012 13:29 |
|
duck monster posted:Does anyone know where I can find an installer for mysql-python on the mac.
|
# ? Mar 28, 2012 13:37 |
|
I just install everything possible through macports and everything seems to "just work". If you try to use the built-in Apple python with a mysql installation from a .dmg or goes halfsies with Brew, things get flaky. And then if there's a package that's not in macports yet, you can install pip through ports and go from there. I don't think I've run in to too much that I had to install by hand outside of ports.
|
# ? Mar 28, 2012 13:46 |
|
duck monster posted:Apple seriously needs to adopt apt-get , or anoint brew or something as its official distro thingo. I hear nice things about brew, but I've found the least painful thing is still using OSX as a dumb client for a linux install. vikingstrike posted:I've actually thought about doing this, too. Glad to know I'm not crazy. Unless your software is being deployed on OSX, it isn't that crazy to use linux to test/develop on.
|
# ? Mar 28, 2012 14:14 |
|
In the software os x thread there are people that mention brew fucks with the permissions on /usr/bin and other folders. Any truth to this? Edit: oh poo poo with textmate 2's rmate script the VM route may be the perfect ticket. vikingstrike fucked around with this message at 15:06 on Mar 28, 2012 |
# ? Mar 28, 2012 15:02 |
|
vikingstrike posted:In the software os x thread there are people that mention brew fucks with the permissions on /usr/bin and other folders. Any truth to this? brew recommends that you do something awful like chmod 777 /usr/local/bin. You don't have to, though. They just seem to think that requiring users to use sudo to install system packages is somehow a bad thing.
|
# ? Mar 28, 2012 15:36 |
|
So I got into this whole discussion today with someone about high-level lanuages vs low-level languages. The meat of the problem is the guy is coding some fairly involved numerical integrals that have to literally be run thousands of times (lots of data!). The problem is that he originally coded it in Mathematica, but is now moving it cpp because it runs entirely too slow on Mathematica. I understand one of the biggest "pluses" (nyuk nyuk) regarding cpp is its speed, but I'm not entirely convinced you couldn't code something like that in python. IF coded well, I bet you could do it without much difference in speed. I guess the counter arguement would be that in cpp you'd not have to be as creative with coding as you do with cpp to get it to run fast. Then again, the biggest mistake I think people make is they try to optimize too early. Design and write your code, get it to work right. THEN try to slim down time if you don't like how fast it works. Then again, I'm thinking from a scientific programming angle, so maybe this is a laughable perspective for a py developer. Thermopyle posted:I figured this out. Sorry I didn't think of that, I have indeeed had to do that in the past. poo poo has been nuts with the spacecraft data I've been having to crunch lately. In the future, I'll be better about keeping up with e-promises.
|
# ? Mar 28, 2012 15:56 |
|
Sailor_Spoon posted:brew recommends that you do something awful like chmod 777 /usr/local/bin. You don't have to, though. They just seem to think that requiring users to use sudo to install system packages is somehow a bad thing. Ahh, thanks for the clarification! Yeah, that advice is dumb as poo poo. Jesus, that's really bad. Another reason I asked was that I installed it once, checked my folder perms, and wondered what the hell people were talking about.
|
# ? Mar 28, 2012 16:07 |
|
vikingstrike posted:Ahh, thanks for the clarification! Yeah, that advice is dumb as poo poo. Jesus, that's really bad. That's nothing compared to the poo poo macports puts you through. Fun macports fact - if you don't install everything through macports, macports gets really loving furious and screws up your system. Sometimes really bad. I've had to completely reinstall the entire system more than once because of macports being such a loving rear end in a top hat about this.
|
# ? Mar 28, 2012 16:14 |
|
JetsGuy posted:Then again, the biggest mistake I think people make is they try to optimize too early. Design and write your code, get it to work right. THEN try to slim down time if you don't like how fast it works. Then again, I'm thinking from a scientific programming angle, so maybe this is a laughable perspective for a py developer. usually i've found when people profile and find a bug, they call it a bug and fix it. when they optimise things, they're changing poo poo without testing or measuring it I've written python that outperforms C++ and Java implementations of things. Mostly because I picked the right algorithm from the outset. If you've doing the right thing in python, doing the right thing in C++ will be faster - but will take much longer to get working correctly. That said, judicious use of numpy/pypy may work out quite well
|
# ? Mar 28, 2012 16:43 |
|
JetsGuy posted:So I got into this whole discussion today with someone about high-level lanuages vs low-level languages. The meat of the problem is the guy is coding some fairly involved numerical integrals that have to literally be run thousands of times (lots of data!). The problem is that he originally coded it in Mathematica, but is now moving it cpp because it runs entirely too slow on Mathematica. In general, which py libraries do you use most often? I'm assuming that you're using nump/scipy, at least. I do Matlab work with people at school, but at home, I've been doing personal work in python and am wondering if there is a nice package I'm missing. I pretty much just use the ScipySuperpack.
|
# ? Mar 28, 2012 16:56 |
|
vikingstrike posted:In general, which py libraries do you use most often? I'm assuming that you're using nump/scipy, at least. I do Matlab work with people at school, but at home, I've been doing personal work in python and am wondering if there is a nice package I'm missing. I pretty much just use the ScipySuperpack. I've gotten to a point that I forget that there's built-in versions of many things I do in numpy. It's gotten to a point that I will use num.float() instead of just float(). I use numpy in literally every python program I have ever written. Maybe this sounds very newbie to say, but numpy arrays just work a lot better towards my way of thinking than the python tuples. Also, numpy has a lot of *very* quick operations if you know how to use it. Second up is matplotlib just because it rules, is made to basically be MATLAB's plotter for python (which makes showing it to other astrophysicists easy). It's got a bit of a learning curve, but once you know how to make the kind of plots you (usually) make, it's easy. Third is Space Telescope's PyFITS, which loving rules. I do a *lot* of work reading our spacecraft data, and sometimes there's just no other way to do what you want but to read the raw HDUs. http://www.stsci.edu/institute/software_hardware/pyfits Next up is SciPy, which I use often, but I've been using less and less. The problem is a lot of the fitting algorithims in SciPy don't serve the purposes I need. It's great for data where you have even error bars, or fairly well behaved data. The problem is routines like curve_fit are not well behaved for the data I generally deal with. *Part* of the problem is I deal with very chaotic data, so w/e. The old fortran MPFIT tends to work great. I know several people that have re-written it to python too! I don't use Hubble data too too much, so I don't generally use it, but I know a *lot* of astronomers that use multi-drizzle. There's literally no reason to use it if you're not doing HST observations. However, if you're interested in just the kind of coding and problems they are solving here is a link: http://stsdas.stsci.edu/multidrizzle/multidrizzle_overview.htm
|
# ? Mar 28, 2012 17:13 |
|
I general, the three languages I run into the most are: FORTRAN-95 IDL Python Pretty much in that order. There's some cpp, as I indicated, but there ya have it. I've not coded in IDL in years, but I have to read enough IDL code that I can generally fix small bugs when poo poo goes wrong. Our major analysis packages were written in IDL and FORTRAN. Thank God I've not had to read (much) FORTRAN code. I keep telling myself that I have to learn cpp so I can get a REAL JOB (TM) outside of scientific research, but I just am exhausted when I go home...
|
# ? Mar 28, 2012 17:16 |
|
JetsGuy posted:I keep telling myself that I have to learn cpp so I can get a REAL JOB (TM) outside of scientific research, but I just am exhausted when I go home... I feel you on this. A lot of the people that I run into use cpp. "It's low level, so I can do this and that and it's faster!" Whereas, I generally care more about the readability of my code and being able to develop quickly. I believe that you do more numerical work than me (although, I've used numpy, matplotlib, and scipy from your list, no need for the astrophysics stuff, i really enjoy pandas too). A lot of the data work I do involves strings and manipulating, searching, and parsing, which I am always looking for techniques to improve on. Like, I'll have a file with 2,000,000+ rows that I need to basically grep quickly, store results, etc.
|
# ? Mar 28, 2012 17:24 |
|
vikingstrike posted:I feel you on this. A lot of the people that I run into use cpp. "It's low level, so I can do this and that and it's faster!" Whereas, I generally care more about the readability of my code and being able to develop quickly. Yes, by and large my data products are big numeric tables with some array of strings I make manually describing the output. I would recommend looking at PyFITS, however, as you can totally use it for non-astrophysics purposes. Just because it was written by ScSTI doesn't mean you can't use it for your own data management purposes!
|
# ? Mar 28, 2012 17:38 |
|
tef posted:I hear nice things about brew, but I've found the least painful thing is still using OSX as a dumb client for a linux install. Yeah, I've been taking to using my XBMC/debian box to dev on a bit later since netatalk file sharing integrates loving smooth as hell with macs. Probably time I moved my django dev over there too.
|
# ? Mar 29, 2012 06:02 |
|
JetsGuy posted:Yes, by and large my data products are big numeric tables with some array of strings I make manually describing the output. There's some distinct similarities with the bioinformatics work I do in there. Most of my colleagues are biologists and the like, so there's a certain culture for GUI tools, but a lot of lifting is (thankfully) done in scripts I have the source of. We almost exclusively use R, probably because it has packages for more or less everything you might want to do with biological data (and statistical analysis) - but I've written a chunk of python to do more housekeeping-ish tasks. It's all tab-separated text files with a bit of text in the margins around huge tables of numbers, anyway.
|
# ? Mar 29, 2012 08:30 |
|
Hi guys, I'm stuck on this one for a quiz. "Write a boolean-valued function is_odd(n) that returns True if and only if its int parameter n is odd. [Hint: consider the mod operator, '%'.]" I have, quote:def is_odd(n): However when you 'check' the answer in the quiz program it runs examples through the function to see if it works. Unbeknownst to me, it tries the following two commands. quote:print type(is_odd(411)) Where the correct answers are <type 'bool'>. If I want the first numbers-based part correct I can only get <type 'str'> and vice versa. Plz halp.
|
# ? Mar 29, 2012 10:57 |
|
for your specific problem consider:code:
|
# ? Mar 29, 2012 11:07 |
|
I'm sorry, I don't understand. The quotation marks don't change anything.
|
# ? Mar 29, 2012 11:12 |
|
How about this? code:
|
# ? Mar 29, 2012 11:26 |
|
Auditore posted:I'm sorry, I don't understand. The quotation marks don't change anything. Yes, they do. Use the code from the post above and run type() on the answers to see it.
|
# ? Mar 29, 2012 12:19 |
|
Auditore posted:Hi guys, I'm stuck on this one for a quiz. code:
|
# ? Mar 29, 2012 12:47 |
|
code:
code:
With "True" you'd have to compare strings: code:
Remember, boolean only has two possible returns: True or False. It's confusing, but "True" and "False" are not the same thing.
|
# ? Mar 29, 2012 18:52 |
|
JetsGuy posted:I keep telling myself that I have to learn cpp so I can get a REAL JOB (TM) outside of scientific research, but I just am exhausted when I go home... In my career I've programmed in PHP, Python, Ruby, and Erlang. I guess what I'm saying is that I hope like hell I never get one of those real jobs, because I'm not a fan of cpp For your particular problem definitely check out numpy, and don't forget about pypy like tef mentioned. Pypy does seriously amazing things.
|
# ? Mar 29, 2012 21:05 |
|
gently caress cpp. Like java, I just get headaches looking at it. I recently got handed a rescue job after a contractor did a runner on a J2EE job he was doing. he had been at it 2 months. Hundreds and hundreds of files. I threw it all out and rewrote it in a week and a half with django and it runs *faster* and better and doesnt cause the vhost to poo poo itself with memory exhaustion anymore. (Java, but yeah, CPP is the same giant codebase pattern-madness poo poo but with added pointer/malloc hell.) I've grown awfully fond of ObjC lately. *THAT* is how you do an object oriented C thats agile as gently caress (storyboards + arc on iphone, goodness me!) and is based on smalltalk goodness rather than simula badness duck monster fucked around with this message at 09:04 on Mar 30, 2012 |
# ? Mar 30, 2012 09:01 |
|
Kim Jong III posted:In my career I've programmed in PHP, Python, Ruby, and Erlang. I guess what I'm saying is that I hope like hell I never get one of those real jobs, because I'm not a fan of cpp Well, yeah, I use numpy literally every day. I have for 7 years. The problem I face is: Option 1) Leave research-based jobs, get job that is "scientific programming" or something in the D-industry where they need a coder who is *very* good at math. They want me to be a cpp or java guru from the start. Option 2) Try for CS job. They want me to be familiar with db-structures (which we don't use in astrophysics). Both options sneer at python. duck monster posted:gently caress cpp. Like java, I just get headaches looking at it. I recently got handed a rescue job after a contractor did a runner on a J2EE job he was doing. he had been at it 2 months. Hundreds and hundreds of files. The *entire* defense industry codes in cpp and java. It is maddening. Oh, excpept for when you see a job that wants, God help us, Ada.
|
# ? Mar 30, 2012 16:48 |
|
|
# ? May 9, 2024 10:56 |
|
JetsGuy posted:The *entire* defense industry codes in cpp and java. It is maddening. The solution is obvious. Become a defense contractor and run loops around the existing ones because Python is better!
|
# ? Mar 30, 2012 17:29 |