Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Failing at python

Name: Anonymous 2010-01-27 7:24

All I want to do is read all the lines from a file and put them into a list. This is all. I am failing rather hard. Halp? I'm trying to read each line with a for loop and put them into a list but I can't get it to work.

Name: Anonymous 2010-01-27 7:25

Read SICP. The forced indentation of code. Thread over. My other car is a cdr. Hax my anus

Name: Anonymous 2010-01-27 7:52

(define (file->list file)
    (call-with-input-file file
      (lambda (in)
         (let loop ((collect (list)))
            (let ((line (read-line in)))
               (if (eof-object? line)
                   (reverse collect)
                   (loop (cons line collect)))))))

Name: Anonymous 2010-01-27 8:19

Name: Anonymous 2010-01-27 8:47

>>4
I know what the things are but I'm not sure how to implement it.

Name: Anonymous 2010-01-27 9:24

ITT: /prouge/ codes for you

Name: Anonymous 2010-01-27 9:27

Try a real scripting language:


<?php
$list = file($filename, FILE_IGNORE_NEW_LINES);
?>

Name: Anonymous 2010-01-27 9:31

>>5
Yes, because you're trying to program in Python, but 'implementing' a single function call is beyond your capability. I'll believe that.

Name: Anonymous 2010-01-27 9:45

>>5
Oh, you really need it at all written for you?

file = open('file.txt', 'read').read()
lines = file.readlines().splitlines()

Name: Anonymous 2010-01-27 10:03

>>9
Did you mean lines = open('file.txt','r').readlines()

Name: Anonymous 2010-01-27 10:09

Use Perl with Tie::File.

Name: Anonymous 2010-01-27 10:22

>>9
I just keep getting errors like 'AttributeError: 'str' object has no attribute 'readlines' for some reason

Name: Anonymous 2010-01-27 10:50

in perl:

my(@lines)=<>;

Name: Anonymous 2010-01-27 13:06

>>13
What's with all the extra characters?
Did you mean:
@l=<>

Name: Anonymous 2010-01-27 13:48

>>14
GOLF MY ANUS

Name: Anonymous 2010-01-27 17:04

Anyone who knows perl should be ashamed of themselves.

Name: Anonymous 2010-01-27 17:54

>>16
use English; before you write anything next time.

Name: Anonymous 2010-01-28 0:45


(defun read-all-strings (file) 
  (loop
     for line = (read-line file nil :eof) 
     while (not (eql line :eof))
     collect line))

Name: Anonymous 2010-11-26 12:11

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List