Re: [Tutor] Dictionary
On 6/17/2012 2:26 PM, Selby Rowley-Cannon wrote: [snip] Do you have any programming (algorithm development) experience? Do you want to translate words independent of context? -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Simple Python Address Book (Advice welcome!)
def LoadAddresses(): Loads all addresses from file and places them in tuple in form (bool, list), where the list is each row from the file (a person's name | email). success, lines = (False, []) try: f = open(addressBookPath, 'r') lines = f.readlines() f.close() success, lines = (True, lines) except IOError as e: print 'Error opening address book: ', e return (success, lines) The latest style preference in Python is to use with statements for file handling, so that would become: try: with f as open(.): success,lines = True, f.readlines() except IOError as e: print ... return (success,lines) def main(): (success, lines) = LoadAddresses() if not success: No real reason to return success as you can do this instead for the same effect. The only difference would be on reading an empty file. Not sure what you would want it to do... def main(): lines = LoadAddressses() if not lines: Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionaries
This sounds a wee bit like a homework assignment and we have a policy of not doing those for you... Just to clarify, we will help you on it but not do it for you. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Installing NumPy
Hi Every body, I'm trying to install NumPy on Python 2.7 for windows 32. But have had no success so far. I appreciate any help. Thanks, Ali ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing NumPy
On 6/18/2012 12:50 PM Ali Torkamani said... Hi Every body, I'm trying to install NumPy on Python 2.7 for windows 32. But have had no success so far. Hmmm. I have Active State's version 2.7 installed on the machine I';m in front of today. Launched and confirmed no numpy installed. Then I downloaded and ran http://pypi.python.org/packages/2.7/n/numpy/numpy-1.6.2.win32-py2.7.exe and I can now import numpy. What did you try? Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing NumPy
Thanks. I installed active python and then ran numpy package installer, and now it seems liek I can import numpy. Previously I had installed: http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi but there should be a problem connecting this one with numpy. Thanks any way, it's working now! Ali On Mon, Jun 18, 2012 at 5:15 PM, Emile van Sebille em...@fenx.com wrote: On 6/18/2012 12:50 PM Ali Torkamani said... Hi Every body, I'm trying to install NumPy on Python 2.7 for windows 32. But have had no success so far. Hmmm. I have Active State's version 2.7 installed on the machine I';m in front of today. Launched and confirmed no numpy installed. Then I downloaded and ran http://pypi.python.org/**packages/2.7/n/numpy/numpy-1.* *6.2.win32-py2.7.exehttp://pypi.python.org/packages/2.7/n/numpy/numpy-1.6.2.win32-py2.7.exeand I can now import numpy. What did you try? Emile __**_ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with Matplotlib labels
I'm working on a simple python web app that generates graphs, because managers love graphs. I've got it about 90% done, but I'm having trouble getting labels onto my stacked graph. In the matplotlib documentation there is a nice example showing how to create the legend. Note how the variables p1 and p2 are used to generate the legend in this example: http://matplotlib.sourceforge.net/examples/pylab_examples/bar_stacked.html code p1 = plt.bar(ind, menMeans, width, color='r', yerr=womenStd) p2 = plt.bar(ind, womenMeans, width, color='y', bottom=menMeans, yerr=menStd) plt.ylabel('Scores') plt.title('Scores by group and gender') plt.xticks(ind+width/2., ('G1', 'G2', 'G3', 'G4', 'G5') ) plt.yticks(np.arange(0,81,10)) plt.legend( (p1[0], p2[0]), ('Men', 'Women') ) /code Unfortunately my graph is generated dynamically. How can I create my legend when my 'bar' objects have no names to refer to? for admin in bd: bar(ind, bd[admin], width, color=colordict[admin]) xticks(ind+width/2., datenames) legend() grid('on') outfile = 'testfile.png' savefig('/var/www/'+outfile) return outfile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
Unfortunately my graph is generated dynamically. How can I create my legend when my 'bar' objects have no names to refer to? I also noticed another issue with my stacked bar graph; the total height of the bar is the size of the largest number of the dataset, and not the total of all the individual items. Anyone matplotlib experts out there who can weigh in? ___ 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/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. -- 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] Help with Matplotlib labels
Not me, but I notice there is a gmane newsfeed for matplotlib: gmane.comp.python.matplotlib.general Probably worth posting questions there. Thank you, I will inquire on the newsfeed. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
Unfortunately my graph is generated dynamically. How can I create my legend when my 'bar' objects have no names to refer to? for admin in bd: bar(ind, bd[admin], width, color=colordict[admin]) xticks(ind+width/2., datenames) legend() grid('on') outfile = 'testfile.png' savefig('/var/www/'+outfile) return outfile I found the solution to this problem, one of the optional kwargs for the pyplyt.bar() function is label. Once I assigned that, legend() worked fine. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
I also noticed another issue with my stacked bar graph; the total height of the bar is the size of the largest number of the dataset, and not the total of all the individual items. Anyone matplotlib experts out there who can weigh in? I figured out what was going on here; the bars were all rendering on top of one another. Adjustments to the bottom parameter have fixed the issue. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python varying mulitple inheritance
Thank you Steve, for the pointing me in a smarter direction! My immediate homework is: - Practice consistent conventions for naming things -- pep-0008. - Learn composition/has-a. I thought of a better way to think of my problem. A list element would contain the things that Bob has in his pockets, at a given moment. For example: Bob has 6 things. They are well known things and it's easy to make a class for each of them. But Bob could have 2 to the power of 6, combinations of those things in his pockets. I don't want to make 64 classes, to cover each possible combination. I would read from a file to know what Bob has: time wallet keys comb USB cell_phone work_badge 00 000 0 0 11 100 0 1 20 000 1 0 30 000 1 1 41 111 0 0 ... 0 = not in his pocket 1 = has-a in his pocket I don't want an instance of something, if it's not in Bob's pocket at that time. (Maybe I'm making it harder than it needs to be.) If no one responds, it's OK because now I know where to focus. (But help would be welcome.) I was told that you guys were great. You are!!! Ken On Sun Jun 17 18:36 , Steven DAprano sent: ke...@kendy.org wrote: Hello I'm new to classes. And I hope the my question isn't too big. I have electronic test equipment, but thought that a boat example would be easier. Can you help me untangle my class design? My problem is basically multiple inheritance, but I want to be flexible for how many will inherit. Your first problem is that you are misusing inheritance when you should be using composition instead. http://www.python.org/dev/peps/pep-0008/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python varying mulitple inheritance
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): ... On Mon Jun 18 22:03 , sent: Thank you Steve, for the pointing me in a smarter direction! My immediate homework is: - Practice consistent conventions for naming things -- pep-0008. - Learn composition/has-a. I thought of a better way to think of my problem. A list element would contain the things that Bob has in his pockets, at a given moment. For example: Bob has 6 things. They are well known things and it's easy to make a class for each of them. But Bob could have 2 to the power of 6, combinations of those things in his pockets. I don't want to make 64 classes, to cover each possible combination. I would read from a file to know what Bob has: time wallet keys comb USB cell_phone work_badge 00 000 0 0 11 100 0 1 20 000 1 0 30 000 1 1 41 111 0 0 ... 0 = not in his pocket 1 = has-a in his pocket I don't want an instance of something, if it's not in Bob's pocket at that time. (Maybe I'm making it harder than it needs to be.) If no one responds, it's OK because now I know where to focus. (But help would be welcome.) I was told that you guys were great. You are!!! Ken On Sun Jun 17 18:36 , Steven DAprano sent: ke...@kendy.org wrote: Hello I'm new to classes. And I hope the my question isn't too big. I have electronic test equipment, but thought that a boat example would be easier. Can you help me untangle my class design? My problem is basically multiple inheritance, but I want to be flexible for how many will inherit. Your first problem is that you are misusing inheritance when you should be using composition instead. http://www.python.org/dev/peps/pep-0008/ ___ 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
[Tutor] Pymongo Error
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 module 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': 'user123', 'PASSWORD': '12424214', 'HOST': 'mongodb://staff.mongohq.com/db-name', '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
[Tutor] Writing to Windows 64-bit event log
Hi there, 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. My Python version is 2.7.1 and I am running the 32-bit Windows version on a Windows 7 laptop. Is there a way I can log entries to the Windows event log on my laptop from my Python application? Thanks Johan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor