By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

Writing table contents into a Text file

P: 21
Hi All,
I have stored contents of a table as a variable as shown below:
partner_table = get_table("//table.1.1")

Now i need to write the contents of "partner_table" into a TEXT file.
There is should be some way, does it require file.open command!!

Hoping to hear from you soon.

Cheers
ideal
Jan 21 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 303
Something like the following should work for you.
Expand|Select|Wrap|Line Numbers
  1. # Create new file called 'filename.txt' at a specified path.
  2. my_file = File.new("path/filename.txt","w")
  3. # Write text to the file.
  4. my_file.write "text to be written to file"
  5. # Close the file.
  6. my_file.close
Jan 21 '08 #2

P: 21
Thanks for Code, it works fine :)
I have one more stuff to go with writing the text files,
My present output looks like this:

Upload Result\n filename status #Rows Quantity #Ignored #Deleted #Modified Messages FISCAL-CALENDAR.xls Loaded 140 0 0 0 0 On Hold 0 0 0 0 0

I rather like to see new line after each sentence, what should i do for that? Is there a way i can say to insert new line character after each sentence!
something like this-

Upload Result
filename status
#Rows Quantity
#Ignored

Cheers
Jan 22 '08 #3

Expert 100+
P: 303
Use "\n" for a new line. Make sure its in double quotes, not single quotes. Using double quotes will output a new line, using single quotes will output the text \n.
Expand|Select|Wrap|Line Numbers
  1. my_file.write @table_cell.to_s + "\n"
Jan 22 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.