-1

I have written c# code and i need this to be written in python but i dont no how to use stream writer in python.Please help me how to use the stream writer functionality in python

TextWriter tw = new StreamWriter(val);
                            tw.WriteLine(" used.");
                            tw.WriteLine();
                            tw.WriteLine("02");
                            tw.Write(unit.ToString("X8") + " ");
                            tw.Write(result.Length.ToString("X4"));
vinod raj
  • 69
  • 2
  • 10

2 Answers2

0

Take a look at the StringIO module; I believe it will largely do what you want.

TML
  • 12,813
  • 3
  • 38
  • 45
0

There is documentation on StreamWriter here: https://wiki.python.org/moin/StreamWriter

var tw = StreamWriter(val)
      tw.write(" used.\n");
      tw.write("\n");
      tw.write("02\n");
      ...

If it is simply string manipulation i suggest: https://docs.python.org/2/library/stringio.html

CodeTower
  • 6,293
  • 5
  • 30
  • 54
  • thanks it is working fine then how can we use b.ToString("X2") in python – vinod raj Oct 23 '14 at 09:49
  • What is the type of b and what is the desired output? You have methods such as hex() to print hexidecimal values. – CodeTower Oct 23 '14 at 09:50
  • here b is a datatype of byte and in python how can we define and assign a byte datatype – vinod raj Oct 23 '14 at 09:55
  • Python does not really have a byte data type. Try `hex(b)` or look at: https://wiki.python.org/moin/BitManipulation or https://docs.python.org/3.1/library/functions.html#bytes – CodeTower Oct 23 '14 at 10:10