Python Forum
Commas issue in variable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Commas issue in variable (/thread-41899.html)



Commas issue in variable - ddahlman - Apr-04-2024

This is the code I am having an issue with

tagPath = system.tag.read("[e1ccd]Extruder/E1_ExtruderAData_MeltPumpAdapterPressure_PV")
today = system.date.format(system.date.now(), "MM/dd/yyyy HH:mm")
dataRow = [today," EDT,",tagPath.value]

with open(filePath, 'a') as csvfile:
   writer = csv.writer(csvfile, lineterminator='\n')
   writer.writerow(dataRow)
The line writes to the file like this

04/04/2024 09:27," EDT,",10000.0

I need it like this

04/04/2024 09:27 EDT,10000.0

but can not figure out how to get that format


RE: Commas issue in variable - Gribouillis - Apr-04-2024

Use
dataRow = [f"{today} EDT",tagPath.value]



RE: Commas issue in variable - ddahlman - Apr-04-2024

(Apr-04-2024, 02:08 PM)Gribouillis Wrote: Use
dataRow = [f"{today} EDT",tagPath.value]

Appreciate the help but I get errors when using
dataRow = [f"{today} EDT",tagPath.value]


RE: Commas issue in variable - Gribouillis - Apr-04-2024

(Apr-04-2024, 02:28 PM)ddahlman Wrote: I get errors when using
Please post the complete error message that Python is sending.


RE: Commas issue in variable - deanhystad - Apr-04-2024

When posting please provide information about what modules you are using. My guess is you are using ignition.

https://www.docs.inductiveautomation.com/

You might have better luck asking your question at the ignition forum. Most of the users here are familiar with CPython. Ignition uses Jython, a Java based implementation of Python.


RE: Commas issue in variable - Gribouillis - Apr-04-2024

(Apr-04-2024, 03:32 PM)deanhystad Wrote: Ignition uses Jython, a Java based implementation of Python.
If Jython doesn't know f-strings, it will work with strings concatenation
dataRow = [today + " EDT", tagPath.value]



RE: Commas issue in variable - deanhystad - Apr-05-2024

Not using a csv file writer will reduce the number of commas. You don't need to use a csv writer to write two values separated by a comma.
with open(filePath, 'a') as csvfile:
    print(today, " EDT,", tagPath.value, file=csvfile, sep="")