Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with opening files in python
    primarykey
    data
    text
    <p>I was trying to write a program where I can upload a file that has first and last names in it and create a new file with the first letter of each first name followed by the last name.</p> <p>The file that I created is a textfile and the lines would be like this:</p> <pre><code>firstname1 lastname1 (for example, john smith) firstname2 lastname2 (for example jane jones) firstname 3 lastname3 (for example jane doe) etc... </code></pre> <p>I want to create a file that would look like this:</p> <pre><code>jsmith jjones jdoe </code></pre> <p>The issue that I am getting is that when I open the file in python it gives me all of these weird unwanted characters before getting to the actual text of the file. The book I am using to learn from doesn't say anything about this which is why i am posting here. </p> <p>For example when I upload the file and run the following command:</p> <pre><code>newfile=open("example.file.rtf","r") for i in newfile: print(i) </code></pre> <p>I get this: </p> <pre><code>{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \margl1440\margr1440\vieww9000\viewh8400\viewkind0 \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural \f0\fs24 \cf0 name 1\ name 2\ name 3 \ name 4 \ </code></pre> <p>The actual text that I wrote in the textfile was just this:</p> <pre><code>name 1 name 2 name 3 name 4 </code></pre> <p>Why is this happening? Why wouldn't it just show the plain text? If I can't get it to do that, how can I get around this issue for when I run loops through the file. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload