Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-28 Thread Francesco Loffredo
lina wrote: On Fri, Oct 7, 2011 at 9:38 AM, Dave Angel mailto:d...@davea.name>> wrote: On 10/06/2011 12:21 PM, lina wrote: Yes. I understand this part now. But how can I print a list consists of the value of key B + E. For {'B': [4, 5, 6], 'E': [1, 2, 3]} I wanna get the summ

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-09 Thread lina
Just wanna say a quick thanks to all of you here, Very informative. Thanks, On Sun, Oct 9, 2011 at 11:08 AM, Steven D'Aprano wrote: > Walter Prins wrote: > > As for the compiler/interpreter argument, I'll just point out again that >> actually Python in its various forms can either be compiled

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Steven D'Aprano
Walter Prins wrote: As for the compiler/interpreter argument, I'll just point out again that actually Python in its various forms can either be compiled and/or interepreted, it depends on you really. For compiled Python flavours, see for example Cython (http://cython.org/) which provides a way

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Walter Prins
Hi Lina, On 8 October 2011 18:18, lina wrote: > I write mainly critical speed code and large memory code that are meant to > run as hug jobs over cluster (transportability is an issue; > my C code is really faster than my Maple code; interpreter language are > good for development of algorithm

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Walter Prins
Lina, Just a couple of comments on the topic of Python vs other languages to add to what others have said: On 7 October 2011 16:40, lina wrote: > but today I was also discouraged, I was told that you should not have > learned python, you should focus on C or bash, or D, cause python is going >

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread lina
On Sat, Oct 8, 2011 at 11:34 PM, Alan Gauld wrote: > On 08/10/11 14:17, lina wrote: > > You will never say, "Gosh, I wish I knew FEWER programming languages!" >> Ha Ha ... >> >> regarding the python and C, I was told that python is good for interface >> and others, but slow. and further was su

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread lina
On Sat, Oct 8, 2011 at 11:34 PM, Alan Gauld wrote: > On 08/10/11 14:17, lina wrote: > > You will never say, "Gosh, I wish I knew FEWER programming languages!" >> Ha Ha ... >> >> regarding the python and C, I was told that python is good for interface >> and others, but slow. and further was su

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread lina
On Sat, Oct 8, 2011 at 10:50 PM, Alan Gauld wrote: > On 08/10/11 11:27, Alan Gauld wrote: > > What you want, I think, is to join the original list >> with spaces(and maybe add a newline for writing to file) >> >> summary = ' '.join(summary) + \n >> > > But you need to make the original items stri

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Alan Gauld
On 08/10/11 14:17, lina wrote: You will never say, "Gosh, I wish I knew FEWER programming languages!" Ha Ha ... regarding the python and C, I was told that python is good for interface and others, but slow. and further was suggested to write the main part in C and wrapped in python. The m

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Alan Gauld
On 08/10/11 11:27, Alan Gauld wrote: What you want, I think, is to join the original list with spaces(and maybe add a newline for writing to file) summary = ' '.join(summary) + \n But you need to make the original items strings first so it should be: summary = ' '.join( map(str,summary) ) +

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread lina
On Sat, Oct 8, 2011 at 6:27 PM, Alan Gauld wrote: > On 08/10/11 04:34, lina wrote: > > print(summary) ### output is [1,3,5,6] >> summary='\n'.join(str(summary)**.split(',')) >> > > This line is wrong. > This is converting summary to a string -> '[1,3,5,6]' > Then splitting by co

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread lina
On Sat, Oct 8, 2011 at 6:27 PM, Alan Gauld wrote: > On 08/10/11 04:34, lina wrote: > > print(summary) ### output is [1,3,5,6] >> summary='\n'.join(str(summary)**.split(',')) >> > > This line is wrong. > This is converting summary to a string -> '[1,3,5,6]' > Then splitting by co

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread lina
On Sat, Oct 8, 2011 at 4:43 PM, Steven D'Aprano wrote: > Alan Gauld wrote: > >> On 07/10/11 16:40, lina wrote: >> >> but today I was also discouraged, I was told that you should not have >>> learned python, you should focus on C or bash, or D, cause python is >>> going to be obsolete, >>> >> >>

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Alan Gauld
On 08/10/11 04:34, lina wrote: print(summary) ### output is [1,3,5,6] summary='\n'.join(str(summary).split(',')) This line is wrong. This is converting summary to a string -> '[1,3,5,6]' Then splitting by commas to create a new list -> [ '[1', '3', '5', 6]' ] Notice the fir

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Steven D'Aprano
Alan Gauld wrote: On 07/10/11 16:40, lina wrote: but today I was also discouraged, I was told that you should not have learned python, you should focus on C or bash, or D, cause python is going to be obsolete, C is a great language for writing Operating Systems and other "near the metal" cod

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Andreas Perstinger
On 2011-10-08 09:12, lina wrote: $ python3 counter-vertically-WORKING.py [26, 22, 28, 30, 32, 27, 30, 29, 28, 30, 32, 24, 27, 27, 28, 30, 32, 30, 33, 27, 33, 32, 34, 31, 28, 34, 33, 32, 25, 35, 30, 32, 30, 32, 25, 30, 26, 24, 33, 28, 27, 26, 23, 27, 27, 28, 27, 25, 24, 23, 23, 27, 24, 27, 26, 23,

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread lina
On Sat, Oct 8, 2011 at 2:50 PM, Andreas Perstinger < andreas.perstin...@gmx.net> wrote: > On 2011-10-08 08:25, lina wrote: > >> Still have a reading "multiple" files issue: >>> Traceback (most recent call last): File "counter-vertically-WORKING.py", line 26, in

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread lina
On Sat, Oct 8, 2011 at 2:50 PM, Andreas Perstinger < andreas.perstin...@gmx.net> wrote: > On 2011-10-08 08:25, lina wrote: > >> Still have a reading "multiple" files issue: >>> Traceback (most recent call last): File "counter-vertically-WORKING.py", line 26, in

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Andreas Perstinger
On 2011-10-08 08:25, lina wrote: Still have a reading "multiple" files issue: Traceback (most recent call last): File "counter-vertically-WORKING.**py", line 26, in results[ch][col]+=1 IndexError: list index out of range only one file ss_1.xpm was processed and wrote file, for the

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
> Still have a reading "multiple" files issue: >> >> Traceback (most recent call last): >> File "counter-vertically-WORKING.**py", line 26, in >> results[ch][col]+=1 >> IndexError: list index out of range >> >> only one file ss_1.xpm was processed and wrote file, for the rest >> ss_2.xpm, >>

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Andreas Perstinger
On 2011-10-08 06:07, lina wrote: Still have a reading "multiple" files issue: Traceback (most recent call last): File "counter-vertically-WORKING.py", line 26, in results[ch][col]+=1 IndexError: list index out of range only one file ss_1.xpm was processed and wrote file, for the rest ss

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Andreas Perstinger
On 2011-10-08 05:34, lina wrote: Another minor derived questions: summary=[] for a,b in zip(results['E'],results['B']): summary.append(a+b)## now the summary is '[0,1, 3, 5, 6,0,0,0]' del summary[0] ## here I wanna remove the first zero, which came f

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
Still have a reading "multiple" files issue: Traceback (most recent call last): File "counter-vertically-WORKING.py", line 26, in results[ch][col]+=1 IndexError: list index out of range only one file ss_1.xpm was processed and wrote file, for the rest ss_2.xpm, ss_3.xpm and following keep

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
Another minor derived questions: summary=[] for a,b in zip(results['E'],results['B']): summary.append(a+b)## now the summary is '[0,1, 3, 5, 6,0,0,0]' del summary[0] ## here I wanna remove the first zero, which came from the initial double quote "EB...E",

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
> C is a great language for writing Operating Systems and other "near the > metal" code. But its not the best language for busiess apps, artificial > intelligence and a host of other things. Bash is a good user shell, but its > not even the best Unix shell for scripting (Thats probably ksh). > D? W

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
> The 'with' syntax above implicitly closes the file for you > at the end of the block. If you use the > > f = open(...) > > style you are expected to explicitly close the file when you are finished > with it. This is especially important when writing to a file because that > will guarantee that

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Alan Gauld
On 07/10/11 18:56, lina wrote: On Oct 8, 2011, at 0:39, "Prasad, Ramit" wrote: I would really change this to explicitly close the file. with open(base+OUTFILEEXT,"w") as f: f.write(str(summary)) Btw, I do notice lots of suggestions of closing file. Does your above sentence close the fil

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Alan Gauld
On 07/10/11 16:40, lina wrote: but today I was also discouraged, I was told that you should not have learned python, you should focus on C or bash, or D, cause python is going to be obsolete, C is a great language for writing Operating Systems and other "near the metal" code. But its not the

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Oct 8, 2011, at 0:39, "Prasad, Ramit" wrote: >> open(base+OUTFILEEXT,"w").write(str(summary)) > Unless Python3 is different with respect to files, I would really change this > to explicitly close the file. In general, I think explicitly closing > resources (database connections, files, etc)

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Oct 8, 2011, at 0:33, "Prasad, Ramit" wrote: >> what does the >> >> for col, ch in enumerate(line): >> > > I highly recommend looking at web documentation when you can. It is not that > I have any problems answering any questions, but I know I get frustrated when > I am forced to l

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Prasad, Ramit
>what does the > >for col, ch in enumerate(line): > I highly recommend looking at web documentation when you can. It is not that I have any problems answering any questions, but I know I get frustrated when I am forced to learn things in 5 minute increments while waiting on people to r

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Prasad, Ramit
> open(base+OUTFILEEXT,"w").write(str(summary)) Unless Python3 is different with respect to files, I would really change this to explicitly close the file. In general, I think explicitly closing resources (database connections, files, etc) are a Good Thing. with open(base+OUTFILEEXT,"w") as f:

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
#!/usr/bin/python3 import os.path import glob TOKENS="BE" LINESTOSKIP=0 INFILEEXT=".xpm" OUTFILEEXT=".txt" if __name__=="__main__": for fileName in glob.glob('*.xpm'): base, ext =os.path.splitext(fileName) text=open(fileName).readlines() text=text[LINESTOSKIP:]

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
what does the for col, ch in enumerate(line): enumerate(line) mean, I used idle3 test enumerate, it always showed me: >>> a 'abcde' >>> enumerate(a) I don't have a deep understanding. Thanks all of you, for your kindness of giving advice and your patience in explaination. also anothe

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Fri, Oct 7, 2011 at 11:03 PM, Alan Gauld wrote: > On 07/10/11 13:21, lina wrote: > > One simple explanation: it continued on to the next file, which has >>neither "E" nor "B" in it. >> >> In this directory, I only kept one file. try.xpm >> >> $ more try.xpm >> aaEbb >> aEEbb >> EaEbb

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Alan Gauld
On 07/10/11 13:21, lina wrote: One simple explanation: it continued on to the next file, which has neither "E" nor "B" in it. In this directory, I only kept one file. try.xpm $ more try.xpm aaEbb aEEbb EaEbb EaEbE $ ls counter-vertically-v2.py try.xpm counter-vertically.py try.t

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Alan Gauld
On 07/10/11 11:25, Dave Angel wrote: for a,b in zip(results['E'],results['B']): summary.append(a+b) I don't know why this gives a key error on 'E' (which basically means that there is no key 'E') since the code above should guarantee that it exists. Odd. I'm also not sure why the error occurs

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
> > Now fixed the excessive output. > > Thanks, > > but in another case, seems there is a problem, for the line actually is: > > "EEES~~EE~EE~EE~ > > E~~EEE~E >

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Fri, Oct 7, 2011 at 4:08 PM, lina wrote: > > > On Fri, Oct 7, 2011 at 3:39 PM, lina wrote: > >> >> >> On Fri, Oct 7, 2011 at 9:50 AM, Steven D'Aprano wrote: >> >>> lina wrote: >>> >>> May I ask a further question: a >>> >> {'B': [4, 5, 6], 'E': {1, 2, 3}} >>> >>> Why

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Fri, Oct 7, 2011 at 9:08 PM, Andreas Perstinger < andreas.perstin...@gmx.net> wrote: > On 2011-10-07 14:21, lina wrote: > >> I don't know why this gives a key error on 'E' (which basically means that there is no key 'E') since the code above should guarantee that it exists. >>>

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Andreas Perstinger
On 2011-10-07 14:21, lina wrote: I don't know why this gives a key error on 'E' (which basically means that there is no key 'E') since the code above should guarantee that it exists. Odd. I'm also not sure why the error occurs after it prints summary. Are you sure the output is in the sequenc

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
When I put it into a real case, it showed me all as 0 0 0 s The python code and the real one file can be accessed from below link: https://docs.google.com/leaf?id=0B93SVRfpVVg3MjQ0YzEzOWUtYWU0MC00YzAwLWJiYTctY2E5YTEzY2U0NGI3&hl=en_GB https://docs.google.com/leaf?id=0B93SVRfpVVg3MWMxZDg0MmItOTNi

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Fri, Oct 7, 2011 at 6:25 PM, Dave Angel wrote: > On 10/07/2011 06:06 AM, Alan Gauld wrote: > >> On 07/10/11 09:08, lina wrote: >> >> >> summary=[] >>> for a,b in zip(results['E'],results['B'])**: >>> summary.append(a+b) >>> >> >> I don't know why this gives a key error on 'E'

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Fri, Oct 7, 2011 at 6:25 PM, Dave Angel wrote: > On 10/07/2011 06:06 AM, Alan Gauld wrote: > >> On 07/10/11 09:08, lina wrote: >> >> >> summary=[] >>> for a,b in zip(results['E'],results['B'])**: >>> summary.append(a+b) >>> >> >> I don't know why this gives a key error on 'E'

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Dave Angel
On 10/07/2011 06:06 AM, Alan Gauld wrote: On 07/10/11 09:08, lina wrote: summary=[] for a,b in zip(results['E'],results['B']): summary.append(a+b) I don't know why this gives a key error on 'E' (which basically means that there is no key 'E') since the code above should gu

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Dave Angel
On 10/07/2011 04:08 AM, lina wrote: I thought it might be some loop reason made it double output the results, so I made an adjustation in indent, now it showed: $ python3 counter-vertically-v2.py {'B': [0, 0, 0, 0, 0, 0], 'E': [1, 0, 1, 0, 1, 0]} {'B': [0, 0, 0, 0, 0, 0], 'E': [1, 0, 1, 0, 1, 0]

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Alan Gauld
On 07/10/11 09:08, lina wrote: TOKENS="BE" LINESTOSKIP=0 INFILEEXT=".xpm" OUTFILEEXT=".txt" def dofiles(topdirectory): for filename in os.listdir(topdirectory): processfile(filename) def processfile(infilename): results={} base, ext =os.path.splitext(infilename) if

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Fri, Oct 7, 2011 at 3:39 PM, lina wrote: > > > On Fri, Oct 7, 2011 at 9:50 AM, Steven D'Aprano wrote: > >> lina wrote: >> >> May I ask a further question: >>> >>> a >> > {'B': [4, 5, 6], 'E': {1, 2, 3}} >>> >> >> Why is a['B'] a list and a['E'] a set? >> >> >> >> >> How can I get th

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Fri, Oct 7, 2011 at 9:50 AM, Steven D'Aprano wrote: > lina wrote: > > May I ask a further question: >> >> a > {'B': [4, 5, 6], 'E': {1, 2, 3}} >> > > Why is a['B'] a list and a['E'] a set? > > > > > How can I get the value of >> set(a['E'])+set(a['B']) >> >> I mean, get a new dict

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread lina
On Fri, Oct 7, 2011 at 9:38 AM, Dave Angel wrote: > On 10/06/2011 12:21 PM, lina wrote: > >> >> >> >>> As for splitting into functions, consider: >>> >>> #these two are capitalized because they're intended to be constant >>> TOKENS = "BE" >>> LINESTOSKIP = 43 >>> INFILEEXT = ".xpm" >>> OUTFILEEX

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread Steven D'Aprano
lina wrote: May I ask a further question: a {'B': [4, 5, 6], 'E': {1, 2, 3}} Why is a['B'] a list and a['E'] a set? How can I get the value of set(a['E'])+set(a['B']) I mean, get a new dict 'B+E':[5,7,9] You are confusing different things into one question, as if I had asked: "How

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread Dave Angel
On 10/06/2011 12:21 PM, lina wrote: As for splitting into functions, consider: #these two are capitalized because they're intended to be constant TOKENS = "BE" LINESTOSKIP = 43 INFILEEXT = ".xpm" OUTFILEEXT = ".txt" def dofiles(topdirectory): for filename in os.listdr(topdirectory):

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread lina
> > > As for splitting into functions, consider: > > #these two are capitalized because they're intended to be constant > TOKENS = "BE" > LINESTOSKIP = 43 > INFILEEXT = ".xpm" > OUTFILEEXT = ".txt" > > def dofiles(topdirectory): >for filename in os.listdr(topdirectory): >processfile(f

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread Andreas Perstinger
On 2011-10-06 16:11, lina wrote: I still don't know how to (standard) convert the list values to a string. def writeonefiledata(outname,results): outfile = open(outname,"w") for key, value in results.items(): print(value) outfile.write(str(results[key])) Is it a wrong

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread lina
On Thu, Oct 6, 2011 at 4:33 AM, Prasad, Ramit wrote: > >>yes, you're iterating over the keys of a dictionary. Since it only has > the key "E", that's what you get. Try printing dir(results) to see what > methods might return something other than the key. Make the language work > for you. > > >S

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread lina
On Thu, Oct 6, 2011 at 1:39 PM, Andreas Perstinger < andreas.perstin...@gmx.net> wrote: > On 2011-10-06 05:46, lina wrote: > >> On Thu, Oct 6, 2011 at 4:33 AM, Prasad, >> Ramit >> >wrote: >> >>> Dictionaries {} are containers for key/value based pairs like { key : >>> >>> value, another_key : v

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread lina
On Thu, Oct 6, 2011 at 5:18 PM, Alan Gauld wrote: > On 06/10/11 04:54, lina wrote: > > If you use IDLE, the standard IDE that comes with Python, you should >>find that hitting tab (or pausing briefly) in a file editor will >>bring up a pick list of options. >> >> Just tried the idle-p

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread Alan Gauld
On 06/10/11 04:54, lina wrote: If you use IDLE, the standard IDE that comes with Python, you should find that hitting tab (or pausing briefly) in a file editor will bring up a pick list of options. Just tried the idle-python2.6, Q1: Is it bound with certain python version, such as

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread Andreas Perstinger
On 2011-10-06 05:46, lina wrote: On Thu, Oct 6, 2011 at 4:33 AM, Prasad, Ramitwrote: Dictionaries {} are containers for key/value based pairs like { key : value, another_key : value(can be same or repeated) } For example: {'B': [0, 0, 0, 0, 0, 0], 'E': [2, 1, 4, 0, 1, 0]} The keys here are

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread lina
On Thu, Oct 6, 2011 at 2:01 AM, Alan Gauld wrote: > On 05/10/11 13:46, lina wrote: > > another question, you know in linux, when use TAB, can automatically >> input something, >> so in python3, are there some way they can intelligent give some hints >> or fill the left. >> > > What development to

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread lina
On Thu, Oct 6, 2011 at 4:33 AM, Prasad, Ramit wrote: > >>yes, you're iterating over the keys of a dictionary. Since it only has > the key "E", that's what you get. Try printing dir(results) to see what > methods might return something other than the key. Make the language work > for you. > > >S

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread Prasad, Ramit
>>yes, you're iterating over the keys of a dictionary. Since it only has the >>key "E", that's what you get. Try printing dir(results) to see what methods >>might return something other than the key. Make the language work for you. >Sorry I am not smart. value? Dictionaries {} are container

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread Alan Gauld
On 05/10/11 13:46, lina wrote: another question, you know in linux, when use TAB, can automatically input something, so in python3, are there some way they can intelligent give some hints or fill the left. What development tool are you using? If you use IDLE, the standard IDE that comes with P

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread lina
> I ask again. What did results look like when you print it out. I'm > referring to the argument to writeonefiledata(). > >> def writeonefiledata(outname,**results): >> > put the lines here: >print ("results is: ", results) >print("repr is:", repr(results)) $ python3 c

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread Dave Angel
On 10/05/2011 08:46 AM, lina wrote: On Wed, Oct 5, 2011 at 8:21 PM, Dave Angel wrote: #these two are capitalized because they're intended to be constant TOKENS = "BE" LINESTOSKIP = 43 INFILEEXT = ".xpm" OUTFILEEXT = ".txt" def dofiles(topdirectory): for filename in os.listdr(topdirector

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread lina
On Wed, Oct 5, 2011 at 8:21 PM, Dave Angel wrote: > > >> >>> #these two are capitalized because they're intended to be constant >>> TOKENS = "BE" >>> LINESTOSKIP = 43 >>> INFILEEXT = ".xpm" >>> OUTFILEEXT = ".txt" >>> >>> def dofiles(topdirectory): >>>for filename in os.listdr(topdirectory):

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread Dave Angel
On 10/05/2011 02:51 AM, lina wrote: On Wed, Oct 5, 2011 at 1:42 PM, Dave Angel wrote: On 10/04/2011 11:13 PM, lina wrote: On Wed, Oct 5, 2011 at 10:45 AM, Dave Angel wrote: On 10/04/2011 10:22 PM, lina wrote: On Wed, Oct 5, 2011 at 1:30 AM, Prasad, Ramit *com w SyntaxError: inva

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread lina
On Wed, Oct 5, 2011 at 1:42 PM, Dave Angel wrote: > On 10/04/2011 11:13 PM, lina wrote: > >> On Wed, Oct 5, 2011 at 10:45 AM, Dave Angel wrote: >> >> On 10/04/2011 10:22 PM, lina wrote: >>> >>> On Wed, Oct 5, 2011 at 1:30 AM, Prasad, Ramit>>> *com > w > >>> SyntaxError:

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Andreas Perstinger
On 2011-10-05 05:13, lina wrote: $ python3 counter-vertically.py ^^^ File "counter-vertically.py", line 20 print item ^ SyntaxError: invalid syntax In Python 3 print is a function: print(item) In another message in this thread you've said: "Sorry, I am still lac

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Dave Angel
On 10/04/2011 11:13 PM, lina wrote: On Wed, Oct 5, 2011 at 10:45 AM, Dave Angel wrote: On 10/04/2011 10:22 PM, lina wrote: On Wed, Oct 5, 2011 at 1:30 AM, Prasad, Ramit w SyntaxError: invalid syntax for fileName in os.listdir("."): if os.path.isfile(fileName) and os.path.splitext(

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread lina
On Wed, Oct 5, 2011 at 10:45 AM, Dave Angel wrote: > On 10/04/2011 10:22 PM, lina wrote: > >> On Wed, Oct 5, 2011 at 1:30 AM, Prasad, >> Ramit >> >wrote: >> >> But I still don't know how to get the statistic result of each column, >>> Thanks. >>> try: >>>cols = len( text[0] ) # Fi

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Dave Angel
On 10/04/2011 10:22 PM, lina wrote: On Wed, Oct 5, 2011 at 1:30 AM, Prasad, Ramitwrote: But I still don't know how to get the statistic result of each column, Thanks. try: cols = len( text[0] ) # Find out how many columns there are (assuming each row has the same number of columns) except

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread lina
On Wed, Oct 5, 2011 at 1:30 AM, Prasad, Ramit wrote: > >But I still don't know how to get the > >statistic result of each column, > > Thanks. > > try: >cols = len( text[0] ) # Find out how many columns there are (assuming > each row has the same number of columns) > except IndexError: >ra

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Alan Gauld
On 04/10/11 18:09, lina wrote: But I still don't know how to get the statistic result of each column, Let's ignore the traversal of files issue for now. Let's look at processing one file: You want a list of totals of equal length to the number of columns. We can find that number using len(line

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Alan Gauld
On 04/10/11 17:38, lina wrote: For file: aaEbb aEEbb EaEbb EaEbE the expected output is 2 1 0 1 I expected 2 1 4 0 1 In the first column there is 2 E, so the output is 2 E, second column is 1 E. But the 3rd is all E so why miss out the 4? I'm still confused - and I thought I was gettin

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Dave Angel
On 10/04/2011 01:09 PM, lina wrote: But I still don't know how to get the statistic result of each column, Thanks for further suggestions, Best regards, lina As I said before, your current code counts across a line at a time, while you need to count vertically. That could be done by transpo

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Prasad, Ramit
>But I still don't know how to get the >statistic result of each column, try: cols = len( text[0] ) # Find out how many columns there are (assuming each row has the same number of columns) except IndexError: raise # This will make sure you can see the error while developing;

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread lina
But I still don't know how to get the statistic result of each column, Thanks for further suggestions, Best regards, lina ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tut

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread lina
On Wed, Oct 5, 2011 at 12:59 AM, Marc Tompkins wrote: > On Tue, Oct 4, 2011 at 8:48 AM, lina wrote: > >> if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm": >> filedata = open(fileName) >> text=filedata.readlines() >> for line in text[0:]: >>

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Marc Tompkins
On Tue, Oct 4, 2011 at 8:48 AM, lina wrote: > if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm": > filedata = open(fileName) > text=filedata.readlines() > for line in text[0:]: > result.append({t:line.strip().count(t) for t in tokens}) >

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread lina
For file: aaEbb aEEbb EaEbb EaEbE the expected output is 2 1 0 1 In the first column there is 2 E, so the output is 2 E, second column is 1 E. #!/bin/python import os.path tokens=['B','E'] for fileName in os.listdir("."): result=[] if os.path.isfile(fileName) and os.path.splitext(f

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Dave Angel
On 10/04/2011 10:26 AM, lina wrote: On Thu, Sep 29, 2011 at 11:28 PM, Dave Angel wrote: (Please don't top-post. Put your remarks AFTER the part you're quoting from the previous message) On 09/29/2011 10:55 AM, lina wrote: import os.path tokens=['E'] result=[] for fileName in os.listdir(

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread lina
On Tue, Oct 4, 2011 at 11:27 PM, Dave Angel wrote: > On 10/04/2011 10:26 AM, lina wrote: > >> On Thu, Sep 29, 2011 at 11:28 PM, Dave Angel wrote: >> >> (Please don't top-post. Put your remarks AFTER the part you're quoting >>> from the previous message) >>> >>> >>> On 09/29/2011 10:55 AM, lina

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread lina
On Thu, Sep 29, 2011 at 11:28 PM, Dave Angel wrote: > (Please don't top-post. Put your remarks AFTER the part you're quoting > from the previous message) > > > On 09/29/2011 10:55 AM, lina wrote: > >> import os.path >> >> tokens=['E'] >> result=[] >> >> for fileName in os.listdir("."): >> if

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
Hi Alan, On 29 September 2011 18:12, Alan Gauld wrote: > On 29/09/11 17:00, Walter Prins wrote: > > email. By the way, a question to the list adminstrators: why does the >> default reply to address for this mailing list not default to the >> mailing list? >> > > This is an oft debated issue an

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Prasad, Ramit
>This is an oft debated issue and there are arguments for both options. >The current setup allows easier replies to either originator or list by >simply selecting which Reply button you use. If you set default reply to >the list how do you reply to just the originator when you want to? I would h

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Alan Gauld
On 29/09/11 17:00, Walter Prins wrote: email. By the way, a question to the list adminstrators: why does the default reply to address for this mailing list not default to the mailing list? This is an oft debated issue and there are arguments for both options. The current setup allows easier r

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Alan Gauld
On 29/09/11 15:22, lina wrote: I want to read a bunch of *.doc file in present working directory, What format are the doc files? If they are word processor files they may well be in binary format so you will need to either decode them (using struct?) or find a module that can read them, or a

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Fri, Sep 30, 2011 at 12:31 AM, Walter Prins wrote: > Hi, > > On 29 September 2011 17:07, lina wrote: > >> I found one thing a bit weird, Here is the one: >> >> import os.path >> >> tokens=['E'] >> result=[] >> >> """ >> for fileName in os.listdir("."): >> if os.path.isfile(fileName) and o

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
Hi, On 29 September 2011 17:07, lina wrote: > I found one thing a bit weird, Here is the one: > > import os.path > > tokens=['E'] > result=[] > > """ > for fileName in os.listdir("."): > if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm": > """ > filedata = open("1.xpm") >

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 11:57 PM, Walter Prins wrote: > Hi, > > On 29 September 2011 16:39, lina wrote: > >> >> Or you can get lines 24-28, with text[24, 29] (look up slices in the >>> Python doc) >>> >> > Dave probably meant: text[24:29] > > > >> >>> print splitext.__doc__ >> Traceback (mos

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
Hi, On 29 September 2011 16:39, lina wrote: > Traceback (most recent call last): > File "", line 1, in > NameError: name 'slices' is not defined > Sorry I meant to include a link to relevant documentation: http://docs.python.org/tutorial/introduction.html (And apologies for forgetting to re

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
Hi, On 29 September 2011 16:39, lina wrote: > > Or you can get lines 24-28, with text[24, 29] (look up slices in the >> Python doc) >> > Dave probably meant: text[24:29] > >>> print splitext.__doc__ > Traceback (most recent call last): > File "", line 1, in > NameError: name 'splitext'

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Prasad, Ramit
Or you can get lines 24-28, with  text[24, 29]   (look up slices in the Python doc)  >>> print splitext.__doc__ Traceback (most recent call last):   File "", line 1, in NameError: name 'splitext' is not defined >>> print slices.__doc__ Traceback (most recent call last):   File "", line 1, in Na

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 11:28 PM, Dave Angel wrote: > (Please don't top-post. Put your remarks AFTER the part you're quoting > from the previous message) > > > On 09/29/2011 10:55 AM, lina wrote: > >> import os.path >> >> tokens=['E'] >> result=[] >> >> for fileName in os.listdir("."): >> if

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Dave Angel
(Please don't top-post. Put your remarks AFTER the part you're quoting from the previous message) On 09/29/2011 10:55 AM, lina wrote: import os.path tokens=['E'] result=[] for fileName in os.listdir("."): if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm": fileda

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 11:18 PM, Walter Prins wrote: > > > On 29 September 2011 16:13, lina wrote: > >> mport os.path >> >> tokens=['E'] >> result=[] >> >> for fileName in os.listdir("."): >> if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm": >> filedata = open(fileN

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
On 29 September 2011 16:13, lina wrote: > mport os.path > > tokens=['E'] > result=[] > > for fileName in os.listdir("."): > if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm": > filedata = open(fileName,'r') > > text=filedata.readlines() > for line in te

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
mport os.path tokens=['E'] result=[] for fileName in os.listdir("."): if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm": filedata = open(fileName,'r') text=filedata.readlines() for line in text: print line why here I print nothing out? The

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 10:55 PM, lina wrote: > import os.path > > tokens=['E'] > result=[] > > > for fileName in os.listdir("."): > if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm": > filedata = open(fileName) > text=filedata.readlines() > for line in

  1   2   >