Python Forum

Full Version: Commas issue in variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Use
dataRow = [f"{today} EDT",tagPath.value]
(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]
(Apr-04-2024, 02:28 PM)ddahlman Wrote: [ -> ]I get errors when using
Please post the complete error message that Python is sending.
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.
(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]
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="")