Re: [Tutor] Impossible Else as Exception

2013-04-10 Thread Alan Gauld
On 10/04/13 07:18, Jordan wrote: Alan you are right, the code should be better tested, but test driven development seems like it would take me forever to complete even small tasks, there is so much to be tested. I have limited time to program with my wife and kids, but do you think test driven

Re: [Tutor] Chapter 3 Projects

2013-04-10 Thread Alan Gauld
On 10/04/13 04:11, Dave Angel wrote: I'd do it like this score = raw_input('score? ') That would need to be: score = int(raw_input('score? ') Oops, yes. Good catch. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _

[Tutor] running python from windows command prompt

2013-04-10 Thread Arijit Ukil
I like to run a python program "my_python.py" from windows command prompt. This program ( a function called testing) takes input as block data (say data = [1,2,3,4] and outputs processed single data. import math def avrg(data): return sum(data)/len(data) def testing (data): val = avrg(

Re: [Tutor] Impossible Else as Exception

2013-04-10 Thread Dave Angel
On 04/10/2013 02:18 AM, Jordan wrote: Thank you all for the feedback and suggestions. I have never used an assertion, before so I will read up on the concept. One comment about assertion. Even though an optimized run will ignore the assertion itself, it can save a (small) amount of time avo

Re: [Tutor] running python from windows command prompt

2013-04-10 Thread Dave Angel
(Please don't hijack a thread with an unrelated question. You're no doing yourself any favors, as any decent thread-viewer will hide your new subject line, and group the whole thread with its original title. That can cause your query to be ignored by many of the readers.) To start a new threa

[Tutor] Running python from windows command prompt

2013-04-10 Thread Arijit Ukil
I like to run a python program "my_python.py" from windows command prompt. This program ( a function called testing) takes input as block data (say data = [1,2,3,4] and outputs processed single data. import math def avrg(data): return sum(data)/len(data) def testing (data): val =

Re: [Tutor] Running python from windows command prompt

2013-04-10 Thread Amit Saha
On Wed, Apr 10, 2013 at 10:32 PM, Arijit Ukil wrote: > I like to run a python program "my_python.py" from windows command prompt. > This program ( a function called testing) takes input as block data (say > data = [1,2,3,4] and outputs processed single data. > > import math > > def avrg(data): >

Re: [Tutor] Running python from windows command prompt

2013-04-10 Thread Amit Saha
On Wed, Apr 10, 2013 at 10:32 PM, Arijit Ukil wrote: > I like to run a python program "my_python.py" from windows command prompt. > This program ( a function called testing) takes input as block data (say > data = [1,2,3,4] and outputs processed single data. > > import math > > def avrg(data): >

Re: [Tutor] Running python from windows command prompt

2013-04-10 Thread Dave Angel
On 04/10/2013 08:32 AM, Arijit Ukil wrote: I like to run a python program "my_python.py" from windows command prompt. This program ( a function called testing) takes input as block data (say data = [1,2,3,4] and outputs processed single data. import math def avrg(data): return sum(data)/len

[Tutor] File not found error, but it is in the folder!

2013-04-10 Thread Woody 544
I have a script that worked before I moved it to another folder. I cannot understand why I am getting a 'No such file or directory' error, when the file is in the folder. Any clues would be much appreciated. Thanks! MJ Here is a copy and paste of the script up to the error, output/error and a

Re: [Tutor] Reading Program

2013-04-10 Thread bob gailer
On 4/8/2013 2:58 PM, Donald Dietrich wrote: I am just new to python programing, but would like some help developing a program for "flow reading" What I would like the program to do is use any .txt file like micorsoft word .txt file and flow the words across the screen one at time until the fi

Re: [Tutor] building a website with python

2013-04-10 Thread Bradley Cloete
On Wed, Apr 10, 2013 at 5:07 AM, Benjamin Fishbein wrote: > > > > You've gotten some good feedback, but I suspect you will get better > information if you provide more information about your goals for the site. > > > > Thanks for your help, everyone. There are some specific things I want the > sit

Re: [Tutor] Phyton script for fasta file (seek help)

2013-04-10 Thread Ali Torkamani
I have written the following function for reading fasta files, I hope this helps: Ali def ReadFasta(filename): dictFasta=dict() prevLine=''; try: f = open(filename, "r") for line in f: print line line=line.lower() line=line.strip(

Re: [Tutor] File not found error, but it is in the folder!

2013-04-10 Thread Mark Lawrence
On 10/04/2013 15:44, Woody 544 wrote: I have a script that worked before I moved it to another folder. I cannot understand why I am getting a 'No such file or directory' error, when the file is in the folder. Any clues would be much appreciated. Thanks! MJ Here is a copy and paste of the scr

Re: [Tutor] Running python from windows command prompt

2013-04-10 Thread eryksun
On Wed, Apr 10, 2013 at 8:32 AM, Arijit Ukil wrote: > > python my_python.py 1 3 2 Adding Python's installation directory to PATH is for starting the interpreter with specific options (-O, -vv, etc), running a module on Python's sys.path (-m), running a command (-c), or starting an interactive sh

Re: [Tutor] Phyton script for fasta file (seek help)

2013-04-10 Thread Danny Yoo
Hi Ali, Again, I recommend not reinventing a FASTA parser unless you really need something custom here. In this particular case, the function ReadFasta here is slow on large inputs. The culprit is the set of lines: if line[0]=='>': prevLine=line[1:] d

[Tutor] Appending an extra column in a data file

2013-04-10 Thread Sayan Chatterjee
Dear All, I have some data files with numpy arrays stored in it in 2 columns. I want to add a third column with just floating point numbers(not numpy array) and plot them later with Matplotlib in 3d. How is it done? Could you please illuminate me? Bests, Sayan -- -

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Andre' Walker-Loud
Hi Sayan, This question would be better suited to the matplotlib list. Also, a more precise description of your existing data, and what you hope it would look like would make it easier to help answer your question. Eg., from your description, it is not clear if your existing data is in a table,

Re: [Tutor] File not found error, but it is in the folder!

2013-04-10 Thread Dave Angel
On 04/10/2013 10:44 AM, Woody 544 wrote: I have a script that worked before I moved it to another folder. I cannot understand why I am getting a 'No such file or directory' error, when the file is in the folder. Any clues would be much appreciated. Thanks! MJ Here is a copy and paste of the

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Sayan Chatterjee
Thank Andre for your prompt answer. I'll figure out the plotting issue once the dat files are made. So it's the primary concern. For an example I am attaching a dat file herewith. The two columns here are 2 numpy arrays.I want to add a third column, to be precise, I want to print a parameter value

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Andre' Walker-Loud
Hi Sayan, > Thank Andre for your prompt answer. No problem. > I'll figure out the plotting issue once the dat files are made. So it's the > primary concern. > For an example I am attaching a dat file herewith. The two columns here are 2 > numpy arrays.I want to add a third column, to be preci

Re: [Tutor] Running python from windows command prompt

2013-04-10 Thread Alan Gauld
On 10/04/13 13:32, Arijit Ukil wrote: I like to run a python program "my_python.py" from windows command prompt. This program ( a function called testing) takes input as block data (say data = [1,2,3,4] and outputs processed single data. Hopefully the code below is not your entire program. If

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Sayan Chatterjee
Hi Andre, Well,this is the concerned snippet of the code: while *t < 1*: pp_za = pp_init + t*K*np.sin(K*pp_init) # Periodic Boundary Condition for i in range(0,999): if pp_za[i] < 0: pp_za[i] = 2 - abs(pp_za[i]) if pp_za[i] > 2: pp_za[i] = pp_za[i] % 2 pv_za = +K*

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Alan Gauld
On 10/04/13 16:44, Sayan Chatterjee wrote: I have some data files with numpy arrays stored in it in 2 columns. I Can you define what that means? All files on a computer are data files in some sense. They exist as text files or binary files. If they are text files then the content of your arra

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Andre' Walker-Loud
Hi Sayan, > Well,this is the concerned snippet of the code: > > > while t < 1: > > > pp_za = pp_init + t*K*np.sin(K*pp_init) > > # Periodic Boundary Condition > > for i in range(0,999): > > if pp_za[i] < 0: > pp_za[i] = 2 - abs(pp_za[i]) > if pp_za[i] > 2: > pp

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Sayan Chatterjee
Hi Alan, Sorry for the ambiguity I have created. I have added the snippet of code just in the previous mail and also the sample data in the text file. Have you had a look on them? I am copy pasting it in this email: Hi Andre, Well,this is the concerned snippet of the code: while *t < 1*:

Re: [Tutor] building a website with python

2013-04-10 Thread Don Jennings
On Apr 9, 2013, at 11:07 PM, Benjamin Fishbein wrote: >> >> You've gotten some good feedback, but I suspect you will get better >> information if you provide more information about your goals for the site. >> > > Thanks for your help, everyone. There are some specific things I want the > sit

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Sayan Chatterjee
Yup it's exactly what I want! I want *many* data files,not one...to make an animation out of it. For a data file t is constant. the solution you have just mentioned i.e np.array([t,pp_za,pv_za]) is giving the following error: Traceback (most recent call last): File "ZA_Phase_Plot.py", line 38

Re: [Tutor] Phyton script for fasta file (seek help)

2013-04-10 Thread Ali Torkamani
On Wed, Apr 10, 2013 at 8:32 AM, Danny Yoo wrote: > Hi Ali, > > Again, I recommend not reinventing a FASTA parser unless you really > need something custom here. In this particular case, the function > ReadFasta here is slow on large inputs. The culprit is the set of > lines: > > if

Re: [Tutor] File not found error, but it is in the folder!

2013-04-10 Thread eryksun
On Wed, Apr 10, 2013 at 12:22 PM, Dave Angel wrote: > My preference is to use absolute directories for every reference, in which > case you'd use something like > ...open(os.path.join(directory, i), ... +1 > With of course a better name than 'i', which is traditionally an integer. > (since 1

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Andre' Walker-Loud
Hi Sayan, > Yup it's exactly what I want! > > I want many data files,not one...to make an animation out of it. For a data > file t is constant. You should not need many data files to make an animation. If you write your loops correctly, you can take a single data file with all the data. If y

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Sayan Chatterjee
Hi Andre, Is it that? We can have different plots and hence animation from a single data file.Very good!...if you have some time in your disposal, it will be kind of you to illumine in this matter...may be some useful link will do. I have written this small code from scratch,there's no 'get it to

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Oscar Benjamin
On 10 April 2013 17:58, Sayan Chatterjee wrote: > Thank Andre for your prompt answer. > > I'll figure out the plotting issue once the dat files are made. So it's the > primary concern. > For an example I am attaching a dat file herewith. The two columns here are > 2 numpy arrays.I want to add a th

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Sayan Chatterjee
Hi Andre, I figured it out. Need not reply of np.savetxt for storing array simply f.wite() is doing fine. while i < 999: print i fo.write('{0:f} {1:f} {2:f}\n'.format(pp_za[i], pv_za[i],t)) i = i + 1 Eager to know that single file thing though! Sayan On 10 April 2013 23:52, Saya

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Sayan Chatterjee
Thanks Oscar figured it out...:) On 11 April 2013 00:17, Oscar Benjamin wrote: > On 10 April 2013 17:58, Sayan Chatterjee > wrote: > > Thank Andre for your prompt answer. > > > > I'll figure out the plotting issue once the dat files are made. So it's > the > > primary concern. > > For an examp

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Oscar Benjamin
On 10 April 2013 19:48, Sayan Chatterjee wrote: > Hi Andre, > > I figured it out. Need not reply of np.savetxt for storing array simply > f.wite() is doing fine. > > while i < 999: > print i > fo.write('{0:f} {1:f} {2:f}\n'.format(pp_za[i], pv_za[i],t)) > i = i + 1 > > Eager to know

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Andre' Walker-Loud
Hi Sayan, > Is it that? We can have different plots and hence animation from a single > data file.Very good!...if you have some time in your disposal, it will be > kind of you to illumine in this matter...may be some useful link will do. > > I have written this small code from scratch,there's n

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Albert-Jan Roskam
> Subject: Re: [Tutor] Appending an extra column in a data file >   > The file you attached is a space-delimited text file. If you want to > add a third column with the value '1.0' on every row you can just do: > > with open('old.dat') as fin, open('new.dat', 'w') as > fout: >     for line in

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread eryksun
On Wed, Apr 10, 2013 at 4:45 PM, Albert-Jan Roskam wrote: > >> with open('old.dat') as fin, open('new.dat', 'w') as fout: > > Is that Python 3.x? It's the same syntax as an import statement such as the following: import numpy as np, matplotlib as mpl A downside with this is the inability to

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Oscar Benjamin
On 10 April 2013 21:45, Albert-Jan Roskam wrote: > > >> Subject: Re: [Tutor] Appending an extra column in a data file >> > > >> The file you attached is a space-delimited text file. If you want to >> add a third column with the value '1.0' on every row you can just do: >> >> with open('old.dat')

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread Oscar Benjamin
On 10 April 2013 22:17, eryksun wrote: > > But I think it's more readable to break up a long line like this: > > fin = open('old.dat') > fout = open('new.dat', 'w') > > with fin, fout: > for line in fin: This has the same problems as contextlib.nested: An error raised while op

Re: [Tutor] Appending an extra column in a data file

2013-04-10 Thread eryksun
On Wed, Apr 10, 2013 at 5:49 PM, Oscar Benjamin wrote: >> fin = open('old.dat') >> fout = open('new.dat', 'w') >> >> with fin, fout: >> for line in fin: > > This has the same problems as contextlib.nested: An error raised while > opening 'new.dat' could prevent 'old.dat' from b

[Tutor] Python bz2 "IOError: invalid data stream" when trying to decompress

2013-04-10 Thread Rodney Lewis
My question is at StackOverflow so I won't repeat it here. http://stackoverflow.com/questions/15938629/python-bz2-ioerror-invalid-data-stream-when-trying-to-decompress Thanks so much in advance for any help you can provide regarding this. http://www.squidoo.com/introductiontopython -- Rodney L

Re: [Tutor] Python bz2 "IOError: invalid data stream" when trying to decompress

2013-04-10 Thread Dave Angel
On 04/10/2013 08:18 PM, Rodney Lewis wrote: My question is at StackOverflow so I won't repeat it here. http://stackoverflow.com/questions/15938629/python-bz2-ioerror-invalid-data-stream-when-trying-to-decompress Thanks so much in advance for any help you can provide regarding this. http://www.

[Tutor] Sharing Code Snippets

2013-04-10 Thread Amit Saha
Hello everyone, I am not sure if this has been shared on this list. However, to help both those seeking help and those wanting to help, may I suggest that for all of you posting your programs, how about using a service such as GitHub's Gists [1]. It allows you to post entire programs with advantag

Re: [Tutor] Python bz2 "IOError: invalid data stream" when trying to decompress

2013-04-10 Thread eryksun
On Wed, Apr 10, 2013 at 8:18 PM, Rodney Lewis wrote: > My question is at StackOverflow so I won't repeat it here. Short link: http://stackoverflow.com/q/15938629/205580 Your function worked fine for me on Windows Python 2.7.3, compressing/decompressing a text file that's about 150 KiB. The bz2

Re: [Tutor] Sharing Code Snippets

2013-04-10 Thread Sayan Chatterjee
Tried it out.It's really cool.From next time on, shall try to make use of this. Thanks. :) On 11 April 2013 06:58, Amit Saha wrote: > Hello everyone, > > I am not sure if this has been shared on this list. However, to help > both those seeking help and those wanting to help, may I suggest that

Re: [Tutor] Running python from windows command prompt

2013-04-10 Thread Arijit Ukil
Thanks for the help. Now I have modifed the code as: import sys def main(argv): data = int(sys.argv[1]) avg = average (data) print "Average:", avg def average(num_list): return sum(num_list)/len(num_list) if __name__ == "__main__": main(sys.argv[1:]) When running in com

Re: [Tutor] Running python from windows command prompt

2013-04-10 Thread Asokan Pichai
On Thu, Apr 11, 2013 at 11:38 AM, Arijit Ukil wrote: > Thanks for the help. Now I have modifed the code as: > > import sys > > def main(argv): > > data = int(sys.argv[1]) > > avg = average (data) > > print "Average:", avg > > def average(num_list): > return sum(num_list)/len(num_l

Re: [Tutor] Running python from windows command prompt

2013-04-10 Thread Alan Gauld
On 11/04/13 07:08, Arijit Ukil wrote: Thanks for the help. Now I have modifed the code as: import sys def main(argv): data = int(sys.argv[1]) avg = average (data) print "Average:", avg def average(num_list): return sum(num_list)/len(num_list) if __name__ == "__main__":