Re: [Tutor] Need Help Modifying a wxPython GUI (scrolling display and logging)
On 13/06/13 05:24, Matt D wrote: I already told you i found the file? why would someone else be running the program? Because it does something useful? Most pro programmers write programs for other people to use. Even an amateur may be creating something for their family use. If someone other than you were running it that might explain why the current directory wasn't what you expected since they will have a different $HOME for example. That's why Dave was asking. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Value Error
On Wed, Jun 12, 2013 at 6:31 PM, Dave Angel wrote: > i = complex(0,1) >>> 1j 1j http://en.wikipedia.org/wiki/Imaginary_unit#Alternative_notations cmath.sqrt(float((math.e **(i * math.pi)).real)) The real/imag attributes are already floats: >>> from math import e, pi, sin, cos >>> cos(pi / 3), (e ** (1j * pi / 3)).real (0.5001, 0.5001) >>> sin(pi / 3), (e ** (1j * pi / 3)).imag (0.8660254037844386, 0.8660254037844386) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Value Error
On 06/13/2013 04:09 AM, eryksun wrote: On Wed, Jun 12, 2013 at 6:31 PM, Dave Angel wrote: i = complex(0,1) >>> 1j 1j I had forgotten that notation for a complex literal. I knew the magic syntax had j in it, but didn't remember it needs to be part of the numeric token. Of course the output of the debugger should have reminded me, but you did a better job. http://en.wikipedia.org/wiki/Imaginary_unit#Alternative_notations cmath.sqrt(float((math.e **(i * math.pi)).real)) The real/imag attributes are already floats: >>> from math import e, pi, sin, cos >>> cos(pi / 3), (e ** (1j * pi / 3)).real (0.5001, 0.5001) >>> sin(pi / 3), (e ** (1j * pi / 3)).imag (0.8660254037844386, 0.8660254037844386) Yeah, I know. I originally put the float in to get rid of the small bit of imaginary noise that the complex exponentiation created. When that failed, (apparently you can't use float() to get the real portion of a complex value), I added the .real() and forgot to remove the float(). In case this wasn't obvious to everyone, I was just playing with the "e to the I PI is minus one" trick, then feeding that -1 to square root. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)
On 06/13/2013 12:18 AM, Matt D wrote: yes the .py file has TextCtrl fields that get there values from a pickled dictionary. Another peice of the code watches a thread for the pickle. this is why i didnt use a list. I have been unable to find a nice way to just make a list with the items i need. would be nice to have that simplicity. What you said is true, the the list is unordered. More importantly the new line comes in at the wrong point. I want all the values in a row starting with time. from there i will look for a way to remove some unwanted items and ordering the others. I attached the .py file for you to see the whole thing hoping this is not too presumptuous. Thanks. I don't mind the attached source file. Note that some readers may not be able to see it (attachments aren't guaranteed to survive), and others might find it excessive in length. But I'm fine with it. I notice you didn't change the newline to a comma, in the place that I commented earlier. You explicitly separate the fields with newlines, while commenting that it's done with commas. What you presumably want is to change the line inside the loop self.logfile.write('\n') to self.logfile.write(',') and add one of the former lines outside the loop, after writing the last field. About the ordering: Do you have a specific ordering in mind? Who decides it? The program that creates the pickle? How tightly bound are the two? Is there a 3rd program that's going to read the csv file? Are all of these programs written in Python? Will there be multiple versions, over time? If all of these programs have to share the same definition for the csv file, then at least some of it should be in common code. Simplest is to have the list/tuple of field names as a real list, defined in a module that they all import. Then, instead of using self.fields.items(), you use something like common.FIELD_LIST_NAMES common.py might have a line something like: #define the tuple of names that will be used for the csv file FIELD_LIST_NAMES = ("date", "duid", "nac", "source", "dest", "mfid", "algid", "kid", "mi", "tgid") Notice that TrafficPanel.init() might well collapse into a loop, if you add just a little more information into common.py Then you'd find that editing the one place adds a new field, both to the csv file but also to the gui. However, then if you add a new field, or remove one, you're obsoleting any csv files that may still be lying around, with no way to detect which ones are new and which ones are old. Typically this is managed with a version field in the first line of the file. But another, more standard, way to manage this is to make it a real csv file, with the field names in the first line (also comma separated). Python has a csv module, which solves another potential problem your logic may have: what happens if any of those values has a comma in it? I know I only hinted at the possible implementations, but until you make some architectural choices clear, I really cannot add much more. Here are some other remarks about the code: line 53: method Clone() should be lowercase, per Pep8. I don't believe it does anything useful, but you don't call it anyway. line 76: deleting a local just before a method returns does exactly nothing. When the method ends, the local will go out of scope, and the effect in either case is to decrement the refcount for the created DataEvent instance. Incidentally, if you happen to be using Thunderbird, you might look for the Reply-List button. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need Help Modifying a wxPython GUI (scrolling display and logging)
On 06/13/2013 03:39 AM, Alan Gauld wrote: > On 13/06/13 05:24, Matt D wrote: > >> I already told you i found the file? why would someone else be running >> the program? > > Because it does something useful? > Most pro programmers write programs for other people to use. > Even an amateur may be creating something for their family use. > > If someone other than you were running it that might explain why the > current directory wasn't what you expected since they will have a > different $HOME for example. That's why Dave was asking. > yeah i am not a programmer. just trying to increase the utility of a program (open source) someone else wrote. the file was in the home directory but i have so much pollution there that it took too long for me to spot it. not sure whey the file search didn't work. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)
On 06/13/2013 08:22 AM, Dave Angel wrote: > On 06/13/2013 12:18 AM, Matt D wrote: >> >> >> >>> >>> >> yes the .py file has TextCtrl fields that get there values from a >> pickled dictionary. Another peice of the code watches a thread for the >> pickle. this is why i didnt use a list. I have been unable to find a >> nice way to just make a list with the items i need. would be nice to >> have that simplicity. >> What you said is true, the the list is unordered. More importantly the >> new line comes in at the wrong point. I want all the values in a row >> starting with time. from there i will look for a way to remove some >> unwanted items and ordering the others. >> I attached the .py file for you to see the whole thing hoping this is >> not too presumptuous. Thanks. >> >> > > I don't mind the attached source file. Note that some readers may not > be able to see it (attachments aren't guaranteed to survive), and others > might find it excessive in length. But I'm fine with it. > > I notice you didn't change the newline to a comma, in the place that I > commented earlier. You explicitly separate the fields with newlines, > while commenting that it's done with commas. > > What you presumably want is to change the line inside the loop > > self.logfile.write('\n') > to > self.logfile.write(',') > > and add one of the former lines outside the loop, after writing the last > field. > > About the ordering: Do you have a specific ordering in mind? Who > decides it? The program that creates the pickle? How tightly bound are > the two? Is there a 3rd program that's going to read the csv file? Are > all of these programs written in Python? Will there be multiple > versions, over time? > > If all of these programs have to share the same definition for the csv > file, then at least some of it should be in common code. Simplest is to > have the list/tuple of field names as a real list, defined in a module > that they all import. Then, instead of using self.fields.items(), you > use something like common.FIELD_LIST_NAMES > > common.py might have a line something like: > > #define the tuple of names that will be used for the csv file > FIELD_LIST_NAMES = ("date", "duid", "nac", "source", "dest", "mfid", > "algid", "kid", "mi", "tgid") > > Notice that TrafficPanel.init() might well collapse into a loop, if you > add just a little more information into common.py Then you'd find that > editing the one place adds a new field, both to the csv file but also to > the gui. > > However, then if you add a new field, or remove one, you're obsoleting > any csv files that may still be lying around, with no way to detect > which ones are new and which ones are old. Typically this is managed > with a version field in the first line of the file. > > But another, more standard, way to manage this is to make it a real csv > file, with the field names in the first line (also comma separated). > Python has a csv module, which solves another potential problem your > logic may have: what happens if any of those values has a comma in it? > > > I know I only hinted at the possible implementations, but until you make > some architectural choices clear, I really cannot add much more. > > Here are some other remarks about the code: > > line 53: method Clone() should be lowercase, per Pep8. I don't believe > it does anything useful, but you don't call it anyway. > > line 76: deleting a local just before a method returns does exactly > nothing. When the method ends, the local will go out of scope, and the > effect in either case is to decrement the refcount for the created > DataEvent instance. > > Incidentally, if you happen to be using Thunderbird, you might look for > the Reply-List button. > Hey, line 202: self.logfile.write('%s,'%(str(f))) d does put the comma in properly but, line 203: self.logfile.write('\n') was putting the newline after each value like you said. I moved this back outside of the if statement to see (i am still a little unsure about the indention and i have to test) if it will create a new row only when all the k,v values have been looped through. the ordering: yes this is quite a hole in my understanding of what is going on here. the pickle is created in a collection of pretty complicated C++ code that doesn't explicitly show how the pickle is ordered or whats in it even in the pickle.cc and pickle.h files. the pickle files take in some sort of stream, pickle the data, and send it to a message queue that the trafficpanel waits on. i need to log this pickle or at at least dump it to terminal because i am pretty sure the 'source' and 'dest' fields (which currently are not available) are in the pickle, albeit in a different data unit. I have read "http://www.python.org/doc//current/library/pickle.html"; two times already and still cant find a way to print the pickle in human readable form. my understanding of pickling stinks. The ordering at this point is not so impor
[Tutor] regex grouping/capturing
Hello, I have a string of the form "required optional3 optional2 optional1 optional3" ('optional' may be any kind of string, so it's not simply 'optional\d+'. I would like to use a regex so I can distinguish groups. Desired outcome: ('required', 'optional3', 'optional2', 'optional1', 'optional3'). Below is a fragment of the many things I have tried. >>> import re >>> regex = r"(required) (optional1)* (optional2)* (optional3)*" >>> #regex = r"(required) (?:(optional1)*|(optional2)*|(optional3)*)*" >>> #regex = r"(required) (optional1|optional2|optional3)*" >>> s = "required optional3 optional2 optional1 optional3" >>> re.search(regex, s).groups() Traceback (most recent call last): File "", line 1, in re.search(regex, s).groups() AttributeError: 'NoneType' object has no attribute 'groups' >>> s2 = "required optional1 optional2 optional3" >>> re.search(regex, s2).groups() ('required', 'optional1', 'optional2', 'optional3') # it only 'works' if the optional words are in the same order as in the regex, and not specified multiple times. How can I make this work? Thank you in advance! Regards, Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)
On 06/13/2013 10:37 AM, Matt D wrote: On 06/13/2013 08:22 AM, Dave Angel wrote: On 06/13/2013 12:18 AM, Matt D wrote: Hey, line 202: self.logfile.write('%s,'%(str(f))) d does put the comma in properly but, line 203: self.logfile.write('\n') was putting the newline after each value like you said. I moved this back outside of the if statement to see (i am still a little unsure about the indention and i have to test) if it will create a new row only when all the k,v values have been looped through. Then put it AFTER the loop, not after the if. It should line up with the for statement. And if you mix spaces with tabs, heaven help you. Different people have different preferences, but I despise tabs in source code. Notice that you've done it at least four places: #output the value with trailing comma #if the field 'duid' == 'hdu', then clear all the fields return 0 main() If your editor let you do that, you aren't using the right settings on the editor (or the right editor). This didn't affect anything, since indentation doesn't matter on comments, and the other two lines are isolated indentations. the ordering: yes this is quite a hole in my understanding of what is going on here. the pickle is created in a collection of pretty complicated C++ code that doesn't explicitly show how the pickle is ordered or whats in it even in the pickle.cc and pickle.h files. the pickle files take in some sort of stream, pickle the data, and send it to a message queue that the trafficpanel waits on. i need to log this pickle or at at least dump it to terminal because i am pretty sure the 'source' and 'dest' fields (which currently are not available) are in the pickle, albeit in a different data unit. I have read "http://www.python.org/doc//current/library/pickle.html"; two times already and still cant find a way to print the pickle in human readable form. my understanding of pickling stinks. The ordering at this point is not so important (not nearly as important as getting the 'source' 'dest' fields) because the point of the .csv file is just to import it into librecalc and work time series analysis on the data manually. at some later point in the development maybe this this task can be automated but for now just an unordered file will suffice. If you want a consistent ordering, then add the line I described to your own source code, at module scope. Since you have no access to (control over) the C++ code, you'll just have to make up your own list, as you've already effectively done with your GUI. For every field that is NOT in the dict, you should be outputting a simple comma. So your if test is wrong, since it will eat zeros as well as missing values. And you need an else clause: for k,v in FIELD_LIST_NAMES: # get the value of the current TextCtrl field f = field_values.get(k, None) if not f is None: #output the value with trailing comma self.logfile.write('%s,'%(str(f))) else: self.logfile.write(",") self.logfile.write("\n") And don't forget to add in the header line to your csv file, naming the fields that are to be used in every line. -- -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)
On 06/13/2013 11:23 AM, Dave Angel wrote: > On 06/13/2013 10:37 AM, Matt D wrote: >> On 06/13/2013 08:22 AM, Dave Angel wrote: >>> On 06/13/2013 12:18 AM, Matt D wrote: > > >>> >> Hey, >> line 202: self.logfile.write('%s,'%(str(f))) d >> does put the comma in properly but, >> line 203: self.logfile.write('\n') >> was putting the newline after each value like you said. >> I moved this back outside of the if statement to see (i am still a >> little unsure about the indention and i have to test) if it will create >> a new row only when all the k,v values have been looped through. > > Then put it AFTER the loop, not after the if. It should line up with > the for statement. And if you mix spaces with tabs, heaven help you. > Different people have different preferences, but I despise tabs in > source code. Notice that you've done it at least four places: > > #output the value with trailing comma > #if the field 'duid' == 'hdu', then clear all the fields > return 0 > main() > > If your editor let you do that, you aren't using the right settings on > the editor (or the right editor). This didn't affect anything, since > indentation doesn't matter on comments, and the other two lines are > isolated indentations. > > >> >> the ordering: yes this is quite a hole in my understanding of what is >> going on here. the pickle is created in a collection of pretty >> complicated C++ code that doesn't explicitly show how the pickle is >> ordered or whats in it even in the pickle.cc and pickle.h files. the >> pickle files take in some sort of stream, pickle the data, and send it >> to a message queue that the trafficpanel waits on. i need to log this >> pickle or at at least dump it to terminal because i am pretty sure the >> 'source' and 'dest' fields (which currently are not available) are in >> the pickle, albeit in a different data unit. I have read >> "http://www.python.org/doc//current/library/pickle.html"; two times >> already and still cant find a way to print the pickle in human readable >> form. my understanding of pickling stinks. The ordering at this point >> is not so important (not nearly as important as getting the 'source' >> 'dest' fields) because the point of the .csv file is just to import it >> into librecalc and work time series analysis on the data manually. at >> some later point in the development maybe this this task can be >> automated but for now just an unordered file will suffice. > > If you want a consistent ordering, then add the line I described to your > own source code, at module scope. Since you have no access to (control > over) the C++ code, you'll just have to make up your own list, as you've > already effectively done with your GUI. For every field that is NOT in > the dict, you should be outputting a simple comma. > > So your if test is wrong, since it will eat zeros as well as missing > values. And you need an else clause: > > for k,v in FIELD_LIST_NAMES: > # get the value of the current TextCtrl field > f = field_values.get(k, None)2013-06-12 16:28:59,Unknown (0x658), DES-OFB, HDU, 0xa4d5010ca0bbdb0900, 0xfff, Standard MFID (pre-2001), 00x1, > if not f is None: > #output the value with trailing comma > self.logfile.write('%s,'%(str(f))) > else: > self.logfile.write(",") > self.logfile.write("\n") > > And don't forget to add in the header line to your csv file, naming the > fields that are to be used in every line. > as of now the order in the .csv file is like this: 2013-06-12 16:28:59,Unknown (0x658), 00x80, $80 Clear, 0xa4d5010ca0bbdb0900, 0xfff, Standard MFID (pre-2001), 00x1, and keeps repeating this order as long as HUDs are coming in. i am unsure why the date/time is on the same line as NAC? Oh and i have not tested yet with the '\n' newline command out of the if statement. If i have to i can modify the C++ code but was hoping not to have to do that at this stage. the C++ is used for what is computationally intense and the Python is used mainly for the UI. Any idea of a way to write the pickle to file to see what it contains? because it is not explicit in the C++ files, at least not as far as I can tell as of yet. Thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] sound implementation problems
Hi I'm about 2 yrs into studying Python - started with "Hello World", and I'm working with v 2.5.1 right now. The past year I've begun trying to write my own interactive fiction. That works pretty well, but now I'm attempting to put some music into programs (I thought background music would be good), and I'm running into roadblocks. I've tried several different things for this, and come up with either my text that comes to a halt eventually at an error message (can't read from the files or mixer isn't initialized are the most common ones), or a completely blank screen with no sound. I've tried both .mp3 files and .wav ones, neither works for this. Here's the most recent code I've attempted: import pygame , sys import random size=[500,500] def run(self): import pygame.mixer pygame.mixer.init(22050, -16, 2, 4096) self.sound.seek(0) snd = pygame.mixer.Sound(self.sound) pygame.mixer.Sound.play("bach-cello-suite-1.wav") musicPlaying = True Any ideas would be appreciated. Thanks. my website: http://jahowe.com___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)
On 06/13/2013 12:32 PM, Matt D wrote: On 06/13/2013 11:23 AM, Dave Angel wrote: On 06/13/2013 10:37 AM, Matt D wrote: On 06/13/2013 08:22 AM, Dave Angel wrote: On 06/13/2013 12:18 AM, Matt D wrote: Hey, line 202: self.logfile.write('%s,'%(str(f))) d does put the comma in properly but, line 203: self.logfile.write('\n') was putting the newline after each value like you said. I moved this back outside of the if statement to see (i am still a little unsure about the indention and i have to test) if it will create a new row only when all the k,v values have been looped through. Then put it AFTER the loop, not after the if. It should line up with the for statement. And if you mix spaces with tabs, heaven help you. Different people have different preferences, but I despise tabs in source code. Notice that you've done it at least four places: #output the value with trailing comma #if the field 'duid' == 'hdu', then clear all the fields return 0 main() If your editor let you do that, you aren't using the right settings on the editor (or the right editor). This didn't affect anything, since indentation doesn't matter on comments, and the other two lines are isolated indentations. the ordering: yes this is quite a hole in my understanding of what is going on here. the pickle is created in a collection of pretty complicated C++ code that doesn't explicitly show how the pickle is ordered or whats in it even in the pickle.cc and pickle.h files. the pickle files take in some sort of stream, pickle the data, and send it to a message queue that the trafficpanel waits on. i need to log this pickle or at at least dump it to terminal because i am pretty sure the 'source' and 'dest' fields (which currently are not available) are in the pickle, albeit in a different data unit. I have read "http://www.python.org/doc//current/library/pickle.html"; two times already and still cant find a way to print the pickle in human readable form. my understanding of pickling stinks. The ordering at this point is not so important (not nearly as important as getting the 'source' 'dest' fields) because the point of the .csv file is just to import it into librecalc and work time series analysis on the data manually. at some later point in the development maybe this this task can be automated but for now just an unordered file will suffice. If you want a consistent ordering, then add the line I described to your own source code, at module scope. Since you have no access to (control over) the C++ code, you'll just have to make up your own list, as you've already effectively done with your GUI. For every field that is NOT in the dict, you should be outputting a simple comma. So your if test is wrong, since it will eat zeros as well as missing values. And you need an else clause: for k,v in FIELD_LIST_NAMES: # get the value of the current TextCtrl field f = field_values.get(k, None)2013-06-12 16:28:59,Unknown (0x658), DES-OFB, HDU, 0xa4d5010ca0bbdb0900, 0xfff, Standard MFID (pre-2001), 00x1, if not f is None: #output the value with trailing comma self.logfile.write('%s,'%(str(f))) else: self.logfile.write(",") self.logfile.write("\n") And don't forget to add in the header line to your csv file, naming the fields that are to be used in every line. as of now the order in the .csv file is like this: 2013-06-12 16:28:59,Unknown (0x658), 00x80, $80 Clear, 0xa4d5010ca0bbdb0900, 0xfff, Standard MFID (pre-2001), 00x1, and keeps repeating this order as long as HUDs are coming in. i am unsure why the date/time is on the same line as NAC? Because you don't have a bogus newline after the date/time, but do after all the other fields. Oh and i have not tested yet with the '\n' newline command out of the if statement. If i have to i can modify the C++ code but was hoping not to have to do that at this stage. the C++ is used for what is computationally intense and the Python is used mainly for the UI. Any idea of a way to write the pickle to file to see what it contains? because it is not explicit in the C++ files, at least not as far as I can tell as of yet. Thanks! I don't see any need to modify the C++ sources. I don't know how to examine a pickle, file or otherwise. You can, however, trivially print out all the keys (and values even) in field_values, for each record, and make sure they match your FIELD_LIST_NAMES, other than for order. Perhaps they named source and dest as Source and dESt, respectively, or src and dst, or whatever. If you really want the pickle as a file, you could write pickled_dict to a separate file. Just be sure to create that file as binary, since (some ?) pickle formats are not text. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or ch
Re: [Tutor] sound implementation problems
On 06/13/2013 01:21 PM, jessica peters wrote: Hi I'm about 2 yrs into studying Python - started with "Hello World", and I'm working with v 2.5.1 right now. The past year I've begun trying to write my own interactive fiction. That works pretty well, but now I'm attempting to put some music into programs (I thought background music would be good), and I'm running into roadblocks. I've tried several different things for this, and come up with either my text that comes to a halt eventually at an error message (can't read from the files or mixer isn't initialized are the most common ones), or a completely blank screen with no sound. I've tried both .mp3 files and .wav ones, neither works for this. Here's the most recent code I've attempted: import pygame , sys import random size=[500,500] def run(self): It's not customary to use self as a name in a non-class function. import pygame.mixer pygame.mixer.init(22050, -16, 2, 4096) self.sound.seek(0) What is the object that has this sound attribute? snd = pygame.mixer.Sound(self.sound) pygame.mixer.Sound.play("bach-cello-suite-1.wav") musicPlaying = True Nobody calls the function, so this file will silently exit. Any ideas would be appreciated. Thanks. Somebody familiar with both pygame and with sound might be able to help. But you really ought to tell them what version of pygame, and what OS you're running on. And if you get an error message, copy/paste the whole thing, don't paraphrase, and show the same code as what was failing. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sound implementation problems
I'll assume you're using Windows. If not, ignore this ;') winsound on windows is Python native, much simpler, and always works. After importing it you can type help(winsound) to see its controls. But here is the usage for a wav file (it doesn't play mp3s) There is no rule you have to use the pygame functionality, which is more complex, to get a sound, if that's all you want. import winsound winsound.PlaySound('c:/python33/media/wtf.wav', 1) Make sure you end with the "1". The helpfile doesn't mention what to use as the second parameter, but 1 works fine. And one other thing that tripped me up. If you're using an IDE or editor, mine has the unfortunate habit of loading in its own directory, and having no option to automatically access files from my program directory. It saves a program into the last used directory, but looks for sounds in its own directory. Ugh. When I thought my program was accessing a wav from my standard program directory, it was really trying to find it in the PyScripter directory ;') So use the Full Path to your sound file, and avoid that possible problem. I have a startup script that now stays in my program directory, though. Of course, if you have an IDE or editor that lets you set the default directory that's no problem. If your editor doesn't do default directories but has startup scripts this will work (changing the directoy in chdir to your system, of course) import os os.chdir('c:/python33/jimprogs') del(os) Jim On 13 June 2013 10:21, jessica peters wrote: > Hi > > I'm about 2 yrs into studying Python - started with "Hello World", and I'm > working with v 2.5.1 right now. The past year I've begun trying to write > my own interactive fiction. That works pretty well, but now I'm attempting > to put some music into programs (I thought background music would be good), > and I'm running into roadblocks. > > I've tried several different things for this, and come up with either my > text that comes to a halt eventually at an error message (can't read from > the files or mixer isn't initialized are the most common ones), or a > completely blank screen with no sound. I've tried both .mp3 files and .wav > ones, neither works for this. > > Here's the most recent code I've attempted: > > import pygame , sys > import random > size=[500,500] > def run(self): > import pygame.mixer > pygame.mixer.init(22050, -16, 2, 4096) > self.sound.seek(0) > snd = pygame.mixer.Sound(self.sound) > pygame.mixer.Sound.play("bach-cello-suite-1.wav") > musicPlaying = True > > Any ideas would be appreciated. Thanks. > > my website: http://jahowe.com > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Jim A noun is just a verb with the hiccups ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sound implementation problems
I'd start with something simple first, to make sure you have sound output etc. Run python interactively in the directory you have your wav file. At a minimum, you need to import pygame, init the mixer (args are not really needed, but I'll use what you had), set up the sound file and finally, play it: >>> import pygame >>> pygame.mixer.init(22050,-16,2,4096) >>> snd = pygame.mixer.Sound("bach-cello-suite-1.wav") >>> music = snd.play() music will start playing in the background. To check if the music is still playing: >>> music.get_busy() 1 >>> music.get_busy() 1 >>> music.get_busy() 0 And that's that. In your code, your run() function was probably a method taken out of a class where sound returns a filename and seek(0) seeks to the beginning of a file. You are missing the rest of the class. But, like I said, you really only need 4 lines to play a wav file. BTW, nice russian машинистка in the background image of your site. Francois -- www.pyptug.org - raspberry-python.blogspot.com - @f_dion On Thu, Jun 13, 2013 at 1:21 PM, jessica peters wrote: > Hi > > I'm about 2 yrs into studying Python - started with "Hello World", and I'm > working with v 2.5.1 right now. The past year I've begun trying to write > my own interactive fiction. That works pretty well, but now I'm attempting > to put some music into programs (I thought background music would be good), > and I'm running into roadblocks. > > I've tried several different things for this, and come up with either my > text that comes to a halt eventually at an error message (can't read from > the files or mixer isn't initialized are the most common ones), or a > completely blank screen with no sound. I've tried both .mp3 files and .wav > ones, neither works for this. > > Here's the most recent code I've attempted: > > import pygame , sys > import random > size=[500,500] > def run(self): > import pygame.mixer > pygame.mixer.init(22050, -16, 2, 4096) > self.sound.seek(0) > snd = pygame.mixer.Sound(self.sound) > pygame.mixer.Sound.play("bach-cello-suite-1.wav") > musicPlaying = True > > Any ideas would be appreciated. Thanks. > > my website: http://jahowe.com > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regex grouping/capturing
On 13.06.2013 17:09, Albert-Jan Roskam wrote: I have a string of the form "required optional3 optional2 optional1 optional3" ('optional' may be any kind of string, so it's not simply 'optional\d+'. I would like to use a regex so I can distinguish groups. Desired outcome: ('required', 'optional3', 'optional2', 'optional1', 'optional3'). Below is a fragment of the many things I have tried. [SNIP] How can I make this work? If you really want to use a regex: >>> import re >>> s = "required optional3 optional2 optional1 optional3" >>> s2 = "required optional1 optional2 optional3" >>> pattern = "required|optional1|optional2|optional3" >>> re.findall(pattern, s) ['required', 'optional3', 'optional2', 'optional1', 'optional3'] >>> re.findall(pattern, s2) ['required', 'optional1', 'optional2', 'optional3'] But why not simply: >>> s.split() ['required', 'optional3', 'optional2', 'optional1', 'optional3'] >>> s2.split() ['required', 'optional1', 'optional2', 'optional3'] Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] find a tutorial for starting with python and netbeans (Igor Fleischer)
void that possible problem. I > have a startup script that now stays in my program directory, though. Of > course, if you have an IDE or editor that lets you set the default > directory that's no problem. > > If your editor doesn't do default directories but has startup scripts this > will work (changing the directoy in chdir to your system, of course) > > import os > os.chdir('c:/python33/jimprogs') > del(os) > > > Jim > > On 13 June 2013 10:21, jessica peters wrote: > > > Hi > > > > I'm about 2 yrs into studying Python - started with "Hello World", and > I'm > > working with v 2.5.1 right now. The past year I've begun trying to write > > my own interactive fiction. That works pretty well, but now I'm > attempting > > to put some music into programs (I thought background music would be > good), > > and I'm running into roadblocks. > > > > I've tried several different things for this, and come up with either my > > text that comes to a halt eventually at an error message (can't read from > > the files or mixer isn't initialized are the most common ones), or a > > completely blank screen with no sound. I've tried both .mp3 files and > .wav > > ones, neither works for this. > > > > Here's the most recent code I've attempted: > > > > import pygame , sys > > import random > > size=[500,500] > > def run(self): > > import pygame.mixer > > pygame.mixer.init(22050, -16, 2, 4096) > > self.sound.seek(0) > > snd = pygame.mixer.Sound(self.sound) > > pygame.mixer.Sound.play("bach-cello-suite-1.wav") > > musicPlaying = True > > > > Any ideas would be appreciated. Thanks. > > > > my website: http://jahowe.com > > > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > http://mail.python.org/mailman/listinfo/tutor > > > > > > > -- > Jim > A noun is just a verb with the hiccups > -- next part -- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/tutor/attachments/20130613/df20d7c5/attachment-0001.html > > > > -- > > Message: 3 > Date: Thu, 13 Jun 2013 15:21:45 -0400 > From: Francois Dion > To: jessica peters > Cc: "Tutor@python.org" > Subject: Re: [Tutor] sound implementation problems > Message-ID: > gixp4_k4tvrnqzjzgh0gdl...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > I'd start with something simple first, to make sure you have sound output > etc. Run python interactively in the directory you have your wav file. At a > minimum, you need to import pygame, init the mixer (args are not really > needed, but I'll use what you had), set up the sound file and finally, play > it: > > >>> import pygame > >>> pygame.mixer.init(22050,-16,2,4096) > >>> snd = pygame.mixer.Sound("bach-cello-suite-1.wav") > >>> music = snd.play() > > music will start playing in the background. To check if the music is still > playing: > > >>> music.get_busy() > 1 > >>> music.get_busy() > 1 > >>> music.get_busy() > 0 > > And that's that. In your code, your run() function was probably a method > taken out of a class where sound returns a filename and seek(0) seeks to > the beginning of a file. You are missing the rest of the class. But, like I > said, you really only need 4 lines to play a wav file. > > BTW, nice russian ?? in the background image of your site. > > Francois > -- > www.pyptug.org - raspberry-python.blogspot.com - @f_dion > > > > On Thu, Jun 13, 2013 at 1:21 PM, jessica peters >wrote: > > > Hi > > > > I'm about 2 yrs into studying Python - started with "Hello World", and > I'm > > working with v 2.5.1 right now. The past year I've begun trying to write > > my own interactive fiction. That works pretty well, but now I'm > attempting > > to put some music into programs (I thought background music would be > good), > > and I'm running into roadblocks. > > > > I've tried several different things for this, and come up with either my > > text that comes to a halt eventually at an error message (can't read from > > the files or mixer isn't initialized are the most common ones), or a > > completely blank screen with no sound. I've tried both .mp3 files and > .wav > > ones, neither works for this. > > > > Here's the most recent code I've attempted: > > > > import pygame , sys > > import random > > size=[500,500] > > def run(self): > > import pygame.mixer > > pygame.mixer.init(22050, -16, 2, 4096) > > self.sound.seek(0) > > snd = pygame.mixer.Sound(self.sound) > > pygame.mixer.Sound.play("bach-cello-suite-1.wav") > > musicPlaying = True > > > > Any ideas would be appreciated. Thanks. > > > > my website: http://jahowe.com > > > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > http://mail.python.org/mailman/listinfo/tutor > > > > > -- next part -- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/tutor/attachments/20130613/d42716e0/attachment.html > > > > -- > > Subject: Digest Footer > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > -- > > End of Tutor Digest, Vol 112, Issue 52 > ** > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] find a tutorial for starting with python and netbeans (Igor Fleischer)
On 13 June 2013 14:32, I. Alejandro Fleischer wrote: > Hi, > > Im starting to learn Python, and downloaded Net Beans as an IDE. > Would you recomend me please a tutorial for a begining with this two > integrated enviroments? > I'm just starting, also, went that route, and quickly ditched NetBeans. It's Huge overkill and you'll spend more time fighting with it and setting it up than learning Python. Try Wing 101, which is python-specific, very easy to understand, and works for Python right out of the box. Available for Windows, Linux, and OS-X http://wingware.com/downloads/wingide-101/4.1.13-1/binaries However, if you want to learn a general all-around IDE for all sorts of languages, netbeans or some of the other big IDEs are good for that. Depends on your purposes. But I'm only focusing on Python right now. Python also comes with a GUI, called IDLE, which should be already installed. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] find a tutorial for starting with python and netbeans (Igor Fleischer)
On 13/06/13 22:32, I. Alejandro Fleischer wrote: Hi, Hi, welcome to the list. In future please delete any irrelevant messages from the digest listing. It confuses things and also costs money to those who pay by the byte who have to download lots of irrelevant stuff to read your message. Also its good to know your background. Can you already program in other languages or are you a complete programming beginner? Which OS are you using? Which version of Python are you using? I'm starting to learn Python, and downloaded Net Beans as an IDE. Any good reason why you did that if you don't know how to use it? It's way overkill for learning Python. Learning one thing at a time is usually easier. Would you recommend me please a tutorial for a beginning with this two integrated environments? There are many tutorials listed on the Python web site but which one best suits you depends on: 1) Your starting level 2) Your personal learning style (humorous, concise, theory based, hands-on, etc) 3) Your long term objectives (sys admin automation v games for example) But you could try mine for starters :-) It's aimed at complete beginners, provides background theory, is fairly comprehensive and is moderately serious in tone. It aims to teach programming in general rather than Python specifically. Otherwise try the python web site and/or tell us more about your objectives and background. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sound implementation problems
On 13/06/13 18:56, Jim Mooney wrote: tripped me up. If you're using an IDE or editor, mine has the unfortunate habit of loading in its own directory, and having no option to automatically access files from my program directory. It saves a program into the last used directory, This is a function of the IDE application itself > but looks for sounds in its own directory. And this is a function of the interpreter that the IDE is using to execute your code. The IDE has no direct control over that. It's important when using an IDE to appreciate the bits of your workflow that are being done by the IDE code and the bits being done by the interpreter that the IDE uses to execute your code. So use the Full Path to your sound file, and avoid that possible problem. This is good practice in any program you write. Either derive the full path or set the working directory prior to accessing the files. Full paths are ultimately the only sure way. I have a startup script that now stays in my program directory, though. Of course, if you have an IDE or editor that lets you set the default directory that's no problem. That's a dodgy way to solve the problem since if you change IDE or run the program outside the IDE that startup script will likely get forgotten and not be used. Remember you are not expected to use an IDE for anything other than developing the code, its not intended to be a runtime environment. Relying on the IDE is a bad habit to develop. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] find a tutorial for starting with python and netbeans (Igor Fleischer)
On 14/06/13 07:32, I. Alejandro Fleischer wrote: Hi, Im starting to learn Python, and downloaded Net Beans as an IDE. Would you recomend me please a tutorial for a begining with this two integrated enviroments? Thank you very much. [trimmed almost FIVE PAGES of quoted text] Alejandro, please do not reply to digests without deleting the unnecessary quoted text. We have already see all the messages in the digest, we don't need to see them again copied in your email. I'm afraid I don't know anything about Net Beans, so I can't help you there. But for general Python tutorials, you can start here: http://docs.python.org/2/tutorial/index.html If you are using Python 3, you should start here instead: http://docs.python.org/3/tutorial/index.html Also try this: http://www.alan-g.me.uk/ Good luck, and feel free to come back with any questions! (I recommend that you change your subscription settings away from Digest mode to individual emails. It makes it MUCH easier to carry on a conversation, asking questions and receiving replies, with individual emails.) -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] For those who downloaded the game code...
Seems I made a rather dumb mistake and uploaded a version of the core code that was a partial conversion for the next update, and thus failed miserably when you ran it. I am mobile but did a quick edit and updated the link with something that at least works and doesn't throw errors immediately. Thanks for your patience and efforts! DragonDon ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sound implementation problems
Alan Gauld That's a dodgy way to solve the problem since if you change IDE or run the > program outside the IDE that startup script will likely get forgotten and > not be used. Remember you are not expected to use > an IDE for anything other than developing the code, its not > intended to be a runtime environment. Relying on the IDE is > a bad habit to develop. > Got me already ;') I reinstalled Py2.7 since there are too many things not available yet for Py3.3 - but I know which one is loading at the command line since I specify Python2.7 or Python3.3 (The Activestate dist copies and renames one of the Pys so that's clear - I just went and copied and renamed the other - along with pip) My IDE startup script has been changed to also go to the proper working directory. BUT - Py 3.3 at the command prompt uses my 3.3 working directory, and Py 2.7 ALSO uses the 3.3 working directory, which is not what I want, obviously. Those are two different sets of scripts that won't always play together. Is there a way to set up each different interpreter, either Py 3.3 or Py 2.2, to automatically change to a particular working directory when you call it - with a command line switch for instance? I can os.chdir after it starts, of course, but that's a drag and I'll forget to do it at some point. If I can do that from the call to Python I can make a batch file for each one, with two different names - and easy typing ones like Py27 and Py33 ;') I see one possible candidate in python --help -c cmd : program passed in as string (terminates option list) But what does "program passed in as a string(terminates option list)" mean? How do I stringify import os > os.chdir('my directory') ? That's unclear to me. Speaking of Py distributions I used ActiveState for various reasons, but I looked at Enthought Canopy and was really annoyed. You can go over their entire website and they don't tell you which Python version it's for - 2.7 and 3.3 being a bit different. It's almost like they hide it. ActiveState makes it clear so I used them. I'm pretty sure Canopy is for 2.7 but I'm not going to do a huge download on a slow connection when they don't tell you. -- Jim A noun is just a verb with the hiccups ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sound implementation problems
On 06/13/2013 11:55 PM, Jim Mooney wrote: Alan Gauld That's a dodgy way to solve the problem since if you change IDE or run the program outside the IDE that startup script will likely get forgotten and not be used. Remember you are not expected to use an IDE for anything other than developing the code, its not intended to be a runtime environment. Relying on the IDE is a bad habit to develop. Got me already ;') I reinstalled Py2.7 since there are too many things not available yet for Py3.3 - but I know which one is loading at the command line since I specify Python2.7 or Python3.3 (The Activestate dist copies and renames one of the Pys so that's clear Renames one of what "Pys" ? - I just went and copied and renamed the other - along with pip) My IDE startup script has been changed to also go to the proper working directory. What IDE would that be? BUT - Py 3.3 at the command prompt Do you mean Py 3.3.bat ? With a space in the program name, even? Or something else? uses my 3.3 working directory, and Py 2.7 ALSO uses the 3.3 working directory, which is not what I want, Then why did you write those batch files to change directories at all? What's wrong with getting the current directory from "the actual current directory" ? obviously. Those are two different sets of scripts that won't always play together. Is there a way to set up each different interpreter, either Py 3.3 or Py 2.2, to automatically change to a particular working directory when you call it - with a command line switch for instance? I can os.chdir after it starts, of course, but that's a drag and I'll forget to do it at some point. So you're intending that all the 2.7 scripts you write will use the same current directory? Regardless of the wishes of the author/user? If I can do that from the call to Python I can make a batch file for each one, with two different names - and easy typing ones like Py27 and Py33 ;') I see one possible candidate in python --help -c cmd : program passed in as string (terminates option list) But what does "program passed in as a string(terminates option list)" mean? How do I stringify import os > os.chdir('my directory') ? That's unclear to me. Speaking of Py distributions I used ActiveState for various reasons, but I looked at Enthought Canopy and was really annoyed. You can go over their entire website and they don't tell you which Python version it's for - 2.7 and 3.3 being a bit different. It's almost like they hide it. ActiveState makes it clear so I used them. I'm pretty sure Canopy is for 2.7 but I'm not going to do a huge download on a slow connection when they don't tell you. I don't understand your problem at all. Current directory should nearly always be decided by the user of the code, and should have nothing to do with either the location of the interpreter or the location of the script. And in the 1% of scripts where you cannot figure out how to work with that, you can add the two lines to the beginning of the script. (And lots more lines to the documentation for the script) As for how the unknown IDE decides what to make the current directory when running a particular script, that presumably is the job of the project file. If it forces all scripts to run in the same directory, then contact the author and ask for an update. As others have said, many times the files your script wants to manipulate will go in locations determined at run time, and not relative to the current directory. The current directory should only be used as a target (if at all) for those files you the user wants to create explicitly. In that case, he decides their location by switching to that directory. What I really detest (as a user) is programs that allow me to specify the filename, but won't let me specify a complete path, instead making their own decision on file path. So filename completion won't work, and any intuitive understanding of where this named file will go goes up in smoke. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor