Skip to content

Instantly share code, notes, and snippets.

@hanxiaomax hanxiaomax/Aisfun.py

Last active Aug 29, 2015
Embed
What would you like to do?
itertools模块/filter/起名软件/编码

###1.Python几个特殊的语法

参考链接

###2.itertool

参考链接

###3.关于软件打包 NSIS有GUI,可以使用向导来创建脚本,需要另外下载

打包python的时候通常会同时打包一个Python,但是会优化,对于GUI程序,应该使用pythonw.exe来执行,这样不会出现CLI。

这里需要注意快捷方式的起始路径需要设置SetOutPath,是在 CreateShortCut "$DESKTOP\xxxx.lnk" "$INSTDIR\python\pythonw.exe" '-m "softwareGUI"' "$INSTDIR\Getname.ico" 之前

不太清楚怎么把PYTHON很好的打包,现在的方式零碎的文件太多,应该不是这样

#coding:utf-8
__author__='Lingfeng Ai'
__license__='GPL'
import itertools
class GetName(object):
def __init__(self):
self.num=0
def getResult_ordered(self,filename,list1,list2,list3,list4):
self.num = 0
f = open(filename , 'w')
for i in xrange(0,len(list1)):
for j in xrange(0,len(list2)):
for k in xrange(0,len(list3)):
for n in xrange(0,len(list4)):
word=list1[i]+list2[j]+list3[k]+list4[n]
f.write(word.encode('utf-8')+"\n")
self.num+=1
f.close()
def getResult_all(self,filename,_list):
self.num=0
f=open(filename,'w')
_list = filter(lambda x:x!='',_list)#过滤所有空串
#filter把结果为True的item返回,返回类型同_list
iterlist=list(itertools.permutations(_list,3))
#permutations(iterable [,r]):
#创建一个迭代器,返回iterable中所有长度为r的项目序列,如果省略了r,那么序列的长度与iterable中的项目数量相同:
for item in iterlist:
f.write("".join(item).encode('utf-8')+"\n")#把列表变成字符串且处理编码
self.num+=1
f.close()
def get_num(self):
return self.num
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import wx.xrc
from fun import Aisfun
__author__='Lingfeng Ai'
__license__='GPL'
class MainFrame( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"起名软件", pos = wx.DefaultPosition, size = wx.Size( 390,297 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_3DLIGHT ) )
gbSizer1 = wx.GridBagSizer( 0, 0 )
gbSizer1.SetFlexibleDirection( wx.BOTH )
gbSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
self.titlelabel = wx.StaticText( self, wx.ID_ANY, u"新疆沃达农业科技开发有限公司", wx.DefaultPosition, wx.DefaultSize, 0 )
self.titlelabel.Wrap( -1 )
gbSizer1.Add( self.titlelabel, wx.GBPosition( 0, 0 ), wx.GBSpan( 1, 1 ), wx.ALL, 5 )
sbSizer1 = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, wx.EmptyString ), wx.VERTICAL )
fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 )
fgSizer1.SetFlexibleDirection( wx.BOTH )
fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
#第一个输入框
self.wordlist1 = wx.StaticText( self, wx.ID_ANY, u"备选词列表1", wx.DefaultPosition, wx.DefaultSize, 0 )
self.wordlist1.Wrap( -1 )
fgSizer1.Add( self.wordlist1, 0, wx.ALL, 5 )
self.listinput1 = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizer1.Add( self.listinput1, 0, wx.ALL, 5 )
sbSizer1.Add( fgSizer1, 1, wx.EXPAND, 5 )
fgSizer2 = wx.FlexGridSizer( 0, 2, 0, 0 )
fgSizer2.SetFlexibleDirection( wx.BOTH )
fgSizer2.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
self.wordlist2 = wx.StaticText( self, wx.ID_ANY, u"备选词列表2", wx.DefaultPosition, wx.DefaultSize, 0 )
self.wordlist2.Wrap( -1 )
fgSizer2.Add( self.wordlist2, 0, wx.ALL, 5 )
self.listinput2 = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizer2.Add( self.listinput2, 0, wx.ALL, 5 )
sbSizer1.Add( fgSizer2, 1, wx.EXPAND, 5 )
fgSizer3 = wx.FlexGridSizer( 0, 2, 0, 0 )
fgSizer3.SetFlexibleDirection( wx.BOTH )
fgSizer3.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
self.wordlist3 = wx.StaticText( self, wx.ID_ANY, u"备选词列表3", wx.DefaultPosition, wx.DefaultSize, 0 )
self.wordlist3.Wrap( -1 )
fgSizer3.Add( self.wordlist3, 0, wx.ALL, 5 )
self.listinput3 = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizer3.Add( self.listinput3, 0, wx.ALL, 5 )
sbSizer1.Add( fgSizer3, 1, wx.EXPAND, 5 )
fgSizer4 = wx.FlexGridSizer( 0, 2, 0, 0 )
fgSizer4.SetFlexibleDirection( wx.BOTH )
fgSizer4.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
self.wordlist4 = wx.StaticText( self, wx.ID_ANY, u"备选词列表4", wx.DefaultPosition, wx.DefaultSize, 0 )
self.wordlist4.Wrap( -1 )
fgSizer4.Add( self.wordlist4, 0, wx.ALL, 5 )
self.listinput4 = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizer4.Add( self.listinput4, 0, wx.ALL, 5 )
sbSizer1.Add( fgSizer4, 1, wx.EXPAND, 5 )
gbSizer1.Add( sbSizer1, wx.GBPosition( 1, 0 ), wx.GBSpan( 1, 1 ), wx.EXPAND, 5 )
sbSizer4 = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, wx.EmptyString ), wx.VERTICAL )
self.rb_ordered = wx.RadioButton( self, wx.ID_ANY, u"保持顺序", wx.DefaultPosition, wx.DefaultSize, 0 )
sbSizer4.Add( self.rb_ordered, 0, wx.ALL, 5 )
self.rb_all = wx.RadioButton( self, wx.ID_ANY, u"完全乱序", wx.DefaultPosition, wx.DefaultSize, 0 )
sbSizer4.Add( self.rb_all, 0, wx.ALL, 5 )
self.rb_ordered.SetValue( True )
gbSizer1.Add( sbSizer4, wx.GBPosition( 1, 2 ), wx.GBSpan( 1, 1 ), wx.EXPAND, 5 )
m_sdbSizer2 = wx.StdDialogButtonSizer()
self.okbutton = wx.Button( self, wx.ID_OK )
m_sdbSizer2.AddButton( self.okbutton )
self.Bind(wx.EVT_BUTTON, self.OnClick, self.okbutton)
m_sdbSizer2.Realize()
gbSizer1.Add( m_sdbSizer2, wx.GBPosition( 3, 2 ), wx.GBSpan( 1, 1 ), wx.EXPAND, 5 )
self.SetSizer( gbSizer1 )
self.Layout()
self.Centre( wx.BOTH )
def OnClick(self, event):
get=Aisfun.GetName()
dlg = wx.FileDialog(self, u"保存结果", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
dlg.SetWildcard('.txt')
if dlg.ShowModal() != wx.ID_OK:
dlg.Destroy()
return
dest = dlg.GetPath()
list1=self.listinput1.GetValue().split(' ')
list2=self.listinput2.GetValue().split(' ')
list3=self.listinput3.GetValue().split(' ')
list4=self.listinput4.GetValue().split(' ')
_list=list1+list2+list3+list4
if self.rb_ordered.GetValue():
get.getResult_ordered(dest,list1,list2,list3,list4)
else:
get.getResult_all(dest,_list)
dlg.Destroy()
num=get.get_num()
message_dlg = wx.MessageDialog(None,(u"已为您生成%d个名字\n")%num+u'保存至'+dest,u'完成',wx.OK|wx.ICON_INFORMATION)
message_dlg.ShowModal()
message_dlg.Destroy()
def main():
app=wx.PySimpleApp()
frame=MainFrame(parent=None)
frame.Show(True)
app.MainLoop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.