Re: [Tutor] pickling, writing, reading individual lists from a file
On Mon, 03 Nov 2008 06:42:28 -0500, Kent Johnson wrote: > On Mon, Nov 3, 2008 at 6:15 AM, Lie Ryan <[EMAIL PROTECTED]> wrote: >> On Sun, 02 Nov 2008 23:20:47 -0800, Dinesh B Vadhia wrote: >> >>> I want to pickle a bunch of lists and write each list separately to a >>> fileand then read them back. > >> To solve your problem, you have several alternative possibilities: > > 6. Make multiple calls to dump() and load() using an explicit pickler, > pickling directly to the file (not tested): > > filename = 'lists.txt' > fw = open(filename, 'wb') # Note open in binary mode for protocol 2 > pickler = pickle.Pickler(fw, 2) > for l in m: > pickler.dump(l) > fw.close() > > fr = open(filename, 'rb') > pickler = pickle.Unpickler(fr) > for i in range(3): > line = pickler.load(fr) > print line > fr.close() Ah, I see, that's why the pickle module contains Pickler object. btw, I have to add, none of the five code I wrote is tested at all, and definitely #4 wouldn't work as it assumed there is a function that could automagically escape the string. And, using Pickler object is probably the best solution here. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter troubles
Hi guys, I'm having trouble with weird activity with a Tkinter GUI I'm creating. I've stripped down the code somewhat to simplify the problem somewhat, and I've posted it below, with further explanation at the end of this message: from Tkinter import * import tkFileDialog,tkSimpleDialog WINDOWWIDTH=500 WINDOWHEIGHT=500 class App: def __init__ (self,master): self.window = Frame(master) self.window.pack() self.master= master #Create frame to contain all others self.display=Frame(self.window,width=WINDOWWIDTH,height=WINDOWHEIGHT, bg='black') self.display.pack() self.addMenu(self.master) #Create widgets self.createwidgets() def createwidgets(self): self.leftframe=Frame(self.display, width=WINDOWWIDTH/3,height=WINDOWHEIGHT, bg='white') self.rightframe=Frame(self.display, width=2*WINDOWWIDTH/3,height=WINDOWHEIGHT, bg='blue') self.leftframe.pack(side="left", expand="yes", fill="x") self.rightframe.pack(side="left", expand="yes", fill="x") def displayStories(self): self.lb = Text(self.leftframe) self.lb.pack() def addMenu(self,master): self.menu = Menu(self.window) master.config(menu=self.menu) self.feedmenu = Menu(self.menu) self.menu.add_cascade(label="RSS", menu=self.feedmenu) self.feedmenu.add_command(label="Load RSS", command=self.displayStories) root=Tk() app=App(root) root.mainloop() : Basically I'm trying to create 2 columns on the page so that (eventually) I will be able to have sepearte text boxes in each column. The code so far creates a leftframe and rightframe, with parent frame self.display . When I run the script this happens as expected. But next, I want to create a text box within self.leftframe which is done in function displayStories . self.lb is created with parent self.leftframe . When this is run, the text box shows up, but my layout goes to hell. I want the text box to be contained within self.leftframe, but when it is added self.leftframe disappears (or is completely filled by the text box), the dimensions that I had specified for self.leftframe and self.rightframe are forgotten about, and I can see self.display (black background) on the part of the screen in the left frame that is not filled by the text box. This makes a lot more sense if you run the simple script I've posted. I've tried adjusting various options, and also using the "grid" manager instead of "pack", but I can't seem to figure out why this is happening. Can anyone help out? Thanks, Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pickling, writing, reading individual lists from a file
Just one change - pickler.load() doesn't take an argument - otherwise works perfectly! Thank-you. ... 6. Make multiple calls to dump() and load() using an explicit pickler, pickling directly to the file (not tested): import cPickle as pickle filename = 'lists.txt' fw = open(filename, 'wb') # Note open in binary mode for protocol 2 pickler = pickle.Pickler(fw, 2) for l in m: pickler.dump(l) fw.close() fr = open(filename, 'rb') pickler = pickle.Unpickler(fr) for i in range(3): line = pickler.load() print line fr.close() ... Dinesh From: Kent Johnson tds.net> Subject: Re: pickling, writing, reading individual lists from a file Newsgroups: gmane.comp.python.tutor Date: 2008-11-03 11:42:28 GMT (2 hours and 16 minutes ago) On Mon, Nov 3, 2008 at 6:15 AM, Lie Ryan gmail.com> wrote: > On Sun, 02 Nov 2008 23:20:47 -0800, Dinesh B Vadhia wrote: > >> I want to pickle a bunch of lists and write each list separately to a >> fileand then read them back. > To solve your problem, you have several alternative possibilities: 6. Make multiple calls to dump() and load() using an explicit pickler, pickling directly to the file (not tested): filename = 'lists.txt' fw = open(filename, 'wb') # Note open in binary mode for protocol 2 pickler = pickle.Pickler(fw, 2) for l in m: pickler.dump(l) fw.close() fr = open(filename, 'rb') pickler = pickle.Unpickler(fr) for i in range(3): line = pickler.load(fr) print line fr.close() Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read over serial port
Hey all, sorry, but am i supposed to be using 'rb' to read this? thanks sk On Sun, Nov 2, 2008 at 11:50 AM, shawn bright <[EMAIL PROTECTED]> wrote: > Thanks all, > Yeah, checked the settings, and when i have the thing talk to a > program that just prints out whatever the serial port reads, It was > looking fine. > Incorrect baudrate was my first problem, and did cause weirdness, > escpeially on the latter end of the message, but this isn't the same > problem. Just don't know how to read it. > thanks > > shawn > > > On Sun, Nov 2, 2008 at 9:38 AM, Brian C. Lane <[EMAIL PROTECTED]> wrote: >> -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 >> > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read over serial port
ok, i have another question: if i run this: #!/usr/bin/env python f = 'test_out' f = open(f, 'r').read() for i in f: print ord(i) I get this: 0 6 0 58 128 31 22 103 74 115 222 192 74 115 222 192 (deleted some in the email for brevity) if i do for i in f: print chr(ord(i)) i get the same weird characters. should these be read some other way? thanks, shawn On Mon, Nov 3, 2008 at 8:14 AM, shawn bright <[EMAIL PROTECTED]> wrote: > Hey all, sorry, but am i supposed to be using 'rb' to read this? > thanks > > sk > > On Sun, Nov 2, 2008 at 11:50 AM, shawn bright <[EMAIL PROTECTED]> wrote: >> Thanks all, >> Yeah, checked the settings, and when i have the thing talk to a >> program that just prints out whatever the serial port reads, It was >> looking fine. >> Incorrect baudrate was my first problem, and did cause weirdness, >> escpeially on the latter end of the message, but this isn't the same >> problem. Just don't know how to read it. >> thanks >> >> shawn >> >> >> On Sun, Nov 2, 2008 at 9:38 AM, Brian C. Lane <[EMAIL PROTECTED]> wrote: >>> -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 >>> >> > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] stopping threads ?
Hi All, Why when I use threads in my app (I know they are evil ...lol) does it not stop with ctrl-c, I have to use ctrl-z ? Cheers Dave -- Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] string.join()
Hello again, Just looking for clarification on a point: the book I'm using is written around Python v.2.3, and has an exercise using string.join(). Specifically, it said to use string.join(msgList, ""), the object of which was to take the list items in msgList and concatenate them using a blank or no character between. After some work it did work as advertised, which is all well and good, but I hit a bit of a snag along the way. I *think* I got it figgered out, but would like some verification. Basically... when I was reading through the documentation trying to decide how to re-write an earlier program using string.join() as described above... I noticed the docs said that a bunch of string functions were deprecated and going away in Python 3.0. As such... I thought perhaps since I was in the neighborhood so to speak maybe I should learn to do things the 'new' way. It took me a while to get from string.join(words[, sep]) to str.join()... which almost immediately puked and didn't work. After a while longer, I finally noticed somewhere that 'str' was supposed to be the string used for the separator, so I use ''.join(msgList), which seems to work (or at least give identical output) in this case. So... do I have it correct? Yes/no/maybe? Thanks, Monte ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pickling, writing, reading individual lists from a file
On Mon, Nov 3, 2008 at 6:15 AM, Lie Ryan <[EMAIL PROTECTED]> wrote: > On Sun, 02 Nov 2008 23:20:47 -0800, Dinesh B Vadhia wrote: > >> I want to pickle a bunch of lists and write each list separately to a >> fileand then read them back. > To solve your problem, you have several alternative possibilities: 6. Make multiple calls to dump() and load() using an explicit pickler, pickling directly to the file (not tested): filename = 'lists.txt' fw = open(filename, 'wb') # Note open in binary mode for protocol 2 pickler = pickle.Pickler(fw, 2) for l in m: pickler.dump(l) fw.close() fr = open(filename, 'rb') pickler = pickle.Unpickler(fr) for i in range(3): line = pickler.load(fr) print line fr.close() Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to check online status
Dear fellow Pythonistas, is it possible to check with Python whether a computer is connected to the internet or not? I don't not find a module which can do such a thing like 'ping'? And how do I make my python scipts that use urllib to recognize the windows operating system proxy settings? Thanks in advance and kind regards, Timmie ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string.join()
Monte Milanuk wrote: Hello again, Just looking for clarification on a point: the book I'm using is written around Python v.2.3, and has an exercise using string.join(). Specifically, it said to use string.join(msgList, ""), the object of which was to take the list items in msgList and concatenate them using a blank or no character between. After some work it did work as advertised, which is all well and good, but I hit a bit of a snag along the way. I *think* I got it figgered out, but would like some verification. looks fine to me. An experiment in Python confirmed that: Python 2.3.4 (#1, Jul 25 2008, 14:24:21) [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import string >>> string.join(['a', 'b', 'c'], '-') 'a-b-c' each value in the list gets seperated from other value(s) by the seperator string ("-" in this case). neighborhood so to speak maybe I should learn to do things the 'new' way. It took me a while to get from string.join(words[, sep]) to str.join()... which almost immediately puked and didn't work. After a while longer, I finally noticed somewhere that 'str' was supposed to be the string used for the separator, so I use ''.join(msgList), which seems to work (or at least give identical output) in this case. Correct too: >>> '-'.join(['a', 'b', 'c']) 'a-b-c' This is indeed the recommended way of joining strings. Sincerely, Albert ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string.join()
On Mon, Nov 3, 2008 at 10:54 AM, Monte Milanuk <[EMAIL PROTECTED]> wrote: > Hello again, > > Just looking for clarification on a point: the book I'm using is written > around Python v.2.3, and has an exercise using string.join(). Specifically, > it said to use string.join(msgList, "") > After a while > longer, I finally noticed somewhere that 'str' was supposed to be the string > used for the separator, so I use ''.join(msgList), which seems to work (or > at least give identical output) in this case. > > So... do I have it correct? Yes/no/maybe? Yes, that is correct. Instead of string.join(seq, sep) use sep.join(seq). Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to check online status
Timmie wrote: Dear fellow Pythonistas, is it possible to check with Python whether a computer is connected to the internet or not? You've got several options. The simplest, cross-platform solution is to connect a socket to a known port on a known server with a timeout and see if it connects. But there are ping-alike Python modules around if that's really what you want: http://www.google.co.uk/search?hl=en&q=python+ping+module And how do I make my python scipts that use urllib to recognize the windows operating system proxy settings? http://docs.python.org/howto/urllib2.html TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to check online status
On Mon, Nov 3, 2008 at 9:54 AM, Timmie <[EMAIL PROTECTED]> wrote: > Dear fellow Pythonistas, > is it possible to check with Python whether a computer is connected to the > internet or not? Yes. That's the short answer anyway. > I don't not find a module which can do such a thing like 'ping'? you could use the os module to execute the system command "ping" > And how do I make my python scipts that use urllib to recognize the windows > operating system proxy settings? I'm not particularly sure, but at first glance http://www.google.com/search?q=python+urllib+windows+proxy seems to have some useful looking links. HTH, Wayne > > > Thanks in advance and kind regards, > Timmie > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] request from john caldwell to get off the mailing list
On Sun, 02 Nov 2008 12:59:16 -0800, john caldwell wrote: > Please take me oof of the mailing list. thank you > [EMAIL PROTECTED] > > You can unsubscribe from here: http://mail.python.org/mailman/listinfo/ tutor alternatively, you can also send some magic mail to a magic email address containing some magic subject line and content. I think for this mailing list, the magic address is: [EMAIL PROTECTED], send a message containing just 'help' ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pickling, writing, reading individual lists from a file
On Sun, 02 Nov 2008 23:20:47 -0800, Dinesh B Vadhia wrote: > I want to pickle a bunch of lists and write each list separately to a > fileand then read them back. Here is my code with the EOF error: > > filename = 'lists.txt' > fw = open(filename, 'w') > for l in m: > n = pickle.dumps(l, 2) + "\n" > fw.write(n) > fw.close() That is because a pickle.dumps() produces a string of bytes, and may contain "\n". When you try to read the file, you split the file based on "\n", since the original pickled items contains "\n", you split the pickled data in places where it shouldn't be. To solve your problem, you have several alternative possibilities: 1. just pickle the whole of them 2. put each pickled object in separate file (alternatively zipping them if you have a lot of them) 3. choose a separator that is guaranteed that pickle wouldn't emit 4. escape the separator you choose 5. put the pickled data in a list/dict, then pickle that list/dict 1. pickle.dump(m, 'lists.p', 2) 2. for i, l in enumerate(m): pickle.dump(l, 'list%s.p' % i, 2) 3. #from __future__ import with_statement # uncomment the line above if python version < 2.6 separator = "something pickle wouldn't emit" with open('lists.txt', 'w') as fw: for l in m: n = pickle.dumps(l, 2) + separator fw.write(n) 4. separator = "|" with open('lists.txt', 'w') as fw: for l in m: n = escape(pickle.dumps(l, 2)) + separator fw.write(n) 5. # since the objects you're pickling is already in a list # this solution is exactly the same as solution #1 # however, in cases where the object you intend to pickle # is scattered, you should make a dict/list. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On Sat, 01 Nov 2008 06:17:06 -0500, otu wrote: > Dear Friends, > I have just started learning python programming. I have no previous > programming knowledge. > I am presently using Python 2.6 windows version. I am struggling with > how to enable executable files. I copied the ff program on idlle > non-interactice and run it. > > the_world_is_flat =1 > if the_world_is_flat: > print"Be careful not to fall off" > > > > > The result came out on the interactive window. I saved this as > "example.py" on the desktop. The python icon appears on the the desktop > alright. When I attempt to run it by double clicking the icon, only a > black DOS window flashes. I know I am doing something seriously wrong. > What is it? > Regards, > Bennedy. There are two ways to answer your problem. First, you open the command prompt (Start > Run > cmd) then change directory (cd) to where your script is located (e.g. cd C:/scripts/ test.py). Then run the script with "python " (including the .py extension) Second alternative, which is usually easier if you're not comfortable with working in command prompt, is to use an IDE (Integrated Development Environment), python ships with an IDE called IDLE by default. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unsubscribing to tutor assistance
On Sun, 02 Nov 2008 20:53:41 -0600, Sean Fisher wrote: > please end y tutor e-mail assistance > Thank you You can unsubscribe from here: http://mail.python.org/mailman/listinfo/ tutor alternatively, you can also send some magic mail to a magic email address containing some magic subject line and content. I think for this mailing list, the magic address is: [EMAIL PROTECTED], send a message containing just 'help' ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] stopping threads ?
On Mon, 03 Nov 2008 14:46:09 +, dave selby wrote: > Hi All, > > Why when I use threads in my app (I know they are evil ...lol) does it > not stop with ctrl-c, I have to use ctrl-z ? > > Cheers > > Dave Wonder why? Because Ctrl-C merely raises KeyboardInterrupt in the main thread, breaking the main thread, while leaving the other threads running. To interrupt a multi-threaded program, you'd need to stop all running threads. Stopping the current thread is usually easy if you write that thread code, it's usually merely breaking the loop or raising an unhandled exception (or an exception handled outside the thread loop). The problem is to communicate to all threads to quit immediately, a common way is by using an event queue, when the main thread receives a Keyboard Interrupt, it sends as many Quit Event as the number of threads. This Quit Event would be caught by each thread and each thread would exits upon receiving the Quit Event. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read over serial port
On Mon, 03 Nov 2008 08:48:44 -0600, shawn bright wrote: > ok, i have another question: > if i run this: > #!/usr/bin/env python > f = 'test_out' > f = open(f, 'r').read() > for i in f: > print ord(i) > > I get this: > 0 > 6 > 0 > 58 > 128 > 31 > 22 > 103 > 74 > 115 > 222 > 192 > 74 > 115 > 222 > 192 (deleted some in the email for brevity) > > if i do > for i in f: > print chr(ord(i)) > i get the same weird characters. > should these be read some other way? Wait... are these "weird" characters in the form of: �� or if you used "print repr(chr(ord(i)))": "\x87\x88\x89\x8a\x8b\x8c\x8d \x8e\x8f\x90\x91" That is python's escape characters. Python's default byte-to-character encoding is ASCII, a 7-bit encoding, values in the range(128, 256) cannot be represented in ASCII so python uses � to represent these unrepresentable characters. If you used repr(), it would escape the unrepresentable characters into an escaped form, using '\xkk' where kk is the two-digit hexadecimal representing the byte value of the character ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read over serial port
On Mon, 03 Nov 2008 08:48:44 -0600, shawn bright wrote: > ok, i have another question: > if i run this: > #!/usr/bin/env python > f = 'test_out' > f = open(f, 'r').read() > for i in f: > print ord(i) > > I get this: > 0 > 6 > 0 > 58 > 128 > 31 > 22 > 103 > 74 > 115 > 222 > 192 > 74 > 115 > 222 > 192 (deleted some in the email for brevity) > > if i do > for i in f: > print chr(ord(i)) > i get the same weird characters. > should these be read some other way? Wait... are these "weird" characters in the form of: �� or if you used "print repr(chr(ord(i)))": "\x87\x88\x89\x8a\x8b\x8c\x8d \x8e\x8f\x90\x91" That is python's escape characters. Python's default byte-to-character encoding is ASCII, a 7-bit encoding, values in the range(128, 256) cannot be represented in ASCII so python uses � to represent these unrepresentable characters. If you used repr(), it would escape the unrepresentable characters into an escaped form, using '\xkk' where kk is the two-digit hexadecimal representing the byte value of the character ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string.join()
Thanks for the verification, folks. What had me stumped for a while was the first method was string.join(words[,sep]), and the new one showed str.join(words)... it wasn't immediately obvious (to me) that 'str' was in this case supposed to be the separator. Thanks again, Monte ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Thank You! Kent and Kerbros. I got it Regards, Bennedy. > On Sat, Nov 1, 2008 at 7:17 AM, <[EMAIL PROTECTED]> wrote: > >> >> I am struggling with how to enable executable files. I copied the ff >> program on idlle non-interactice and run it. >> >> the_world_is_flat =1 >> if the_world_is_flat: >>print"Be careful not to fall off" >> >> The result came out on the interactive window. I saved this as >> "example.py" on the desktop. The python icon appears on the the desktop >> alright. When I attempt to run it by double clicking the icon, only a >> black DOS window flashes. > > > The problem is that the DOS window closes when the program exits. Try > adding > the line > raw_input("Press return to exit ") > to the end of your program. > > Kent > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] stopping threads ?
On Mon, Nov 3, 2008 at 1:14 PM, Lie Ryan <[EMAIL PROTECTED]> wrote: > On Mon, 03 Nov 2008 14:46:09 +, dave selby wrote: > >> Hi All, >> >> Why when I use threads in my app (I know they are evil ...lol) does it >> not stop with ctrl-c, I have to use ctrl-z ? >> >> Cheers >> >> Dave > > Wonder why? Because Ctrl-C merely raises KeyboardInterrupt in the main > thread, breaking the main thread, while leaving the other threads > running. To interrupt a multi-threaded program, you'd need to stop all > running threads. If you mark the non-main threads as daemon threads then the program will exit without stopping them. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read over serial port
yes, they look like this �� so i used your print repr(chr(ord(i))) and got this '\x00' '\x06' '\x00' ':' '\x80' '\x1f' '\x16' 'g' 'J' 's' '\xde' '\xc0' 'J' 's' '\xde' '\xc0' '\xce' '\xcc' '\x06' '\n' '\x00' '\x00' ' ' '\xaf' 'J' 's' '\xde' '\xc0' so, what do i do now? and thanks for the info, by the way, been writing python for 2 years, but this is all new to me. shawn On Mon, Nov 3, 2008 at 11:28 AM, Lie Ryan <[EMAIL PROTECTED]> wrote: > On Mon, 03 Nov 2008 08:48:44 -0600, shawn bright wrote: > >> ok, i have another question: >> if i run this: >> #!/usr/bin/env python >> f = 'test_out' >> f = open(f, 'r').read() >> for i in f: >> print ord(i) >> >> I get this: >> 0 >> 6 >> 0 >> 58 >> 128 >> 31 >> 22 >> 103 >> 74 >> 115 >> 222 >> 192 >> 74 >> 115 >> 222 >> 192 (deleted some in the email for brevity) >> >> if i do >> for i in f: >> print chr(ord(i)) >> i get the same weird characters. >> should these be read some other way? > > Wait... are these "weird" characters in the form of: > �� > > or if you used "print repr(chr(ord(i)))": "\x87\x88\x89\x8a\x8b\x8c\x8d > \x8e\x8f\x90\x91" > > That is python's escape characters. Python's default byte-to-character > encoding is ASCII, a 7-bit encoding, values in the range(128, 256) cannot > be represented in ASCII so python uses � to represent these > unrepresentable characters. If you used repr(), it would escape the > unrepresentable characters into an escaped form, using '\xkk' where kk is > the two-digit hexadecimal representing the byte value of the character > > ___ > 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] accessing an image with pygame.image.load()
I want to access a spaceship image with pygame.image.load(), so I wrote self.image = pygame.image.load("C:Users\Chris\Documents\python\assignment07\chris_graphics\spaceship.gif") However, I got this error message: error: Couldn't open C:Users\Chris\Documents\python\assignment07\chris_graphics\spaceship.gif I can't give pygame.image.load a path? Does anyone know how I would load an image located in a seperate directory? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read over serial port
On Mon, Nov 3, 2008 at 4:08 PM, shawn bright <[EMAIL PROTECTED]> wrote: > yes, they look like this > �� > > so i used your print repr(chr(ord(i))) and got this Note that that's the same thing as just printing repr(i). > so, what do i do now? > and thanks for the info, by the way, been writing python for 2 years, > but this is all new to me. Maybe we should back up a little bit. You said in your original post that you were expecting ASCII characters from the serial device. How do you know that's what you should be getting back? Have you tried communicating with the device using some other program? If so, what program? Do you have specs that tell you that's how it's supposed to work? Are you sure you're connecting to the device with the right parameters for baudrate, byte size, parity, etc? I notice that nowhere in this thread have you posted the code you use to actually communicate with the serial device. Maybe you should do that. -- Jerry ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python based blogging software/cms?
Not sure if this is appropriate for the tutor mailing list, but it is a beginner question for python. It seems most of the popular cms/blogging software is php/mysql based Anything of substancial popularity/support based on python? I was looking for something along the lines of wordpress popular, but not sure if there exists something for python. I'm aware of Zine (http://dev.pocoo.org/projects/zine/ ) that is trying to become wordpress like, any others? Regards, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] accessing an image with pygame.image.load()
Christopher Spears wrote: I want to access a spaceship image with pygame.image.load(), so I wrote self.image = pygame.image.load("C:Users\Chris\Documents\python\assignment07\chris_graphics\spaceship.gif") However, I got this error message: error: Couldn't open C:Users\Chris\Documents\python\assignment07\chris_graphics\spaceship.gif I can't give pygame.image.load a path? Does anyone know how I would load an image located in a seperate directory? Since \ is used to "escape" certain characters it is advisable to either use \\ or preface the string with r. "C:Users\\Chris\\ etc. OR r"C:Users\Chris\ That *might* solve your problem. it is unfortunate that the error messages say can't open rather than file not found. -- Bob Gailer Chapel Hill NC 919-636-4239 When we take the time to be aware of our feelings and needs we have more satisfying interatctions with others. Nonviolent Communication provides tools for this awareness. As a coach and trainer I can assist you in learning this process. What is YOUR biggest relationship challenge? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python based blogging software/cms?
On Mon, Nov 03, 2008, [EMAIL PROTECTED] wrote: >Not sure if this is appropriate for the tutor mailing list, but it >is a beginner question for python. > >It seems most of the popular cms/blogging software is php/mysql based > >Anything of substancial popularity/support based on python? > >I was looking for something along the lines of wordpress popular, but not >sure if there exists something for python. > >I'm aware of Zine (http://dev.pocoo.org/projects/zine/ ) that is trying to >become wordpress like, any others? We have been using Zope and Plone for about 4 years now. Bill -- INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way Voice: (206) 236-1676 Mercer Island, WA 98040-0820 Fax:(206) 232-9186 "If taxation without consent is not robbery, then any band of robbers have only to declare themselves a government, and all their robberies are legalized." -- Lysander Spooner, Letter to Grover Cleveland 1886 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read over serial port
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. settings are the same as in my python script thanks for any help, shawn On Mon, Nov 3, 2008 at 3:49 PM, Jerry Hill <[EMAIL PROTECTED]> wrote: > On Mon, Nov 3, 2008 at 4:08 PM, shawn bright <[EMAIL PROTECTED]> wrote: >> yes, they look like this >> �� >> >> so i used your print repr(chr(ord(i))) and got this > > Note that that's the same thing as just printing repr(i). > >> so, what do i do now? >> and thanks for the info, by the way, been writing python for 2 years, >> but this is all new to me. > > Maybe we should back up a little bit. You said in your original post > that you were expecting ASCII characters from the serial device. How > do you know that's what you should be getting back? Have you tried > communicating with the device using some other program? If so, what > program? Do you have specs that tell you that's how it's supposed to > work? > > Are you sure you're connecting to the device with the right parameters > for baudrate, byte size, parity, etc? > > I notice that nowhere in this thread have you posted the code you use > to actually communicate with the serial device. Maybe you should do > that. > > -- > Jerry > ___ > 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] accessing an image with pygame.image.load()
On Mon, Nov 3, 2008 at 7:05 PM, bob gailer <[EMAIL PROTECTED]> wrote: > Christopher Spears wrote: >> self.image = >> pygame.image.load("C:Users\Chris\Documents\python\assignment07\chris_graphics\spaceship.gif") >> > > Since \ is used to "escape" certain characters it is advisable to either use > \\ or preface the string with r. Beyond what Bob says about being careful of the escape character ('\') and the need to either double it up in a string literal or use a raw string, are you sure that path is right? Usually a drive letter is followed by a backslash in windows. That is, "C:\Users\Chris" rather than "C:Users\Chris". -- Jerry ___ 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: > 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
Hey all, thanks for all the help. I will go out in the morning and check all the equipment, have heard too much advice from too many with python experience to ignore the fact that something is likely screwed up in my settings or baudrate. will be back in touch later as i check it out. sk On Mon, Nov 3, 2008 at 10:14 PM, Brian C. Lane <[EMAIL PROTECTED]> wrote: > -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 > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor