[Tutor] Posting to Numpy and Scipy
Has anyone had a problem posting to either of these mailing lists. I am a member and have sent a few posts to each of them over the last couple months, but none of them show up in the list. I always receive a 'awaiting moderator approval' email. I have sent an email to the owner about this, but have not received a response. -- "The game of science can accurately be described as a never-ending insult to human intelligence." - João Magueijo "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. " -Albert Einstein ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Replace sequence in list - looking for direction
Hello all, Thanks in advance for any thoughts, direction, and guidance. Let's say I have a list like the following: a = ['a1','a2','a3','a4','a5','a6'] and then I have dictionary like the following: b = {'a1,a2,a3':'super'} I need some direction and thoughts on how I might seach the list for the string (the key in dict b) sequence in list a and replace the occurance with the value from dict b. At the end I would like to have list a represented as: a = ['super', 'a4', 'a5', 'a6'] Thanks. G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Moving a window... on windows?
I'm not even sure if this is possible... and so far a google search of "python move windows xp" has failed to yield any helpful looking results. I'm trying to create a script that will move a program window around on the desktop, and other than that search I'm not sure where to look. What we have is a digital signage program that is ridiculously old, and we're trying to squeeze a bit more life out of it, until we have more money to spend on a better solution. It runs on a system with two video cards, because it requires an 640x480 output (regular coax... the system is ~10 yrs old), but the silly programmers did some things so the window will spawn in the same place on the wrong monitor. Currently I move it manually, but I want to automate the movement. If there's a way to move the program window by a specific X, Y value, I could make it work no problem. Does anyone have any experience with this sort of task? Or can someone point me towards a solution? Thanks in advance, Wayne -- 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] Moving a window... on windows?
W W wrote: I'm not even sure if this is possible... and so far a google search of "python move windows xp" has failed to yield any helpful looking results. I'm trying to create a script that will move a program window around on the desktop, and other than that search I'm not sure where to look. What we have is a digital signage program that is ridiculously old, and we're trying to squeeze a bit more life out of it, until we have more money to spend on a better solution. It runs on a system with two video cards, because it requires an 640x480 output (regular coax... the system is ~10 yrs old), but the silly programmers did some things so the window will spawn in the same place on the wrong monitor. Currently I move it manually, but I want to automate the movement. If there's a way to move the program window by a specific X, Y value, I could make it work no problem. Does anyone have any experience with this sort of task? Or can someone point me towards a solution? My guess is that you want the "MoveWindow" API from the pywin32 extensions win32gui module. http://timgolden.me.uk/pywin32-docs/win32gui__MoveWindow_meth.html TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Replace sequence in list - looking for direction
On Mon, Jun 16, 2008 at 10:41 AM, GTXY20 <[EMAIL PROTECTED]> wrote: > I need some direction and thoughts on how I might seach the list for the > string (the key in dict b) sequence in list a and replace the occurance with > the value from dict b. At the end I would like to have list a represented > as: > > a = ['super', 'a4', 'a5', 'a6'] That's a really odd problem... If your dict key value will always be separated by a comma, the easiest thing to do would use split on the key. replacement_items = [] for x in b: replacement_items.append(x.split(',')) [['a1', ' a2', ' a3']] will be replacement_items. You can simply iterate over those values and a.remove(each_value). It took me 6 lines to write a function that will do what you're requesting, though if you want 'super' to replace the consecutive(?) string in place (i.e. a[0:2]) it would take a little more coding, but not much. HTH, Wayne ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Replace sequence in list - looking for direction
On Mon, Jun 16, 2008 at 11:41:25AM -0400, GTXY20 wrote: > Hello all, > > Thanks in advance for any thoughts, direction, and guidance. > > Let's say I have a list like the following: > > a = ['a1','a2','a3','a4','a5','a6'] > > and then I have dictionary like the following: > > b = {'a1,a2,a3':'super'} > > I need some direction and thoughts on how I might seach the list for the > string (the key in dict b) sequence in list a and replace the occurance with > the value from dict b. At the end I would like to have list a represented > as: > > a = ['super', 'a4', 'a5', 'a6'] The following works for your example. I assume the values in the a list are unique. for key in b: keylist = key.split(',') if keylist < a: i = a.index(keylist[0]) print a[:i] + [b[key]] + a[i+len(keylist):] Tiago Saboga. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Moving a window... on windows?
"Tim Golden" <[EMAIL PROTECTED]> wrote Currently I move it manually, but I want to automate the movement. If there's a way to move the program window by a specific X, Y value, I could make it work no problem. Does anyone have any experience with this sort of task? Or can someone point me towards a solution? My guess is that you want the "MoveWindow" API from the pywin32 extensions win32gui module. http://timgolden.me.uk/pywin32-docs/win32gui__MoveWindow_meth.html And also see the Microsoft docs at MSDN. Go to: http://msdn.microsoft.com/en-gb/default.aspx Just type MoveWindow into the search box. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] newbie Python Modules
*Module Name eli.py* x = 0 y = [1, 2] print 'Running module "eli"' def whitney(): print 'whitney' def printValues(): print x , y *When I imported the Module* from eli import x, y, printValues printValues() y[0] = 'cat' x = 'dog' printValues() Output Running module "eli" 0 [1, 2] 0 ['cat', 2] Can Someone explain this to me? Why x remains 0 Is it because x = 'dog' is local variable and y being a list is a mutable object that is changed easily. Also once we reload the module every value reverts to its original value .. Am I Right? Thanks, G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] newbie Python Modules
"Guess?!?" <[EMAIL PROTECTED]> wrote *Module Name eli.py* x = 0 y = [1, 2] def whitney(): print 'whitney' def printValues(): print x , y *When I imported the Module* from eli import x, y, printValues Note that by doing this you are not really importing the module but the names from the module into your name space. printValues() y[0] = 'cat' This is changing the value of the y variable which is in the eli module. x = 'dog' This is creaating a new x value in your local namespace. printValues() This prints the values from the eli module. Running module "eli" 0 [1, 2] 0 ['cat', 2] x is unchanged at zero. y is also unchanged but the content is changed Is it because x = 'dog' is local variable and y being a list is a mutable object that is changed Yes, although being picky about the term local its not strictly true since local means inside a function or method In your case you created a new global (ie module scope) variable x which masked the imported one. Also once we reload the module every value reverts to its original value .. Am I Right? Yes, but you have not "loaded" the module yet, only the names from within it. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] newbie Python Modules
On Mon, Jun 16, 2008 at 4:38 PM, Guess?!? <[EMAIL PROTECTED]> wrote: > Also once we reload the module every value reverts to its original > value .. Am I Right? Yes, but maybe not in the way you think. A new copy of the module will be loaded and bound to the name 'eli'. But the names x, y and printValues, which are bound to values in the old copy of the module, will not change. So if, after all your above manipulations, you import eli reload(eli) you will see that x, y and printValues have the same values as before, but eli.x and eli.y will be restored to the original values. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] newbie Python Modules
Thanks Alan and Kent ...Its much clearer now. Any tutorial/reference you recommend to read about python modules? Thanks G On Mon, Jun 16, 2008 at 5:08 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > On Mon, Jun 16, 2008 at 4:38 PM, Guess?!? <[EMAIL PROTECTED]> wrote: > > > Also once we reload the module every value reverts to its original > > value .. Am I Right? > > Yes, but maybe not in the way you think. A new copy of the module will > be loaded and bound to the name 'eli'. But the names x, y and > printValues, which are bound to values in the old copy of the module, > will not change. > > So if, after all your above manipulations, you > import eli > reload(eli) > > you will see that x, y and printValues have the same values as before, > but eli.x and eli.y will be restored to the original values. > > Kent > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] my own error code when no argument is sent
when i execute my program without an argument i receive, infile = sys.argv[1] IndexError: list index out of range is there a way that i could suppress this and add my own error code ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] my own error code when no argument is sent
when i execute my program without an argument i receive, > > > infile = sys.argv[1] > > IndexError: list index out of range > > is there a way that i could suppress this and add my own error code The direct way to handle this is to check the length of sys.argv first. sys.argv is a list, so you can ask the list for its length. Do you know how to do that? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Using SAPI 5 Voices and Methods
Hi! I am resending this SAPI examples for speech, I guess in some cases the email message gets messed up so I attached the SAPI 5 test for voices along with an HTML version using Java Script. It also has the methods and a voice by name assignment since the voices are an array list by element. So I use the description to find the name. It also lists the voice names in the console field. I guess you could also use the pyTTS version as well. I did have one problem and that was the isfilename flag seems to get an error. But, also my spell tag did not work on my tower computer, but did work on my Lap Top. Do not know why, but it could be a version issue. Yet the isfilename also does not work on the Lap Top, so who knows. Anyway, have fun and install if for either your games or web pages... Bruce #THE NEXT TO LAST TEST IS THE ISFILE AND I COMMENTED IT OUT FOR THERE IS AN ERROR! import Sapi5, time, os av = Sapi5.SynthDriver() av.init() SYNC = av._sync ASYNC = av._async PURGE = av._purge ISFILE = av._is_filename XML = av._xml NOT_XML = av._not_xml PERSIST = av._persist_xml PUNC = av._punc WAIT = av._wait av.Speak("Hello!") av.Speak( "I am speaking in the default voice!") av.Speak( "Number of voices is: %d" % av.getVoiceCount()) av.Speak( "Hello! Now saying the punctuation in this sentence.", PUNC) time.sleep(.5) av.setVoiceByName( "Mike") av.setVolume( 100) av.Speak( " The Volume Is Set At Speaker Volume!") av.setRate( 5) av.setPitch(0) av.setVoiceByName( "Mary") av.setPitch(5) av.Speak( "Set To Voice Mary and Pitch 5 or 75% of maximum pitch!") time.sleep(1) av.setPitch(0) av.setRate(0) av.Speak( "The rate and pitch are now set for normal!") time.sleep(1) av.read_Voices() av.setVoiceByName( "Mary") av.Speak( "Hit enter key to stop speaking!") av.setPitch(10) av.Speak("Pitch 100%", ASYNC) av.setPitch(5) av.Speak("Pitch 75%", ASYNC) av.setPitch(0) av.Speak("Pitch 50%", ASYNC) av.setPitch( -5) av.Speak("Pitch 25%", ASYNC) av.setPitch( -10) av.Speak("Pitch 0%", ASYNC) av.setPitch(0) av.Speak( "Hit enter key!", ASYNC) hit = raw_input("Hit enter key >") #av.SpeakFile( "readthis.txt", ASYNC, ISFILE) av.Speak(" Now Good bye", ASYNC, PURGE) av.setVoiceByName( "Sam") av.Speak( " goodbye") #DRIVERS FOR SAPI 5 AND VOICES! #NOTE THE CONSTANTS AND IN THE SPEAK FUNCTION AND THE ADDING/OR OF THE VALUES. from comtypes.client import CreateObject import _winreg class constants4tts: Wait = -1 Sync = 0 Async = 1 Purge = 2 Is_filename = 4 XML = 8 Not_XML = 16 Persist = 32 Punc = 64 class SynthDriver(): name="sapi5" description="Microsoft Speech API version 5 (sapi.SPVoice)" _pitch = 0 _voices = [] _wait = -1 #WAIT INDEFINITELY _sync = 0 #WAIT UNTIL SPEECH IS DONE. _async = 1 #DO NOT WAIT FOR SPEECH _purge = 2 #CLEAR SPEAKING BUFFER _is_filename = 4 #OPEN WAV FILE TO SPEAK OR SAVE TO WAV FILE _xml = 8 #XML COMMANDS, PRONUNCIATION AND GRAMMER. _not_xml = 16 #NO XML COMMANDS _persist_xml = 32 #Changes made in one speak command persist to other calls to Speak. _punc = 64 #PRONOUNCE ALL PUNCTUATION! def check(self): try: r=_winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,"SAPI.SPVoice") r.Close() return True except: return False #INITIALIZE ENGINE! def init(self): try: self.tts = CreateObject( 'sapi.SPVoice') self._voice=1 self._voiceCount = len(self.tts.GetVoices()) for v in range(self._voiceCount): self._voices.append( self.tts.GetVoices()[v]) return True except: return False #TERMINATE INSTANCE OF ENGINE! def terminate(self): del self.tts #NUMBER OF VOICES FOR ENGINE! def getVoiceCount(self): return len(self.tts.GetVoices()) #NAME OF A VOICE NUMBER! def getVoiceName(self, num): return self.tts.GetVoices()[num-1].GetDescription() #WHAT IS VOICE RATE? def getRate(self): "MICROSOFT SAPI 5 RATE IS -10 TO 10" return (self.tts.rate) #WHAT IS THE VOICE PITCH? def getPitch(self): "PITCH FOR MICROSOFT SAPI 5 IS AN XML COMMAND!" return self._pitch #GET THE ENGINE VOLUME! def getVolume(self): "MICROSOFT SAPI 5 VOLUME IS 1% TO 100%" return self.tts.volume #GET THE VOICE NUMBER! def getVoiceNum(self): return self._voice #SET A VOICE BY NAME! def setVoiceByName(self, name): "VOICE IS SET BY NAME!" for i in range( self._voiceCount): vp = self.tts.GetVoices()[ i].GetDescription().find( name) if vp>0: self.tts.Voice = self._voices[i] #self.tts.Voice = self.tts.GetVoices()[i] self.tts.Speak( "%s Set!" % name) self._voice=i+1 break if i >= self._voiceCount: self.tts.Speak( "%s Not Found!" % name) #USED FOR BOOKMARKING
[Tutor] Python Gotcha - List Question
Exercise 17.6 Write a definition for a class named Kangaroo with the following methods: 1. An init method that initializes an attribute named pouch contents to an empty list. 2. A method named put in pouch that takes an object of any type and adds it to pouch contents. Test your code by creating two Kangaroo objects, assigning them to variables named kanga and roo, and then adding roo to the contents of kanga's pouch. class Kangaroo: def __init__(self, pouch_contents=None): if pouch_contents is None: pouch_contents = [] else: self.pouch_contents = pouch_contents def put_in_pouch(self,obj): self.pouch_contents.append(obj) return self.pouch_contents kanga = Kangaroo([1,2]) roo = Kangaroo([3,4]) print kanga,roo print kanga.put_in_pouch(roo.pouch_contents) ** <__main__.Kangaroo instance at 0x00A9A878> <__main__.Kangaroo instance at 0x00A9A8A0> [1, 2, [3, 4]] ** when I modify as class Kangaroo: def __init__(self, pouch_contents=None): if pouch_contents is None: pouch_contents = [] else: self.pouch_contents = pouch_contents def put_in_pouch(self,obj): self.pouch_contents.append(obj) return self.pouch_contents kanga = Kangaroo() roo = Kangaroo() print kanga,roo print kanga.put_in_pouch(roo) I get error which states ... empty list never got formed <__main__.Kangaroo instance at 0x00A9A878> <__main__.Kangaroo instance at 0x00A9A8A0> Traceback (most recent call last): File "C:\Documents and Settings\Gagan\workspace\PythonWork\src\Kangaroo.py", line 17, in print kanga.put_in_pouch(roo) File "C:\Documents and Settings\Gagan\workspace\PythonWork\src\Kangaroo.py", line 10, in put_in_pouch self.pouch_contents.append(obj) AttributeError: Kangaroo instance has no attribute 'pouch_contents' Where Am I acting as NewBie :)? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Gotcha - List Question
On Tue, Jun 17, 2008 at 12:14 AM, Guess?!? <[EMAIL PROTECTED]> wrote: > Exercise 17.6 Write a definition for a class named Kangaroo with the > following methods: [cut] Be careful about asking for homework help. We're restricted from giving much help on homework questions. The error message you're seeing is: AttributeError: Kangaroo instance has no attribute 'pouch_contents' I would believe this message. This is saying that, for some reason, your Kangaroos don't have pouches. Where would this 'pouch_contents' attribute be initialized? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter problem
A followup on the message below. The source code has errors in it because I keyed it in rather than copying and pasting, as pointed out by Alan Gauld. Joe replied with corrected code and said it worked for him. I took his code and ran it on the Mac and had the same problem as before: everything but the background color worked. I then installed Python on a Windows PC and tried the same code: with the PC, the background color works. So the problem seems to be bug in Tkinter for the Mac. Thanks Alan and Joe for your help. Message: 3 Date: Sun, 15 Jun 2008 14:07:58 -0700 From: Arden Hall <[EMAIL PROTECTED]> Subject: [Tutor] Tkinter problem To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed I'm trying to learn to use Tkinter from "Thinking in Tkinter" and don't seem to be able to get the examples to work the way they are supposed to. I have the latest version of Python on a Macbook. Here's an example of the kind of problem I run into: The source code is: from Tkinter import * root = Tk() myContainer1 = Frame(root) myContainer.pack() button1 = Button(myContainer1) button1["text"} = "Hello, World!" button1[background"] = "green" button1.pack root.mainloop() I can execute this, but the button isn't green (or any other color I try) although it turns blue when I click the mouse on it. . Similarly, I've tried to write a bit of code to create a canvas object and put a rectangle in it, but I can't dimension the canvas, change its color, or get the rectangle to appear. Any advice or suggestion where to look for documentation would be greatly appreciated. Thanks Arden ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Gotcha - List Question
Hello Danny, It isnt my homework. I am reading Think Python: An Introduction to Software Design . This is Exercise question of Chap 17 Thanks, G On Mon, Jun 16, 2008 at 9:24 PM, Danny Yoo <[EMAIL PROTECTED]> wrote: > On Tue, Jun 17, 2008 at 12:14 AM, Guess?!? <[EMAIL PROTECTED]> wrote: >> Exercise 17.6 Write a definition for a class named Kangaroo with the >> following methods: > > [cut] > > Be careful about asking for homework help. We're restricted from > giving much help on homework questions. > > > The error message you're seeing is: > >AttributeError: Kangaroo instance has no attribute 'pouch_contents' > > I would believe this message. This is saying that, for some reason, > your Kangaroos don't have pouches. > > Where would this 'pouch_contents' attribute be initialized? > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Gotcha - List Question
Hello All, Just made a minor change . its fixed now :) class Kangaroo: def __init__(self, pouch_contents=None): if pouch_contents is None: self.pouch_contents = [] else: self.pouch_contents = pouch_contents def put_in_pouch(self,obj): self.pouch_contents.append(obj) return self.pouch_contents kanga = Kangaroo() roo = Kangaroo() print kanga,roo print kanga.put_in_pouch(roo.pouch_contents) ***88 <__main__.Kangaroo instance at 0x00A9A878> <__main__.Kangaroo instance at 0x00A9A8A0> [[]] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] a question about iterators
I've been learning about how to implement an iterator in a class from Core Python Programming (2nd Edition). >>> class AnyIter(object): ... def __init__(self, data, safe=False): ... self.safe = safe ... self.iter = iter(data) ... ... def __iter__(self): ... return self ... ... def next(self, howmany=1): ... retval = [] ... for eachItem in range(howmany): ... try: ... retval.append(self.iter.next()) ... except StopIteration: ... if self.safe: ... break ... else: ... raise ... return retval ... >>> >>> a = AnyIter(range(10)) >>> i = iter(a) >>> for j in range(1,5): ... print j, ':', i.next(j) ... 1 : [0] 2 : [1, 2] 3 : [3, 4, 5] 4 : [6, 7, 8, 9] I am confused by this statement: >>> i = iter(a) Why do I need to turn 'a' into an iterator? Didn't I already do this when I constructed the class? As a test, I tried the following: >>> for j in range(1,5): ... print j, ':', a.next(j) ... 1 : Traceback (most recent call last): File "", line 2, in ? File "", line 13, in next StopIteration >>> Why didn't that work? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor