Translating some Java to Python
A while ago I wrote a class in Java for all kinds of dice rolling methods, as many sides as you want, as many dice as you want, only count values above or below some number in the total, things like that. Now I'm writing a project in Python that needs to be able to make use of that kind of a class. The Java version has static methods for common roll styles (XdY and XdY +Z) for classes that just want a result but don't want to bother keeping an object around for later. So the question is, assuming that I wanted to keep the static method behavior (which I'm not really sure I do), how does one format the method header on a 'static' method in Python? Is it just something like: class Foo: def statAdd(self,a): return a+5 or do you drop the 'self' bit and just use a 1 variable parameter list? -- http://mail.python.org/mailman/listinfo/python-list
Re: Translating some Java to Python
Alright, sounds good. I'm just not as familiar with the preferred designs of python. As to wanting to have them in a class, sometimes I do. Persisting a roll in a class is only for the slightly more complicated rolls such as 3d6+5d4-1d12 or "4d6 (drop the lowest and re-roll ones)", things of that sort. -- http://mail.python.org/mailman/listinfo/python-list
Re: paste text with newlines into raw_input?
#!/usr/bin/python print "paste quote:" emptycount = 0 lines = [] while emptycount < 2: t = raw_input() if len(t) == 0: emptycount +=1 else: emptycount=0 lines.append(t) lines.append("\n") quote = " ".join(lines[:-3]) print "Quote was this:" print "===" print quote print "===" -- http://mail.python.org/mailman/listinfo/python-list
trouble with wxPython intro
I'm trying to learn WxPython with the tutorial: http://wiki.wxpython.org/Getting_Started But I can't seem to get the example for events to work. I pasted the code they had directly into an interpreter and it got a dialog to appear and the program was able to close itself, but my own copy won't work. As far as I can see, it isn't at all different except for the name of the main frame, and so I differ to you for help. my own code: #!/usr/bin/python import wx ID_ABOUT=101 ID_EXIT=110 class MainWindow(wx.Frame): def __init__(self,parent,id,title): wx.Frame.__init__(self,parent,id,title,size=(200,100)) self.control = wx.TextCtrl(self,1,style=wx.TE_MULTILINE) self.CreateStatusBar() #adds a status bar to the bottom #Menu setup filemenu = wx.Menu() filemenu.Append(wx.ID_ABOUT,"&About","Info about the program") filemenu.AppendSeparator() filemenu.Append(wx.ID_EXIT,"E&xit","Terminate the program.") #Menubar setup menuBar = wx.MenuBar() menuBar.Append(filemenu,"&File") #add file to the menubar self.SetMenuBar(menuBar) #add in the menubar # Add events wx.EVT_MENU(self,ID_ABOUT,self.OnAbout) wx.EVT_MENU(self,ID_EXIT,self.OnExit) # Go! self.Show(True) def OnAbout(self,e): print "Show!" d = wx.MessageDialog(self,"A sample editor.","About Sample Ed",wx.OK) d.ShowModal() d.Destroy() def OnExit(self,e): print "close!" self.Close(True) app = wx.PySimpleApp() frame = MainWindow(None,wx.ID_ANY,'Small Ed!') app.MainLoop() -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble with wxPython intro
That's so simple I'm embarrassed. I should have noticed the change from the example before to this one. It works now, thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python editor/IDE on Linux?
In Linux I just use Gedit. In windows I settle for Notepad2. With python having help built into the interpreter, anything more than line numbering, simple syntax highlighting, and auto-indent when you hit enter just doesn't seem necessary. Vim has b and c, but not a. Using Kate for Python would probably be very similar to using Gedit (from my limited experience with Kate). -- http://mail.python.org/mailman/listinfo/python-list
Re: is laziness a programer's virtue?
You fail to understand the difference between passive laziness and active laziness. Passive laziness is what most people have. It's active laziness that is the virtue. It's the desire to go out and / make sure/ that you can be lazy in the future by spending just a little time writing a script now. It's thinking about time economically and acting on it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python editor/IDE on Linux?
didn't know that one. Perhaps I'll look into Gvim (I still like to cut and paste with the mouse, even if I left that off my list). -- http://mail.python.org/mailman/listinfo/python-list