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
JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

yaoi prophet posted:

I don't know how good Python is but I do know that you can run a Debian virtual machine on any computer that's not powered by a potato battery.
I know of at least one potato battery that is very likely running Debian...

Adbot
ADBOT LOVES YOU

Captain Capacitor
Jan 21, 2008

The code you say?
The biggest pain in the rear end for me with Python and Windows was having to have so many different SDKs and toolchains installed. I guess *nix spoiled me in that regard.

What I'm saying is that someone needs to port Homebrew to Windows.

Emacs Headroom
Aug 2, 2003
There's cygwin, but it's not tremendously awesome.

Munkeymon
Aug 14, 2003

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



http://sourceware.org/cygwinports/ helps if you're using CygWin.

Captain Capacitor
Jan 21, 2008

The code you say?
I hope you guys don't mind if I plug an upcoming sprint for a project I've been working with a lot recently, Salt. If there's a meet near you feel free to stop by, or pop by IRC if you're stuck somewhere remote.

More details here

duck monster
Dec 15, 2004

Captain Capacitor posted:

I hope you guys don't mind if I plug an upcoming sprint for a project I've been working with a lot recently, Salt. If there's a meet near you feel free to stop by, or pop by IRC if you're stuck somewhere remote.

More details here

Tell them to put "Say what SALT does on the front page of the website" as a sprint task. Seriously. I found it in the documentation, but that website really looks like its been fistfucked by a marketing person who actually has no idea what the products for.

Thermopyle
Jul 1, 2003

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

duck monster posted:

Tell them to put "Say what SALT does on the front page of the website" as a sprint task. Seriously. I found it in the documentation, but that website really looks like its been fistfucked by a marketing person who actually has no idea what the products for.

Yes. I gave up before making it to the documentation.

Hed
Mar 31, 2004

Fun Shoe
Yep, I clicked around and gave up. I see it has ACLs though!

Captain Capacitor
Jan 21, 2008

The code you say?
The site recently went under a redesign, so the new look still has some fixes needed. Basically it's a server configuration and remote execution system. Fabric meets Puppet, minus Puppet's DSL and more centrally managed than Fabric.

duck monster
Dec 15, 2004

Captain Capacitor posted:

The site recently went under a redesign, so the new look still has some fixes needed. Basically it's a server configuration and remote execution system. Fabric meets Puppet, minus Puppet's DSL and more centrally managed than Fabric.

See this poo poo here, it needs to be on the front page. Attention spans are short, especially for IT people who are desparately trying to research a solution on a lovely limited time span. A 2 sentence description right up the top on the front page, followed by a "Learn more" link that clearly enumerates what it does will make a world of difference.

e: Even better just give the loving thing a slogan that appears near the logo on every god drat page, so that no matter what direction I land from google, I'll see "SALT , a remote configuration toolkit for people who forgot to stab the marketing guy" and I'll see it and go "Hey, this poo poo is useful, wheres the "ABOUT" link?" and go find out more.

duck monster fucked around with this message at 04:31 on Jun 26, 2012

xPanda
Feb 6, 2003

Was that me or the door?
What is a good module for visualising graphs of python module imports? pycallgraph is for calls, but i'm looking into python module dependencies. A quick google shows something called snakefood, has anyone used one they'd recommend?

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

duck monster posted:

See this poo poo here, it needs to be on the front page. Attention spans are short, especially for IT people who are desparately trying to research a solution on a lovely limited time span. A 2 sentence description right up the top on the front page, followed by a "Learn more" link that clearly enumerates what it does will make a world of difference.

e: Even better just give the loving thing a slogan that appears near the logo on every god drat page, so that no matter what direction I land from google, I'll see "SALT , a remote configuration toolkit for people who forgot to stab the marketing guy" and I'll see it and go "Hey, this poo poo is useful, wheres the "ABOUT" link?" and go find out more.

Yeah, I agreein' with this. I literally would never get to the documentation page if I were working on something that could use this tool. Also, the front page really barely indicates it's a python toolkit. If I got to the front page through a google search, I'd literally say "what the poo poo is this?" and click back.

So yeah, as DuckMonster said, it seems like the marketing guy is loving over the dev team because they can't be arsed to even learn what y'all do.

Also, I'm a scientific programmer who probably isn't your target audience, so keep that in mind anyway.

Civil Twilight
Apr 2, 2011

JetsGuy posted:

Also, I'm a scientific programmer who probably isn't your target audience, so keep that in mind anyway.
I am the target audience, and when he linked it originally I got too frustrated with the site not even telling me what it was about that I just closed the tab before managing to find out. When i came back and actually looked for it, I had to click around until I found the link to another loving website (their readthedocs page) that finally told me what I was looking at. That's just terrible.

Looks like a useful tool, though I'm not sure why I'd use it over the more established competitors -- that's probably another thing that should be on the site.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
For what it's worth I thought with the word stack in there it was a web framework. It's a ridiculously ambiguous web site, and someone really needs to just get onto the front page's CMS now and plug in a few words about what this thing actually is, especially if you're trying to pass around the link and make conversions.

xPanda
Feb 6, 2003

Was that me or the door?
Is there some way to make an installable python package usable in-place as a git submodule? For instance, if I have numpy or something as a submodule of my repository, which is rooted at foo/ (so the submodule is at foo/numpy), is there some way to make numpy importable and usable from foo/ ? That is, if my CWD is foo/, I want to be able to just go 'import numpy' and have it work. I've been experimenting with setup.py develop, but it's obsessed with having even develop mode install to somewhere on your python path, whereas I just want to be relatively importable from its parent directory like any old package directory.

I'm driving myself mad with virtualenvs, but something always escapes scope. Trying to have this work with Eclipse isn't helping.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES
Just postin' to share a story of stupidity. As I've said, I use PyFits a LOT. Nontheless, I just made a dumb, dumb mistake. I was screaming at my program trying to figure out *why* a certain procedure was only working part of the time, and part of the time it wasn't.

Turns out that I forgot that I forgot that while the tables in a FITS files are indexed from 0,1... the tables are indexed as 1,2... This made the values I was returning off by 1. It was part of the time because the conditions I wanted were actually screwing up in a wonky way because I forgot about this dumb thing.

Essentially, while I was reading the tables in fv, I was like "WHY ARE YOU RETURNING INDEX 71 YOU STUPID PYTHON" when fv was clearly saying it should be 72. Oh, it turns out I am the stupid one, because Python was reading them as 0,1 to make my life easier.

Sigh.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
So for years I've been saying that what Python needs is a notebook interface. (Or rather "What I need is a Python notebook interface.") So having belatedly found out about IPython's notebook, I went to install it.

Frustrating. After a few stops and starts, I get it installed and run the server. Seems fine, until I go to the web interface and start to use it. After a few seconds, it reports that that the kernel has stopped (at the console it says "kernel has failed to respond to heartbeat") and do I want to restart it? Do so. After a few seconds the situation repeats.

Chased a few bug reports and there were some suggestions about altering the config stayalive values. Did so, made no difference.

The conversation in the bug tracker alternates between "yeah, that's fixed" and "well, it works for me". Any insight on this? Running this on Ubuntu 10.04.

the
Jul 18, 2004

by Cowcaster
how do I run a file with a space in it in ipython?

ex. cat 5.py

run cat 5.py doesn't work
run "cat 5.py" doesn't work
run 'cat 5.py' doesn't work

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Try
code:
cat\ 5.py
But even easier, just tab autocomplete that poo poo.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
So I've got a colleague, who desperately needs to learn how to program for the purposes of munging and analysing data. (Seriously: we're going over this detailed, hardcore analysis of thousands of points that he's done and then I found out that he did it by hand.) But he's self-labelled as not good at learning stuff by himself and is in a remote location. Any recommendations for online classes or communities where he can learn Python in a group?

the
Jul 18, 2004

by Cowcaster
I'm doing a Python assignment for a Physics class. We're doing a simple projectile problem, where I'm given a velocity and a launch angle and plotting the x versus y position.

The professor said, for extra credit, it would be nice if the plot would scale depending on the x and y values that I end up with.

So, I have

code:
import math
import numpy
import pylab

g = -9.81

v = raw_input('Input initial velocity ')
v = float(v)

deg = raw_input('Input launch angle in degrees ')
deg = float(deg) 
deg = (deg)*(math.pi/180)

vx = math.cos(deg)*v
vy = math.sin(deg)*v

t=numpy.arange(0.,10,.01)

x = vx*t
y = vy*t+(1./2.)*g*t**2

pylab.plot(x,y)
pylab.title('X-Position vs. Y-Position in meters')
pylab.xlabel('X-Position (m)')
pylab.ylabel('Y-Position (m)')
pylab.xlim([0,x.max()])
pylab.ylim([0,y.max()])
pylab.show()
The problem is that my x axis goes to like 140, which is a lot longer than I need it to be, because my total values for y's array go below y = 0 (which makes no sense in reality).

So, what I'd like is to make the plot stop at whatever x value exists when y = 0. This is slightly tricky because y = 0 at two points, the initial launch and then when it "hits the ground" again.

So how do I do this?

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
Look up where() in the numpy docs.

Emacs Headroom
Aug 2, 2003

the posted:

So how do I do this?

I usually do something like

Python code:
xmax = x.max()
if y[-1] < 0:
    max_i = numpy.nonzero(y < 0)[0][0]
    xmax = x[max_i]
pylab.xlim([0, xmax])

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES
You know, as I've said before, pylab is really not needed, and you should use pyplot.

http://matplotlib.sourceforge.net/faq/usage_faq.html#matplotlib-pylab-and-pyplot-how-are-they-related

You should *only* use pylab if you want interactive graphs. Interactive in this case not meaning simply zooming, you can do that in pyplot too.

I understand the biggest draw for people to use pylab is it includes numpy in the same namespace. That's really just asking for trouble later on.

the
Jul 18, 2004

by Cowcaster
I don't like having to know which module they're all from when I can just say pylab.blah

Is that a bad habit to get into? Why?

Blenheim
Sep 22, 2010
My intro to Python 2.7 class is asking for a recursive functions that counts the vowels in a string.

code:
def countVowels(s,idx):
    lst = list(s)
    i = 0
    if idx == len(lst)-1: 
        if character in ["a","e","i","o","u","A","E","I","O","U"]:
            i = i + 1
        return i
    else:
        return i + countVowels(s,idx+1) 

s = raw_input("Sentence? ")
print countVowels(s,0)
Problem 1 is that the program claims the global name "character" is not defined. Problem 2 is everything else. (Also, the professor wants a recursive version of the program without the idx argument, but one thing at a time, I suppose.) I've been struggling with this for a while now and could use some guidance.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

Blenheim posted:

My intro to Python 2.7 class is asking for a recursive functions that counts the vowels in a string.

code:
def countVowels(s,idx):
    lst = list(s)
    i = 0
    if idx == len(lst)-1: 
        if character in ["a","e","i","o","u","A","E","I","O","U"]:
            i = i + 1
        return i
    else:
        return i + countVowels(s,idx+1) 

s = raw_input("Sentence? ")
print countVowels(s,0)
Problem 1 is that the program claims the global name "character" is not defined. Problem 2 is everything else. (Also, the professor wants a recursive version of the program without the idx argument, but one thing at a time, I suppose.) I've been struggling with this for a while now and could use some guidance.

Wrap the if in a for loop over the characters.

Senso
Nov 4, 2005

Always working

Blenheim posted:

My intro to Python 2.7 class is asking for a recursive functions that counts the vowels in a string.

code:
def countVowels(s,idx):
    lst = list(s)
    i = 0
    if idx == len(lst)-1: 
        if character in ["a","e","i","o","u","A","E","I","O","U"]:
            i = i + 1
        return i
    else:
        return i + countVowels(s,idx+1) 

s = raw_input("Sentence? ")
print countVowels(s,0)
Problem 1 is that the program claims the global name "character" is not defined. Problem 2 is everything else. (Also, the professor wants a recursive version of the program without the idx argument, but one thing at a time, I suppose.) I've been struggling with this for a while now and could use some guidance.

I would do something like this:
EDIT: I missed the "recursive function" part of your post.

Basically, you don't need to do "lst = list(s)" as a string can be iterated over just like a list.

xtal
Jan 9, 2011

by Fluffdaddy
i don't know why you'd ever want to do that recursively but this is the best i could do:

Python code:
def count_vowels(word):
    if len(word) == 0:
        return 0

    vowels = ['a', 'e', 'i', 'o', 'u']

    return int(word[0].lower() in vowels) + count_vowels(word[1:])

print count_vowels('fArt') # => 1
because it copies each segment of the string on each iteration, it's very inefficient. perhaps there's a better solution?

Jewel
May 2, 2009

Ridgely_Fan posted:

I would say you shouldn't just do someone's homework for them, but it looks like you haven't since you ignored what was asked for, ha.

Because someone already did it for them in a recursive way! I was simply showing them the preferred method to use when actually programming and not forced to constrain to a specific style by an assignment :)

Oh my god I thought I hit new post not edit, welp, there goes all my code :suicide:

Jewel fucked around with this message at 05:02 on Jul 2, 2012

Emacs Headroom
Aug 2, 2003

Blenheim posted:

Problem 1 is that the program claims the global name "character" is not defined. Problem 2 is everything else. (Also, the professor wants a recursive version of the program without the idx argument, but one thing at a time, I suppose.) I've been struggling with this for a while now and could use some guidance.

Problem 1: well yeah you haven't defined the variable 'character'. Did you mean to put a line like 'character = s[idx]' but forgot or something?

Problem 2: Yes you don't need the idx because you can pass a substring to the recursive calls. The bigger problem though is you're only checking whether the very last character is a vowel. Don't you think you should check the other ones also? Try thinking it out in pseudocode first if you can -- something like "Ok I'll check if this first character is a vowel, then if so I'll just return 1 plus the count of the vowels left over. To get the vowels left over I'll take the remaining string, now I'll just check if this first character is a vowel, then if so..."


I would say you shouldn't just do someone's homework for them, but it looks like you haven't since you ignored what was asked for, ha.

the
Jul 18, 2004

by Cowcaster

Ridgely_Fan posted:

I usually do something like

Python code:
xmax = x.max()
if y[-1] < 0:
    max_i = numpy.nonzero(y < 0)[0][0]
    xmax = x[max_i]
pylab.xlim([0, xmax])

Thanks, but could you explain in a little bit more detail what you did there in the if statement?

Emacs Headroom
Aug 2, 2003

the posted:

Thanks, but could you explain in a little bit more detail what you did there in the if statement?

Python code:
if y[-1] < 0:
This tests if the final value of y is less than zero, obviously. If it's not less than zero, you're not going to want to bother finding where y crosses zero...

Python code:
max_i = numpy.nonzero(y < 0)[0][0]
'y < 0' is going to yield an array the same size as y. For every value of y >= 0, the array is going to contain False. For every value of y < 0, the array will contain True. For example:

code:
In [1]: y = arange(5, -5, -1)

In [2]: y
Out[2]: array([ 5,  4,  3,  2,  1,  0, -1, -2, -3, -4])

In [3]: y < 0
Out[3]: array([False, False, False, False, False, False,  True,  True,  True,  True], dtype=bool)
the call to 'nonzero' takes the array of True and False values, and yields an index of each True value:
code:
In [4]: nonzero(y < 0)
Out[4]: (array([6, 7, 8, 9]),)
since it happens to return a tuple, we have to dereference to get the array of indeces, then we take the first one as the array where 0 was crossed by y.

Then you'll want the value of x where y crossed 0, which is 'xmax = x[max_i]'.

Now read some documentation you lazy person.

Emacs Headroom
Aug 2, 2003

Jewel posted:

Because someone already did it for them in a recursive way! I was simply showing them the preferred method to use when actually programming and not forced to constrain to a specific style by an assignment :)

Oh my god I thought I hit new post not edit, welp, there goes all my code :suicide:

Haha, sorry. I didn't notice someone else had already actually done the assignment in the post before yours. Didn't mean to make you obliterate your post!

Blenheim
Sep 22, 2010

xtal posted:

because it copies each segment of the string on each iteration, it's very inefficient. perhaps there's a better solution?

It showed me the way, and that's good enough for me. Thanks very much for the help.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

the posted:

I don't like having to know which module they're all from when I can just say pylab.blah

Is that a bad habit to get into? Why?

Personally, I think it's a bad habit since it essentially doesn't teach you what is from numpy and what's from pyplot. Hell, even if I used pylab, I'd still import numpy just because that's what I'm used to using. It's a bit of a picky point to be sure, but you probably want to know *exactly* what you're doing. What happens if pylab ever becomes depreciated? What if one day you're coding something that you don't need to graph, and it's just easier to import numpy? How would you know if you've never used them separately?

In addition, numpy is updated a lot more often than matplotlib, so you'll also benefit from more updated modulues.

OnceIWasAnOstrich
Jul 22, 2006

This might not really be a Python question, but I am slowly compiling a bunch of methods I use into a program I'll be releasing as open source with a scientific paper thats hopefully getting published soon. In trying to make it as flexible as possible I've started using the argparse module. I end up with an object containing all of my parameters. In possible coding horror fashion, my program consists of a cascade of small functions passing data around. I am wondering what the correct way to distribute parameters is. Do I pass the argparse object around like a toy, do I take the parameters out and pass them around or make it global somehow? The problem I am discovering is that I get 5-6 function calls deep and my methods have all sorts of parameters in them that they really have no use for except to pass to their grandchildren for use.

Thermopyle
Jul 1, 2003

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

OnceIWasAnOstrich posted:

This might not really be a Python question, but I am slowly compiling a bunch of methods I use into a program I'll be releasing as open source with a scientific paper thats hopefully getting published soon. In trying to make it as flexible as possible I've started using the argparse module. I end up with an object containing all of my parameters. In possible coding horror fashion, my program consists of a cascade of small functions passing data around. I am wondering what the correct way to distribute parameters is. Do I pass the argparse object around like a toy, do I take the parameters out and pass them around or make it global somehow? The problem I am discovering is that I get 5-6 function calls deep and my methods have all sorts of parameters in them that they really have no use for except to pass to their grandchildren for use.

Some options in ascending order of complexity. In terms of "elegance" we kinda descend from least elegant to most elegant.

  1. Use the argparse object as a global variable so that functions can just directly access it.
  2. Pass the argparse object around.
  3. Build another object to pass around that does what you want that takes the argparse object and parses the arguments into some sort of common format and the pass this object around.
  4. Change all your functions into methods with rewrites as necessary and make your argparse object a field of that object.

I'm excited you're even worrying about this. We're having a related discussion right now in another thread starting right here.

Blenheim
Sep 22, 2010
In my Python for Dummies class, we're doing an exercise where we compile a dictionary of terms from a text file and make a simple translator. The keys are all one-word, but the values vary from one word to several.

So:

code:
for line in FILE:
	pairs = line.split( 	)
	key = pairs[0]
	value = pairs[1]
	dct[key] = value
I need to say that the zeroth element in a line is the key and the rest, be it one word or several, is the value. I don't know what terminology to use to do that, though. (I know that the current code is directing the value to be the first element in the list only.) Any help would be appreciated.

Adbot
ADBOT LOVES YOU

Jewel
May 2, 2009

Blenheim posted:

In my Python for Dummies class, we're doing an exercise where we compile a dictionary of terms from a text file and make a simple translator. The keys are all one-word, but the values vary from one word to several.

So:

code:
for line in FILE:
	pairs = line.split( 	)
	key = pairs[0]
	value = pairs[1]
	dct[key] = value
I need to say that the zeroth element in a line is the key and the rest, be it one word or several, is the value. I don't know what terminology to use to do that, though. (I know that the current code is directing the value to be the first element in the list only.) Any help would be appreciated.

If you're asking what I think you're asking, I think you can use "value = pairs[1:]" which means "1 and everything after it". I didn't know about that terminology for a while since it's hard to search for it. There's also other tricks like [::2] being every second key, and [::-1] being the list in reverse.

  • Locked thread