python - Csv Writer - Trying to write variable in each Column -


I am trying to write some data in a CSV file but I can not select different columns.

  car = ["car 11"] expired = ["Landhaus, Nord"] Time = ["['05: 36 ']", [['06: 06'] "," [ '['08: 36'] "," ['08: 36 '] "," ['08: 36'] "," ['08: 36 '], "['08: 36']," ['07: 36 '], '' ['9: 36'] ", '[' 10: 06 ']", [' 10: 36 '] "," ['11: 06'] "," ['13: 06'] ", '[' 13: 36 ']",' ['13: 36'], '[' 12: 36 '],' ['12: 36'] ", '[' ['14: 06'] ", '['14: 36']", "['15: 06 ']," ['15: 36'] "," ['16: 06'] "," ['18: 36'] ", '[' 17: 36 ']," [' 17: 36 '], "[' 18: 06 ']," [' 18: 36 '] "," ['19: 06'] "," ['19: 36'] "," ['20: 06 '] ", [' 20: 36 ']"] 
Myfile = Open ("Informationen.csv", "wb") Authors = Csv.writer (myfile, dialect = 'excel', delimiter = '') bla = [car, finish, time] writer.writerow (bla)

output:

  11 Landhos, Nord "['05: 36 ']", [[066: 06'] ", [..]   

All in line 1 And Colum 1

but I like it

  car 11 (Colum 1 in 1 line1). "Landhaus, Nord" (in line 1 column 2). ['05: 36 '] (in line 1 column 3). << Code>  

Thanks for any help!

Edit
and how it should look like, for example Line 1: Car 11 (Column 1) Landhos, Nord (column 2) ['05: 36 '] (column 3) [' 05: 36 '] (column 4) [...] Example

Solution yet: But problems with time list still

  car = ["car 11 "[['06: 06 ']", "['06: 36']", "[['06: 36 ']]" [ '['08: 36'] ',' ['08: 36 '] "," [' 9: 06 ']', '['07: 06'] ", '['07: 36'] '['08: 06'] ' 9: 36]], "['10: 06'] '[' 10: 36 ']", [[11: 06'] ", [[11: 36]]," ['12] : '[' 13: 36 '] ",' ['13: 36']," ['13: 36'], "['14: 06 ']," ['14: 36] '' ['15: 06 ']' ['15: 36 '] ", [[16: 06']", "['16: 36']", "['17: 06'] "," ['17: 36'] ['18: 06'], "['18: 36']", [[19: 06 '] "," [' 19: 36 '] "," [' Myfile = open ("Informationen2.csv", "wb") Author = csv.writer (myfile, delimiter = '') bla = car + trenn + (20: 36 '] "," [' 20: 36 '] "] Finish + trenn + time author. Author (bla) myfile.close ()    

For the states, the csv.writer () function ...

"optional bid parameter can be used for any state Specific CSV bid is used to define the set of specific parameters. "

... and that ...

Other optional fmtparams keyword logic Individual formatting parameters can be overridden in the current format. The problem you are experiencing is the result of writing a file to write the string presentation of the time list and using the white space delimiter. If you had to look at Informationen.csv as a plain text file, the problem becomes clear

First of all, write a whitespace delimiter to Csv.writer (myfile, dialect = 'excel', delimiter = '') is given in the form of arguments as the default delimiter overrides as defined in the excel bid and bla Contrary to the element1, element2, element3 resulting in elements in the list, file with element1 element2 element3 Is being written .

However, most elements in the time list allocate their own columns in the desired form in a spreadsheet, writing the list as string representation itself. Has contributed to the complete unwanted formatting.

When you open a file created with Excel as your Excel file, Excel reads two initial values ​​based on the first two comma which it finds string 'Landhaus, Nord Within the representation of the string of the "center of and the time list.

You can obtain column segregation, which you need before by adding it to the time list in the time list as before, Nostalgia is in opposition to the latter. After this you have to leave the delimiter = '' csv.writer (myfile, dialect = 'excel', delimiter = '') , thus delimiting override effects while typing To avoid the file:

  import CSV car = ['car 11'] over = ['landhos, Nord'] time = ["['05: 36 ']", " ['06: 06 '] "," ['06: 36'] "," ['07: 06 '] "," ['07: 36'] "] Try: with open ('Informationen.csv ',' W ') as myfile: Author = csv.writer (myfile, dialect =' excel ') bla = [car, finish] for each time in time: bla.append (every_time) writer.writerow (bla ) Except for IOError io: Production of the following product in Excel:  



Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

c# - Add Image in a stackpanel based on textbox input -

java - Reaching JTextField in a DocumentListener -