Python与.NET中的随机二进制读/写
我非常喜欢.NET如何实现二进制数据的读写。干净优雅 我可以用Python来做这个吗Python与.NET中的随机二进制读/写,python,.net,vb.net,file-io,binaryfiles,Python,.net,Vb.net,File Io,Binaryfiles,我非常喜欢.NET如何实现二进制数据的读写。干净优雅 我可以用Python来做这个吗 Sub Main() Using writer As New System.IO.BinaryWriter( _ System.IO.File.Open("Test.bin", IO.FileMode.Create)) writer.Write(True) writer.Write(123) writer.Write(123.456)
Sub Main()
Using writer As New System.IO.BinaryWriter( _
System.IO.File.Open("Test.bin", IO.FileMode.Create))
writer.Write(True)
writer.Write(123)
writer.Write(123.456)
writer.Write(987.654D)
writer.Write("Test string.")
End Using
Using reader As New System.IO.BinaryReader( _
System.IO.File.Open("Test.bin", IO.FileMode.Open))
Console.WriteLine(reader.ReadBoolean())
Console.WriteLine(reader.ReadInt32())
Console.WriteLine(reader.ReadDouble())
Console.WriteLine(reader.ReadDecimal())
Console.WriteLine(reader.ReadString())
End Using
Console.Write("Press <RETURN> to exit.")
Console.ReadKey()
End Sub
Sub-Main()
使用writer作为新系统。IO.BinaryWriter(_
System.IO.File.Open(“Test.bin”,IO.FileMode.Create))
writer.Write(真)
写作(123)
writer.Write(123.456)
writer.Write(987.654D)
writer.Write(“测试字符串”)
终端使用
将reader用作新的System.IO.BinaryReader(_
System.IO.File.Open(“Test.bin”,IO.FileMode.Open))
Console.WriteLine(reader.ReadBoolean())
Console.WriteLine(reader.ReadInt32())
Console.WriteLine(reader.ReadDouble())
Console.WriteLine(reader.ReadDecimal())
Console.WriteLine(reader.ReadString())
终端使用
控制台。写入(“按以退出”)
Console.ReadKey()
端接头
是。将“with”用于open,参见示例:将open(“file.txt”)用作file:
是的,我了解上下文管理器,但如何编写bool
,int
,float
,str
,decimal.decimal
,等等。我见过编写完整结构的解决方案,如列表或类,例如,使用pickle
模块,但不要使用太多单独的值。这就是为什么我在题目中用了“随机”这个词。啊,我明白了。但我认为python中不存在类似的东西。用泡菜…是的。将“with”用于open,参见示例:将open(“file.txt”)用作file:
是的,我了解上下文管理器,但如何编写bool
,int
,float
,str
,decimal.decimal
,等等。我见过编写完整结构的解决方案,如列表或类,例如,使用pickle
模块,但不要使用太多单独的值。这就是为什么我在题目中用了“随机”这个词。啊,我明白了。但我认为python中不存在类似的东西。用泡菜。。。