Jun-11-2019, 02:30 AM
So, first, here is the code:
What it is supposed to do is take the content of a cell in column 1 (or "0" if you prefer), open a file with those cell contents as the filename, then input the content of row 3 into the file and save/close the file in the script directory.
There is a bit of "bug" tracking I put in so I can see if it is actually running - and it outputs to the screen. That output looks like this:
If I run it in IDLE - it generates the output and the 13 files:
If I double click or run it in CMD or run it in python within the CMD window (with the prompt) it generates the print output - including the last path line - but no files. As you can likely tell from the imports and odd shebang I have played with it a good bit. I should also add I am/was a py2 user and am now a py3 user (or trying to be). It's as if it is putting the new files someplace else and I cannot find them. Or somehow running without closing them or throwing an error.
Appreciate any thoughts. Hope I was clear - first post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!python3 C:\Users\Chris\AppData\Local\Programs\Python\Python37-32 import csv import os import time import os.path x = 0 f = open ( 'filename.csv' , 'r' ) csv_f = csv.reader(f) for row in csv_f: #following is a counter as a bug solver x = x + 1 print (x) #this creates the file and names it the contents of the first column or whatever column you change it to file = open (row[ 0 ] + ".txt" , "w" ) #this writes the content from the second column or whatever column you change it to. file .write(row[ 2 ]) file .close() #following is my attempt to figure out if files are being closed in the right directory print ( 'Stored in' , os.path.dirname(os.path.abspath( file .name))) |
There is a bit of "bug" tracking I put in so I can see if it is actually running - and it outputs to the screen. That output looks like this:
Quote:1
2
3
4
5
6
7
8
9
10
11
12
13
Stored in C:\Users\Chris\Desktop\GELOE\Excel Test
If I run it in IDLE - it generates the output and the 13 files:
Quote:.txt 6/10/2019 6:39:42 PM
Aton archive.txt 1 KB 6/10/2019 6:41:56 PM
Brass Lamp Rebuild Red chade.txt 1 KB 6/10/2019 6:41:56 PM
Candle.txt 1 KB 6/10/2019 6:41:56 PM
Crafts.txt 6/10/2019 6:41:56 PM
Cookbook.txt 1 KB 6/10/2019 6:41:56 PM
File:Csv_Scraper.py 1 KB 6/10/2019 6:39:41 PM
Description.txt 1 KB 6/10/2019 6:41:56 PM
Flexo lamp.txt 1 KB 6/10/2019 6:41:56 PM
KoreanJapanese Lamp rebuild.txt 1 KB 6/10/2019 6:41:56 PM
Bride rebuild.txt 1 KB 6/10/2019 6:41:56 PM
Oak and iron music stand.txt 1 KB 6/10/2019 6:41:56 PM
Photograph of Sulpher Springs.txt 1 KB 6/10/2019 6:41:56 PM
filename.csv 1 KB 6/10/2019 6:41:43 PM
iLamp.txt 1 KB 6/10/2019 6:41:56 PM
x-mas orniments.txt 6/10/2019 6:41:56 PM
If I double click or run it in CMD or run it in python within the CMD window (with the prompt) it generates the print output - including the last path line - but no files. As you can likely tell from the imports and odd shebang I have played with it a good bit. I should also add I am/was a py2 user and am now a py3 user (or trying to be). It's as if it is putting the new files someplace else and I cannot find them. Or somehow running without closing them or throwing an error.
Appreciate any thoughts. Hope I was clear - first post.