[Tutor] Getting Started with Python
Hi all, I started going through the [Tutor] archives looking for resources on where to start. I have wanted to program for many years, but only just recently have made the time. I thought through different languages to start with: C, C# (My work uses .NET), Java, Python, Ruby, and others. I think I will still learn Java, but I have settled on putting most of my effort into Python first. So, where do I start? I have very little money for books, but I expect there are good resources on the web. My eventual goal is to write either a sci-fi rogue-like game or a rogue-like game engine that allows "anyone" to create their own. I have glanced at PyGame, and like what it can do, but I don't even really know many basics of programming. Anyway, Thanks for taking the time to read this. Oh, some background... I graduated College with a music degree and a music teaching credential. That led into, believe it or not, a night job doing internet tech support, then a full time customer service manager at the same company, then help desk support at a non-profit, then help desk at a for profit Anyway, I'm a teacher by schooling, a computer tech by learning, and a programmer by yearning. :) Ok enough... Thanks for your time. Will -- Will Shattuck ( willshattuck.at.gmail.com ) Home Page: http://www.thewholeclan.com/will When you get to your wit's end, you'll find God lives there. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Getting Started with Python
Hi Will, do a search in the archives, plenty of similar discussions, even just few days ago. Try http://wiki.python.org/moin/BeginnersGuide/NonProgrammers (Admins: consider sending a welcome message on the subscription to each newcomer specifying usually recommended sources.) > just recently have made the time. I thought through different > languages to start with: C, C# (My work uses .NET), Java, Python, Once you learn the basics, look for Python for .NET, IronPython, http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=IronPython&ReleaseId=423. I'm not sure how it measures up to C# nor whether it would be usable in your work, but seems you could kill two flies in one hit that way. -- Tom, http://www.vscripts.net/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] howto keep a program organised?
Hello All, I have been programming with Python for a few weeks now. By now I have problems keeping my program organised. (program runs from a Linux Busybox environment). For example, I may need to mount the usb storage device at some point in the program. For this end I made the following functions: - usbMount() -> main function. - usbUmount() -> main function. - usbMounted() -> help function. Checks if usb already mounted. - usbConnected() -> help function. Checks id usb connected to computer. - usbValid() -> help function. Checks if usb contains certain info (only these may be mounted). The help functions are called from the main functions. So I have multiple help functions, while only two are actively called. What is a good way to keep this organised? - Just put it in a usb.py module? - Should I make a class? I haven't worked with OOP before, because I didn't think it would be useful so far. Are there any advantages if I put this in a class, instead of in a module? This is only a small example, but I run into the same problem with other parts of my program, that are larger, and where the functions also depend on each other, while only a few are called (and the rest just clutter my view in the IDE). Any advice about how you organise this kind of things, is very much appreciated. Thanks, Rob ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Getting Started with Python
tomd wrote: > Hi Will, > > do a search in the archives, plenty of similar discussions, even just > few days ago. Try http://wiki.python.org/moin/BeginnersGuide/NonProgrammers > > (Admins: consider sending a welcome message on the subscription to > each newcomer specifying usually recommended sources.) Good idea! I just added this text to the welcome message: There are many on-line resources that can help you get started with Python. See the http://wiki.python.org/moin/BeginnersGuide/NonProgrammers";>Beginners Guide for a list of some good ones. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] howto keep a program organised?
Hi Rob, > For example, I may need to mount the usb storage device at some > point > in the program. > For this end I made the following functions: > - usbMount() -> main function. > - usbUmount() -> main function. > - usbMounted() -> help function. Checks if usb already mounted. > - usbConnected() -> help function. Checks id usb connected to > computer. > - usbValid() -> help function. Checks if usb contains certain info > (only these may be mounted). > The help functions are called from the main functions. > So I have multiple help functions, while only two are actively > called. > > What is a good way to keep this organised? > - Just put it in a usb.py module? Thats a very good place to start. > - Should I make a class? I think, without seeing the internals of the code, that this is likely to be a good idea in this case. If you have a number of shared global variables between functions then I'd certainly say yes. > Are there any advantages if I put this in a class, instead of in a > module? The advantage of a class is that if you ever need more than one USB device mounted then the instances of the class can each hold their own state information, whereas with global variables you would be limited to one mounted instance - unless you stuck very rigorously to functional programming principles... > This is only a small example, but I run into the same problem with > other parts of my program, that are larger, and where the functions > also depend on each other, while only a few are called (and the rest > just clutter my view in the IDE). Where things depend on each other a module is the minimum organising device. Where functions share data a class is usually a good idea on top of that. Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 31, Issue 26
Hi,My thought is seperate main and utility functions to different files.For example there will be a Main.py and UsbUtil.py and from Main.pyyou can import usb functions. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] howto keep a program organised?
Thanks Alan, The functions do not share variables, I don't use global vars, and I don't need a new instance. So in my case the only use of a class would be that all related usb code will be grouped together, even though I do not need any of the Class special abilities, as far as I understand. I think I will make a usb class to keep it better organised. I have attached the module that contains the usb and related code, to give a better view of what I'm talking, and I would appreciate any feedback on it. Thanks, Rob On 9/11/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > Hi Rob, > > > For example, I may need to mount the usb storage device at some > > point > > in the program. > > For this end I made the following functions: > > - usbMount() -> main function. > > - usbUmount() -> main function. > > - usbMounted() -> help function. Checks if usb already mounted. > > - usbConnected() -> help function. Checks id usb connected to > > computer. > > - usbValid() -> help function. Checks if usb contains certain info > > (only these may be mounted). > > The help functions are called from the main functions. > > So I have multiple help functions, while only two are actively > > called. > > > > What is a good way to keep this organised? > > - Just put it in a usb.py module? > > Thats a very good place to start. > > > - Should I make a class? > > I think, without seeing the internals of the code, that this is > likely to be a good idea in this case. If you have a number of > shared global variables between functions then I'd certainly > say yes. > > > Are there any advantages if I put this in a class, instead of in a > > module? > > The advantage of a class is that if you ever need more than > one USB device mounted then the instances of the class can > each hold their own state information, whereas with global > variables you would be limited to one mounted instance > - unless you stuck very rigorously to functional programming > principles... > > > This is only a small example, but I run into the same problem with > > other parts of my program, that are larger, and where the functions > > also depend on each other, while only a few are called (and the rest > > just clutter my view in the IDE). > > Where things depend on each other a module is the minimum > organising device. Where functions share data a class is usually > a good idea on top of that. > > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] howto keep a program organised?
Rob Vogel wrote: > Thanks Alan, > > The functions do not share variables, I don't use global vars, and I > don't need a new instance. > So in my case the only use of a class would be that all related usb > code will be grouped together, even though I do not need any of the > Class special abilities, as far as I understand. All good reasons *not* to make a class. A module is a fine way to group related code together. > > I think I will make a usb class to keep it better organised. Grouping the usb code in a module accomplishes all the organization you need, from what you have said. It sounds like putting it in a class just adds needless complexity. > > I have attached the module that contains the usb and related code, to > give a better view of what I'm talking, and I would appreciate any > feedback on it. The attachment didn't make it to the list... Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] howto keep a program organised?
> The functions do not share variables, I don't use global vars, and I > don't need a new instance. In that case you don't need a class. A module should do all you need by providing a common namespace for your functions. > So in my case the only use of a class would be that all related usb > code will be grouped together, even though I do not need any of the > Class special abilities, as far as I understand. A module groups code together nicely, if the code doesn't share data and you don't create multiple instances there is no need for a class. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] howto keep a program organised?
Thanks for the info. I will use a module. Regards, Rob On 9/11/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > The functions do not share variables, I don't use global vars, and I > > don't need a new instance. > > In that case you don't need a class. > A module should do all you need by providing a common namespace > for your functions. > > > So in my case the only use of a class would be that all related usb > > code will be grouped together, even though I do not need any of the > > Class special abilities, as far as I understand. > > A module groups code together nicely, if the code doesn't share data > and you don't create multiple instances there is no need for a class. > > Alan G. > > ___ > 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] man pages parsing (still)
I'm still there, trying to parse man pages (I want to gather a list of all options with their help strings). I've tried to use regex on both the formatted output of man and the source troff files and I discovered what is already said in the doclifter man page: you have to do a number of hints, and it's really not simple. So I'm know using doclifter, and it's working, but is terribly slow. Doclifter itself take around a second to parse the troff file, but my few lines of code take 25 seconds to parse the resultant xml. I've pasted the code at http://pastebin.ca/166941 and I'd like to hear from you how I could possibly optimize it. Thanks, Tiago. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
Tiago Saboga wrote: > I'm still there, trying to parse man pages (I want to gather a list of all > options with their help strings). I've tried to use regex on both the > formatted output of man and the source troff files and I discovered what is > already said in the doclifter man page: you have to do a number of hints, and > it's really not simple. So I'm know using doclifter, and it's working, but is > terribly slow. Doclifter itself take around a second to parse the troff file, > but my few lines of code take 25 seconds to parse the resultant xml. I've > pasted the code at http://pastebin.ca/166941 > and I'd like to hear from you how I could possibly optimize it. How big is the XML? 25 seconds is a long time...I would look at cElementTree (implementation of ElementTree in C), it is pretty fast. http://effbot.org/zone/celementtree.htm In particular iterparse() might be helpful: http://effbot.org/zone/element-iterparse.htm I would also try specifying a buffer size in the call to os.popen2(), if the I/O is unbuffered or the buffer is small that might be the bottleneck. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
Em Segunda 11 Setembro 2006 11:15, Kent Johnson escreveu: > Tiago Saboga wrote: > > I'm still there, trying to parse man pages (I want to gather a list of > > all options with their help strings). I've tried to use regex on both the > > formatted output of man and the source troff files and I discovered what > > is already said in the doclifter man page: you have to do a number of > > hints, and it's really not simple. So I'm know using doclifter, and it's > > working, but is terribly slow. Doclifter itself take around a second to > > parse the troff file, but my few lines of code take 25 seconds to parse > > the resultant xml. I've pasted the code at http://pastebin.ca/166941 > > and I'd like to hear from you how I could possibly optimize it. > > How big is the XML? 25 seconds is a long time...I would look at > cElementTree (implementation of ElementTree in C), it is pretty fast. > http://effbot.org/zone/celementtree.htm It's about 10k. Hey, it seems easy, but I'd like not to start over again. Of course, if it's the only solution... 25 (28, in fact, for the cp man page) isn't really acceptable. > In particular iterparse() might be helpful: > http://effbot.org/zone/element-iterparse.htm Ok, I'll look that. > I would also try specifying a buffer size in the call to os.popen2(), if > the I/O is unbuffered or the buffer is small that might be the bottleneck. What's appropriate in that case? I really don't understand how I should determine a buffer size. Any pointers? Thanks, Tiago. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
Tiago Saboga wrote: > Em Segunda 11 Setembro 2006 11:15, Kent Johnson escreveu: >> Tiago Saboga wrote: >> How big is the XML? 25 seconds is a long time...I would look at >> cElementTree (implementation of ElementTree in C), it is pretty fast. >> http://effbot.org/zone/celementtree.htm > > It's about 10k. Hey, it seems easy, but I'd like not to start over again. Of > course, if it's the only solution... 25 (28, in fact, for the cp man page) > isn't really acceptable. That's tiny! No way it should take 25 seconds to parse a 10k file. Have you tried saving the file separately and parsing from disk? That would help determine if the interprocess pipe is the problem. > >> I would also try specifying a buffer size in the call to os.popen2(), if >> the I/O is unbuffered or the buffer is small that might be the bottleneck. > > What's appropriate in that case? I really don't understand how I should > determine a buffer size. Any pointers? To tell the truth I don't use popen myself so if anyone else wants to chime in that would be fine...but I would try maybe 1024 or 10240 (10k). Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
Em Segunda 11 Setembro 2006 12:24, Kent Johnson escreveu: > Tiago Saboga wrote: > > Em Segunda 11 Setembro 2006 11:15, Kent Johnson escreveu: > >> Tiago Saboga wrote: > >> How big is the XML? 25 seconds is a long time...I would look at > >> cElementTree (implementation of ElementTree in C), it is pretty fast. > >> http://effbot.org/zone/celementtree.htm > > > > It's about 10k. Hey, it seems easy, but I'd like not to start over again. > > Of course, if it's the only solution... 25 (28, in fact, for the cp man > > page) isn't really acceptable. > > That's tiny! No way it should take 25 seconds to parse a 10k file. > > Have you tried saving the file separately and parsing from disk? That > would help determine if the interprocess pipe is the problem. Just tried, and - incredible - it took even longer: 46s. But in the second run it came back to 25s. I really don't understand what's going on. I did some other tests, and I found that all the code before "parser.parse(stout)" runs almost instantly; it then takes all the running somewhere between this call and the first event; and the rest is almost instantly again. Any ideas? By the way, I've read the pages you indicated at effbot, but I don't see where to begin. Do you know of a gentler introduction to this module (cElementTree)? Thanks, Tiago. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
Tiago Saboga wrote: > Em Segunda 11 Setembro 2006 12:24, Kent Johnson escreveu: >> Tiago Saboga wrote: >>> Em Segunda 11 Setembro 2006 11:15, Kent Johnson escreveu: Tiago Saboga wrote: How big is the XML? 25 seconds is a long time...I would look at cElementTree (implementation of ElementTree in C), it is pretty fast. http://effbot.org/zone/celementtree.htm >>> It's about 10k. Hey, it seems easy, but I'd like not to start over again. >>> Of course, if it's the only solution... 25 (28, in fact, for the cp man >>> page) isn't really acceptable. >> That's tiny! No way it should take 25 seconds to parse a 10k file. >> >> Have you tried saving the file separately and parsing from disk? That >> would help determine if the interprocess pipe is the problem. > > Just tried, and - incredible - it took even longer: 46s. But in the second > run > it came back to 25s. I really don't understand what's going on. I did some > other tests, and I found that all the code before "parser.parse(stout)" runs > almost instantly; it then takes all the running somewhere between this call > and the first event; and the rest is almost instantly again. Any ideas? What did you try, buffering or reading from a file? If parsing from a file takes 25 secs, I am amazed... > > By the way, I've read the pages you indicated at effbot, but I don't see > where > to begin. Do you know of a gentler introduction to this module > (cElementTree)? The main ElementTree page is here, but try parsing from a file first, your file is so small... http://effbot.org/zone/element.htm Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Injecting Data into XML Files
I am wrestling with the incredibly vast array of XML parsing and writing documentation, and I'm not seeing (or perhaps not understanding) what I'm looking for. Here's the situation: I have a large number of XML documents to add data to. They are currently skeletal documents, looking like this: http://www.w3.org/1999/02/22-rdf-syntax-ns#";> ... What I want is to open each document and inject some data between specific sets of tags. I've been able to parse these documents, but I am not seeing how to inject data between tags so I can write it back to the file. Any pointers are appreciated. Thanks. -- yours, William ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Injecting Data into XML Files
On Mon, Sep 11, 2006 at 12:11:37PM -0400, William O'Higgins Witteman wrote: > I am wrestling with the incredibly vast array of XML parsing and writing > documentation, and I'm not seeing (or perhaps not understanding) what > I'm looking for. Here's the situation: > > I have a large number of XML documents to add data to. They are > currently skeletal documents, looking like this: > > > > http://www.w3.org/1999/02/22-rdf-syntax-ns#";> > > > > ... > > What I want is to open each document and inject some data between > specific sets of tags. I've been able to parse these documents, but I am > not seeing how to inject data between tags so I can write it back to the > file. Any pointers are appreciated. Thanks. *How* did you parse your XML document? If you parsed it and produced a minidom tree or, better yet, an ElementTree tree, you can modify the DOM tree, and then you can write that tree out to disk. Here is a bit of code to give you the idea with ElementTree (or lxml, which uses the same API as ElementTree): from elementtree import ElementTree as etree doc = etree.parse('content.xml') root = doc.getroot()) # Do something with the DOM tree here. o o o # Now write the tree back to disk. f = open('tmp.xml', 'w') doc.write(f) f.close() Here is info on ElementTree -- Scroll down and look at the example in the section titled "Usage", which seems to do something very similar to what you ask about: http://effbot.org/zone/element-index.htm And, lxml -- same API as ElementTree plus additional capabilities, but requires installation of libxml: http://codespeak.net/lxml/ Also, minidom: http://docs.python.org/lib/module-xml.dom.minidom.html Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Injecting Data into XML Files
On Mon, Sep 11, 2006 at 09:57:28AM -0700, Dave Kuhlman wrote: >On Mon, Sep 11, 2006 at 12:11:37PM -0400, William O'Higgins Witteman wrote: >> I have a large number of XML documents to add data to. They are >> currently skeletal documents, looking like this: >> >> >> >> http://www.w3.org/1999/02/22-rdf-syntax-ns#";> >> >> >> >> ... >> >> What I want is to open each document and inject some data between >> specific sets of tags. I've been able to parse these documents, but I am >> not seeing how to inject data between tags so I can write it back to the >> file. Any pointers are appreciated. Thanks. >*How* did you parse your XML document? If you parsed it and >produced a minidom tree or, better yet, an ElementTree tree, >you can modify the DOM tree, and then you can write that tree out >to disk. I have tried the common XML modules - minidom, sax and ElementTree. There are clear, easy-to-follow examples of parsing for each one. >Here is a bit of code to give you the idea with ElementTree (or >lxml, which uses the same API as ElementTree): > >from elementtree import ElementTree as etree >doc = etree.parse('content.xml') >root = doc.getroot() ># Do something with the DOM tree here. >o This is the bit I'm missing - I can't seem to find an existing element and change it's value. When I do so I just get an additional element. Here's the code I'm using: main = etree.SubElement(root,"rdf:Description") title = etree.SubElement(main,"title") title.text = "Example Title" >o ># Now write the tree back to disk. >f = open('tmp.xml', 'w') >doc.write(f) >f.close() > >Here is info on ElementTree -- Scroll down and look at the example >in the section titled "Usage", which seems to do something very >similar to what you ask about: > >http://effbot.org/zone/element-index.htm This is, I suspect, a fine module, but the documentation you mention is not helpful to me. Specifically, in the above-mentioned section, it reads like this: # if you need the root element, use getroot root = tree.getroot() # ...manipulate tree... What I need is an example or a clear description of what they mean when they write "manipulate tree". My problem is not "which tool to use?" but "how does it work?". Thanks for the help thusfar - one last push would be greatly appreciated. Thanks again. -- yours, William ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Injecting Data into XML Files
William O'Higgins Witteman wrote: > On Mon, Sep 11, 2006 at 09:57:28AM -0700, Dave Kuhlman wrote: >> On Mon, Sep 11, 2006 at 12:11:37PM -0400, William O'Higgins Witteman wrote: >>> I have a large number of XML documents to add data to. They are >>> currently skeletal documents, looking like this: >>> >>> >>> >>> http://www.w3.org/1999/02/22-rdf-syntax-ns#";> >>> >>> >>> >>> ... >>> >>> What I want is to open each document and inject some data between >>> specific sets of tags. I've been able to parse these documents, but I am >>> not seeing how to inject data between tags so I can write it back to the >>> file. Any pointers are appreciated. Thanks. > >> Here is a bit of code to give you the idea with ElementTree (or >> lxml, which uses the same API as ElementTree): >> >>from elementtree import ElementTree as etree >>doc = etree.parse('content.xml') >>root = doc.getroot() >># Do something with the DOM tree here. >>o > > This is the bit I'm missing - I can't seem to find an existing element > and change it's value. When I do so I just get an additional element. > Here's the code I'm using: > > main = etree.SubElement(root,"rdf:Description") > title = etree.SubElement(main,"title") > title.text = "Example Title" That's what SubElement does - it creates a new element. You need to find the existing element. The section on Searching should point you in the right direction: http://effbot.org/zone/element.htm#searching-for-subelements Try something like title = root.find('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description/title') Note that ET uses the URI of the namespace, not the short name. You can explore a bit from the interactive interpreter to help get your bearings, for example print root for sub in root: print sub will give you a good idea what the correct name of the Description element. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Injecting Data into XML Files
On Mon, Sep 11, 2006 at 02:38:46PM -0400, Kent Johnson wrote: >>>On Mon, Sep 11, 2006 at 12:11:37PM -0400, William O'Higgins Witteman >>>wrote: What I want is to open each document and inject some data between specific sets of tags. I've been able to parse these documents, but I am not seeing how to inject data between tags so I can write it back to the file. Any pointers are appreciated. Thanks. >> >>>Here is a bit of code to give you the idea with ElementTree (or >>>lxml, which uses the same API as ElementTree): >>> >>> from elementtree import ElementTree as etree >>> doc = etree.parse('content.xml') >>> root = doc.getroot() >>> # Do something with the DOM tree here. >>> o >> >>This is the bit I'm missing - I can't seem to find an existing element >>and change it's value. >That's what SubElement does - it creates a new element. You need to find >the existing element. The section on Searching should point you in the >right direction: >http://effbot.org/zone/element.htm#searching-for-subelements > >Try something like >title = >root.find('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description/title') > >Note that ET uses the URI of the namespace, not the short name. That's a huge help, thank you. What would I do if there is no namespace for the given documents? I find that a great deal of "XML" content is just well-formed ad-hoc-ery, lacking formal definitions and namespaces, and so there is no URI to put in the find argument. Do I have to find a new module? Thanks again. -- yours, William ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Injecting Data into XML Files
William O'Higgins Witteman wrote: > On Mon, Sep 11, 2006 at 02:38:46PM -0400, Kent Johnson wrote: >> Note that ET uses the URI of the namespace, not the short name. > > That's a huge help, thank you. What would I do if there is no namespace > for the given documents? I find that a great deal of "XML" content is > just well-formed ad-hoc-ery, lacking formal definitions and namespaces, > and so there is no URI to put in the find argument. Do I have to find a > new module? Thanks again. I think it will just parse as the tag name in that case; try it and see! If you have truly bad XML - that is not well-formed so it won't parse with a correct parser - then you need BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/documentation.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
Em Segunda 11 Setembro 2006 12:59, Kent Johnson escreveu: > Tiago Saboga wrote: > > Em Segunda 11 Setembro 2006 12:24, Kent Johnson escreveu: > >> Tiago Saboga wrote: > >>> Em Segunda 11 Setembro 2006 11:15, Kent Johnson escreveu: > Tiago Saboga wrote: > How big is the XML? 25 seconds is a long time...I would look at > cElementTree (implementation of ElementTree in C), it is pretty fast. > http://effbot.org/zone/celementtree.htm > >>> > >>> It's about 10k. Hey, it seems easy, but I'd like not to start over > >>> again. Of course, if it's the only solution... 25 (28, in fact, for the > >>> cp man page) isn't really acceptable. > >> > >> That's tiny! No way it should take 25 seconds to parse a 10k file. > >> > >> Have you tried saving the file separately and parsing from disk? That > >> would help determine if the interprocess pipe is the problem. > > > > Just tried, and - incredible - it took even longer: 46s. But in the > > second run it came back to 25s. I really don't understand what's going > > on. I did some other tests, and I found that all the code before > > "parser.parse(stout)" runs almost instantly; it then takes all the > > running somewhere between this call and the first event; and the rest is > > almost instantly again. Any ideas? > > What did you try, buffering or reading from a file? If parsing from a > file takes 25 secs, I am amazed... I read from a file, and before you ask, no, I'm not working in a 286 and compiling my kernel at the same time... ;-) In fact, I decided to strip down both my code and the xml file. I've stripped the code to almost nothing, having yet a 23s time. And the same with the xml file... until I cut out the second line, with the dtd [1]. And surprise: I've a nice time. So I put it all together again, but have the following caveat: there's an error that did not raise previously:] Traceback (most recent call last): File "./liftopy.py", line 130, in ? parser.parse(stout) File "/usr/lib/python2.3/site-packages/_xmlplus/sax/expatreader.py", line 109, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/lib/python2.3/site-packages/_xmlplus/sax/xmlreader.py", line 123, in parse self.feed(buffer) File "/usr/lib/python2.3/site-packages/_xmlplus/sax/expatreader.py", line 220, in feed self._err_handler.fatalError(exc) File "/usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: /home/tiago/Computador/python/opy/manraw/doclift/cp.1.xml.stripped:279:16: undefined entity Ok, the guilty line (279) has a "©" that was probably defined in the dtd, but as it doesn't know what is the right dtd... But wait... How does python read the dtd? It fetches it from the net? I tried it (disconnected) and the answer is yes, it fetches it from the net. So that's the problem! But how do I avoid it? I'll search. But if you can spare me some time, you'll make me a little happier. [1] - The line is as follows: http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd";> Thanks! Tiago. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Java: (and python ?) nearer measles than coffee
Sometimes I have also some - or more - problems trying digesting python and feeling totally blocked. My programming experience (beginning at the card-reader era) main-frame, mini and micro : Bit / Byte / Word system-programming via switch-console followed by Assembler and commercial software using Basic, Cobol, Pascal and SQL. Mnemonic programming-language - in my understanding - can only be consisting of expressions near the human language. The best example for writing non-system-programms are Basic, Cobol (thanks to Alan) and SQL(especially Informix-SQL as full language - not only for DB). Why should I waste time in learning a "language" like Java (or more positive: python) ? Nevertheless this Tutor Digest is most helpful, the number of questions / problems show: some more people are looking for a mnemonic-language which should optimized cross-compile to something with multiplatform-capability like Java. Please let me know, if I am entirely wrong. Klaus Ramelow ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Java: (and python ?) nearer measles than coffee
Klaus Ramelow wrote: > Sometimes I have also some - or more - problems trying digesting python > and feeling totally blocked. > > My programming experience (beginning at the card-reader era) > main-frame, mini and micro : > Bit / Byte / Word system-programming via switch-console followed by > Assembler and commercial software using Basic, Cobol, Pascal and SQL. > > Mnemonic programming-language - in my understanding - can only be > consisting of expressions near the human language. > The best example for writing non-system-programms are > Basic, Cobol (thanks to Alan) and SQL(especially Informix-SQL as full > language - not only for DB). > Why should I waste time in learning a "language" like Java (or more > positive: python) ? > Nevertheless this Tutor Digest is most helpful, the number of questions > / problems show: > some more people are looking for a mnemonic-language which should > optimized cross-compile to something with multiplatform-capability > like Java. > Please let me know, if I am entirely wrong. I'm not really sure what you are asking. Many people find Python to be useful and enjoyable for a wide variety of personal and professional programming. But if you are happy with Basic and Cobol and they meet your needs then there is no need to "waste your time" learning anything else, I suppose. I am not really interested in trying to convince you to learn python; if you decide you want to learn this list is a great place to get help. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Java: (and python ?) nearer measles than coffee
Hrmmm...my opinion is that you shouldn't waste your time with Java (sorry to any Java coders on this list). It's entirely too automated for my tastes (automatic garbage collection, transparent pointers, etc...). To quote an unknown author who was quite the anti-OOP programmer, "it made me want to throw a java.f***ThisException". So why, might you ask, am I bothering learning Python? Well, at first I was looking for a powerful scripting language to prototype with. You know the routine...whip up a quick and dirty "version 0.1" and let the customer see what's in store, test layouts, algorithms, design ideas, etc... Reason I use Python #1: But then I noticed something. Python runs on my wife's Windows machine...and my Linux machine...and my OpenBSD machine...and ...etc... The real catch for me was OpenBSD support. Find a thorough java runtime for OpenBSD (I last looked probably a year or two ago, so correct me if I'm wrong on this), and perhaps I'll try it out, but until then, Python is my choice when I need code that will run on multiple OS's. Reason I use Python #2: I'm not trying to flatter anyone, seriously, I'm not...but this list is another reason Python has been a favorite of mine. Reason I use Python #3: I am a strong advocate of Open Source Software and the GPL. If Sun truly supported Open Source, then the OpenBSD team would have the specs for Java. Reason I use Python #4: If I want to code something in Java, give me a week. For Python, give me one night, perhaps two. I prefer getting done so I can move on, ya know? Anyways, those are the first few reasons I use Python. Jonathon Klaus Ramelow wrote: > Sometimes I have also some - or more - problems trying digesting python > and feeling totally blocked. > > My programming experience (beginning at the card-reader era) > main-frame, mini and micro : > Bit / Byte / Word system-programming via switch-console followed by > Assembler and commercial software using Basic, Cobol, Pascal and SQL. > > Mnemonic programming-language - in my understanding - can only be > consisting of expressions near the human language. > The best example for writing non-system-programms are > Basic, Cobol (thanks to Alan) and SQL(especially Informix-SQL as full > language - not only for DB). > Why should I waste time in learning a "language" like Java (or more > positive: python) ? > Nevertheless this Tutor Digest is most helpful, the number of questions > / problems show: > some more people are looking for a mnemonic-language which should > optimized cross-compile to something with multiplatform-capability > like Java. > Please let me know, if I am entirely wrong. > > Klaus Ramelow > > ___ > 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] Traversing Excel Columns
This is what I have, but it requires me to know the end of the column I'm working with, which changes. try:#Loop through the rows from 6 -> 25 for row in range(6, 25): #Write each row, increment 1+row in column 5 print >> file, "(%d) => %s" % (row, xlSht.Cells (1+row, 5).Value) I'm looking for something more like try:#Loop until rows are null while row in xlwksht != null #Write each row, incriment 1+row in column 5 print >> file, "'" + %s + "',", % (xlSht.Cells(1+row,5).Value) Maybe someone already tackled this? Or am I over thinking this problem? Thanks. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traversing Excel Columns
Chris Hengge wrote: > This is what I have, but it requires me to know the end of the column > I'm working with, which changes. > > try:#Loop through the rows from 6 -> 25 > for row in range(6, 25): > #Write each row, increment 1+row in column 5 > print >> file, "(%d) => %s" % (row, xlSht.Cells (1+row, 5).Value) > > I'm looking for something more like > try:#Loop until rows are null > while row in xlwksht != null > #Write each row, incriment 1+row in column 5 > print >> file, "'" + %s + "',", % (xlSht.Cells(1+row,5).Value) What is xlSht? Are you using COM, or xlrd, or pycelerator, or?? to read the spreadsheet? It probably has a way to find out the last row, or if the cell has data... Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traversing Excel Columns
I'm no expert in Excel programming but I assum,e you tried the obvious: > I'm looking for something more like > try:#Loop until rows are null >while row in xlwksht != null > #Write each row, incriment 1+row in column 5 > print >> file, "'" + %s + "',", % > (xlSht.Cells(1+row,5).Value) for row in xlSht.Cells: print >> file, row.Value I know you can do something similar in VBScript, I'm not sure if the Python bindinghs to the COM objects are gtthat clever however. But might be worth some experimenting at the >>> prompt. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traversing Excel Columns
from win32com.client import Dispatch soo... that would be com.. sorry about that.. xlSht is the worksheet I'm currently reading from. On 9/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Chris Hengge wrote:> This is what I have, but it requires me to know the end of the column> I'm working with, which changes. >> try:#Loop through the rows from 6 -> 25> for row in range(6, 25):> #Write each row, increment 1+row in column 5> print >> file, "(%d) => %s" % (row, xlSht.Cells (1+row, 5).Value)>> I'm looking for something more like> try:#Loop until rows are null> while row in xlwksht != null> #Write each row, incriment 1+row in column 5 > print >> file, "'" + %s + "',", % (xlSht.Cells(1+row,5).Value)What is xlSht? Are you using COM, or xlrd, or pycelerator, or?? to readthe spreadsheet? It probably has a way to find out the last row, or if the cell has data...Kent___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traversing Excel Columns
Just tried that (pretty sure I already did, but hey... I could have goofed it) No go On 9/11/06, Alan Gauld <[EMAIL PROTECTED]> wrote: I'm no expert in Excel programming but I assum,e you triedthe obvious:> I'm looking for something more like > try:#Loop until rows are null>while row in xlwksht != null> #Write each row, incriment 1+row in column 5> print >> file, "'" + %s + "',", %> ( xlSht.Cells(1+row,5).Value)for row in xlSht.Cells: print >> file, row.ValueI know you can do something similar in _vbscript_, I'm not sureif the Python bindinghs to the COM objects are gtthat clever however. But might be worth some experimenting at the >>> prompt.Alan G.___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
Tiago Saboga wrote: > Ok, the guilty line (279) has a "©" that was probably defined in the > dtd, > but as it doesn't know what is the right dtd... But wait... How does python > read the dtd? It fetches it from the net? I tried it (disconnected) and the > answer is yes, it fetches it from the net. So that's the problem! > > But how do I avoid it? I'll search. But if you can spare me some time, you'll > make me a little happier. > > [1] - The line is as follows: > "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd";> I'm just guessing, but I think if you find the right combination of handlers and feature settings you can at least make it just pass through the external entities without looking up the DTDs. Take a look at these pages for some hints: http://www.cafeconleche.org/books/xmljava/chapters/ch07s02.html#d0e10350 http://www.cafeconleche.org/books/xmljava/chapters/ch06s11.html They are talking about Java but the SAX interface is a cross-language standard so the names and semantics should be the same. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Java: (and python ?) nearer measles than coffee
>> some more people are looking for a mnemonic-language which should >> optimized cross-compile to something with multiplatform-capability like >> Java. Please let me know, if I am entirely wrong. > > I'm not really sure what you are asking. Many people find Python to be > useful and enjoyable for a wide variety of personal and professional > programming. But if you are happy with Basic and Cobol and they meet > your needs then there is no need to "waste your time" learning anything > else, I suppose. I want to support Kent in this. We're not language bigots. (In fact, I'm not really much of a Python programmer at the moment. *grin*) I have no idea what a mnemonic language should be: perhaps you're talking about domain-specific languages in the sense discussed in: http://www.ddj.com/184405575 In which case, one argument for learning Python or any other general purpose language is to know the necessary tools to write the domain-specific language you want. That is, the point of a general purpose language is to "bootstrap": to give us enough tools to build our way up to the domain. If someone's already done that work, then yes, of course, use the domain-specific language. If I'm doing some kind of simple text processing, then Perl's probably a good choice, because that language has a lot of built-in support for text munging. If I need to do something with database management, I'd be silly if I didn't take a close look at an SQL implementation first. But if I'm writing a simulator for elevator systems, I might be in for some work. It's unlikely that someone has written a domain-specific language for ascending platforms, and I'm probably going to have to bootstrap my way up from a general purpose language (like Python or Perl or Ruby or Java or Scheme or ...) so that I can eventually talk about the problem in the natural terms of my domain. And if a language helps me claw up that much more quickly, then that's a very good reason for me to learn that new language. That's the claim of high-level, general purpose languages: we don't learn them just for their own sake, but because they help us build the tools we need to get to the real interesting problems. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
> terribly slow. Doclifter itself take around a second to parse the troff > file, but my few lines of code take 25 seconds to parse the resultant > xml. I've pasted the code at http://pastebin.ca/166941 and I'd like to > hear from you how I could possibly optimize it. Hi Tiago, Before we go any further: have you run your program through the Python profiler yet? Take a look at: http://docs.python.org/lib/profile.html and see if that can help isolate the slow sections in your program. If I really had to guess, without profiling information, I'd take a very close look at the characters() method: it's doing some string concatentation there that may have very bad performance, depending on the input. See: http://mail.python.org/pipermail/tutor/2004-August/031568.html and the thread around that time for details on why string concatentation should be treated carefully. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
Danny Yoo wrote: > If I really had to guess, without profiling information, I'd take a very > close look at the characters() method: it's doing some string > concatentation there that may have very bad performance, depending on the > input. See: > > http://mail.python.org/pipermail/tutor/2004-August/031568.html > > and the thread around that time for details on why string concatentation > should be treated carefully. Gee, Danny, it's hard to disagree with you when you quote me in support of your argument, but...the characters() method is probably called only once or twice per tag, and the string is reinitialized for each tag. So this seems unlikely to be the culprit. Course it helps that I have read to the end of the thread - the problem seems to be accessing the external DTD ;-) By the way that article of mine is obsoleted by Python 2.4, which optimizes string concatenation in a loop... http://www.python.org/doc/2.4.3/whatsnew/node12.html#SECTION000121 Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traversing Excel Columns
Hmm... ok... after some thought... this is what I'm looking for #some great line that gives me an int for the number of not null cells intLastUsedRow = xlSht.Cells.LastValue #Made this up, but basically what I need. I need to iterate through a range() because I dont know another good way to tell it not to use the column headings and other junk over the data I want to collect. try: #Loop through rows for row in range(5,intLastUsedRow): #Write each row, incriment 1+row in column 5 file.write(xlSht.Cells(1+row,5).Value) On 9/11/06, Alan Gauld <[EMAIL PROTECTED] > wrote: I'm no expert in Excel programming but I assum,e you triedthe obvious:> I'm looking for something more like > try:#Loop until rows are null>while row in xlwksht != null> #Write each row, incriment 1+row in column 5> print >> file, "'" + %s + "',", %> ( xlSht.Cells(1+row,5).Value)for row in xlSht.Cells: print >> file, row.ValueI know you can do something similar in _vbscript_, I'm not sureif the Python bindinghs to the COM objects are gtthat clever however. But might be worth some experimenting at the >>> prompt.Alan G.___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] encoding
watch this example: >>> a=['lula', 'cação'] >>> print a ['lula', 'ca\xc3\xa7\xc3\xa3o'] >>> print a[1] cação when i print the list the special characters are not printed correctly! But if i print only the list item that has the special charaters it runs OK. How do i get list print correctly? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] encoding
Jose P wrote: > watch this example: > a=['lula', 'cação'] print a > ['lula', 'ca\xc3\xa7\xc3\xa3o'] print a[1] > cação > > > when i print the list the special characters are not printed correctly! When you print a list, it uses repr() to format the contents of the list; when you print an item directly, str() is used. For a string containing non-ascii characters, the results are different. > > But if i print only the list item that has the special charaters it runs > OK. > > How do i get list print correctly? You will have to do the formatting your self. A simple solution might be for x in a: print x If you want exactly the list formatting you have to work harder. Try something like "['" + "', '".join([str(x) for x in a]) + "']" Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] urllib
Hi, I have used urllib and urllib2 to post data like the following: dict = {} dict['data'] = info dict['system'] = aname data = urllib.urlencode(dict) req = urllib2.Request(url) And to get the data, I emulated a web page with a submit button: s = "" s += "" s += "" s += "" s += "" s += "" I would like to know how to send a file. It's a text file that will be gzipped before being posted. I'm using python version 2.2.3. Thanks, Patricia ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] foreach loops
Does python have foreach loops? I don't see any mention of them in the docs. Am I going to have to use Perl (gasp!) if I want my beloved foreach loop? -Chris ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] man pages parsing (still)
> Gee, Danny, it's hard to disagree with you when you quote me in support > of your argument, but...the characters() method is probably called only > once or twice per tag, and the string is reinitialized for each tag. So > this seems unlikely to be the culprit. Ah, didn't see those; that'll teach me not to guess. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] foreach loops
> Does python have foreach loops? I don't see any mention of them in the > docs. Am I going to have to use Perl (gasp!) if I want my beloved > foreach loop? Can you show an example of a Perl foreach loop? Perhaps someone can help translate it into idiomatic Python. Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] foreach loops
Danny Yoo wrote: > >> Does python have foreach loops? I don't see any mention of them in the >> docs. Am I going to have to use Perl (gasp!) if I want my beloved >> foreach loop? >> > > Can you show an example of a Perl foreach loop? Perhaps someone can help > translate it into idiomatic Python. > It seems to me that foreach is the same as the python 'for' loop #-- perl code @myNames = ('Larry', 'Curly', 'Moe'); print "Who's on the list:\n"; foreach (@myNames) { print $_ . "\n"; } #--- python code: names = ['Larry','Curly','Moe'] print "Who's on the list?\n" for x in mynames: print x+'\n' # Am I missing the point here? -Luke > Good luck! > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] foreach loops
Hmmm...Perl is probably a bad example. My apologies. I was thinking more along the lines of this: A C++ for loop: #include using std::cout; int main() { for (int i = 0; i < 10; i++) { cout << i << "\n"; } return 0; } ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] foreach loops
Christopher Spears wrote: > Hmmm...Perl is probably a bad example. My apologies. > I was thinking more along the lines of this: > > A C++ for loop: > > #include > > using std::cout; > > int main() { > > for (int i = 0; i < 10; i++) { > cout << i << "\n"; > } > > return 0; > } > > for i in range(10): print i+'\n' that does the same thing as a = [0,1,2,3,4,5,6,7,8,9] for i in a: print i+'\n' or a = range(10) for i in a: print i+'\n' Python's 'for' loop is not really meant as an iterator over a list of numbers so this feature isn't built into the loop itself, you have to use the range function, which just generates a list of numbers to iterate over. Perhaps you should read an introductory Python tutorial. Any one of them should cover the types of questions that people from other languages have about Python. It sounds like you know how to program already, so the 'python for non-programmers' type of tutorial may not be best-suited to you, but just look around. If you have any more questions I'd be happy to answer them, as would the rest of the list, I'm sure. HTH, -Luke > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] foreach loops
Christopher Spears wrote: > Hmmm...Perl is probably a bad example. My apologies. > I was thinking more along the lines of this: > > A C++ for loop: > > #include > > using std::cout; > > int main() { > > for (int i = 0; i < 10; i++) { > cout << i << "\n"; > } > > return 0; > } > The same functionality can be provided using python for and the range() function, like: for i in range(0, 10): print i Though because of the way python works you don't need to use this type of loop anywhere near as often as in other languages. For example in java (and c++, but my c++ is so rusty I'm not going embarrass myself trying to write an example) you're constantly doing things like looping over an array: public void main(String[] args) { int[] foo; /* then later after foo has been initialized to whatever: */ for (int i=0; ihttp://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traversing Excel Columns
I don't suppose that anyone has a fix for me eh? I've tried about all I can think of and I'd like to be able to give this program a trial tomorrow when I get back to work.. sure would save me some time :] On Mon, 2006-09-11 at 17:48 -0700, Chris Hengge wrote: > Hmm... ok... after some thought... this is what I'm looking for > > #some great line that gives me an int for the number of not null cells > intLastUsedRow = xlSht.Cells.LastValue #Made this up, but basically > what I need. > > I need to iterate through a range() because I dont know another good > way to tell it not to use the column headings and other junk over the > data I want to collect. > > try: #Loop through rows > for row in range(5,intLastUsedRow): > #Write each row, incriment 1+row in column 5 > file.write(xlSht.Cells(1+row,5).Value) > > > On 9/11/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > I'm no expert in Excel programming but I assum,e you tried > the obvious: > > > I'm looking for something more like > > try:#Loop until rows are null > >while row in xlwksht != null > > #Write each row, incriment 1+row in column 5 > > print >> file, "'" + %s + "',", % > > ( xlSht.Cells(1+row,5).Value) > > for row in xlSht.Cells: >print >> file, row.Value > > I know you can do something similar in VBScript, I'm not sure > if the Python bindinghs to the COM objects are gtthat clever > however. > > But might be worth some experimenting at the >>> prompt. > > Alan G. > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traversing Excel Columns
On 12/09/06, Chris Hengge <[EMAIL PROTECTED]> wrote: > I don't suppose that anyone has a fix for me eh? I've tried about all I > can think of and I'd like to be able to give this program a trial > tomorrow when I get back to work.. sure would save me some time :] Will there be internal blanks? You could just scan for Cells(row, col).Value in (None, ''). Otherwise, run makepy.py (if you haven't already) on Excel, and then look through the code it generates. It will show you all the methods you can call, and what arguments they expect. Something may leap out at you. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor