Using IronPython, write text files

xiaoxiao2021-03-06  73

It is found that there is a link "IronPython Getting Started" on the 9CBS home page! Supervise yourself to write something

In the first two essays, add something, read, write a text file, but read, the part written is used in Python, there is no use .NET Framework in System. The class under the IO namespace, single from these two functions, the code is indeed that the .net is simple, .NET also invokes the constructor before calling the corresponding method.

Since there is no IDE, the interface is not very good, and there is no exception handling.

Below is the corresponding .py file content:

# 进 名 空间. From system.windows.forms import * from system.drawing import *

# 窗 f = form () f.text = "IronPython Load and save text file"

# 按 b B = Button () B.Text = "Load text file" b.top = 110

Btnsave = button () btnsave.text = "save text file" btnsave.top = 110btnsave.Left = 100

#RichtextBoxRichtext = richtextbox (); richtext.width = 150richtext.Height = 100

F.Controls.add (richtext) f.controls.add (b) f.controls.add (btnsave)

# Define Event DEF ButtonClick (Data, Event): INPUT = Open ("D: //1.txt", 'R') S = INPUT.READ () Input = s () richtext.text = s

# DEF BTNSAVECLICK (Data, Event): output = open ("D: //1.txt", 'W') Output.write () Output.close () B.Click = ButtonClick btnsave.click = btnsaveClickf.showdialog ()

Execute in IronPython's bin directory, assuming the .py file is d: /TEXT.PY:

IronPythonConsole D: /Text.py

Program screenshot

转载请注明原文地址:https://www.9cbs.com/read-121169.html

New Post(0)