Re: [Tutor] Thanks for the advise to tutor! HTTP Error 400 resolved
I have added below to the first line of the function and managed to ignore the space and solve it. Thank you for the hint! some_text=urllib.parse.quote_plus(some_text) On Tue, Feb 13, 2018 at 5:00 PM, wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > Today's Topics: > >1. Re: [Help] urllib.error.HTTPError: HTTP Error 400: Bad > Request (Peter Otten) > > > -- Forwarded message -- > From: Peter Otten <__pete...@web.de> > To: tutor@python.org > Cc: > Bcc: > Date: Tue, 13 Feb 2018 14:47:56 +0100 > Subject: Re: [Tutor] [Help] urllib.error.HTTPError: HTTP Error 400: Bad > Request > cm wrote: > >> Dear tutors, >> >> I have written below function to open the profanity check url and then >> to check for profanity in some text. When I go to the url >> http://www.wdylike.appspot.com/?q= and type in the same text, it works >> fine. >> >> I am using Microsoft OS X and Python 3.5.2 Interpreter with Pycharm >> Community Edition. >> >> --- >> import urllib.request >> >> def check_profanity(some_text): >> # check text for a curse word >> connection = >> urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text) >> output = connection.read() >> print(output) >> connection.close() >> >> check_profanity(some_text="I gave it a good shot") >> --- >> >> Error message: >> Traceback (most recent call last): >> File >> "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py", >> line 29, in >> check_profanity(some_text="I gave it a good shot") >> File >> "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py", >> line 15, in check_profanity >> connection = >> urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 163, in >> urlopen >> return opener.open(url, data, timeout) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 472, in >> open >> response = meth(req, response) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 582, >> in http_response >> 'http', request, response, code, msg, hdrs) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 510, in >> error >> return self._call_chain(*args) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 444, >> in _call_chain >> result = func(*args) >> File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 590, >> in http_error_default >> raise HTTPError(req.full_url, code, msg, hdrs, fp) >> urllib.error.HTTPError: HTTP Error 400: Bad Request >> >> Process finished with exit code 1 >> >> --- >> However when I run the code it just says Bad Request. I tried to read >> into the traceback message but it refers not only to my file but the >> urllib function itself too and I can't understand. > > Spaces aren't allowed in the url: > c = rq.urlopen("http://www.wdylike.appspot.com/?q=nice try") > [...] > urllib.error.HTTPError: HTTP Error 400: Bad Request > > Once you escape the ' ': > c = rq.urlopen("http://www.wdylike.appspot.com/?q=nice+try";) c.read() > b'false' > > Have a look at the first example at > > https://docs.python.org/dev/library/urllib.request.html#urllib-examples > > for a more general solution. > > > > ___ > Tutor maillist - Tutor@python.org > 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
[Tutor] Thanks Alan.
I'll look into it. Yehuda ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] thanks - Beginner - explaining 'Flip a coin' bug
Hi David, Thanks for your input about the logic of this little script of mine. I confess I omitted the edge possibility and assumed heads or taisl only. As I progress further with getting the foundation knowledge of the language itself, it is really appreciated to be corrected on what good programming is about regardless of the language. Please keep commenting/helping whenever necessary. Cheers, Marc Date: Fri, 14 Feb 2014 22:49:43 -0500 Subject: Re: [Tutor] Beginner - explaining 'Flip a coin' bug From: dwightdhu...@gmail.com To: marc_eym...@hotmail.com CC: tutor@python.org Here is a problem I've come across, from empirical evidence, that also relates to your equation. We always assume that their are always two probabilities, that a coin can be either head or tails. However, there are dynamics within a third realm of the dimensionality of the coin...it's not a two dimensional plane. So the planar probabilities in relation to the 'surface are' hold another possibility...the 'edge'. The algorithm of applying the edge are up to you, but I've seen the coin land on it's curved edge more than once, so this function you've designed, should have more than two possibilities, within a complete algorithm to the real world functionality of the coin in question. On Wed, Feb 12, 2014 at 10:25 AM, Marc Eymard wrote: Hello there, I want to emulate a coin flip and count how many heads and tails when flipping it a hundred times. I first coded coinflip_WRONG.py with "count_flips += 1" statement within the if/else block. When running it, either returned values are wrong or the script seems to enter in an infinite loop showing no return values at all. coinflip.py is a corrected version I worked out myself. I moved "count_flips+= 1" out of if/else block and inserted it before if/else. However, I still don't understand the bug since, in my understanding, both files are incrementing variable count_flips each time until the loop becomes false. Can somebody explain the reason of the bug. Cheers, Marc ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)
On Sun, Dec 15, 2013 at 7:10 AM, Walter Prins wrote: > OK perhaps it remembers your preference for original emails sent by > yourself as well, but for replies (which is what I was commenting on) > my experience is as I described. To test it -- hit reply or reply-all > on this message (which is text mode), and you'll see the reply format > will be text mode, as indicated by the button bottom right. Then go > and find a digest email or any other email originally sent to you as > HTML/dual mode and hit reply -- you'll find the reply is in HTML mode > by default. > I sent a rich text email to myself. Now I'm replying to you, and it appears to still be in rich text mode. In further experiments in plain text mode (i.e. after having sent a plain text email to myself), I discovered that the mode it chooses when replying to a rich text message is in fact variable -- and random for all I can tell. Clearly it's using some criteria to pick the mode -- content, recipients, my usage history, who knows. I give up. ;) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)
Hi, On 15 December 2013 05:38, eryksun wrote: > On Sat, Dec 14, 2013 at 10:16 AM, Walter Prins wrote: >> >> Gmail matches the format of the sender. If I reply to a text format >> email, the reply is text format. If the original is HTML mail, it >> replies in HTML format. In that sense it talks back and respects the >> sender on their terms. Also, there is a drop down (right bottom) with >> which it's trivial to change from one format to the other. > > This is contrary to my experience. If I send a test message to myself > in rich text mode, Gmail's webmail composer remembers that setting the > next time I reply (i.e., the reply uses styled block quoting, > practically destined to be mangled as messages are quoted multiple > times through incompatible clients). This setting is apparently stored > in one's account and remembered across sessions. I can log out, remove > all Google cookies, and the choice of rich text persists in a new > session. But outside of a test message, I never use rich text. When I > reply it's always in plain text mode; the format of the original > message doesn't matter. Maybe it's more complicated than this, but I > can only speak from experience. OK perhaps it remembers your preference for original emails sent by yourself as well, but for replies (which is what I was commenting on) my experience is as I described. To test it -- hit reply or reply-all on this message (which is text mode), and you'll see the reply format will be text mode, as indicated by the button bottom right. Then go and find a digest email or any other email originally sent to you as HTML/dual mode and hit reply -- you'll find the reply is in HTML mode by default. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)
On Sat, Dec 14, 2013 at 10:16 AM, Walter Prins wrote: > > Gmail matches the format of the sender. If I reply to a text format > email, the reply is text format. If the original is HTML mail, it > replies in HTML format. In that sense it talks back and respects the > sender on their terms. Also, there is a drop down (right bottom) with > which it's trivial to change from one format to the other. This is contrary to my experience. If I send a test message to myself in rich text mode, Gmail's webmail composer remembers that setting the next time I reply (i.e., the reply uses styled block quoting, practically destined to be mangled as messages are quoted multiple times through incompatible clients). This setting is apparently stored in one's account and remembered across sessions. I can log out, remove all Google cookies, and the choice of rich text persists in a new session. But outside of a test message, I never use rich text. When I reply it's always in plain text mode; the format of the original message doesn't matter. Maybe it's more complicated than this, but I can only speak from experience. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)
Hi, On 14 December 2013 03:31, Steven D'Aprano wrote: > On Fri, Dec 13, 2013 at 02:24:15PM -0500, eryksun wrote: >> On Fri, Dec 13, 2013 at 12:47 PM, Mark Lawrence >> wrote: >> > Did you really have to send an entire digest, without changing the title, >> > just to send this one line? >> >> Gmail's composer top posts unless the text to quote is selected >> beforehand. > [...] > > This explains the faux pas, it doesn't excuse it. Gmail is, in my > opinion, a *terrible* mail client. It makes what should be easy hard, > what should be hard impossible, and encourages the dumbing down of > communication. > > It is bad enough that non-technical people cannot control their email > beyond clicking "Forward" and "Reply". But when people who have You have the option to Forward, Reply or Reply-all, not just Forward or Reply. > expectations of being programmers cannot even control what they send out > as an email, well, that's just shameful. And Google has to take a large > part of the blame for that. Gmail matches the format of the sender. If I reply to a text format email, the reply is text format. If the original is HTML mail, it replies in HTML format. In that sense it talks back and respects the sender on their terms. Also, there is a drop down (right bottom) with which it's trivial to change from one format to the other. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)
On 12/14/2013 04:31 AM, Steven D'Aprano wrote: To err is human, to forgive is humane. Nicely said. To the Original Poster, whoever you are... I hope you'll hang around here and [...] If it were me, he would probably not; too bad. Denis ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)
On Fri, Dec 13, 2013 at 02:24:15PM -0500, eryksun wrote: > On Fri, Dec 13, 2013 at 12:47 PM, Mark Lawrence > wrote: > > Did you really have to send an entire digest, without changing the title, > > just to send this one line? > > Gmail's composer top posts unless the text to quote is selected > beforehand. [...] This explains the faux pas, it doesn't excuse it. Gmail is, in my opinion, a *terrible* mail client. It makes what should be easy hard, what should be hard impossible, and encourages the dumbing down of communication. It is bad enough that non-technical people cannot control their email beyond clicking "Forward" and "Reply". But when people who have expectations of being programmers cannot even control what they send out as an email, well, that's just shameful. And Google has to take a large part of the blame for that. On the other hand, even the best of us have made silly mistakes, sent an email to the wrong place, forgotten to change the subject line, left people out of the CC list, quoted too much or too little. To err is human, to forgive is humane. We've all made mistakes. What matters is not the mistake itself, but what comes next. To the Original Poster, whoever you are... I hope you'll hang around here and learn something useful. Hopefully it will be good and effective email skills as well as Python programming. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)
On Fri, Dec 13, 2013 at 12:47 PM, Mark Lawrence wrote: > Did you really have to send an entire digest, without changing the title, > just to send this one line? Gmail's composer top posts unless the text to quote is selected beforehand. The user has to click on '...' to see the quoted text. Changing the subject requires the user to select "Edit subject" from a menu, which switches to a larger composer. The composer also remembers the last choice of rich vs plain text, instead of letting the user set a default mode. Someone who switches modes may forget to switch back to plain text. In this case, the entire digest was sent twice, as both plain and rich text in a multipart message. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)
On 13/12/2013 17:40, Rishi Ganesh V wrote: Really your page is useful for me... Did you really have to send an entire digest, without changing the title, just to send this one line? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks
I just want to thank all who gave some input into my questions. And the points on convention ,hey I just learned about plain text! Thanks Mike Michael Waters Business Unit Information Technology Global Data Center Data Center Services Team GDC 24/7 HotLine # 800-267-3471 McNeil Consumer Heathcare A division of Johnson & Johnson Desk # 519-826-6226 ex 5860 Home# 519-767-2629 Cell 226-500-1776 Office Hours M-F 8:00am 4:00pm My hours 8:00AM-12:00PM ITS Guelph 890 Woodlawn Road West,Guelph,On. N1K 1A5 mwat...@its.jnj.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks for all your comments regarding how we communicate.
Thanks for all your comments regarding how we communicate. I appreciate your support when someone responds negatively to my offerings of help. It is true that I can be "brusque" (which is an embarrassment for me as a teacher of Nonviolent Communication). Your encouragement to be welcoming and supportive is important to me and I will strive to be more so. I am often puzzled when I see folk asking for help with homework when it seems that the student is not in a class designed to help him learn Python (either by being in the wrong class, not meeting the prerequisites or having an instructor who cannot communicate clearly or give assignments that will get good results. I have taught in industry and in fast-path-masters )FPM) programs. I once had 5evenings to teach Pascal to FPM students. Their prerequisite class failed to do what it was supposed to do, and I got the blame for not being able to deliver fully my 5 5evenings' worth. I also find it frustrating when presented with a program that is a hodge-podge of things (e.g. functions) that came from various sources with no indication of who wrote what, and no sense that the programmer understands the various pieces. A couple of years ago a local graduate found me by searching and finding references to my participation on these lists. We negotiated a private tutoring agreement. On his first visit he presented a Python program which I assumed he had written. I could see that it was doing things the hard and inefficient way, so I coached him on how to make it better. Eventually I discovered that (1) he knew almost noting about Python; (2) the original program had been written by his advisor. (3) His advisor did not even know enough about Python to understand how inefficient the program was; (4) his advisor kept aiming at a moving target. Very frustrating for all of us. Once i understood his position I created a series of exercises to help me evaluate his knowledge and to help him learn. These exercises turned out to be at a beginner's tutorial level. Let us be compassionate; put our effort where it does the best; but continue asking for cooperation from the questioner. If I had more time I probably could make the above shorter. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks!!
On 22/08/2012 16:48, Cecilia Chavana-Bryant wrote: Hola, Just a big THANK YOU!!! to everyone that has replied to my post. I have been so confused about how to get started and since I am working from home, it has been a very frustrating and lonely experience so far. Many, many thanks for your empathy, encouragement and availability!! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Please save your thanks until you're graduated from the tutor mailing list to the main Python mailing list :) For more help take a look here http://wiki.python.org/moin/BeginnersGuide/NonProgrammers -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks!!
Hola, Just a big THANK YOU!!! to everyone that has replied to my post. I have been so confused about how to get started and since I am working from home, it has been a very frustrating and lonely experience so far. Many, many thanks for your empathy, encouragement and availability!! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks Everyone!!!
Thanks for the tips everyone! I am fairly new to programming and am finding myself both bewildered and amazed. Its fun when it works, but boy oh boy, when it doesn't Anyway thanks again, you all have been very helpful. [?] <<330.gif>>___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks!
Thanks for all your help guys! I will try to buy all those books so that if I find something in one book not understandable, I will look for it in another book. Again Thanks. This list really is Helpful! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] thanks
thanks a lot for responding to my emails , the suggestions that i got from the members were pretty good , i like the suggestion that bhaalu gave me . feeling motivated now . will read the chapter again . god bless us all . ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks
Hello Your code is concise and neat.It will take some time for me to understand how it is doing the job. Thank you >You have a lot of duplicated code. You can reduce the duplication by >using functions and loops. >The first step is to put all the print code into a function rather >than repeating the same three formatting expressions over and over: >def show(x, y): > print '%3d'%(x),'x','%3d'%(y),'=','%3d'%(x*y),(' '*5), >Then mtab() can be written like this: >def mtab(*arg): > for x in range(1,11): show(x, arg[0]) show(x, arg[1]) show(x, arg[2]) print print(('-')*10).center(78) for x in range (1,11): show(x, arg[3]) show(x, arg[4]) show(x, arg[5]) print >Now you can see that the show() statements are still repetitive, they >can be put into a loop: >def mtab(*arg): > for x in range(1,11): for i in range(0, 3): show(x, arg[i]) print print(('-')*10).center(78) for x in range (1,11): for i in range(3, 6): show(x, arg[i]) print >This is OK except the interface is awkward; do you really want to tell >it each number for the table, or would you rather give it a range of >numbers? Also you can use another loop to eliminate the duplicated >printing of the tables: >def mtab(lower, upper): for start in range(lower, upper+1, 3): for x in range(1,11): for y in range(start, start+3): show(x, y) print print(('-')*10).center(78) >mtab(1, 11) >This does not give quite the same result as your original - it prints >the divider after each table - and it always prints three tables per >group, even if you didn't ask for it - but it is much simpler and more >flexible than your original. >Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks (was Random Number Generator)
On Dec 4, 2007 7:21 PM, earlylight publishing <[EMAIL PROTECTED]> wrote: > Thank you everyone for your help! I have no idea why it never occured to me > to Google it. Thanks for the code. Now let's see if I can get this sucker > to work! > 1) Wikipedia <-- learn a basic vocabulary so you can enter keywords into 2) Google <-- Feeling Lucky? If that doesn't work, sort through the other 200K 3) Python Tutorials <-- Get up and going quickly, saving the hard parts for 4) Python Documentation and Books And then there's the Python Tutor list! 8^D Best of luck getting your program working. If you get stuck, show us your code, and error messages, we'll try to help. (It also helps to add system info as well as Python version, etc.) Happy Programming! -- b h a a l u u at g m a i l dot c o m ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks (was Random Number Generator)
Thank you everyone for your help! I have no idea why it never occured to me to Google it. Thanks for the code. Now let's see if I can get this sucker to work! - Looking for last minute shopping deals? Find them fast with Yahoo! Search.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks re: [::-1]
"Charles Cuell" <[EMAIL PROTECTED]> wrote > The one odd thing about Python's slice notation is that the -1 means > to > start from the end and work backwards. My first inclination would > have > been to assume that -1 means to start at i and go to j by steps > of -1 > (only nonempy if j < i). I mentally resolve this by thinking of sequences as being circular. Thus the -1 character is the last one - the one before the first. But that doesn't work for the step size k, you just have to realise that the minus sign there means work backwards and therefore start from the second parameter. However... >>> 'abcdefgh'[3:1:-1] 'dc' >>> 'abcdefgh'[1:3:-1] '' >>> 'abcdefgh'[::-1] 'hgfedcba' It seems that if you do provide values for j,k the first must be bigger than the second to work so Python is being slightly more intelligent about the default values than I initially thought, but the docs do say: If i or j are omitted or None, they become ``end'' values (which end depends on the sign of k). --- How interesting. And thank goodness for the >>> prompt. - the ultimate arbiter and test... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks re: [::-1]
Charles Cuell wrote: > The one odd thing about Python's slice notation is that the -1 means to > start from the end and work backwards. My first inclination would have > been to assume that -1 means to start at i and go to j by steps of -1 > (only nonempy if j < i). A negative step attribute does not change the semantics of the start and stop (read only) attributes of slice objects: >>> m = range(10) >>> m[2:7:-1] [] >>> m[7:2:-1] [7, 6, 5, 4, 3] >>> m[-3:-8:-1] [7, 6, 5, 4, 3] >>> So your first inclination was correct! :) i does go to j by steps of k. -- Sincerely, Chris Calloway http://www.seacoos.org office: 332 Chapman Hall phone: (919) 962-4323 mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks re: [::-1]
Thanks to everybody that worked to clarify the meaning of [::-1]. My main concern was that it looked like the notation came out of nowhere and, as such, was inconsistent with the usual slice notation. The documentation did make it clear, since the full slicing notation is s[i:j:k], leaving out the i and j to indicate starting at the beginning and stopping at the end results in s[::k]. The one odd thing about Python's slice notation is that the -1 means to start from the end and work backwards. My first inclination would have been to assume that -1 means to start at i and go to j by steps of -1 (only nonempy if j < i). Thanks again. Charles Cuell [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks
Hello, I want to thank all you for the all help that you have been lending to me for the past months. My masters thesis is now finished and I have to say that it has been very succesfull. This is something that would have been impossible if not for all the help that you gave to me. I was thinking in mentioning those of you who helped me, but really fear to miss someone, so thanks to all of you who contributed. Thank you very much. This doesnt means that you will get rid of me, I want to get into OO now. :) Cheers, Carlos ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks.....KentRe: ANN: Resources for Python Newbies
Hi folks... Thanks a lot, Kent for this great resource. Remain blessed. Regards, Asrarahmed Kadri On 10/23/06, Kent Johnson <[EMAIL PROTECTED]> wrote: I thought this notice from the python-announce list might be of interesthere.KentSubject: ANN: Resources for Python Newbies - a 30 minute video tour of the web (2New ShowMeDo videos)From:Ian Ozsvald <[EMAIL PROTECTED]>Date:Sun, 22 Oct 2006 16:50:56 +0100 To:[EMAIL PROTECTED], Kyran Dale <[EMAIL PROTECTED]>,[EMAIL PROTECTED] Summary:Ian Ozsvald (joint founder of ShowMeDo.com) introduces all the usualPython on-line resources that a new Python programmer should knowabout. The videos cover the main Python sites, news, books, blogs, community and some of the major projects:http://showmedo.com/videos/series?name=pythonOzsvaldIntroToPyResourcesSeries Detail:Here I give a 30 minute tour of all the main Python resources that aprogrammer should know about. This is the kind of introduction I'dgive to any new Python programmer when they ask me 'what's out there?'. Resources covered include the main Python site, Tutorials, Cheeseshop,ShowMeDo's Python videos, the Cookbook, DiveIntoPython, Daily Python,several new-programmer blogs, comp.lang.python, books (Beginning Python, Python in a Nutshell, Dive Into Python, Cookbook) andfive of the larger Python projects.About ShowMeDo.com:Free videos (we call them ShowMeDos) showing you how to do things.The videos are made by us and our users, for everyone. 38 videos for Python, 71 in total, and the collection is growing.We'd love to have more contributions - would you share what you know?The founders,Ian Ozsvald, Kyran Dale___ Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor -- To HIM you shall return. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] thanks
just a quick note to say thanks to all the replies i got from the community. once again, my idea has already been done, and far better than i could have imagined. i'm off to wander aimlessly around the useless python site ;-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks , Now able to do Marks entry and display it using Histogram
Glad you got it working, now here are some picky comments about style: > # This program is to see how can we see how many > students got particular mark > # And how u print it An introductory comment is good but in Python a common way to do that is to use documentation strings, typically using triple quotes: """This program is to see how can we see how many students got particular mark And how u print it """ Now if you import your module and do print modulename.__doc__ or even help(modulename) Python will print the doc string for you whioch can be useful and saves you opening the file in an editor to read the comments. You can do the same with functions and classes when you get around to using them... > print " \nFirst Enter the No of Students ... " > print "\n Then No of marks " This is kind of redundant since your raw_input promprts tell us what to do each time. > # defining empty array array > array = [] calling something an array is pretty meaningless, it might be better to call it marks or scores or something else that decribes its purpose rather than its structure. One of the design goals of a good programme should be to hide the details of *how* a program is built from the reader and reveal *why* the program is built the way it is.. The same applies to comments. > # defining i > i = 0 So the comment above is pretty much redundant since we can see that we are defining i.The more important question is - what is i for? Its a counter so why not call it that? > # n is the NO of students which I have to enter the > marks > n = int(raw_input("Enter the no: of students : \n")) So why not call it numStudents or similar, then you wouldn't need the comment and the following code will be much more obvious in its meaning. > # m is the Marks of the students which I have to enter m? I see no 'm'. But I do see a 'marks' variable which is self evident. Looks like to anticipated my comment here! :-) Although being really picky I'd probably suggest mark since it only holds one mark at a time... marks implies (to me at least) some kind of collection. > while i < n: >marks = int(raw_input("Enter the Marks for the > students : \n")) >array.append(marks) >print "Marks are ", marks >i = i+1 > > #print "Array Marks ", array > > # Now to display How many students got the same marks > > j = 0 Why introduice a new counter? Just use the previous one. The more names you have in a programme the harder it is to remember what they are all for - especially if they are single letter names. You finished with the counter above so why not just reinitialise it here. > ## > #To Display the histograph of the students Marks > #25 is the Max marks > # > > for j in range(25): >print j,"x" * array.count(j) >j += 1 Not sure why you increment j since the for loop does that for you. BTW. Another approach to this problem would be to use a dictionary. That way you can count the occurences as they are added: """ This program is to see how can we see how many students got particular mark And how u print it """ scores = {} mark = int(raw_input('mark?(-1 to end) ')) while mark != -1: try: scores[mark] += 1 except KeyError: scores[mark] = 1 # first time for this mark mark = int(raw_input('mark?(-1 to end) ')) for key in scores: print key,' x' scores[key] You can tidy that up and avoid the try/except by using the get() method of a dictionary, but I'll leave that as an excercise! Hint: use a default value of zero.:-) HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks , Now able to do Marks entry and display it using Histogram
John Joseph said unto the world upon 03/01/06 02:02 AM: > Hi All > Thanks to Shantanoo,Brian,Alan,Owen > Now I am able to enter the marks for each > students , and display the results the frequency of > marks in histogram > Even though I am able to display the > histogram of the marks with students , I would like > to modify it further as I learn more , I am adding the > program which I had done >Thanks to the list , I am getting more > encouragement here ,it is fun over here > Thanks >Joseph John Joseph, great :-) It is a friendly place to learn. I have a suggestion about one way you might take your efforts to improve things. > ## > #To Display the histograph of the students Marks > #25 is the Max marks > # > > for j in range(25): > #print j , "is ",array.count(j) > print j,"x" * array.count(j) > j += 1 Hard-coded magic numbers like 25 here are something it often pays to eliminate. If you know that every test or assignment for the entire future of time is out of 25, then it is fine. But, you can plan for the future and be more general by trying to accommodate varying point totals. If you try that and get stuck, post about it. Good luck with however you choose to improve your approach. Best, Brian vdB ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks , Now able to do Marks entry and display it using Histogram
Hi All Thanks to Shantanoo,Brian,Alan,Owen Now I am able to enter the marks for each students , and display the results the frequency of marks in histogram Even though I am able to display the histogram of the marks with students , I would like to modify it further as I learn more , I am adding the program which I had done Thanks to the list , I am getting more encouragement here ,it is fun over here Thanks Joseph John *** # This program is to see how can we see how many students got particular mark # And how u print it print " \nFirst Enter the No of Students ... " print "\n Then No of marks " # defining empty array array array = [] # defining i i = 0 # n is the NO of students which I have to enter the marks n = int(raw_input("Enter the no: of students : \n")) # m is the Marks of the students which I have to enter while i < n: marks = int(raw_input("Enter the Marks for the students : \n")) array.append(marks) print "Marks are ", marks i = i+1 #print "Array Marks ", array # Now to display How many students got the same marks j = 0 ## #To Display the histograph of the students Marks #25 is the Max marks # for j in range(25): #print j , "is ",array.count(j) print j,"x" * array.count(j) j += 1 ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks for the Help on the Quick Question
Kent and Todd, Thanks for the help on my quick question regarding readlines. That helped a lot. - Steve ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks, you prevented "Coder's Remorse"
Thanks to everyone who responded to my "Prevent Coder's Remorse" posting; the result of combining the ideas that you contributed is below. It's a little long, but I'm delighted with it so far, and maybe someone else can use it. It's nice for representing a sparse table, where all the records share columns, but a lot of the values in any given column are the same. Geographic points (my original question) are just a special case. One example is a table where the Null value isn't predefined but is represented by a 'magic value' that means null in that table. I realize now that I might have been better off just to use a database; they know all about nulls, tables. types, defaults, etc. Still, I learned a LOT. So, no remorse! Thanks again, Ron #magicvaluetable.py ### # -*- coding: utf-8 -*- #may use a guid to keep things straight import guid # Make it work with Python 2.3 try: set except NameError: from sets import Set as set class MVTRecord(dict): """A record belonging to a magic value table (MVTable). Requires a parent MVTable and an id assigned by it. Other attributes (column values) may be assigned. Attributes not specifically assigned at the record level are deferred to the parent MVTable's attDict.""" def __init__(self,mvtParent,id,**args): dict.__init__(self) self.mvtParent = mvtParent self.id = id for arg in args: self[arg]=args[arg] def __getitem__(self, key): if key in self.keys(): return dict.__getitem__(self, key) else: return self.mvtParent.attDict[key] raise KeyError,'Key "%s" was not found in MVTRecord or MVTable'%key def __setitem__(self, key, value): (nullValue,valueType)=self.__testType(value) if key not in self.mvtParent.attDict.keys(): self.mvtParent.addAttribute(key,nullValue) (whoCares,columnType)=self.__testType(self.mvtParent.attDict[key]) # make sure what's set is proper type or can degrade to proper type if valueType == columnType: dict.__setitem__(self, key, value) else: if columnType == 'float'and valueType=='int': dict.__setitem__(self, key, float(value)) elif columnType == 'string': dict.__setitem__(self, key, str(value)) else: msg = 'The %s attribute requires %s data'%(key, columnType) raise ValueError,msg def __delitem__(self, key): if key in self.keys(): dict.__delitem__(self, key) elif key in self.mvtParent.attDict.keys(): pass else: raise KeyError,'Key "%s" was not found in MVTRecord or MVTable'%key def __testType(self, value): try: if str(value)==str(int(value)): test = (self.mvtParent.nullInt,'int') else: test = (self.mvtParent.nullFloat,'float') except ValueError: test=(self.mvtParent.nullString,'string') return test class MVTable(object): """Defines a group of records (MVTRecord) with common columns. Attributes (record values in a given column) which are not specified at the record level are deferred to the MVTable attDict. Note: the nullInt, nullFloat, and nullString are designed to hold 'magic values' for use with data structures(CSV, DBF) having no defined 'null'.""" def __init__(self, nullInt=0, nullFloat=0.0, nullString='null'): self.nullInt=nullInt self.nullFloat = nullFloat self.nullString = nullString self.attDict = {} self.membersDict = {} def addMember(self,id=None,**args): if not id: id = guid.generate() self.membersDict[id]=MVTRecord(self,id=id,**args) return self.membersDict[id] def delMember(self,member): del self.membersDict[member.id] def addAttribute(self, name, nullValue=None): if nullValue == None:nullValue=self.nullString self.attDict[name]=nullValue def delAttribute(self, name): for member in self.membersDict: if member.has_key(name):del member[name] del self.attDict[name] def compactAttributesDictionary(self): """removes unreferenced attributes""" newkeys = set() for member in self.membersDict: for key in self.membersDict[member].keys(): newkeys.add(key) for key in self.attDict.keys(): if key not in newkeys: del self.attDict[key] if __name__ == "__main__": mvt = MVTable() me=mvt.addMember() he=mvt.addMember(third=3, fourth=4) mvt.addAttribute('first', 5) #print basic functionality outputs for column in mvt.attDict: print 'Column:%s, me:%s, he:%s'%(column,me[column],he[column]) ##
[Tutor] thanks!
Hi, everyone. Just a note of thanks to all of you who participate on the tutor list. I recently finished my first python CGI program, but I didn't have to post a lot of questions because most had been asked and answered already : >) For example, I wondered how to get unique file names for dynamic creation of web pages (answer: tempfile module). Keep up the great work. Thanks again, Don ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks
Wow! Congratulations! I wish I had 1/10 your success in converting Java diehards. Kent Servando Garcia wrote: > My thanks to the list. With your help each day I convert another C++ > die hard to python. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks
My thanks to the list. With your help each day I convert another C++ die hard to python. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks to all!
I am going to try and tackle the file I/O exercise in Non-Programmers Tutorial For Python found at http://www.honors.montana.edu/~jjc/easytyt/easytut/easytut.html. Should be a fun task. - Original Message - From: <[EMAIL PROTECTED]> To: Sent: Sunday, July 31, 2005 4:32 PM Subject: Re: [Tutor] Thanks to all! > > Congratulations! So what are you going to try next? > > --Todd > > On Sunday 31 July 2005 06:27 pm, Nathan Pinno wrote: >> The Giant Calculator is perfect also! >> - Original Message - >> From: Nathan Pinno >> To: tutor@python.org >> Sent: Sunday, July 31, 2005 3:34 PM >> Subject: [Tutor] Thanks to all! >> >> >> Thank you to all. All my calculators run perfect. I can now make a >> perfect Giant Calculator as well. >> >> Thanks again, >> Nathan >> >> >> --- >>--- >> >> >> ___ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks to all!
Congratulations! So what are you going to try next? --Todd On Sunday 31 July 2005 06:27 pm, Nathan Pinno wrote: > The Giant Calculator is perfect also! > - Original Message - > From: Nathan Pinno > To: tutor@python.org > Sent: Sunday, July 31, 2005 3:34 PM > Subject: [Tutor] Thanks to all! > > > Thank you to all. All my calculators run perfect. I can now make a > perfect Giant Calculator as well. > > Thanks again, > Nathan > > > --- >--- > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks to all!
The Giant Calculator is perfect also! - Original Message - From: Nathan Pinno To: tutor@python.org Sent: Sunday, July 31, 2005 3:34 PM Subject: [Tutor] Thanks to all! Thank you to all. All my calculators run perfect. I can now make a perfect Giant Calculator as well. Thanks again, Nathan ___Tutor maillist - Tutor@python.orghttp://mail.pythonorg/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks to all!
Thank you to all. All my calculators run perfect. I can now make a perfect Giant Calculator as well. Thanks again, Nathan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks.
Thanks all for helping me. Thanks to the group, I have figured out a way to make Giant Calculator and any program repeat until the user wants to exit. Thanks again, Nathan Pinno ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks for Regex help
Thanks to Matt, Kent and Danny for helping me with my regex question. I will try your suggestions this morning. In response to Danny's question about tokenising first, there are reasons why I don't want to do this - the initial problem was that filenames in my test data were being tokenised as separate words. EG. DataMarchAccounts.txt would be tokenised as two words, neither of which are real words that can be found in an English dictionary. (Often, filenames are not proper words, which is why I needed to delete the whole string - and by 'string' I mean any consecutive string of non-whitespace characters.) Because I don't want to subsequently analyse any 'non-words', only real words that will then be automatically checked against a lexicon. Well - my code is all done now, apart from the tweaking of this one RE. BTW - I am new to Python and had never done any programming before that, so you may see some more questions from me in the future... Cheers again, Debbie -- *** Debbie Elliott Computer Vision and Language Research Group, School of Computing, University of Leeds, Leeds LS2 9JT United Kingdom. Tel: 0113 3437288 Email: [EMAIL PROTECTED] *** ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor