Note that there are some explanatory texts on larger screens.

plurals
  1. PONew to python, write function
    primarykey
    data
    text
    <p>I'm attempting to learn a few languages and as such I am doing the same problem on different languages. Here is my code: </p> <pre><code>def read_one_file(): with open('C:\Python27\inventory.dat', 'r') as f: invid = f.readline().strip() invtype = f.readline().strip() price = f.readline().strip() stock = f.readline().strip() title = f.readline().strip() author = f.readline().strip() published = f.readline().strip() return invid, invtype, price, stock, title, author, published def write_one_file(holdId, holdType, holdPrice, holdStock, holdTitle, holdAuthor, holdPublished): with open('C:\Python27\inventory.dat', 'w') as f: invid = holdId price = holdPrice newstock = holdStock published = holdPublished f.write("Item Id: %s\n" %invid) f.write("Item Type: %s\n" %holdType) f.write("Item Price: %s\n" %price) f.write("Number In Stock: %s\n" %newstock) f.write("Title: %s\n" %holdTitle) f.write("Author: %s\n" %holdAuthor) f.write("Published: %s\n" %holdPublished) return invid, invtype, price, stock, title, author, published = read_one_file() print "Update Number In Stock" print "----------------------" print "Item ID: ", invid print "Item Type: ", invtype print "Price: ", price print "Number In Stock: ", stock print "Title: ", title print "Author/Artist: ", author print "Published: ", published print "----------------------" print "Please Enter New Stock Number: " newstock = raw_input("&gt;") write_one_file(invid, invtype, price, newstock, title, author, published) </code></pre> <p>EDIT: I've tried using str() to convert but still doesn't run. EDIT2: I ended up changing %d to %s and seems to work. The only issue is when I run it, it tends to put book on line with 123456.</p> <p>What ends up happening in the console</p> <pre><code> Update Number In Stock ---------------------- Item ID: 123456book Item Type: 69.99 Price: 20 Number In Stock: Title: Walter_Savitch Author/Artist: 2011 Published: ---------------------- Please Enter New Stock Number: &gt; </code></pre> <p>this is the .txt file:</p> <p>123456book 69.99 20</p> <p>Walter_Savitch 2011</p> <p>something with a newline?</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.
 

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