2 Replies - 347 Views - Last Post: 27 January 2012 - 03:57 PM Rate Topic: -----

Topic Sponsor:

#1 praditmodi  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 37
  • Joined: 30-November 11

Write Format

Posted 27 January 2012 - 03:27 PM

I want to write a piece of code to a file in this format
digraph fsm {
rankdir="LR" 

f.write("digraph fsm "+\n+" {rankdir="LR"")
this gives me an error ? can someone tell me the exact formatting for this line ?
Is This A Good Question/Topic? 0
  • +

Replies To: Write Format

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 772
  • View blog
  • Posts: 6,133
  • Joined: 07-September 06

Re: Write Format

Posted 27 January 2012 - 03:37 PM

The problem is that you are trying to treat the \n as a variable, it isn't it is a character. So change this:
f.write("digraph fsm "+\n+" {rankdir="LR"")

To this:
f.write("digraph fsm \n {rankdir=\"LR\"")

and you should have better results.

NOTE - Untested code.

Basically, what that does is puts the new line character in the string instead of trying to add it in (using concatenation). It also escapes the double quotes which you are wanting in the output file. This tells python not to try ending the string at the double quote like it would normally (\").

Hope that helps.
Was This Post Helpful? 1
  • +
  • -

#3 praditmodi  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 37
  • Joined: 30-November 11

Re: Write Format

Posted 27 January 2012 - 03:57 PM

Thank you it worked ! ! :-)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1