Re: [Tutor] why does this fail
Hello Alan, Oops, then I have a problem. Im following this book : http://openbookproject.net/thinkcs/python/english2e/ which is the first link in the beginners tutorial page. And it's talking about the string modules. Roelof Date: Wed, 25 Aug 2010 15:49:14 -0700 From: alan.ga...@btinternet.com Subject: Re: [Tutor] why does this fail To: rwob...@hotmail.com Thats OK, I only replied because what you said could genuinely have been a mistake because some old tutorials still refer to the string module amnd its functions. Because other begineers may read the post too it was important to make the distinction. Regards, Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ From: Roelof Wobben rwob...@hotmail.com To: alan.ga...@btinternet.com Sent: Wednesday, 25 August, 2010 19:38:03 Subject: RE: [Tutor] why does this fail Oke, That's what I ment. Apolize for the bad English. It's not the language I often use. Roelof To: tutor@python.org From: alan.ga...@btinternet.com Date: Wed, 25 Aug 2010 19:32:59 +0100 Subject: Re: [Tutor] why does this fail Roelof Wobben rwob...@hotmail.com wrote It's for learning purposed but I forget that de module string has built in functions.Thank you for remainding it to me. Its not the string module that Christian is referring to, its the methods of string objects - different things: You can do: import string string.replace(aString, aChr, another) # use string module But its better to do aString.replace(aChr, another) # use string method HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ 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
[Tutor] (no subject)
Hello, I have this exercise : Try each of the following formatted string operations in a Python shell and record the results: “%s %d %f” % (5, 5, 5) “%-.2f” % 3 “%-10.2f%-10.2f” % (7, 1.0/2) print ” $%5.2fn $%5.2fn $%5.2f” % (3, 4.5, 11.2) But if I try in a python 2.7 IDLE enviroment I get this : %s %d %f % (5, 5, 5) SyntaxError: invalid syntax print “%s %d %f” % (5, 5, 5) SyntaxError: invalid syntax Roelof ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] What Design Pattern for Document class (NOT URGENT)
Hello All, I want to build some classes by optimizing their design. But I want to keep quite 'simples'. I have a XML document which represents let's say some rules (id, description, value). My first idea is to create an *docrules* class which holds my document. This class will use 2 other instances from 2 respectives classes reader and writer. The main method of reader is get(). The main method of writer is write(). To resume I have: -- --- - docrules --- reader - -- --- - filename - - file - - --- - - - get() - - ------ -- - - - ---writer- - file - - write() - The *docrules* will do the parsing (*xml.etree* very effective) and create the reader and the writer instance. I want to create 2 others classes (or more) more specific which have more the knowledge about the XML documents structures. *SpecificRuleReader*, *SpecificRuleWriter* which are deriving resp. from Reader and Writer which hold resp. *getSpecificRules*() (use of get('/tag1/tag2/tag3/specificTagRules') and a* writeSpecificRules*(): - - reader writer - - ^ ^ || --- --- *SpecificRuleReader* *SpecificRulesWriter* --- --- *getSpecificRules*() *writeSpecificRules()* -- My purpose is to separate as far as possible XML representation from core classes. I will have certainly more SpecificrulesReader/Writer classes becauses the document is huge and several discipline rules will be adressed. I don't want necessarily have 2 big classes which know everything about XML document because I will have too many methods. So, for if anybody has this kind of experience or any design pattern idea, I will be enchanté. Regards Karim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Hi Roelof, The problem is in quotation marks. Please use plain double instead of curly quotes. (That's a common issue when you copy-paste the code from pdf/doc) On Thu, Aug 26, 2010 at 9:25 AM, Roelof Wobben rwob...@hotmail.com wrote: Hello, I have this exercise : Try each of the following formatted string operations in a Python shell and record the results: “%s %d %f” % (5, 5, 5) “%-.2f” % 3 “%-10.2f%-10.2f” % (7, 1.0/2) print ” $%5.2fn $%5.2fn $%5.2f” % (3, 4.5, 11.2) But if I try in a python 2.7 IDLE enviroment I get this : %s %d %f % (5, 5, 5) SyntaxError: invalid syntax print “%s %d %f” % (5, 5, 5) SyntaxError: invalid syntax Roelof ___ Tutor maillist - tu...@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Thanks, Volodymyr ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] why does this fail
Roelof Wobben rwob...@hotmail.com wrote then I have a problem. Im following this book : http://openbookproject.net/thinkcs/python/english2e/ which is the first link in the beginners tutorial page. And it's talking about the string modules. So it is which is quite bizarre since it is using Python 2.5! The string module is deprecated and in Python v3 has had most of the functions removed. Do not use ther string module functions, use the string methods instead. It is usually a simple translation from string.function(aString, other args...) to aString.method(otherargs...) You can check the documentation for the string methods using help(str) I don't want to put you off the tutorial because it is quite a good tutor, but I never noticed it was still promoting the use of the string module before - very odd! -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble with exercise regarding classes
Andrew Martin amartin7...@gmail.com wrote I want to compare zenith, a floating point number, with the current y value? I thought the current y value could be retrieved by Projectile.getY. Projectile.getY is a reference to the getY method of the Projectile class. (See the separate thread on function objects for more on this topic) You want to execute the method so you need parens on the end. But, you also want to execute it for the cball instance. You have already done this earlier in your code, here: while cball.getY() = 0: So you just need to make the if test compatible with that: if Projectile.getY zenith: becomes if cball.getY() zenith: And similarly for the assignment zenith = Projectile.getY() becomes zenith = cball.getY() As an aside you can do this using Projectile, but its bad practice: Projectile.getY(cball) This explicitly provides the self argument instead of Python doing it for you when you use the instance. We can use this technique when calling inherited methods inside a class method definition. Anywhere else its best to use the instance to call a method. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] wx to convert Group 4 Tifs to Gifs
Hi, I have a small application, written in Tkinter. It is supposed to display a tif image, among other things. The problem is, PIL won't decode group 4 Tifs (G4 TIF). The tifs that I have are about 125kb and contain two pages per file. They're scanned, monochrome files. I need the second page of the tif, more specifically the lower half of the second page. I will have 5000-6000 tifs eventually, to manual conversion is not an option. While googling around, I found many other people who faced the same problem. Since I cannot download executables here, I decided to use wx. Ideally, I'd like an object that can be handled with Tkinter.PhotoImage, but I'm also very happy with a simple program that converts from G4 tif to Gif. I have zero knowledge from wx. Therefroe, I'd really appreciate some pointers as to how to make the program below work. import wx, os def tif2gif(infile): This does *not* work SECONDPAGE = 1 outfile = os.path.splitext(infile[0] + .gif) image = wx.Image(name = infile, type = wx.BITMAP_TYPE_TIF, index = SECONDPAGE) bitmap = wx.BitmapFromImage(self.image) bitmap.SaveFile(outfile, wx.BITMAP_TYPE_GIF) tif2gif(infile = d:/temp/somefile.tif) Thank you very much in advance! Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] wx to convert Group 4 Tifs to Gifs
On 26/08/2010 11:46, Albert-Jan Roskam wrote: Hi, I have a small application, written in Tkinter. It is supposed to display a tif image, among other things. The problem is, PIL won't decode group 4 Tifs (G4 TIF). The tifs that I have are about 125kb and contain two pages per file. They're scanned, monochrome files. I need the second page of the tif, more specifically the lower half of the second page. I will have 5000-6000 tifs eventually, to manual conversion is not an option. While googling around, I found many other people who faced the same problem. Since I cannot download executables here, I decided to use wx. Ideally, I'd like an object that can be handled with Tkinter.PhotoImage, but I'm also very happy with a simple program that converts from G4 tif to Gif. I have zero knowledge from wx. Therefroe, I'd really appreciate some pointers as to how to make the program below work. import wx, os def tif2gif(infile): This does *not* work SECONDPAGE = 1 outfile = os.path.splitext(infile[0] + .gif) image = wx.Image(name = infile, type = wx.BITMAP_TYPE_TIF, index = SECONDPAGE) bitmap = wx.BitmapFromImage(self.image) bitmap.SaveFile(outfile, wx.BITMAP_TYPE_GIF) tif2gif(infile = d:/temp/somefile.tif) Thank you very much in advance! Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Any chance you run Linux ? If so you can do it with convert like for fn in ./*.tif; do convert $fn $fn.jpg; done for fn in ./*-1.jpg; do convert $fn $fn.gif; done The reason for the 2 step conversion is tif - gif seems to only give you access to the first page. -- Kind Regards, Christian Witts ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] continuous running of a method
On Thu, 26 Aug 2010 12:27:03 pm R. Alan Monroe wrote: Any modern multi-tasking operating system will ensure than a while loop doesn't kill your computer's responsiveness. A decent operating system will still remain responsive even at 100% CPU usage. Even Windows does that! Opinions vary. If you try this on a laptop, the end user will be quite annoyed to see their battery drop to zero, their cooling fans go into overdrive, and to receive first degree burns on their hands and/or lap. Hmmm. Well, there is that. But the OS will remain responsive while you're looking for the burn cream for your lap! Busywaiting my cpu makes your program an instant candidate for immediate deletion. Maybe that's just me :) Ah, I take it you've deleted the Flash plugin then? Or maybe it's just the Linux version that periodically goes nuts. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] design of Point class
On Thu, 26 Aug 2010 07:29:42 am Gregory, Matthew wrote: I hope you'll suffer me one more question on this thread. In thinking about creating other distance methods (as you suggest), how best to create a generic enough interface, so that ANY distance metric could be used. It seems like coding the Point class with multiple distance methods is not very flexible, especially if you wanted to iterate over those methods for any two points, e.g. class Point(tuple): def euclidean_distance(self, other): ... def manhattan_distance(self, other): ... def any_other_distance(self, other): ... Would this be a place for a generic get_distance with a DistanceMetric subclass as a parameter, e.g. class DistanceMetric(object): def distance(self, p1, p2): assert 0, 'Must be defined in subclasses' class EuclideanDistMetric(DistanceMetric): def distance(self, p1, p2): ... class Point(tuple): def get_distance(self, other, metric): distance = metric.distance(self, other) return distance That could work, but it seems like a terribly heavyweight solution for a lightweight problem to me. It doesn't save you any work -- you still have to code the distance method, but instead of creating a single method, you have to create an entire class. So it's more work. I believe the simplest solution is to use the bound methods as first class functions: pt = Point(23, 42) # choose a distance if today == Tuesday: dist = pt.manhattan_distance else: dist = pt.euclidean_distance for other in list_of_other_points: print(dist(other)) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] question about lists and doctest
hello, I have this programm # Add your doctests here: a_list[3] 42 a_list[6] 'Ni!' len(a_list) 8 a_list = ['test', 'test','test',42,'test','test','Ni!','test'] print a_list[3] print a_list[6] print len(a_list) if __name__ == '__main__': import doctest doctest.testmod() If I change lets say 42 to 16 then the doctest fails with Expecting 42 Got 16. How does doctest now which values are right or not ? Roelof ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about lists and doctest
The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown. Here ur a_list[3] in docstring is 42 then doctest expects it to be 42 for success. Since u changed 42 to 16 then it is not = 42 as per the a_list[3]=42 in docstring hence it raises error. --nitin On Thu, Aug 26, 2010 at 9:11 PM, Roelof Wobben rwob...@hotmail.com wrote: hello, I have this programm # Add your doctests here: a_list[3] 42 a_list[6] 'Ni!' len(a_list) 8 a_list = ['test', 'test','test',42,'test','test','Ni!','test'] print a_list[3] print a_list[6] print len(a_list) if __name__ == '__main__': import doctest doctest.testmod() If I change lets say 42 to 16 then the doctest fails with Expecting 42 Got 16. How does doctest now which values are right or not ? Roelof ___ 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
[Tutor] SSH session problems with network devices
I have Python code that opens a telnet session with a network device and performs a multitude of tasks. Now, I am trying to establish and maintain an SSH connection as an alternative to telent. My research has found that the SSH implementation some network device manufacturers use is not consistent and the problems I'm having are common. I'm hoping to find someone who has found a solution. I am using Paramiko, but I am not limited to that. I am also exploring Appgate MindTerm http://www.appgate.com/index/products/mindterm/. My Paramiko code works correctly when connecting with a Linux system. But when I connect with a router, the connection is dropped immediately after a command is exectued, so it isn't possible to send a sequence of interrelated commands. For example, I want to change the screen paging value so that complete results from the next command will stream back without stopping for --MORE--. Or I need to change the user level and enter a password followed by a series of commands. I have reviewed relevant postings from on the Paramiko list, but there are no clear solutions. http://www.lag.net/pipermail/paramiko/2010-June/001322.html http://www.lag.net/pipermail/paramiko/2010-June/001320.html http://www.lag.net/pipermail/paramiko/2010-March/001284.html I have tried three methods, unsuccessfully, for establishing and maintaining an SSH connection. My test code is at http://pastebin.ca/1918235. I would appreciate any help. I'm open to a non-Paramiko solution, but it has to plug-and-play with the Python utility code I already have. And I hope to keep it simple. Thank you, David Heiser ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] exercise problem
Hello, I have this exercise: Lists can be used to represent mathematical vectors. In this exercise and several that follow you will write functions to perform standard operations on vectors. Create a file named vectors.py and write Python code to make the doctests for each function pass. Write a function add_vectors(u, v) that takes two lists of numbers of the same length, and returns a new list containing the sums of the corresponding elements of each. def add_vectors(u, v): add_vectors([1, 0], [1, 1]) [2, 1] add_vectors([1, 2], [1, 4]) [2, 6] add_vectors([1, 2, 1], [1, 4, 3]) [2, 6, 4] add_vectors([11, 0, -4, 5], [2, -4, 17, 0]) [13, -4, 13, 5] add_vectors should pass the doctests above I think that u is the name of the new list and v is the number which represent the number which must be eveluated. Is this right or do I mis understood the exercise ? Roelof ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] exercise problem
On 8/26/2010 12:02 PM Roelof Wobben said... Hello, I have this exercise: Lists can be used to represent mathematical vectors. In this exercise and several that follow you will write functions to perform standard operations on vectors. Create a file named vectors.py and write Python code to make the doctests for each function pass. Write a function add_vectors(u, v) that takes two lists of numbers of the same length, and returns a new list containing the sums of the corresponding elements of each. def add_vectors(u, v): add_vectors([1, 0], [1, 1]) [2, 1] add_vectors([1, 2], [1, 4]) [2, 6] add_vectors([1, 2, 1], [1, 4, 3]) [2, 6, 4] add_vectors([11, 0, -4, 5], [2, -4, 17, 0]) [13, -4, 13, 5] add_vectors should pass the doctests above I think that u is the name of the new list and v is the number which represent the number which must be eveluated. No. u,v are the parameters names for the two lists of numbers of the same length. So in the example add_vectors([1, 0], [1, 1]), u will take on the value [1, 0] and v the value [1, 1]. HTH, Emile Is this right or do I mis understood the exercise ? Roelof ___ 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] SSH session problems with network devices
On Fri, Aug 27, 2010 at 2:54 AM, davidheise...@gmail.com wrote: My Paramiko code works correctly when connecting with a Linux system. But when I connect with a router, the connection is dropped immediately after a command is exectued, so it isn't possible to send a sequence of interrelated commands. What Router is this ? What OS does it run ? I may have some experience with this as I often ssh into various networking devices including Linux servers and systems, etc... cheers James -- -- James Mills -- -- Problems are solved by method ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SSH session problems with network devices
On Fri, Aug 27, 2010 at 8:42 AM, davidheise...@gmail.com wrote: I'm running tests on - Cisco IOS Software, s72033_rp Software (s72033_rp-ADVIPSERVICESK9_WAN-M), Version 12.2 It's running SSHv2.0 My solution should be portable to other vendor/models. Can you normally ssh into your Cisco routers and be presented with a shell of some kind ? cheers James PS: Please post to the list. -- -- James Mills -- -- Problems are solved by method ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] exercise problem
Roelof Wobben rwob...@hotmail.com wrote Write a function add_vectors(u, v) that takes two lists of numbers I think that u is the name of the new list and v is the number which represent the number which must be eveluated. No. It sounds like you don't really understand the basic concepts behind functions yet. Try reading the Modules and Functions topic in my tutorial. See if that clarifies things for you. Getting these basic concepts right at the beginning is very important, don't try to rush it. If confused by one tutorial reading an alternative explanation can often help - at least it does for me! :-) -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SSH session problems with network devices
On Fri, 27 Aug 2010 02:54:27 am davidheise...@gmail.com wrote: I have Python code that opens a telnet session with a network device and performs a multitude of tasks. Now, I am trying to establish and maintain an SSH connection as an alternative to telent. My research has found that the SSH implementation some network device manufacturers use is not consistent and the problems I'm having are common. I'm hoping to find someone who has found a solution. Hi David, you may be better off on a more senior discussion list than this. It's not really a beginners question, and you may benefit from having a lit more eyes on your question :) Have you tried python-l...@python.org or its newsgroup mirror comp.lang.python ? http://mail.python.org/mailman/listinfo/python-list -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SSH session problems with network devices
On Fri, Aug 27, 2010 at 9:13 AM, davidheise...@gmail.com wrote: Yes. No problem. The point is that I have Python programs that normally access these devices by telnet to complex tasks. I have to find a way to use SSH to replace the telnet in my code. I actually have no experience with Cisco devices, but the question that remains to be seen really is; Why are your Cisco devices terminating the SSH connection after the first command ? This actually might be a terminal or some kind of configuration issue (if you can normally ssh into your Cisco devices and get a prompt/terminal). Ssh'ing and executing remote commands might be interpreted differently by the Cisco ssh/shell/etc. It might be worth your while looking into this as it'll have nothing at all to do with Python or Paramiko.. cheers James -- -- James Mills -- -- Problems are solved by method ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] question about import statement
I was experimenting with Tk today, just trying it out. I found this example of a very simple hello world button click program. This is it. from tkinter import * from tkinter import ttk root = Tk() button = ttk.Button(root, text=Hello World).grid() root.mainloop() What I don't understand is why it is necessary to run that import statement twice. Shouldn't import * bring everything in from tkinter? Just wondering, Bill Allen ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about import statement
On Thu, Aug 26, 2010 at 7:44 PM, Corey Richardson kb1...@aim.com wrote: Why don't you try it out without the from tkinter import ttk statement, and see if it works? Bill Allen wrote: I was experimenting with Tk today, just trying it out. I found this example of a very simple hello world button click program. This is it. from tkinter import * from tkinter import ttk root = Tk() button = ttk.Button(root, text=Hello World).grid() root.mainloop() What I don't understand is why it is necessary to run that import statement twice. Shouldn't import * bring everything in from tkinter? Just wondering, Bill Allen ___ 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] question about import statement
On Thu, Aug 26, 2010 at 7:44 PM, Corey Richardson kb1...@aim.com wrote: Why don't you try it out without the from tkinter import ttk statement, and see if it works? Bill Allen wrote: I was experimenting with Tk today, just trying it out. I found this example of a very simple hello world button click program. This is it. from tkinter import * from tkinter import ttk root = Tk() button = ttk.Button(root, text=Hello World).grid() root.mainloop() What I don't understand is why it is necessary to run that import statement twice. Shouldn't import * bring everything in from tkinter? Oops, sorry about the previous empty post. I did try that and of course it gave an error because it was necessary. I just did not know why. However, I later found an explanation on the web. Here it is: *from tkinter import * from tkinter import ttk These two lines tell Python that our program needs two modules. The first, tkinter, is the standard binding to Tk, which when loaded also causes the existing Tk library on your system to be loaded. The second, ttk, is Python's binding to the newer themed widgets that were added to Tk in 8.5. * -Bill ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about import statement
On Thu, Aug 26, 2010 at 9:16 PM, Bill Allen walle...@gmail.com wrote: I did try that and of course it gave an error because it was necessary. I just did not know why. However, I later found an explanation on the web. Here it is: from tkinter import * from tkinter import ttk These two lines tell Python that our program needs two modules. The first, tkinter, is the standard binding to Tk, which when loaded also causes the existing Tk library on your system to be loaded. The second, ttk, is Python's binding to the newer themed widgets that were added to Tk in 8.5. yeah, from package import * doesn't actually import every name from a module. For example, by default, names starting with an underscore are not imported. Alternatively, if you have a variable named __all__ in your module, and it's a list of names, only those names in the list actually get imported when you do a from x import * Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about import statement
On 08/26/2010 10:29 PM, Hugo Arts wrote: On Thu, Aug 26, 2010 at 9:16 PM, Bill Allen walle...@gmail.com wrote: I did try that and of course it gave an error because it was necessary. I just did not know why. However, I later found an explanation on the web. Here it is: from tkinter import * from tkinter import ttk These two lines tell Python that our program needs two modules. The first, tkinter, is the standard binding to Tk, which when loaded also causes the existing Tk library on your system to be loaded. The second, ttk, is Python's binding to the newer themed widgets that were added to Tk in 8.5. yeah, from package import * doesn't actually import every name from a module. For example, by default, names starting with an underscore are not imported. Alternatively, if you have a variable named __all__ in your module, and it's a list of names, only those names in the list actually get imported when you do a from x import * Hugo Why would the person who wrote this package choose to do it this way, though? If it was something that people would use and not just an internal name, why hide it this way? Greg ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about import statement
On Thu, Aug 26, 2010 at 11:18 PM, Greg Bair gregb...@gmail.com wrote: On 08/26/2010 10:29 PM, Hugo Arts wrote: On Thu, Aug 26, 2010 at 9:16 PM, Bill Allen walle...@gmail.com wrote: I did try that and of course it gave an error because it was necessary. I just did not know why. However, I later found an explanation on the web. Here it is: from tkinter import * from tkinter import ttk These two lines tell Python that our program needs two modules. The first, tkinter, is the standard binding to Tk, which when loaded also causes the existing Tk library on your system to be loaded. The second, ttk, is Python's binding to the newer themed widgets that were added to Tk in 8.5. yeah, from package import * doesn't actually import every name from a module. For example, by default, names starting with an underscore are not imported. Alternatively, if you have a variable named __all__ in your module, and it's a list of names, only those names in the list actually get imported when you do a from x import * Hugo Why would the person who wrote this package choose to do it this way, though? If it was something that people would use and not just an internal name, why hide it this way? http://docs.python.org/tutorial/modules.html#importing-from-a-package It's a practical thing, mostly for packages. When you import * from a package 'x', how does python know all the modules present in the package? You would hope that it somehow goes into the filesystem and figures out all the files inside the 'x' directory, but this could take a long time and have unwanted side-effects. So, you have to specify the __all__ variable inside your __init__.py file, and that way import * will know what to do. Alternatively, you can just import all the modules inside __init__.py, since any names that are inside __init__.py will also be loaded. Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor