Re: [Tutor] python varying mulitple inheritance
On 19/06/12 06:14, ke...@kendy.org wrote: Hmmm. No need to write the whole thing written out. Just how not to code: class Pocket1(Wallet, Keys, Comb, Usb, CellPhone, WorkBadge): class Pocket2(Wallet, Keys, Comb, Usb, CellPhone): class Pocket3(Wallet, Keys, Comb, Usb,WorkBadge): class Pocket4(Wallet, Keys, Comb, Usb): class Pocket5(Wallet, Keys, Comb, CellPhone, WorkBadge): class Pocket6(Wallet, Keys, Comb, CellPhone): ... Back to basics. a class is a definition of a *type* of thing, not a particular case. A Pocket is a general purpose container. Each instance can hold many things. So you would normally expect one pocket class and 6 instances. Each instance holding a different list of items. The only time you need a different Pocket class is where the pocket has different *behaviour*. It is normally the behaviours that differentiate classes not the data. The class data is there to support the class behaviour. The behaviour of a Pocket is probably some thing like: addItem removeItem findItem countItems open close empty In most implementations a Pocket will look a lot like a list... HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing to Windows 64-bit event log
On 19/06/12 06:37, Johan Geldenhuys wrote: I've looked all over, but couldn't find any help as far as an API goes to log to a 64-bit Windows7 machine event log. I don't know if your search included MSDN but that would be my third port of call after the standard library and Google... There will be a Windows API call and you can access those via ctypes or Pythonwin. There is almost certainly a Windows Knowledge Base article too, use the MSDN search to find it... hth -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing to Windows 64-bit event log
On 19/06/2012 06:37, Johan Geldenhuys wrote: > I've looked all over, but couldn't find any help as far as an API goes > to log to a 64-bit Windows7 machine event log. There are functions available in the pywin32 package under the win32evtlog module. I have wrapped some of them in my winsys package. Some examples here: http://winsys.readthedocs.org/en/latest/cookbook/event_logs.html TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
On 19/06/2012 00:46, Alan Gauld wrote: On 19/06/12 00:13, Sean Carolan wrote: and not the total of all the individual items. Anyone matplotlib experts out there who can weigh in? Not me, but I notice there is a gmane newsfeed for matplotlib: gmane.comp.python.matplotlib.general Probably worth posting questions there. No probably about it, I've asked questions there and like all Python lists found them extremely friendly and helpful. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pymongo Error
For some reason, GMail sent my response to Ranjith and not to the whole list. Fixing with his response added. On Tue, Jun 19, 2012 at 7:22 AM, Ranjith Kumar wrote: > Hi all, > I tried Django with Mongodb while running manage.py syncdb I endup with this > error > > note : it works fine with sqlite and mysql db > > (django-1.3)ranjith@ranjith:~/ > sandbox/python-box/hukkster-core-site/hukk$ ./manage.py syncdb > /home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/pymongo/connection.py:385: > UserWarning: must provide a username and password to authenticate to > hukkster_testing > "to authenticate to %s" % (db,)) > Creating tables ... > Traceback (most recent call last): > File "./manage.py", line 14, in > execute_manager(settings) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", > line 438, in execute_manager > utility.execute() > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", > line 379, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 191, in run_from_argv > self.execute(*args, **options.__dict__) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 220, in execute > output = self.handle(*args, **options) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 351, in handle > return self.handle_noargs(**options) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", > line 109, in handle_noargs > emit_post_sync_signal(created_models, verbosity, interactive, db) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/sql.py", > line 190, in emit_post_sync_signal > interactive=interactive, db=db) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", > line 172, in send > response = receiver(signal=self, sender=sender, **named) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", > line 41, in create_permissions > "content_type", "codename" > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 107, in _result_iter > self._fill_cache() > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 772, in _fill_cache > self._result_cache.append(self._iter.next()) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 959, in iterator > for row in self.query.get_compiler(self.db).results_iter(): > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 229, in results_iter > for entity in self.build_query(fields).fetch(low_mark, high_mark): > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 290, in build_query > query.order_by(self._get_ordering()) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 339, in _get_ordering > raise DatabaseError("Ordering can't span tables on non-relational > backends (%s)" % order) > django.db.utils.DatabaseError: Ordering can't span tables on non-relational > backends (content_type__app_label) > > > DB settings in settings.py > > DATABASES = { > 'default': { > 'ENGINE': 'django_mongodb_engine', > 'NAME': 'helloworld', > 'USER': '', > 'PASSWORD': '12424214', > 'HOST': 'mongodb://staff.mongohq.com/', > 'PORT': 'X', > }, > } > > my requirement packages, > Django==1.3 > dictshield==0.4.4 > django-mongodb-engine==0.4.0 > django-social-auth==0.6.9 > djangotoolbox==0.0.1 > httplib2==0.7.4 > mongoengine==0.6.10 > mongokit==0.8 > oauth2==1.5.211 > pymongo==2.2 > python-openid==2.2.5 > simplejson==2.5.2 > wsgiref==0.1.2 > > Please point me what i missed here... > > -- > Cheers, > Ranjith Kumar K, > Chennai. > > http://ranjithtenz.wordpress.com > > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > On 2012-06-19T13:05:00Z Kwpolska wrote: > http://mongodb-is-web-scale.com > > Seriously: > django.db.utils.DatabaseError: Ordering can't span tables on non-relational > backends (content_type__app_label) > >It's left to you to understand the problem. On 2012-06-19T13:30:00Z Ran
Re: [Tutor] Pymongo Error
On Tue, Jun 19, 2012 at 1:22 AM, Ranjith Kumar wrote: > Hi all, > I tried Django with Mongodb while running manage.py syncdb I endup with > this error > > note : it works fine with sqlite and mysql db > > (django-1.3)ranjith@ranjith:~/ > sandbox/python-box/hukkster-core-site/hukk$ ./manage.py syncdb > /home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/pymongo/connection.py:385: > UserWarning: must provide a username and password to authenticate to > hukkster_testing > "to authenticate to %s" % (db,)) > Creating tables ... > Traceback (most recent call last): > File "./manage.py", line 14, in > execute_manager(settings) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", > line 438, in execute_manager > utility.execute() > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", > line 379, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 191, in run_from_argv > self.execute(*args, **options.__dict__) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 220, in execute > output = self.handle(*args, **options) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 351, in handle > return self.handle_noargs(**options) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", > line 109, in handle_noargs > emit_post_sync_signal(created_models, verbosity, interactive, db) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/sql.py", > line 190, in emit_post_sync_signal > interactive=interactive, db=db) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", > line 172, in send > response = receiver(signal=self, sender=sender, **named) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", > line 41, in create_permissions > "content_type", "codename" > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 107, in _result_iter > self._fill_cache() > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 772, in _fill_cache > self._result_cache.append(self._iter.next()) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 959, in iterator > for row in self.query.get_compiler(self.db).results_iter(): > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 229, in results_iter > for entity in self.build_query(fields).fetch(low_mark, high_mark): > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 290, in build_query > query.order_by(self._get_ordering()) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 339, in _get_ordering > raise DatabaseError("Ordering can't span tables on non-relational > backends (%s)" % order) > django.db.utils.DatabaseError: Ordering can't span tables on > non-relational backends (content_type__app_label) > > > DB settings in settings.py > > DATABASES = { > 'default': { > 'ENGINE': 'django_mongodb_engine', > 'NAME': 'helloworld', > 'USER': '', > 'PASSWORD': '12424214', > 'HOST': 'mongodb://staff.mongohq.com/', > 'PORT': 'X', > }, > } > > my requirement packages, > Django==1.3 > dictshield==0.4.4 > django-mongodb-engine==0.4.0 > django-social-auth==0.6.9 > djangotoolbox==0.0.1 > httplib2==0.7.4 > mongoengine==0.6.10 > mongokit==0.8 > oauth2==1.5.211 > pymongo==2.2 > python-openid==2.2.5 > simplejson==2.5.2 > wsgiref==0.1.2 > > Please point me what i missed here... > > -- > Cheers, > Ranjith Kumar K, > Chennai. > > http://ranjithtenz.wordpress.com > > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > This list here is for new users to python. Using mongo with django is a pretty advanced topic. I would suggest posting this on stackoverflow, or to the django-users group (and there are a ton of resources on this already on those two sites on this topic) That said, having used mongo with django, I'll bet your problem is that you are using the django version provided by the django pro
Re: [Tutor] python varying mulitple inheritance
Thank you Steve and Alan! I'll keep studying and practicing. Ken >Back to basics. a class is a definition of a *type* of thing, not a >particular case. A Pocket is a general purpose container. Each instance >can hold many things. So you would normally expect one pocket class and >6 instances. Each instance holding a different list of items. > >The only time you need a different Pocket class is where the pocket has >different *behaviour*. It is normally the behaviours that differentiate >classes not the data. The class data is there to support the class >behaviour. The behaviour of a Pocket is probably some thing like: >addItem >removeItem >findItem >countItems >open >close >empty > >In most implementations a Pocket will look a lot like a list... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Mailing list; I have a small, [for the most part] functioning translation app for Rydish, a language created for the sole purpose of an RPG. The only problem is when I enter a word that has not yet been translated, I get this error: Traceback (most recent call last): File "translator.py", line 25, in Etranslate() File "translator.py", line 14, in Etranslate print(Edictionary[Eword]) KeyError: 'world' Is there a way to print a user-freindly message instead of displaying a traceback? Thanks, -Selby ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On Tue, Jun 19, 2012 at 3:35 PM, Selby Rowley-Cannon wrote: > Mailing list; > I have a small, [for the most part] functioning translation app for > Rydish, a language created for the sole purpose of an RPG. The only problem > is when I enter a word that has not yet been translated, I get this error: > > Traceback (most recent call last): > File "translator.py", line 25, in > Etranslate() > File "translator.py", line 14, in Etranslate > print(Edictionary[Eword]) > KeyError: 'world' > > Is there a way to print a user-freindly message instead of displaying a > traceback? > Thanks, > -Selby > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > try: print(Edictionary[Eword] except KeyError: print Eword, " has not yet been translated" If you catch the exception you can print a useful message. Not sure what that would be but I took a stab -- Joel Goldstick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Greetings Selby, : I have a small, [for the most part] functioning : translation app for Rydish, a language created for the sole : purpose of an RPG. The only problem is when I enter a word that : has not yet been translated, I get this error: : : Traceback (most recent call last): : File "translator.py", line 25, in : Etranslate() : File "translator.py", line 14, in Etranslate : print(Edictionary[Eword]) : KeyError: 'world' : : Is there a way to print a user-freindly message instead of : displaying a traceback? Thanks, -Selby Try the two techniques here (and the one Joel just posted): http://mail.python.org/pipermail/tutor/2012-June/090025.html -Martin (You asked your question much more clearly this time and with a code sample--so, keep it up and enjoy the Python.) -- Martin A. Brown http://linux-ip.net/___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 06/19/2012 03:35 PM, Selby Rowley-Cannon wrote: > Mailing list; > I have a small, [for the most part] functioning translation app for > Rydish, a language created for the sole purpose of an RPG. The only problem > is when I enter a word that has not yet been translated, I get this error: > > Traceback (most recent call last): > File "translator.py", line 25, in > Etranslate() > File "translator.py", line 14, in Etranslate > print(Edictionary[Eword]) > KeyError: 'world' > > Is there a way to print a user-freindly message instead of displaying a > traceback? > Thanks, > -Selby > > Even easier than catching an exception is to test for the condition you expect might not pass. Assuming your Edictionary is a dict, all you need to do is to make the reference conditional on the presence of that particular key. if Eword in Edictionary: print(Edictionary[Eword]) else: print("oops -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 19/06/2012 21:07, Dave Angel wrote: On 06/19/2012 03:35 PM, Selby Rowley-Cannon wrote: Mailing list; I have a small, [for the most part] functioning translation app for Rydish, a language created for the sole purpose of an RPG. The only problem is when I enter a word that has not yet been translated, I get this error: Traceback (most recent call last): File "translator.py", line 25, in Etranslate() File "translator.py", line 14, in Etranslate print(Edictionary[Eword]) KeyError: 'world' Is there a way to print a user-freindly message instead of displaying a traceback? Thanks, -Selby Even easier than catching an exception is to test for the condition you expect might not pass. Assuming your Edictionary is a dict, all you need to do is to make the reference conditional on the presence of that particular key. if Eword in Edictionary: print(Edictionary[Eword]) else: print("oops But note the comparison between LBYL and EAFP - I'll leave those interested to google for it :) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 06/19/2012 06:48 PM, Mark Lawrence wrote: > On 19/06/2012 21:07, Dave Angel wrote: >> On 06/19/2012 03:35 PM, Selby Rowley-Cannon wrote: >>> Mailing list; >>> I have a small, [for the most part] functioning translation >>> app for Rydish, a language created for the sole purpose of an RPG. >>> The only problem is when I enter a word that has not yet been >>> translated, I get this error: >>> >>> Traceback (most recent call last): >>>File "translator.py", line 25, in >>> Etranslate() >>>File "translator.py", line 14, in Etranslate >>> print(Edictionary[Eword]) >>> KeyError: 'world' >>> >>> Is there a way to print a user-freindly message instead of >>> displaying a traceback? >>> Thanks, >>> -Selby >>> >>> >> >> Even easier than catching an exception is to test for the condition you >> expect might not pass. Assuming your Edictionary is a dict, all you >> need to do is to make the reference conditional on the presence of that >> particular key. >> >> if Eword in Edictionary: >> print(Edictionary[Eword]) >> else: >> print("oops >> >> >> > > But note the comparison between LBYL and EAFP - I'll leave those > interested to google for it :) > If the program is multithreaded, or if it's NOT a dictionary, then perhaps LBYL is not the right answer. Otherwise, it describes what's wanted, and doesn't risk catching too broad an exception. I've seen far too many programs that used a bare except to mask not only the condition, but lots of other things. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 6/19/2012 12:35 PM Selby Rowley-Cannon said... Mailing list; I have a small, [for the most part] functioning translation app for Rydish, a language created for the sole purpose of an RPG. The only problem is when I enter a word that has not yet been translated, I get this error: Traceback (most recent call last): File "translator.py", line 25, in Etranslate() File "translator.py", line 14, in Etranslate print(Edictionary[Eword]) KeyError: 'world' Is there a way to print a user-freindly message instead of displaying a traceback? As you're writing a translator it may be interesting to swap in something that can still be used in the translation. No one's mentioned get as an option: >>> Edict = dict(zip('abcde','ABCDE')) >>> for ii in 'agbdteabcdfe': ... print Edict.get(ii,'-grumble-') ... A -grumble- B D -grumble- E A B C D -grumble- E >>> Or spice it up! >>> import random >>> undefined = ['-grumble-','-mumble-','-garbled-','-cough-'] >>> for ii in 'agbdteabcdfe': ... print Edict.get(ii,random.choice(undefined)) ... A -mumble- B D -grumble- E A B C D -cough- E >>> Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor