Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??
input() must be avoided at all costs in Python 2.x. if you find any Python (2.x) book which employs that, consider the author uninformed. it is a huge security risk and the main reason why in Python 3 raw_input() is renamed to and replaces input(). cheers, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??
Vern, Quite right! I see what you mean. I quite inadvertently stumbled into examples that would work without realizing it. I typically program in Python 3, so not as familiar with the limitations on Python 2x. I've had quite a chuckle over this! Thanks, Bill On Thu, Jan 13, 2011 at 10:31 PM, Vern Ceder wrote: > Bill, > > Try this: > > >>> print("hello", "Bill") > ('Hello', 'Bill') > >>> x = input("Your name?") > Your name?Bill > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in > NameError: name 'Bill' is not defined > > and see if those work (my results on 2.6 shown). In Python 3 the results > are: > > >>> print ("Hello", "Bill") > Hello Bill > >>> x = input("Your name?") > Your name?Bill > >>> > > Cheers, > Vern > The two examples you show would work on any Python 2.x (or even 1.5) > system. The parens around the single string won't cause an error nor will > using input to get an integer. > > Cheers, > Vern > > On Thu, Jan 13, 2011 at 11:18 PM, Bill Allen wrote: > >> I will agree that it seems odd, but here is a sample run from my system. >> I promise I am not pulling anyone's leg! :-)) >> >> wallenpb@Ubuntu-D810:~$ python >> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) >> [GCC 4.4.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> print("hello world") >> hello world >> >>> x = input("how many?") >> how many?5 >> >>> x >> 5 >> >> On Thu, Jan 13, 2011 at 9:31 PM, Corey Richardson wrote: >> >>> On 01/13/2011 10:29 PM, Bill Allen wrote: >>> > That is correct about the difference between Python 2 and Python 3 >>> > syntax. However, I am surprised that with 2.7.1 these do not work. >>> I >>> > have found that on my Ubuntu system with Python 2.6.5 these Python 3 >>> > syntax items do seem to work properly. I am assuming they were back >>> > ported or something. I would have expected the same for 2.7.1. >>> > >>> > --Bill >>> >>> I'm using Python 2.6.6 and I have a feeling you are not using python >>> 2.6.5 with Python3 syntax working. I could be very wrong, but just a >>> hunch ;) >>> >>> ~Corey >>> >> >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >> > > > -- > Vern Ceder > vce...@gmail.com, vce...@dogsinmotion.com > The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW > > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??
Bill, Try this: >>> print("hello", "Bill") ('Hello', 'Bill') >>> x = input("Your name?") Your name?Bill Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'Bill' is not defined and see if those work (my results on 2.6 shown). In Python 3 the results are: >>> print ("Hello", "Bill") Hello Bill >>> x = input("Your name?") Your name?Bill >>> Cheers, Vern The two examples you show would work on any Python 2.x (or even 1.5) system. The parens around the single string won't cause an error nor will using input to get an integer. Cheers, Vern On Thu, Jan 13, 2011 at 11:18 PM, Bill Allen wrote: > I will agree that it seems odd, but here is a sample run from my system. I > promise I am not pulling anyone's leg! :-)) > > wallenpb@Ubuntu-D810:~$ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> print("hello world") > hello world > >>> x = input("how many?") > how many?5 > >>> x > 5 > > On Thu, Jan 13, 2011 at 9:31 PM, Corey Richardson wrote: > >> On 01/13/2011 10:29 PM, Bill Allen wrote: >> > That is correct about the difference between Python 2 and Python 3 >> > syntax. However, I am surprised that with 2.7.1 these do not work. I >> > have found that on my Ubuntu system with Python 2.6.5 these Python 3 >> > syntax items do seem to work properly. I am assuming they were back >> > ported or something. I would have expected the same for 2.7.1. >> > >> > --Bill >> >> I'm using Python 2.6.6 and I have a feeling you are not using python >> 2.6.5 with Python3 syntax working. I could be very wrong, but just a >> hunch ;) >> >> ~Corey >> > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Vern Ceder vce...@gmail.com, vce...@dogsinmotion.com The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??
I will agree that it seems odd, but here is a sample run from my system. I promise I am not pulling anyone's leg! :-)) wallenpb@Ubuntu-D810:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print("hello world") hello world >>> x = input("how many?") how many?5 >>> x 5 On Thu, Jan 13, 2011 at 9:31 PM, Corey Richardson wrote: > On 01/13/2011 10:29 PM, Bill Allen wrote: > > That is correct about the difference between Python 2 and Python 3 > > syntax. However, I am surprised that with 2.7.1 these do not work. I > > have found that on my Ubuntu system with Python 2.6.5 these Python 3 > > syntax items do seem to work properly. I am assuming they were back > > ported or something. I would have expected the same for 2.7.1. > > > > --Bill > > I'm using Python 2.6.6 and I have a feeling you are not using python > 2.6.5 with Python3 syntax working. I could be very wrong, but just a > hunch ;) > > ~Corey > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??
On 01/13/2011 10:29 PM, Bill Allen wrote: > That is correct about the difference between Python 2 and Python 3 > syntax. However, I am surprised that with 2.7.1 these do not work. I > have found that on my Ubuntu system with Python 2.6.5 these Python 3 > syntax items do seem to work properly. I am assuming they were back > ported or something. I would have expected the same for 2.7.1. > > --Bill I'm using Python 2.6.6 and I have a feeling you are not using python 2.6.5 with Python3 syntax working. I could be very wrong, but just a hunch ;) ~Corey ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??
That is correct about the difference between Python 2 and Python 3 syntax. However, I am surprised that with 2.7.1 these do not work. I have found that on my Ubuntu system with Python 2.6.5 these Python 3 syntax items do seem to work properly. I am assuming they were back ported or something. I would have expected the same for 2.7.1. --Bill On Thu, Jan 13, 2011 at 7:55 PM, Corey Richardson wrote: > On 01/13/2011 08:50 PM, Elwin Estle wrote: > > I am going through the book mentioned in the subject line, and I have > found a couple of things that don't seem to work the way the author shows in > the book. So, either I am doing something wrong, or what he is saying isn't > quite right. > > > > I am using Python 2.7.1 on Mac OS X Leopard. > > > > The first thing is what he has for getting keyboard input (this is > non-GUI stuff). > > > > Several times he does something like this: > > > > x = input('type something: ") > > > > But when I do the above and type something in, I get an error message > saying that whatever I have typed in response to the above input() command, > is an undefined name, unless I put it in quotes when I type it. I did a bit > of poking around on the net and found out that input() actually appears to > treat whatever is typed as an actual python command, i.e. as if it was being > "eval"ed. If this is the case...why does he describe the usage this way in > his book? > > > > On the other hand, raw_input() works just as exected, is it a typo? > Seems like kind of a bad error to have in a Python book for beginners. > > > > And I just found another one that doesn't appear to work as he describes. > > > > print("some text here", end = ' ') > > > > He says this is supposed to control the end character on a print > statement, allowing one to choose what the last character printed will be, > other than a newline. But when I try it, I get a syntax error on the "=" > after "end". > > > > So is this not a valid command format? Or is he using perhaps an earlier > version of python? The copyright date on the book is 2010, and it is the > 3rd Edition of the book. > > > > > > > > He's not using an older version - you are! That book was written for > Python 3.x, you are using Python 2.x. As you have found, replace input > with raw_input, and for that print statement you can use: > > print "Some text", > > The comma suppresses the newline from being printed. > > HTH, > ~Corey > > ___ > 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] module to parse XMLish text?
Does anyone know of a module that can parse out text with XML-like tags as in the example below? I emphasize the "-like" in "XML-like". I don't think I can parse this as XML (can I?). Sample text between the dashed lines:: - Blah, blah, blah SOMETHING ELSE SOMETHING DIFFERENT - I'd like to be able to have a dictionary (or any other structure, really; as long as I can get to the parsed-out pieces) that would look smoothing like: {"BING" : "ZEBRA", "BANG" : "ROOSTER" "BOOM" : "GARBONZO BEAN" "BLIP" : "SOMETHING ELSE" "BASH" : "SOMETHING DIFFERENT"} The "Blah, blah, blah" can be tossed away, for all I care. The basic rule is that the tag either has an operand (e.g., ), in which case the name is the first word and the content is everything else that follows in the tag; or else the tag has no operand, in which case it is matched to a corresponding closing tag (e.g., SOMETHING ELSE), and the content is the material between the two tags. I think I can assume there are no nested tags. I could write a state machine to do this, I suppose, but life's short, and I'd rather not re-invent the wheel, if there's a wheel laying around somewhere. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??
On 01/13/2011 08:50 PM, Elwin Estle wrote: > I am going through the book mentioned in the subject line, and I have found a > couple of things that don't seem to work the way the author shows in the > book. So, either I am doing something wrong, or what he is saying isn't > quite right. > > I am using Python 2.7.1 on Mac OS X Leopard. > > The first thing is what he has for getting keyboard input (this is non-GUI > stuff). > > Several times he does something like this: > > x = input('type something: ") > > But when I do the above and type something in, I get an error message saying > that whatever I have typed in response to the above input() command, is an > undefined name, unless I put it in quotes when I type it. I did a bit of > poking around on the net and found out that input() actually appears to treat > whatever is typed as an actual python command, i.e. as if it was being > "eval"ed. If this is the case...why does he describe the usage this way in > his book? > > On the other hand, raw_input() works just as exected, is it a typo? Seems > like kind of a bad error to have in a Python book for beginners. > > And I just found another one that doesn't appear to work as he describes. > > print("some text here", end = ' ') > > He says this is supposed to control the end character on a print statement, > allowing one to choose what the last character printed will be, other than a > newline. But when I try it, I get a syntax error on the "=" after "end". > > So is this not a valid command format? Or is he using perhaps an earlier > version of python? The copyright date on the book is 2010, and it is the 3rd > Edition of the book. > > > He's not using an older version - you are! That book was written for Python 3.x, you are using Python 2.x. As you have found, replace input with raw_input, and for that print statement you can use: print "Some text", The comma suppresses the newline from being printed. HTH, ~Corey ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] errors in "Python Programming for the Absolute Beginner"??
I am going through the book mentioned in the subject line, and I have found a couple of things that don't seem to work the way the author shows in the book. So, either I am doing something wrong, or what he is saying isn't quite right. I am using Python 2.7.1 on Mac OS X Leopard. The first thing is what he has for getting keyboard input (this is non-GUI stuff). Several times he does something like this: x = input('type something: ") But when I do the above and type something in, I get an error message saying that whatever I have typed in response to the above input() command, is an undefined name, unless I put it in quotes when I type it. I did a bit of poking around on the net and found out that input() actually appears to treat whatever is typed as an actual python command, i.e. as if it was being "eval"ed. If this is the case...why does he describe the usage this way in his book? On the other hand, raw_input() works just as exected, is it a typo? Seems like kind of a bad error to have in a Python book for beginners. And I just found another one that doesn't appear to work as he describes. print("some text here", end = ' ') He says this is supposed to control the end character on a print statement, allowing one to choose what the last character printed will be, other than a newline. But when I try it, I get a syntax error on the "=" after "end". So is this not a valid command format? Or is he using perhaps an earlier version of python? The copyright date on the book is 2010, and it is the 3rd Edition of the book. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] creating a text widget
Forwarding to list... > none of it actually. i am brand new to Tk/Python. Actually, i don't have a >need to do any editing on the file. OK, display is pretty easy. Take a look in my tutorial under Event Driven Programming. There you will see a simple text widget with text being inserted. Or look in the Case Study topic for a more extensive GUI with more text being inserted into a text widget. But perhaps you should try first to write a program that simply pages data from your file onto the screen using print() - perhaps limited to 25 lines at a time? Hitting space should bring up the next 25 lines, and so on. That will give you experience of working with files. HTH, Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ From: Alan Gauld To: tutor@python.org Sent: Thu, January 13, 2011 1:35:08 PM Subject: Re: [Tutor] creating a text widget "W S" wrote > could someone please provide me some code that would create a text widget > that >i could open a text file in? > You don;t open the text file in the widget as such, you open the file in Python as usual and copy its contents into the text widget. When you are done making changes (if you are making changes) then you have to copy the content back out to the file (or rename the original to .bak and create a new version) So the question is which part do you not understand? - Creating a text widget - opening the file - copying the file to the widget - copying changes to the file 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
Re: [Tutor] turn a path into nested list
"ingo" wrote at the os.walk() function for traversing directory trees? It may be all you need. Yes, but I'm not confident with it (the more reason to use it you will say :) ). Quite. A simple tree printout looks like this: for t in os.walk('Root'): ...print t ... And the result is:('Root', ['D1', 'D2', 'D3'], ['FA.txt', 'FB.txt']) ('Root/D1', ['D1-1'], ['FC.txt']) ('Root/D1/D1-1', [], ['FF.txt']) ('Root/D2', [], ['FD.txt']) ('Root/D3', ['D3-1'], ['FE.txt']) ('Root/D3/D3-1', [], ['target.txt']) That's a lot of work done for just 2 lines of code...Thats taken from the OS topic in my tutorial(V2 only as yet)It goes into slightly more detail and more examples.But it looks like it will sace you a lot of work! -- Alan GauldAuthor of the Learn to Program web sitehttp://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] (no subject)
On Thu, Jan 13, 2011 at 4:53 PM, Steven D'Aprano wrote: > lmho...@jacks.sdstate.edu wrote: >> >> Hello All, >> I am having an issue with lists and am not sure where to go from here any >> advice appreciated. I colored the areas of concern. >> blue my comments >> purple example of output >> red area area concerned > > You may have coloured the text before you sent it, but the colours did not > survive being sent to a mailing list. Everything you have written is a nice, > plain black. > > Colouring text is no substitute for actually taking the time to explain: > > * what you tried; > * what you expected to happen; > * what happened instead. > > It is good practice to try to reduce the code to the smallest amount that > actually demonstrates the same problem. Actually the color survived on my end, but all of steven's other comments about noise and unnecessary text applies. Even with the color, I didn't bother reading your question because it seemed to me like you didn't bother formulating a good question either. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
lmho...@jacks.sdstate.edu wrote: Hello All, I am having an issue with lists and am not sure where to go from here any advice appreciated. I colored the areas of concern. blue my comments purple example of output red area area concerned You may have coloured the text before you sent it, but the colours did not survive being sent to a mailing list. Everything you have written is a nice, plain black. Colouring text is no substitute for actually taking the time to explain: * what you tried; * what you expected to happen; * what happened instead. It is good practice to try to reduce the code to the smallest amount that actually demonstrates the same problem. For example, in your code you have this: [...] # Check out any necessary licenses gp.CheckOutExtension("spatial") # Load required toolboxes... gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx") gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.workspace = "D:\model" This is almost certainly irrelevant to the problem. To us, this is just noise -- we can't run it, because we don't have the arcgisscripting module, we don't have any way of testing for a licence, we can't load the toolboxes. For us to help you, you have to help us -- don't ask us to debug code we can't run. (We can sometimes try, if the bug is obvious, but usually it is just frustrating for everybody involved.) Spending the time to simplify the problem to the point we can run the code will help us to help you, and it might even let you solve the problem yourself. Some further comments: # Table and field name inputs inTable = "D:\model\Files.mdb\Last" inPath="D:\model\Path.lyr" In *this* particular case, this way of writing file names is safe, but in general, it risks clashing with Python's "character escapes". String literals like \t \n \r and many others have special meaning to Python, and are turned into special characters like tab, newline, etc. Fortunately, Windows accepts both backslash and forward slash for file names, so the safest and easiest way to write those files names is: inTable = "D:/model/Files.mdb/Last" inPath = "D:/model/Path.lyr" Further comments: paths = gp.SearchCursor(inTable) path = paths.Next() # Create an empty list PathList = [] while path: # If the value is not already in the list, append it if path.GetValue(inField) not in PathList: PathList.append(path.GetValue(inField)) path = paths.Next() [...] This is the area that I am having complications with I am getting the correct output at the end of print PRList however because of the loop it overwrites the list each time. Ultimately I need to get a PR list of evens and odds but when I put the EVEN Odd Check in the loop it will only calculate the first even number then give an error. Traceback (most recent call last): File "C:\Users\lwood\Desktop\MODEL SCRIPTS\E\oddeven.py", line 65, in if PR.GetValue(PRField) not in PRList: AttributeError: 'int' object has no attribute 'GetValue' This error does not match the code you have written: the error talks about PR.GetValue, your code says path.GetValue. What other differences are there? What is PR? How does it differ from path? It is a waste of time to ask us to debug code that is not the code that is failing! The problem is, you have a line that *may or may not* look like this: paths = gp.SearchCursor(inTable) We don't know what paths will equal! It could be anything. But from the name, it should be some sort of collection of path objects, whatever they are. Each path object should have a method GetValue, but apparently (guessing from your error) some of them are plain int objects instead of path objects. There are 233 paths and within each a different number of rows. I need a list to make a feature layer of just odds and of evens per each path. It works fine when it is out of the loop but only gives me the last path list. I don't understand how you can say it works fine, when a moment ago you said it gives an error. I realize that this it is looping over the list each time and that is why the output is for the last path only. I would just like it all in one loop is possible but not necessary. I don't understand what this means. I'm not sure but what I have thought may work is writing the list to a file and appending it each time then reopenning it for the calculations but that seems a little much. Perhaps a Mapping technique or dictionary? Or like I mentioned before it would be fine to do it all in one loop as well. There shouldn't be any need to write to a file. But I can't suggest an alternative because I don't understand what you are trying to do. I'm sorry that I can't be of more assistance, but unfortunately my crystal ball is broken this week *wink* -- Steven _
Re: [Tutor] Beginning Python and other resources (was Re: SlicingTuples)
Also check bigwords.com, they aggregate lots of other book sites and will get you a great deal, especially if you are buying multiple books because it smartly combines shipping and all. - Sent from a mobile device. Apologies for brevity and top-posting. - On Jan 13, 2011, at 6:24 AM, Brett Ritter wrote: > On Tue, Jan 4, 2011 at 4:50 PM, Patty wrote: >> Hi David - I was looking for the book you recomended below - "Python 3 >> Object Oriented Programming" by Dusty Phillips - and found it on Amazon for >> $43 new on up and $70 for used but maybe that was hardback? Do you happen >> to know of some other way to obtain it for less than $45? > > Half.com is always my stop of choice for programming books. I see a > copy there for $16. > > -- > Brett Ritter / SwiftOne > swift...@swiftone.org > ___ > 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] Beginning Python and other resources (was Re: SlicingTuples)
>> Object Oriented Programming" by Dusty Phillips - and found it on Amazon for >> $43 new on up and $70 for used but maybe that was hardback? Do you happen >> to know of some other way to obtain it for less than $45? the retail price of the book is $49.99, and Packt books are usually POD (print on-demand), and they don't discount them very much because... they're not mass-produced. > I obtained my paperback copy from the publisher's website > www.packtpub.com It is also available there as an e-book. Also I > notice there is a free sample chapter there which will give an idea of > its content. the free material is chapter 7 of the book, called "object-oriented shortcuts." it's a nice intro/summary of every day Python tools like various utility built-in functions (len, enumerate, reversed, zip), list and other comprehensions leading to generator expressions then generators proper. continuing the functional programming feel from there, it goes into the various features available in your function signature, e.g., default args, varargs; then functions themselves as objects. based on this theme, it sounds like a book that introduces Python (specifically Python 3) from an "object-based" approach. it doesn't mean that the whole book will be about *writing classes* in Python, but to have more object-awareness as you're learning the language. (this wasn't a book review as much as it was getting a feel for the book based on looking through one sample chapter.) :-) cheers, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Hello All, I am having an issue with lists and am not sure where to go from here any advice appreciated. I colored the areas of concern. blue my comments purple example of output red area area concerned theoretically written not tested Sorry if its messy still a newbie. Thanks in advance! Lynn # Import native arcgisscripting module import arcgisscripting, sys, string, os, math # Create the geoprocessor object gp = arcgisscripting.create(9.3) gp.overwriteoutput = 1 # Check out any necessary licenses gp.CheckOutExtension("spatial") # Load required toolboxes... gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx") gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.workspace = "D:\model" # Table and field name inputs inTable = "D:\model\Files.mdb\Last" inPath="D:\model\Path.lyr" inField = "PATH" PRField = "PR" # Variables ECOAG = "D:\\model\\Files.mdb\\ECOAG" # Eco Ag combined with con statment t= string.Template("D:\\model\\Files.mdb\\T$Num") p = string.Template('"PATH" = $Path') prow = string.Template('"PR" = $PRow') wrs_season_shp="D:\model_workspace\wrs_season.shp" wrs_season_Layer="wrs_season_Layer" Files_mdb = "D:\\model\\Files.mdb" paths = gp.SearchCursor(inTable) path = paths.Next() # Create an empty list PathList = [] while path: # If the value is not already in the list, append it if path.GetValue(inField) not in PathList: PathList.append(path.GetValue(inField)) path = paths.Next() # Sort the list alphanumerically PathList.sort() print PathList[0] print PathList logfile=open('listfile.txt', 'w') logfile.write (str(PathList)) logfile.write('goodbye') This is the area that I am having complications with I am getting the correct output at the end of print PRList however because of the loop it overwrites the list each time. Ultimately I need to get a PR list of evens and odds but when I put the EVEN Odd Check in the loop it will only calculate the first even number then give an error. Traceback (most recent call last): File "C:\Users\lwood\Desktop\MODEL SCRIPTS\E\oddeven.py", line 65, in if PR.GetValue(PRField) not in PRList: AttributeError: 'int' object has no attribute 'GetValue' There are 233 paths and within each a different number of rows. I need a list to make a feature layer of just odds and of evens per each path. It works fine when it is out of the loop but only gives me the last path list. I realize that this it is looping over the list each time and that is why the output is for the last path only. I would just like it all in one loop is possible but not necessary. I'm not sure but what I have thought may work is writing the list to a file and appending it each time then reopenning it for the calculations but that seems a little much. Perhaps a Mapping technique or dictionary? Or like I mentioned before it would be fine to do it all in one loop as well. for path in PathList: gp.MakeFeatureLayer_management(wrs_season_shp, wrs_season_Layer,p.substitute(Path = str(path)), Files_mdb,) print path gp.savetolayerfile("wrs_season_Layer", "Path.1yr") PRS = gp.SearchCursor(inPath) PR = PRS.Next() PRList = [path] while PR: # If the value is not already in the list, append it if PR.GetValue(PRField) not in PRList: PRList.append(PR.GetValue(PRField)) PR = PRS.Next() # Sort the list alphanumerically PRList.sort() print PRList This is part of the output each path is listed first then each row within it and if I call PRList[5] is works fine as well 233008 it begins with [1,1001,1002] etc until this is the last output [233, 233005, 233006, 233007, 233008, 233009, 233010, 233011, 233012, 233013, 233014, 233015, 233016, 233017, 233018, 233050, 233051, 233052, 233053, 233054, 233055, 233056, 233057, 233058, 233059, 233060, 233061, 233062, 233063, 233064, 233065, 233066, 233067, 233068, 233069, 233070, 233071, 233072, 233073, 233074, 233075, 233076, 233077, 233078, 233079, 233080, 233081, 233082, 233083, 233084, 233085, 233086, 233087, 233088, 233089, 233090, 233091, 233092, 233093, 233094, 233095] #Even Odd Check for PR in PRList: if PR%2==0: print "Evens" print PR if PR%2>0: print "Odds" print PR Odds 233 Odds 233005 Evens 233006 Odds 233007 Evens etc What I need the list for is here to enter each even or odd PR as a string for a SQL selection such as this I have not written yet but I figure it would work something like this.. for path in PathList: for PR in PRList[path]: if PR%2==0: print "Evens" ##for calculation ##gp.MakeFeatureLayer_management(wrs_season_shp, inPath, prow.substitute(PRow =
Re: [Tutor] How to find a substring within a list of items
On Thu, Jan 13, 2011 at 2:27 PM, Wayne Werner wrote: > > I don't know if either of these are the best options (they probably > aren't), but they should work, and for 3500 it will probably loop faster > than opening up excel. > > HTH, > Wayne > Thanks Wayne. This would definitely be faster than getting Excel opened and doing it there. Given Alan's great suggestion in only stepping through string fields (this *does* have constant object formats) things should be even quicker. Now to give them a nice simple GUI to do it in. :) Thinking about wxPython (what I'm most used to), though it's been a while. Not sure if there are better options for something simple like this. Great help guys. Thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to find a substring within a list of items
"Richard Querin" wrote I have an object that contains about 3500 list items, each list containing various data, some strings and some floats, like so: ['D', 123.4,'This is a project description', 'type', 52.1,'title'] What is the easiest way to search this list for a given string? Is the format constant? In other words are items 2 and 5 always numbers and therefore can be ignored? If so it might be something as simple as: result = [] for item in data: for index in [0,2,3,5]: if 'scrip' in item[index].lower(): result.append( item) break And you can optimise that as much as you like... :-) 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
Re: [Tutor] turn a path into nested list
On Thu, Jan 13, 2011 at 6:30 PM, Alan Gauld wrote: > Its not clear what exactly the sort criteria is, sorry Alan, I meant that I want to keep the order as is. > however have you looked > at the os.walk() function for traversing directory trees? It may be all > you need. Yes, but I'm not confident with it (the more reason to use it you will say :) ). Below the script I'm working on, rather unstable still. It will be put to work in Cherrypy so I browse through my media directories and send playlists to my media player(s). Very preliminary still. ingo --- %< --- %< --- import os, string, urllib topdirs={ 'Audio': 'c:', 'Video': 'd:', 'Photo': 'e:' } path = 'c:\\Python27' path = os.path.abspath(path) print path topdir = 'Audio' def mkPATH(path, topdirs=topdirs): path=urllib.url2pathname(path) path=string.split(path,'\\',1) return os.path.join(topdirs[path[0]],path[1]) def mkURL(dir): return urllib.pathname2url(dir) def mk_alias(dir, old=topdirs[topdir], new=topdir): return string.replace(dir,old,new) def mk_aliasURL(dir): return mkURL(mk_alias(dir)) def mk_pathlist(path): pathlist=[] dir='' for item in path.split("\\"): dir=os.path.join(dir,item) dir=mkURL(dir) a=[item,dir] pathlist.append(a) return pathlist aliaspath = mk_alias(path) directories = mk_pathlist(aliaspath) files = [] content = os.listdir(path) content.sort() for item in content: fullpath = os.path.join(path, item) if os.path.isdir(fullpath): directories.append([item, mk_aliasURL(fullpath)]) else: files.append([item, mk_aliasURL(fullpath)]) print '\n Path \n', path print '\n AliasPath \n', aliaspath print '\n Dirs \n', directories print '\n Files \n', files ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] creating a text widget
"W S" wrote could someone please provide me some code that would create a text widget that i could open a text file in? You don;t open the text file in the widget as such, you open the file in Python as usual and copy its contents into the text widget. When you are done making changes (if you are making changes) then you have to copy the content back out to the file (or rename the original to .bak and create a new version) So the question is which part do you not understand? - Creating a text widget - opening the file - copying the file to the widget - copying changes to the file 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
Re: [Tutor] How to find a substring within a list of items
On Thu, Jan 13, 2011 at 12:10 PM, Richard Querin wrote: > I have an object that contains about 3500 list items, each list containing > various data, some strings and some floats, like so: > > ['D', 123.4,'This is a project description', 'type', 52.1,'title'] > > What is the easiest way to search this list for a given string? So I want > to find out if this list contains the string 'scrip' anywhere within it > (case insensitive and including being just part of a larger string). > > Incidentally, I'm using the xlrd module to read in a spreadsheet. I > effectively want to quickly pull out a list of lines from that spreadsheet > that contain that substring anywhere within them. Maybe there is a > better/faster way I should be doing this? > > I'm trying to give employees here a better/faster way of filtering through > the company project list rather than opening up excel and doing a find > search each time. > Well, the easiest (maybe not fastest) way would be something like: rows_found = [] for row in rows: for element in row: try: if 'scrip' in element: rows_found.append(row) break # Once we find an element, no need to check others except TypeError: pass #can't iterate over int's & such That should give you the correct results. Alternatively, if you have something against try/except you could do for row in rows if 'scrip' in str(row): #str(row) turns the list into the same thing you get when you print(row) rows_found.append(row) I'm not sure which one is faster, though I presume the first one would be. I don't know if either of these are the best options (they probably aren't), but they should work, and for 3500 it will probably loop faster than opening up excel. HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to find a substring within a list of items
I have an object that contains about 3500 list items, each list containing various data, some strings and some floats, like so: ['D', 123.4,'This is a project description', 'type', 52.1,'title'] What is the easiest way to search this list for a given string? So I want to find out if this list contains the string 'scrip' anywhere within it (case insensitive and including being just part of a larger string). Incidentally, I'm using the xlrd module to read in a spreadsheet. I effectively want to quickly pull out a list of lines from that spreadsheet that contain that substring anywhere within them. Maybe there is a better/faster way I should be doing this? I'm trying to give employees here a better/faster way of filtering through the company project list rather than opening up excel and doing a find search each time. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] creating a text widget
On Thu, Jan 13, 2011 at 12:02 PM, W S wrote: > could someone please provide me some code that would create a text widget > that i could open a text file in? much thanks > Dear Google: Please insert all the results of "simple python GUI text editor" into my brain. Learning is so tiresome! Sincerely, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] creating a text widget
could someone please provide me some code that would create a text widget that i could open a text file in? much thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] turn a path into nested list
It's like the were psychic...or intuitive . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] turn a path into nested list
> Its not clear what exactly the sort criteria is, however have you looked > at the os.walk() function for traversing directory trees? It may be all > you need. it's amazing what the designers of the builtins left for your disposal. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] turn a path into nested list
"ingo" wrote I have a path path = 'Audio/site-packages/pygame/examples/macosx/aliens_app_example/English.lproj' I'd like to turn taht into a list with a certain structure and order: Its not clear what exactly the sort criteria is, however have you looked at the os.walk() function for traversing directory trees? It may be all you need. -- 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] How to insert a quit-Button in a Tkinter class?
Hi All ! Thanks a lot for the great help. As a beginner, I was forgetting to see the "Inheritance from Frame", but now it's all runing ok. Thankfull, enihgil On 01/12/2011 06:23 PM, Karim wrote: Hello, Inherit from Frame see below: from Tkinter import * class App(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createLabel() self.createButton() def createLabel(self): self.label = Tkinter.Label(text="") self.label.grid() self.update_clock() def update_clock(self): now = time.strftime("%H:%M:%S") self.label.configure(text=now) self.after(1000, self.update_clock) def createButton(self): self.quitButton = Button( self, text='Quit', command=self.quit ) self.quitButton.grid() app = App() app.master.title("Clock Time!") app.mainloop() Regards Karim On 01/12/2011 08:41 PM, Enih Gilead wrote: Hi, all ! I've being strugling a lot trying to insert (just as exemple) a quit-Button in a Tkinter class App with no success... What I get is the clock runing ok, but, the App simply ignores the quit-Button... Why? _*Remark*_: I took this minimalist digital clock just to illustrate the "bad :-)" class behavior, but it didn't work in any other Apps I tried. I searched a lot (indeed!) in the net but I couldn't find the reason. Could any of you tell me, please, _*what's the problem?*_ Thanks, enihgil ### import Tkinter import time class App(): def __init__(self): self.root = Tkinter.Tk() self.label = Tkinter.Label(text="") self.label.grid() self.update_clock() self.root.mainloop() def update_clock(self): now = time.strftime("%H:%M:%S") self.label.configure(text=now) self.root.after(1000, self.update_clock) def createButton(self): self.quitButton = Button( self, text='Quit', command=self.quit ) self.quitButton.grid() app=App() ___ 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 maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
On Thu, Jan 13, 2011 at 8:41 AM, David Hutto wrote: > As you can tell, I was excited, and impressed by my own work, and > therefore thought you should follow my wise and almighty work. On the flip side, it's like being an electrician, and seeing the lights come on when you hook the box up. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
As you can tell, I was excited, and impressed by my own work, and therefore thought you should follow my wise and almighty work. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] turn a path into nested list
On Thu, Jan 13, 2011 at 1:51 PM, Christian Witts wrote: > First split your path into segments, then iterate over those segments and > build your new list (item one being the current segment, and part two a > joined string of previous segments). > thanks Christian, path = 'Audio/site-packages/pygame/examples/macosx/aliens_app_example/English.lproj' path=urllib.url2pathname(path) print '\n',path pathlist=[] dir='' for item in path.split("\\"): dir=os.path.join(dir,item) a=[item,dir] pathlist.append(a) print pathlist ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] turn a path into nested list
On 13/01/2011 14:33, ingo wrote: Dear all, a probably simple problem I can't get my head around at the moment (old age?), some input would be appreciated. I have a path path = 'Audio/site-packages/pygame/examples/macosx/aliens_app_example/English.lproj' I'd like to turn taht into a list with a certain structure and order: [['Audio', 'Audio'], ['site-packages', ''Audio/site-packages'], ['pygame', 'Audio/site-packages/pygame'], ['examples', 'Audio/site-packages/pygame/examples'], ['macosx', ''Audio/site-packages/pygame/examples/macosx'], . . ] How to approach this? TIA, ingo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor First split your path into segments, then iterate over those segments and build your new list (item one being the current segment, and part two a joined string of previous segments). -- Kind Regards, Christian Witts ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] turn a path into nested list
Dear all, a probably simple problem I can't get my head around at the moment (old age?), some input would be appreciated. I have a path >>> path = >>> 'Audio/site-packages/pygame/examples/macosx/aliens_app_example/English.lproj' I'd like to turn taht into a list with a certain structure and order: [['Audio', 'Audio'], ['site-packages', ''Audio/site-packages'], ['pygame', 'Audio/site-packages/pygame'], ['examples', 'Audio/site-packages/pygame/examples'], ['macosx', ''Audio/site-packages/pygame/examples/macosx'], . . ] How to approach this? TIA, ingo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginning Python and other resources (was Re: SlicingTuples)
On Tue, Jan 4, 2011 at 4:50 PM, Patty wrote: > Hi David - I was looking for the book you recomended below - "Python 3 > Object Oriented Programming" by Dusty Phillips - and found it on Amazon for > $43 new on up and $70 for used but maybe that was hardback? Do you happen > to know of some other way to obtain it for less than $45? Half.com is always my stop of choice for programming books. I see a copy there for $16. -- Brett Ritter / SwiftOne swift...@swiftone.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question regarding regular expression compile
Luke Paireepinart wrote: No. Did you try that? It doesn't evn look like valid python code to me. You want a single string with the r before it, not 3 separate strings. The line of code in question is: test = re.compile('MAT file (billing|carrier|log|util)' r'\\' '\d{8} deleted') If you actually try it, it is perfectly valid Python code :) However, I agree with Luke: this would be better written as a single string: 'MAT file (billing|carrier|log|util)\d{8} deleted' or even better, a raw string r'MAT file (billing|carrier|log|util)\\\d{8} deleted' Little know Python fact: Python includes implicit concatenation of string literals. If you have two or more string literals (but not variables) written next to each other, Python will automatically concatenate them at compile time. You can mix quotation marks and raw and ordinary strings as needed: >>> print "Hello" 'world' Helloworld Here's a more useful example: if condition: raise ValueError("this is a very long" " error message with much useful detail," " far too much to fit on a single line of" " source code.") which is equivalent to this: if condition: s = "this is a very long" s += " error message with much useful detail," s += " far too much to fit on a single line of" s += " source code." raise ValueError(s) except the string is constructed once, at compile time, and no variable s is created. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginning Python and other resources (was Re: SlicingTuples)
On 5 January 2011 08:50, Patty wrote: > Hi David - I was looking for the book you recomended below - "Python 3 > Object Oriented Programming" by Dusty Phillips - and found it on Amazon for > $43 new on up and $70 for used but maybe that was hardback? Do you happen > to know of some other way to obtain it for less than $45? Hi Patty I obtained my paperback copy from the publisher's website www.packtpub.com It is also available there as an e-book. Also I notice there is a free sample chapter there which will give an idea of its content. Regards David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Determinw Tkinter checkbox state, was Re: question
Stinson, Wynn A Civ USAF AFMC 556 SMXS/MXDED wrote: [In the future please take the time to choose a meaningful subject] > Can someone give me some sample code to use to determine if a checkbox > has been selected using Tkinter? thanks Method 1: check the state of the underlying variable: import Tkinter as tk root = tk.Tk() var = tk.IntVar() cb = tk.Checkbutton(root, text="the lights are on", variable=var) cb.pack() def showstate(): if var.get(): print "the lights are on" else: print "the lights are off" button = tk.Button(root, text="show state", command=showstate) button.pack() root.mainloop() Method 2: trigger a function when the underlying variable changes import Tkinter as tk root = tk.Tk() var = tk.IntVar() cb = tk.Checkbutton(root, text="the lights are on", variable=var) cb.pack() def showstate(*args): if var.get(): print "the lights are on" else: print "the lights are off" var.trace_variable("w", showstate) root.mainloop() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor