Python DictWriter header - not writing in first line of existing file
Hello
I am facing a very unique problem and not able to understand why. I have written a function which will check header of the file. If header is present good else it will write the header on top
So both in dictwriter and doing seek(0) and normal writing it is writing on the last line before other lines are written. If the file does not exist (except block) header is written at the top without an issue. But if the file exist but header is not present - then it is writing after the existing data
The above code screws up the whole writing to csv file also. It looks like it randomly deletes line or override or write from top
This one doesn't override while writing new data. But header row is written at the last line
---------- Post updated at 08:54 AM ---------- Previous update was at 12:43 AM ----------
Closing the thread : Solution as below
When calling the function it looks like it writes to the last line always
So in place replacement is not possible - we have to create temp file and swap it back
Last edited by radioactive9; 06-27-2017 at 05:21 AM..
I created python code that produce output in the form of:
moses-red-sea=1.00.03
genesis-snake=2.03
deliverance=5.0.010
I need to take this output and create a "C" header file and have it look like this:
struct {
char *name;
char *fixed_version;
} filename_versions... (7 Replies)
hello ..
I am new to perl scripting, I have a text file, and would like to insert 3 new lines into the same file at different line numbers using perl scripting. Any Help regarding this will be very useful.
say the file is sample.txt, contents are
aaaaa
bbbb
ccccc
dddd
eeeee
ffffffff... (4 Replies)
hello mates,
this is my first post. please help me out. i have got a file with some data in it. i am asked to write the timestamp as a header for that file. i mean the time the file created should be mentioned at the top of the file. i know we can use sed to insert a sentence but... (6 Replies)
Hi,
I have two text files. Need to create a third text file extracting specific data from first two existing files..
Text File 1: Format contains:
SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010
some text ............so on...and somwhere text like:
Record 1:... (1 Reply)
i have a file called motors with 3 columns separated with tabs eg:
car make reg
i want to create a executable file that will add a line with data eg:
car make reg
benz s600 t35778
can you please show me how to do this? (7 Replies)
Dear All,
I need to add a header of one line to an already existing file.
I know that it can be achieved by the following:
echo "Header" > newfile
cat file1 >> newfile
But my problem is that file is huge and there is no space for creating a new file every time. Is there a way that I can... (5 Replies)
Hi,
I need some help in removing the header (first line) and the trailer (last line) in a give file...
The data file actually comes in EBCDIC format and I converted it into ASCII..
Now I need to strip off the first line and the last line..
I think we can use sed to do something like this:... (2 Replies)
Hello..
I have a text file with 100 lines of data.
I need to add 1 line of data to that already existing file at the first line( beginning of the file) , so that the already existing 100 lines will start from 2 nd line.Now the file will have 101 lines of data.
Help me on how to add the line... (4 Replies)
Hi all,
I need to know what command/s I can use to print lines from a file. I cannot do pattern matching, so grepping for a string is not possible. I'd like to say "print line 3" etc. Any ideas? Ta. (2 Replies)