Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson
On 08/05/2013 10:19 PM, MRAB wrote: On 06/08/2013 03:00, Devyn Collier Johnson wrote: I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume this command does not accept newline characters. file = open('/home/collier

Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson
On 08/05/2013 10:19 PM, MRAB wrote: On 06/08/2013 03:00, Devyn Collier Johnson wrote: I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume this command does not accept newline characters. file = open('/home/collier

Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson
On 08/05/2013 11:49 PM, alex23 wrote: On 6/08/2013 1:12 PM, Joshua Landau wrote: Because it's bad to open files without a with unless you know what you're doing, use a with: with open('/home/collier/pytest/__sort.TXT') as file: sorted(file, key=str.casefold, reverse=True)

Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson
On 08/05/2013 11:12 PM, Joshua Landau wrote: On 6 August 2013 03:00, Devyn Collier Johnson devyncjohn...@gmail.com mailto:devyncjohn...@gmail.com wrote: I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume

Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Chris Angelico
On Tue, Aug 6, 2013 at 11:38 AM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: with open('/home/collier/pytest/sort.TXT') as file: sorted(file, key=str.casefold, reverse=True) Thanks for the advice Joshua. I find these tips very useful. However, how would I close the

Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Joshua Landau
On 6 August 2013 11:52, Chris Angelico ros...@gmail.com wrote: On Tue, Aug 6, 2013 at 11:38 AM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: with open('/home/collier/pytest/sort.TXT') as file: sorted(file, key=str.casefold, reverse=True) Thanks for the advice Joshua. I

Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson
On 08/06/2013 06:52 AM, Chris Angelico wrote: On Tue, Aug 6, 2013 at 11:38 AM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: with open('/home/collier/pytest/sort.TXT') as file: sorted(file, key=str.casefold, reverse=True) Thanks for the advice Joshua. I find these tips

Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Chris Angelico
On Tue, Aug 6, 2013 at 12:44 PM, Joshua Landau jos...@landau.ws wrote: On 6 August 2013 11:52, Chris Angelico ros...@gmail.com wrote: On Tue, Aug 6, 2013 at 11:38 AM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: with open('/home/collier/pytest/sort.TXT') as file:

Sort lines in a plain text file alphanumerically

2013-08-05 Thread Devyn Collier Johnson
I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume this command does not accept newline characters. file = open('/home/collier/pytest/sort.TXT', 'r').read() print(file) z c w r h s d file.sort() #The first blank line

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread MRAB
On 06/08/2013 03:00, Devyn Collier Johnson wrote: I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume this command does not accept newline characters. file = open('/home/collier/pytest/sort.TXT', 'r').read

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread Joshua Landau
On 6 August 2013 03:00, Devyn Collier Johnson devyncjohn...@gmail.comwrote: I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume this command does not accept newline characters. HINT #1: Don't assume that without a reason

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread edu4madh
On Monday, August 5, 2013 10:00:55 PM UTC-4, Devyn Collier Johnson wrote: I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume this command does not accept newline characters. file = open('/home/collier

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23
On 6/08/2013 1:12 PM, Joshua Landau wrote: Because it's bad to open files without a with unless you know what you're doing, use a with: with open('/home/collier/pytest/__sort.TXT') as file: sorted(file, key=str.casefold, reverse=True) Shouldn't that be: with

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23
On 6/08/2013 1:49 PM, alex23 wrote: Shouldn't that be: with open('/home/collier/pytest/__sort.TXT') as file: data = file.readlines() sorted(data, key=str.casefold, reverse=True) I'm tempted to say HINT #5: don't provide a solution without testing it first but that would

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23
On 6/08/2013 1:49 PM, alex23 wrote: On 6/08/2013 1:12 PM, Joshua Landau wrote: Because it's bad to open files without a with unless you know what you're doing, use a with: with open('/home/collier/pytest/__sort.TXT') as file: sorted(file, key=str.casefold, reverse=True)