Re: [Tutor] Looking for ConfigObj Documentation
"Wayne Watson" wrote My assumption was is was fully a DOS window. No its a DOS window on steroids! Thee are a ton of improvements to the DOS shell in XP most of which are turned off by default. Take half an hour to go through the help screens for CMD and turn on the various registry settings it mentions to access its full power. (Type HELP CMD at the prompt) Trying to work my way to folder was a bit daunting, Cut n paste of the path works, but you can also use tab to complete the file name which speeds things up considerably. (And recall that with QuickEdit turned on you can easily cut n paste from the CMD window itself) Now the problem became one of typing in the name of the program each time it was to be executed. Even on DOS F3 repeated the last command but on XP (and indeed since Win95) you can use up/down arrow to step back through the command history. And you can set it to remember the history betweeen sessions (although I don't personally do that...) I think you can also search back through the history but I don't use that very often and I'm maybe confusing it with cygwin/bash! This works inside the python prompt in a CMD window too. Other tricks include environment variable expansion good for HOME, PATH, etc Definitely worth spending some time reading the HELP on the enhanced CMD features. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Alan Gauld wrote: Cut n paste of the path works, but you can also use tab to complete the file name which speeds things up considerably. And you can drag a file in from explorer to a Console window to get the full path pasted in automatically. Even on DOS F3 repeated the last command but on XP (and indeed since Win95) you can use up/down arrow to step back through the command history. And you can set it to remember the history betweeen sessions (although I don't personally do that...) I think you can also search back through the history but I don't use that very often and I'm maybe confusing it with cygwin/bash! No, you're right: if you press a few characters and then F8 a matching line will be populated (can't remember if it's the most recent or the oldest). If you press F7, a selection list of all the lines entered pops up and you can select from there. And all the old tricks from the original DOS shells work: F3 as you mentioned (altho' up/down arrows are easier for this); F2 will copy up to a particular characters. Quite limited but still they have their possibilities. TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Problems with Python 3 and Tkinter
I am trying to learn Python and have just installed Python 3. I am going back over some previous scripts trying to convert them to run under Python 3 (and hopefully learn a bit more in the process). I am having great problems with scripts that use Tkinter. A typical example is a script called calculator.py (the full script can be viewed at: http://openbookproject.net/pybiblio/tips/wilson/tkinterhelp.php ) I have shown some of the problem lines from the script below. 01 from Tkinter import * 02 from tkMessageBox import showerror 03 from math import sqrt ... 41 except ValueError: 42 if self.number.get() == '': 43 showerror('Entry error', 'You have to put a number in the blank.') 44 else: 45 showerror('Square root error', 46 "Can't find the square root of '%s'" % self.number.get()) ... When I run the calculator.py script I get the following error message: -- Python 3 -- Traceback (most recent call last): File "calculator.py", line 1, in from Tkinter import * ImportError: No module named Tkinter Output completed (0 sec consumed) If I change line 01 as follows: 01 from tkinter import * I get the following error message: -- Python 3 -- Traceback (most recent call last): File "calculator.py", line 2, in from tkMessageBox import showerror ImportError: No module named tkMessageBox Output completed (0 sec consumed) Clearly Python 3 needs the Tkinter library typed in lower case. Then it passes on to line 02 where it can't find the module tkMessageBox. I have a copy of Grayson's "Python and Tkinter Programming" and the original script above seems to be Ok. If I comment out line 02 01 from tkinter import * 02 # from tkMessageBox import showerror The script now runs Ok unless I try to calculate a square root with no value entered in the input field. Note: Lines 41 to 46 are there to catch such errant behaviour. With no input I get the following error message: -- Python 3 -- Exception in Tkinter callback Traceback (most recent call last): File "calculator.py", line 39, in calc (self.number.get(), sqrt(float(self.number.get( ) ValueError: empty string for float() During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Python30\lib\tkinter\__init__.py", line 1399, in __call__ return self.func(*args) File "calculator.py", line 43, in calc showerror('Entry error', 'You have to put a number in the blank.') NameError: global name 'showerror' is not defined As part of my 'problem resolution' process I have run scripts under Python 3 that just import the tkinter library and they run fine. It only when I try to use modules such as tkMessageBox that I get problems. I have spent hours researching and Googling this problem. Is there anyone who can help me understand how to get this script running. Additionally, is there any references to Python 3 and Tkinter other than the standard documentation (which is flimsy at best). Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things—Niccolo Machiavelli, /The Prince/, ch. 6 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with Python 3 and Tkinter
I have just re-installed Python 2.5.4 and the calculator.py script runs correctly using the original script (even when no value is entered in the data input field - the error dialog displays correctly). This is very frustrating! Clearly there is something different in the way Python 3.0.1 is handling Tkinter and tkMessageBox. Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things—Niccolo Machiavelli, /The Prince/, ch. 6 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with Python 3 and Tkinter
"Peter Anderson" wrote Additionally, is there any references to Python 3 and Tkinter other than the standard documentation (which is flimsy at best). There are a couple of other tutorials that have been upgraded to v3 but I suspect most, like mine, are still works in progress! Python 3 for a beginner is still pioneer country at present. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/l2p/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with Python 3 and Tkinter
By George I think I've done it!!! I was looking (yet again) through the Python 3 documentation and have changed the calculator.py script to: from tkinter import * from tkinter.messagebox import showerror from math import sqrt ... And it now works! I would still appreciate any help with trying to understand how tkinter and its modules are used. For example, exactly what modules are able to be used? Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things—Niccolo Machiavelli, /The Prince/, ch. 6 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
As it turns out QuickEdit is turned on in my XP, but certainly not by me. The unfolding of what the cmd prompt actually does reminds me of a couple of incidents. When I wrote a book on an interpretive Basic language in the early 90s, the very first paragraph began with how to exit from the interpreter. At the time, it seemed popular with such interpreters to obfuscate the exit command by using names like SYSTEM! Yikes! When I was introduced the C by the Kernighan and Ritchie book, I almost jumped for joy with their famous "Hello World" program. This was a book to be read. When I casually, and I mean casually, started looking at python a few years ago, I started with what I might call a (well-known) bloated book on the subject, it took until chapter 3 for the author to say anything about running programs. The first programming job I had found me staring at a government issued 200 page manual printed in capitals on a then popular language. What a huge bore. It's a wonder that I continued, or anyone, for that matter. I guess the right start matters, or in the words of the hero in Schindler's List (movie), "It's all about presentation." After this cmd console "discovery", I'd say this is quite possibly something I'd put in the first chapter of any book on Python. Nice to know about F8 (and F7), tab or other attempts didn't do it for me. I'll take Alan's suggestion on spending some time on the reading XP Help. Tim Golden wrote: Alan Gauld wrote: Cut n paste of the path works, but you can also use tab to complete the file name which speeds things up considerably. And you can drag a file in from explorer to a Console window to get the full path pasted in automatically. Even on DOS F3 repeated the last command but on XP (and indeed since Win95) you can use up/down arrow to step back through the command history. And you can set it to remember the history betweeen sessions (although I don't personally do that...) I think you can also search back through the history but I don't use that very often and I'm maybe confusing it with cygwin/bash! No, you're right: if you press a few characters and then F8 a matching line will be populated (can't remember if it's the most recent or the oldest). If you press F7, a selection list of all the lines entered pops up and you can select from there. And all the old tricks from the original DOS shells work: F3 as you mentioned (altho' up/down arrows are easier for this); F2 will copy up to a particular characters. Quite limited but still they have their possibilities. TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Nature, to be commanded, must be obeyed." -- Sir Francis Bacon Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with Python 3 and Tkinter
On Sat, Feb 21, 2009 at 8:05 AM, Peter Anderson wrote: > By George I think I've done it!!! > > I was looking (yet again) through the Python 3 documentation and have > changed the calculator.py script to: > > from tkinter import * > from tkinter.messagebox import showerror > from math import sqrt > ... > > And it now works! I would still appreciate any help with trying to > understand how tkinter and its modules are used. For example, exactly what > modules are able to be used? The docs at least list the modules, but without showing their contents: http://docs.python.org/3.0/library/tkinter.html#tkinter-modules To see what is in each package, one option is to start up a pydoc server on your local machine, that gives a convenient way to browse the modules. On Windows, for Python 2.5 at least, there is a Start menu shortcut for this - Start / All Programs / Python 2.5 / Module Docs. You can also browse the source code in Python3.0\Lib\tkinter\ Kent Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] It's all about presentation
Wayne Watson wrote: ... I started with what I might call a (well-known) bloated book on the subject, it took until chapter 3 for the author to say anything about running programs. The first programming job I had found me staring at a government issued 200 page manual printed in capitals on a then popular language. What a huge bore. It's a wonder that I continued, or anyone, for that matter. I guess the right start matters, or in the words of the hero in Schindler's List (movie), "It's all about presentation." In the 80's I taught computer classes at the Boeing Company in Seattle. On several occasions I was given handouts similar to that. One example was a Fortran course that spent the first morning on writing expressions. I imagined students wanting some context for this topic. At the first opportunity I wrote a new handout; the first topic was a program to read 2 numbers, add them and print the sum. (In that era programs were run in batch mode on a HP3000. The students edited the program at their terminals, submitted them, waited a few minutes then received listings from the printer down the hall. We did eventually cover expressions. -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Default list arguments in __init__
Hi, This behavior was totally unexpected. I only caught it because it was the only thing I changed. >>> class foo: ... def __init__(self, lst=[]): ... self.items = lst ... >>> f1 = foo() >>> f1.items [] >>> f1.items.append(1) >>> f2 = foo() >>> f2.items [1] Huh? lst is a reference to the *same list* every instance? I guess I have to do it like this. It seems to work. (i.e. every foo instance with default lst now has a unique new list.) def__init__(self, lst=None): self.items = lst or [] This is on python 2.4.4c1 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Default list arguments in __init__
Le Sat, 21 Feb 2009 11:38:49 -0800, Moos Heintzen s'exprima ainsi: > Hi, > > This behavior was totally unexpected. I only caught it because it was > the only thing I changed. > > >>> class foo: > ... def __init__(self, lst=[]): > ... self.items = lst > ... > >>> f1 = foo() > >>> f1.items > [] > >>> f1.items.append(1) > >>> f2 = foo() > >>> f2.items > [1] > > Huh? lst is a reference to the *same list* every instance? Yop! Default args are evaluated once and only once at func def time. Very common trap, indeed! Note that this has nothing to do with __init__, nore with methods specifically. You can reproduce your example with a "free" function. > I guess I have to do it like this. It seems to work. (i.e. every foo > instance with default lst now has a unique new list.) > > def__init__(self, lst=None): > self.items = lst or [] This is the right remedy. Except that I would write self.items = [] if lst is None else lst to avoid "tricking" with bools (personal taste). denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Title: Signature.html I tried XP's Help on command prompts. Not much there. Is there another source? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Nature, to be commanded, must be obeyed." -- Sir Francis Bacon Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Default list arguments in __init__
On Sat, Feb 21, 2009 at 2:55 PM, spir wrote: > Le Sat, 21 Feb 2009 11:38:49 -0800, > Moos Heintzen s'exprima ainsi: > >> Hi, >> >> This behavior was totally unexpected. I only caught it because it was >> the only thing I changed. Yes, it is a common trap and a FAQ: http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm >> I guess I have to do it like this. It seems to work. (i.e. every foo >> instance with default lst now has a unique new list.) >> >> def__init__(self, lst=None): >> self.items = lst or [] > > This is the right remedy. Except that I would write >self.items = [] if lst is None else lst > to avoid "tricking" with bools (personal taste). These two versions have different behaviour if an empty list is passed in. Most likely the second one will be what was intended. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
On Sat, Feb 21, 2009 at 6:42 PM, Wayne Watson wrote: > I tried XP's Help on command prompts. Not much there. Is there another > source? > There are lots, and Google knows most of them - here's a good one to start with: http://www.ss64.com/nt/ -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Title: Signature.html Yes, to a potential bad idea. I'm not quite sure why I put that in there. Possibly what I really wanted is the location of the file. There are some other entries where I want to know the location of the file. For example, the mask file. I likely want to load that file when the program opens. Similarly with the Events folder. In fact, I probably want the folder's name chosen by the user, and the location. Folders and files are not completely thought out. The hard core data, time, gray choice, lat/long, etc., are currently the most important. Distracted? It happens to me all the time?:-) I tell people my life could be summed up by two words, interrupted projects. I could very likely build the file myself from looking at the descriptions of boolean, etc., but you mentioned something about possibly a validation function(?) that sounded like maybe I didn't yet know all the wrinkles in the file. Marc Tompkins wrote: On Sat, Feb 21, 2009 at 6:46 PM, Wayne Watsonwrote: Marc, did I miss your update on the file? No, just got distracted. I'll get that to you shortly. One thing I meant to ask you - why is the file name the first line of the file? It's up to you, but I think it's generally a bad idea - that's a holdover from my database days; one of the first rules I learned was "Don't store derived data (and if you must, then don't rely on it!)" What benefit does it give you, and what consequences would result if the first line of the file did NOT match the actual file name? (You know, I edit the file and Save As "Initial1.sen", or "Initial.sen.hld", or whatever, but I forget to change the first line - or conversely, I change the first line but forget to rename the file... What happens? In other words, what are you doing with it? -- www.fsrtechnologies.com -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Nature, to be commanded, must be obeyed." -- Sir Francis Bacon Web Page: ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Title: Signature.html I've found others like that, but I was looking for something more descriptive. Things like typing fill-in, or cut/paste, use of F8, etc. I'd guess there are more. Marc Tompkins wrote: On Sat, Feb 21, 2009 at 6:42 PM, Wayne Watsonwrote: I tried XP's Help on command prompts. Not much there. Is there another source? There are lots, and Google knows most of them - here's a good one to start with: http://www.ss64.com/nt/ -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Nature, to be commanded, must be obeyed." -- Sir Francis Bacon Web Page: ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
On Sat, Feb 21, 2009 at 8:26 PM, Wayne Watson wrote: > I've found others like that, but I was looking for something more > descriptive. Things like typing fill-in, or cut/paste, use of F8, etc. I'd > guess there are more. > Click through a little further: http://www.ss64.com/nt/cmd.html Should tell you more than you could possibly want to know about the XP command prompt and its options. -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
On Fri, Feb 20, 2009 at 2:19 PM, Wayne Watson wrote: > Good. Thanks. It works fine for me now. I deleted the file. I just ran > the program again straight from the py file, and it put my the black window > with my raw_input prompt. It seems odd that it wouldn't have left text > debris when it crashed. > > I've attached a copy of an Initial file. It's still under development, but > pretty close for the immediate purposes. The "_file_" names will likely end > up as a string showing the complete path to the file. start/stop_time will > be times in > the format shown, hh:mm:ss. The first line is just a header, and currently > gets tossed when the file is read. "_name" are strings. No others have seen > the program, so development continues. > > Sentinel NC Configuration File Sentinel User 3 - 1/3/2009 (Meteor Software) > config_file_name=Initial.sen > mask_file_name=*none* > gray_scale=True > post_event_stack=False > post_event_format=Tiff 2 > show_real_time=False > hourly_rate=12 > slowdown=1 > start_time=20:00:12 > stop_time=06:03:00 > lat=40.0 > long=120.0 > utc_offset=8 > elevation=1000.0 > site_name=Unknown > clock_drift=0.0 > zenith_x_pixel=319 > zenith_y_pixel=239 > north_angle_rotation=0.0 > events=Events > post_events=Post_Events > meteors=Meteor_Tags > composites=wtw:same as events? > flat_mask_val=30 > mask_file_name=*none* > mask_file_offset=30 > flat_mask_active=False > > OK - first problem is, as the error message indicated, line 1: > Sentinel NC Configuration File Sentinel User 3 - 1/3/2009 (Meteor Software) > It's not a comment, it's not a real configuration item, so ConfigObj barfs. Put a "#" in front of that, and we run just fine until: > configobj.DuplicateError: Duplicate keyword name at line 26. > which is also correct - line 26 is a duplicate of line 3. Put a "#" in front of _that_, and we run just fine with the following result: """ config_file_name = Initial.sen mask_file_name = *none* gray_scale = True post_event_stack = False post_event_format = Tiff 2 show_real_time = False hourly_rate = 12 slowdown = 1 start_time = 20:00:12 stop_time = 06:03:00 lat = 40.0 long = 120.0 utc_offset = 8 elevation = 1000.0 site_name = Unknown clock_drift = 0.0 zenith_x_pixel = 319 zenith_y_pixel = 239 north_angle_rotation = 0.0 events = Events post_events = Post_Events meteors = Meteor_Tags composites = wtw:same as events? flat_mask_val = 30 #mask_file_name=*none* mask_file_offset = 30 flat_mask_active = False """ (Once again, those are my own triple quotes) Notice that the first line has been suppressed - if you want a comment to survive into the actual file, you'll need to add it in the configspec; however, line 26 _did_ survive... there's some mystery there, but I'm not going to kill myself over it. I haven't modified the actual program or the configspec. This illustrates that the configspec dictates the bare minimum that the config file can contain, not the maximum - any valid lines (of the format "name = value") that are in the config file but not in the spec will survive (and be available to your program). -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor