[Tutor] urllib2 sslerror

2011-10-07 Thread Johan Geldenhuys
Hi everybody, Almost weekend, hang in there. I need some advice and hope somebody can help me. I have the follow piece of code that I use to get some data from a https webpage. --- < some other stuff up here> try: return_object = urllib2.u

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-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 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 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 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 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 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 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 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
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 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
> > 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 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 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 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 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
#!/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 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 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 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 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)

[Tutor] Runtime error while Test data creation

2011-10-07 Thread Guess?!?
Hello all, I am trying to create some test data for a search module that I am building. Since I dont want to hit performance related issues late in the game, I decided to create half a million records in the DB. My approach is create a csv file with valid UUIDs which I already have. Read each rec

[Tutor] Help!

2011-10-07 Thread rmntcverses
I need serious help with this Rock, Paper, Scissors program. The program runs smoothly but I can't get the score to print. Please help me with this one aspect! Here is my code right now: import random def computerrockPaperScissors(): selection = random.randint(0, 2) if selection == 0

[Tutor] vcf_files and strings

2011-10-07 Thread Anna Olofsson
Hi, I'm a beginner at Python and would really appreciate some help in how to extract information from a vcf file. The attached file consists of a lot of information on mutations, this one though is just 2 rows and 10 columns (the real one has a lot more rows). I want to extract the mRNA ID

Re: [Tutor] Help!

2011-10-07 Thread Alex Hall
On 10/7/11, rmntcver...@aol.com wrote: > I need serious help with this Rock, Paper, Scissors program. The program > runs smoothly but I can't get the score to print. Please help me with this > one aspect! Here is my code right now: > > > > import random > > > def computerrockPaperScissors(): >

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 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] vcf_files and strings

2011-10-07 Thread Hs Hs
if col[x] == 'missense':     print col[withRefSeqID] hth From: Anna Olofsson To: tutor@python.org Sent: Friday, October 7, 2011 12:12 PM Subject: [Tutor] vcf_files and strings Hi, I'm a beginner at Python and would really appreciate some help in how

Re: [Tutor] Help!

2011-10-07 Thread bob gailer
On 10/7/2011 12:32 PM, rmntcver...@aol.com wrote: I need serious help with this Rock, Paper, Scissors program. The program runs smoothly but I can't get the score to print. Please help me with this one aspect! Here is my code right now: Welcome to Python Help. In future please use a meaningfu

Re: [Tutor] Runtime error while Test data creation

2011-10-07 Thread bob gailer
On 10/7/2011 2:19 PM, Guess?!? wrote: Hello all, I am trying to create some test data for a search module that I am building. Since I dont want to hit performance related issues late in the game, I decided to create half a million records in the DB. My approach is create a csv file with vali

Re: [Tutor] Runtime error while Test data creation

2011-10-07 Thread Guess?!?
Hey Bob, Thanks for the suggestions. There is no traceback/stacktrace errors that I can see (may be there is a file that is generated in python or windows directory due to run time failure but I am not able to locate it. Please let me know if you know). The run time error pops up in a windows dia

Re: [Tutor] Runtime error while Test data creation

2011-10-07 Thread Prasad, Ramit
From: tutor-bounces+ramit.prasad=jpmorgan@python.org [mailto:tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of Guess?!? Sent: Friday, October 07, 2011 4:32 PM To: bob gailer Cc: tutor@python.org Subject: Re: [Tutor] Runtime error while Test data creation Hey Bob, Thanks for t

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 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] Runtime error while Test data creation

2011-10-07 Thread bob gailer
On 10/7/2011 5:32 PM, Guess?!? wrote: Hey Bob, Thanks for the suggestions. There is no traceback/stacktrace errors that I can see (may be there is a file that is generated in python or windows directory due to run time failure but I am not able to locate it. Please let me know if you know).

Re: [Tutor] Runtime error while Test data creation

2011-10-07 Thread bob gailer
On 10/7/2011 5:32 PM, Guess?!? wrote: A couple of suggestion below (inline with the code): import pyodbc, random, datetime, uuid #INT conn = pyodbc.connect('DRIVER={SQL Server};SERVER=SERVERNAME\INT_FOUNDATIONS;DATABASE=membership_service;UID=int_usr;PWD=blah') c = conn

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
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

[Tutor] swapping list elements based on some criterion

2011-10-07 Thread عمـ نوفل ـاد
Hello Tutors, It's been quite some time since I last posted something here, and now I'm back with a question: I want to re-structure English so that the adjectives appear after the nouns, instead of before. If I have a sentence like: The tall man plays well I need to change it to The man tall pla

Re: [Tutor] swapping list elements based on some criterion

2011-10-07 Thread Steven D'Aprano
Emad Nawfal (عمـ نوفل ـاد) wrote: Hello Tutors, It's been quite some time since I last posted something here, and now I'm back with a question: I want to re-structure English so that the adjectives appear after the nouns, instead of before. If I have a sentence like: The tall man plays well I n

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 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] vcf_files and strings

2011-10-07 Thread Andreas Perstinger
[I have already answered your first post but it seems you missed it] On 2011-10-07 18:12, Anna Olofsson wrote: Hi, I'm a beginner at Python and would really appreciate some help in how to extract information from a vcf file. What does "beginner" mean? Do you have experience in other language

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] swapping list elements based on some criterion

2011-10-07 Thread عمـ نوفل ـاد
Hi Steven ans Tutors, Thanks for the code. Actually I'm not a student at all. I'm an assistant professor of Arabic at Suez Canal University in Egypt. I would appreciate more contributions from you and the other list members. 2011/10/8 Steven D'Aprano > Emad Nawfal (عمـ نوفل ـاد) wrote: > >> Hell

Re: [Tutor] swapping list elements based on some criterion

2011-10-07 Thread عمـ نوفل ـاد
2011/10/8 Emad Nawfal (عمـ نوفل ـاد) > Hi Steven ans Tutors, > Thanks for the code. > Actually I'm not a student at all. I'm an assistant professor of Arabic at > Suez Canal University in Egypt. I would appreciate more contributions from > you and the other list members. > > > 2011/10/8 Steven D'

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