Write at the beginn of a File (.py)
-
@J.Hilk
I don't wish to start an argument or sound rude, but why encourage to read the whole file into memory when it's just as simple to do it line by line (at least in OP's case) as you go? Plus read-from-old-write-to-new doesn't suffer from blatting the original when the programmer makes a coding error! :) Anyway it's preference for the OP. -
-
@J-Hilk
Wehen i run your code, my .py scriptcode changed complete to only ONE Row.
-
@J-Hilk
Wehen i run your code, my .py scriptcode changed complete to only ONE Row.
@NotYourFan
the example is not checked, I don't have a +py file for that.Obviously you need to add a new line character at the end of each line.
if( i == 5) wstream << "test = 'TestFile.csv' " << "\n"; wstream << v.at(i) << "\n";;
-
This post is deleted!
-
@J-Hilk
now it works the problem is when i changed the wstram it doesent override.i get " test = 'Hallo221.csv' test = 'Hallo1.csv' ...."
how i can override?
thx
-
@J-Hilk
now it works the problem is when i changed the wstram it doesent override.i get " test = 'Hallo221.csv' test = 'Hallo1.csv' ...."
how i can override?
thx
@NotYourFan
What does "override" mean? Do you mean "overwrite" what is already inwstream
? Do you meanwstream.seek(0)
? -
yeah sry,
i mean "overwrite".
i always get " test = 'Hallo221.csv' test = 'Hallo1.csv' test = 'Hallo12321.csv' .....
but i want to get only "test = 'Hallo12321.csv' so i want to "overwrite" the line 5 and not add a new string
-
yeah sry,
i mean "overwrite".
i always get " test = 'Hallo221.csv' test = 'Hallo1.csv' test = 'Hallo12321.csv' .....
but i want to get only "test = 'Hallo12321.csv' so i want to "overwrite" the line 5 and not add a new string
@NotYourFan
So did you try mywstream.seek(0)?
after the first write and before the second?
Or, depending on just what you intend by "overwrite", you may need towstream.resize(0)
.
Try with both"first-string-is-long"
,"second-is-short"
and then with"first-is-short"
,"second-string-is-long"
to see the difference betweenseek(0)
vsresize(0)
. -
yeah sry,
i mean "overwrite".
i always get " test = 'Hallo221.csv' test = 'Hallo1.csv' test = 'Hallo12321.csv' .....
but i want to get only "test = 'Hallo12321.csv' so i want to "overwrite" the line 5 and not add a new string
You're doing fishy stuff, that may break at any point.
You should rethink what you're actually trying to do.for(int i(0); i < v.size(); i++){ if( i == 5) { wstream << "test = 'TestFile.csv' " << "\n"; if(v.at(i).contains("test = '")) continue; } wstream << v.at(i) << "\n"; }
-
You're doing fishy stuff, that may break at any point.
You should rethink what you're actually trying to do.for(int i(0); i < v.size(); i++){ if( i == 5) { wstream << "test = 'TestFile.csv' " << "\n"; if(v.at(i).contains("test = '")) continue; } wstream << v.at(i) << "\n"; }
@J.Hilk
PERFEKT !!!!!
THANK YOU SO MUTCH