| | |
Writing to MS Word.. Help?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Why don't either of these implementations actually write to the file?
Code v1:
Code v2:
Also, I could use some further help.
Here's what I want each page to look like (note the big font size of the SKUs relative to the page size, and the spacing):
I don't know how to make the font-size huge, or to achieve this spacing through Python code. Nor do I know how to create page breaks. If someone could help me with this that'd be great!
I'm also interested in knowing how to change fonts, and text colors (although it's not necessary for this project).
Additionally, if anyone knows of a good tutorial on writing to files, that'd be greatly appreciated!
Code v1:
Python Syntax (Toggle Plain Text)
txtfile = open('C:/Python31/SKUs.txt', 'w') with txtfile: num = 817 while num <= 820: x = "G" + str(num) print(str(x), end=" ") num += 1 txtfile.close()
Code v2:
Python Syntax (Toggle Plain Text)
txtfile = open('C:/Python31/SKUs.txt', 'w') num = 817 while num <= 820: x = "G" + str(num) print(str(x), end=" ", file = txtfile) num += 1 print("test", file = txtfile) txtfile.close()
Also, I could use some further help.
Here's what I want each page to look like (note the big font size of the SKUs relative to the page size, and the spacing):
Python Syntax (Toggle Plain Text)
----------------------------- | G817 G818 G819 | | | <-- page 1 | | | | |___________________________|
Python Syntax (Toggle Plain Text)
----------------------------- | G817 G818 G819 | | | <-- page 2 | | (and so on, until G10000) | | |___________________________|
I don't know how to make the font-size huge, or to achieve this spacing through Python code. Nor do I know how to create page breaks. If someone could help me with this that'd be great!
I'm also interested in knowing how to change fonts, and text colors (although it's not necessary for this project).
Additionally, if anyone knows of a good tutorial on writing to files, that'd be greatly appreciated!
Last edited by SuperMetroid; Aug 9th, 2009 at 3:55 pm.
Okay, I changed it to the following, but when I run it and open the file, the document is still blank.
Python Syntax (Toggle Plain Text)
txtfile = open('C:/Python31/SKUs.txt', 'w') with txtfile: num = 817 while num <= 820: x = "G" + str(num) txtfile.write(x) num += 1 txtfile.close()
Last edited by SuperMetroid; Aug 9th, 2009 at 4:04 pm.
•
•
•
•
Okay, I changed it to the following, but when I run it and open the file, the document is still blank.
Python Syntax (Toggle Plain Text)
txtfile = open('C:/Python31/SKUs.txt', 'w') with txtfile: num = 817 while num <= 820: x = "G" + str(num) txtfile.write(x) num += 1 txtfile.close()
This shouldn't make a difference but the proper way to use the with statement is like so:
Notice I omit closing the file. That's because the
python Syntax (Toggle Plain Text)
with open('C:/Python31/SKUs.txt', 'w') as txtfile: num = 817 while num <= 820: x = "G" + str(num) txtfile.write(x) num += 1
with syntax automatically closes the file handle. AFter that loop you can test with txtfile.closed , which should return True because it's closed. ![]() |
Similar Threads
- Time complexity of algorithm (Computer Science)
- Case-sensitivity in word count program (Java)
- Word macro to open and Excel spreadsheet needed (Visual Basic 4 / 5 / 6)
- Word turn blue in a textBox (C++)
- Hardware Interrupts & 100% CPU usage (Windows NT / 2000 / XP)
- 1st year CS student question regarding a word search puzzle (Java)
- I Need Help Writing A Word Count Program In My Python (Python)
- Bios,display,pixels problems (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: finding/returning lowest/highest int in lists, in a tuple
- Next Thread: Using a Library e.g. chilkat
Views: 330 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Python
approximation array beginner book builtin change cipher clear client code color converter countpasswordentry cturtle curved def dictionary drive dynamic examples excel file float format ftp function gui homework import inches input java library line lines linux list lists loop microcontroller mouse mysqldb mysqlquery newb number numbers output parsing path plugin port prime program programming projects py2exe pygame pymailer pyqt python random recursion recursive redirect remote script scrolledtext search singleton socket sqlite ssh string strings strip subprocess sum syntax table terminal text textarea thread threading time tkinter tlapse tuple tutorial twoup ubuntu unicode urllib urllib2 variable vigenere wikipedia windows wxpython xlwt






