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
SurgicalOntologist
Jun 17, 2004

I don't, but I'm pretty sure you're correct here. bash_profile is for login shells, bashrc is for interactive, non-login shells, so I don't think there would be any issues. Most similar tools put their code in bashrc, not bash_profile.

It could be that the author is on OSX, where the Terminal app opens a new login shell for every window. But that's not the case on Linux which is why you encountered an issue.

http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

Adbot
ADBOT LOVES YOU

lotor9530
Apr 29, 2009
I'm back with another question!

My Code:
code:
import sys
import numpy as np
import matplotlib.pyplot as plt

array = np.loadtxt('a_' + sys.argv[2] + '_a.dat', skiprows=(1), usecols=(1)
plt.hist(array, bins=100, normed=True)
plt.show()
sys.argv[2] is a number, I'll use 1.0 for the value for my example.

Sample a_1.0_b.dat
code:
Title OtherTitle
100 2.153
200 2.354
300 3.653
What I think it should do:
Read the second column of the file "a_1.0_b.dat" into an array, excluding the first row.
Plot a normalized histogram of those values. IE: the total area of the histogram = 1

What it does:
code:
  File "myfile.py", line 73
    plt.hist(array, bins=100, normed=True)
      ^
SyntaxError: invalid syntax

Thanks in advance for any help.

accipter
Sep 12, 2003

lotor9530 posted:

I'm back with another question!

You are missing a parenthesis on the previous line.

lotor9530
Apr 29, 2009

accipter posted:

You are missing a parenthesis on the previous line.

Damnit. I feel like an idiot now.

Thanks for the quick reply! One of these days I'll stop sucking at python.

namaste friends
Sep 18, 2004

by Smythe

lotor9530 posted:

Damnit. I feel like an idiot now.

Thanks for the quick reply! One of these days I'll stop sucking at python.

Dude, use pycharm. It will catch these mistakes for you.

Space Kablooey
May 6, 2009


lotor9530 posted:

Damnit. I feel like an idiot now.

Thanks for the quick reply! One of these days I'll stop sucking at python.

One way to deal with SyntaxErrors is to take a break for a little while and then come back. :)

Rlazgoth
Oct 10, 2003
I attack people at random.
I just finished the Codecademy course on Python but I have the feeling that what I've learned won't be any good for practical applications. Any recommendations on other, more advanced courses (but not too much - this is my first attempt at learning programming), which I can take up as a follow up?

Thermopyle
Jul 1, 2003

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

Rlazgoth posted:

I just finished the Codecademy course on Python but I have the feeling that what I've learned won't be any good for practical applications. Any recommendations on other, more advanced courses (but not too much - this is my first attempt at learning programming), which I can take up as a follow up?

My brother fiddled around with the code acaedmy python course. I told him to move on to Think Python.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

SurgicalOntologist posted:

I don't, but I'm pretty sure you're correct here. bash_profile is for login shells, bashrc is for interactive, non-login shells, so I don't think there would be any issues. Most similar tools put their code in bashrc, not bash_profile.

It could be that the author is on OSX, where the Terminal app opens a new login shell for every window. But that's not the case on Linux which is why you encountered an issue.

http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

Actually I would not put it in .bashrc if it has a chance of outputting content. I'd do what RVM does and actually output a recommendation to put it on either .bashrc or .bash_profile. You can see the ouput here: http://rvm.io/support/faq under "What shell login means ('bash -l')".

Pudgygiant
Apr 8, 2004

Garnet and black? More like gold and blue or whatever the fuck colors these are
Is there a relatively trivial way to load a webpage, watch for GET requests triggered by JS, and pull the cookies out of those? I can't get Webdriver to play nice with it.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

deimos posted:

Actually I would not put it in .bashrc if it has a chance of outputting content. I'd do what RVM does and actually output a recommendation to put it on either .bashrc or .bash_profile. You can see the ouput here: http://rvm.io/support/faq under "What shell login means ('bash -l')".

quote:

RVM by default adds itself currently to ~/.bash_profile file, and the recommended way is to enable login shell in gnome-terminal (and screen).

Is that this thing? What is actually changing when this setting changes?

hooah
Feb 6, 2006
WTF?
For someone coming from another language (C++ specifically), what are some recommendations for learning Python?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
As was posted just above: http://www.greenteapress.com/thinkpython/

Thermopyle
Jul 1, 2003

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

hooah posted:

For someone coming from another language (C++ specifically), what are some recommendations for learning Python?

Unless someone else has something specific to say about coming from C++, you're probably just best off with the Think Python thing. It will be a breeze to go through for someone with programming experience and will get you up to speed on Python syntax and other specifics.

Haystack
Jan 23, 2005





I'd also add that Python's official documentation is excellent, and good for getting oriented by.

Beyond that, it depends on what you want to do. In my estimation, Python's strong points are web programming, scientific scripting, systems administration, general scripting, and rapid prototyping.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Haystack posted:

I'd also add that Python's official documentation is excellent, and good for getting oriented by.

Beyond that, it depends on what you want to do. In my estimation, Python's strong points are web programming, scientific scripting, systems administration, general scripting, and rapid prototyping.

Just chiming in to say that's how I learned: I read through the docs and fiddled with examples in a REPL. I already knew several other not-super-dissimilar languages (JS, PHP) at the time, though.

Rlazgoth
Oct 10, 2003
I attack people at random.
While we're at it, I'm learning Python for my first language based on the recommendation of it being easy to learn for beginners. With that said, I have specific needs which I am not sure I will be able to meet with Python alone.

Specifically, I'm learning programming in order to do stuff such as handling large data sets in CSV and XLS files among other formats (I want to automate some of the more repetitive tasks such as merging files and such); running statistical analysis; and retrieve specific types of information from the Internet while saving it in a workable format(something like, retrieving all search results in Google Scholar for publications in a given country, and sort them neatly into an Excel file). Will I be able to (eventually) do all this in Python, or would I be better off moving on to another language once I'm done learning this?

EAT THE EGGS RICOLA
May 29, 2008

Rlazgoth posted:

While we're at it, I'm learning Python for my first language based on the recommendation of it being easy to learn for beginners. With that said, I have specific needs which I am not sure I will be able to meet with Python alone.

Specifically, I'm learning programming in order to do stuff such as handling large data sets in CSV and XLS files among other formats (I want to automate some of the more repetitive tasks such as merging files and such); running statistical analysis; and retrieve specific types of information from the Internet while saving it in a workable format(something like, retrieving all search results in Google Scholar for publications in a given country, and sort them neatly into an Excel file). Will I be able to (eventually) do all this in Python, or would I be better off moving on to another language once I'm done learning this?

This is all stuff that be done in Python without too much trouble.

Haystack
Jan 23, 2005





Rlazgoth posted:

While we're at it, I'm learning Python for my first language based on the recommendation of it being easy to learn for beginners. With that said, I have specific needs which I am not sure I will be able to meet with Python alone.

Specifically, I'm learning programming in order to do stuff such as handling large data sets in CSV and XLS files among other formats (I want to automate some of the more repetitive tasks such as merging files and such); running statistical analysis; and retrieve specific types of information from the Internet while saving it in a workable format(something like, retrieving all search results in Google Scholar for publications in a given country, and sort them neatly into an Excel file). Will I be able to (eventually) do all this in Python, or would I be better off moving on to another language once I'm done learning this?

Those are all pretty much exactly in python's sweet spot. There are libraries for dealing with everything you listed.

EAT THE EGGS RICOLA
May 29, 2008

Oh! Also check out Open Refine (formerly Google Refine). It's a tool for working with and extending data using data from other sources. It also stores all of the transformations you do in the project, so if you want to repeat a set of transformations, you can just pop in another huge dataset and tell it to run the same changes again.

hooah
Feb 6, 2006
WTF?
Alright, thanks for the recommendation. I'd prefer not to faff about with Linux if I don't have to, since I use Windows 90%+ of the time, so with that in mind, what's the best IDE for Python? I saw Python Tools for Visual Studio, which appeals to me since I'm fairly competent with VS anyway. Is that any good?

EAT THE EGGS RICOLA
May 29, 2008

hooah posted:

Alright, thanks for the recommendation. I'd prefer not to faff about with Linux if I don't have to, since I use Windows 90%+ of the time, so with that in mind, what's the best IDE for Python? I saw Python Tools for Visual Studio, which appeals to me since I'm fairly competent with VS anyway. Is that any good?

PyCharm.

Thermopyle
Jul 1, 2003

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


...is always the right answer.

Karate Bastard
Jul 31, 2007

Soiled Meat
I've used Python as my main professional tool for the last 6 or so years, and now I'm sort of handholding my friend who's a learning programming as a hobby. I recommended him to start with python, and in particular http://learnpythonthehardway.org/ by Zed Shaw. I'd be interested to hear what you guys think of it, as a beginner's resource? I haven't read this one myself, but recommended it nonetheless based on the fact that I really liked "Learn C the hard way" by the same author, because of his down-to-business style.

I like that Zed wastes no time talking about stuff, but instead gets right down to doing them, and then when you've done them you can reason about them more efficiently because at that point you already know how they work, so it's less abstract. I also think the C one is well organized, so you're learning stuff pretty darn quickly, and despite this it feels like it's small and simple steps forward all the time.

In particular, I'd be interested to hear a comparison to this book:


I read 3 words of that and became angry. These words were "from TurtleWorld import *", in "Chapter 4 Case study: interface design".

Reading on just a tad, they go on to explain iteration, by showing how to repeatedly use the funtions fd() and lt() from their TurtleWorld package.

So chapter 4 on interface design covers iteration instead of how to choose good names for your interface, and the first example they present is complete garbage. I don't know one experienced python programmer who'd put fd() and lt() in an api that they'd show to others, instead of move_forward() and turn_left(). Rather, I believe they would be slapped about the ears if they did.

And please don't teach people to import *. Protip: import only what you're going to use, so you'll know what you're actually using, and from where you got it. Otherwise there will be misery, tears and ruin waiting for you down the line, when fd() suddenly is no longer "move forward" but "format drive" that you had no idea was going to be introduced in the next update to the package that your program imports * on the next line down.

So is the rest of this book equally garbage, or does it have redeeming qualities? (And is my recommendation in fact equally offensive? :) )

e: I cannot spell TurdleWorld.

Karate Bastard fucked around with this message at 21:18 on Oct 8, 2014

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

This should probably just get added to the OP at this point.

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Karate Bastard posted:

I read 3 words of that and became angry.

I'm pretty sure the author was keen on reproducing the original turtle graphics logo experience, where the commands were stuff like LT and PU. I never read much of those case studies chapters (because at the time I read the book they weren't there) but even if the author could update the chapter using the stdlib turtle I think it's a good experience to make the reader mess around with third party libraries at this point.

I think you have a point about import *, even if the author states the disadvantage in the previous chapter I feel like it's not a thing that should be encouraged in any way.

Anyway...

I don't like Zed Shaw, he's kind of a douche and his personality comes off in his book. I don't think it's a bad book really but it mildly irritates me how he teaches about programming as if he was a drill instructor. Some people are ok with that, it's a personality clash I guess. :shrug:

The Codecademy python course is great for people who never programmed before, but I'm pretty sure everyone comes out of it with the impression that it's kind of shallow. Because it really is shallow, and it's not their fault really. It's made for absolute beginners feel great about programming. In my opinion Think Python comes as a great follow-up because, even still with a newbie-friendly approach, it actually teaches a lot of CS/programming culture. I love the glossaries, I love how he defines a shitton of programming lexicon like data structure, accumulator, attribute etc. I keep referring back to these definitions even today.

I don't think Hard Way is shallow, but it's definitely not as deep as Think Python. There are aspects about it where it's better and contemporary, like the chapters about testing. Think Python's approach seems to be more academic and it misses practical stuff like that. But then I think a better follow-up to Think Python is something like Peter Norvig's course where he deals with these things and also a lot of other unintuitive python features.

Karate Bastard
Jul 31, 2007

Soiled Meat
Haha yes I can see how you could get annoyed by that tone, but I actually appreciate it. I don't have much time to spend on this stuff so I like the terseness, and when I feel compelled to cut/paste his examples and not learn a goddamn thing, he tells me not to, and I go well, ok then you cheeky bastard, and type it out like he says I should, and actually pay attention to what I do, actually learning the stuff faster.

In what way is he a douche? I have no idea who he is. I think I just found him on Google. Or some goon may have recommended the C book to me.

e: vvvvvv he's got all these "learn X the hard way" books, where "the hard way" is just typing everything out yourself, doing every exercise yourself, in order, from beginning to end. You're not supposed to skip ahead or copy/paste, but to type every single thing out yourself. Idea is that then you'll actually notice that there's actually brackets here or there instead of colons or what have you, and that is significant for some reason, and then you can reflect on that and possibly learn someting that you hadn't if you had skipped ahead or copypasted. Works for me :)

Karate Bastard fucked around with this message at 23:51 on Oct 8, 2014

qntm
Jun 17, 2009
I don't understand why anybody would want to learn Python the hard way. C, sure, C is a minefield. Python is meant to be relatively friendly and forgiving for first-timers.

No Safe Word
Feb 26, 2005

Karate Bastard posted:

In what way is he a douche? I have no idea who he is. I think I just found him on Google. Or some goon may have recommended the C book to me.

He's not really a douche he's just unrepentantly opinionated and doesn't apologize for it (not that he needs to), so he comes off a bit brusque if you disagree with one if his opinions. But I don't think it's malicious in intent, it's just his way of expressing his opinion. I mean I just googled his name for an example of it and a top result was his essay titled "Programmers Need To Learn Statistics Or I Will Kill Them All"

Thermopyle
Jul 1, 2003

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

Karate Bastard posted:

Think Python vs Hard Way

They both have things you can pick out and complain about...just like any programmer can do with any large enough sample of anothers code. Overall they are both good and both have been go-to recommendations in this thread for years.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

hooah posted:

Alright, thanks for the recommendation. I'd prefer not to faff about with Linux if I don't have to, since I use Windows 90%+ of the time, so with that in mind, what's the best IDE for Python? I saw Python Tools for Visual Studio, which appeals to me since I'm fairly competent with VS anyway. Is that any good?

Honestly, PyCharm rules but just get this: https://store.continuum.io/cshop/anaconda/

Use IPython Notebook for all your data munching and stats needs.

Nippashish
Nov 2, 2005

Let me see you dance!

Blinkz0rz posted:

Honestly, PyCharm rules but just get this: https://store.continuum.io/cshop/anaconda/

You say that like they're mutually exclusive. Pycharm+anaconda is a great combination. (but get miniconda and install the packages you need with conda/pip, anaconda is huge and includes a ton of stuff you will almost certainly never use).

Pollyanna
Mar 5, 2005

Milk's on them.


The Python thread might be the best place to ask: where do people usually get their datasets for Data Visualization projects, like on Ladyparts and Orienteer.it? I want to do my next project in dataviz, but I'm not sure where I'd get these open-source sets of data. I've done a good bit of Googling, but a lot of them are either heavily outdated, for pay, or don't actually have the statistics/data I need. Mining stuff from Twitter has proven to be a loving pain, too. :(

EAT THE EGGS RICOLA
May 29, 2008

Pollyanna posted:

The Python thread might be the best place to ask: where do people usually get their datasets for Data Visualization projects, like on Ladyparts and Orienteer.it? I want to do my next project in dataviz, but I'm not sure where I'd get these open-source sets of data. I've done a good bit of Googling, but a lot of them are either heavily outdated, for pay, or don't actually have the statistics/data I need. Mining stuff from Twitter has proven to be a loving pain, too. :(

Check out governmental open data portals (some are way better than others) or just search for "thing_you_want api" (lots of companies have api access to their data because it gets people to make cool stuff with their platform.) I've petitioned the city I live in to release lots of datasets and they've been good about it because it's pretty "safe" politically and everyone seems to love "open data".

hooah
Feb 6, 2006
WTF?
I feel pretty dumb. I installed PyCharm, and tried the "Hello, World!" program in the Think Python book (print('Hello, World!')). When I ran it in PyCharm, I see this in the output window:
code:
C:\Python33\python.exe "C:/Users/spart_000/Google Drive/Python/First/Hello"

Process finished with exit code -1073741515 (0xC0000135)
The book didn't mention any other code, so I don't think I missed anything in that regard. What am I not getting about Python?

accipter
Sep 12, 2003

Pollyanna posted:

The Python thread might be the best place to ask: where do people usually get their datasets for Data Visualization projects, like on Ladyparts and Orienteer.it? I want to do my next project in dataviz, but I'm not sure where I'd get these open-source sets of data. I've done a good bit of Googling, but a lot of them are either heavily outdated, for pay, or don't actually have the statistics/data I need. Mining stuff from Twitter has proven to be a loving pain, too. :(

I found this with a little bit of googling, which might be helpful. If you provide more specifics of what sort of data you are looking for we might be able to provide specific recommendations.

SurgicalOntologist
Jun 17, 2004

hooah posted:

I feel pretty dumb. I installed PyCharm, and tried the "Hello, World!" program in the Think Python book (print('Hello, World!')). When I ran it in PyCharm, I see this in the output window:
code:
C:\Python33\python.exe "C:/Users/spart_000/Google Drive/Python/First/Hello"

Process finished with exit code -1073741515 (0xC0000135)
The book didn't mention any other code, so I don't think I missed anything in that regard. What am I not getting about Python?

It's more likely to be something about your system/install, I would guess. Can you run a Python console from PyCharm (tools menu I think) or do you get an error right away?

psydude
Apr 1, 2008

I'm trying to write a simple script in python that effectively just automates a bunch of linux CLI commands and executes some perl/ruby scripts.

As far as I can tell, I can just use subprocess.call to issue commands and then pass any arguments, such as :

code:
subprocess.call(["cd", "~/DEPLOY/"])
subprocess.call(["perl", "/DEPLOY/test.pl"])
subprocess.Popen(["bash", "-c", "~/DEPLOY/vars.rb]
Is this even going to work? I've never used python this way before.

Thermopyle
Jul 1, 2003

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

psydude posted:

I'm trying to write a simple script in python that effectively just automates a bunch of linux CLI commands and executes some perl/ruby scripts.

As far as I can tell, I can just use subprocess.call to issue commands and then pass any arguments, such as :

code:
subprocess.call(["cd", "~/DEPLOY/"])
subprocess.call(["perl", "/DEPLOY/test.pl"])
subprocess.Popen(["bash", "-c", "~/DEPLOY/vars.rb]
Is this even going to work? I've never used python this way before.

Yes. Why don't you just try it and see?

Adbot
ADBOT LOVES YOU

hooah
Feb 6, 2006
WTF?

SurgicalOntologist posted:

It's more likely to be something about your system/install, I would guess. Can you run a Python console from PyCharm (tools menu I think) or do you get an error right away?

Interestingly, it works on my laptop, but not on my desktop. However, I was able to use the command-line interpreter to correctly print the statement. What does this mean?

  • Locked thread