Re: [Tutor] laying out frames
> I want to create a basic quadrant of frames but am not able to > follow the > logic to do so, whats the right way or an easier way to control > layout of > frames and wigets. A pixel approach would be nice (where by you can > specify pixel locations for a frame or a widget to be located) > instead of > specifying arbitary location positions like LEFT, RIGHT, etc and > things > moving constantly when you add more widgets or resize windows. You can use the placer widget manager instead of grid or pack to specify pixel based locations. But grid or pack are preferred precisely because they do automatically move things around when you resize screens - one of the hardest things to do when using pixel arrangements! Also pixel based layouts tend not to be very portable between systems - some use square pixels, others rectangular etc So the GUI looks different on different machines. Intelligent layout managers make life much easier if you are running on anything other than a single defined computer spec. For a quadrant layout the grid manager is probably the best option. Simply define a 2x2 grid and put the frames/widgets in that. However even using pack its easy enough, just define two frames, top and bottom. insert two frames(left and right) into reach of those two frames. This gives you 6 frames in total. HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
Terry Carroll wrote: > I want to see if I'm reinventing a wheel here, or maybe doing it > unpythonically. > > I need to extract from a byte (i.e., a one-character string) a field of an > certain number of bits. For example, a certain byte of an MP3 frame > header has the format xxxVVxxx, where the value of VV (00, 01, 10 or 11) > tels what version of MPEG Audio is being used. The other bits marked 'x' > are not relevant to the version id, and may be 1s or 0s. > > Here's my stab: > > def getbits(byte, fieldlength, rightpad): > ''' > returns an integer with the value derived from a string of bits of > length fieldlength, right-padded with rightpad number of bits. > e.g., getbyte(byte, 2, 3) returns a value from bits 3-4 > (counting from the right) > ''' > bitmask = (2**fieldlength-1) << rightpad > return (ord(byte) & bitmask) >> rightpad > > testbytes = ["\xC0", "\x08", "\xF0", "\x19"] > for byte in testbytes: > print getbits(byte, 2, 3) > # should get 0, 1, 2, 3 > > > This works (at least for these 4 test cases). But is this the best way to > extract a bit-level field, or am I missing some appropriate module or > something? You might be interested in Construct, it aims to make it easy to parse and create structures based on bit fields: http://pyconstruct.wikispaces.com/ It seems to work by assembling a string representing the bit values of the target, then converting to binary. My guess is your method will be faster but Construct looks pretty convenient to work with. If you try it let us know how it goes... Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] laying out a menu widget inside a frame
On Mon, 15 May 2006 18:47:16 -0400 (EDT) "Zubin Wadia" <[EMAIL PROTECTED]> wrote: Hi Zubin, > root.config(relief=RIDGE, bg="lightblue", bd=3) doesn't seem to work it works for me (linux), maybe a platform issue? > I'm not sure if the menu() widget can be packed in a frame container?? > I don't think you can: >>> m=Menu(frame) >>> m.pack(side='top', fill='x') Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 1595, in pack_configure self.tk.call( TclError: can't pack ".135695884.135828540": it's a top-level window It seems like the Pmw.MenuBar widget can do what you want: >>> mb =Pmw.MenuBar(frame) >>> mb.pack(side='top', fill='x') >>> mb.addmenu('File', 'File') >>> adds a menu bar to the Frame, so maybe you will want to have a look at Pmw. I hope this helps Michael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Treeview
Sometimes it's your own problem that is hardest to solve, as you're too familiar with the code. :) Congratulations on making sense of pyGTK, the documentation isn't overly helpful... ...I'm used to the wxPython docs and still got confused with the pyGTK ones. Regards, Liam Clarke On 5/14/06, John CORRY <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > I have managed to find the solution to my problem. > > > > I have defined iter as > > > > Iter = model.get_iter(combo3) > > > > The code now works. I will show it below for completeness: > > > > combo3 = self.wTree.get_widget("treeview1") > > > > model=gtk.TreeStore(gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING) > > self.hostsmodel = model > > combo3.set_model(model) > > combo3.connect("row_activated", self.callback53, combo3,model) > > > > def callback53(self,data,combo3,data2,data3,model): > > > > > > lookup = [] > > > > iter = model.get_iter(combo3) > > counter = 0 > > while counter < 8: > > > > result = model.get_value(iter,counter) > > lookup.append(result) > > counter = counter + 1 > > print lookup > > > > Technically this is the first solution that I have been able to post on the > mailing list. Does this mean I am improving? Or does it not count as I > have solved my own problem? > > > > Regards, > > > > John. > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python new comer
Hey I am currently learning Python to start scripting automated tests. A lot of these tests require me to strip out values from xml docs using the minidom feature. So really I am just looking for any good articles to start learning Python as a whole and to learn about using Python as a node iterator to strip out required info from an xml doc. Thanks k-- "Behind every great man, there is a great woman. Behind that woman is Mr.T." ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python new comer
kieran flanagan wrote: > Hey > > I am currently learning Python to start scripting automated tests. A lot > of these tests require me to strip out values from xml docs using the > minidom feature. So really I am just looking for any good articles to > start learning Python as a whole and to learn about using Python as a > node iterator to strip out required info from an xml doc. Welcome! Have you found the page of beginners' tutorials? http://wiki.python.org/moin/BeginnersGuide/NonProgrammers If you are just starting with Python and XML I recommend ElementTree rather than minidom. It is an add-on module that will be part of the standard library in Python 2.5. http://effbot.org/zone/element-index.htm This page talks about searching an ElementTree for subelements: http://effbot.org/zone/element.htm#searching-for-subelements Ask questions here as needed, we're very friendly! Try to be specific - if you have a question about how to process XML, show a snippet of XML and any code you have tried. If you get an error you don't understand, copy and paste the entire error message into your email. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
Terry, Your approach is fine. Personally however I'd just have defined some constants and done a direct bitwise and - this is the approach used in the stat module: VMASK = 0x14 # 00011000 VER00 = 0x00 VER01 = 0x04 VER10 = 0x10 VER11 = 0x14 version = byte & VMASK if version == VER00: #do something elif version == VER01: # do another etc... But I'm just an old assembler programmer in disguise :-) A function approach is OK too... Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld - Original Message - From: "Terry Carroll" <[EMAIL PROTECTED]> To: Sent: Tuesday, May 16, 2006 6:25 AM Subject: [Tutor] Bit-level field extraction >I want to see if I'm reinventing a wheel here, or maybe doing it > unpythonically. > > I need to extract from a byte (i.e., a one-character string) a field > of an > certain number of bits. For example, a certain byte of an MP3 frame > header has the format xxxVVxxx, where the value of VV (00, 01, 10 or > 11) > tels what version of MPEG Audio is being used. The other bits > marked 'x' > are not relevant to the version id, and may be 1s or 0s. > > Here's my stab: > > def getbits(byte, fieldlength, rightpad): >''' >returns an integer with the value derived from a string of bits > of >length fieldlength, right-padded with rightpad number of bits. >e.g., getbyte(byte, 2, 3) returns a value from bits 3-4 >(counting from the right) >''' >bitmask = (2**fieldlength-1) << rightpad >return (ord(byte) & bitmask) >> rightpad > > testbytes = ["\xC0", "\x08", "\xF0", "\x19"] > for byte in testbytes: >print getbits(byte, 2, 3) ># should get 0, 1, 2, 3 > > > This works (at least for these 4 test cases). But is this the best > way to > extract a bit-level field, or am I missing some appropriate module > or > something? > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question on option parser
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Everyone, I have a program that I'd would like to enhance flexibility in calling. Is there a way to leverage optionparser so it can accept input from both command line and a configuration file? Current code block is: # # Parse command line options and automatically build # help/usage display # parser = OptionParser() parser.add_option("-m","--qmanager", dest="qmanager", help="\t\tQueue Manager to inquire against"), parser.add_option("-q","--queue", dest="queue", help="\t\tQueue the message will be sent to"), parser.add_option("-t","--to", dest="mto", help="\t\taddress any mail messages will be sent to") (options, args) = parser.parse_args() Any help you can provide on this would be greatly appreciated. Thanks, Andy -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (MingW32) iD8DBQFEaf5xDvn/4H0LjDwRAnzAAJ94RcBxTxARkvX5pwMtvVM9n/vntgCfZ1bV FvMSiQpo/2EneM9hvuxpCi8= =2Il4 -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question on option parser
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Kent, If I understood correctly, you meant something like this? # # Parse command line options and automatically build help/usage # display # if len(sys.argv) == 2: infile= open(sys.argv[1],"rb").read() parser=OptionParser() (options, args) = parser.parse_args(infile) else: parser = OptionParser() parser.add_option("-m","--qmanager", dest="qmanager", help="\t\tQueue Manager to inquire against"), parser.add_option("-q","--queue", dest="queue", help="\t\tQueue the message will be sent to"), parser.add_option("-t","--to", dest="mto", help="\t\taddress any mail messages will be sent to") (options, args) = parser.parse_args() print options.qmanager If so, the code generates the following deletion error. Traceback (most recent call last): File "C:\Documents and Settings\Andrew Robert\My Documents\receiver.py", line 326, in ? (options, args) = parser.parse_args(infile) File "C:\Python24\lib\optparse.py", line 1275, in parse_args stop = self._process_args(largs, rargs, values) File "C:\Python24\lib\optparse.py", line 1322, in _process_args del rargs[0] TypeError: object doesn't support item deletion Any ideas? -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (MingW32) iD8DBQFEahcFDvn/4H0LjDwRAkZFAKCGapybjYnhuX9dy1DvMswskawLegCdEbbY o/VaV2WP/ymg3dbwo3TaBi4= =wLEn -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
On Tue, 16 May 2006, Alan Gauld wrote: > Your approach is fine. Personally however I'd just have defined > some constants and done a direct bitwise and - this is the > approach used in the stat module: > > VMASK = 0x14 # 00011000 > VER00 = 0x00 > VER01 = 0x04 > VER10 = 0x10 > VER11 = 0x14 > > version = byte & VMASK > if version == VER00: #do something > elif version == VER01: # do another > etc... Good idea. In this particular case, I actualy need the value, because it's to be used either as a key to a dictionary or a subscript to a list later on; i.e., my if tree would look like this: if version == VER00: ver_num = 0 elif version == VER01: ver_num = 1 elif version == VER02: ver_num = 2 elif version == VER03: ver_num = 3 Actually, the version number doesn't equal the two-bit number; values of 0, 2 and 3 mean versions 2.5, 2 or 1, respectively (1 being reserved), but you get the idea. The key is I need later to be able to use the value itself. But I have a number of other parts of the frame header where the defined constants are a great way to go; thanks. > But I'm just an old assembler programmer in disguise :-) Heh, you and me both. I cut my teeth on IBM System/370 assembler. Last time I had a job where I actually did programming as part of it, it was System/390 machine code. That's right, machine code, not assembler; I'd directly type my hexadecimal programs into low storage at the operator's console. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
On Tue, 16 May 2006, Kent Johnson wrote: > You might be interested in Construct, it aims to make it easy to parse > and create structures based on bit fields: > http://pyconstruct.wikispaces.com/ Thanks, I'll have a look at it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question on option parser
On 16 Mai 2006, [EMAIL PROTECTED] wrote: > Is there a way to leverage optionparser so it can accept input from both > command line and a configuration file? > > Current code block is: > > # > # Parse command line options and automatically build > # help/usage display > # > parser = OptionParser() > parser.add_option("-m","--qmanager", dest="qmanager", > help="\t\tQueue Manager to inquire against"), > parser.add_option("-q","--queue", dest="queue", > help="\t\tQueue the message will be sent to"), > parser.add_option("-t","--to", dest="mto", > help="\t\taddress any mail messages will be sent to") > (options, args) = parser.parse_args() parse_args() can take the list to parse as argument; per default it parses sys.argv[1:]. So you could build a list of options from your config file and call parse_args() like that: (options, args) = parser.parse_args(configlst + sys.argv[1:]) Like that options given on the command line would overwrite options from the config file. Another approach could be to define default values for the variables. Let's take your above example. parser.add_option("-m","--qmanager", dest="qmanager", help="\t\tQueue Manager to inquire against"), parser.add_option("-q","--queue", dest="queue", help="\t\tQueue the message will be sent to"), parser.add_option("-t","--to", dest="mto", help="\t\taddress any mail messages will be sent to") Then you would read the values from the config file and call parser.set_defaults() with the values. parser.set_defaults(qmanager="Foo", queue="Bar", mto="[EMAIL PROTECTED]") Karl -- Please do *not* send copies of replies to me. I read the list ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
On Tuesday 16 May 2006 16:01, Alan Gauld wrote: > Terry, > > Your approach is fine. Personally however I'd just have defined > some constants and done a direct bitwise and - this is the > approach used in the stat module: > > VMASK = 0x14 # 00011000 > VER00 = 0x00 > VER01 = 0x04 > VER10 = 0x10 > VER11 = 0x14 > > version = byte & VMASK > if version == VER00: #do something > elif version == VER01: # do another > Alan Gauld Whoops, a typo I think. VMASK = 0x18 #00011000 orVMASK = 0x14 #00010100 Stan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running Java process doesn't return to subprocess.call (fwd)
-- Forwarded message -- Date: Tue, 16 May 2006 11:50:32 -0700 (PDT) From: Jerome Jabson <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Subject: Re: [Tutor] Running Java process doesn't return to subprocess.call Hi Danny, I actually changed that just before I sent the email to tutor, cause I'd seen a reference on the web about a Java process in Zope hanging. And the fix was to have errfile set to None. It did NOT fix the problem. It actually cause a Java Expection now! :-( The Java program expect nothing from input. So I'm still stumped on why this is hanging. Is there any insight you have on why a Java process would hang like that? I use the same function in other programs and it works just fine. Thanks again for your help! Jerome On Mon, 15 May 2006, Jerome Jabson wrote: > I'm running a Java process from my python script using the subprocess > module. But there seems to be some problem with the return code to > subprocess and the Java program is just hanging waiting for something. Hi Jerome, I see that you're using subprocess.call(): retval = subprocess.call(cmd, 0, None, None,outptr, None) I expected to see some reference to 'errFile' in the call here; otherwise, the java subprocess won't know that you want to dump error output there. Does your Java program expect anything out of standard input as well? Best of wishes! __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Division operation
Hi there, I'm new to Python and programming in general. This is the function I am writing: def function(): x = int(raw_input("Enter value of x: ")) y = int(raw_input("Enter value of y: ")) z = x / y print "The value of z is", z, "unit of measurement" Now, say, user input: x = 200 y = 1000 The value returned will be '0'. My question: What is the proper way of writing the operation so that if z = x /y, the result would be '0.20' instead of just '0'? TIA. -Miguel ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Division operation
On Tue, 16 May 2006, Miguel Estrada wrote: > def function(): > x = int(raw_input("Enter value of x: ")) > y = int(raw_input("Enter value of y: ")) > z = x / y > print "The value of z is", z, "unit of measurement" > > > Now, say, user input: > > x = 200 > y = 1000 > > The value returned will be '0'. > > My question: What is the proper way of writing the operation so that if > z = x /y, the result would be '0.20' instead of just '0'? This is a frustrating design choice in Python, which I believe is on the list of Guido's regrets and will be corrected in Python 3.0. Where both operands are integers, Python division truncates to and integer result, thus: >>> x = 200 >>> y = 1000 >>> z = x/y >>> z 0 But if either operand is a float, you get the results that you'd expect: >>> x = 200.0 >>> y = 1000 >>> z = x/y >>> z 0.20001 >>> (the "00..1" is rounding error from the basic impossibility of representing 1/5 in a binary system) You can include the following in your program (I often do) if you want division to operate the way you expect: >>> from __future__ import division >>> from __future__ import division >>> x = 200 >>> y = 1000 >>> z = x/y >>> z 0.20001 >>> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
> Heh, you and me both. I cut my teeth on IBM System/370 assembler. > Last > time I had a job where I actually did programming as part of it, it > was > System/390 machine code. That's right, machine code, not assembler; > I'd > directly type my hexadecimal programs into low storage at the > operator's > console. Hah, if you haven't bootstrapped a VAX using the toggle switches on the front panel you ain't a real progammer ;-) Actually one of our local Universities still starts their computer science courses by teaching students how to do that, before moving them onto machine code, assembler, C and finally Java(*). It's like an historical tour of computing/programming. The machine code is done on little hex keypads with pocket calculator style printout rools! Its only when they get to C that they get to use a PC! (*) Actually they get to choose from several languages in their 4th (final) year, including Lisp and Prolog(both), Haskell and PL/SQL... They consistently produce very good graduates, so it seems to work. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I create the equivalent of a Java class in Python?
Alan Gauld wrote: > > How do I create the equivalent of a Java class in Python? I've been > looking > > at the reference, and it's been confusing to me at least. > > Adapted from my book: > > Java code: > > class Msg{ >private String txt; >public Msg(String s){ > this.txt = s; >} >public void say(){ > if (this.txt == "") > System.out.println("No message"); > else > System.out.println(this.txt); >} > } > > Python code: > > class Msg: >def __init__(self,s): > self.s = s >def say(self): > if self.s: print "No message" > else: print self.s > > Does that help? > There is more on writing classes in the OOP topic of my tutor. > > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > Erm. Shouldn't that be the following? class Msg: def __init__(self,s): self.s = s def say(self): if *not *self.s: print "No message" else: print self.s -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Division operation
> You can include the following in your program (I often do) if you > want > division to operate the way you expect: > from __future__ import division > Or you can do an explicit float conversion inside your function if you don't want the import effect. def f(x,y): returm float(x)/y This issue is discussed in the Simple Sequences topic of my tutor. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
>> VMASK = 0x14 # 00011000 > > Whoops, a typo I think. VMASK = 0x18 #00011000 > orVMASK = 0x14 #00010100 A typo is being kind. A mistake in reality, that's what happens when I don't have a Python session handy! :-) Fortunately Terry knew what I meant. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] New programmer, need some help getting started on my first project
Hello all, I have been studying python tutorials and have a couple beginning python books that I have worked through. I have a very specific project in mind and I want to ask a couple questions. The project in question is this:I am making a Hand History converter for online poker players. This takes the textual record of how a hand played and turns into a more readable format suitable for posting at various websites where people discuss how the hand was played. Id like to start with the converter working for one particular online poker site (every site formats their hand histories somewhat differently) and expand it so that it can recognize the site a hand history came from and format accordingly. So, I am pretty sure that regular expressions will play a big part in the functions in this program. Also, the converter needs to be able to pull dollar amounts out and add them up to keep a running pot size for each round of betting. I guess I am really unsure of how to start. Ive sort of drawn out how I think the program should flow. I know this is sort of an open ended question and I hope it is appropriate for the list. What would really be helpful is if someone was willing to correspond privately since Im sure I will have a flood of questions but I realize you all have lives and so this might not be desireable or doable. But if anyone is willing, it would be really helpful. Ive been lurking for a few days now and this seems like a very friendly and helpful group. Thanks for taking the time to read this and I look forward to reading your replies, should anyone decide to do so. ChrisPS I should add that some of these "converters" already exist, I have the perl script for one but the site I currently play on isnt supported and plus I just want to do this. :) Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running Java process doesn't return to subprocess.call (fwd)
> I actually changed that just before I sent the email to tutor, cause I'd > seen a reference on the web about a Java process in Zope hanging. And > the fix was to have errfile set to None. It did NOT fix the problem. It > actually cause a Java Expection now! :-( Hi Jerome, [Please keep tutor@python.org in CC; I'm about to dive into a situation (grad school) where I may not be able to answer Tutor mail for a while. It's best to keep the discussion within the mailing list. That way, other folks can help too, and we avoid a single-point-of failure: me. *grin* As another meta note to the others here on Tutor: since I might be gone for a bit, the current plan is to pass the administrative reins to Kent Johnson.] Do you mind if you show the exception traceback to us on the list? That's a significant change in behavior, and an unexpected one! Let's look the error there more closely. > The Java program expect nothing from input. So I'm still stumped on why > this is hanging. Is there any insight you have on why a Java process > would hang like that? I use the same function in other programs and it > works just fine. Odd. Does this happen to all Java programs you run through Python's subprocess module, or is it exclusive to the program that you are running now? What happens if you do run something silly and simple like: /*** Java code ***/ public class Test { static public void main(String[] args) { System.out.println("Hello world"); } } // For you, does subprocess also freeze here when it tries to drive this Test class too? I have to admit that I'm very ignorant about what's happening here. *grin* I think we need to isolate the issue better. You mentioned that subprocess-ing other programs seems fine, so one natural question follows: is it Java itself that's doing something funky, or is it something particular to the particular Java program we're driving? Let's do a little more work to find what the real issue is. Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I create the equivalent of a Java class in Python?
> Erm. Shouldn't that be the following? > > class Msg: > def __init__(self,s): > self.s = s > def say(self): > if *not *self.s: print "No message" > else: print self.s Yep, its my week for making mistakes. Although this one was just a typo... My only excuse is that I'm really busy with my project at work just now so not really checking the tutor code... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New programmer, need some help getting started on my first project
> I am making a Hand History converter for online poker players. > This takes the textual record of how a hand played and turns > into a more readable format suitable for posting at various websites > where people discuss how the hand was played. Id like to start > with the converter working for one particular online poker site > (every site formats their hand histories somewhat differently) > and expand it so that it can recognize the site a hand history > came from and format accordingly. I don't know anything about poker but in general terms this is a text format conversion tool. since you know the source can be in different formats I'd adopt an OOP approach with a generic hand object which can be subclassed for each new format. The methods of the hand object might be something like load() and print(). The load method will be specific to each site and will convert the site format to some standard format defined in the generic hand. The print method then prints to a standard output format and only needs overriding for sites where you need a different output format - which sounds to be rare from your desciption. The generic hand class then allows you to write the resty of the application in a generic way without worrying about site details apart from the point where you instantiate the hands - and even that can be data driven via an external file or environment variable etc.. > So, I am pretty sure that regular expressions will play > a big part in the functions in this program. Possibly but I would defer that decision for as long as possible! > Also, the converter needs to be able to pull dollar amounts > out and add them up to keep a running pot size for each > round of betting. You may need a pot class in the same way as the hand above - but I'm not sure how that would workj since I don't know anything about poker! > really be helpful is if someone was willing to correspond > privately since Im sure I will have a flood of questions It would be more helpful - to you and the rest of the readership - if you keep it public. The kind of questions you will be asking are likely to be the kind any newbie will come across in a real project. By sharing the pain you also share the experience. You also get access to many more heads. > PS I should add that some of these "converters" already exist, > I have the perl script for one but the site I currently play on > isnt supported and plus I just want to do this. :) Converting the Perl into Python shouldn't be too hard when we get to the stage of needing to do that. For now let's start with one site and get it working, while building in enough flexibility for the future sites we know we need to deal with later. In fact maybe we should start at the end and work on the internal data structure needed to print out the final format. Can we define a program that can read the target format in and print oit out in the desired format? It may sound trivial but it gets a lot of the scaffolding in place early. Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Solution found for option parser
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi everyone, Just to be complete, I figured I would share the solution to use option parser for both command line and configuration file option passing. I hope it may be of use to someone in the future. parser = OptionParser() if len(sys.argv) == 2: lines = open(sys.argv[1],"rb").readlines() for line in lines: line=line.strip() if not line: continue short, long, dest, help, default = line.split(";") help = "\t\t" + help # Prepend tabs to help message parser.add_option(short, long, dest=dest, help=help, default=default) else: parser.add_option("-m","--qmanager", dest="qmanager", help="\t\tQueue Manager to inquire against"), parser.add_option("-q","--queue", dest="queue", help="\t\tQueue the message will be sent to"), parser.add_option("-d","--dest", dest="dest", help="\t\tDestination File Name"), parser.add_option("-f", "--file", action="store", type="string", dest="filename", help="File to be transmitted", metavar="FILE") (options, args) = parser.parse_args() thanks all for the insight -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (MingW32) iD8DBQFEanTrDvn/4H0LjDwRAmt0AJ4jf84OXoNdrxzz+A/pdKgiPnhyAwCfZQrG QCuhjN8sbYq+WhzmLToKIZs= =nOFN -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New programmer, need some help getting started on my first project
Alan, First off, thanks for the detailed reply, it is much appreciated. On to your message:>I don't know anything about poker but in general terms this is>a text format conversion tool. since you know the source can>be in different formats I'd adopt an OOP approach with a generic>hand object which can be subclassed for each new format.>The methods of the hand object might be something like load()>and print(). The load method will be specific to each site and>will convert the site format to some standard format defined>in the generic hand. The print method then prints to a standard>output format and only needs overriding for sites where you>need a different output format - which sounds to be rare from>your desciption.>The generic hand class then allows you to write the resty>of the application in a generic way without worrying about>site details apart from the point where you instantiate the>hands - and even that can be data driven via an external file>or environment variable etc..Well, I thought this would be the right approach to take given where I ultimately want to go with this. Im glad that I was thinking about this in the correct fashion. >Possibly but I would defer that decision for as long as possible!Hmm can you elaborate on this? (re: regular expressions) >You may need a pot class in the same way as the hand>above - but I'm not sure how that would workj since I don't>know anything about poker!Quickly on the format of the form of poker that I play most: No Limit Texas Hold'emEach player is dealt 2 cards face down. There are 2 forced bets called the Small Blind and Big Blind. Each player, starting to the left of the blinds can fold, call, or raise any amount. Once the action is complete, 3 cards are dealt face up(these are community cards, and are used in conjunction with the players' hole cards to make their best hand), and the betting action repeats itself, only now the Small Blind acts first. Another card is dealt face up if there 2 or more players left and the betting action occurs again. Once the action is complete then a final card is dealt and the action repeats. The remaining players then showdown their hands and the best 5 card hand wins. So a pot class would have to be able to extract the dollar amounts from each round of betting and then sum them after each betting round. This is important for talking about how hands play out, but I wont talk about why unless you are just interested. >It would be more helpful - to you and the rest of the>readership - if you keep it public. The kind of questions you>will be asking are likely to be the kind any newbie will come>across in a real project. By sharing the pain you also share>the experience. You also get access to many more heads.Thank you. I hoped to discuss it via the list but didnt want to spam the list unnecessarily. >Converting the Perl into Python shouldn't be too hard when>we get to the stage of needing to do that. For now let's start>with one site and get it working, while building in enough>flexibility for the future sites we know we need to deal with later.I just wanted to let you know that I had one in case anyone was interested in working version. Here is an interesting thing. All the converters that I know of are not stand alone apps. They are tied to forms on websites where people input their hands and then take the output to post on various popular internet poker web forums. I can provide links if anyone is interested. I wasnt necesarily wanting to convert the script, that feels a bit like cheating. >In fact maybe we should start at the end and work on the>internal data structure needed to print out the final format.>Can we define a program that can read the target format>in and print oit out in the desired format? It may sound trivial>but it gets a lot of the scaffolding in place early.I was very very happy to read this Alan. I was going to ask you in my original email if I should start with the output and work backwards. It actually gives me a lot of confidence that I seem to be thinking along the right lines here. I will start working on that and provide the list with my work on that. Thanks again Alan.Cheers, Chris Blab-away for as little as 1¢/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python simulations - saving state
Hi, I am fairly new to programming in python, but for work I am running a simulation of a distribution center. What I am trying to do now is to save the state of the simulation (i.e. the event list and any other necessary variables) so that it can be "restored" later. I eventually want to be able to save the state of the simulation and restart it as well as being able to save periodically and change the event list for changes in the simulation (i.e. for a distribution center if a truck is running late and will not be arriving on time I would need to modify it's arrive time and see how that would change the execution of the rest of the simulation). I have found I can't pickle _e (the event list) and I was wondering what suggestions you could give or where I could go to get more help on this topic. Thanks, Sarah Moody ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python simulations - saving state
Depends, you can pickle the list, but all objects need to be pickleable, maybe you can put up with this requeriment by changing your events to be pickleable?, but i don't know what data you store in a event or what kind of data is it. Regards On 5/16/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > I am fairly new to programming in python, but for work I am running a > simulation > of a distribution center. What I am trying to do now is to save the state of > the simulation (i.e. the event list and any other necessary variables) so that > it can be "restored" later. I eventually want to be able to save the state of > the simulation and restart it as well as being able to save periodically and > change the event list for changes in the simulation (i.e. for a distribution > center if a truck is running late and will not be arriving on time I would > need > to modify it's arrive time and see how that would change the execution of the > rest of the simulation). > > I have found I can't pickle _e (the event list) and I was wondering what > suggestions you could give or where I could go to get more help on this topic. > > Thanks, > Sarah Moody > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] about calling external program in Python
Dear all, I'm trying to call an executable program in Python. I did the following, but it doesn't work. Any help is appreciated. os.system('C:\Program Files\EPANET2\epanet2d.exe C:\simulation test\Network3_1.inp C:\simulation test\Network3_1.out') Thanks. J. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor