Home > other >  Python CSV reading & writing
Python CSV reading & writing

Time:09-24


Save me
Really be killed in a disaster to cry aloud for the first time
There is something wrong with the first question your IQ is really
This is how make haven't a clue!

CodePudding user response:

This is a English problem, provide a read_csv_header wording,

 

Def read_csv_header (csv_file) :
The import CSV
With the open (csv_file) as f:
The row=CSV. Reader (f, delimiter=', ')
Return next (row)

CodePudding user response:

reference 1/f, old coconut response:
this is an English problem, provide a read_csv_header wording,

 

Def read_csv_header (csv_file) :
The import CSV
With the open (csv_file) as f:
The row=CSV. Reader (f, delimiter=', ')
Return next (row)

delimiter=", "this is what meaning, I can understand other just don't know much about this

CodePudding user response:

refer to the second floor weixin_45736034 response:
Quote: refer to 1st floor old coconut response:
this is an English problem, provide a read_csv_header wording,

 

Def read_csv_header (csv_file) :
The import CSV
With the open (csv_file) as f:
The row=CSV. Reader (f, delimiter=', ')
Return next (row)

delimiter=", "this is what meaning, I can understand just don't know much about this other

Delimiter=", "is set delimiter as comma

CSV file field generally use a comma between, also useful TAB,

CodePudding user response:

Share one of my reading method, a great god don't smile
 
. If the request method=="POST" :
Now=datetime. Datetime. Now ()
Today=now. Strftime (" % % m - Y % d ")
The datalist=[]
Li=[
'Z:/machine01/', 'Z:/machine02/', 'Z:/machine03/', 'Z:/machine04/', 'Z:/machine05/', 'Z:/machine06/'
]
For I in li:
Datadict={}
Filename=today + 'CSV'
# to determine whether a file exists
Xx=OS. Path. The exists (I + filename)
If (xx==False) :
Pass
The else:
With the open (I + filename, 'r') as f:
# z01
Tablename="z" + STR (I [and])
# print (tablename)
Each line # traversal
For the line in f:
If the line. The startswith (', ') :
Pass
The else:
# by comma split branch data
List=line. The split (', ')
Vultime [0]=list
Opetime=list [1]
Prdate=the list [2]
Prtime=list [3]
Datadict [' vultime]=vultime
Datadict [' opetime]=opetime
Datadict [' prdate]=prdate
Datadict [' prtime]=prtime
Datadict [' machine ']=tablename
The datalist. Append (datadict)
F. lose ()
Print (datalist)

CodePudding user response:

reference 4 floor nebuung response:
share one of my reading method, a great god don't smile
 
. If the request method=="POST" :
Now=datetime. Datetime. Now ()
Today=now. Strftime (" % % m - Y % d ")
The datalist=[]
Li=[
'Z:/machine01/', 'Z:/machine02/', 'Z:/machine03/', 'Z:/machine04/', 'Z:/machine05/', 'Z:/machine06/'
]
For I in li:
Datadict={}
Filename=today + 'CSV'
# to determine whether a file exists
Xx=OS. Path. The exists (I + filename)
If (xx==False) :
Pass
The else:
With the open (I + filename, 'r') as f:
# z01
Tablename="z" + STR (I [and])
# print (tablename)
Each line # traversal
For the line in f:
If the line. The startswith (', ') :
Pass
The else:
# by comma split branch data
List=line. The split (', ')
Vultime [0]=list
Opetime=list [1]
Prdate=the list [2]
Prtime=list [3]
Datadict [' vultime]=vultime
Datadict [' opetime]=opetime
Datadict [' prdate]=prdate
Datadict [' prtime]=prtime
Datadict [' machine ']=tablename
The datalist. Append (datadict)
F. lose ()
Print (datalist)
this is which? Looking at a little be
  • Related