[Tutor] Careful Dictionary Building
I'm building a dictionary from a list with ~ 1M records. Each record in the list is itself a list. Each record in the list has a line number, (index 0) which I wish to use as a dictionary key. The problem: It is possible for two different records in the list to share this line number. If they do, I want to append the record to the value in the dictionary. The obvious (lazy) method of searching for doubled lines requires building and parsing a key list for every record. There must be a better way! dict = {} for record in list if record[0] in dict.keys(): dict[ record[0] ].append( record ) else: dict[ record[0] ] = [record] Once you get ~ 80,000 records it starts slowing down pretty badly (I would too ...). Here's hoping there is a really fast, pythonic way of doing this! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Careful Dictionary Building
*sigh* Ignore folks. I had forgotten about .has_key(). On Dec 28, 2007 11:22 AM, doug shawhan <[EMAIL PROTECTED]> wrote: > I'm building a dictionary from a list with ~ 1M records. > > Each record in the list is itself a list. > Each record in the list has a line number, (index 0) which I wish to use > as a dictionary key. > > The problem: It is possible for two different records in the list to share > this line number. If they do, I want to append the record to the value in > the dictionary. > > The obvious (lazy) method of searching for doubled lines requires building > and parsing a key list for every record. There must be a better way! > > dict = {} > for record in list > if record[0] in dict.keys (): > dict[ record[0] ].append( record ) > else: > dict[ record[0] ] = [record] > > Once you get ~ 80,000 records it starts slowing down pretty badly (I would > too ...). > > Here's hoping there is a really fast, pythonic way of doing this! > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor] Careful Dictionary Building
Lots of very good answers to a pretty stupid question! *blush* I guess there is more than one way to do it! Uh ... guys? Did I say something wrong...? On Dec 28, 2007 12:23 PM, Tony *** <[EMAIL PROTECTED]> wrote: > Hello Doug, > > You can also use exceptions instead of the if /else. It has more of a > pythonic syntax to it, but I'm not sure about performance. > > try: >dict[ record[0] .append( record ) ] > except:KeyError > > dict[ record[0] ] = [record] > > > To help performance a bit, don't call dict.keys() on every iteration, > since you're invoking a function. > > dict = {} > allKeys =dict.Keys > for record in list > if record[0] in allKeys: > dict[ record[0] .append( record ) ] > else: > dict[ record[0] ] = [record] > allKeys = dict.Keys()# this function is > only invoked some of the time, not on every iteration > > > See how much this helps your performance. It may not be much, but a > little can help > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Scan Codes, Character Sets: Any Modules?
The difficulty I have may or may not be something that may be easily handled with pyserial and some other mystery module. I am attempting to screen scrape SuperDOS, an extremely closed system that uses wyse 60 terminals to communicate with a dos machine. I have not been able to communicate properly with superdos until trying the handy miniterm.py example from the pyserial package in conjunction with Markus Gutschke's wy60 emulator which translates input through an xterm into wyse 60 commands. These programs together allow me to interact with superdos pretty well ... with the exception of the arrow keys: for those I must fall back to the old cntl-letter combos to get the cursor to behave (actually cntl-letter x 2.. for some reason it likes an extra prod). This is fine, as now I have a way to debug my eventual script. My big problem is, I am completely unable to get SuperDos to respond to my carriage returns from within the script! I can watch the script work via miniterm.py. I have sent the return and newline characters in various combinations starting with "\n,\r", "\x0a\x0d", but they respond weirdly, putting the cursor *above* the existing command line, changing the cursor to an outline and generally letting me know that I am on the wrong track. Has some clever human alread created a handy module to handle wyse60 and other terminal emulation from within a python program? I have looked over the curses module, but it seems to be aimed at drawing proper screens for the user, not translation. PySerial's ability to suck up the output via readlines() is awesome, and I can see how I *think* it should all be done, but the weirdness has got me stymied! I am going to look at Mr. Gutscheke's source to see how he does it, but I am barely conversant in python and fear that exposure to that much C code may cause dizziness! Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unpack/regexp
I always slice the string in this sort of situation: s = "12345678901234567890123456789012 " t = s[:10],s[10:20],s[20:-1] print t ('1234567890', '1234567890', '123456789012') One could always bracket it to make a list or whatever. Hope this helps! On 4/11/06, Paul Kraus <[EMAIL PROTECTED]> wrote: Ok sorry for the perl refernce but I can't figure out how to do this.I have a fixed width text file i need to parse.so lets say I want an array to containt the pieces i need.if the fields I want are lengths from left to right. 10 10 1312345678901234567890123456789012I want to turn this into an array that has these elements.12345678901234567890123456789012 <--notice white spaceIn Perl its a simplemy @array = unpack ( "A10 A10 A13" , $line ) this extracts it and removes the whitespace after doing so.or if i wanted i could domy @array = ( $1, $2, $3 ) if ( $line =~ m/^(.{10})(.{10})(.{13}) )--Paul Kraus=-=-=-=-=-=-=-=-=-=-= PEL Supply CompanyNetwork Administrator216.267.5775 Voice216.267.6176 Faxwww.pelsupply.com=-=-=-=-=-=-=-=-=-=-=___ Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scan Codes, Character Sets: Any Modules?
Oho! http://www.wyse.com/service/support/kbase/Keydetl1.asp?Q=7&R=6 has the hex codes! Thanks! Perhaps this will fix what ails me.On 4/11/06, doug shawhan <[EMAIL PROTECTED]> wrote: Yeah, termca was were I looked first. The OpenBSD 3.8 termcap shows: :cr=^M:ct=\E0:dc=\EW:dl=\ER:do=^J:ds=\EF\r:ei=\Er:fs=^M:\ for the carriage return, but then I can't find the hex code for ^M! :-) At that point I thought I'd ask if there was some sort of termcapesque module available. I will scope the wyse website again, perhaps I can locate it this time! ThanksOn 4/11/06, Alan Gauld < [EMAIL PROTECTED]> wrote: Hi Doug,> I am attempting to screen scrape SuperDOS, uses wyse 60 terminals> I must fall back to the old cntl-letter combos to get the cursor to behaveSounds like you need to find a tech spec for the Wyse 60. That should give you all of the Ctrl character combos to control the screen.If you have access to a Unix box you might find the info you needin the termcap or terminfo databases. But Wyse should have thespec sheet on their web site somewhere... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scan Codes, Character Sets: Any Modules?
No luck. I think I am missing something utterly basic, and completely unrelated to python. :-) I'll quit filling everyone's mailbox with cheese and move on to a terminal newsgroup for my future pesterances. Thanks for the help folks!On 4/11/06, doug shawhan <[EMAIL PROTECTED]> wrote: Oho! http://www.wyse.com/service/support/kbase/Keydetl1.asp?Q=7&R=6 has the hex codes! Thanks! Perhaps this will fix what ails me.On 4/11/06, doug shawhan < [EMAIL PROTECTED]> wrote: Yeah, termca was were I looked first. The OpenBSD 3.8 termcap shows: :cr=^M:ct=\E0:dc=\EW:dl=\ER:do=^J:ds=\EF\r:ei=\Er:fs=^M:\ for the carriage return, but then I can't find the hex code for ^M! :-) At that point I thought I'd ask if there was some sort of termcapesque module available. I will scope the wyse website again, perhaps I can locate it this time! ThanksOn 4/11/06, Alan Gauld < [EMAIL PROTECTED]> wrote: Hi Doug,> I am attempting to screen scrape SuperDOS, uses wyse 60 terminals> I must fall back to the old cntl-letter combos to get the cursor to behaveSounds like you need to find a tech spec for the Wyse 60. That should give you all of the Ctrl character combos to control the screen.If you have access to a Unix box you might find the info you needin the termcap or terminfo databases. But Wyse should have thespec sheet on their web site somewhere... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Raw Bits! (Control characters ahoy!)
I am in the middle of a project that requires me to send and retrieve information from a machine connected to a serial port. My problems are these: 1. I cannot send control characters 2. I cannot read data streaming from the serial port I have been doing fine with: os.system("echo '5' >/dev/tty00") os.system("echo '8' >/dev/tty00") and the like to the remote machine, but I need to be able to send control characters the same way to scroll through menus. I have tried pyserial and pexpect with mixed (mostly horrible) results (not the fault of the module builders!), thus far the simple act of echoing the strings to the serial port is the only reliable method I have found. Reading from the serial port has also been problematic. I find that simply opening the port /dev/tty00 file and using readlines(), read() or whatever gives me empty strings or lists. Pbth. So first: how should I go about adding the hex escape sequences (\x0a and \x50) to the above strings in their raw form? second: what method should I use to read a raw stream from the serial port for a given period? I have looked carefully at the neat and tidy miniterm.py example in the pyserial examples directory, and see how one can continuously read via a thread from the port, but have not been able to replicate it thus far. Any help whatsoever would be great! I'm beginning to feel a little lightheaded. Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Brain In Vice: Why is this so fun to me?
I think I'm going to have to suck it up and learn some regular expressions. I have finally gotten my script (using the excellent pyserial module) to behave. Most of my troubles as enumerated here before were utterly self-induced. Apparently one cannot watch the execution of one's script through another program without affecting it's outcome in unforseen ways. (Sound familiar Herr Schroedinger? :-) Now that I am actually extracting data in a fairly predictable way, I am at the point where I need to parse it! I have some output here (modified to show the ESC and NUL characters.) When I pull data from the port, the remote computer sends it in one long string per screen: newlines are not painted in by using the expected x\0a that I had hoped for! No easy readlines() fun for me. Instead I get: ESC=( 1. ESC=($4x2, 6-239 (3.9L) ..ESC=(a03252 ESC=(k0 ESC=) 2. ESC=))8-318 (5.2L) ..ESC=)a03242 ESC=)k0 ESC=* 3. ESC=*)8-360 (5.9L) ..ESC=*a03351 ESC=*k 0 ESC=+ 4. ESC=+$4x4, 6-239 (3.9L) ..ESC=+a03240 ESC=+k 0 ESC=, 5. ESC=,)8-318 (5.2L) ..ESC=,a03243 ESC=,k 0 ESC=- 6. ESC=-)8-360 (5.9L) ..ESC=-a03352 ESC=-k 0 ESC=. 7. ESC=.aCH8299 ESCTNULESC)NULESC=% LINEESCTNULESC=& R = RELIST = NONE I have broken it up for ease of viewing. I need to split the string where ESC= , k and 0 are found, but ESC= ,k and 0 are seperated by various spaces, parentheis and other characters that are apparently used to mark the end of the line until the next ESC is found, thereby displaying a new line (note how the character after the first ESC on each line is repeated after the ESC on the end. I cannot for the life of me figure out a pythonic way (read: using the split() builtin) to scan for instances of these characters in such and such order and proximity. I know this is what regex is for, but I have no experience. I have obtained a copy of "Mastering Regular Expressions" but thought I would inquire here first for caveats and tips as the book is larger than my brain, and I haven't used the re module, ever. Why in the world does this make me so happy? :-)~ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Brain In Vice: Why is this so fun to me?
That works wonderfully! Thanks!On 4/20/06, Liam Clarke <[EMAIL PROTECTED]> wrote: Trick is, to limit them very carefully by specifying what they are to match.Watch .* - I always use .*? myself.For instance, for one of your strings, which ends with the ESC=character>k(some whitespace or not)0 \x1b.*?0 would certainly match that, but it'd also match ESC foo ### # ESC=#k0Whereas \x1b\=.k\w*?0 would match it far more precisely, becausethat's the regex foresc=k0 *excluding \n unless the flag re.DOTALL is used.So yeah; something else to note, certain characters need to be escapedin regex strings.Namely, these ones - .^$*+?{[|( That second to last one is a pipe by the way, not an I.And * is very greedy, but a ? limits it's greediness greatly.Good luck,Liam ClarkeOn 4/21/06, doug shawhan <[EMAIL PROTECTED] > wrote:> I am discovering that. They tend to get all Ayn Rand on you and grab too> much. :-)>>> On 4/20/06, Liam Clarke <[EMAIL PROTECTED] > wrote:> > Yeah, Alan's tutorial is what I used to learn how to code, it's very good.> > Regexes are very powerful; which can be a very good thing and a very> > bad thing. ;)> > > > Good luck.> >> > On 4/20/06, doug shawhan <[EMAIL PROTECTED]> wrote:> > > Got it! Thanks! Mr. Gald hooked me up with his re tutorial as well. > Great!> > >> > >> > > On 4/19/06, Liam Clarke <[EMAIL PROTECTED] > wrote:> > > > Here's my copy, it should work if you have Tkinter. > > > >> > > > Good luck!> > > >> > > > On 4/20/06, doug shawhan <[EMAIL PROTECTED]> wrote:> > > > > Drat, I installed from the OpenBSD ports tree and this is not > included.> > > I'll> > > > > scout around on the net.> > > > >> > > > > Thanks again!> > > > >> > > > > > > > > > On 4/19/06, doug shawhan < [EMAIL PROTECTED]> wrote:> > > > > >> > > > > > Holy moley.> > > > > > > > > > > > Thanks!> > > > > >> > > > > >> > > > > >> > > > > > On 4/19/06, Liam Clarke < [EMAIL PROTECTED]> wrote:> > > > > > > Hi Doug,> > > > > > >> > > > > > > Best tip ever is> > > > > your_python_dir\tools\scripts\redemo.py > > > > > > >> > > > > > > Interactive regexes. :)> > > > > > >> > > > > > > This is pretty good as well -> > > > > http://www.amk.ca/python/howto/regex/> > > > > > >> > > > > > > Good luck,> > > > > > >> > > > > > > Liam Clarke > > > > > > >> > > > > > > On 4/20/06, doug shawhan < [EMAIL PROTECTED]> wrote:> > > > > > > > I think I'm going to have to suck it up and learn some regular > > > > > expressions.> > > > > > > >> > > > > > > > I have finally gotten my script (using the excellent pyserial> > > module)> > > > > to > > > > > > > > behave. Most of my troubles as enumerated here before were> utterly> > > > > > > > self-induced. Apparently one cannot watch the execution of > one's> > > > > script> > > > > > > > through another program without affecting it's outcome in> > > unforseen> > > > > ways.> > > > > > > > (Sound familiar Herr Schroedinger? :-) > > > > > > > >> > > > > > > > Now that I am actually extracting data in a fairly> predictable> > > way, I> > > > > am at > > > > > > > > the point where I need to parse it! I have some output here> > > (modified> > > > > to> > > > > > > > show the ESC and NUL characters.) > > > > > > > >> > > > > > > > When I pull data from the port, the remote computer sends it> in> > > one> > > > > long> > > > > > > > string per screen: newlines are not painted in by using the > > > expected> > > > > x\0a> > > > > > > > that I had hoped for! No easy readlines() fun for me. Instead> I> > > get:> > > > > > > > > > > > > > > > ESC=( 1. ESC=($4x2, 6-239 ( 3.9L)> > > &g
[Tutor] SOAP Modules - I need a little direction.
I am in preparation mode for creating a script which uses SOAP. I have been looking at the various SOAP modules: soapy, soap.py, ZSI, pywebsvcs. I'm very confused as to the status of these projects. Most seem to be only partially supported, if not abandoned completely. Thre appears to have been a flurry of interest in 2001, then everyone got jobs! ;-) This project is going to be a lulu for someone of my limited abilites, so I'd really rather not give myself a skull hernia on a dead-end module. Which of these modules I've listed (or haven't!) is most complete and appears to have a future? Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SOAP Modules - I need a little direction.
The problem is, I am trying to develop a script to upload massive amounts of stuff onto an ebay store. Unfortunately the folks at ebay have settled on a couple sorts of soapism as their standard. (They seem to be very Java and Dot Net happy over there ...) I would prefer nearly *any* other protocol. Reading the official SOAP documentation has been like licking the hoof of a very angry mule. But if you gotta, you gotta!On 4/26/06, Kent Johnson <[EMAIL PROTECTED]> wrote: doug shawhan wrote:> I am in preparation mode for creating a script which uses SOAP.>> I have been looking at the various SOAP modules: soapy, soap.py, ZSI,> pywebsvcs.>> I'm very confused as to the status of these projects. Most seem to be > only partially supported, if not abandoned completely. Thre appears to> have been a flurry of interest in 2001, then everyone got jobs! ;-)SOAPpy seems to be the most commonly mentioned one, though I think Python developers tend to avoid SOAP if possible, preferring lighterprotocols.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] SOAP Modules - I need a little direction.
The https/XML API is deprecated and will no longer be supported after the first of June. :-/ The real drag is: the older XML api had *2* very nice python implementations. I was successfull in less than 10 minutes with both of those. It's a shame. I was hoping to avoid the REST method, as I would like to have the whole shebang on one computer and not worry about making sure my hosting provider is using the same version of as I am developing with ... I'm just chicken, I guess. :-) On 4/27/06, Kent Johnson <[EMAIL PROTECTED]> wrote: doug shawhan wrote:> The problem is, I am trying to develop a script to upload massive> amounts of stuff onto an ebay store. Unfortunately the folks at ebay> have settled on a couple sorts of soapism as their standard. (They seem > to be very Java and Dot Net happy over there ...)>> I would prefer nearly *any* other protocol. Reading the official SOAP> documentation has been like licking the hoof of a very angry mule. But > if you gotta, you gotta!A quick Google for "python ebay" turns up a couple of Python packagesthat might be useful. The eBay developer docs talk about REST and XMLAPIs as well as SOAP. Looks like you need to dig a little more. Kent___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SOAP Modules - I need a little direction.
... Upon which I completely expose my ignorance of REST. I was completely concentrating on SOAP, since it seemed to have much more activity and had not looked at the REST description. It look like, for eBay's purposes, that to use the older xml-based systems, one must append "schema=1" to the requests. *blush* Ah well, not the first time I have dined on my foot on this mailing list! (Memo to self, stock up on ketchup)On 4/27/06, doug shawhan < [EMAIL PROTECTED]> wrote:The https/XML API is deprecated and will no longer be supported after the first of June. :-/ The real drag is: the older XML api had *2* very nice python implementations. I was successfull in less than 10 minutes with both of those. It's a shame. I was hoping to avoid the REST method, as I would like to have the whole shebang on one computer and not worry about making sure my hosting provider is using the same version of as I am developing with ... I'm just chicken, I guess. :-) On 4/27/06, Kent Johnson <[EMAIL PROTECTED]> wrote: doug shawhan wrote:> The problem is, I am trying to develop a script to upload massive> amounts of stuff onto an ebay store. Unfortunately the folks at ebay> have settled on a couple sorts of soapism as their standard. (They seem > to be very Java and Dot Net happy over there ...)>> I would prefer nearly *any* other protocol. Reading the official SOAP> documentation has been like licking the hoof of a very angry mule. But > if you gotta, you gotta!A quick Google for "python ebay" turns up a couple of Python packagesthat might be useful. The eBay developer docs talk about REST and XMLAPIs as well as SOAP. Looks like you need to dig a little more. 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
[Tutor] python cgi and html streams
I've been a-googling for examples or information on recieving and parsing html streams in a cgi script. I need to send a request like: ''http://www.foo.com/cgi-bin/responder.cgi?foo=hi&bar=there&bat=buddy&identifier=myname" to a remote server which will then stream a response to my script, similar to what I have grown to expect from cgi.FieldStorage when processing user input. I was hoping for something magical like: gulp = cgi.StreamIO("http://www.foo.com/cgi-bin/responder.cgi?foo=hi&bar=there&bat=buddy").read() ... but for some reason not one of the python creators foresaw that I might one day need them to do all the thinking, typing and other hard parts for me! So I decided to play around for a while and see what I could happen on my own. I first went to the interpreter: >>> dir(cgi) ['FieldStorage', 'FormContent', 'FormContentDict', 'InterpFormContentDict', 'MiniFieldStorage', 'StringIO', 'SvFormContentDict', 'UserDict', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__version__', 'dolog', 'escape', 'initlog', 'log', 'logfile', 'logfp', 'maxlen', 'mimetools', 'nolog', 'os', 'parse', 'parse_header', 'parse_multipart', 'parse_qs', 'parse_qsl', 'print_arguments', 'print_directory', 'print_environ', 'print_environ_usage', 'print_exception', 'print_form', 'rfc822', 'sys', 'test', 'urllib', 'valid_boundary'] Oho! StringIO seems like it is my baby: dir(cgi.StringIO) ['__doc__', '__init__', '__iter__', '__module__', 'close', 'flush', 'getvalue', 'isatty', 'next', 'read', 'readline', 'readlines', 'seek', 'tell', 'truncate', 'write', 'writelines'] Right on! GetValue! Read and Write! That looks like the ticket and it appears to work the same way as the usual StringIO module. Now my connundrum: I can't find any examples. I'm guessing what needs to happen is this: meScript --> sends request with an identifier to the remote server. RemoteServer --> sends data back to my meOtherScript (or a routine in meScript) which either pickles the data or stores it in a handy database. while my the first instance of meScript which has now passed the identifier to itself loops around reading from the database until either the identifier (and other data) to show up or the script times out, generating a heartfelt apology. Am I on the right track here? I suspect there is some sort of super easy way to accomplish this, but I am probably missing it. Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python cgi and html streams
On 5/5/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > I was hoping for something magical like:>> gulp = cgi.StreamIO("> http://www.foo.com/cgi-bin/responder.cgi?foo=hi&bar=there&bat=buddy ").read()>> ... but for some reason not one of the python creators foresaw that I might> one day need them to do all the thinking, typing and other hard parts for> me! Hi Doug,Try the 'urllib' client library. Headway! The information I was trying to recive is meant to be returned to another cgi script in a parameter string. urllib.urlopen.geturl() gets my information back to me: The following is run on mywebsite.com #!/usr/bin/env python import urllib parameters = urllib.urlencode({"id":"hippiedavey","origin":"goatville","dest":"cowtown"}) info = urllib.urlopen("http://www.hillbillyheaven.org/expectorate.asp?%s"%parameters).geturl() print info "http://mywebsite.com/Database/test.py?quoteno=999&originzip=47567&destzip=47598&id=hippiedavey&netcharges=$251.73&days=2 " I can, of course, use string methods to convert the returned request to whatever I want, but I still don't belive this was the original intent of the provider. :-) As it is now, I belive I'll have to create a script that will retrieve the info string, then call another copy of itself to extract the parameters from the info string! Not the worst fate, but it does seem to double up my calls to the webserver. On the other hand, I'll probably figure something else out! :-) Thanks! http://www.python.org/doc/lib/module-urllib.html The CGI server library is meant for servers, say, for the person whowould be implmenting responder.cgi.If you need to do more complicated interactions as a client, thensomething like Mechanize might also do the trick: http://wwwsearch.sourceforge.net/mechanize/but I'd recommend looking into urllib first to see if it's sufficient foryour problem. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Drifting Values in urllib.
I am having difficulty inderstanding urllib's handling of values passed to it. I assign values from cgi.FieldStorage() thusly: if form.has_key("id"): id = form["id"].value if form.has_key("origin"): origin = form["origin"].value if form.has_key("dest"): dest = form["dest"].value - and so on. I then attempt to pass the values to urllib.urlencode(): parameters = urllib.urlencode({"id":"%s","origin":"%s","dest":"%s","class1":"85","weight1":"185","custdata":"%s","respickup":"","resdel":"%s","insidechrg":"","furnchrg":"","cod":""})%(id,origin,dest,custdata,resdel) which rewards me with an error from the remote server. I then print the parameters value to see what is going on: origin= 8002886787&insidechrg=&respickup=&dest= 47720&resdel= 47567&custdata= Goat Kamal&cod=&weight1=185&furnchrg=&id=X&class1=85 Hmmm.. not at all what I put in! :-) I checked just to make sure my assignments were correct in the first place: print '''"id":"%s","origin":"%s","dest":"%s","class1":"85","weight1":"185","custdata":"%s","respickup":"","resdel":"%s","insidechrg":"","furnchrg":"","cod":""'''%(id,origin,dest,custdata,resdel) which reaps: "id":"8002886787","origin":"47720","dest":"47567","class1":"85","weight1":"185","custdata":"GoatKamal","respickup":"","resdel":"X","insidechrg":"","furnchrg":"","cod":"" Am I missing something fundamental here? I am not used to dictionaries swirling around like this. :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] partial string matching in list comprehension?
I have a series of lists to compare with a list of exclusionary terms. junkList =["interchange", "ifferen", "thru"] The comparison lists have one or more elements, which may or may not contain the junkList elements somewhere within: l = ["My skull hurts", "Drive the thruway", "Interchangability is not my forte"] ... output would be ["My skull hurts"] I have used list comprehension to match complete elements, how can I do a partial match? def removeJunk(reply, junkList): return [x for x in reply if x not in junkList] It would be so much prettier than searching through each list element for each term - I tend to get lost in a maze of twisty corridors, all alike. Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] XML Parsing Woes.
Having been dragged kicking and screaming into the fussy, fussy world of XML, I find myself in a pickle. I keep getting an error complaining of a missing end-tag: : XML Parse error. XML Error Text: "; nested exception is: org.xml.sax.SAXParseException: The element type "Description" must be terminated by the matching end-tag "".". Now of course, I have saved my output and found the end-tag to be there. I have stripped out everything I can think of that might cause the parser to puke. The string enclosed by the tags varies from a few characters to a couple of thousand: all fail with the same error. I am very new to XML and find it's jargon fairly impenetrable. Is there a handy python module that can one can use to scan XML output for errors? I know the mistake is probably mine ... or perhaps I have actually run on to a bug in the remote application? :-) (Right!) Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Offtopic observation
This marks the third time this week I have been typing in a question for the group, and have made the answer apparent just by trying to explain my question clearly. This suggests that either I think better in text, or Proust was onto something ... but then again, I majored in english. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] errno vs. sys.exc_info
I am in need of a clear way to return exceptions within a try loop. I have been looking at both errno and sys.exc_info. I know that using errno is not encouraged in threaded programs, but this is no big deal for my purposes. I found a good, clear example for translating the rather cryptic output from sys.exc_info: def formatExceptionInfo(maxTBlevel=5): cla, exc, trbk = sys.exc_info() excName = cla.__name__ try: excArgs = exc.__dict__["args"] except KeyError: excArgs = "" excTb = traceback.format_tb(trbk, maxTBlevel) return (excName, excArgs, excTb) Which seems to cover most of the bases, but I have yet to find a good example of using errno. Can someone provide a quick cut? :-) Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] XML: Expletive Deleted
I realize XML is going to save us all from something or other, but I just can't get my head around it. I have been trying to do what should be a very simple action: Extract values from element tags. I first grab my data from a website with httplib: >> connection = httplib.HTTPSConnection(serverUrl) >> connection.request("POST", serverDir, buildRequestXml("ReturnAll", "1"), buildHttpHeaders()) >> response = connection.getresponse() >> from xml.dom.minidom import parse, parseString >> data = ""> >> connection.close() >> response = parseString(data) >> itemIDs = response.getElementsByTagName("ItemID") >> response.unlink() I have tried everything I can find to extract the values from the elements: >> for item in itemIDs: >> print item yeilds Okay, no problem. Now all I have to do is figure out which particlular.string.of.words.interconnected.by.periods to pass to extract the values. >> for item in itemIDs: >> print item.nodeValue Seems logical: None None None None None Oh for crying out loud ... Hmmm ... I have saved the output from response.read() to a file and sure enough, amid all the other element tags, I find the expected values in My problem is: I'm ignorant. I don't know whether my data is being returned from parseString() as text, or a list or a beautiful rainbow made of skittles and pixie droppings. The Python/XML howto and the bajillion other "XML made clear to YOU!" sites I have looked at have left me more confused ... I'm just completely lost in the (apparently arbitrary) nomeclature of lists, nodes, elements, trees, habitrails and intestines. (Yes, I'm just complaining now, but dang it! I'm frustrated! *ahem* Could someone kindly point out where I am going wrong and perhaps send me to a very *practical* introduction to reading data from a dom? Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XML: Expletive Deleted
Kent, Danny, Lawrence, et. al. Thanks! I was kind of cringing as I sent this plaint/rant, but it seems I'm not the only one who has had trouble grokking DOM. I spanked the problem temporarily with regex, but can now actually fix it properly. Appreciate all the help!On 6/10/06, Kent Johnson <[EMAIL PROTECTED]> wrote: In my opinion the standard DOM models are the most awkward way to dealwith XML. If you are trying to get data from HTML on a web page, look atBeautifulSoup. For general XML processing, look at ElementTree. They are both simpler than DOM.http://www.crummy.com/software/BeautifulSoup/http://effbot.org/zone/element.htm Kent___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] datetime: What happended yesterday? :-)
I've been looking at datetime and cannot figure out what was a very simple operation with the time module. How does one add or subtract 24 (or any number) of hours from a given date and time using the datetime module? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime: What happended yesterday? :-)
Heh. Your example would look very, very nice in the timedelta (http://docs.python.org/lib/datetime-timedelta.html) section of the docs! :-) It makes perfect sense, the authors probably thought it was too easy to need an explaination ...On 6/12/06, Kent Johnson < [EMAIL PROTECTED]> wrote:doug shawhan wrote:> I've been looking at datetime and cannot figure out what was a very > simple operation with the time module.>> How does one add or subtract 24 (or any number) of hours from a given> date and time using the datetime module?Use a datetime.timedelta: In [1]: import datetimeIn [2]: now = datetime.datetime.now()In [3]: nowOut[3]: datetime.datetime(2006, 6, 12, 16, 7, 47, 69000)In [4]: >In [5]: now-one_day Out[5]: datetime.datetime(2006, 6, 11, 16, 7, 47, 69000)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] die or exit function?
Hi Andy, Putting a try:/except: loop in your __main__() (or whatever you call your base function) with sys.exit("Message") is pretty much the way I always do it. try: gak = puke + die except: sys.exit("Oy!") If you would like sys.exit() to provide you with a bit more information (like what actually happened during the failure and where!) I found this handy function: def formatExceptionInfo(maxTBlevel=5): cla, exc, trbk = sys.exc_info() excName = cla.__name__ try: excArgs = exc.__dict__["args"] except KeyError: excArgs = "" excArgsString = '' for item in excArgs: excArgsString = excArgsString + ' ' + str(item) excTb = traceback.format_tb(trbk, maxTBlevel) excTbString = '' for item in excTb: excTbString = excTbString + " " + str(item) report = "%s %s %s"%(excName, excArgsString, excTbString) return(report) This function now goes in most of what I do that requires error reporting. Hope this helps! On 6/13/06, Andy Koch <[EMAIL PROTECTED]> wrote: > Bkgd: I've been doing PHP for the last several years. > > Q: In PHP there are functions die and exit which terminate processing of > a script with an optional string output. Is there something similar to > this in Python? > > ___ > 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] How to make the loop work?
Hi Bob, You can use a while loop in this case, but range() might be a bit more appropriate! c = 0 d = raw_input("Enter Number Limit: ") for i in range(int(d)): #note, we make sure "d" is an integer! c = c + 1 print cOn 6/22/06, Bob Gailer <[EMAIL PROTECTED]> wrote: Ivan Low wrote:> Hi, I'm new to python trying to figure how to make this work.>> c=0;d=raw_input("input number limit: ")>> while 1:> c = c + 1> if c == d: break > print c,>>> My idea is to able to input a number to limit the print out of this loop.> But this will not work. Where is the error?>"Will not work" does not (in general) give us enough to go on. Please in the future tell us what the evidence of the problem is - e.g. unexpectedoutput, exception, ... If it is an exception please include thetraceback in your post.--Bob Gailer510-978-4454___ Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python text adventures question
I got a copy of Creating Adventure Games on Your Computer in the mail yesterday. Very fun! I set up a moodle class for the project. It seems like a good way to do such a thing. http://crackrabbit.com/moodle/ I realize that I am probably not anyone's idea of a programming howto writer, but hey! I had the space and it looks like a lot of fun. Code snippets will go under the WikiWiki and may be linked to from anywhere. Moodle is pretty neat, despite being written in PHP (WackaWacka). Anyway, sign up if you like the idea and I'll give you instructor ops. Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python text adventures question
Whoops, the password is 'ascii'. :-) Guess I could just take that off, couldn't I? On 9/29/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote: doug shawhan wrote:> I got a copy of Creating Adventure Games on Your Computer in the mail > yesterday.>> Very fun! I set up a moodle class for the project. It seems like a> good way to do such a thing.>> http://crackrabbit.com/moodle/ >> I realize that I am probably not anyone's idea of a programming howto> writer, but hey! I had the space and it looks like a lot of fun.>> Code snippets will go under the WikiWiki and may be linked to from > anywhere. Moodle is pretty neat, despite being written in PHP> (WackaWacka).>> Anyway, sign up if you like the idea and I'll give you instructor ops.I don't get it.What's the password? starts with a?password.startswith('a') == True? >_>Can you private e-mail me the password so I can see this?>> Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Self, Scopes and my unbelievable muddleheadedness.
I'm having a rather difficult time understanding the proper use of "self". I have two functions (yes, they are ugly, I was getting ready to split them in to smaller bits when this particular hole in my skull opened up) in a module. They use the same list of dictionaries to create some tables in a gadfly database. I know I could fix this in any number of ways (including, but not limited to, acting on the same input list twice, or acting on it in such a fashion in the first place), but I am trying to actually understand "self". Here's the horrid, horrid mess: class Create: def freshDB(self, DBPATH, Fields): self.Fields = Fields for field in self.Fields.keys(): columns = self.Fields[field] columns = columns.split(',') query = '' for each in columns: query = "%s, %s varchar"%(query,each) query = query[1:] query = "Create Table %s (%s)"%(field,query) self.Fields[field] = query connection = gadfly.gadfly() connection.startup("InventoryDB", DBPATH) cursor = connection.cursor() for field in self.Fields.keys(): cursor.execute(self.Fields[field]) connection.commit() for field in self.Fields.keys(): cursor.execute("Select * from %s"%field) print cursor.pp() connection.close() def comparisonTable(self, DBPATH, Fields, columns, mode): query = "" if mode == 'new': connection = gadfly.gadfly("InventoryDB",DBPATH) cursor = connection.cursor() try: cursor.execute("drop table comparison") except: print "No old table found." columns = Fields["Common"].split(',') for each in columns: query = "%s, %s varchar"%(query,each) query = query[1:] query = "Create Table comparison (%s)"%query cursor.execute(query) connection.commit() cursor.execute("select * from comparison") print cursor.pp() Now when I run freshDB from the other script: Fields = {"Common":"Inventory_Number, Stock_Number, Location, Year, Make, Model, Part_Type, Mileage, Description, Interchange_Data, Condition, Price", "EvilBay":"EvilBay_Title, EvilBay_Description", "HappyBase":"HappyBase_Description, HappyBase_Long_Description"} d = DBMod d.Create().freshDB(DBPATH, Fields) d.Create().comparisonTable(DBPATH, Fields, columns, "new") the resulting query is: Create Table comparison ( Inventory_Number varchar, Stock_Number varchar, Location varchar, Year varchar, Make varchar, Model varchar, Part_Type varchar, Mileage varchar, Description varchar, Interchange_Data varchar, Condition varchar, Price varchar) The query from comparisonTable gives me: Create Table comparison ( Create Table Common ( Inventory_Number varchar varchar, Stock_Number varchar varchar, Location varchar varchar, Year varchar varchar, Make varchar varchar, Model varchar varchar, Part_Type varchar varchar, Mileage varchar varchar, Description varchar varchar, Interchange_Data varchar varchar, Condition varchar varchar, Price varchar) varchar) If I restate the "Fields" input list before running comparisonTable, my results are as expected (i.e. exactly like the first query, exept the table is named "comparison"). I thought that when "self" was invoked for a function then that data was acted on only for the scope of that function, yet the data is changed in the original. Why? I'm sure this is so obvious that a crack-addled tapeworm head down in a bucket of stupid could understand it, unfortunately, I'm not quite at that level today. Sorry. Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Self, Scopes and my unbelievable muddleheadedness.
On 10/25/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote: >> I'm sure this is so obvious that a crack-addled tapeworm head down in> a bucket of stupid could understand it, unfortunately, I'm not quite> at that level today. Sorry.Uh, I don't understand why you're passing Fields to the functions but then putting the value in self.Fields...but we'll ignore that for now :) http://www.penzilla.net/tutorials/python/modules/ I explain my confusion more coherently in my reply to Mr. Gald. :-) The problem it sounds like you're having is that you think that passinglists to functions copies them, when in fact it just creates a reference to them.Take this, for example: Close! I thought that "self" would somehow automagically create a copy of the list, leaving a global intact. I am disillusioned. >>> def append_five(alist):alist.append(5) >>> a = [1,2,3,4] >>> append_five(a) >>> a[1, 2, 3, 4, 5] >>> append_five(a) >>> a[1, 2, 3, 4, 5, 5] Which answers my question "why is my list of dictionaries turning in to a list with a dictionary with a list of dictionaries therein! :-) Other than that,Maybe you think self is used for something other than what it's intended to be used for...but I can't be sure. Again, see my reply to Mr. Gald. I am starting to get my head around "self". I searched usenet for explanations, apparently I'm not the only one. :-). It seems to be pretty simple, for most. I'm reminded of learning to solve for polynomials or diagram sentences: It's elementary to some and completely obtuse to others, depending on mindset and experience. I'm sure someone else can give you a good example.I, however, have to run. HTH,-Luke Thanks! I appreciate it! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Self, Scopes and my unbelievable muddleheadedness.
-- Forwarded message --From: doug shawhan <[EMAIL PROTECTED]>Date: Oct 26, 2006 1:45 PM Subject: Re: [Tutor] Self, Scopes and my unbelievable muddleheadedness.To: Alan Gauld <[EMAIL PROTECTED]> On 10/26/06, Alan Gauld <[EMAIL PROTECTED]> wrote: "doug shawhan" <[EMAIL PROTECTED]> wrote> I'm having a rather difficult time understanding the proper use of > "self".Doug, I think you may be having a more fundamental problem. Looking at your code at the most superficial level it seemsyou may not understand objects. I've always been confused by much of the OOP terminology. I'm about to go off on a tangent below regarding your explaination. I think it is helping me, but I want to be sure. Bear with me. :-) My original question should have been: "Why is this dictionary coming back weird?" The dictionary was just a placeholder for a future .ini file to be read with ConfigParser. In playing around with different ideas. I thought "I'd like to put each particular set of activities into modules anyway, so let's just figure out how that might work". I ran onto the problem of the dictionary being changed globally, when I thought that use of "self" meant that any changes to that data were limited to the scope of the method in that particular class (and it's resultant object), thereby insulating it from other methods in the same class and other objects which inherit from the same class" (Don't reply to this yet! :-) I'm sure that I have simply thought that my global declaration was not going to be changed in place by misunderstanding what "self" means. My confusion stemmed from just how weird the change appeard to be. I.e. "But I just looked at the dang thing and it was what I expected! Where dem extra parentheis come from? Huh?" I apologize for my incoherence in asking the question. I was in the middle of trying out different ideas and ran onto this weirdness and could not let it go. I should taken the time to write a generic example, but frankly, I was frustrated and was not thinking about how best to frame the question. It was impolite of me to subject the list to my half-baked meanderings. Again, sorry. You guys have helped so much and you deserve a little more effort on my part. So, fortified with 8 hours of sleep and 15mg of Adderall, here we go! Classes are used to generate objects. Objects represent things.By logical deduction objects correspond to nouns in language. Objects do things when they receive messages (Possiblyfrom other objects). Messages cause methods to be invoked,methods therefore correspond to verbs in language. I felt like I was being told an integer is a "counting number" here. ;-) Looking at your code we find:class Create: # a verbdef freshDB(self, DBPATH, Fields): # a noun def comparisonTable(self, DBPATH, Fields, columns, mode): #a nounIn other words you have the concept inside out.you are trying to create Create objects and call Table and Databasemethods. It doesn't make sense. Normally we would expect to see DB and Table objects to whichyou send create messages. I was even more confused. Were you objecting to my nomenclature? So I thought, "If I named the class "Steve" and called the methods createFreshDB() and createComparisonTable() so it would read: "Steve, create a fresh database which includes tables named for the keys and columns named for the values in this dictionary I'm handing you." "Steve, create a comparison table just like above, but with a different key." which would be followed (eventually, if I hadn't gotten bogged down) by "Steve, tell gadfly to collate those two tables I just had you make and put them in another table so I can generate a report" Would that make any difference? No especially in how the code was written (it was still ugly and half-baked, and showing tons of bad habits), but I did suddenly realize what you meant by "noun". I have been treating objects like a corporate sales droid treats nouns. I've been "Gifting" and "Tableing" the objects "TheGift" and "TheTable" in my mind. (I fear I've also been "Impacting" the method "impact()" without asking Steve.Please() first, (I.E. not quite understanding why my classes within the modules were not showing up like I expected, but that's another story.) I've not been thinking of an object as a verb, rather more like a gerund. Still wrong, but a different kind of wrong. Now if you think of the objects as verbs then self is a confusing concept. But if you think of the objects as nouns then self is simply areferenceto the object instance in question, a particular database or table. Which leads me back to the "why is it there?" question I saw on the list re
Re: [Tutor] Help with Elementtree ...how to access the attributes..
I'm having some difficulties with elementtree as well. I'm attempting to parse a fairly sizeable xml file (it's the ebay "category tree" report. I've cached a copy at http://www.crackrabbit.com/misc/CatTree.xml). 900K or so! :-) For some reason I'm unable to read any elements from the file. I have no problems with Asraramed's example. (I'm not attempting to extract values here, just to make sure that there is actual parsing going on!) #!/usr/bin/env python2.4 from elementtree import ElementTree as et tree = et.parse("kadri.xml") companies = tree.findall('company') for c in companies: print c which gives me: Cool beans. There's something in there! Now when I attempt the same with the data found at the above link: #!/usr/bin/env python2.4 from elementtree import ElementTree as et tree = et.parse('CatTree.xml') categories = tree.findall("CategoryArray") for cat in categories: print cat I receive nothing. I've made a smaller version that I could easily get me brain around: 2006-11-07T07:45:40.908Z Success 485 e485_core_Bundled_3782281_R1 true 6000 1 eBay Motors 6000 false false false false false true which also seems to parse cleanly and appears to be similar to what Asraramed had constructed, but still does not yeild any results no matter which element I attempt to find with findall(). What am I doing wrong? Thanks! On 11/9/06, John Fouhy <[EMAIL PROTECTED]> wrote: On 10/11/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:> I am trying to parse XML documents using elementtree. > I have just started with it. Can somebody help me with how to select nodes > with a particular atribute set to some value. For example, I have the> following file. Now I want to access the founder element of the company> whose attribute is set to 'ndtv'. Can somebody help me with this? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Elementtree ...how to access the attributes..
Ah. Apparently, the string xmlns="urn:ebay:apis:eBLBaseComponents" is causing some sort of outfreakage. I'm not well versed in xml lore: is the "urn:" tag out of context here? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Elementtree ...how to access the attributes..
Oho! Thanks, Kent (and everyone else.) That clears up some things. The link has some embarassment reducing info as well. :-)On 11/11/06, Kent Johnson < [EMAIL PROTECTED]> wrote:doug shawhan wrote:> I'm having some difficulties with elementtree as well. >> I'm attempting to parse a fairly sizeable xml file (it's the ebay> "category tree" report. I've cached a copy at> http://www.crackrabbit.com/misc/CatTree.xml ). 900K or so! :-)> I've made a smaller version that I could easily get me brain around:>> > > 2006-11-07T07:45:40.908Z> Success> 485> e485_core_Bundled_3782281_R1 > > > true> 6000> 1 > eBay Motors> 6000> false> false > false> false> false> true > > > >> which also seems to parse cleanly and appears to be similar to what> Asraramed had constructed, but still does not yeild any results no > matter which element I attempt to find with findall().>> What am I doing wrong? Thanks!When an XML document is in a namespase, ET includes the name of thenamespace as part of the element name and you have to include it when you use findall().Try categories =tree.findall("{urn:ebay:apis:eBLBaseComponents}CategoryArray")http://effbot.org/zone/element.htm#xml-namespaces Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] free IDE for Python?
I know it's merely a text editor, but for any non-gui stuff I use SciTE. The little execution pane is gawgeous, gawgeous, gawgeous. (Though I find it best to use at least a 19" monitor! ) On 11/15/06, Chris Hengge <[EMAIL PROTECTED]> wrote: BTW... that also counts as my vouce for using SPE =D On 11/15/06, Chris Hengge <[EMAIL PROTECTED]> wrote: > > I tried it back before I tried SPE. I remember it taking several hours > and being very bloated. Have you watched the showmedo video? Thats what I > used... > > http://showmedo.com/videos/series?name=PyDevEclipseList > > If I personally "had" to use something that obnoxious I'd just reinstall > ironpython and use Visual Studio for everything since I already have it for > C# applications. (Yes I understand it makes .net runtime code and not python > code, but I can't justify using that large and resource eating a program to > use a language that is supposed to be quick and easy... ) > > On 11/15/06, Alan Gauld < [EMAIL PROTECTED]> wrote: > > > > > > "wesley chun" <[EMAIL PROTECTED]> wrote > > > Eclipse > > > http://pydev.sourceforge.net > > > http://www.eclipse.org/ > > > > Has anyone got an idiot's guide to getting Eclipse working > > with python? > > > > I've tried a couple of times but ran out of patience. In fact I > > haven't really got vanilla Eclipse working for Java yet, it all > > seems a lot of work for an IDE! NetBeans was so much > > easier but my friends all laughed at me and said I should > > be using Eclipse... :-) > > > > Alan (the impatient) 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 maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] wrapping a command line tool
Actually, I've had excellent results with pyserial. http://pyserial.sourceforge.net/ I've used it to write a screen-scraping tool. It comes with a little demo terminal program that shows many interesting ways to fiddle about with the module. I use it in conjunction with the wy60 emulator on OpenBSD to access an ancient SuperDOS system. On 12/15/06, Tim Golden <[EMAIL PROTECTED]> wrote: > I am using a command line tool that allows me to specify a serial > port and either read from or write data to it. I would like to create > a python module that wraps that functionality and allows me to > manipulate the incoming data to present it in a table for instance > (like top works) or maybe store it in a dictionary and drop it into a > database at timed intervals. Simplest (though not necessarily the most modern) way: import os data = os.popen ("do_thing.exe param1 param2").read () # # Do stuff with results according to need # Obviously how to format as a table depends largely on what the data looks like and what your intended display medium is. (PDF? HTML? console?) TJG ___ 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] Regular expressions - Ignoring linefeeds
I've been looking through various sites, but cannot find the magic button that allows me to match a string with linefeeds I'd rather not strip out the linefeeds, then stick them back in. :-) I'm attempting something that should be fairly simple: snippy = re.compile('Hi there.*Bye there.') s = '''Good gravy! Hi there. I'm some text someone wants to match. Bye there. See you around''' yield = re.match(snippy) Anything after the linefeed is not matched, yielding naught but pain. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor