[Tutor] Upgrade Python distribution 2.4 to 2.5

2008-06-11 Thread washakie
Hello, I searched the web and python.org but I haven't found a good resource that explains how to upgrade python from 2.4 to 2.5 What I'm wondering is whether I'll have to start from scratch on the installation of all my external modules such as Numpy, Matplotlib, PyXML, etc... Could someone pl

[Tutor] inserting a vector into an array - numpy Q

2008-06-10 Thread washakie
I know there must be a better way to do this with slices, but I can't seem to figure it out - I keep getting errors about the need to have the same dimensions: Here's what I'm trying: >>> type(time) >>> type(new_data) >>> shape(time) (1334,) >>> shape(new_data) (1334, 54) >>> newArray=concatena

Re: [Tutor] create numpy array from list of strings

2008-06-03 Thread washakie
Thank you again. I can see your point about not wanting the tempDATA var hanging around, so I guess this is better as a function. And yes, the transpose is for the 'next step' - sorry if that cause anyone confusion. Danny Yoo-3 wrote: > > > If you already have the values as a list of rows, w

Re: [Tutor] create numpy array from list of strings

2008-06-03 Thread washakie
Thanks, I'm not really trying to create a function. I actually thought this would be as simple as the 'load' command to get the data in from a file. But I just couldn't find the documentation online to do it once i have the data already 'inside' of python as a list. So, my options are: 1) write

[Tutor] create numpy array from list of strings

2008-06-03 Thread washakie
Hello, I have a list of strings: data = [ '33386.472.22-1.11 0.43' '33386.67 3.33 -1.23 0.54' ... '46728.470.1-1.87-0.54' '46728.479.75.680.38' '46729.47-0.17-0.470.23'] I wish to convert it to a numpy array of floats. How do I accomplish t

[Tutor] help with slice

2008-03-04 Thread washakie
Could someone please explain 'slices' also for dictionaries? basically, I'd like to know how you would call every 3rd element in a list of lists... My logic says: ThirdElems=List[:][2] Which to me reads, for every item in List (which are lists), return the third item. but this doesn't work. T

Re: [Tutor] permissions problem using subprocess

2008-02-10 Thread washakie
Answering my own question here, but for the sake of it... adding: os.chdir(newpath) makes it all work... so we have: def run_cmd(cmd): """RUN A BASH CMD""" import subprocess as sub p = sub.Popen(['/bin/bash', '-c', cmd], stdout=sub.PIPE, stderr=sub.STDOUT) output =

[Tutor] permissions problem using subprocess

2008-02-10 Thread washakie
Hello, I'm converting a perl script which calls shell scripts which call fortran routines into a python cgi that calls fortran directly (well, not yet using f2py), but using subprocess.popen. Here's my code: def run_cmd(cmd): """RUN A BASH CMD""" import subprocess as sub p = sub.Popen(

Re: [Tutor] seek and slice a range in a list of dates

2008-02-10 Thread washakie
Yes, I'm using 2.4, and will not likely be able to upgrade... so, the final, as you suggested Kent: dates_dt=([datetime.datetime(int(dates_list[i][0][:4]),int(dates_list[i][0][4:6]), int(dates_list[i][0][6:8]),int(dates_list[i][0][8:10]),

Re: [Tutor] seek and slice a range in a list of dates

2008-02-09 Thread washakie
It's not pretty, but this is what seems to work... I'd be happy hear more about a better approach... I like the idea of using a list, but ran into troubles with min and max, maybe I don't entirely understand the lambda function, but when I tried a list, I got an error that min() has no optional va

[Tutor] seek and slice a range in a list of dates

2008-02-09 Thread washakie
Hello, I'm using the code below to select the closest dates in a dictionary of dates, to selected dates (Tstart, Tend)... Now, I need to get all the dates (slice) from the dictionary in between the two dates TstartNew and TendNew. Basically, I need to know what the 'index' is for them in the in t

Re: [Tutor] ssh script

2008-01-24 Thread washakie
Thanks everyone these seem like promising directions to go... Eric, any chance you could share your 'similar' code? The problem it seems with paramiko is that it has little 'newbie' documentation, and I'm not clear how to set up the reverse port forwarding on it. Thus I may need to use the pexpect

[Tutor] ssh script

2008-01-23 Thread washakie
Hello, I'm trying to write a script which will allow me to create a reverse tunnel from a remote machine using SSH -R I know the reverse tunnel script works on it's own run from the shell, but I don't want to leave it open always... does anyone have any ideas on how to make this work? There seems

[Tutor] for k,v in d: ValueError: too many values to unpack

2007-05-21 Thread John Washakie
I have a Dictionary, that is made up of keys which are email addresses, and values which are a list of firstname, lastnamet, address, etc... If I run the following: #! /bin/python import csv last = {} rdr = csv.DictReader(file("reg-data.csv")) for row in rdr: #print row last[row

Re: [Tutor] Running and passing variables to/from Fortran

2007-05-12 Thread John Washakie
WAY too large a project I'm afraid. Yes, that would be the one which would make me an 'expert' in Python ;) Too bad there's just no time right now... On 5/10/07, Bob Gailer <[EMAIL PROTECTED]> wrote: > John Washakie wrote: > > I have access to the source code

Re: [Tutor] Alright... I'm new...

2007-05-09 Thread John Washakie
> > I want to create a fully functional program that actually does something > USEFUL. And just what would that be? Ask yourself that.. then perhaps folks on the list could guide you in the right direction... -j ___ Tutor maillist - Tutor@python.org h

Re: [Tutor] Running and passing variables to/from Fortran

2007-05-09 Thread John Washakie
I have access to the source code. And I probably could pass the data to stdout, so maybe .popen would work! I'll have a look... thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Running and passing variables to/from Fortran

2007-05-06 Thread John Washakie
I have a FORTRAN program which reads in unformatted sparse matrix data. Rather than rewriting the code in Python, I was hoping there is a way to call the Fortran program, passing filename variables TO Fortran, and returning the data (which is an array) back to my .py code for use there. Is there a

Re: [Tutor] Aaagh! Stack arrays!?! calc average

2007-05-01 Thread John Washakie
And of course, thanks all! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Aaagh! Stack arrays!?! calc average

2007-05-01 Thread John Washakie
It aint pretty! And if I had just walked away, it probably would've taken half the time in the morning, but here's what I've come up with (any suggestions for improvements, or course are welcome): for d in data: w = len(d) if d[0] <= tinit+60: d = column_stack(d)

Re: [Tutor] Aaagh! Stack arrays!?! calc average

2007-05-01 Thread John Washakie
Ug, It still doesn't make sense due to the sum/cnt where cnt is just an int, and sum is a 1-dimensional array! I'm missing something here about working with numpy arrays... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/

Re: [Tutor] Aaagh! Stack arrays!?! calc average

2007-05-01 Thread John Washakie
Thanks for the feedback, The average was a little bit goofed up. Here's what I have now: for d in data: if d[0] <= tinit+60: d = column_stack(d) cnt=cnt+1 sum = sum+d else: avg = sum/cnt if init==0: newData = av

Re: [Tutor] Aaagh! Stack arrays!?! calc average

2007-05-01 Thread John Washakie
Oops, I meant it crashes at line 7.. > > 1) tinit = data[0][0] > 2)for d in data: > 3)if d[0] <= tinit+60: > 4)sum = sum+d > 5)else: > 6)avg = sum/len(sum) > 7)newData = append([newData],[avg],axis=0) > 8)tinit = d[0] > >

[Tutor] Aaagh! Stack arrays!?! calc average

2007-05-01 Thread John Washakie
Hello, I'm trying to calculate an average for columns in my array(data), there's a catch though, I want to create a new array of shorter length (NOTE: this crashes at line 8): 1) tinit = data[0][0] 2)for d in data: 3)if d[0] <= tinit+60: 4)sum = sum+d 5)else: 6)

Re: [Tutor] Running a program

2007-05-01 Thread John Washakie
Jessica, Assuming you have python installed on your system (Windows?, *nix?), then all you have to do is double click the .py file and it will run. If you want, you can run it from the command line: C:\> python yourfile.py On 5/1/07, Jessica Brink <[EMAIL PROTECTED]> wrote: > > > I know thi

Re: [Tutor] if in an iteration, quick Q!!

2007-05-01 Thread John Washakie
Thanks > > Depending on what an 'empty' element is you may have to refine that. > I also noted, if I used: tmp = data[6].strip().split() rather than: tmp = data[6].strip().split(' ') I eliminated the 'empty' elements... ___ Tutor maillist - Tuto

[Tutor] if in an iteration, quick Q!!

2007-05-01 Thread John Washakie
I can't recall how to do this: I want: a = [int(x) for x in tmp] but, my tmp has some empty elements, so it fails... Therefore I want to be able to say: a = [int(x) for x in tmp IF x in tmp] I know there's a way! Ive seen it before, but now cannot find it! 'if' is a pretty generic thing to se

[Tutor] listing files in an html directory

2007-04-29 Thread John Washakie
Hello all, I'm trying to write a program which will take a path, look in it for all files matching a certain pattern, then create javascript player to play them. A key part of the code at this point is: searchPath = imageRoot + '*' + imgExt avail = glob.glob(searchPath) #will glob work over http

[Tutor] a way to glob over http?

2007-04-26 Thread John Washakie
Hello all, I'm writing a program which take input about a path. The path may be http or absolute or local. Once I have the path, I want to search the directory for images (type also defined by user), then get a count on the number of images in order to build the rest of my program: searchPath = i

Re: [Tutor] best search/replace method?

2007-04-25 Thread John Washakie
Excellent. Thanks Luke, that seems to be working On 4/25/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote: > John Washakie wrote: > > Tested. Failed... > > > > I thought it would be something like that, but that doesn't work.. > > perhaps because '

Re: [Tutor] best search/replace method?

2007-04-25 Thread John Washakie
TECTED]> wrote: > On 4/25/07, John Washakie <[EMAIL PROTECTED]> wrote: > > > cat raw.html | > > sed 's/ImagePathReplaceMe/NewPathToImage/g' | > > sed 's/TitleReplaceMe/NewTitle/g' > new.html > > One line's sufficient: >

[Tutor] best search/replace method?

2007-04-25 Thread John Washakie
Folks, I'm writing a program which will read in an html file, and then replace certain elements, such as the title, and various paths defined for images. I can make a 'source' file with ImagePathReplaceMe and TitleReplaceMe text in it, then search for that and replace it. With sed my script would

Re: [Tutor] read text file in zip archive, process, plot

2007-04-15 Thread Washakie
Thanks so much! Now another task, associated with this one... what I actually ultimately want is to just pull out several fields from the text file in the zip archive (there is actually only one file).. so, my goal is the to create a file that looks like: t[0], x[0], y[0] t[1], x[1], y[1] t[2], x

Re: [Tutor] read text file in zip archive, process, plot

2007-04-15 Thread Washakie Wyoming
Thank you both! That seems to make my code much more clear... I thought it was foolish writing files, but I just couldn't determine how to parse the data! Kent, one thing, regarding: x = [] t = [] for l in data[stind:-1]: l = l.split() # Split on whitespace