Re: [Tutor] self keyword in recursive function
That's all the code I'm writing. As for the reference to line 182, I have no idea since my code doesn't have line 182. Also, as Peter wrote: "The "topcoder" site is probably infested with the world view of Java where every function is a method inside a class." Topcoder seems too much in love with Java style of coding and Python seems much better. I'm switching to some other platform. Thank You all for the quick response. On Sat, May 31, 2014 at 11:53 AM, Marc Tompkins wrote: > On Fri, May 30, 2014 at 11:06 PM, Ritwik Raghav > wrote: > >> That's all the code I'm writing. >> > > That can't be true - the 11 lines of code you posted doesn't include > anything that would give you "Correct Return Value: No", let alone any > reference to PersistentNumber. From the error message, it would appear > that you've written (at least) 182 lines, and that the problem is on line > 182 - but that's not what you're showing us. > > > >> The complete problem statement is: >> http://pastebin.com/E970qYXk >> > > Yes, but that's not _your_ code, so it tells us nothing about your error. > > > -- Ritwik Raghav ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Break outside the loop error (line 23)
On 31/05/14 10:23, Sasi - wrote: Hi, i tried to make a code to execute the functions that i described below. However i got a break outside the loop error Always post the full error message it usually contains lots of useful detail. ## Created the lists for brain and plasma before searching for common bioseq. while True: count1 += 1 s1=file1.readline().partition(',')[0] if s1 and count1 > 1: This line is not indented so the loop stops on the previous line. brain.append(s1) if not s1: break But your 'break' is here so it is outside the loop. You need to indent the whole section from if s1 and count1 > 1: so that it is inside the loop. while True: count2 += 1 s2=file2.readline().partition(',')[0] if s2 and count2 > 1: plasma.append(s2) if not s2: break And the same problem here. The indentation defines what is inside the loop. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Break outside the loop error (line 23)
On 31.05.2014 11:23, Sasi - wrote: Hi, i tried to make a code to execute the functions that i described below. However i got a break outside the loop error and i have tried to tab and all that but i still get the same error for line 23. I'm using python 2.7 Hi, as a general rule, copy paste the traceback of the actual python exception instead of summarizing it. In this specific case the error is obvious though (see below). Please help me. I'm completely new to coding (just started last week) Thank you for your time, i have pasted the code below. ## open both files file1 = open('human_brain_proteins.csv') file2 = open('human_plasma_proteins.csv') #file1 = open('log1') #file2 = open('log2') ## createdd a counter to count lines count1 = 0 count2 = 0 ## define 3 lists to be filled in later common = list() brain = list() plasma = list() ## Created the lists for brain and plasma before searching for common bioseq. while True: count1 += 1 s1=file1.readline().partition(',')[0] your while loop ends here because the next line is not indented (probably not what you intended). if s1 and count1 > 1: brain.append(s1) if not s1: break since you are not inside the while loop anymore, there is nothing to break from. while True: count2 += 1 s2=file2.readline().partition(',')[0] if s2 and count2 > 1: plasma.append(s2) if not s2: break ## Compared the lists to find out common bioseq., add the common bioseq. into the common list, ## then remove the common bioseq. from both lists for item1 in brain: for item2 in plasma: if item1 == item2: common.append(item1) brain.remove(item1) plasma.remove(item2) ## closed both files file1.close() file2.close() ## print out the lists print "Common biosequence:" print common,"\n" print "Brain specific biosequence:" print brain,"\n" print "Plasma specific biosequence:" print plasma,"\n" additional suggestion: read about the set datatype of python and its intersection and difference methods (https://docs.python.org/2/library/stdtypes.html#set-types-set-frozenset). It looks like handling your data as two sets instead of two lists should be much more convenient. Best, Wolfgang ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Break outside the loop error (line 23)
Hi, i tried to make a code to execute the functions that i described below. However i got a break outside the loop error and i have tried to tab and all that but i still get the same error for line 23. I'm using python 2.7 Please help me. I'm completely new to coding (just started last week)Thank you for your time, i have pasted the code below. ## open both filesfile1 = open('human_brain_proteins.csv')file2 = open('human_plasma_proteins.csv')#file1 = open('log1')#file2 = open('log2') ## createdd a counter to count linescount1 = 0count2 = 0 ## define 3 lists to be filled in latercommon = list()brain = list()plasma = list() ## Created the lists for brain and plasma before searching for common bioseq.while True:count1 += 1s1=file1.readline().partition(',')[0]if s1 and count1 > 1:brain.append(s1)if not s1: breakwhile True:count2 += 1s2=file2.readline().partition(',')[0]if s2 and count2 > 1:plasma.append(s2)if not s2:break ## Compared the lists to find out common bioseq., add the common bioseq. into the common list,## then remove the common bioseq. from both listsfor item1 in brain:for item2 in plasma:if item1 == item2: common.append(item1)brain.remove(item1) plasma.remove(item2) ## closed both filesfile1.close()file2.close() ## print out the listsprint "Common biosequence:"print common,"\n"print "Brain specific biosequence:"print brain,"\n"print "Plasma specific biosequence:"print plasma,"\n" ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about scraping
On May 30, 2014 10:12 PM, "Matthew Ngaha" wrote: > > Thanks for the response Alan. I forgot to reply to tutor on my 2nd > comment. Just incase someone might want to see it, here it is: > > "Okay I think learning how to scrap (library or framework) is not > worth the trouble. Especially if some people consider it illegal. > Thanks for the input." > ___ Check out beautiful soup > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Library for .ppt to .txt conversion
Aaron Misquith Wrote in message: > The only thing i want from the ppt's is text and ignoring all graphical representations. I > need the text to perform various nltk operations. > On Fri, May 30, 2014 at 11:54 PM, Alan Gauld > wrote: >> Bearing in mind that Powerpoint is intended for graphical presentations the >> text >> elements are not necessarily going to be useful. Often Powerpoint text >> is actually part of a graphic anyway. 1. please don't top-post. Place your comments after the quoted text from the previous message. Please tell your mail program to use text, not html when posting here. 2. Alan has pointed out that there may not be any text in the ppt file, but just image data that represents the text. Similar to the way a scanned piece of paper has no text till you try to ocr it. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HTML Parsing
> > I see others have answered the programming question, but there's > a separate one. What is the license of the particular ste, yahoo > in this case. For an occasional scrape, nobody's likely to mind. > But if you plan any volume, using the official api is more > polite. Thanks for the reply. We have a legacy intranet site that hosts reports in html. I need to convert reports in CSV format. So I wanted to connect to the site and parse to CSV. On Thu, May 29, 2014 at 12:10 AM, Dave Angel wrote: > "Mitesh H. Budhabhatti" Wrote in > message: > > (please post in text email, not html. Doesn't matter for most > people on this particular message, but it's the polite thing to > do) > > I see others have answered the programming question, but there's > a separate one. What is the license of the particular ste, yahoo > in this case. For an occasional scrape, nobody's likely to mind. > But if you plan any volume, using the official api is more > polite. > > -- > DaveA > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Library for .ppt to .txt conversion
The only thing i want from the ppt's is text and ignoring all graphical representations. I need the text to perform various nltk operations. On Fri, May 30, 2014 at 11:54 PM, Alan Gauld wrote: > On 30/05/14 10:41, Aaron Misquith wrote: > >> Like pypdf is used to convert pdf to text; is there any library that is >> used in converting .ppt files to .txt? Even some sample programs will be >> helpful. >> > > Bearing in mind that Powerpoint is intended for graphical presentations > the text elements are not necessarily going to be useful. Often Powerpoint > text is actually part of a graphic anyway. > > If the Powerpoint is just a set of bullet points (shame on the presenter!) > you probably don't want the text unless you can > also get the notes. I don't know of any libraries that can do that. > > But one option is that Open/Libre office can import Powerpoint and > apparently has a Python API which you could use to drive an export > from there. Just a thought... > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.flickr.com/photos/alangauldphotos > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] self keyword in recursive function
On Fri, May 30, 2014 at 10:16 PM, Ritwik Raghav mailto:ritwikragha...@gmail.com>> wrote: and the error is: Correct Return Value: No Answer check result: Result must be not null. Execution Time: 0.017s Peak memory used: 24.551MB abnormal termination (exit 1) Standard Output: Standard Error: Traceback (most recent call last): File "Wrapper.py", line 182, in AttributeError: 'module' object has no attribute 'PersistentNumber' This is not standard Python error output so I assume it has something to do with how you submit code to the site you are using. It looks like it has some kkind of testing framework that your code must comply with. You probably need to read their guidance on code submission closely. One possible bug I did notice in your code is here: count = 0 You define count outside the method but not as part of self. def getPersistence(self,n): product = 1 if len(str(n)) == 1: return self.count then you return self.count. That's a different value, which may be defaulting to None in your test environment? If you insist on using recursion I'd bring the count back as an argument defaulted to zero as you did in your original code. else: a = str(n) for i in a: product *= int(i) self.count += 1 return self.getPersistence(product) But without knowing how toploader tests your code its hard to say for sure what's going wrong. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor