Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
Wow. Something horrible happened here. http://xkcd.com/386/ I THOUGHT the guaranteed same-ordering of dict.keys and dict.values started in python 2.6. That was a simple mistake. It turns out, that's not the case. But in general, access to dicts and sets is unordered, so you can't/don't/shoul

Re: [Tutor] copy directory from one part to another and preserve permissions

2010-05-27 Thread Steven D'Aprano
On Thu, 27 May 2010 10:12:58 pm Norman Khine wrote: > hello, > i have this code: > > if i want to copy the 'files' directory contents and preserve > permissions is this the right way to do this? > > import shutil > path_to_old_files_dir = '/var/www/dev.site.com/htdocs/files' > path_to_new_files_dir

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Steven D'Aprano
On Fri, 28 May 2010 09:44:36 am Matthew Wood wrote: > That said, the version with an extra line will work on python < 2.6, > so I'd probably just leave it that way. Why? That's like saying: "I could write y = x+2 in Python, but y = 1+x+1 will work too, so I'll write that instead, just in case.

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Steven D'Aprano
On Fri, 28 May 2010 09:19:20 am Matthew Wood wrote: > I BELIEVE there's some new cool features in 2.6 or maybe 3.0 where > non-simultaneous access to my_dict.keys() and my_dict.values() will > keep them "paired up", but I don't know the details. This is not a new feature, but a very old feature.

Re: [Tutor] Speed it up...

2010-05-27 Thread Matthew Wood
On Thu, May 27, 2010 at 3:37 AM, trias wrote: > > Hi, > >  I have wrote the following lines that work fine, but are quite slow, are > there any obvious things I can consider to speed things up? > >  Thanks > > import MySQLdb > > import scipy > > import csv > > dbtest=MySQLdb.connect(host="***",use

[Tutor] Speed it up...

2010-05-27 Thread trias
Hi, I have wrote the following lines that work fine, but are quite slow, are there any obvious things I can consider to speed things up? Thanks import MySQLdb import scipy import csv dbtest=MySQLdb.connect(host="***",user="***",passwd="***") cursor=dbtest.cursor() cursor.execute("""SEL

Re: [Tutor] NLTK needs YAML?

2010-05-27 Thread kagebatsu
Michael Scharf-6 wrote: > > $ sudo python setup.py install > > Traceback (most recent call last): > File "setup.py", line 13, in > import nltk > File "/private/tmp/nltk-installer/nltk/__init__.py", line 92, in > > from yamltags import * > File "/private/tmp/nltk-installer/nltk/y

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
Well, that makes a lot of sense. I probably should have looked it up. :-) That said, the version with an extra line will work on python < 2.6, so I'd probably just leave it that way. But thanks the docs pointer. Always useful. That said, if I KNEW that my software was only to be implemented

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Mark Lawrence
I confess that I don't like top posting :) Please see below. On 28/05/2010 00:19, Matthew Wood wrote: #!/usr/bin/env python Here's my best attempt. I'm not sure if it's "simpler" than yours, but for me it seems a bit cleaner. Then again, I LOVE the zip operator, and the '*' operator too. :

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
#!/usr/bin/env python Here's my best attempt.  I'm not sure if it's "simpler" than yours, but for me it seems a bit cleaner.  Then again, I LOVE the zip operator, and the '*' operator too.  :-)  Whenever I see a "transpose this" type problem, I think zip. y = {'a': [1, 2, 3], 'c': [7, 8, 9], 'b

[Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread David Perlman
Using the csv.DictReader and csv.DictWriter lets you read and write lists of dictionaries from files containing tabular data. I have a system that naturally generates tabular data in the form of a dictionary of lists: the dictionary key is the name of the column, and then the value is a li

Re: [Tutor] class methods: using class vars as args?

2010-05-27 Thread Alex Hall
Thanks for all the explanations, everyone. This does make sense, and I am now using the if(arg==None): arg=self.arg idea. It only adds a couple lines, and is, if anything, more explicit than what I was doing before. On 5/27/10, Mark Lawrence wrote: > On 23/05/2010 20:40, Alex Hall wrote: >> Hello

[Tutor] Battleship grid not working how I expect

2010-05-27 Thread Alex Hall
Hi all, I very much hoped not to have to do this, but I have been staring at my code for two days and I just cannot see what is going on. http://www.gateway2somewhere.com/bs.zip has my code in it. You need wxPython to run it. speech.py has some pywin stuff, but that is only to interface with screen

Re: [Tutor] class methods: using class vars as args?

2010-05-27 Thread Mark Lawrence
On 23/05/2010 20:40, Alex Hall wrote: Hello all, I know Python reasonably well, but I still run into basic questions which those over on the other python list request I post here instead. I figure this would be one of them: Why would this not work: class c(object): def __init__(self, arg1, arg

Re: [Tutor] class methods: using class vars as args?

2010-05-27 Thread spir ☣
On Sun, 23 May 2010 15:40:13 -0400 Alex Hall wrote: > Hello all, > I know Python reasonably well, but I still run into basic questions > which those over on the other python list request I post here instead. > I figure this would be one of them: > Why would this not work: > > class c(object): >

Re: [Tutor] Recent Documents

2010-05-27 Thread David Abbott
On Thu, May 27, 2010 at 2:45 PM, John Storta Jr. wrote: > I am working on an app that runs in gnome and uses gtk.  I am extremely > new to Python.  (been working with it for all of 2 days). > > I am wanting to add a 'Recent Documents' menu option to the app.  Gnome > tracks your recent documents -

Re: [Tutor] Recent Documents

2010-05-27 Thread Joel Goldstick
On Thu, May 27, 2010 at 2:45 PM, John Storta Jr. wrote: > I am working on an app that runs in gnome and uses gtk. I am extremely > new to Python. (been working with it for all of 2 days). > > I am wanting to add a 'Recent Documents' menu option to the app. Gnome > tracks your recent documents

[Tutor] Recent Documents

2010-05-27 Thread John Storta Jr.
I am working on an app that runs in gnome and uses gtk. I am extremely new to Python. (been working with it for all of 2 days). I am wanting to add a 'Recent Documents' menu option to the app. Gnome tracks your recent documents -- apparently in a file called '.recently-used.xbel' in your home d

Re: [Tutor] PYTHON 3.1

2010-05-27 Thread wesley chun
greetings and welcome (back) to Python! i have a few comments for you: 1. The syntax for Python 3.x has changed from 2.x, so please be aware of the differences as you are learning. Most books and code out there is still 2.x. 3.x is being adopted but because of the differences, it is slower than mo

[Tutor] copy directory from one part to another and preserve permissions

2010-05-27 Thread Norman Khine
hello, i have this code: if i want to copy the 'files' directory contents and preserve permissions is this the right way to do this? import shutil path_to_old_files_dir = '/var/www/dev.site.com/htdocs/files' path_to_new_files_dir = '/var/www/site.com/htdocs/sites/default/files' shutil.rmtree(pat

Re: [Tutor] Program_to_catch_changes_in_webpage

2010-05-27 Thread Dipo Elegbede
i hope i'll one day get to this level in my programming quest. welldone all. On 5/27/10, nikunj badjatya wrote: > Hi, > >>Is it the standard Outlook Web Access(OWA) tool that >>comes with MS Exchange? > > Yes. > >>Are you trying to write a script that talks to the web >>browser to refresh the pag

Re: [Tutor] PYTHON 3.1

2010-05-27 Thread Dipo Elegbede
Sir, Under the handling files topic, trying to compile the addressbook example you gave, am I to put them all in one file and save as address book? or each is a different module is saved in different files? I have attached for your correction what I did, please let me know if it is wrong and then

Re: [Tutor] Program_to_catch_changes_in_webpage

2010-05-27 Thread nikunj badjatya
Hi, >Is it the standard Outlook Web Access(OWA) tool that >comes with MS Exchange? Yes. >Are you trying to write a script that talks to the web >browser to refresh the page? Or are you looking to monitor >the server? Yes, Talking to the web browser seems to be easiest way without notifying admi

Re: [Tutor] Program_to_catch_changes_in_webpage

2010-05-27 Thread Alan Gauld
"nikunj badjatya" I am actually using a web interface for outlook mails. * It should periodically check for any changes in that webpage . * If their is any, then notification should be sent to user. ( some dialog pop up, or some sound. ) Is it the standard Outlook Web Access(OWA) tool

[Tutor] Program_to_catch_changes_in_webpage

2010-05-27 Thread nikunj badjatya
Hi All, I am actually using a web interface for outlook mails. Pointing the link to my browser opens a page which shows me all my mails. I had to refresh it to check for a new mail. Many a times I was very late to send a reply because of it. So a thought to make a script which will automatically r