[Tutor] Str Method
Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements. For an example... set1 = Set() print(set1) {} Question is how do you implement the curly brackets in my str method? This is what I have so far... def __init__( self, *initElements ): self._theElements = list() def __str__(self): return self._theElements ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Str Method
On 01/11/12 15:34, Ashley Fowler wrote: Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements. For an example... set1 = Set() print(set1) {} Question is how do you implement the curly brackets in my str method? Curly brackets are just characters like any other... print( '{', 42, '}' ) This is what I have so far... def __init__( self, *initElements ): self._theElements = list() def __str__(self): return self._theElements You are returning a list. But __str__() is supposed to return a string. You need to create a string representation of your data. There are many ways to do that depending on what you want it to look like or contain. 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] Str Method
On 11/1/2012 11:34 AM, Ashley Fowler wrote: Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements. For an example... set1 = Set() print(set1) {} Question is how do you implement the curly brackets in my str method? This is what I have so far... def __init__( self, *initElements ): self._theElements = list() def __str__(self): return self._theElements Please include the class statement. Give us an example of the desired output when theElementsis not empty. Why not create theElements as a set to start with? what is Set ADT? is it important that we know that? -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Str Method
On 01/11/2012 15:34, Ashley Fowler wrote: Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements. For an example... set1 = Set() Please tell us what this Set() is, then we'll attempt to answer your questions. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] need help
working through my tutorial ive been told to set up a simple webserver. i can't even get started because the 1st line of code its asked me to do fails with a syntax error. here's the code: python3 -m http.server any ideas what is going wrong? it asked me to make some simple .html files, then in the same directory run that line of code. I havent any experience with web servers, so i might not understand advanced instructions:( ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
On 2012-11-01 21:24:52 +, Matthew Ngaha said: working through my tutorial ive been told to set up a simple webserver. i can't even get started because the 1st line of code its asked me to do fails with a syntax error. here's the code: python3 -m http.server any ideas what is going wrong? it asked me to make some simple .html files, then in the same directory run that line of code. I havent any experience with web servers, so i might not understand advanced instructions:( Works for me with 3.3: aclark@Alexs-MacBook-Pro:~/ python3.3 -m http.server Serving HTTP on 0.0.0.0 port 8000 ... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Alex Clark · https://www.gittip.com/aclark4life/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
On 11/01/2012 05:24 PM, Matthew Ngaha wrote: working through my tutorial ive been told to set up a simple webserver. i can't even get started because the 1st line of code its asked me to do fails with a syntax error. here's the code: If you got an error, quote it in full in your message (using copy/paste, not by retyping or paraphrasing. As it stands, we don't know if the error was in bash, in csh, in cmd, or in Python, and if it was in python, we don''t know what version. python3 -m http.server Where did you type that? Was it in a shell, or the interpreter, or in IDLE, or someplace else complicated? any ideas what is going wrong? it asked me to make some simple .html files, then in the same directory run that line of code. I havent any experience with web servers, so i might not understand advanced instructions:( You've already got one response showing it working with Python 3.3 on OSX. it also works here, running Python 3.2 on Linux. But you don't say what version, nor what OS. I'd also ask what directory you're running it in. davea@think:~/temppython$ python3 -m http.server Serving HTTP on 0.0.0.0 port 8000 ... -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
Always, *always* include the *full* error message, otherwise we have to guess. Not fun. Some other questions: What operating system are you using? What version of Python does your tutorial assume? Do you in fact have Python 3 installed on your system? maybe im running it from the wrong place. on IDLE i get: SyntaxError: invalid syntax (pyshell#0, line 1) and on cmd it says 'python3' is not recognized as an internal or external command, operable program or batch file. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
Works for me with 3.3: aclark@Alexs-MacBook-Pro:~/ python3.3 -m http.server Serving HTTP on 0.0.0.0 port 8000 ... hey how do you start it or where do you run it from. did you type that in the command line? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Str Method
On Thu, Nov 1, 2012 at 4:12 PM, bob gailer bgai...@gmail.com wrote: Why not create theElements as a set to start with? what is Set ADT? is it important that we know that? I suppose it's an implementation of the set abstract data type (i.e. operations such as add, union, difference): http://en.wikipedia.org/wiki/Set_%28abstract_data_type%29 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
On 11/01/2012 05:47 PM, Matthew Ngaha wrote: Always, *always* include the *full* error message, otherwise we have to guess. Not fun. Some other questions: What operating system are you using? What version of Python does your tutorial assume? Do you in fact have Python 3 installed on your system? maybe im running it from the wrong place. on IDLE i get: SyntaxError: invalid syntax (pyshell#0, line 1) If you're inside IDLE, you do NOT run python commands, you run python programs. That's not what you want here. When the instructions begin python or python3, then it's a commandline thing, which you do from the shell. and on cmd it says 'python3' is not recognized as an internal or external command, operable program or batch file. That's it, keep making us play detective to determine those things you could easily have provided for us. I'll guess you're running Windows, because you mention cmd, and I'll guess it's Windows 8, since that's just out this week. And I'll guess you've installed Python 2.4, and that's your problem, as Python3 won't be on your path when you've only installed Python 2.4. If perchance you're running XP, and have installed Python 3.2, then what directory did it install into? is that directory on your path? What happens when you run python itself, is it version 2.72 ? -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
If you got an error, quote it in full in your message (using copy/paste, not by retyping or paraphrasing. As it stands, we don't know if the error was in bash, in csh, in cmd, or in Python, and if it was in python, we don''t know what version. python3 -m http.server Where did you type that? Was it in a shell, or the interpreter, or in IDLE, or someplace else complicated? You've already got one response showing it working with Python 3.3 on OSX. it also works here, running Python 3.2 on Linux. But you don't say what version, nor what OS. I'd also ask what directory you're running it in. davea@think:~/temppython$ python3 -m http.server Serving HTTP on 0.0.0.0 port 8000 ... i type it in both IDLE and CMD. in the directory where i made those .html files, i held shift and right clicked to get the command line open. im on windows vista. the i type that line in there. i use Python 3.1 also i made a .py file in that folder. opened it for editing, then pressed F5 to run it., then type the code into IDLE's interactive interpreter. which is where i got the invalid syntax error: SyntaxError: invalid syntax (pyshell#0, line 1) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
On 11/01/2012 05:55 PM, Matthew Ngaha wrote: If you got an error, quote it in full in your message (using copy/paste, not by retyping or paraphrasing. As it stands, we don't know if the error was in bash, in csh, in cmd, or in Python, and if it was in python, we don''t know what version. python3 -m http.server Where did you type that? Was it in a shell, or the interpreter, or in IDLE, or someplace else complicated? You've already got one response showing it working with Python 3.3 on OSX. it also works here, running Python 3.2 on Linux. But you don't say what version, nor what OS. I'd also ask what directory you're running it in. davea@think:~/temppython$ python3 -m http.server Serving HTTP on 0.0.0.0 port 8000 ... i type it in both IDLE and CMD. in the directory where i made those .html files, i held shift and right clicked to get the command line open. im on windows vista. the i type that line in there. i use Python 3.1 also i made a .py file in that folder. opened it for editing, then pressed F5 to run it., then type the code into IDLE's interactive interpreter. which is where i got the invalid syntax error: SyntaxError: invalid syntax (pyshell#0, line 1) Don't run it from inside IDLE. You were right to run it from cmd. Pasting the error message you showed elsewhere: 'python3' is not recognized as an internal or external command, operable program or batch file. That simply says that the PATH does not point to your PYTHON3.bat or PYTHON3.exe program. When I was stuck on Windows, I used the ActivePython version, as it had many enhancements for Windows users over standard CPython. One of those enhancements was a simpler install that set up associations and paths automatically. Consequently, I don't have any idea how your Windows install tried to set up your PATH. Look in a directory like C:\Python3.1 to see if it's there at all. And if it is, add it to your PATH. That's a Windows thing, which you can do from the control panel. But for testing, you can just manually add it to the path of your current cmd shell. In case you didn't know, PATH is an environment variable used by the cmd shell (and other programs) to search for .exe, .bat, and .cmd programs. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
Don't run it from inside IDLE. You were right to run it from cmd. Pasting the error message you showed elsewhere: 'python3' is not recognized as an internal or external command, operable program or batch file. That simply says that the PATH does not point to your PYTHON3.bat or PYTHON3.exe program. When I was stuck on Windows, I used the ActivePython version, as it had many enhancements for Windows users over standard CPython. One of those enhancements was a simpler install that set up associations and paths automatically. Consequently, I don't have any idea how your Windows install tried to set up your PATH. Look in a directory like C:\Python3.1 to see if it's there at all. And if it is, add it to your PATH. That's a Windows thing, which you can do from the control panel. But for testing, you can just manually add it to the path of your current cmd shell. In case you didn't know, PATH is an environment variable used by the cmd shell (and other programs) to search for .exe, .bat, and .cmd programs. im really not any good with cmd or know how to set things to my python path. what do you mean when you say Look in a directory like C:\Python3.1 to see if it's there at all? you mean to see if the code works, or something else? i have my python installed not in my C:drive but... D:\Data\Program Files Data\Py in a folder named Py. i opened the cmd there and typed python3 and python 3.1 but got the same errors. i also ran the same code to start the server but still got the same error. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
On Thu, Nov 1, 2012 at 5:55 PM, Matthew Ngaha chigga...@gmail.com wrote: i type it in both IDLE and CMD. in the directory where i made those .html files, i held shift and right clicked to get the command line open. im on windows vista. the i type that line in there. i use Python 3.1 The interpreter executable in Windows is always called python (console) or pythonw (no console). The 3.1 installer doesn't put the executable's directory on the system PATH. The option to add this was added to the 3.3 installer. Otherwise you'll have to add the directory manually. In IDLE check the result of the following: import sys sys.executable '/usr/bin/python3' For you it will probably display C:\Python31\pythonw.exe. That being the case; you have to append C:\Python31 to your PATH. You can do this temporarily using the cmd shell's set command (e.g. set PATH=%PATH%;C:\Python31), or permanently in the system registry by following instructions easily found online. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
The interpreter executable in Windows is always called python (console) or pythonw (no console). The 3.1 installer doesn't put the executable's directory on the system PATH. The option to add this was added to the 3.3 installer. Otherwise you'll have to add the directory manually. In IDLE check the result of the following: import sys sys.executable '/usr/bin/python3' For you it will probably display C:\Python31\pythonw.exe. That being the case; you have to append C:\Python31 to your PATH. You can do this temporarily using the cmd shell's set command (e.g. set PATH=%PATH%;C:\Python31), or permanently in the system registry by following instructions easily found online. here were the results: import sys sys.executable 'D:\\Data\\Program Files Data\\Py\\pythonw.exe' '/usr/bin/python3' '/usr/bin/python3' i dont see Python31 .. is this Py that is supposed to be Python31?.. and do i type this exactly like you did in cmd? set PATH=%PATH%;C:\Python31 ? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
On Thu, Nov 1, 2012 at 6:37 PM, Matthew Ngaha chigga...@gmail.com wrote: import sys sys.executable 'D:\\Data\\Program Files Data\\Py\\pythonw.exe' i dont see Python31 .. is this Py that is supposed to be Python31?.. and do i type this exactly like you did in cmd? set PATH=%PATH%;C:\Python31 ? No, in your case it's set PATH=%PATH%;D:\Data\Program Files Data\Py That's just a temporary modification for the current cmd process. It's easiest to show how to change it permanently with screen captures; search for vista set path. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
No, in your case it's set PATH=%PATH%;D:\Data\Program Files Data\Py That's just a temporary modification for the current cmd process. It's easiest to show how to change it permanently with screen captures; search for vista set path. i followed the instructions at http://banagale.com/changing-your-system-path-in-windows-vista.htm i added D:\Data\Program Files Data\Py to my variable value but i still get the same error that Py is not recognized:( ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
On Thu, Nov 1, 2012 at 7:12 PM, Matthew Ngaha chigga...@gmail.com wrote: No, in your case it's set PATH=%PATH%;D:\Data\Program Files Data\Py That's just a temporary modification for the current cmd process. It's easiest to show how to change it permanently with screen captures; search for vista set path. i followed the instructions at http://banagale.com/changing-your-system-path-in-windows-vista.htm i added D:\Data\Program Files Data\Py to my variable value but i still get the same error that Py is not recognized:( Py is a directory. Once you've added the Python executable's directory to the path, you can start the http.server module as a script by running the following: python -m http.server Don't use pythonw in this case. The latter is associated with the .pyw file extension, used for scripts that run without a console. For example, IDLE is a GUI app that uses Tk widgets, so it doesn't need a console. That's why it runs with pythonw.exe. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help
Py is a directory. Once you've added the Python executable's directory to the path, you can start the http.server module as a script by running the following: python -m http.server Don't use pythonw in this case. The latter is associated with the .pyw file extension, used for scripts that run without a console. For example, IDLE is a GUI app that uses Tk widgets, so it doesn't need a console. That's why it runs with pythonw.exe. wow i am so grateful.. i had given up hope just trying different things. its finally working. thank you:) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Str Method
On 02/11/12 02:34, Ashley Fowler wrote: Question is how do you implement the curly brackets in my str method? This is what I have so far... def __init__( self, *initElements ): self._theElements = list() def __str__(self): return self._theElements __str__ should return a string, not a list. Since _theElements is a list, you cannot rightly return that. You could convert that to a string first: s = str(self._theElements) and then replace the square brackets [ ] with curly brackets: s = s.replace([, {).replace(], }) return s Another way is to build the string yourself: s = ', '.join(str(item) for item in self._theElements) return '{' + s + '}' -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Str Method
On Thu, Nov 1, 2012 at 8:19 PM, Steven D'Aprano st...@pearwood.info wrote: s = str(self._theElements) s = s.replace([, {).replace(], }) return s Another way is to build the string yourself: s = ', '.join(str(item) for item in self._theElements) return '{' + s + '}' Or s = str(self._theElements) return {%s} % s[1:-1] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tutor needed!
Looking for someone who can walk me through certain homework assignments, as well as explaining how to create them. If interested please e-mail me as soon as possible. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor