Re: [Tutor] Sequences of letter

2010-04-12 Thread Rich Lovely
On 13 April 2010 01:07, Alan Gauld wrote: > > "Steven D'Aprano" wrote > > import itertools > for x in itertools.product('abc', 'abc', 'abc'): >> >> If you don't like the repeated 'abc' in the call to product(), it can be >> written as itertools.product(*['ab']*3) instead. > > Nope, I thin

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Alan Gauld
"Dotan Cohen" wrote I use this one-liner for moving photos nested a single folder deep into the top-level folder: find * -name "*.jpg" | awk -F/ '{print "mv "$0,$1"-"$2}' | sh You could miss out the awk and use the exec option of find... Or miss out the shell and use the system() function

Re: [Tutor] Sequences of letter

2010-04-12 Thread Alan Gauld
"Steven D'Aprano" wrote import itertools for x in itertools.product('abc', 'abc', 'abc'): If you don't like the repeated 'abc' in the call to product(), it can be written as itertools.product(*['ab']*3) instead. Nope, I think the repeated string is much clearer, and thus better, than the c

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Sander Sweers
On 12 April 2010 22:13, Dave Angel wrote: > When combining directory paths, it's generally safer to use > > os.path.join() As KDE/Dolphin runs on windows this is even more important as it will sort out the directory separator (/ vs \) for you. Some added reading on os.path can be found on Doug's

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Dave Angel
Dotan Cohen wrote: All right, I have gotten quite a bit closer, but Python is now complaining about the directory not being empty: ✈dcl:test$ cat moveUp.py #!/usr/bin/python # -*- coding: utf-8 -*- import os currentDir =s.getcwd() filesList =s.walk(currentDir) for root, folder, file in filesL

Re: [Tutor] accessing Postgres db results by column name

2010-04-12 Thread Serdar Tumgoren
> Wanted to send along one more update about this topic. Steve Orr pointed > out in a comment on Ricardo's new recipe that there's yet another way to get > named attribute access to cursor results. > I should add the disclaimer that namedtuple is only available in Python 2.6+ _

Re: [Tutor] accessing Postgres db results by column name

2010-04-12 Thread Serdar Tumgoren
Hey folks, Wanted to send along one more update about this topic. Steve Orr pointed out in a comment on Ricardo's new recipe that there's yet another way to get named attribute access to cursor results. The secret sauce is namedtuple, "high performance" collection type. This appears to be the "c

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Dave Angel
Dotan Cohen wrote: On 12 April 2010 20:12, Sander Sweers wrote: On 12 April 2010 18:28, Dotan Cohen wrote: However, it fails like this: $ ./moveUp.py Traceback (most recent call last): File "./moveUp.py", line 8, in os.rename(f, currentDir) TypeError: coercing to Unicode: need st

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Wayne Werner
On Mon, Apr 12, 2010 at 1:21 PM, Dotan Cohen wrote: > All right, I have gotten quite a bit closer, but Python is now > complaining about the directory not being empty: > > ✈dcl:test$ cat moveUp.py > #!/usr/bin/python > # -*- coding: utf-8 -*- > import os > currentDir = os.getcwd() > > filesList =

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Dotan Cohen
All right, I have gotten quite a bit closer, but Python is now complaining about the directory not being empty: ✈dcl:test$ cat moveUp.py #!/usr/bin/python # -*- coding: utf-8 -*- import os currentDir = os.getcwd() filesList = os.walk(currentDir) for root, folder, file in filesList: for f in f

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Dotan Cohen
On 12 April 2010 20:12, Sander Sweers wrote: > On 12 April 2010 18:28, Dotan Cohen wrote: >> However, it fails like this: >> $ ./moveUp.py >> Traceback (most recent call last): >>  File "./moveUp.py", line 8, in >>    os.rename(f, currentDir) >> TypeError: coercing to Unicode: need string or buf

Re: [Tutor] Sequences of letter

2010-04-12 Thread Steven D'Aprano
On Tue, 13 Apr 2010 02:46:39 am Dave Angel wrote: > Or more readably: > > from string import lowercase as letters > for c1 in letters: > for c2 in letters: > for c3 in letters: > print c1+c2+c3 Here's another solution, for those using Python 2.6 or better: >>> impo

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Sander Sweers
On 12 April 2010 18:28, Dotan Cohen wrote: > However, it fails like this: > $ ./moveUp.py > Traceback (most recent call last): >  File "./moveUp.py", line 8, in >    os.rename(f, currentDir) > TypeError: coercing to Unicode: need string or buffer, tuple found os.rename needs the oldname and the

Re: [Tutor] Sequences of letter

2010-04-12 Thread Dave Angel
Or more readably: from string import lowercase as letters for c1 in letters: for c2 in letters: for c3 in letters: print c1+c2+c3 Yashwin Kanchan wrote: Hi Juan Hope you have got the correct picture now... I just wanted to show you another way of doing the above th

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Dotan Cohen
I'm really stuck here. I need move all files in subdirectories of cwd to cwd. So that, for instance, if we are in ~/photos then this file: ~/photos/a/b/file with space.jpg ...will move to this location: ~/photos/file with space.jpg This is what I've come up with: #!/usr/bin/python # -*- coding: u

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Dotan Cohen
> "Lovely"??? What on earth does it do? It's worse than Perl code!!! > *half a wink* > Like a good wife, it does what I need even if it is not pretty on the eyes. _That_ is lovely! (I can get away with that, I'm married to a redhead.) > See the shell utilities module: > > import shutil > It ove

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Steven D'Aprano
On Tue, 13 Apr 2010 12:11:30 am Dotan Cohen wrote: > I use this one-liner for moving photos nested a single folder deep > into the top-level folder: > find * -name "*.jpg" | awk -F/ '{print "mv "$0,$1"-"$2}' | sh > > I would like to expand this into an application that handles > arbitrary nesting

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Dotan Cohen
On 12 April 2010 17:23, Serdar Tumgoren wrote: >  What fine manual should I be reading? I am not asking for >> >> code, rather just a link to the right documentation. > > You'll definitely want to explore the os module, part of Python's built-in > standard library. > > http://docs.python.org/libra

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Serdar Tumgoren
What fine manual should I be reading? I am not asking for > code, rather just a link to the right documentation. > You'll definitely want to explore the os module, part of Python's built-in standard library. http://docs.python.org/library/os.html http://docs.python.org/library/os.html#files-and

[Tutor] Move all files to top-level directory

2010-04-12 Thread Dotan Cohen
I use this one-liner for moving photos nested a single folder deep into the top-level folder: find * -name "*.jpg" | awk -F/ '{print "mv "$0,$1"-"$2}' | sh I would like to expand this into an application that handles arbitrary nesting and smart rename, so I figure that Python is the language that

Re: [Tutor] Sequences of letter

2010-04-12 Thread Yashwin Kanchan
Hi Juan Hope you have got the correct picture now... I just wanted to show you another way of doing the above thing in just 4 lines. for i in range(65,91): for j in range(65,91): for k in range(65,91): print chr(i)+chr(j)+chr(k), On 12 April 2010 06:12, Juan Jose Del Toro wrote: > Dear List;

Re: [Tutor] Sequences of letter

2010-04-12 Thread spir ☣
On Mon, 12 Apr 2010 00:12:59 -0500 Juan Jose Del Toro wrote: > Dear List; > > I have embarked myself into learning Python, I have no programming > background other than some Shell scripts and modifying some programs in > Basic and PHP, but now I want to be able to program. > > I have been readi

Re: [Tutor] Sequences of letter

2010-04-12 Thread Alan Gauld
"Juan Jose Del Toro" wrote So far this is what I have: letras = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","z"] Because a string is a sequence of letters you could have saved some typing by just doing: letras = "abcdefghijklmnopqrstuvwxyz"

Re: [Tutor] Sequences of letter

2010-04-12 Thread Stefan Behnel
Juan Jose Del Toro, 12.04.2010 07:12: I wan to write a program that could print out the suquence of letters from "aaa" all the way to "zzz" like this: aaa aab aac ... zzx zzy zzz So far this is what I have: letras = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t