lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
4 là một chuỗi thoát mà chỉ hoạt động trong các chuỗi chữ. lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
5 không lấy một chuỗi theo nghĩa đen, nó lấy văn bản mà người dùng nhập và không thực hiện bất kỳ xử lý nào trên đó để bất kỳ ai nhập lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
6 theo sau là lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
7 tạo ra một chuỗi hai ký tự, dấu gạch chéo ngược và chữ cái lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
7, không phải là dòng mới.Bạn sẽ phải tự mình thực hiện việc tự thoát như vậy:
file = file.replace[r'\n', '\n']
Ở đây tôi đã sử dụng một chuỗi thô theo nghĩa đen, cũng không hỗ trợ thoát khỏi các chuỗi, để xác định dấu gạch chéo ngược theo nghĩa đen
lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
6 theo sau là lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
7.Ngoài ra, liên tục hỏi người dùng một tên tệp mới, cho đến khi chúng được thực hiện:
lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
Demo:
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
Xin chào các bạn, câu hỏi này đã được hỏi trước đây, nhưng câu trả lời thiên đường đã giúp tôi. Tôi muốn tách các dòng khi tôi tiếp tục điều khiển văn bản. Nhưng "\ n" chỉ đơn giản là không hoạt động. Tôi đang sử dụng Python 2.7, trên Windows 7. Vui lòng giúp đỡ. Tôi muốn hiển thị tất cả các tên tệp trên dòng tiếp theo, bất cứ khi nào người dùng thêm một tệp. Cảm ơn trước.
I want to seperate lines when i am appending the text control. But "\n" is simply not working .
I am using Python 2.7 , on Windows 7. Please help. I want to display all file names
on next line , whenever user adds a file . Thanks in advance.
Cũng lưu ý, nếu chúng ta tạo một văn bản,
>>> hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
>>> hello
'This is a rather long string containing\nseveral lines of text just as you would do in C.\n Note that whitespace at the beginning of the line is significant.'
Vì vậy, bạn có thể thấy ngay cả điều này không hoạt động với chuỗi cơ bản.
import wx
class TextFrame[wx.Frame]:
def __init__[self]:
wx.Frame.__init__[self, None, -1, 'Text Entry Example', size=[500, 450]]
panel = wx.Panel[self, -1]
menubar=wx.MenuBar[]
#Menu section
pehla=wx.Menu[]
doosra=wx.Menu[] #So there will be two drop down menu
#Menu Bar Items
menu_1=menubar.Append[pehla,"File"] #Naming of Menu items
menu_2=menubar.Append[doosra,"Edit"]
self.SetMenuBar[menubar]
#Menu Items
item1_1=pehla.Append[wx.ID_OPEN,"Add","This is add files"] #Sub-Items of First menu pull down list
item1_2=pehla.Append[wx.ID_EXIT,"Exit","This will exit app"] #The last comment will show on status bar when mouse is on that option
self.Bind[wx.EVT_MENU, self.OnFileOpen,item1_1]
#multiLabel = wx.StaticText[panel, -1, "Multi-line"]
self.Bind[wx.EVT_MENU, self.OnFileExit,item1_2]
#Text boxes
Search_Text = wx.TextCtrl[panel, -1,"Enter search string",pos=[5,5],size=[350,30], style=wx.ALIGN_LEFT]
Search_Text.SetInsertionPoint[0]
mytext="\n"
self.Files_List = wx.TextCtrl[panel, -1,mytext,size=wx.Size[400,100],pos=[5,40],style=wx.TE_READONLY]
Search_Text.SetInsertionPoint[0]
#Seacrh Button
btn_Process = wx.Button[panel,-1,label='Search',pos=[360,5]]
self.Bind[wx.EVT_BUTTON, self.Process, btn_Process]
#Function Definations
def OnFileOpen[self, e]:
""" File|Open event - Open dialog box. """
self.dirname = ''
dlg = wx.FileDialog[self, "Choose a file", self.dirname, "", "*.xls*"]
if [dlg.ShowModal[] == wx.ID_OK]:
self.fileName = dlg.GetFilename[]
self.dirName = dlg.GetDirectory[]
text1=str[self.fileName]
self.Files_List.AppendText[text1+"\n"]
def OnFileExit[self, e]:
""" File|Exit event """
self.Close[True]
def Process[self,event]:
print"This is a test"
app = wx.PySimpleApp[]
frame = TextFrame[]
frame.Show[]
app.MainLoop[]
Nếu bạn quen thuộc với Python, bạn có thể nhận thấy rằng chức năng tích hợp
1 không cần ký tự >>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
4 rõ ràng ở cuối mỗi dòng.lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
Điều này có nghĩa là đầu ra từ đoạn mã sau
print['freeCodeCamp Curriculum']
print['freeCodeCamp News']
print['freeCodeCamp YouTube Channel']
sẽ là:
freeCodeCamp Curriculum
freeCodeCamp News
freeCodeCamp YouTube Channel
Điều này xảy ra vì hàm
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
1 thêm ký tự lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
4 vào cuối mỗi dòng in. Mặc dù hầu hết thời gian đây là một sự tiện lợi, đôi khi bạn có thể muốn in ra các dòng mà không có ký tự lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
4.Trong bài viết này, bạn sẽ học cách thay đổi phần cuối của mỗi câu lệnh in. Và bạn cũng sẽ tìm hiểu một số cách khác để sửa đổi cách thức hoạt động của chức năng tích hợp theo mặc định.
Cách in mà không có dòng mới trong Python
Theo tài liệu chính thức cho hàm
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
1, chữ ký chức năng như sau:print[*objects, sep=' ', end='\n', file=sys.stdout, flush=False]
Như bạn có thể thấy chức năng mất tổng cộng năm đối số. Đầu tiên là [các] đối tượng mà bạn muốn in trên thiết bị đầu cuối. Sau đó, có dấu phân cách [mà bạn sẽ tìm hiểu trong một phần sau] và tham số ____27.
Giá trị mặc định của tham số
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
7 là lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
4, có nghĩa là một ký tự dòng mới sẽ được thêm vào mỗi dòng được in trên thiết bị đầu cuối.Để thay đổi hành vi này, bạn chỉ có thể ghi đè tham số này như sau:
print['freeCodeCamp Curriculum', end=', ']
print['freeCodeCamp News', end=', ']
print['freeCodeCamp YouTube Channel']
Vì, tôi đã thay đổi giá trị của
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
7 thành dấu phẩy, đầu ra sẽ là >>> hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
>>> hello
'This is a rather long string containing\nseveral lines of text just as you would do in C.\n Note that whitespace at the beginning of the line is significant.'
1 thay vì ba dòng riêng biệt.Bạn có thể sử dụng bất kỳ ký tự nào làm giá trị của
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
7. Nếu bạn không muốn gì ở cuối dòng, chỉ cần sử dụng một chuỗi trống.Cách in với dấu tách trong Python
Bạn có nhớ đối số
>>> hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
>>> hello
'This is a rather long string containing\nseveral lines of text just as you would do in C.\n Note that whitespace at the beginning of the line is significant.'
3 trong chữ ký hàm không? Trong phần này, bạn sẽ tìm hiểu về việc sử dụng của nó.Bạn có thể hoặc chưa biết rằng chức năng
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
1 có thể lấy nhiều đối tượng cùng một lúc để in ra như sau:print['freeCodeCamp Curriculum', 'freeCodeCamp News', 'freeCodeCamp YouTube Channel']
Đầu ra từ mã này sẽ là:
lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
0Như bạn có thể thấy, chức năng đã in ba chuỗi trong một dòng được phân tách bằng dấu phẩy. Nếu bạn muốn sử dụng một thứ khác như dấu gạch ngang làm dấu phân cách, bạn có thể làm như vậy như sau:
lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
1Đầu ra từ mã này sẽ là:
lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
2Như bạn có thể thấy, chức năng đã in ba chuỗi trong một dòng được phân tách bằng dấu phẩy. Nếu bạn muốn sử dụng một thứ khác như dấu gạch ngang làm dấu phân cách, bạn có thể làm như vậy như sau:
Tôi hy vọng bạn có ý tưởng. Giống như đối số >>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
7, bạn có thể sử dụng nhiều hơn bất kỳ chuỗi hợp lệ nào làm giá trị của đối số >>> hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
>>> hello
'This is a rather long string containing\nseveral lines of text just as you would do in C.\n Note that whitespace at the beginning of the line is significant.'
3.
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
>>> hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
>>> hello
'This is a rather long string containing\nseveral lines of text just as you would do in C.\n Note that whitespace at the beginning of the line is significant.'
Cách in vào tệp trong Python
Thay vì in mọi thứ vào thiết bị đầu cuối, bạn cũng có thể sử dụng chức năng
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
1 để in nội dung trực tiếp vào tệp.Hàm
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
1 có một đối số khác >>> hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
>>> hello
'This is a rather long string containing\nseveral lines of text just as you would do in C.\n Note that whitespace at the beginning of the line is significant.'
9 mặc định là import wx
class TextFrame[wx.Frame]:
def __init__[self]:
wx.Frame.__init__[self, None, -1, 'Text Entry Example', size=[500, 450]]
panel = wx.Panel[self, -1]
menubar=wx.MenuBar[]
#Menu section
pehla=wx.Menu[]
doosra=wx.Menu[] #So there will be two drop down menu
#Menu Bar Items
menu_1=menubar.Append[pehla,"File"] #Naming of Menu items
menu_2=menubar.Append[doosra,"Edit"]
self.SetMenuBar[menubar]
#Menu Items
item1_1=pehla.Append[wx.ID_OPEN,"Add","This is add files"] #Sub-Items of First menu pull down list
item1_2=pehla.Append[wx.ID_EXIT,"Exit","This will exit app"] #The last comment will show on status bar when mouse is on that option
self.Bind[wx.EVT_MENU, self.OnFileOpen,item1_1]
#multiLabel = wx.StaticText[panel, -1, "Multi-line"]
self.Bind[wx.EVT_MENU, self.OnFileExit,item1_2]
#Text boxes
Search_Text = wx.TextCtrl[panel, -1,"Enter search string",pos=[5,5],size=[350,30], style=wx.ALIGN_LEFT]
Search_Text.SetInsertionPoint[0]
mytext="\n"
self.Files_List = wx.TextCtrl[panel, -1,mytext,size=wx.Size[400,100],pos=[5,40],style=wx.TE_READONLY]
Search_Text.SetInsertionPoint[0]
#Seacrh Button
btn_Process = wx.Button[panel,-1,label='Search',pos=[360,5]]
self.Bind[wx.EVT_BUTTON, self.Process, btn_Process]
#Function Definations
def OnFileOpen[self, e]:
""" File|Open event - Open dialog box. """
self.dirname = ''
dlg = wx.FileDialog[self, "Choose a file", self.dirname, "", "*.xls*"]
if [dlg.ShowModal[] == wx.ID_OK]:
self.fileName = dlg.GetFilename[]
self.dirName = dlg.GetDirectory[]
text1=str[self.fileName]
self.Files_List.AppendText[text1+"\n"]
def OnFileExit[self, e]:
""" File|Exit event """
self.Close[True]
def Process[self,event]:
print"This is a test"
app = wx.PySimpleApp[]
frame = TextFrame[]
frame.Show[]
app.MainLoop[]
0 hoặc đầu ra tiêu chuẩn. Đó là bộ mô tả tệp mặc định trong đó một quy trình có thể ghi đầu ra.lines = []
print['Type in your document, followed by a blank line:']
while True:
line = input["> "]
if not line:
break
lines.append[line]
file = '\n'.join[lines]
3Bạn có thể ghi đè này để ghi vào một tệp thay thế như sau:
Đầu tiên, bạn mở một tệp có tên import wx
class TextFrame[wx.Frame]:
def __init__[self]:
wx.Frame.__init__[self, None, -1, 'Text Entry Example', size=[500, 450]]
panel = wx.Panel[self, -1]
menubar=wx.MenuBar[]
#Menu section
pehla=wx.Menu[]
doosra=wx.Menu[] #So there will be two drop down menu
#Menu Bar Items
menu_1=menubar.Append[pehla,"File"] #Naming of Menu items
menu_2=menubar.Append[doosra,"Edit"]
self.SetMenuBar[menubar]
#Menu Items
item1_1=pehla.Append[wx.ID_OPEN,"Add","This is add files"] #Sub-Items of First menu pull down list
item1_2=pehla.Append[wx.ID_EXIT,"Exit","This will exit app"] #The last comment will show on status bar when mouse is on that option
self.Bind[wx.EVT_MENU, self.OnFileOpen,item1_1]
#multiLabel = wx.StaticText[panel, -1, "Multi-line"]
self.Bind[wx.EVT_MENU, self.OnFileExit,item1_2]
#Text boxes
Search_Text = wx.TextCtrl[panel, -1,"Enter search string",pos=[5,5],size=[350,30], style=wx.ALIGN_LEFT]
Search_Text.SetInsertionPoint[0]
mytext="\n"
self.Files_List = wx.TextCtrl[panel, -1,mytext,size=wx.Size[400,100],pos=[5,40],style=wx.TE_READONLY]
Search_Text.SetInsertionPoint[0]
#Seacrh Button
btn_Process = wx.Button[panel,-1,label='Search',pos=[360,5]]
self.Bind[wx.EVT_BUTTON, self.Process, btn_Process]
#Function Definations
def OnFileOpen[self, e]:
""" File|Open event - Open dialog box. """
self.dirname = ''
dlg = wx.FileDialog[self, "Choose a file", self.dirname, "", "*.xls*"]
if [dlg.ShowModal[] == wx.ID_OK]:
self.fileName = dlg.GetFilename[]
self.dirName = dlg.GetDirectory[]
text1=str[self.fileName]
self.Files_List.AppendText[text1+"\n"]
def OnFileExit[self, e]:
""" File|Exit event """
self.Close[True]
def Process[self,event]:
print"This is a test"
app = wx.PySimpleApp[]
frame = TextFrame[]
frame.Show[]
app.MainLoop[]
1 dưới dạng import wx
class TextFrame[wx.Frame]:
def __init__[self]:
wx.Frame.__init__[self, None, -1, 'Text Entry Example', size=[500, 450]]
panel = wx.Panel[self, -1]
menubar=wx.MenuBar[]
#Menu section
pehla=wx.Menu[]
doosra=wx.Menu[] #So there will be two drop down menu
#Menu Bar Items
menu_1=menubar.Append[pehla,"File"] #Naming of Menu items
menu_2=menubar.Append[doosra,"Edit"]
self.SetMenuBar[menubar]
#Menu Items
item1_1=pehla.Append[wx.ID_OPEN,"Add","This is add files"] #Sub-Items of First menu pull down list
item1_2=pehla.Append[wx.ID_EXIT,"Exit","This will exit app"] #The last comment will show on status bar when mouse is on that option
self.Bind[wx.EVT_MENU, self.OnFileOpen,item1_1]
#multiLabel = wx.StaticText[panel, -1, "Multi-line"]
self.Bind[wx.EVT_MENU, self.OnFileExit,item1_2]
#Text boxes
Search_Text = wx.TextCtrl[panel, -1,"Enter search string",pos=[5,5],size=[350,30], style=wx.ALIGN_LEFT]
Search_Text.SetInsertionPoint[0]
mytext="\n"
self.Files_List = wx.TextCtrl[panel, -1,mytext,size=wx.Size[400,100],pos=[5,40],style=wx.TE_READONLY]
Search_Text.SetInsertionPoint[0]
#Seacrh Button
btn_Process = wx.Button[panel,-1,label='Search',pos=[360,5]]
self.Bind[wx.EVT_BUTTON, self.Process, btn_Process]
#Function Definations
def OnFileOpen[self, e]:
""" File|Open event - Open dialog box. """
self.dirname = ''
dlg = wx.FileDialog[self, "Choose a file", self.dirname, "", "*.xls*"]
if [dlg.ShowModal[] == wx.ID_OK]:
self.fileName = dlg.GetFilename[]
self.dirName = dlg.GetDirectory[]
text1=str[self.fileName]
self.Files_List.AppendText[text1+"\n"]
def OnFileExit[self, e]:
""" File|Exit event """
self.Close[True]
def Process[self,event]:
print"This is a test"
app = wx.PySimpleApp[]
frame = TextFrame[]
frame.Show[]
app.MainLoop[]
2 và truyền đó là giá trị của đối số >>> hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
>>> hello
'This is a rather long string containing\nseveral lines of text just as you would do in C.\n Note that whitespace at the beginning of the line is significant.'
9. Nếu bạn chạy mã, một tệp mới sẽ được tạo và bên trong tệp đó sẽ là đầu ra của bạn.
import wx
class TextFrame[wx.Frame]:
def __init__[self]:
wx.Frame.__init__[self, None, -1, 'Text Entry Example', size=[500, 450]]
panel = wx.Panel[self, -1]
menubar=wx.MenuBar[]
#Menu section
pehla=wx.Menu[]
doosra=wx.Menu[] #So there will be two drop down menu
#Menu Bar Items
menu_1=menubar.Append[pehla,"File"] #Naming of Menu items
menu_2=menubar.Append[doosra,"Edit"]
self.SetMenuBar[menubar]
#Menu Items
item1_1=pehla.Append[wx.ID_OPEN,"Add","This is add files"] #Sub-Items of First menu pull down list
item1_2=pehla.Append[wx.ID_EXIT,"Exit","This will exit app"] #The last comment will show on status bar when mouse is on that option
self.Bind[wx.EVT_MENU, self.OnFileOpen,item1_1]
#multiLabel = wx.StaticText[panel, -1, "Multi-line"]
self.Bind[wx.EVT_MENU, self.OnFileExit,item1_2]
#Text boxes
Search_Text = wx.TextCtrl[panel, -1,"Enter search string",pos=[5,5],size=[350,30], style=wx.ALIGN_LEFT]
Search_Text.SetInsertionPoint[0]
mytext="\n"
self.Files_List = wx.TextCtrl[panel, -1,mytext,size=wx.Size[400,100],pos=[5,40],style=wx.TE_READONLY]
Search_Text.SetInsertionPoint[0]
#Seacrh Button
btn_Process = wx.Button[panel,-1,label='Search',pos=[360,5]]
self.Bind[wx.EVT_BUTTON, self.Process, btn_Process]
#Function Definations
def OnFileOpen[self, e]:
""" File|Open event - Open dialog box. """
self.dirname = ''
dlg = wx.FileDialog[self, "Choose a file", self.dirname, "", "*.xls*"]
if [dlg.ShowModal[] == wx.ID_OK]:
self.fileName = dlg.GetFilename[]
self.dirName = dlg.GetDirectory[]
text1=str[self.fileName]
self.Files_List.AppendText[text1+"\n"]
def OnFileExit[self, e]:
""" File|Exit event """
self.Close[True]
def Process[self,event]:
print"This is a test"
app = wx.PySimpleApp[]
frame = TextFrame[]
frame.Show[]
app.MainLoop[]
import wx
class TextFrame[wx.Frame]:
def __init__[self]:
wx.Frame.__init__[self, None, -1, 'Text Entry Example', size=[500, 450]]
panel = wx.Panel[self, -1]
menubar=wx.MenuBar[]
#Menu section
pehla=wx.Menu[]
doosra=wx.Menu[] #So there will be two drop down menu
#Menu Bar Items
menu_1=menubar.Append[pehla,"File"] #Naming of Menu items
menu_2=menubar.Append[doosra,"Edit"]
self.SetMenuBar[menubar]
#Menu Items
item1_1=pehla.Append[wx.ID_OPEN,"Add","This is add files"] #Sub-Items of First menu pull down list
item1_2=pehla.Append[wx.ID_EXIT,"Exit","This will exit app"] #The last comment will show on status bar when mouse is on that option
self.Bind[wx.EVT_MENU, self.OnFileOpen,item1_1]
#multiLabel = wx.StaticText[panel, -1, "Multi-line"]
self.Bind[wx.EVT_MENU, self.OnFileExit,item1_2]
#Text boxes
Search_Text = wx.TextCtrl[panel, -1,"Enter search string",pos=[5,5],size=[350,30], style=wx.ALIGN_LEFT]
Search_Text.SetInsertionPoint[0]
mytext="\n"
self.Files_List = wx.TextCtrl[panel, -1,mytext,size=wx.Size[400,100],pos=[5,40],style=wx.TE_READONLY]
Search_Text.SetInsertionPoint[0]
#Seacrh Button
btn_Process = wx.Button[panel,-1,label='Search',pos=[360,5]]
self.Bind[wx.EVT_BUTTON, self.Process, btn_Process]
#Function Definations
def OnFileOpen[self, e]:
""" File|Open event - Open dialog box. """
self.dirname = ''
dlg = wx.FileDialog[self, "Choose a file", self.dirname, "", "*.xls*"]
if [dlg.ShowModal[] == wx.ID_OK]:
self.fileName = dlg.GetFilename[]
self.dirName = dlg.GetDirectory[]
text1=str[self.fileName]
self.Files_List.AppendText[text1+"\n"]
def OnFileExit[self, e]:
""" File|Exit event """
self.Close[True]
def Process[self,event]:
print"This is a test"
app = wx.PySimpleApp[]
frame = TextFrame[]
frame.Show[]
app.MainLoop[]
>>> hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
>>> hello
'This is a rather long string containing\nseveral lines of text just as you would do in C.\n Note that whitespace at the beginning of the line is significant.'
Sự kết luận
Hàm
>>> lines = []
>>> print['Type in your document, followed by a blank line:']
Type in your document, followed by a blank line:
>>> while True:
... line = input["> "]
... if not line:
... break
... lines.append[line]
...
> foo
> bar
>
>>> lines
['foo', 'bar']
>>> '\n'.join[lines]
'foo\nbar'
1 là một trong những hàm được sử dụng phổ biến nhất trong Python. Vì vậy, có một sự hiểu biết tốt về các cách sử dụng khác nhau của chức năng tích hợp này có thể làm tăng năng suất của bạn.Tôi cũng có một blog cá nhân nơi tôi viết về các công cụ công nghệ ngẫu nhiên, vì vậy nếu bạn quan tâm đến một cái gì đó như vậy, hãy kiểm tra //farhan.dev. Nếu bạn có bất kỳ câu hỏi hoặc bối rối về bất cứ điều gì - hoặc chỉ muốn liên lạc - tôi có sẵn trên Twitter và LinkedIn.
Học mã miễn phí.Chương trình giảng dạy nguồn mở của Freecodecamp đã giúp hơn 40.000 người có được việc làm với tư cách là nhà phát triển.Bắt đầu