BluShift
July 18th, 2009, 01:42 AM
Hi all. I have been just experimenting with Python (trying to extend my Python understanding) and I was playing around with integrating Zenity and Python, using a temp text file. Here's the code:
#!/usr/bin/python
import os, time
# TEST 1
raw_input("Press any key to bring up the file selection dialog")
fout=open("/home/alex/Desktop/yo.tmp", "w")
fout.write("Hi there man")
fout.close()
fin=open("/home/alex/Desktop/yo.tmp", "r")
print fin.read()
fin.close()
#TEST 2
raw_input()
os.system("zenity --file-selection>hithere.tmp")
fish=open("/home/alex/Desktop/hithere.tmp", "r")
print fish.read()
fish.close()
raw_input()
Now when TEST 1 is complete, it writes, reads, and prints the lines FLAWLESSLY. When TEST 2 finishes, it somehow inserts a newline (\n) character into the end of the line ALWAYS. I have opened the "hithere.tmp" file and there is no newline in the file. That's just how Python reads it. What is going on here? Character encoding problems?
#!/usr/bin/python
import os, time
# TEST 1
raw_input("Press any key to bring up the file selection dialog")
fout=open("/home/alex/Desktop/yo.tmp", "w")
fout.write("Hi there man")
fout.close()
fin=open("/home/alex/Desktop/yo.tmp", "r")
print fin.read()
fin.close()
#TEST 2
raw_input()
os.system("zenity --file-selection>hithere.tmp")
fish=open("/home/alex/Desktop/hithere.tmp", "r")
print fish.read()
fish.close()
raw_input()
Now when TEST 1 is complete, it writes, reads, and prints the lines FLAWLESSLY. When TEST 2 finishes, it somehow inserts a newline (\n) character into the end of the line ALWAYS. I have opened the "hithere.tmp" file and there is no newline in the file. That's just how Python reads it. What is going on here? Character encoding problems?