Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
vikingstrike
Sep 23, 2007

whats happening, captain
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:
import re

try:
    db_lines = [re.sub(';', '', line) for line in open('dbfile.whatevs', 'r')]
except IOError:
    print "poo poo is broken"

Adbot
ADBOT LOVES YOU

Bazanga
Oct 10, 2006
chinchilla farmer

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:

code:

inputfile =  'your\path\here\uglyfile.txt'
outputfile = 'your\path\here\freshfile.txt'

with open(inputfile) as f:
    lines = [line.strip() for line in f.readlines()]

multiline = False
holder = list()

with open(outputfile,'a') as f:
    for line in lines:
        if multiline:
            if line.endswith('\\'):
                holder.append(line)
            else:
                print>>f, ''.join(holder)
                multiline = False
                holder = list()

        else:
            if line.endswith('\\'):
                multiline = True
                holder.append(line.rstrip('\\'))
            elif line == ';':
                pass
            else:
                print>>f, line
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.

This is much better than the weird C-in-Python implementation I was hacking away at. Thanks!

FoiledAgain
May 6, 2007

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.

This is much better than the weird C-in-Python implementation I was hacking away at. Thanks!

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.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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:
ax = fig.add_subplot(111)
ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
Dur.

FoiledAgain
May 6, 2007

I was playing with lambda just because it came up in the thread, and I was comparing this:

code:
def sigmoid(n):
    return 1/(1+math.e**(-n))

Y = [sigmoid(x) for x in X]
with this:

code:
Y = [lambda x: 1/(1+math.e**(-x)) for x in X]
Unexpectedly, the result of the second is a list full of functions. For some reason I thought that would do the lambda function "inline" and then make a list full of the results. I also have no academic background in programming, so I'm probably missing crucial information to understand this. Is this what you smarter people would have expected to happen?

super_chair
Mar 13, 2012
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.

spankweasel
Jan 4, 2006

super_chair posted:

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.

The last one (with quicksort) is actually impressive in it's obfuscation.

Modern Pragmatist
Aug 20, 2008

FoiledAgain posted:

I was playing with lambda just because it came up in the thread, and I was comparing this:

code:
def sigmoid(n):
    return 1/(1+math.e**(-n))

Y = [sigmoid(x) for x in X]
with this:

code:
Y = [lambda x: 1/(1+math.e**(-x)) for x in X]
Unexpectedly, the result of the second is a list full of functions. For some reason I thought that would do the lambda function "inline" and then make a list full of the results. I also have no academic background in programming, so I'm probably missing crucial information to understand this. Is this what you smarter people would have expected to happen?

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:
sigmoid = lambda x: 1/(1+math.e**(-x))
Y = [sigmoid(x) for x in X]
But the point being made, is that apart from callbacks and very specific needs, it makes more sense to just do:
code:
 Y = [1/(1+math.e**(-x)) for x in X]

xPanda
Feb 6, 2003

Was that me or the door?
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:
$ pip search Django
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/pip-1.1-py2.6.egg/pip/basecommand.py", line 104, in main
    status = self.run(options, args)
  File "/usr/lib/python2.6/site-packages/pip-1.1-py2.6.egg/pip/commands/search.py", line 34, in run
    pypi_hits = self.search(query, index_url)
  File "/usr/lib/python2.6/site-packages/pip-1.1-py2.6.egg/pip/commands/search.py", line 48, in search
    hits = pypi.search({'name': query, 'summary': query}, 'or')
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1235, in request
    self.send_content(h, request_body)
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1349, in send_content
    connection.endheaders()
  File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
    self._send_output()
  File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
    self.send(msg)
  File "/usr/lib64/python2.6/httplib.py", line 739, in send
    self.connect()
  File "/usr/lib64/python2.6/httplib.py", line 720, in connect
    self.timeout)
  File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
    raise error, msg
error: [Errno 101] Network is unreachable
This is when making a connection with httplib:
code:
>>> import httplib
>>> conn1 = httplib.HTTPConnection("www.python.org")
>>> conn1.request("GET", "/index.html")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/httplib.py", line 914, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib64/python2.6/httplib.py", line 951, in _send_request
    self.endheaders()
  File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
    self._send_output()
  File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
    self.send(msg)
  File "/usr/lib64/python2.6/httplib.py", line 739, in send
    self.connect()
  File "/usr/lib64/python2.6/httplib.py", line 720, in connect
    self.timeout)
  File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
    raise error, msg
socket.error: [Errno 101] Network is unreachable
Using httplib to connect to the proxy works, of course:
code:
>>> conn2 = httplib.HTTPConnection("myproxy", 8080)
>>> conn2.request("GET", "http://www.python.org/index.html")
>>> r2 = conn2.getresponse()
I don't expect manually doing that connection to the proxy would be a good solution as it would presumably require modifying every errant program. Is there some way to make httplib-using programs go through the proxy? urllib handles proxies just fine.

duck monster
Dec 15, 2004

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.

:sigh:

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

tef
May 30, 2004

-> some l-system crap ->
Friends don't let friends use mysql :v:


(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)

duck monster
Dec 15, 2004

tef posted:

Friends don't let friends use mysql :v:
*postgresql install explodes all over hard drive with smugness*

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!

vikingstrike
Sep 23, 2007

whats happening, captain

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.

ufarn
May 30, 2009

duck monster posted:

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.

:sigh:

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
If you install ActivePython, you just type in `pypm mysql` or `pypm python-mysql`, and it should install. That's about the only way to do it in Windows to get it to work.

devilmouse
Mar 26, 2004

It's just like real life.
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.

tef
May 30, 2004

-> some l-system crap ->

duck monster posted:

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!

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.

vikingstrike
Sep 23, 2007

whats happening, captain
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

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

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?

Edit: oh poo poo with textmate 2's rmate script the VM route may be the perfect ticket.

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.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES
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.

So, to prevent matplotlib from using scientific notation on an axis, do this:

code:
ax = fig.add_subplot(111)
ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
Dur.

:doh:

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. :D

vikingstrike
Sep 23, 2007

whats happening, captain

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.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

vikingstrike posted:

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.

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.

tef
May 30, 2004

-> some l-system crap ->

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 :v:


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 :3:

vikingstrike
Sep 23, 2007

whats happening, captain

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.

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.

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.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

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. :v: It's gotten to a point that I will use num.float() instead of just float(). :smug:

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

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES
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... :(

vikingstrike
Sep 23, 2007

whats happening, captain

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.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

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.

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.

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!

duck monster
Dec 15, 2004

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.


Unless your software is being deployed on OSX, it isn't that crazy to use linux to test/develop on.

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.

Computer viking
May 30, 2011
Now with less breakage.

JetsGuy posted:

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!

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. :)

Auditore
Nov 4, 2010
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):
if n%2 == 0:
return "False"
elif n%2 != 0:
return "True"

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))
print type(is_odd(412))

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.

Dirty Frank
Jul 8, 2004

for your specific problem consider:
code:
>>> print type(True)
<type 'bool'>
>>> print type("True")
<type 'str'>
In a more general sense maybe going through something like http://learnpythonthehardway.org/book/ would help.

Auditore
Nov 4, 2010
I'm sorry, I don't understand. The quotation marks don't change anything.

Dirty Frank
Jul 8, 2004

How about this?

code:
>>> True == "True"
False
>>> True == True
True
>>> "True" == "True"
True
When you put quotation marks around something you're telling the computer that its a string (hence <type 'str'>), whereas without the quotation marks you're referring to something else; in this case a boolean (<type 'bool'>).

vikingstrike
Sep 23, 2007

whats happening, captain

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.

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

Auditore posted:

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,


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.


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.

code:
>>> def is_odd(n):
...     if n%2 == 0:
...         return False
...     else:
...         return True
...
>>> print type(is_odd(411))
<type 'bool'>
>>> print type(is_odd(412))
<type 'bool'>
:confused:

Gothmog1065
May 14, 2009
code:
>>> a = True
>>> print a
True
>>> print type(a)
<type 'bool'>

>>> b = "True"
>>> print b
True
>>> print type(b)
<type 'str'>
>>> 

>>> if a==b:
	print "Same thing"
    else:
	print "Not the same"

Not the same
So basically this is what Dirty Frank said. Rather than print the type of the evaluation you might try something like this:

code:
eval = is_odd(411)
if eval: 
    print "The value is odd"
else: 
    print "The value is even"
This literally reads: If the return from the function is_odd is True, then print "Odd", otherwise print "even".

With "True" you'd have to compare strings:
code:
eval = is_odd(411)
if eval == "True":
    print "Odd"
else:
    print "Even"
This reads: If the return from is_odd is the word "True" then Odd, otherwise even.

Remember, boolean only has two possible returns: True or False. It's confusing, but "True" and "False" are not the same thing.

Johnny Cache Hit
Oct 17, 2011

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.

duck monster
Dec 15, 2004

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

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

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 ;)

For your particular problem definitely check out numpy, and don't forget about pypy like tef mentioned. Pypy does seriously amazing things.

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.

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

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.

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

JetsGuy posted:

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.

The solution is obvious. Become a defense contractor and run loops around the existing ones because Python is better!

  • Locked thread