Re: [Tutor] I think I've broken my Python
On Mon, Nov 12, 2018 at 3:31 PM Mats Wichmann wrote: > > Reconstruct the virtualenv you want maybe? Their whole concept is that > they're cheap and easy and can just be thrown away. Of course, you then > have to remember what you did to create it in order to make a new one... It's been 3 years, I'm clueless as to how I created it. Also I'm a noob when it comes to Linux which makes this even more confusing for me. The 3 years I've been absent from Programming I went back to Windows. > Since you're on a Linux platform, use "which" to see how the names you > are typing are resolving > > which python > which python3 The "command" gives this output: (website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite> which python /usr/bin/python (website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite> which python3 /usr/bin/python3 > Usually if the virtualenv has been broken by external factors, it won't > even activate. Are you sure you remembered to try to activate it? > Yep, I double checked to make sure I remembered to try to activate it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] I think I've broken my Python
I haven't coded in about 3 years and I used to use Python3.4 on openSUSE13.1. I had a virtual environment with this Python for a development Django website. Before I stopped coding, I upgraded to Python3.5, but everything still worked if I remember correctly. But now I'm back to coding I tried to load up my Django website but I get the error: Traceback (most recent call last): File "manage.py", line 8, in from django.core.management import execute_from_command_line ImportError: No module named django.core.management What happens is Django's manage.py can't be found so the line: "from django.core.management import execute_from_command_line" throws the error. In the virtual environment when I type python in the command line, it opens Python2.7 and when I type Python3, it opens Python3.5. So it seems my Python3.4 is lost. I thought the virtual environment only loaded up the Python version it was installed for, in my case Python3.4 when I type python or python3 in the command line, had I known this wasn't the case I would have never upgraded Python. Is there anything I can do? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When do you know you're ready to start applying for jobs?
Thank you all for replying, I really appreciate it. It's all I've been thinking about lately and your responses have really cleared up a lot of things for me. On Tue, Dec 12, 2017 at 11:37 PM, Alan Gauld via Tutorwrote: > > But there are things you can learn now that won't ever change. > And that includes the principles of design - an aspect all too > often ignored by people learning "programming" But you can't > build a significant system of any kind without an underlying > design. And you can't build big systems without understanding architecture. > Thanks Alan you gave a really profound reply and I've been digesting it slowly but surely. Can you give me any tips on how I can improve on this (where I quoted you). And are there any books or tutorials you can recommend for me. > Hopefully you see where I'm going - you never stop learning > and you can waste a lot of time becoming an expert in things > that will be of no use in a few years, or you can focus on > principles that are the very basis of system design and > construction. > Yes I see where you're going. I just need a push in the right direction on where I can learn about the principles of system design. Also why isn't this taught in beginner tutorials, or is it an advanced concept? Thanks again for your response. I remember years ago your website was one of the 1st tutorials I read on python. Recently I needed a refresher on the os module and I recalled you covered it extensively, but sadly I found it's no longer on your site. It says under construction. Any ideas of when that will be finished? Thanks again. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] When do you know you're ready to start applying for jobs?
Hi all. I took 2-3 years off in 2012 to teach myself programming. I learnt basic Javascript & Python with some Django. I don't have a Computer Science (CS) degree so I never applied for a job because I always thought I still had lots to learn and most jobs say a CS degree is required. In 2015 I had to stop my learning to find a real minimum wage job as I needed to support myself. I will never know now if I would have got a python job had I applied. It's now december 2017, so I haven't touched programming in 2 years. I've forgotten most of what I learnt now. :( I'm now financially secure to give programming another go but I don't know how I feel about relearning everything I forgot. Is it's worth it? What are your thoughts? Can I get a junior programming job without a CS degree? When do you know you're ready to start applying for jobs? How can a self learner ever know? should I have applied for some jobs back in 2015 when I was still studying? What are your opinions on my situation? Is learning Python all over again worth it without a CS degree? would I be wasting my time? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python programming for the absolute beginner
On Fri, Sep 29, 2017 at 7:20 PM, Alan Gauld via Tutorwrote: > If you want to follow the book use the version the book > uses - probably 2.6 or something close? > I think the book uses either Python 3.0 or 3.1. It's been a while since I read it but it doesn't use Python 2. The 2nd edition written in 2010 used Python 3 but the 1st edition used Python 2. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GUI development with Python 3.4.1
PyQt or PySide offers QtDesigner. Which is a drag and drop builder. They are both quite complex GUI toolkits so you will need some basic knowledge on them first, but I Imagine there are good guides on using QtDesigner if it's your last option. On Thu, Sep 18, 2014 at 2:14 PM, Juan Christian juan0christ...@gmail.com wrote: On Thu, Sep 18, 2014 at 10:12 AM, Joel Goldstick joel.goldst...@gmail.com wrote: I've not used it but Tkinter seems to be well used. I'm not sure what a C#/Java-ish thing is, but python isn't that. C#/Java-ish in terms of GUI Builder, drag and drop, like Glade and gui2py. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] python ssl error
Hi this might not be the correct place to ask this. I am using the google api and as soon as I use the build function: service = build('books', 'v1', developerKey=api_key) I get an SSL error. I'm not sure what build() does but it triggers an SSL error. Here's the error message: ssl.SSLError: [Errno 185090050] _ssl.c:357: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib I googled this error but I don't understand the solution. It seems specific to httplib2: https://github.com/kennethreitz/requests/issues/557 Here is the full trace back. Any ideas? http://bpaste.net/show/isukkSeo08a0rx23ziBD/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python ssl error
On Sun, Aug 17, 2014 at 11:26 PM, Danny Yoo d...@hashcollision.org wrote: I would recommend checking whether the 'cacerts.txt' file in that subdirectory is user-readable or not. Make sure it's readable. If it isn't, chmod it and try again: that will probably fix it. Thanks ever so much for your efforts! I'm glad to say your suggestion above fixed the problem. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Socket Error: Connection refused
On Mon, Jul 7, 2014 at 12:55 PM, Dave Angel da...@davea.name wrote: You will want to configure your DOS Box to make it easier to cut and paste. How is this done? I'm not on windows atm to test it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python sockets
On Tue, Jun 10, 2014 at 5:28 PM, Jon Engle jon.en...@gmail.com wrote: startingPort=input(\nPlease enter starting port: ) startingPort=int(startingPort) def setup(PORT): PORT = startingPort#arbitrary port not currently in use There's a conflict with this PORT variable. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Question about scraping
Hey all. I've been meaning to get into web scraping and was pointed to the directions of lxml (library) and scrapy (framework). Can I ask in terms of web scraping, what's the difference between a library and a framework? Surely everyone should use a framework but I get the idea more people use the available libraries like lxml over scrapy. Any advantages or disadvantages for each? And which do you use out of the 2? I also have another question due to reading this: [Tutor] HTML Parsing . It seems some experienced coders don't find scraping as useful since web sites offer apis for their data. Is the idea/concept here the same as scraping? And is there any use of scraping anymore when sites are now offering their data? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about scraping
Thanks for the response Alan. I forgot to reply to tutor on my 2nd comment. Just incase someone might want to see it, here it is: Okay I think learning how to scrap (library or framework) is not worth the trouble. Especially if some people consider it illegal. Thanks for the input. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Recommendation For A Complete Noob
Hi, I'm completely new to programming in general and everything I have read so far has pointed me to Python. I was just hoping to get some input as to where I might start. Start with Python programming for the absolute beginner Great author. The book gives you lots of exercises at the end of each chapter to make sure you understood everything up to that point. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Windows Install Issue
Hi I'm trying to install pyqt5.2 for Windows Vista (Python3.3). 1st i need to install sip but i run into this issue. after ./configure, a MAKEFILE is created. I'm supposed to do 'make' and 'make install', but i get this cmd error: C:\pathmake 'make' is not recognized as an internal or external command, operable program or batch file. I'm not really sure what i should do? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Windows Install Issue
On Sat, Jan 11, 2014 at 2:55 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: On Windows finding a binary installer is always the first thing to do, makefiles indeed. Go here http://www.riverbankcomputing.co.uk/software/pyqt/download5, find the section Binary Packages and this gives Windows 32 and 64 bit installers. sorry i forgot to explain. i cant get the binary: http://www.riverbankcomputing.co.uk/software/pyqt/download5 Unfortunately it is not possible to use both the PyQt4 and PyQt5 installers at the same time. If you wish to have both PyQt4 and PyQt5 installed at the same time you will need to build them yourself from the source packages. after seeing this i thought it was better not to try it and maybe currupt my files ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Windows Install Issue
On Sun, Jan 12, 2014 at 1:13 AM, eryksun eryk...@gmail.com wrote: The pre-built versions of PyQt4 and PyQt5 don't use the same version of SIP. If you don't have a build system (e.g. Visual Studio 2010, the Windows 7 SDK, or MinGW), then using a virtual environment should work around the problem. http://docs.python.org/3/library/venv.html Install PyQt4, and then copy the following files and directories to a separate environment: Problem solved. Thanks so much:) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] ubuntu hassles.
Hi i wrote about a week ago about the problems i had with importing sqlite3 on python 3.3 on ubuntu 12.04. Due to this ive tried to revert back to python 3.2 which is the default installation along wit 2.7. I've run into 2 problems. 1) I'm new to ubuntu and someone helped me install python3.3 from source. I've tried 'make uninstall' from the dir containing the source package but it seems there is no way to get this version off my computer. 2) I really need to use virtualenv for python3.2. The problem is python3.3 seems to be the default and overrides every virtualenv thing i try doing. whether it is pyvenv or virtualenv, the 3.3 version takes priority. It is located in /usr/local/bin ... I have no idea where my 3.2 virtualenv is located although i know i definately installed it with : sudo apt-get install python-virtualenv if i can achieve 1) or 2) im sure the rest would be straightforward. any ideas? I know this isn't really a python issue but it's a last resort as the ubuntu guys are unsure of how to solve this. If i can't resolve it, not to worry, i'll just upgrade my ubuntu to a more recent version. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ubuntu hassles.
On Tue, Jan 7, 2014 at 12:40 AM, eryksun eryk...@gmail.com wrote: virtualenv allows you to specify the target Python: virtualenv --python=/usr/bin/python3.3 myenv Refer to `man virtualenv` for more options. Or use synaptic if you prefer a GUI interface. Ubuntu has a Python 3.3 package. Installation should be simple: $ sudo apt-get update $ sudo apt-get install python3.3 If you're building from source, or need to uninstall after a previous `make install`, use checkinstall to build a package. I'm currently studying/coding on windows but thanks so so much for this detailed response. I will try again tomorrow, but im now very confident! thanks again:) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python problems on android
On Sat, Jan 4, 2014 at 11:24 AM, blech...@fireflyuk.net wrote: I havent included the script as it seems to be the use ' input' on my phone that now wont work. Even if the error is with 'input', it is still an odd error and no one will be able to debug your program or have a clue what's going wrong if you don't provide us any code. It will save a lot of time also. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqlite3 import problem
On Fri, Jan 3, 2014 at 10:36 AM, Alan Gauld alan.ga...@btinternet.com wrote: On 03/01/14 02:17, Matthew Ngaha wrote: im having problems importing sqlite3 on ubuntu python3. File /usr/local/lib/python3.3/sqlite3/__init__.py, line 23, in module from sqlite3.dbapi2 import * File /usr/local/lib/python3.3/sqlite3/dbapi2.py, line 26, in module from _sqlite3 import * ImportError: No module named '_sqlite3' As a matter of interest why do you have the underscore in front of sqlite3? Is that deliberate? I normally import it with just import sqlite3 or from sqlite3 import ... Hi Alan. The code in the traceback is being done internally. my code has import sqlite3. Python finds it in this directory: /usr/local/lib/python3.3/sqlite3/ and runs the code from the traceback. I have no idea why it's using _sqlite3:( On Fri, Jan 3, 2014 at 6:12 AM, Kushal Kumaran kushal.kumaran+pyt...@gmail.com wrote: The /usr/local heirarchy is not used by official debian/ubuntu packages, so other people will not have the same contents in there as you. You must have a locally built python in /usr/local. Check the build logs if it has complained about not being able to build the sqlite3 module. If so, you can install all build dependencies for the offical python3 package by running this command: # apt-get build-dep python3 And then rebuilding your local python3 installation. On Fri, Jan 3, 2014 at 3:00 AM, Danny Yoo d...@hashcollision.org wrote: This might be an Ubuntu bug or deficiency. Hi, Danny Kushal. Originally i only had python 2.7 and 3.2 as default for Ubuntu. Kushal you're right my 3.2 has a different path to sqlite3 than /usr/local/lib/python3.3/sqlite3/ Infact i haven't been able to find its location. 3.2 imports sqlite3 with no errors. I'm currently not on ubuntu to try your instruction. Will the build logs be inside the python3.3 directory? I'm still new to linux so sorry for newbie questions. it took me a very long time to get it right when building python3.3. When you say rebuild, is there a command for doing that or do you mean simply uninstall python then build it again? On Fri, Jan 3, 2014 at 10:36 AM, Alan Gauld alan.ga...@btinternet.com wrote: On 03/01/14 02:17, Matthew Ngaha wrote: im having problems importing sqlite3 on ubuntu python3. File /usr/local/lib/python3.3/sqlite3/__init__.py, line 23, in module from sqlite3.dbapi2 import * File /usr/local/lib/python3.3/sqlite3/dbapi2.py, line 26, in module from _sqlite3 import * ImportError: No module named '_sqlite3' As a matter of interest why do you have the underscore in front of sqlite3? Is that deliberate? I normally import it with just import sqlite3 or from sqlite3 import ... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] sqlite3 import problem
im having problems importing sqlite3 on ubuntu python3. File /usr/local/lib/python3.3/sqlite3/__init__.py, line 23, in module from sqlite3.dbapi2 import * File /usr/local/lib/python3.3/sqlite3/dbapi2.py, line 26, in module from _sqlite3 import * ImportError: No module named '_sqlite3' i have that path and file (dbapi2.py). the problem is an import statement for _sqlite3. i don't see this file but shouldn't python3.3 be able to import sqlite without errors? any suggestions? does anyone have _sqlite3.py in their /usr/local/lib/python3.3/sqlite3/ directory? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] certain packages won't install
hey i've tried installing a few packages with pip that failed. i'm on windows and python3.3. I have tried 'pip install pycurl' and 'pip install flup' which is something i need for django. I tried flup today and what bothers me is even though it failed, it's making some temp folders in places i never look at. here's the error: File appdata\local\temp\pip-build-happylions\flup\setup.py , line 2, in module from ez_setup import use_setuptools File .\ez_setup.py, line 98 except pkg_resources.VersionConflict, e: ^ SyntaxError: invalid syntax pycurl is in the same location if you replace \flup\ with \pycurl\ in that path above. It has a full directory with even a Makefile in it, yet the pip install failed. I'm a bit confused that these directories have been in these hard to find places and i haven't known. But it also makes me question if i did something wrong? directories usually won't be created if the install fails. Is there another way to install these packages? especially flup? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] certain packages won't install
oh i think it might be the 2nd case of having the wrong version of pip. I do have pip for Python 2 also but both are not on my path so cmd doesn't recognise 'pip' unless used in their python folders. I'll try reinstalling pip. i got it via easy_install so i may have the wrong one there also:( On Sun, Dec 22, 2013 at 11:21 PM, Steven D'Aprano st...@pearwood.info wrote: On Sun, Dec 22, 2013 at 11:10:13PM +, Matthew Ngaha wrote: hey i've tried installing a few packages with pip that failed. i'm on windows and python3.3. You're trying to use Python 3.3, but somehow your version of pip is written for Python 2, which is why you're getting syntax errors. This could happen if you have two versions of pip installed, and Windows is getting confused about which version goes with which version of Python. Or possibly you only have one version of pip, but the wrong one. I don't know. You might try reinstalling pip, making sure you get a Python 3 compatible version. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] more html/css question than python
hey guys ive got the very basics of django down. i was able to design a very basic dynamite site and interacted with django. It's basic limited in every way, with the little it does, and the plain ugly design. This won't be good enough to put up anywhere but on localhost. My question is, How do you guys or designers in general go about creating a site. do you guys find designing a site from scratch with html/css fun... or is it so tedious that you just go with an existing template? I was told people don't design sites with manual html/css anymore as they use many tools that can generate web pages without having to type all that code. i'm wondering if its worth learning html5/css3 beyond a basic level in conjunction with django, or are there easier better options. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] more html/css question than python
On Sat, Dec 21, 2013 at 5:56 PM, Alan Gauld alan.ga...@btinternet.com wrote: You really need to know html and css if you are building modern web UIs. That's because most good modern web sites use a lot of client side(browser) scripting, usually using JQuery. JQuery requires that you really understand how html tags and css styles work. So you may get out of creating the bulk of the code but you still need to understand the detail of what the tool produces. More so today that, say, 10 years ago. Finally, I'd really aim for xhtml rather than html since it's easier to parse and not too much extra work to produce. (htmltidy can convert to xhtml for you if you prefer) so xhtml even over html5? isn't html5 the new thing these days? I know basic javascript, so it's definately better to also learn jquery? I've always pushed it to the side :( ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reading CSV files in Pandas
Does pandas do the same thing numpy does? I've never used them and unsure of what they are about. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] global variables
I'm always told to avoid using them. I read discussions on the python irc channel about them but honestly i feel there are some times where i can't avoid using them. Like where i want to keep track of a state variable in many different functions that may or may not alter its value and also not wanting any of the functions to return it to the caller. My question is how many global variables did your last decent sized program have? Also please share any insight you have about them. I do try to avoid them, but is this always possible? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global variables
On Thu, Aug 22, 2013 at 1:40 PM, Chris Down ch...@chrisdown.name wrote: It sounds like you want to use a class. Why would you not just use a class if you want to store state? I don't feel my program needs a class. Also i have been told to stop using classes by some very experienced Python programmers on irc even though i don't see why. It's confusing being told different things. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global variables
On Thu, Aug 22, 2013 at 2:52 PM, Chris Down ch...@chrisdown.name wrote: I would doubt that anyone has told you don't ever use classes, because that's nonsense; you've probably misread a dissuasion from that path in a single instance as applying more broadly than was intended. I am being totally honest here. I was very confused at the time and i said i didn't agree because it's what i had put so much effort into learning. They went on to say at some well known Python talks speakers have stated why using OOP (especially inheritance, but not excluding any others) is very bad design and the same thing can always be achieved without it. To be clear they said every use case OOP is the worst option. I asked what about GUIs which their design is strongly based around OOP? and they sad GUIs are badly designed to begin with so it proves the point about OOP. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global variables
On Thu, Aug 22, 2013 at 3:04 PM, Alan Gauld alan.ga...@btinternet.com wrote: On 22/08/13 13:36, Matthew Ngaha wrote: Global variables in themselves are not the problem. It's how they tend to get used that causes problems. Globals that are only changed via a set of dedicated functions are not topo much of a problem - although they should probably be bundled as a class (or module) Usually that should be in a class. A class represents a set of operations using common data. Therefore shared state would naturally fit in a class along with the operations which depend on/modify that state. Oh this makes a lot of sense. Sorry about disagreeing with Chris i now see that perhaps a class is definately the best choice for keeping a state variable. Thats more problematic and usually a sign of a bad design. Even if using global variables you should modify them explicitly via return values of functions rather than as hidden side-effects inside other functions. mystate = changestate(mystate, some, other, args) Yeah i have to agree about the bad design now i think about it. I didn't see the issues before reading this It is possible but only by playing silly games with semantics such as: class MyProgram global1 = 0 global2 = True [Or alternatively you can hide them inside a database.] Now technically there are no globals but in fact we are just moving them inside the meaningless class and have all the same potential issues with global side effects etc. About the class variables, i have used them a lot without realising they had all the same side effects as global variables. Something i now have to try a different approach with. In my experience there are usually a few globals required for any meaningful program. It's not avoiding globals completely that's important, it's being careful to use them sensibly and with good adherence to the principles of coupling and cohesion in the design. Thanks alot! This is definately a lot of food for choice and will help in my future decisions. I'm happy i asked this question as i can honestly say i had been developing some bad habbits. The responses have definately been helpful about program design and not just global variables. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global variables
On Thu, Aug 22, 2013 at 4:35 PM, Steven D'Aprano st...@pearwood.info wrote: Good question! And one that needs a long answer. Hey i just checked mail again... A big thank you for your responses, i will read all of them now.. im pretty my programs/designs will be much cleaner by the time i done. And yes i was talking about freenode:) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: QT Python: How to re-use the return value of fileDialog.openFileName() ?
Sorry for the forward, i forgot to reply to tutor On Mon, May 27, 2013 at 3:53 AM, Sunitha Misra sunith...@gmail.com wrote: self.fileDialog = QtGui.QFileDialog() QtCore.QObject.connect(self.toolButton, QtCore.SIGNAL(_fromUtf8(clicked())), self.fileDialog.getOpenFileName) i think the way youre doing it won't allow you to get the filename as you are calling it through a signal. Things you can do: 1) dont use self.fileDialog.getOpenFileName as a slot like you are doing. Create a function and call it when the toolbar's button is clicked, then in that function assign the filename to the return value of self.fileDialog.getOpenFileName. 2) if the only thing your self.fileDialog is doing is responding to the toolbar's button, don't create it at all. do what i said in #1 and assign a filename variable to the full method of the dialog. What im saying is there might be no need to create the self.fileDialog instance variable at all. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: QT Python: How to re-use the return value of fileDialog.openFileName() ?
On Mon, May 27, 2013 at 2:14 PM, SM sunith...@gmail.com wrote: But then I also had to use self.fileDialog from within the function. Not sure how I could avoid using fileDialog. Thanks. No problem. to do it without the instance variable, you access its method directly. so replace: path = self.fileDialog.getOpenFileName() with path = QFileDialog.getOpenFileName(self) which is basically the same thing except you're going to the method directly instead of creating a class instance. The self argument may or may not be needed, its been a while since ive used Qt. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Difference between types
wait for someone more knowledgeable to answer, but from what i know, Yes it does have a profound meaning. Strings consist of character sets. Something that was here way before Python Like i said my experience is limited so i too would like to hear some reponses ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] challenge-chapter 2
On Wed, May 22, 2013 at 6:02 AM, Andrew Triplett andrew139...@yahoo.com wrote: I am on chapter two for Python Programming working on the challenges and the question is: 1. Create a list of legal and illegal variable names. Describe why each is either legal or illegal. Next, create a list of good and bad legal variable names. Describe why each is either a good or bad choice for a variable name. The title is a bit ambigious. Just incase anyone likes the sound of the challenge, the book is: Python Programming For The Absolute Beginner i also used it and would recommend it to anyone trying to learn Python ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] model methods in Django
Thanks guys i had no idea about these method attributes and also these underlying oop __objects__ @ eryksun i understand your explanation, im still having trouble figuring out how django is being used in the tutorial. class Poll(models.Model): # ... def was_published_recently(self): return self.pub_date = timezone.now() - datetime.timedelta(days=1) was_published_recently.admin_order_field = 'pub_date' was_published_recently.boolean = True was_published_recently.short_description = 'Published recently?' list_filter = ['pub_date'] search_fields = ['question'] date_hierarchy = 'pub_date' if you look at the diagram under that function, why is the value of was_published_recently.short_description the title of that field? replacing the old title? is a short_desccription attribute set somewhere in django being inactive, but once you make use of this attribute(or keyword), whatever the value is automatically becomes the field title? is it the same for boolean being the value of the field with the checked or unchecked symbol? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] model methods in Django
The default description is the name with underscores removed, unless you set a custom description in the function's short_description attribute. I'm not experienced with Django, so I can't ramble off lots of examples, but hopefully you get the gist. Thanks that does clear it up. Also thats a huge script you linked, can i ask which framework you're coming from, and why you have decided to try out django? When i asked around, people's opinions of it weren't good and i was recommended to try flask but as i only use Python 3, i won't be able to use Flask. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] model methods in Django
class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def was_published_recently(self): return self.pub_date = timezone.now() - datetime.timedelta(days=1) # was_published_recently.admin_order_field = 'pub_date' was_published_recently.boolean = True was_published_recently.short_description = 'Published recently?' Source: https://docs.djangoproject.com/en/dev/intro/tutorial01/ https://docs.djangoproject.com/en/dev/intro/tutorial02/ I find the Django (and this fragment) very elegant UP TO the comment. is the dislike after the comment more to do with the python code rather than django itself? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] model methods in Django
options.py is the biggest module in the admin package. The link I posted is to the get_actions method of ModelAdmin. In the tutorial, PollAdmin extends this class. oh ok thanks, yes i will definately look through it I'm not coming from any framework. My knowledge of web development is scattered from bits learned here and there, out of curiosity rather than necessity. With Python 3 you're a bit limited, but you still have options. Obviously there's Django -- arguably the most popular, batteries-included framework. Pyramid is a leaner alternative. Bottle and CherryPy (also a WSGI server) are micro frameworks. There's also Tornado if you want an asynchronous framework based on callbacks and coroutines. As there are a lot more guides for Django i think i will stick with it rather than Pyramid. Maybe after ive learnt it well i can pick up Cherrypy as i like the sounds of a small framework with a server. But Django will be my main focus. Thanks for detailing the options for Python 3 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] model methods in Django
On Sun, May 19, 2013 at 3:34 PM, Steven D'Aprano st...@pearwood.info wrote: Matthew, who are you quoting? Your email program should automatically insert an attribution line, such as the one just below. Without that attribution line, it is hard to follow the conversation, as we can't tell who you are quoting. On 20/05/13 00:23, Matthew Ngaha wrote: ok thanks i didnt think about that. I was quoting eryksun. I'll includethat line from now on ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] model methods in Django
im following the official docs and after learning Python im sure of how methods work, but the model example on the beginners guide has me really confused. The model definition is omitted but can anyone explain how this methed (was_published_recently) is given these attributes: class Poll(models.Model): # ... def was_published_recently(self): return self.pub_date = timezone.now() - datetime.timedelta(days=1) was_published_recently.admin_order_field = 'pub_date' was_published_recently.boolean = True was_published_recently.short_description = 'Published recently?' are the names of the attributes already attached to these functions/methods, or are they being created on the fly with whatever name you want? As i am unable to comprehend what is going on, i dont really have a clue as to what each definition is doing and how it affects the model, even after reading this section of the docs over and over again im still lost. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] env var packages
Thank you Vasya and Eryksun. Sorry i didn't mention my OS i am on windows. Thanks for the links and detailed explanations which after following, i now have django up and running! thanks again ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the Absolute Beginner
i completed this book and i did every exercise. are you asking for help with the challenges, or have you completed them and want code to compare yours too? im relunctant to share challenge code, incase you havent done them. They are really good exercises to try doing. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Interested in learning Python
i recommend getting a copy of Python Programming for the absolute beginner. It offers end of chapter exercises to make sure you understand everything you are reading. It was a great read for me and made my learning experience really fun. I garantee by the end you would have gained a lot of confidence and will be able to pick up and learn many new things ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] env var packages
i have to install django and ive come across some weird instructions. it says to set Django's django-admin.py file to my environment variable. I was instructed to get django via easy installer that was located in my Python/Scripts folder. it installed django to a different place in site-packages, where django-admin.py resides.But now its telling me to add this file to my env variable and it should also be located in Python/Scripts .. but as i've said, its clearly not there, it is somewhere in a site-packages/django sub folder. so is this an error? or do i go ahead and add Python/Scripts to the env variable, even those the file points somewhere else? My 2nd problem is it says after adding it i will get a python interpreter and Django's djando-admin.py commad up and running. What does this mean? both files open? it was specific about adding the path to the env variable, but if i already have python added, why do i need to add django? shouldnt it already be added? i will quote: You should make sure djando-admin.py is in your PATH environment variable so that it can be executed from the command-line (unless you like calling interpreters by using full pathnames) does this mean in a terminal, that i can be in Python/myproject/script_one/ and be able to open a .py file in Python/myproject/script_two/ by simpling typing its file name without having to cd into its directory or typing its full path? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help regarding game code
bWater.clicked.connect( water_clicked ) AttributeError: 'int use a paste site like http://bpaste.net/+python to show us the code. i am no expert @ programming myself but that error is telling you you used an int and tried to access an int method called connect somewhere in your code. ints do not have this method. However some PyQt objects (mostly button widgets) do have this method, which is actually a signal called clicked for when you mouse click on the widget(button). So basically ints (integers) do not have signals, try and connect the name(variable name) of what you are clicking to that method, instead of the int object (bWater) bWater.clicked.connect( water_clicked ) should become: button_name.clicked.connect( water_clicked ) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] urllib.urlretrieve ?
Im following a tutorial on what i believe is using Python 2 and i'm a bit confused. I use Python 3 on windows vista. I believe urlretrieve() is a python 2 function that isnt in 3, but why is the tutorial using urllib instead of urllib2? Also when i run the program on Python 3, it says: AttributeError: 'module' object has no attribute 'urlretrieve' so Python 3 doesnt recognize this function, i want to ask if there is an equivalent function to 'urlretrieve' in Python 3? the program uses this function to download a file as so: urllib.urlretrieve(self._url, self._filename, reporthook) the 3rd argument is a function that is called to track progress of the current download status. i dont really need help with the program, i understand its code, but i need to know if this function has one similar in Python 3? or do you have any examples of how i could add its functionality to Python 3. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib.urlretrieve ?
the whole program depends on the urlretrieve 3rd argument, the function to be called.. is there no options to include a callback? def _download(self): def reporthook(pos, block, total): if self.size != total: self._size = total self.on_size.emit() self.progress = float(pos*block)/float(total) urllib.urlretrieve(self._url, self._filename, reporthook) ##3rd arg calls inner function self.running = False ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib.urlretrieve ?
Look in the module docs for urlib.request. Hi. Ive never used the urllib before unless it was typing in something from an unrelated tutorial. I've also never done anything related to web programming. I'm looking at the urllib.request page and i really don't understand what i'm looking at. I'm confused as to what i should be looking for. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib.urlretrieve ?
You might want to look at requests module: http://docs.python-requests.org/en/latest/ Many people think it is easier to use than the native python support. are all of these modules related to web programming like clients and (HTTP)servers? I've come across urllib a lot of times but only followed along, maybe its best i just learn about HTTP and its concepts etc so i can understand the request module better then come back to my problem.. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib.urlretrieve ?
yeah, sadly urlretrieve doesnt exist on my version of python. i just need a function to put in the same line that replaces this one with the same arguments in order to see the results of my tutorial. urllib.urlretrieve(self._url, self._filename, reporthook) On Sun, Apr 7, 2013 at 7:10 PM, Alan Gauld alan.ga...@btinternet.com wrote: On 07/04/13 17:20, Matthew Ngaha wrote: Look in the module docs for urlib.request. Hi. Ive never used the urllib before In Python 3 urllib combines (the best) features of urllib and urllib2 from Python 2. web programming. I'm looking at the urllib.request page and i really don't understand what i'm looking at. I'm confused as to what i should be looking for. You were asking about urllib.urlretrieve. It's documented on that page. Now, beyond that, what else are you confused about? The more specific the question the more specific the answer. -- 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 maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib.urlretrieve ?
org/2/library/urllib.html#urllib.urlretrieve or http://docs.python.org/3/library/urllib.request.html#urllib.request.urlretrieve sorry about the top posting gmail has changed the way their messages are done, it gave me a blank field i didnt realize i was writing above the message. i must have missed it but your 2nd link was exactly what i needed. ive got the program to run without the module error. However i'm out of luck as i now get this error: urllib.error.HTTPError: HTTP Error 404: Not Found i guess the tutorial is very old that the site doesnt exist anymore:( Thanks for the help ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib.urlretrieve ?
Unless you're looking for something specific from the URL that the tutorial uses, then you could use any address Bodsda thanks i did that and to my suprise an extra file showed up in my folder, of the page i just visited:) thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] break
i cant seem to break out of this loop. let me explain the variables you see: Enemy.ships = [] #an Enemy class variable that contains enemy ships self.missiles = [] an instance variable that appends how many Visible missiles my ship has fired Enemy.rects = [] an Enemy class variable that represents a rectangle for every ship in Enemy.ships Explosion() = a class where explosions occur QPoint() = is a pyqt function that takes a point x, y position as arguments im trying to destroy the ships if they hit a missile, even though i use pyqt this is mainly python code if Enemy.ships: for missile in self.missiles: for rect in Enemy.rects: if QPoint(missile.x + 5, missile.y) in rect: explosion = Explosion(rect.x(), rect.y()) self.explosions.append(explosion) break once the missile has hit 1 Enemy.rect i want to break and go to the next missile so the missile is destroyed and doesnt hit another Enemy, but for some reason the break i have isnt working and the same missile sometimes is hitting 2 different rects on the same iteration. i have done the same loop using a simple print statements on strings greater than a certain length and it breaks correctly. anyone have any ideas why the break isnt breaking out of the nested/inner loop but instead continuing to loop through the Enemies? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] break
if Enemy.ships: for missile in self.missiles: flag = False for rect in Enemy.rects: assert(!flag) if QPoint(missile.x + 5, missile.y) in rect: explosion = Explosion(rect.x(), rect.y()) self.explosions.append(explosion) flag = True break im about to try the suggestions. i on python 3 and this line is giving me a syntax error assert(!flag). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] break
One good approach is to have a separate function or method with both loops: def attack(self, Enemy): for missile in self.missiles: for rect in Enemy.rects: if QPoint(missile.x + 5, missile.y) in rect: explosion = Explosion(rect.x(), rect.y()) self.explosions.append(explosion) return i altered this because once it returns the outer loop also stops and i need it incase i have more than 1 missile to loop through. i made it so i did the outer loop in the program and sent the inner loop to this function, but for some reason the code seems to break my program.. no errors are returned but it just freezes on inputs and missile collision. You could also set a flag and check it at the end of outer loop and have a second break statement when the flag is set. im trying to figure out this technique with flags but i havent got it yet.. what does a flag stand for? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] break
thanks guys ive finally got it working. even though i didnt use the flag due to invalid syntax i realized since i was getting no errors i wasnt actually doing anything wrong. My mistake was i removed the ememy ship but for some reason forgot to remove the missile so it was still active on the next update/mainloop. im still interested in finding out how to write this in python 3 assert(!flag). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
understanding of how everything works. Use it., Experiment with it. Break it. Thats the best way. Read the source code its all available in Python or C. Hey can you please tell me which source code youre referring too? The initial files that come with Python? also the C code, where can i locate this? is C something worth learning? why is Python code available in C? like how can i make my own custom container and not have it subclass list(), and still act like a list()? That's a more sensible option especially if you make it a type of container that Python doesn't already have. Maybe a bag or a stack or even a circular list. But there is no shame in inheriting from list if that makes sense. That would be good software engineering - don't reinvent the wheel! When building reusable code start from the perspective of the user. Write yes i will try not to reinvent the wheel, a lot of tutorials ive read seem to always point this out. Just out of curiousity what is a bag, stack or circular list? what is needed to create something like this? i sort of heard about a stack its a C/C++ thing i think? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
Hey, a Big thanks to everyone that has offered their input. I really appreciate it. Also thanks for all the additional links, i will definately start to read up on data structures , source code and everything else that was suggested ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how can i use python 2 alongside 3?
hi guys i am a python 3.1.1. user but really need to use python 2 to be able to use certain libraries and frameworks. i have installed python 2.7 but they cant run together as all .py and .pyw files are opened with python 3. i can open simple python 2 files by right clicking and finding pythons 2's python.exe, but these only works for simple files with no imports because the import i think seems to look in the python 3 directory and can't find the packages. i have checked stackoverflow for answers but i get lost in all the terms and keywords they use to solve this. is there a simple straightfoward way to fix this that is easy for someone like me to understand or follow? thanks. i use windows vista ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how can i use python 2 alongside 3?
Python 3.3 for Windows comes with a launcher, which will approximate (for Python only) what Unix and Linux users have had for years for any scripting language. You can get it separately, as Mark Lawrence has said, but maybe it's time to bring your 3.x current. there was a lot of reading in the previous links, i got a bit lost as i didnt recognize a lot of the words they were using. If i install Pyhon 3.3 do i need to uninstall my current python 3.1 and reinstall all the downloaded modules/packages i installed? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how can i use python 2 alongside 3?
You don't have to uninstall 3.1 but you would have to install all the downloaded modules or packages that you have in your 3.1 site packages folder to the 3.3 site packages folder. Maybe it's easier to simply grab the standalone pylauncher as I suggested earlier. Only you know what is the path of least resistance. yes the 2nd option (standalone pylauncher) sounds more convienient for me. i just have to try and comprehend all the instructions given.. hopefully ill get there in the end ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how can i use python 2 alongside 3?
yes the 2nd option (standalone pylauncher) sounds more convienient for me. i just have to try and comprehend all the instructions given.. hopefully ill get there in the end i managed to install the laucher. on the site when i click the correct launcher 32bit, i chose run and it automatically installed rather than asking me or allowing me to install it in cmd like their directions showed. my python 3 files still open but python 2 files still return errors like: print string is invalid syntax which tells me its still using python 3 to open these files. when i right click .py files a new option has been added to open with which is open with Python Launcher for Windows. Even when i do this my python 2 files won't open ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how can i use python 2 alongside 3?
Have you added shebang lines to those scripts yet? yes i added them. i think the problem is at the start where it asks me to: You should ensure the launcher is on your PATH - depending on how it was installed it may already be there, but check just in case it is not. From a command-prompt, execute the following command: py You should find that the latest version of Python 2.x you have installed is started .. py is not recognized and and it said depending on how it was installed. the problem is it didnt allow me to select a path when installing. it just automatically did everything. i have searched my PC for python launcher but it cant find it, so i dont know where its location is. i see it in control panel to uninstall a program but right clicking it doesnt give me an option to see its containing folder ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how can i use python 2 alongside 3?
I'm not using it, since I'm not using Windows. So these are guesses based on years stuck\b\b\b\b\b spent in the Windows environment. Clearly, the name of the program is py.exe, so that's what you should try searching for. From the cmd prompt, try dir /s py.exe Or, you could just try searching under c:\windows since that's where it's likely to be. To see your PATH, type PATH at the cmd prompt. To make temporary changes to your PATH (if py.exe is in an obscure place), just type set PATH=c:\mydir;%PATH% To make permanent changes to PATH, you have to change the environment variables in the Control Panel. I've done it many times, but don't recall just where it is. Such permanent changes will affect any new runs of CMD, as well as affect any other program subsequently started. thanks Dave. the file was py.exe as you said and the temporary path is able to open both version 2 and 3's python.exe. There seems to be a problem. python 2 seems to be the only version opening my files unless i do a few things. So with the shebang set: the python launcher, launches my python 3 files with the correct version if i double click the file or run it from a console. But it uses the wrong version if i run it from IDLE or if i right click the file and open with the Python Launcher. i guess i can live with that, but is there anyway around this? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how can i use python 2 alongside 3?
Did you find the control-panel-way to modify the PATH (assuming py.exe wasn't already in there) ? Without it, I'd be surprised if right-click would work correctly. And as for IDLE, there are two different IDLEs, one in each directory. So run the one that corresponds to the python you'll be using. How to do that? I dunno, since I don't use IDLE, but I'd find or make batch files called something like IDLE2.bat and IDLE3.bat that know how to find and run the appropriate IDLE. i didnt use the control panel way but the right click is now working, it was an error that in the script i had a txt.file open() and the right click way said no such file but the other ways found the txt file which is weird but right clicking works for other files without a txt file. i can live with that. i think it wise for me to try to permanently add the path with control panel. Thanks for all the help, its such a relief to now be able to run python 2 files ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how can i use python 2 alongside 3?
On Thu, Jan 24, 2013 at 9:35 PM, eryksun eryk...@gmail.com wrote: On Thu, Jan 24, 2013 at 1:56 PM, Matthew Ngaha chigga...@gmail.com wrote: py is not recognized and and it said depending on how it was installed. the problem is it didnt allow me to select a path when installing. The simpler installer is launchwin.msi, which installs to the Windows directory. This directory should already be on the PATH. In a cmd shell, check that 'assoc .py' is Python.File and that 'ftype Python.File' points to py.exe in your Windows directory, e.g. C:\Windows\py.exe %1 %*'. If it's wrong, re-install. Or fix it manually using assoc and ftype in an elevated cmd shell, which updates the local machine registry keys in HKLM\Software\Classes. Also, Windows Explorer has an Open With dialog that configures per-user settings for multiple associations, including a default (i.e. the Always use... checkbox). These keys are stored in HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py. Make sure that UserChoice is set to the Progid Python.File. You should be able to change this using the 'Open With-Choose Default Program...' dialog. You can customize pylauncher by editing its ini file in your profile. For example, run 'notepad %localappdata%\py.ini' to create/edit it. See the docs for the settings, such as changing the default interpreter and adding custom shebangs. sorry i didnt see this message. I havent read it yet although it looks complicated. Thanks ill report back if i need help ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how can i use python 2 alongside 3?
In a cmd shell, check that 'assoc .py' is Python.File and that 'ftype Python.File' points to py.exe in your Windows directory, e.g. C:\Windows\py.exe %1 %*'. If it's wrong, re-install. Or fix it manually using assoc and ftype in an elevated cmd shell, which updates the local machine registry keys in HKLM\Software\Classes. i think this is ok, i got these results. D:\Data\Py\myworkassoc .py .py=Python.File D:\Data\Py\myworkftype Python.File Python.File=D:\Data\Py2.7\python.exe %1 %* Also, Windows Explorer has an Open With dialog that configures per-user settings for multiple associations, including a default (i.e. the Always use... checkbox). These keys are stored in HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py. Make sure that UserChoice is set to the Progid Python.File. You should be able to change this using the 'Open With-Choose Default Program...' dialog. i dont quit understand when you say UserChoice is set to the Progid Python.File? what is Progid? i cant seem to locate that path HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traffic Light
On Sat, Jan 19, 2013 at 10:56 PM, anthonym antho...@att.net wrote: Thanks again for the info Alan. I am still passing the button process until I can get my rectangle and ovals on the canvass. The program runs and produces a window with the radio buttons on top. I would like them on the bottom but changes to the row field have no effect. Anybody have any ideas on why I don't see my shape on the canvass? i doubt i can help, but it might help if you could paste the section of the code in relation to what you're explaining and tell us what it's doing? some people don't use tkinter so its a bit hard to understand what you're saying. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Traffic Light
On Sun, Jan 20, 2013 at 12:05 AM, Matthew Ngaha chigga...@gmail.com wrote: On Sat, Jan 19, 2013 at 11:29 PM, anthonym antho...@att.net wrote: Sure thing. Here is the code. And after that is the box I get with the radio buttons but no shapes. i might be way off as im struggling to understand how tkinter works, but i noticed a few things which hopefully might help. starting with you wanting the buttons on the bottom of the window and not at the top where they are showing. from tkinter import * # Import tkinter class Trafficlight: def __init__(self): window = Tk() self.canvas = Canvas(window, width = 480, height = 480, bg = white) self.canvas.pack() # Add three radio buttons to frame1 frame1 = Frame(window) frame1.pack() rbRed = Radiobutton(frame1, text = Red, bg = red, variable = self.v2, value = 1, command = self.processRadiobutton) rbYellow = Radiobutton(frame1, text = Yellow, bg = yellow, variable = self.v2, value = 2, command = self.processRadiobutton) rbGreen = Radiobutton(frame1, text = Green, bg = green, variable = self.v2, value = 3, command = self.processRadiobutton) rbRed.grid(row = 400, column = 1) rbYellow.grid(row = 400, column = 2) rbGreen.grid(row = 400, column = 3) row = 400 seems a bit odd? do you really have 399 occupied rows? you define the canvas with absolute positioning: Canvas(window, width = 480, height = 480). where you trying to place the buttons with absolute positioning also? it seems they are appearing inside the frame in which you have put them in so why are you trying to move them again? im guessing you would have to reposition the Frame itself. also you are not using instance variables(self) for either the frame or the buttons, maybe they lose the reference to them once moved outside the frame. as for your shapes not appearing: def displayRect(self): self.canvas.create_rectangle(10, 10, 100, 100, tages = rect) # Display a Oval for the top light def displayOval(self): self.canvas.create_oval(10, 10, 10, 10) # Display an Oval for the middle light def displayOval(self): self.canvas.create_oval(20, 20, 20, 20) # Display an Oval for the bottom light def displayOval(self): self.canvas.create_oval(30, 30, 30, 30) If that is the complete code you showed.. Your buttons are not doing anything. they are calling a method that does nothing: def processRadiobutton(self): pass also i dont see anywhere in your code where you are calling any of those methods that create the shapes. you have to fix your method that your buttons are calling, and have it call the correct method for your specific shape. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] unclear topic
hey guys, this is not really a Python question. When ever im doing a tutorial, it could be pygame or some gui application, i usually find everything straight forward until the demonstration involves drawing. Then maths is applied and i can't follow along as easily. In the end by commenting out certain lines of code, i understand what each line is doing but the fact is im still faced with being very weak at drawing and working out the logic behind it. I also can't imagine if im designing a program and need to do drawings of my own how i would work out the calculations and be able to think for myself. The help im asking for is what do i need to study to be able to design my own programs that involve drawing? do i need to go off and learn maths? if so which type? some sort of geometry? or do i start studying some sort of physics? or does the answer lie within some framework/library python tutorial? on amazon ive seen: maths books physics book 2d engine physics books(box2d etc) game physics books - http://www.amazon.co.uk/Game-Physics-/dp/147103397X/ my other problem is i don't want to over do it. do i need to buy a game physics book, if all i want to do is understand how to implement my own calculations for complex objects etc? then again maybe that's not so bad. If you know your way around this stuff? what did you learn that gave you these skills? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for Absolute Beginners, 3rd Edition
With the code not being on the page, I went to the directed website and got the downloads, yet I couldn't find the source code anywhere to be found. Am I missing something plainly obvious? what exactly did you download? all the source code for every chapter is included in the download ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] exercise
return {e for (e, g) in self.sort_email.items() if g groups_list} guys i think ive got it. The in that comprehension was really confusing me, but i found out it means intersection, so i took the sets manually and saw the results i got using intersection and it became more clear from there. A Big Thanks if you took the time to help solve my issues. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Proper useage of open
I typed in to my script: a = open (dupli, r) and got an error stating that dupli is not deffined. it needs the quotes around it. so try: a = open (dupli, r) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help
Traceback (most recent call last): File Match finder GUI.py, line 87, in ? app = Application(root) File \Match finder GUI.py, line 23, in __init__ self.create_widgets() File Match finder GUI.py, line 61, in create_widgets self.submit_bttn = Button(self, text = Submit, command = self.reveal) AttributeError: Application instance has no attribute 'reveal' i only know really basic tkinter, but i think the error is looking for a method called reveal(). other than your __init__() and create_widgets() methods, i only see an update() method. I think your update method should be named reveal? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help
It's asking a lot if you want people to read your whole code to try and spot the errors. Try to run it from the console and paste what the errors are here. ___ 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
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] 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
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
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
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
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] help with homework
In your original getNames do something like this. Initialise a counter to zero. Every time you get a valid name increment the count. If the count is three you're finished. hey i was looking at the question as im learning also. With the counter, would you use a while loop instead of a for loop, with the condition being something like, while count 3: ? without len() the for loop option seems difficult ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Which is better Practice and why
In many of the tutorial examples ive come across, the main code's program is never at the top level, but always in a function of some sort. i understand why but, there is always a different way used to access the main code, i want to know which is the best. main() main's code #top level main() they call the main program by simply calling the main function. I've also seen a more complcated: if __name__ == '__main__': main() the 2nd one usually includes a lot more code then i showed. can you please tell me why different methods are used to access the main code? is it just preference or is one way actually better coding practice? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which is better Practice and why
oh ok i understand it.. Thanks for the help guys ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hasattr()
Thank you xDog and Steven. The whole assignment makes a lot of sense now after your explanations of what hasattr is doing. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] hasattr()
im trying to understand this hasattr function. i am supposed to pass in an object and an attribute name into its parametres... so im trying to get it to return True. Here's a quick test class Test: def __init__(self): self.att = testing e = Test() hasattr(e, e.att) False hasattr(e, testing) False what can i do to make this True? my e object has an attribute att but it returns False. Any code showing it return True? the task i have been set is very difficult but i don't want to ask for help just yet, i think understanding how hasattr works might make everything else clear. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need an explanation
Thanks for everyone that replied. I really gained a lot from all the input. Also thanks to Dave and Prasad for explaining why i had errors trying to run the program. I fully understand the code now and im able to run it without errors. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] need an explanation
i need help on 2 topics. 1) can someone please tell me what sys is doing, and why its using weird indexing? if __name__ == __main__: A_Class(*sys.argv[1:4]).A_Class_Method() is sys able to call methods? if so why does it need indexing if it uses * . -- 2) also i need help with zipfiles. these 2 functions are related in the same class. def __init__(self): self.zipping_directory = unzipped-{}.format(filename) def _full_filename(self, filename): return os.path.join(self.zipping_directory, filename) def zip_files(self): file = zipfile.ZipFile(self.filename, 'w') for filename in os.listdir(self.zipping_directory): file.write(self._full_filename(filename), filename) the main thing i need help with is the last line. the zip file is writing to a file but why does it use the same argument twice? the for loop above that line returns the file from the zipping directory, which is the 2nd argument on file.write? But the 1st argument is using that same file because that is the file returned from the def _full_filename(self, filename): method. so please can someone tell me why it uses the same file argument twice in its write method? thanks for your time ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need an explanation
Obviously a Monty Python fan as I see 3 methods :) lol i dont know what i was looking at.. yes its 3 methods sorry:( def __init__(self): self.zipping_directory = unzipped-{}.format(filename) Where did filename appear from above? sorry i didnt write everything. the init method also had... self.filename = filename ... i will paste the whole code I suggest that you show us some real code that will run with some print statements in appropriate places to show us what is happening. That way you may well be able to answer your own questions and learn at the same time. sadly when i run the file i get an error so i dont know what to doto fix it and be able to run @ DAVE.. you said sys is a module (presumably you have an import somewhere above this line). In the module, there's a list argv. the import statements are: import sys import os import shutil import zipfile so im guessing [sys, os, shutil, zipfile] these are the arguments being passed? my mind tells me no, as these are more likely the arguments in the A_Class init method? here is he full code... i changed the names in the mail to make it clearer. so the names in the code will be different. A_Class is actually ZipReplace etc.. i cant test it because on start the program returns this error and i dont know how to fix it: ZipReplace(*sys.argv[1:4]).zip_find_replace() TypeError: __init__() takes exactly 4 positional arguments (1 given) full code: import sys import os import shutil import zipfile class ZipReplace: def __init__(self, filename, search_string, replace_string): self.filename = filename self.search_string = search_string self.replace_string = replace_string self.temp_directory = unzipped-{}.format( filename) def _full_filename(self, filename): return os.path.join(self.temp_directory, filename) def zip_find_replace(self): self.unzip_files() self.find_replace() self.zip_files() def unzip_files(self): os.mkdir(self.temp_directory) zip = zipfile.ZipFile(self.filename) try: zip.extractall(self.temp_directory) finally: zip.close() def find_replace(self): for filename in os.listdir(self.temp_directory): with open(self._full_filename(filename)) as file: contents = file.read() contents = contents.replace( self.search_string, self.replace_string) with open(self._full_filename(filename), w) as file: file.write(contents) def zip_files(self): file = zipfile.ZipFile(self.filename, 'w') for filename in os.listdir(self.temp_directory): file.write(self._full_filename(filename), filename) shutil.rmtree(self.temp_directory) if __name__ == __main__: ZipReplace(*sys.argv[1:4]).zip_find_replace() is a bit too advanced for me but i now see what it does.. although i wish it didnt return an error when run. so the arguments being passed are... [os, shutil, zipfile] or [filename, search_string, return_string] ? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Tkinter-discuss] whats Style()
sorry i sent the email directly by mistake. Just like to say thanks once again for all the help ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Tkinter-discuss] whats Style()
sorry i sent the email directly by mistake. Just like to say thanks once again for all the help this email was a mistake, meant for anything mailing section.. please ignore it ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Tkinter-discuss] displaying an image
You need to install PIL to use the tutorial you are doing. http://www.pythonware.com/products/pil/ the site says The current free version is PIL 1.1.7. This release supports Python 1.5.2 and newer, including 2.5 and 2.6. A version for 3.X will be released later. i have python 3. all the downloads below it only show python 2 versions. am i stuck?:( ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simon game issues
It would appear you're running some form of event loop, such as wxpython, tkinter, pygame, or whatever. If so, you have to do your delays using the mechanism that system defines, not using sleep(). As you've discovered, sleep() stops the whole thread, and that's not what you want. What you want is to set an event to fire at some measured time in the future, so the actual waiting is done inside the event loop. hey i looked at the livewires documentation and pulled up the timer information. im struggling to figure out how to use its explanation. i need to use it at 2 different parts of the program. 1st when the game starts i need to create my sprite objects so they appear before my animation objects: red = Sprite(colour = Colours.red, x = 250, y = 255) games.screen.add(red) #timer event delay goes here so the animations don't start as soon as the game is opened, before the coloured sprites as they've been doing. self.create_animations() - i also need a timer event when i display my sequence of animation objects so they dont show on screen simultaneously. so: #1st animation red_animation = Animation(images = c_red, x = 250, y = 255, repeat_interval = 4, n_repeats = 1) games.screen.add(red_ani) red_sound.play() #Timer event to go here, so next animation in sequence goes after the timed pause. #2nd animation blue_animation = Animation(images = c_blue, x = 373, y = 255, repeat_interval = 4, n_repeats = 1) games.screen.add(blue_ani) blue_sound.play() do you think you can offer any help how to implement the timer code or function? i will provide the link to the page, but here's the relevant code: Timer The Timer class is a class you can add to something which is also a subclass of Object, to make an object that performs actions at regular intervals. A class which is intended to be used with another class is called a mix-in. For instance, if you wanted to make a new class of your own which was a Circle and also a Timer, you would define the class by saying class MyClass (games.Circle, games.Timer): • init_timer (interval) interval is how often the tick method is called, measured in timer ticks. How long a tick is depends on the fps argument you give to the Screen‘s mainloop method. Setting fps to 50 means a tick is 1/50 of a second. You must call this method emph{after} you have called the init_ method for the Object subclass you are using. • stop () Stop the timer running. It continues to exist, but doesn’t count any more. • start () Starts the timer again. A full interval will elapse before it ticks. • get_interval () Gets the current interval. • set_interval (interval) Sets the current interval. • tick () This method must be supplied by you, by subclassing the Timer class. http://www.geon.wz.cz/livewires/w-livewires.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] simon game issues
Hi guys. my Python tutorial set me a task to recreate a simon game using livewires. http://www.youtube.com/watch?v=agUABjGAJww this is quite long, i understand if you can't help right away summary: i create 4 squared shaped objects(red, blue, green, yellow) as instances for a class derived from the Sprite class i create 4 animation objects to represent the 4 colour shaped objects. the animations get brighter in colour so the user can understand which colour he has to follow the animations also light up when the user presses the keyboard key they are assigned too. they are instances for a class derived from the Animation class. i have also included 4 sound files, assigned to 1 animation object to be played each time that animation lights up My problems: everytime i want to play a sequence for the user to follow. i run into this problem. i create 1 animation say red, so the user can see the 1st colour he has to follow. then i put a timed delay time.sleep(1) before i display the next animation, say blue. i have tried many other timing methods to achieve this, but once there is some sort of timer, the whole screen pauses for the duration of the timed delay (but the sound files play simultaneously during that freeze) then after that, the sequence is displayed at the same time. not 1 after the other. so even though i put the timer after the creation of the 1st animation, the timer for some reason happens before it. is there a way i can get around this? I also start the game/program by displaying the 4 square objects (Sprite Class) before adding their animation. after the creation of the sprites i play the animation sequence. The problem is they play as soon as the game starts before the Sprites are even displayed, and also simultaneously (not in a sequnce) making it confusng. so after creating the sprites, i added a timer so the animations happens after the sprites are shown. But again because of this timer, which is meant to occur after the creation of the sprites, when i start the game, i get a blank screen for the duration of the timer((but the sound files, again play simultaneously during that time). After that i still don't get the sprites, i get their animatons instead, then finally the sprites are displayed. i dont understand, the Sprites are meant to be the 1st things on the screen, is there a solution? Getting user input: the last problem i have is when the user presses a key to select a colour. i have the script check for the key press, then return the colour to a function/method called def result(self, color): that determines if he got the right colour. if he does i increase score by 1. to check results i create 2 lists. one with all 4 colours: self.animation = [Pressed.dict_red, Pressed.dict_blue, Pressed.dict_green, Pressed.dict_yellow] then i create an empty list to append the sequence in the order i randomly played them, so i can check if the user got each colour: self.get_animation = [] they append from the 1st list above and my result function uses it to check colours here's how it goes. if keyboard for colour red is pressed: create red animation: send results back to result method: self.game.result(red) my result method and its class: self.stage = 3 ..#say if we were on stage 3. i would play 3 colours. stage 4 would be 4 colours self.counter = -1 .#to correctly index list def result(self, COLOUR): self.counter += 1#count is now at 0 self.end_testing = self.stage..#this will count down from the stages value. once it reaches 0, there is no more colours to check for if COLOUR in self.get_animation[self.counter]: self.score.value += 1 self.end_testing -= 1 even though i am using a counter here to count down: self.end_testing i have used while and for loops also. My problem is none of these work because a keypress from the user, even if tapped, registers as multiple key presses, the self.score that i increment by 1 flies to about 40 from 1 key press. as a result my counter i use to index the list is way out of range. i tried to add a time.sleep(.03) as soon as a key is pressed, so it would register once. it managed to limit it to 4 presses, so self.score would equal 4 after 1 press, 8 after 2.. in that i started my counter at -4. then the code self.counter /= 4 would give me 0. after the next 4 presses, my counter would be at 4, the same code self.counter /= 4 would give me 1. after the next 4 presses, my counter would be at 8, the same code self.counter /= 4 would give me 2. this successfully fixed my indexing issue, but it needs A LOT of if statements and it is getting to confusing. isnt there a way to make 1 key press mean 1? and not 40? other wise how can i keep track of the score. any help? do i quit this exercise and blame it on the program just not following my instructions? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:
[Tutor] setting a timer
i have a way to set a timer for creating new objects copied from a book but as i have started my next exercise in a very different way, i want to avoid that math method/formula as it will cause me to rearrange some classes totally... i tried a simple method but its not working. any ideas? heres my code, ill leave out the irrelevant code. class Game(object): interval = 0 def play(self): Game.interval = 40 while Game.interval 0: self.count_down() def count_down(self): Game.interval -= 1 so the play() method gives interval a value of 40. the while loop should reduce interval by 1 everytime it calls the count_down() method. The problem is this is happening instantly. i've even put the Game.interval value as high as 5 and it reaches 0 instantly. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setting a timer
Get a slower computer. I expect that if you find an old Commodore 64 from 1982, or perhaps an 1984 Apple Macintosh, it might be slow enough for your count down idea to work. But with modern computers, counting up to, or down from, 5 is more or less instantaneous in human terms. A better way to pause for a moment is this: import time time.sleep(0.1) # pause for 0.1 second time.sleep(60) # pause for 1 minutes hah do u think i could find one of those on ebay??? i wasnt aware of the time module! thanks a lot for your help:) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simon says
Sounds as though what is wanted in a Pythonic version of an early electronic game Simon that was marketed back in the late 70's. It was roughly Frisbee shaped although slightly larger. The top was divided into four quadrant-shaped paddles each of a different color. The game consisted of Simon generating longer and longer sequences of random color-sound flashes (each element in the sequence consisted of a momentary sound accompanied by the appropriate quadrant lighting up). After Simon had generated a sequence, the player had to duplicate it by pressing the paddles. A successful recreation of a sequence was rewarded by Simon generating a longer one, until the player finally screwed up. At that point Simon made an electronic rude noise and the device was handed on to the next player if there were multiple players. The player who succeeded in matching the longest sequence was the winner of that round. I'll bet ebay still has them for sale, and Google would get you a description that would be better than mine. -Bill Thanks Bill. I did some more searching and managed to find a few new versions on youtube with altered gameplay i guess. Here's the closest to what has been described here: http://www.youtube.com/watch?v=agUABjGAJww thanks to everyone ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor