Re: [Tutor] Beep sound
On 24/03/13 12:18, Steven D'Aprano wrote: On 24/03/13 10:31, Phil wrote: Actually, I didn't think there was any need to make any guesses since "echo -e" is exclusively a Linux command. Nonsense. Not only does echo exist as a command on any Unix, including Apple Mac OS, FreeBSD, OpenBSD, Solaris and others, it also exists on Windows and DOS: http://www.computerhope.com/echohlp.htm I don't want to appear augmentative but there is no echo -e command for Windows. There is, however, echo without the 'e' switch. -- Regards, Phil ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python based SMB 2.1/3 testing tool
Hi, I'm looking for a tool like PySMB which can provide support for SMB 2.1. Any references will be appreciated. Thanks, Pankaj ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beep sound
On 24/03/13 10:31, Phil wrote: Actually, I didn't think there was any need to make any guesses since "echo -e" is exclusively a Linux command. Nonsense. Not only does echo exist as a command on any Unix, including Apple Mac OS, FreeBSD, OpenBSD, Solaris and others, it also exists on Windows and DOS: http://www.computerhope.com/echohlp.htm More important than the operating system, what terminal application are you using, and does it have Terminal Bell enabled? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beep sound
On 24/03/13 03:42, Bod Soutar wrote: On Mar 23, 2013 2:24 AM, "Steven D'Aprano" mailto:st...@pearwood.info>> wrote: > > On 23/03/13 12:48, Phil wrote: >> >> Just out of curiosity how can a beep sound be generated? >> >> My interest in this came about because echo -e '\a' no longer works. Also print '\a' doesn't work, presumably for the same reason. The following is also mute: >> >> import Tkinter >> Tkinter.Tk().bell() >> >> Print '\a', under Idle, causes a bell icon to be displayed so it seems that the lack of a beep is due to a system setting. > > > > Would you like us to guess what system you are running? Linux, Mac OS, Windows, FreeBSD, OpenBSD, Android, something else? My guess is... Windows XP. Am I close? > I'm gonna guess Ubuntu, in which case the system beep is probably disabled system wide. Google "ubuntu enable disable system beep" Thank you for your reply Bodsda, Actually, I didn't think there was any need to make any guesses since "echo -e" is exclusively a Linux command. Anyway, I had already spent some time searching for an answerer and the answer given most often was to "modprobe pcspkr". This didn't lead to a working beep. As I said previously, I'm was only curious and it's of little importance. There are many methods, some more complex than others, to play sound files. I found that the pygame library is the easiest to use. Thank you again for taking the time to answer. -- Regards, Phil ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help with installing and/or running PyNomo
On 23/03/13 22:35, Edythe Thompson wrote: Using Python 2.6.5 Mac OS X version 10.6.8 I want to run the PyNomo package that uses python. This list is for learning core Python so you are probably better off asking on a PyNomo forum or mailing list. Or at the very least the MacPython list. However, Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) This is running Python 2.7 not the 2.6 that you installed. This os probably because your MacOS has python 2.7 installed by default. You will maybe need to explicitly run the 2.6 version for PyNomo. Traceback (most recent call last): File "/Users/edythethompson/Desktop/Type8-Sample.py", line 3, in from pynomo.nomographer import * ImportError: No module named pynomo.nomographer >>> I have no idea what PyNomo is or how it works so thats a guess but there is also a danger that some of your other packages have installed themselves in the wrong Python so some may be inPython 2.6 and others in 2.7! That's a pure guess... But what the error says is that python 2.7 doesn't know what/where PyNomo is. My best advice is to see if there is a Python 2./7 version available and if so install that instead. Failing that check that all your installs have been in the 2.6 area and then run Python2.6 (create a shortcut to the executable) Finally your paste suggests you are actually running Python within IDLE. That may not be the best thing to do when using 3rd party packages like PyNomo. Again check with a PyNomo forum (or the developer if there is no forum) 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
[Tutor] help with installing and/or running PyNomo
Using Python 2.6.5 Mac OS X version 10.6.8 I want to run the PyNomo package that uses python. I have followed the instructions shown. Install newest python (2.6.5 tested) [1] Download and install latest Numpy for python 2.6. Download and install latest Scipy Install PIL (or skip, probably you won't need it) Install MacTex Install PyX sudo python setup.py install Install PyNomo Run tests on examples directory found in zip-distribution python GENERATE_ALL.py The Numpy and PyX files do not have an installer and can't be dropped into the applications folder, so I have them on the desktop. Python will open in a shell, but shows the following when I run it. Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "copyright", "credits" or "license()" for more information. >>> RESTART >>> Traceback (most recent call last): File "/Users/edythethompson/Desktop/Type8-Sample.py", line 3, in from pynomo.nomographer import * ImportError: No module named pynomo.nomographer >>> I'm stuck here. What do I need to do to make this work, if it will? Regards, Edythe___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beep sound
On Mar 23, 2013 2:24 AM, "Steven D'Aprano" wrote: > > On 23/03/13 12:48, Phil wrote: >> >> Just out of curiosity how can a beep sound be generated? >> >> My interest in this came about because echo -e '\a' no longer works. Also print '\a' doesn't work, presumably for the same reason. The following is also mute: >> >> import Tkinter >> Tkinter.Tk().bell() >> >> Print '\a', under Idle, causes a bell icon to be displayed so it seems that the lack of a beep is due to a system setting. > > > > Would you like us to guess what system you are running? Linux, Mac OS, Windows, FreeBSD, OpenBSD, Android, something else? My guess is... Windows XP. Am I close? > I'm gonna guess Ubuntu, in which case the system beep is probably disabled system wide. Google "ubuntu enable disable system beep" Bodsda ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Overriding equality tests in Python
On 03/23/2013 10:35 AM, Robert Sjoblom wrote: As I said, I don't really understand why a roulette outcome has a name in the first place, but given that it does, I don't any problem with comparing the names directly. Still, I would probably write it as an __eq__ method, since it's easier to write a == b than a.name == b.name. I figured that it would be easier if outcomes had names. Consider that each Bin (where the ball lands) can contain between 2 to 14 different winning outcomes. Each Bin() collects various Outcome()s, each Outcome() handles the amount won. Consider the '1' Bin, it contains the following winning Outcome()s: “1”, “Red”, “Odd”, “Low”, “Column 1”, “Dozen 1-12”, “Split 1-2”, “Split 1-4”, “Street 1-2-3”, “Corner 1-2-4-5”, “Five Bet”, “Line 1-2-3-4-5-6”, “00-0-1-2-3”, “Dozen 1”. All of these bets will payoff if the wheel spins a “1”. I'm almost done with the Outcome() class (just writing the unittests for it), after that I'll tackle the Bin class, at which point I will definitely return for more questions. As I said before, thanks to everyone who answered. So you're using the name attribute to match the Outcome instance in the Bin slot against the Outcome instance in the Betting slot? Have you considered just making exactly one instance of each Outcome, and then you can use something like: for mybet in bets: if mybet.outcome in bin[1]: ...do calculation bin is a simple list describing the wheel, and mybet describes an individual bet. mybet.outcome is the particular Outcome, like "Odd". -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Overriding equality tests in Python
> As I said, I don't really understand why a roulette outcome has a name in > the first place, but given that it does, I don't any problem with comparing > the names directly. Still, I would probably write it as an __eq__ method, > since it's easier to write a == b than a.name == b.name. I figured that it would be easier if outcomes had names. Consider that each Bin (where the ball lands) can contain between 2 to 14 different winning outcomes. Each Bin() collects various Outcome()s, each Outcome() handles the amount won. Consider the '1' Bin, it contains the following winning Outcome()s: “1”, “Red”, “Odd”, “Low”, “Column 1”, “Dozen 1-12”, “Split 1-2”, “Split 1-4”, “Street 1-2-3”, “Corner 1-2-4-5”, “Five Bet”, “Line 1-2-3-4-5-6”, “00-0-1-2-3”, “Dozen 1”. All of these bets will payoff if the wheel spins a “1”. I'm almost done with the Outcome() class (just writing the unittests for it), after that I'll tackle the Bin class, at which point I will definitely return for more questions. As I said before, thanks to everyone who answered. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] send issue
> Does this help? THANKS!! Yes it definately helped. everything is so much clearer now. i always used to wonder about the u"" syntax in python 2___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Overriding equality tests in Python
On 03/23/2013 12:08 AM, Robert Sjoblom wrote: You already got lots of good answers. But I want to explicitly point out a bug in your code (2 places) that was only indirectly mentioned. class Outcome(): def __init__(self, name): #Ignoring odds for now self.name = name def __eq__(self, other): '''returns True if Outcome.name matches other.name''': if self.name == other.name: return True Here your method returns either True or None. You never supply a return value of False, you just let the default None get returned. For most purposes that will work, but it's a problem waiting to happen. In this particular case, it's easiest to just return the expression: self.name == other.name which already has a value of True or False. But if the function were more complex, you'd want to make sure that all paths through it will return the value you desire, and not the default None. def my_method(self, other): '''returns True if Outcome.name matches other.name and False otherwise''': if self.name == other.name: return True return False -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Overriding equality tests in Python
On 23/03/13 04:08, Robert Sjoblom wrote: However, if I were to create a class without the __eq__ and __ne__ definitions, what is to prevent me from doing: a.name == b.name ? Or am I missing something in my implementation of the overrides? Is there a reason why I shouldn't do .name comparisons? Yes, polymorphism. If you have a function that takes a collection of different types of object and you want to compare them you don't want that function to need to know how to compare every possible type of object (including the ones you haven't written yet). The classic example is a sort function L1 = [1,3,5,4,2,6,8] L2 - [ Outcome(...),Outcome(...)...Outcome()] my lists = [L1,L2] for lst in mylists: lst.sort() That last line can only work sensibly if the lists contain objects that know how to compare themselves. There are many other places where you could be processing mixed objects and want to apply an equality test as part of the algorithm. Hiding the details of the representation of the object inside a method is what OOP is all about. That is what allows us to write code that uses objects rather than the data hidden inside those objects. Welcome to the world of abstract data types :-) -- 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
[Tutor] Overriding equality tests in Python
It is also good to know that overriding the "comparison magic methods" in your class can be very useful if you wish to apply sorting/searching procedures available in python. If you also implement __gt__, __lt__, __ge__, __le__ in your class, then you can append each of your objects to a list and successfully use the sorted () function on that list. It will enable you to have your list sorted by some other variables within your class, such as the number scored. John S ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Overriding equality tests in Python
On 23/03/13 15:08, Robert Sjoblom wrote: Hi list. I'll preface this by saying that I am very grateful for all of you, and thank you in advance to anyone that answers. I'm currently working on a roulette simulator, because it seemed like fun. I found out I needed a way to compare two different outcomes, and it was suggested to me that I should override the __eq__ and __ne__ methods. Said and done, I did: class Outcome(): def __init__(self, name): #Ignoring odds for now self.name = name def __eq__(self, other): '''returns True if Outcome.name matches other.name''': if self.name == other.name: return True def __ne__(self, other): '''returns True if Outcome.name does not match other.name''' if self.name != other.name: return True I'm not sure what relevance a name has for roulette simulator, but okay. Those two methods are probably better written something like this: def __eq__(self, other): return (self.name == other.name) def __ne__(self, other): return (self.name != other.name) Actually, here's an even better way of doing it: def __eq__(self, other): if isinstance(other, Outcome): return (self.name == other.name) # Give the other object a chance to check for equality. return NotImplemented def __ne__(self, other): return not self == other Now, this works, as far as this is concerned: a = Outcome('Bob') b = Outcome('Ray') c = Outcome('Bob') a == b a == c True a != b True When testing, you should also test values that give the opposite result. For example, compare a == b and a != c. However, if I were to create a class without the __eq__ and __ne__ definitions, what is to prevent me from doing: a.name == b.name ? Nothing. But consider a more complicated example. Which would you rather write? a.name.lower() == b.name.lower() and a.age == b.age and a.sex == b.sex a == b The idea of defining __eq__ is that you can hide all the complexity of checking equality in a single method. For example, the __eq__ for dicts might look something like this: def __eq__(self, other): if self is other: return True if not isinstance(self, other): return NotImplemented if len(self) != len(other): return False for key in self: if key not in other: return False if self[key] != self[other]: return False return True Imagine having to write something like that every single time you wanted to compare to dicts for equality. Or am I missing something in my implementation of the overrides? Is there a reason why I shouldn't do .name comparisons? As I said, I don't really understand why a roulette outcome has a name in the first place, but given that it does, I don't any problem with comparing the names directly. Still, I would probably write it as an __eq__ method, since it's easier to write a == b than a.name == b.name. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] send issue
On 23/03/13 15:22, Lolo Lolo wrote: You can use bytes() function: bytes('%d' % 3, 'utf-8') b'3' -m thanks this has solved everything. can i ask if this is an issue only in python 3 where sockets cant send strings? the docs state the argument is a string, but i believe that was for 2.7. I knew nothing about b'' or bytes() before today. thanks again The thing to remember is that there are two types of strings: byte strings text strings (also known as Unicode) In Python 2, strings created with "" are called "strings", and even though they are actually byte strings, Python tries really hard to pretend that they are text strings. In Python 2, strings created with u"" are called "unicode strings". They are exactly the same as the strings you create in Python 3 using "" without the U. In Python 3, strings created with b"" are called "bytes", for "byte strings", and Python no longer tries to pretend that they are text strings. (Python 2.7 also understands b"" syntax for creating byte strings.) Summary: * I want a series of bytes, e.g. for sending to a socket - use "abc" or b"abc" in Python 2 - use b"abc" in Python 3 * I want a series of text characters: - use u"abc" in Python 2 - use "abc" in Python 3 * I don't care what I get: - use "abc" in Python 2 or 3, and so long as you don't try to do anything too complicated, it will just work. Does this help? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor