Friday, April 26, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 5319  / 1 Year ago, thu, november 17, 2022, 4:48:07

I am writing a program where you have to extract bits of text from a text file. The specific bit of text is the save directory where I would like to save the files produced by my program. Here is my code:



    file = open("datafile.txt", "r")
SaveDir = file.read()
print SaveDir


That seems to be working properly, the output is exactly as it should be, "/home/marc/QuickJotProgram/QuickJotTexts
"



Please note that the program skips a line before the end quote which is my problem



It's not a problem until later in the program where I use the SaveDir variable:



text_file = open(os.path.join(SaveDir, title), "w")


The error message is:



text_file = open(os.path.join(SaveDir, title), "w")
IOError: [Errno 2] No such file or directory: '/home/marc/QuickJotProgram/QuickJotTexts
/file'


The only thing that should not be there is the "
" I just need to get rid of that, and the program will run smoothly.



Thanks ubuntu :)


More From » python

 Answers
0

Removing
from a string:



newString = oldString.replace("
", "");

[#24659] Saturday, November 19, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iriousutur

Total Points: 321
Total Questions: 112
Total Answers: 106

Location: Sweden
Member since Mon, Dec 7, 2020
3 Years ago
iriousutur questions
Sun, Apr 9, 23, 02:48, 1 Year ago
Tue, May 23, 23, 00:41, 1 Year ago
Fri, Oct 21, 22, 02:47, 2 Years ago
Mon, May 9, 22, 00:01, 2 Years ago
;