Re: [Tutor] Looking for ConfigObj Documentation
On Fri, Feb 20, 2009 at 5:05 PM, Wayne Watson wrote: > Not because of this particular problem, but, out of curiosity, I tried > today to give the MS command line facility a shot. I think that's what we > are discussing here. I immediately ran into something of a problem. My > assumption was is was fully a DOS window. Trying to work my way to folder > was a bit daunting, since I have not used this in a very long time, but this > wasn't the problem. > > As it turns out, there was an easier way. Drag and drop the path+program > link into the window after placing a CD in the command line. Very non-DOS*. > :-) One could then backspace to remove the program name, so the result was a > CD to the program folder, where several programs reside. Now the problem > became one of typing in the name of the program each time it was to be > executed. With a pretty long path name and the need to type in the file name > on each use, it seemed a bit tedious. Maybe there's another way? > > * But yet, no copy and paste from the folder Address area > Two tips: Command Prompt Here and tab completion. 1) If you haven't already, check out the Windows XP PowerToys: http://www.microsoft.com/windowsxp/Downloads/powertoys/Xppowertoys.mspx Most of them are useless (to me, anyway) but the two that are indispensible - I install them on every (XP) machine I work on - are TweakUI and Command Prompt Here. It adds a "Comand Prompt Here" item to the menu when you right-click on a folder. I remember seeing a few articles explaining how to do this yourself - but why bother? 2) Tab completion is turned on by default in Windows XP - just type the first few letters of the filename, and Windows will fill in the rest. If there are several files that start with what you typed, you might need to add a few letters to get the right one, but it still saves lots and lots of typing. It even intelligently handles long filenames with spaces in them, putting them in quotes when required. If it's turned off on your machine, you can turn it back on through TweakUI (see #1 above) under "Command Prompt." So for example, you would right-click on your project folder, select Command Prompt Here, type "python " followed by "G" and a tab, then Enter. (Or maybe "GL" then Tab, or whatever - you get the drift.) If you want a command prompt in your desktop folder, just right-click on a folder on your desktop, select CPH, then type "cd.." Much simpler than Start/Run/cmd followed by "cd \Documents and Settings\username\Desktop". Copy and paste DOES work, but not with keyboard shortcuts (presumably, those are intercepted by the command prompt itself) - right-click in the command window and select Paste. -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Title: Signature.html Not because of this particular problem, but, out of curiosity, I tried today to give the MS command line facility a shot. I think that's what we are discussing here. I immediately ran into something of a problem. My assumption was is was fully a DOS window. Trying to work my way to folder was a bit daunting, since I have not used this in a very long time, but this wasn't the problem. As it turns out, there was an easier way. Drag and drop the path+program link into the window after placing a CD in the command line. Very non-DOS*. :-) One could then backspace to remove the program name, so the result was a CD to the program folder, where several programs reside. Now the problem became one of typing in the name of the program each time it was to be executed. With a pretty long path name and the need to type in the file name on each use, it seemed a bit tedious. Maybe there's another way? * But yet, no copy and paste from the folder Address area P.S. For some very odd reason, now when I press Reply, I get both the poster's address and Tutor. It seems to come and go. Right now it doesn't work, as I try it one other messages I see on screen. Very odd. Alan Gauld wrote: "Wayne Watson" wrote I just ran the program again straight from the py file, and it put my the black window with my raw_input prompt. Thats why, when debugging, its often better to open the command window first and run the program from the OS prompt. That way you don't lose any text messages that may be written to the screen. Alan G ___ 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
"Wayne Watson" wrote I just ran the program again straight from the py file, and it put my the black window with my raw_input prompt. Thats why, when debugging, its often better to open the command window first and run the program from the OS prompt. That way you don't lose any text messages that may be written to the screen. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Title: Signature.html 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. Marc Tompkins wrote: On Fri, Feb 20, 2009 at 9:45 AM, Wayne Watsonwrote: Marc, I'm reaching back here, since something seems to have gone awry. I'm looking at the code for Global_Config1.py. When I execute it from IDLE, I get again: ... File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", line 1637, in _parse ParseError, infile, cur_index) File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", line 1748, in _handle_error raise error ParseError: Invalid line at line "1". <<--- same old, same old However, we know IDLE can goof up. So I thought I'd execute the code by double clicking on the file. A black window appears briefly, then disappears. I have raw_input and other tricks to see if I could slow it down. Finally, I went to the MS Command prompt window, and executed the py file from there. I get exactly the same message (s) as above. I don't recall if you tried the program on your system. Comments? First: the line "1" it's talking about is the first line of the config file, not of configobj.py. Second: as written, there's no GUI here, so we _expect_ it to briefly show a black window, then close - but when it's done, there should be a file called "Initial.sen" in the current directory, which will look like this (this is the output on my machine): """ mask_file_name = None gray_scale = True post_event_stack = False post_event_format = Tiff 2 show_real_time = False hourly_rate = 0 slowdown = 1 start_time = 00:00:00 stop_time = 00:00:00 """ (I've added the triple quotes for visual clarity - they don't appear in the actual file.) I suspect that what's happening is that you already have a file called Initial.sen, and its contents don't match the configspec. So the ParseError is an expected result - we either need to tweak the configspec to match your previous file, or add exception handling, or (simplest) if you don't have any real installed base, just start from scratch. Do me two favors: - send your existing Initial.sen so I can look at modifying the configspec or adding exception handling - delete or rename it, then try the program again. -- 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: 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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] File locking: cross platform?
There's a recipe in the Python Cookbook that addresses this: http://code.activestate.com/recipes/65203/ There are probably others floating around, too. Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
On Fri, Feb 20, 2009 at 10:45 AM, Paul McGuire wrote: > Has anyone already mentioned the article in Python Magazine, May, 2008? > No, I for one haven't seen it. Is it available online, or only for subscribers? -- 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 9:45 AM, Wayne Watson wrote: > Marc, I'm reaching back here, since something seems to have gone awry. I'm > looking at the code for Global_Config1.py. When I execute it from IDLE, I > get again: > > ... > File > "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", > line 1637, in _parse > ParseError, infile, cur_index) > File > "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", > line 1748, in _handle_error > raise error > ParseError: Invalid line at line "1". <<--- same old, same old > > However, we know IDLE can goof up. So I thought I'd execute the code by > double clicking on the file. A black window appears briefly, then > disappears. I have raw_input and other tricks to see if I could slow it > down. Finally, I went to the MS Command prompt window, and executed the py > file from there. I get exactly the same message (s) as above. I don't recall > if you tried the program on your system. Comments? > First: the line "1" it's talking about is the first line of the config file, not of configobj.py. Second: as written, there's no GUI here, so we _expect_ it to briefly show a black window, then close - but when it's done, there should be a file called "Initial.sen" in the current directory, which will look like this (this is the output on my machine): """ mask_file_name = None gray_scale = True post_event_stack = False post_event_format = Tiff 2 show_real_time = False hourly_rate = 0 slowdown = 1 start_time = 00:00:00 stop_time = 00:00:00 """ (I've added the triple quotes for visual clarity - they don't appear in the actual file.) I suspect that what's happening is that you already have a file called Initial.sen, and its contents don't match the configspec. So the ParseError is an expected result - we either need to tweak the configspec to match your previous file, or add exception handling, or (simplest) if you don't have any real installed base, just start from scratch. Do me two favors: - send your existing Initial.sen so I can look at modifying the configspec or adding exception handling - delete or rename it, then try the program again. -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] File locking: cross platform?
Bernard Rankin wrote: Hello, What is the correct way to implement cross-platform "flock like" file locking? Specifically, how would i acquire "exclusive read-write" and "shared read-only" locks for a CGI script that I expect to run on both Windows and Linux servers. Some other tutor may have a different answer. I propose you open(filename, 'r') or open(filename, 'w'). -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] File locking: cross platform?
Hello, What is the correct way to implement cross-platform "flock like" file locking? Specifically, how would i acquire "exclusive read-write" and "shared read-only" locks for a CGI script that I expect to run on both Windows and Linux servers. Thank you, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please remove me from the mailing list
On Fri, Feb 20, 2009 at 12:38 PM, Jennifer Miller wrote: > Hello, > > Could you please remove my address from the mailing list? OK ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Has anyone already mentioned the article in Python Magazine, May, 2008? -- Paul ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] verify the email
jitendra gupta wrote: is there any way so that i can identify wrong email during the run time (when i am sending the email) As I understand things, no. You can validate the domain part, and there is the SMTPRecipientsRefused exception, but you won't get that if you're relaying. Further, mail systems (and administrators) are reluctant to provide spammers an easy way to validate email lists, so where doors may be opened, you're likely to find them closed anyway. Emile ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Title: Signature.html Marc, I'm reaching back here, since something seems to have gone awry. I'm looking at the code for Global_Config1.py. When I execute it from IDLE, I get again: ... File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", line 1637, in _parse ParseError, infile, cur_index) File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", line 1748, in _handle_error raise error ParseError: Invalid line at line "1". <<--- same old, same old However, we know IDLE can goof up. So I thought I'd execute the code by double clicking on the file. A black window appears briefly, then disappears. I have raw_input and other tricks to see if I could slow it down. Finally, I went to the MS Command prompt window, and executed the py file from there. I get exactly the same message (s) as above. I don't recall if you tried the program on your system. Comments? Marc Tompkins wrote: On Wed, Feb 18, 2009 at 7:42 PM, Wayne Watsonwrote: I took your "starter" code, and formatted it to be what I hope is an acceptable program, Gobal_Config.py. See attached. I'm using Python 2.5.2. I put the two modules in the same folder with it, and executed it in IDLE. I got this: ... File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", line 1637, in _parse ParseError, infile, cur_index) File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", line 1748, in _handle_error raise error ParseError: Invalid line at line "1". As far as I can tell, line 1 of config.obj looks OK. It's a comment. Something is amiss. I hate to say it, but IDLE is really holding you back. It's convenient because it installs automagically with Python, but it does funky, confusing things - as in this case, where it's somehow stepped on the real error and assigned blame in the wrong place; you've already experienced its internal conflicts with Tkinter... I use wxPython for my GUI goodness, and swear by SPE (Stani's Python Editor). I don't want to re-ignite the IDE wars, but I definitely think you need to do yourself a favor and move away from IDLE. Anyway, I didn't mean for that to be a standalone program, but to be picked apart into chunks and dropped into an existing program (or, actually, just to be used as an example - maybe of what _not_ to do, but an example...) First error: if argv is None: argv = sys.argv <<== you haven't imported "sys" Second error: app = MyApp(0) <<== you haven't defined a class called "MyApp", so you can't do this... So I cut it down to just this bit: test = Global.cfgFile.validate(Global.vtor, copy=True) Global.cfgFile.write() (unindented all the way to the left, so that it executes as the main body of the program) and it works just fine... except: Third error (well, issue not error): Take all my comments out! They weren't meant to be included in final code. ConfigObj allows inline comments in your config file, and in the configspec - so my comments show up in there too. Here's what Initial.sen ends up looking like: mask_file_name = None gray_scale = True post_event_stack = False post_event_format = Tiff 2 show_real_time = False hourly_rate = 0 slowdown = 1 # I don't know what # this value is/does, so this is probably wrong start_time = 00:00:00 # or you could make the default None? stop_time = 00:00:00 # as a default latitude, if any... I've cut everything down; I'm attaching it as Global_Config1.py (just to avoid confusion with the earlier version). If you do actually want to use it as the basis of anything, you'll want to place the call to .validate() somewhere near the beginning of the action - remember, the call to .write() just afterward is completely optional; I had it in there for testing and have kept it in there for the same reason. Does PYTHONPATH apply in Win XP? I haven't played at the level of paths for a long time in any OS. We can worry about an install "package" later for the modules. It might be best for the users of this program. Ya know, I have no idea anymore. I thought I knew - but I just did a SET from a command prompt, and I don't have a PYTHONPATH variable. I seem to reacall something from a year or two ago... (looking now) Oh yes - there's a directory under your Python directory (Python25 in my case) called "Lib", and a folder under that called "site-packages"; any text files with the extension ".pth" will be scaned for the names of folders to add to the search path. As much as I love Python, I wish they'd get all this together... -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Wayne Watso
[Tutor] Please remove me from the mailing list
Hello, Could you please remove my address from the mailing list? Thank you, Jennifer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Standardizing on Unicode and utf8
Le Fri, 20 Feb 2009 02:52:27 -0800, "Dinesh B Vadhia" s'exprima ainsi: > We want to standardize on unicode and utf8 and would like to clarify and > verify their use to minimize encode()/decode()'ing: > > 1. Python source files > Use the header: # -*- coding: utf8 -*- You don't even need fancy decoration: # coding: utf-8 is enough. Denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Standardizing on Unicode and utf8
On Fri, Feb 20, 2009 at 5:52 AM, Dinesh B Vadhia wrote: > We want to standardize on unicode and utf8 and would like to clarify and > verify their use to minimize encode()/decode()'ing: > > 1. Python source files > Use the header: # -*- coding: utf8 -*- > > 2. Reading files > In most cases, we don't know the source encoding of the files being read. > Do we have to decode('utf8') after reading from file? If you don't know the encoding of the file being read, it is difficult to handle it correctly. A simple strategy is to try several encodings and use the first one that reads without error. Note that *any* text can be decoded using iso-8859-1 (latin-1) or cp1252 so they must be last in the tests. This strategy can distinguish utf-16-be, utf-16-le, utf-8, iso-8859-1 but it can't discriminate between any of the iso-8859-x variants because they all will decode anything (they have characters at every code point). A more sophisticated strategy is to look for character patterns, see Mark Pilgrim's Universal Encoding Detector: http://chardet.feedparser.org/docs/ Best is not to get into this situation to begin with... Where are the files coming from? If they are from web pages, they often have metadata which gives the charset. > 3. Writing files > We will always write to files in utf8. Do we have to encode('utf8') before > writing to file? Yes. The codecs module can help with reading and writing files, it creates file-like objects that encode/decode on the fly. > Is there anything else that we have to consider? Console output also has to be decoded to the charset of the console (sys.stdout.encoding). Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] wxPython dialog problem
On Thu, Feb 19, 2009 at 11:04 PM, Garry Willgoose wrote: > I'm just porting an old code from a GUI in Tkinter to one in wxPython and am > having a problem with one of the dialog widgets. This is on OSX. The code > below gives the result > > result= 5104 5103 5104 > > as expected but if I substitute the single line form that is commented out > (as per the wxPython book) I get > > result= 2 5103 5104 > > can anyone enlighten me as to what is going on? I;m on OSX python 2.5.2 and > wxPython 2.8.9.1 Apparently ShowModal() returns one of wxID_OK, wxID_CANCEL, wxID_YES, wxID_NO whereas MessageBox() returns one of wxYES, wxNO, wxCANCEL, wxOK These are not the same: In [1]: import wx In [3]: wx.ID_OK, wx.ID_CANCEL, wx.ID_YES, wx.ID_NO Out[3]: (5100, 5101, 5103, 5104) In [4]: wx.YES, wx.NO, wx.CANCEL, wx.OK Out[4]: (2, 8, 16, 4) Kent > > code fragment > > dlg=wx.MessageDialog(None,text,title,wx.YES_NO | wx.ICON_QUESTION) > result=dlg.ShowModal() > # result=wx.MessageBox(text,title,wx.YES_NO | wx.ICON_QUESTION) > print 'result=',result,wx.ID_YES,wx.ID_NO > > end code fragment > > > > > ___ > 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] Standardizing on Unicode and utf8
We want to standardize on unicode and utf8 and would like to clarify and verify their use to minimize encode()/decode()'ing: 1. Python source files Use the header: # -*- coding: utf8 -*- 2. Reading files In most cases, we don't know the source encoding of the files being read. Do we have to decode('utf8') after reading from file? 3. Writing files We will always write to files in utf8. Do we have to encode('utf8') before writing to file? Is there anything else that we have to consider? Cheers Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] I have a question plz help
"rev pacce" wrote My mom and I have been trying to hack into the administrator account on our laptop my mom got from her job We don't deal with that kind of hacking on this list. But consider what might happen if you succeed. Suppose Mom's PC develops a fault and her IT people try to go into administrator and find the password has been changed? She could lose her job! They don't tell you the password so you don't change anything and therefore don't mess up the PC settings. It costs businesses a heap of money fixing "broken" PCs. Many companies would consider that malicious damage of company property and sack her... Is it worth it just to play iTunes? Alan g ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor