Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I write to a file using a terminal command in python?
    primarykey
    data
    text
    <p>I am learning to code, Im very new. I have written a few scripts, and would like to combine them into a single script. I am essentially trying to take the "look ." command from terminal, input it into a text file, and then open that text file to begin manipulating the words inside of it. </p> <p>I have tried many different variations:</p> <pre><code>print "What file do you want to create? " file_in = raw_input("&gt;") file_in = open(file_in, 'w') new_file = os.system("look .") file_in.write(new_file) </code></pre> <p>This results in:</p> <pre><code>Traceback (most recent call last): File "hash.py", line 13, in &lt;module&gt; file_in.write(new_file) TypeError: expected a character buffer object </code></pre> <p>After all of the words are printed to screen.</p> <p>I have also tried this:</p> <pre><code>print "What file do you want to create? " file_in = raw_input("&gt;") new_file = os.system("look . &gt; "+file_in+".txt") ##This is attempting to open the file to make each word capital in the list, the list is made at this point capital_words=open(new_file, 'w') </code></pre> <p>But this results in: </p> <pre><code>capital_words = open(new_file, 'w') TypeError: coercing to Unicode: need string or buffer, int found </code></pre> <p>I have tried converting the capital_words to str. But it simply will not let me do this. I can make the list using a script, and I can open an existing list and capitalize each word (which is what I am intending to do here) using a separate script, but I get this problem when I combine them. </p> <p>Any help is appreciated.</p> <p>(I know this doesnt have any practical application, Im just trying to learn the basics of programming)</p>
    singulars
    1. This table or related slice is empty.
    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