-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customise output names #16
Comments
Yes, being able to generate
We would need to update the variable passed to Can you think of a more elegant solution than creating a temporary list for comparison? An alternative could be to update the specified column (lets say its |
i was working on this function and something strange is happening i successfully created that verification
but after implementing that feature i can't traverse in csvdict?? i don't know why here is function: def generate_names(listnm):
newname = []
for i in range(len(listnm)):
if (listnm[i] not in listnm[:i]):
newname.append(listnm[i])
else:
newname.append(listnm[i] + "_" + str(listnm[:i].count(listnm[i]) + 1))
return newname this is what i added in convert function: if ((custom_name != None) and (custom_name not in csv_headers)):
print("column name not found")
exit()
else:
file_names = generate_names(list(row[custom_name] for row in csvdict)) after this block i can't traverse in csvdict this function will return a list with names which we can access using: |
@salmannotkhan -- feel free to make a draft pull request and I can have a look this evening (GMT+1) to try and understand the issue. I suspect, although not certain, that the reason you cannot enumerate To explore my hypothesis above, pass |
I had this issue before - and I concur - it iterates using a reader, which is why the code originally opened the .csv twice (a crude fix I admit). |
Got it |
I'll try to implement the |
I'd suggest that instead to abstract the logic to a separate method above as it will make testing it easier. It also keeps the convert method clean and simple 👍 |
done with this i used seek because i didn't found any other way |
Great work -- if you make a PR I can test it and do a code review for you 👍 |
yeah sure |
In my current use of the module, it would be particularly handy to have the output files be named using the data from the .csv. To illustrate, I am generating .docx that need to be sent to the recipients, whose name I fill in the template. In order to trace back which .docx should go to who, it would be convenient to allow parametric customisation of the output file names.
I am thinking of some kind of overloading (although I understand this is not intended in Python), or adding parameters - and checking their validity after opening the .csv. Then, we would definitely need to allow multiple values to ensure some type of uniqueness (and check for this too). Perhaps list parameter or alike?
E.g.
poetry run convert -t template.docx -c data.csv -n ["FIRSTNAME", "LASTNAME"]
With output files as:
Thoughts?
The text was updated successfully, but these errors were encountered: