Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Commas issue in variable
#1
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
Gribouillis write Apr-04-2024, 02:09 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Use
dataRow = [f"{today} EDT",tagPath.value]
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
(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]
Reply
#4
(Apr-04-2024, 02:28 PM)ddahlman Wrote: I get errors when using
Please post the complete error message that Python is sending.
« We can solve any problem by introducing an extra level of indirection »
Reply
#5
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.
Reply
#6
(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]
« We can solve any problem by introducing an extra level of indirection »
Reply
#7
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="")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  help with commas in print functions kronhamilton 11 3,600 Feb-10-2022, 02:02 PM
Last Post: mishraakash
  Variable scope issue melvin13 2 1,607 Nov-29-2021, 08:26 PM
Last Post: melvin13
  Variable Issue slackerman73 2 1,982 Nov-09-2019, 04:34 PM
Last Post: slackerman73
  Issue with affecting numbers to a variable Adem 3 2,366 Sep-24-2019, 07:48 AM
Last Post: Adem
  Help|CSV Writing on List with Inner Commas soothsayerpg 2 2,413 Jul-20-2019, 06:59 AM
Last Post: scidam
  [split] Automate the boring stuff, inserting commas in list srikanth 1 2,150 Jul-02-2019, 02:29 PM
Last Post: metulburr
  Automate the boring stuff, inserting commas in list DJ_Qu 3 4,785 Apr-21-2019, 03:52 PM
Last Post: perfringo
  accessing array without commas rjnabil1994 1 2,550 Feb-10-2019, 06:29 PM
Last Post: Larz60+
  Mixed string,Integer input variable issue maderdash 2 2,794 Nov-06-2018, 09:46 AM
Last Post: snippsat
  Printing array without commas pawlaczkaj 1 9,523 Apr-08-2018, 07:05 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020