[Tutor] Python And reading the Web - Javascript
Was hoping some could push me in the right direction about reading data from web pages and what modules to use. Is there support for reading if the page uses javascript? If you know any good links to tutorials for this it would be great. I was planning to use python 2.6 currently. I want to read some data from the web it will be text and numeric i was planning to export it to a database. I was thinking while I am learning maybe something simple like Sqlite or MySQL. I then want to read back data to perform sorting and some calculations on. Any ideas in general in how to do this appreciated. i don't mind reading so if you have some good links they are appreciated. Thank You Sayth ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] input and raw input
Hi, any one have an idea about how we can input many number in the one time and change it to list. for example: a=input("Enter the number of your class in the school:") # the number can be enter as: 12,13,14 or 12 13 14 with a space in between. now how I can put these numbers into list like b=[12,13,14] with len( a ) =3 I tried with that but it's working only for a numbers less than 10 ex. 1,2,3 or 1 2 3 but it's not when I go for numbers higher than 10 like in example above. a=raw_input("Enter the number of your class in the school:") m=[] for I range (len( a)): if a[I]==',': pass elif a[I]==' ': pass else: m.append(a[I]) m=map(float,m) print m;print len( m ) >> [1,2,3] >> 3 looking forward to seeing your help, regards, Ahmed ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Plotting a Linear Equation
It sounds to me like you need to set a nonzero linewidth. The default is to not fill in the space between points. Check out the documentation at http://matplotlib.sourceforge.net/contents.html. It's a lot to wade through, but worth it when you learn how to unlock the power of the software. Cheers On Thursday 23 September 2010, Corey Richardson wrote: > Hello tutors. Probably the wrong mailing list, but someone might know. > I want to use matplotlib (or similar) to plot an equation in > slope-intercept (y=mx+b) or standard form (Ax + By = C). As far as I've > read and tested, you can only plot with a series of points. I could make > two points out of those manually, but I was wondering if anyone knew of > an easier way. Thanks. > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting pixels
On 10-09-18 07:39 PM, ALAN GAULD wrote: > It appears that the Tk canvas widget does not support simply plotting a pixel. Correct, and I agree it seems odd, but in practice drawing either lines or ovals of one-pixel do the equivalent job - albeit a little more slowly. > The primitive obviously exists in the underlying code, It probably exists in the native graphics toolkit (Xlib or Win32 or Aqua) but it doesn't exist at the Tk level which is why Tkinter can't expose it. FWIW wxPython does provide a DrawPoint() method as part of its DeviceContext class. Digging a little deeper it seems the idiomatic way to do this in Python is to use PIL the Python Imaging Library to create a GIF or bitmap image and then insert that into Tkinters cancvas as an image object. The Pil ImageDraw class has a point() ethod I've never tried this but it is described in Grayson's (now out of print?) book on Tkinter where he uses it to draw a Mandelbrot The book may be available online these days... Nowdownloadall.com seems to have it although I've no idea of the legality of it! HTH, Alan G. Here's a link, just don't download everything. It would be excessively large. http://isohunt.com/download/212380933/%22Python+and+Tkinter+Programming%22.torrent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python And reading the Web - Javascript
Any ideas in general in how to do this appreciated. i don't mind reading so if you have some good links they are appreciated. I have no experience myself with this task, but I would look at those resource: 1) For reading html pages in addition to the standard-lib modules: http://www.crummy.com/software/BeautifulSoup/ 2) For more advanced stuff it might be worth looking at a webkit implementation of Qt via PyQt Bindings: http://doc.trolltech.com/4.7/qtwebkit.html here the Python bindings http://www.riverbankcomputing.co.uk/news HTH, Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] input and raw input
> any one have an idea about how we can input many number in the one time and > change it to list. > for example: > > a=input("Enter the number of your class in the school:") # the number can > be enter as: 12,13,14 or 12 13 14 with a space in between. > > now how I can put these numbers into list like b=[12,13,14] with len( a ) =3 A string has a method split(); that may help you. In your case, where you want either a space or a comma as a separator, it depends whether both can be used at the same time. If not, you can check for the occurrence of one or the other separator and run split() with the correct separator. If both can occur in the same line, you may want to use the regex module instead: re.split() hth, Evert > I tried with that but it's working only for a numbers less than 10 ex. 1,2,3 > or 1 2 3 but it's not when I go for numbers higher than 10 like in example > above. > > a=raw_input("Enter the number of your class in the school:") > m=[] > for I range (len( a)): > if a[I]==',': > pass > elif a[I]==' ': > pass > else: > m.append(a[I]) > m=map(float,m) > print m;print len( m ) > >> [1,2,3] > >> 3 > > looking forward to seeing your help, > regards, > Ahmed > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 79, Issue 134
I started seting up django. the only issue I am having is that all instructions seem to assume that I am on linux.Don't suppose there are any good instructions for those on a windows based system. On Sat, Sep 25, 2010 at 8:00 PM, wrote: > Send Tutor mailing list submissions to >tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit >http://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: pure function problem (Dave Angel) > 2. Re: pure function problem (Roelof Wobben) > 3. Re: Plotting a Linear Equation (kb1...@aim.com) > 4. Re: list.append(x) but at a specific 'i' (Norman Khine) > 5. Python And reading the Web - Javascript (Sayth Renshaw) > > > -- > > Message: 1 > Date: Fri, 24 Sep 2010 06:29:03 -0400 > From: Dave Angel > To: Roelof Wobben > Cc: tutor@python.org > Subject: Re: [Tutor] pure function problem > Message-ID: <4c9c7d6f.5080...@ieee.org> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 2:59 PM, Roelof Wobben wrote: > > > > > > > >> From: st...@pearwood.info > >> > >> On Fri, 24 Sep 2010 06:20:25 am Roelof Wobben wrote: > >> > >>> time =ijd() > >> [...] > >>> print time(uitkomst) > >> Why are you calling time as a function, when it is a tijd instance? > >> > >> > > > > Hello Steve, > > > > I found this in my tutorial. > > > > 13.8. Instances as return values? > > Functions can return instances. For example, find_center takes a > Rectangle as an argument and returns a Point that contains the coordinates > of the center of the Rectangle: > > def find_center(box): > > p =oint() > > p.x =ox.corner.x + box.width/2.0 > > p.y =ox.corner.y - box.height/2.0 > > return p > > To call this function, pass box as an argument and assign the result to a > variable: > center =ind_center(box) > print_point(center) > > (50.0, 100.0) > > > > > > So i followed it but appearently not the good way. > > > > Roelof > There's a big difference between print_point() and print time(). > > print_point() in your tutorial is a function, presumably defined > someplace else. > > You used print time(), (no underscore), which uses the print statement, > and tries to call a function called time(). > > Since you defined time as an instance of your class, and didn't do > anything special, it's not callable. > > DaveA > > > > -- > > Message: 2 > Date: Fri, 24 Sep 2010 10:40:46 + > From: Roelof Wobben > Cc: > Subject: Re: [Tutor] pure function problem > Message-ID: > Content-Type: text/plain; charset="iso-8859-1" > > > > > > > Date: Fri, 24 Sep 2010 06:29:03 -0400 > > From: da...@ieee.org > > To: rwob...@hotmail.com > > CC: tutor@python.org > > Subject: Re: [Tutor] pure function problem > > > > On 2:59 PM, Roelof Wobben wrote: > >> > >> > >> > >>> From: st...@pearwood.info > >>> > >>> On Fri, 24 Sep 2010 06:20:25 am Roelof Wobben wrote: > >>> > time =ijd() > >>> [...] > print time(uitkomst) > >>> Why are you calling time as a function, when it is a tijd instance? > >>> > >>> > >> > >> Hello Steve, > >> > >> I found this in my tutorial. > >> > >> 13.8. Instances as return values? > >> Functions can return instances. For example, find_center takes a > Rectangle as an argument and returns a Point that contains the coordinates > of the center of the Rectangle: > >> def find_center(box): > >> p =oint() > >> p.x =ox.corner.x + box.width/2.0 > >> p.y =ox.corner.y - box.height/2.0 > >> return p > >> To call this function, pass box as an argument and assign the result to > a variable: > > center =ind_center(box) > > print_point(center) > >> (50.0, 100.0) > >> > >> > >> So i followed it but appearently not the good way. > >> > >> Roelof > > There's a big difference between print_point() and print time(). > > > > print_point() in your tutorial is a function, presumably defined > > someplace else. > > > > You used print time(), (no underscore), which uses the print statement, > > and tries to call a function called time(). > > > > Since you defined time as an instance of your class, and didn't do > > anything special, it's not callable. > > > > DaveA > > > > Oke, > > I see it now. > I have to us a function that i had to write a few questions before. > > Thanks everybody > > Roelof > > > > -- > > Message: 3 > Date: Fri, 24 Sep 2010 12:26:31 -0400 (EDT) > From: kb1...@aim.com > To: tutor@python.org > Subject: Re: [Tutor] Plotting a Linear Equation > Message-ID: <8
Re: [Tutor] Tutor Digest, Vol 79, Issue 134
> I started seting up django. the only issue I am having is that all > instructions seem to assume that I am on linux.Don't suppose there are any > good instructions for those on a windows based system. Firstly: please don't reply to an unrelated message, but start a new one (with a proper subject line). Especially a reply to a digest message contains a lot of unrelated info. Secondly: there is a Django mailing list, which may be more helpful than a generic Python tutoring list. That said: what's wrong with the Django installation notes: I see mentions of Windows there, not just Linux; does that not work? http://docs.djangoproject.com/en/1.2/topics/install/ Googling 'django windows install' also works. Eg, http://www.instantdjango.com/ Cheers, Evert ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] input and raw input
On Sat, Sep 25, 2010 at 9:40 AM, Evert Rol wrote: > > any one have an idea about how we can input many number in the one time > and change it to list. > > for example: > > > > a=input("Enter the number of your class in the school:") # the number > can be enter as: 12,13,14 or 12 13 14 with a space in between. > > > > now how I can put these numbers into list like b=[12,13,14] with len( a ) > =3 > > A string has a method split(); that may help you. > In your case, where you want either a space or a comma as a separator, it > depends whether both can be used at the same time. If not, you can check for > the occurrence of one or the other separator and run split() with the > correct separator. If both can occur in the same line, you may want to use > the regex module instead: re.split() > No need for the 're' module. Even in the case where both can be used together, you can still just use string methods: >>> s '12, 13 14' >>> s.replace(',', '').split(' ') ['12', '13', '14'] > hth, > > Evert > > > > I tried with that but it's working only for a numbers less than 10 ex. > 1,2,3 or 1 2 3 but it's not when I go for numbers higher than 10 like in > example above. > > > > a=raw_input("Enter the number of your class in the school:") > > m=[] > > for I range (len( a)): > > if a[I]==',': > > pass > > elif a[I]==' ': > > pass > > else: > > m.append(a[I]) > > m=map(float,m) > > print m;print len( m ) > > >> [1,2,3] > > >> 3 > > > > looking forward to seeing your help, > > regards, > > Ahmed > > > > > > > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > http://mail.python.org/mailman/listinfo/tutor > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] input and raw input
> > any one have an idea about how we can input many number in the one time and > > change it to list. > > for example: > > > > a=input("Enter the number of your class in the school:") # the number > > can be enter as: 12,13,14 or 12 13 14 with a space in between. > > > > now how I can put these numbers into list like b=[12,13,14] with len( a ) =3 > > A string has a method split(); that may help you. > In your case, where you want either a space or a comma as a separator, it > depends whether both can be used at the same time. If not, you can check for > the occurrence of one or the other separator and run split() with the correct > separator. If both can occur in the same line, you may want to use the regex > module instead: re.split() > > No need for the 're' module. Even in the case where both can be used > together, you can still just use string methods: > > >>> s > '12, 13 14' > >>> s.replace(',', '').split(' ') > ['12', '13', '14'] Good point. To be finicky, you'll probably want to replace ',' by ' ' and let split work on whitespace instead of a single space. In case of tabs or a 12,13,14 input. > > I tried with that but it's working only for a numbers less than 10 ex. > > 1,2,3 or 1 2 3 but it's not when I go for numbers higher than 10 like in > > example above. > > > > a=raw_input("Enter the number of your class in the school:") > > m=[] > > for I range (len( a)): > > if a[I]==',': > > pass > > elif a[I]==' ': > > pass > > else: > > m.append(a[I]) > > m=map(float,m) > > print m;print len( m ) > > >> [1,2,3] > > >> 3 > > > > looking forward to seeing your help, > > regards, > > Ahmed > > > > > > > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > http://mail.python.org/mailman/listinfo/tutor > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > > > -- > Brian K. Jones > My Blog http://www.protocolostomy.com > Follow me http://twitter.com/bkjones ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] input and raw input
Brian Jones wrote: > No need for the 're' module. Even in the case where both can be used > together, you can still just use string methods: > s > '12, 13 14' s.replace(',', '').split(' ') > ['12', '13', '14'] I think to replace "," with " " and then split() without explicit separator is slightly more robust. Compare: >>> s = "12,34, 56 789" >>> s.replace(",", " ").split() ['12', '34', '56', '789'] >>> s.replace(",", "").split(" ") ['1234', '56', '', '789'] Peter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] class method problem
Hello, I have this code: class zoeken() : pass def __len__(self): return 0 def __str__(self): return test2 def find(self, strng, ch, start, stop): index = start while index < len(strng) and index < stop: if strng[index] == ch: return index index += 1 return -1 test = zoeken() test.woord = "tamara" test2 = zoeken.find(test, "a", 1,5) print test(test2) But now I get this message : Traceback (most recent call last): File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20, in test2 = zoeken.find(test, "a", 1,5) TypeError: find() takes exactly 5 arguments (4 given) I can do zoeken.find (test2,test, "a", 1,5) but then I get this message: Traceback (most recent call last): File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20, in zoeken.find( test2, test, "a", 1,5) NameError: name 'test2' is not defined Roelof ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] class method problem
Hello, Still the same errors Roelof > >> Date: Sat, 25 Sep 2010 19:33:52 +0100 >> Subject: Re: [Tutor] class method problem >> From: andre...@gmail.com >> To: rwob...@hotmail.com >> >> Your method receives 4 arguments and you didn't define one default. >> Try to do something like this: >> >> def find(self, strng=None, ch=None, start=None, stop=None): >> >> Or any other default values that matches your needs. >> >> >> >> On 25 September 2010 19:15, Roelof Wobben wrote: >>> >>> >>> Hello, >>> >>> I have this code: >>> >>> class zoeken() : >>> á ápass >>> á ádef __len__(self): >>> á á á áreturn 0 >>> á ádef __str__(self): >>> á á á áreturn test2 >>> á ádef find(self, strng, ch, start, stop): >>> á á á áindex = start >>> á á á áwhile index < len(strng) and index < stop: >>> á á á á á áif strng[index] == ch: >>> á á á á á á á áreturn index >>> á á á á á áindex += 1 >>> á á á á á áreturn -1 >>> >>> >>> test = zoeken() >>> test.woord = "tamara" >>> test2 = zoeken.find(test, "a", 1,5) >>> print test(test2) >>> >>> But now I get this message : >>> >>> Traceback (most recent call last): >>> áFile "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20, in >>> á átest2 = zoeken.find(test, "a", 1,5) >>> TypeError: find() takes exactly 5 arguments (4 given) >>> >>> I can do zoeken.find (test2,test, "a", 1,5) but then I get this message: >>> >>> Traceback (most recent call last): >>> áFile "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20, in >>> á ázoeken.find( test2, test, "a", 1,5) >>> NameError: name 'test2' is not defined >>> >>> >>> Roelof >>> >>> ___ >>> Tutor maillist á- átu...@python.org >>> To unsubscribe or change subscription options: >>> http://mail.python.org/mailman/listinfo/tutor >>> >> >> >> >> -- >> Andreh Palma ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] class method problem
This returns a if "a" in, or -1 if using "z": class zoeken() : pass def __len__(self): return 0 def __str__(self): return test2 def find(self, strng, ch, start, stop): index = start while index < len(strng) and index < stop: if strng[index] == ch: return ch index += 1 return -1 test = zoeken() test.woord = "tamara" stop = len(test.woord) test2 = test.find(test.woord, "a", 1,stop) print test2 David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] class method problem
This is a little better, it returns a if "a" in, or None if using "z": class zoeken() : pass def __len__(self): return 0 def __str__(self): return test2 def find(self, strng, ch, start, stop): index = start while index < len(strng) and index < stop: if strng[index] == ch: return ch index += 1 test = zoeken() test.woord = raw_input('Enter string of letters to search: ' ) stop = len(test.woord) search = raw_input('Enter character to find: ') #print 'search =' ,search test2 = test.find(test.woord, search, 1,stop) print test2 Of course, there are other ways to accomplish this. David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] class method problem
Since I had nothing else to do, but practice, this looks much better: def find(word, search): if search in word: print True else: print False word = raw_input('Enter string of letters to search: ' ) search = raw_input('Enter character to find: ') find(word,search) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] class method problem
On Sun, 26 Sep 2010 04:15:03 am Roelof Wobben wrote: > Hello, > > I have this code: > > class zoeken() : It is traditional to name classes with an initial capital letter, so Zoeken would be better. > pass What is the point of the "pass" statement there? That does nothing. Why did you put that there? > def __len__(self): > return 0 > def __str__(self): > return test2 What is test2? It doesn't exist. > def find(self, strng, ch, start, stop): Count the arguments: 5, including self. Remember that number. This is important later on. > index = start > while index < len(strng) and index < stop: > if strng[index] == ch: > return index > index += 1 > return -1 Watch the indentation. The "return -1" is *inside* the loop. > test = zoeken() > test.woord = "tamara" > test2 = zoeken.find(test, "a", 1,5) > print test(test2) > > But now I get this message : > > Traceback (most recent call last): > File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20, > in test2 = zoeken.find(test, "a", 1,5) > TypeError: find() takes exactly 5 arguments (4 given) Right. READ THE ERROR, don't just immediately cry for help. Being a programmer means you must have ATTENTION TO DETAIL -- the error tells you *exactly* what the problem is: the find() method takes five arguments, *including* self. You have only given four arguments: find method expects: 1: self 2: strng 3: ch 4: start 5: stop find method actually gets 1: test 2: "a" 3: 1 4: 5 5: ?? > I can do zoeken.find (test2,test, "a", 1,5) but then I get this > message: > > Traceback (most recent call last): > File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20, > in zoeken.find( test2, test, "a", 1,5) > NameError: name 'test2' is not defined Exactly. That's because test2 does not exist. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] class method problem
On Sun, 26 Sep 2010 08:13:23 am David Hutto wrote: > Since I had nothing else to do, but practice, this looks much better: > > def find(word, search): > if search in word: > print True > else: > print False For some definition of "better". If I called a function: find("anti-disestablishmentarianism", "lish") and got back an answer: True I'd feel ripped off and cheated. That would be like going to Google, typing in something into the search box, and Google comes back with: Yes, we found your terms on the Internet, but we won't tell you where. If you would like to find something else, we won't tell you where that is either. Aside from the name of the function, which is deceptive because it doesn't describe what the function does, the names of the arguments are also poor. The first argument is not necessarily a word. Nor is there any need for it to be -- it can be any text. The second argument is poorly described as "search" -- search is a verb. A better function signature might be: def search(text, target): # Search for target in text and print whether it is found or not. Even this is slightly misleading, because "text" doesn't need to be an actual string. It could be any sequence, such as a list. But this gives the *intention* of the function, which is to do text searches. So this is (in my opinion) an acceptable compromise between intention and generality. Now on to the code itself. The body of the function is needlessly verbose. You say: if search in word: print True else: print False This is so simple we can trace the entire function by hand. Say we call search("I like spam and eggs", "spam"): (1) target in text? => True (2) take the if branch (3) print True Now say we call find("I like spam and eggs", "cheese"): (1) target in text? => False (2) take the else branch (3) print False Can you see the common factor? The object which is printed is always precisely the same object generated by the `in` test. So we can simplify the body of the function: def search(text, target): print target in text But this is so simple, there's no point to wrapping it in a function! Small functions that do one thing are good, up to a point, but when the function is so small that it is just as easy to include the body in the caller code, the function is pointless. It's not like "search(b, a)" is easier to write or remember than "print a in b" -- if anything the opposite is the case, because I would never remember which order to pass the arguments. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to start IPython in Windows
(I posted this to the ipython-user list 11 hours ago, with no response -- too dumb a question?) 64-bit Vista. I've downloaded "A binary Windows installer (an executable setup file)" from http://ipython.scipy.org/moin/Download , and run it. IPython is now installed in my Python26/Lib/site-packages folder. I also installed win64-unicode version of wxPython. I also have winconsole.py. Sorry for the dumb question, but how do I start IPython? Dick Moores ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to start IPython in Windows
IIRC, it's like idle, just run: python C:\\Python\\Scripts\\ipython.py ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] class method problem
On Sat, Sep 25, 2010 at 9:16 PM, Steven D'Aprano wrote: > On Sun, 26 Sep 2010 08:13:23 am David Hutto wrote: >> Since I had nothing else to do, but practice, this looks much better: >> >> def find(word, search): >> if search in word: >> print True >> else: >> print False > > > For some definition of "better". > > If I called a function: > > find("anti-disestablishmentarianism", "lish") > > and got back an answer: > > True > > I'd feel ripped off and cheated. That would be like going to Google, > typing in something into the search box, and Google comes back with: OP wanted to find if a in b. Does my function do that?...Yep > > Yes, we found your terms on the Internet, but we won't tell you > where. If you would like to find something else, we won't tell > you where that is either. It's not supposed to be a four line version of Google. > > Aside from the name of the function, which is deceptive because it > doesn't describe what the function does, the names of the arguments are > also poor. The first argument is not necessarily a word. Badly named yes, but I know it just finds a string in a string Nor is there > any need for it to be -- it can be any text. The second argument is > poorly described as "search" -- search is a verb. > > A better function signature might be: > > def search(text, target): > # Search for target in text and print whether it is found or not. > > Even this is slightly misleading, because "text" doesn't need to be an > actual string. It could be any sequence, such as a list. But this gives > the *intention* of the function, which is to do text searches. So this > is (in my opinion) an acceptable compromise between intention and > generality. Semantics, are only important to those who didn't write it. > > Now on to the code itself. The body of the function is needlessly > verbose. You say: > > if search in word: > print True > else: > print False > > This is so simple we can trace the entire function by hand. Say we call > search("I like spam and eggs", "spam"): > > (1) target in text? => True > (2) take the if branch > (3) print True > > Now say we call find("I like spam and eggs", "cheese"): > > (1) target in text? => False > (2) take the else branch > (3) print False > > Can you see the common factor? The object which is printed is always > precisely the same object generated by the `in` test. So we can > simplify the body of the function: > > def search(text, target): > print target in text > > > But this is so simple, there's no point to wrapping it in a function! > > Small functions that do one thing are good, up to a point, but when the > function is so small that it is just as easy to include the body in the > caller code, the function is pointless. It's not like "search(b, a)" is > easier to write or remember than "print a in b" -- if anything the > opposite is the case, because I would never remember which order to > pass the arguments. The reason I put it in a function, was the same reason the OP put it in a class, to eventually expand on the initial program being created.(also I had it in a snippets file, accompanied by an instance for it, a way to conveniently call it later if needed) I do know I could have shortened it further, I'm not all omniscient like yourself. Breath deeply, and remember it's someone elses code who hasn't had the same experience writing code that you have. But thanks for pointing it out, I'll know to eliminate the excess in the future, knowing that the all seeing steven is watching my every function. > > > > -- > Steven D'Aprano > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to start IPython in Windows
On Sat, Sep 25, 2010 at 21:12, David Hutto wrote: > IIRC, it's like idle, just run: > python C:\\Python\\Scripts\\ipython.py Yes! Thank you! Here what that got me: = C:\Python26\Scripts>ipython ** Welcome to IPython. I will try to create a personal configuration directory where you can customize many aspects of IPython's functionality in: C:\Users\Dick\_ipython Initializing from configuration: C:\Python26\lib\site-packages\IPython\UserConfig Successful installation! Please read the sections 'Initial Configuration' and 'Quick Tips' in the IPython manual (there are both HTML and PDF versions supplied with the distribution) to make sure that your system environment is properly configured to take advantage of IPython's features. Important note: the configuration system has changed! The old system is still in place, but its setting may be partly overridden by the settings in "~/.ipython/ipy_user_conf.py" config file. Please take a look at the file if some of the new settings bother you. Please press to start IPython. ** Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] Type "copyright", "credits" or "license" for more information. IPython 0.10 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: == Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor