Re: [Tutor] how to read over serial port
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 shawn bright wrote: > Forgot some info, > i hooked the device up and used a serial terminal and got back stuff like this > !^V$G(R)±LL,3602.0960,N,10229.2959,W,r$4013,V*2E > some of the above is what i am looking for. > Ok, that looks bad. You have some of the right stuff, but also some non-ascii characters. You should see lines that start with something like $GPRMC, You either have a hardware problem, or a mismatch in the settings. Brian - -- - ---[Office 68.9F]--[Outside 46.4F]--[Server 99.4F]--[Coaster 70.2F]--- - ---[ ISSAQUAH WSF (366773040) @ 47 31.3927 -122 23.8077 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (Darwin) Comment: Remember Lexington Green! iD8DBQFJD8w2Iftj/pcSws0RAvBcAJ4u56Ns1LvM4fUje6J+C/bNUzdI9ACfVGf8 Al9CxP99ODjq6sPztZ1oAQI= =vsxI -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read over serial port
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 shawn bright wrote: > Hey there all, > > I have a gps device that talks to the computer over a serial port. > i am using the pyserial module and getting values in. Here are the relevant bits of a serial to tcp/ip app that I use. Most likely you have the wrong baudrate set. If it is an older GPS device the baudrate will be 4800, newer devices allow you to set it to higher speeds, 9600 being standard. Check the device settings to make sure that it doesn't have any weird parity settings too. 8 bits, No Parity, 1 stop bit is common. import sys import serial port = "/dev/ttyS0" baud = 9600 ser = serial.Serial() ser.port = port ser.baudrate = baud try: ser.open() except: sys.stderr.write("Error opening serial port %s\n" % (ser.portstr) ) sys.exit(1) ser.setRtsCts(0) while 1: # Read from serial port, blocking data = ser.read(1) # If there is more than 1 byte, read the rest n = ser.inWaiting() if n: data = data + ser.read(n) sys.stdout.write(data) - -- - ---[Office 68.7F]--[Outside 51.0F]--[Server 103.2F]--[Coaster 70.0F]--- - ---[ TACOMA WSF (366772760) @ 47 36.3260 -122 23.1697 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (Darwin) Comment: Remember Lexington Green! iD8DBQFJDcl3Iftj/pcSws0RAs2+AJ91ynHgzdXDfVpbh37iM7XITnDI7wCeNON8 qxyWcuc5opuOpeRCJ6cWr+o= =fPs4 -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Read same instance twice
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Øyvind wrote: > Hello. > > I am trying to gather some information from a webpage: > > side = urlopen("http://www.website.no";) > rawstr = r"""spy.target="_top">(.*?)$""" > rawstr2 = r"""spy.target2="_top">(.*?)$""" > > compile_obj = re.compile(rawstr, re.IGNORECASE| re.MULTILINE| re.VERBOSE > | re.UNICODE) > compile_obj2 = re.compile(rawstr2, re.IGNORECASE| re.MULTILINE| > re.VERBOSE | re.UNICODE) > > liste = self.compile_obj.findall(side.read()) > > liste = self.compile_obj2.findall(side.read()) > > It works like a dream getting the first info, but the second doesn't work. > The instance is empty. > That's because you read all of it and passed it to the first regex. Change to: side = urlopen("http://www.website.no";).read() then: liste = compile_obj.findall(side) liste = compile_obj2.findall(side) That reads the site's contents once, then you can do whatever you want with it in your program. I'm not sure why you had the self. reference to compile_obj, so mix to fit your circumstances :) Brian - -- - ---[Office 68.6F]--[Outside 54.2F]--[Server 100.6F]--[Coaster 69.6F]--- - ---[ LADY MARY (367013060) @ 47 36.3071 -122 23.1817]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (Darwin) Comment: Remember Lexington Green! iD8DBQFJBi/UIftj/pcSws0RAjtiAJ45Sp++yj8jUhir6lwehLqRzBJswwCfREh7 J83jy1sN1xf8Gi+dWZs9GNM= =8YQT -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Edit a Word document programmatically
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 URBAN LANDREMAN wrote: > Good morning, > > I'm trying to write some Python code to programmatically do a Find and > Replace of a string within a Microsoft Word document. > Any suggestions on where I could look to find how to do such a function? > Take a look at the win32com module. Here's a chapter on it from O'Reilly http://oreilly.com/catalog/pythonwin32/chapter/ch12.html#49339 Brian - -- - ---[Office 70.5F]--[Outside 46.5F]--[Server 104.9F]--[Coaster 71.0F]--- - ---[ WSF KITSAP (366772980) @ 47 34.7811 -122 27.7554 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (Darwin) Comment: Remember Lexington Green! iD8DBQFI9KtAIftj/pcSws0RAk9EAJ4/Dysv4TfAdyo+g5t2QLwvLMQR4gCfZ5l0 ic/hQOAv4psFxKN2ErMpEDQ= =8tz8 -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] bug in exam score conversion program
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 David wrote: > Hello!! > > I just completed exercise 7 (chapter 4) in Zelle's book: > "A certain CS professor gives 100-point exams that are graded on the > scale 90–100:A, 80–89:B, 70–79:C, 60–69:D, 60:F. Write a program that > accepts an exam score as input and prints out the corresponding grade." > Just to throw in another method, I tend to use tables of for problems like this. The requirements usually change so its easier to modify later: # min, max, grade grades = [ (90,100,'A'), (80, 89,'B'), (70, 79,'C'), (60, 69,'D'), ( 0, 59,'F'), ] def getGrade(score): """ Return a letter grade based on a score """ for g in grades: if (score <= g[1]) and (score >= g[0]): return g[2] - -- - ---[Office 71.6F]--[Outside 55.4F]--[Server 107.9F]--[Coaster 71.7F]--- - ---[ WSF KITSAP (366772980) @ 47 34.7811 -122 27.7554 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (Darwin) Comment: Remember Lexington Green! iD8DBQFI535RIftj/pcSws0RAldqAJ9yKYSyDArc/LZ6G47SwxUq4z8yAACgioyx b9WnwDEQe8hSOuYbKuKo9sY= =7lCV -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor