About 50 results
Open links in new tab
  1. python - How to read a file line-by-line into a list? - Stack Overflow

    How do I read every line of a file in Python and store each line as an element in a list? I want to read the file line by line and append each line to the end of the list.

  2. python - How to read specific lines from a file (by line number ...

    I'm using a for loop to read a file, but I only want to read specific lines, say line #26 and #30. Is there any built-in feature to achieve this?

  3. How should I read a file line-by-line in Python? - Stack Overflow

    Jul 19, 2012 · This is a subjective question about API design, so I have a subjective answer in two parts. On a gut level, this feels wrong, because it makes iterator protocol do two separate things—iterate …

  4. Python: How to properly use readline () and readlines ()

    Dec 25, 2018 · 2 If you are using readline() function, you have to remember that this function only returns a line, so you have to use a loop to go through all of the lines in the text files. In case of using …

  5. Iterating over lines in a file python - Stack Overflow

    Jul 28, 2015 · for line in contents.splitlines(): # do something Or you can read in the contents as a list of lines by iterating the file object itself (or by using readlines()).

  6. Is there a shortcut to comment multiple lines in python using VS Code ...

    Sep 26, 2022 · Instead of indivually typing out a hash tag in front of each line, is there a way to select a block of code and comment/uncomment everything by only pressing a couple shortcut keys?

  7. python - How do I split a multi-line string into multiple lines ...

    How do I split a multi-line string into multiple lines? Asked 17 years, 4 months ago Modified 2 years, 6 months ago Viewed 573k times

  8. How do I create multiline comments in Python? - Stack Overflow

    111 Python does have a multiline string/comment syntax in the sense that unless used as docstrings, multiline strings generate no bytecode -- just like # -prepended comments. In effect, it acts exactly …

  9. python - How to run a few selected lines of code in vscode? - Stack ...

    Dec 21, 2019 · Select one or more lines, then press Shift+Enter or right-click and select Run Selection/Line in Python Terminal. This command is convenient for testing just a part of a file.

  10. How can I do a line break (line continuation) in Python (split up a ...

    321 From PEP 8 -- Style Guide for Python Code: The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be …