Re: [Tutor] about calling external program in Python
> 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:\simulationtest\Network3_1.out') try putting an "r" in front of the string, i.e. os.system(r'C:.). you mentioned "it doesn't work." what do you mean by that? in other words, what did the Python interpreter do... give an error, nothing, etc.? thanks, -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ 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
Chris Delgado wrote: > 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. I would pick one input format and work on a program that reads it and generates some kind of events for everything significant that happens. At first the events could be just print statements, later they can reformat the data to the required output format. From your description it sounds like there is no need to create an internal data format that holds all the data for a hand. A simple loop to read an event, parse the event and output it in the new format might be enough. It would help a lot to see some sample data. For a project of this (small) scale I don't do much design ahead of time, I let the design emerge from the code as I solve the problem. I would start by writing the simplest program that could possibly work to convert a single format. When that is working then look at what is needed to add a format. This will probably involve some refactoring, introducing functions or classes that are specific to your problems. When you have two or three formats working you should have a tool set that will make subsequent formats easier. If the data format is complex a parsing library like pyparsing might be helpful. But without seeing some data and trying to parse it there is no way to know. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python simulations - saving state
[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. What error do you get when you try to pickle _e? You might me interested in SimPy, it seems well suited for this kind of simulation: http://simpy.sourceforge.net/ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [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') My first guess: you need quotes around paths with spaces in the names. Alan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] about calling external program in Python
Does it return any error message?? From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mu Mu Sent: Wednesday, May 17, 2006 11:47 AM To: Tutor@python.org Subject: [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
Re: [Tutor] about calling external program in Python
> os.system('C:\Program Files\EPANET2\epanet2d.exe > C:\simulation test\Network3_1.inp C:\simulation > test\Network3_1.out') have you tried the following? os.system('"C:\Program Files\EPANET2\epanet2d.exe" "C:\simulation test\Network3_1.inp" "C:\simulation test\Network3_1.out'"') -- Gabriel Dain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Sending e-mail msg
I'm trying to set up a routine to send customized e-mail messages from records in a database. My first step is trying to send one simple e-mail message. After I get that figured out, I can move on to step 2. Unfortunately, when I try the example code in the tutorials for sending e-mail, I get error messages which I am unsure how to interpret. The code I use is: import smtplib fromaddr = "[EMAIL PROTECTED]" toaddrs = "[EMAIL PROTECTED]" # Add the From: and To: headers at the start! msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, toaddrs)) msg = msg + "This is a test message" print "Message = " + msg print "Message length is " + repr(len(msg)) server = smtplib.SMTP('mail.hennepinPublicHealth.org') server.set_debuglevel(1) server.sendmail(fromaddr, toaddrs, msg) server.quit() *** The output I get is: Message = From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] This is a test message Message length is 89 Traceback (most recent call last): File "J:/SPSS/Python/EMailExample.py", line 14, in -toplevel- server = smtplib.SMTP('mail.hennepinPublicHealth.org') File "C:\Program Files\Python\lib\smtplib.py", line 244, in __init__ (code, msg) = self.connect(host, port) File "C:\Program Files\Python\lib\smtplib.py", line 307, in connect (code, msg) = self.getreply() File "C:\Program Files\Python\lib\smtplib.py", line 348, in getreply line = self.file.readline() File "C:\Program Files\Python\lib\socket.py", line 340, in readline data = self._sock.recv(self._rbufsize) error: (10054, 'Connection reset by peer') *** I also tried: server = smtplib.SMTP('localhost') with the same result. I have checked several of the tutorials and FAQ sites and the impression that's given is that this functionality is quite simple, so I assume that I'm just missing one small step. Any suggestion would be much appreciated. Thank you. Urban Landreman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
On Tuesday 16 May 2006 22:41, Alan Gauld wrote: > > 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 You chaps are making me nostalgic; days of the 8080A/Z80/F8/6800 when I built my first computer. In those days 2K of memory was considered large for a personal computer. Stan. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sending e-mail msg
On Wed, 2006-05-17 at 10:03 -0500, URBAN LANDREMAN wrote: > I'm trying to set up a routine to send customized e-mail messages from > records in a database. > My first step is trying to send one simple e-mail message. After I get that > figured out, I can move on to step 2. > > Unfortunately, when I try the example code in the tutorials for sending > e-mail, I get error messages which I am unsure how to interpret. > > The code I use is: > import smtplib > > fromaddr = "[EMAIL PROTECTED]" > toaddrs = "[EMAIL PROTECTED]" > # Add the From: and To: headers at the start! > msg = ("From: %s\r\nTo: %s\r\n\r\n" >% (fromaddr, toaddrs)) > msg = msg + "This is a test message" > > print "Message = " + msg > print "Message length is " + repr(len(msg)) > > server = smtplib.SMTP('mail.hennepinPublicHealth.org') > server.set_debuglevel(1) > server.sendmail(fromaddr, toaddrs, msg) > server.quit() > *** > > The output I get is: > > Message = From: [EMAIL PROTECTED] > > To: [EMAIL PROTECTED] > > > > This is a test message > Message length is 89 > > Traceback (most recent call last): > File "J:/SPSS/Python/EMailExample.py", line 14, in -toplevel- > server = smtplib.SMTP('mail.hennepinPublicHealth.org') > File "C:\Program Files\Python\lib\smtplib.py", line 244, in __init__ > (code, msg) = self.connect(host, port) > File "C:\Program Files\Python\lib\smtplib.py", line 307, in connect > (code, msg) = self.getreply() > File "C:\Program Files\Python\lib\smtplib.py", line 348, in getreply > line = self.file.readline() > File "C:\Program Files\Python\lib\socket.py", line 340, in readline > data = self._sock.recv(self._rbufsize) > error: (10054, 'Connection reset by peer') 'Connection reset by peer' This occurs when a connection is terminated without going through the normal TCP close procedure. If localhost is giving you the same behavior, you should be able to learn why from your logs. Your code looks OK. I would expect that the issue lies with your network config or firewall(s). That mail server was happy to accept a connection from me, so I doubt if the problem is at the server. >>> import smtplib >>> c = smtplib.SMTP('mail.hennepinPublicHealth.org') >>> dir(c) ['__doc__', '__init__', '__module__', 'close', 'connect', 'data', 'debuglevel', 'docmd', 'does_esmtp', 'ehlo', 'ehlo_resp', 'esmtp_features', 'expn', 'file', 'getreply', 'has_extn', 'helo', 'helo_resp', 'help', 'local_hostname', 'login', 'mail', 'noop', 'putcmd', 'quit', 'rcpt', 'rset', 'send', 'sendmail', 'set_debuglevel', 'sock', 'starttls', 'verify', 'vrfy'] >>> c.close() > > *** > I also tried: > server = smtplib.SMTP('localhost') > > with the same result. > > I have checked several of the tutorials and FAQ sites and the impression > that's given is that this functionality is quite simple, so I assume that > I'm just missing one small step. > > Any suggestion would be much appreciated. > > Thank you. > Urban Landreman > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] unpacking PyTime
Hi I am using the Win32com library to pick up data from an EXCEL spreadsheet but am having trouble with dates. I want to convert a date read from the XL sheet into a float using this snippet from win32com.client import dispatch import time xlFile="test.xls" xlApp=Dispatch("Excel.Application") xlApp.Workbooks.Open(xlFile) xlSht=xlApp.Worksheets("data") # OK so far but the problem comes now ... curr_date=xlSht.Cells(1,3).Value # returns PyTime Not how to get the date (as either yy,mm,dd or a single number aka XL). The ASPN ActivePython site suggests using x=curr_date.__float__() but Python gives the error "AttributeError: __float__" I also tried x=float(curr_date) but Python gives the error "TypeError: float() argument must be string or a number". All suggestions gratefully received! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] about calling external program in Python
Dear all, I tried the following: >>> os.system(r'C:\\simulation test\\epanet2d.exe C:\\simulation test\\Network3_1.inp C:\\simulation test\\Network3_1.out')1>>> os.system('C:\simulation test\epanet2d.exe C:\simulation test\Network3_1.inp C:\simulation test\Network3_1.out') 1>>> os.system(r'C:\simulation test\epanet2d.exe C:\simulation test\Network3_1.inp C:\simulation test\Network3_1.out')1>>> os.system(r'"C:\simulation test\epanet2d.exe" "C:\simulation test\Network3_1.inp" "C:\simulation test\Network3_1.out"') 1 They all returned '1' in the interactive window and gave no result in the designated output folder. All I saw is a flash of the ms-dos black window and then disappeared. I tried ms-dos command line, it works pretty good. Thanks. J. On 5/17/06, w chun <[EMAIL PROTECTED]> wrote: > 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:\simulationtest\Network3_1.out')try putting an "r" in front of the string, i.e. os.system (r'C:.).you mentioned "it doesn't work." what do you mean by that? in otherwords, what did the Python interpreter do... give an error, nothing,etc.?thanks,-wesley- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.comwesley.j.chun :: wescpy-at-gmail.com python training and technical consultingcyberweb.consulting : silicon valley, cahttp://cyberwebconsulting.com___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
S W Collier wrote: > You chaps are making me nostalgic; days of the 8080A/Z80/F8/6800 when > I built my first computer. In those days 2K of memory was considered > large for a personal computer. > In 1975 Boeing Computer Services proudly announced the addition of 4 megabytes of memory to one of its IBM Mainframes runnuig VM, at a cost over $100,000! At least that reduced the spooling of virtual memory to the card punch/reader. ;-) -- Bob Gailer 510-978-4454 ___ 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: > Hah, if you haven't bootstrapped a VAX using the toggle switches on > the front panel you ain't a real progammer ;-) Not with a VAX, but I had to do that with a TI-980, long, long ago! And once I had it booted, because the assembler was a pretty primitive two-pass assembler, I had to run my punched cards through twice. But at least I got to use punched cards. I forget what the other system we had in that room was, but I had to use paper tape on that one. > 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 They consistently produce > very good graduates, so it seems to work. I wonder if the results are good because it's an effective teaching method, of because it culls out the faint-of-heart right up front! > 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! A couple years ago, I took a course in which I built my own computer. And I mean built. The individual chips (CPU, RAM, resistors, etc.) were off-the-shelf components, but that's it. I soldered every lead and wire-wrapped every wire on that thing, build on a breadboard. It was very primitive: its only input devices were an 8-bit DIP switch and thermometer sensor chip (and a flashable EEPROM to hold the OS/program, if you count that as an input device); and its only output devices a couple of seven-segment LED displays; but it sure taught the hard-core hardware. I didn't actually need it for the subject matter taught; but I'm planning on taking the patent agent's exam, and the US patent and trademark office insisted I shore up my academic credentials with a few additional physics courses (the course was actually about physic laboratory instrumentation). It was quite a bit of fun, though. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unpacking PyTime
Etrade Griffiths wrote: > Hi > > I am using the Win32com library to pick up data from an EXCEL spreadsheet > but am having trouble with dates. I want to convert a date read from the > XL sheet into a float using this snippet > > from win32com.client import dispatch > import time > > xlFile="test.xls" > xlApp=Dispatch("Excel.Application") > xlApp.Workbooks.Open(xlFile) > xlSht=xlApp.Worksheets("data") > > # OK so far but the problem comes now ... > > curr_date=xlSht.Cells(1,3).Value # returns PyTime > > Not how to get the date (as either yy,mm,dd or a single number aka > XL). The ASPN ActivePython site suggests using > It appears that the ActivePython docs may be wrong, as the only method I see for a PyTime object is Format. Looking up Format leads to curr_date.Format("%y,%m,%d") to get yy,mm,dd. Or you can, as the ActivePython docs suggest, use int(curr_date) to get an integer value which you can then float. -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bit-level field extraction
> But at least I got to use punched cards. I forget what the other > system > we had in that room was, but I had to use paper tape on that one. I've never actually used punch cards. But I have used punch tape. Where a loop really was a loop! :-) We used them to transmit source code from our punch tape writer at high school to the local university mainframe. It ran the programs overnight and they posted back all the output in an envelope which we received 2 days later - the edit-run-debug cycle-time encouraged very rigorous code reviews!! You don't want to wait 3 days to discover a syntax error in line 1. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] about calling external program in Python
"Mu Mu" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I tried the following: > >>> os.system(r'C:\\simulation test\\epanet2d.exe C:\\simulation > test\\Network3_1.inp C:\\simulation test\\Network3_1.out') > 1 Any non zero return value means that an error occurred. The os.system call worked and the OS returned an error, which usually means you got a path wrong or the user running puython doesn't have access rights to the executable. > They all returned '1' in the interactive window and gave no result > in the > designated output folder. All I saw is a flash of the ms-dos black > window > and then disappeared. > > I tried ms-dos command line, it works pretty good. What happens if you try it from the Start->Run dialog? The CMD box may have some environment settings that are missing when Python runs. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] about calling external program in Python
I redid the following: import osimport syssys.path.append('C:\Program Files\EPANET2')os.system('epanet2d.exe C:\simulation_test\Network3_1.inp C:\simulation_test\Network3_1.out') and safed this as test.py In the Pythonwin interface to run. I got nothing. Then I added 'C:\Program Files\EPANET2' into the system path. In the cmd line: I typed python c:\test.py. It ran and then gave the output. Don' t know why command line works. but pythonwin interface failed . Thanks. J. On 5/17/06, Alan Gauld <[EMAIL PROTECTED]> wrote: "Mu Mu" <[EMAIL PROTECTED]> wrote in messagenews:[EMAIL PROTECTED] ...> I tried the following:> >>> os.system(r'C:\\simulation test\\epanet2d.exe C:\\simulation> test\\Network3_1.inp C:\\simulation test\\Network3_1.out')> 1Any non zero return value means that an error occurred. The os.system call worked and the OS returned an error, whichusually means you got a path wrong or the user running puythondoesn't have access rights to the executable.> They all returned '1' in the interactive window and gave no result > in the> designated output folder. All I saw is a flash of the ms-dos black> window> and then disappeared.>> I tried ms-dos command line, it works pretty good.What happens if you try it from the Start->Run dialog? The CMD box may have some environment settings that are missingwhen Python runs.Alan G.___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unpacking PyTime
Bob I was looking at http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/PyTime.html To my untrained eye it looks like there are a number of functions for PyTime objects (eg __int__, __hash__ etc). However, I tried int(curr_date) and it seems to work OK - thanks! At 19:11 17/05/2006, Bob Gailer wrote: >Etrade Griffiths wrote: >>Hi >> >>I am using the Win32com library to pick up data from an EXCEL spreadsheet >>but am having trouble with dates. I want to convert a date read from the >>XL sheet into a float using this snippet >> >>from win32com.client import dispatch >>import time >> >>xlFile="test.xls" >>xlApp=Dispatch("Excel.Application") >>xlApp.Workbooks.Open(xlFile) >>xlSht=xlApp.Worksheets("data") >> >># OK so far but the problem comes now ... >> >>curr_date=xlSht.Cells(1,3).Value # returns PyTime >> >>Not how to get the date (as either yy,mm,dd or a single number aka >>XL). The ASPN ActivePython site suggests using >> >It appears that the ActivePython docs may be wrong, as the only method I >see for a PyTime object is Format. Looking up Format leads to >curr_date.Format("%y,%m,%d") to get yy,mm,dd. > >Or you can, as the ActivePython docs suggest, use int(curr_date) to get an >integer value which you can then float. > >-- >Bob Gailer >510-978-4454 ___ 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
Kent, Thanks for the reply."I would pick one input format and work on a program that reads it and generates some kind of events for everything significant that happens. At first the events could be just print statements, later they can reformat the data to the required output format. From your description it sounds like there is no need to create an internal data format that holds all the data for a hand. A simple loop to read an event, parse the event and output it in the new format might be enough. It would help a lot to see some sample data.For a project of this (small) scale I don't do much design ahead of time, I let the design emerge from the code as I solve the problem. I would start by writing the simplest program that could possibly work to convert a single format. When that is working then look at what is needed to add a format. This will probably involve some refactoring, introducing functions or classes that are specific to your problems. When you have two or three formats working you should have a tool set that will make subsequent formats easier.If the data format is complex a parsing library like pyparsing might be helpful. But without seeing some data and trying to parse it there is no way to know."Here is a sample hand history. Failure To Launch 8161071-72989 Holdem No Limit $0.50/$1[May 17 03:26:33] : Hand Start.[May 17 03:26:33] : Seat 1 : bnb3 has $92.50[May 17 03:26:33] : Seat 2 : pineaa has $15.25[May 17 03:26:33] : Seat 3 : prowlerslim has $107.50[May 17 03:26:33] : Seat 4 : Marcelluz has $174.74[May 17 03:26:33] : Seat 5 : texredfsh has $35.25[May 17 03:26:33] : Seat 6 : aloo has $98.37[May 17 03:26:33] : aloo is the dealer.[May 17 03:26:34] : bnb3 posted small blind.[May 17 03:26:34] : pineaa posted big blind.[May 17 03:26:34] : Game [72989] started with 6 players.[May 17 03:26:34] : Dealing Hole Cards.[May 17 03:26:34] : Seat 3 : prowlerslim has Ah Kc[May 17 03:26:38] : prowlerslim called $1 and raised $4[May 17 03:26:41] : Marcelluz folded.[May 17 03:26:44] : texredfsh called $5[May 17 03:26:46] : aloo called $5[May 17 03:26:49] : bnb3 folded.[May 17 03:26:52] : pineaa folded.[May 17 03:26:53] : Dealing flop.[May 17 03:26:53] : Board cards [Kd Td 5d][May 17 03:27:01] : prowlerslim bet $10[May 17 03:27:04] : texredfsh called $10[May 17 03:27:06] : aloo folded.[May 17 03:27:07] : Dealing turn.[May 17 03:27:07] : Board cards [Kd Td 5d 3c][May 17 03:27:14] : prowlerslim bet $21[May 17 03:27:19] : texredfsh folded.[May 17 03:27:20] : prowlerslim wins $34.75 as the last player standing[May 17 03:27:22] : Hand is over.Im trying to work this out as we speak but not getting too far at the moment. I'll keep plugging along Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] about calling external program in Python
I think you may be confiused about sys.path. import os import sys sys.path.append('C:\Program Files\EPANET2') os.system('epanet2d.exe C:\simulation_test\Network3_1.inp C:\simulation_test\Network3_1.out') -- sys.path is the path that Python uses to look for python modules. It has nothing to do with the PATH environment variable used by the OS to find executables. > In the Pythonwin interface to run. I got nothing. > Then I added 'C:\Program Files\EPANET2' into the system path. Do you mean the OS system PATH? > In the cmd line: I typed python c:\test.py. It ran and then gave the > output. > Don' t know why command line works. but pythonwin interface failed . If you are doing what I think rthen Pythonwin doesn't see the PATH but The cmd line will use the PATH environment variable to find the executable. 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
Chris Delgado wrote: > Here is a sample hand history. > > Failure To Launch 8161071-72989 Holdem No Limit $0.50/$1 > [May 17 03:26:33] : Hand Start. > [May 17 03:26:33] : Seat 1 : bnb3 has $92.50 > [May 17 03:26:33] : Seat 2 : pineaa has $15.25 > [May 17 03:26:33] : Seat 3 : prowlerslim has $107.50 > [May 17 03:26:33] : Seat 4 : Marcelluz has $174.74 > [May 17 03:26:33] : Seat 5 : texredfsh has $35.25 > [May 17 03:26:33] : Seat 6 : aloo has $98.37 > [May 17 03:26:33] : aloo is the dealer. > [May 17 03:26:34] : bnb3 posted small blind. > [May 17 03:26:34] : pineaa posted big blind. > [May 17 03:26:34] : Game ...etc > > Im trying to work this out as we speak but not getting too far at the moment. > I'll keep plugging > along OK, just looking at this, I'm guessing that you might want some kind of data to represent the players, maybe something to represent the pot, maybe something to represent the cards on the table. It really depends on what kind of output you want to get from this. Can you post an example of the desired output? I can see sort of an event-driven parser where each line is an input event. You could have a list of pairs of regular expressions and functions. The code would run down the list of regexes, if one matches, call the function passing it the match object. The function parses the specific line and calls an event handler in an output object. By separating the parser from the output handler, you can write a new parser for a different input format and (in theory) use the same output handler. It's easier to show than to explain. Here is a simple example to parse the data above: import re class Handler(object): ''' This class receives parsed events. It creates any needed data structures and writes the desired output format. This class is independent of the source format. This version just prints the events; the real Handler will be more interesting. ''' def start(self): print 'Game started' def assign_seat(self, num, name, amt): print '%s in seat %s has $%.2f' % (name, num, amt) def set_dealer(self, dealer): print 'dealer is %s' % dealer def set_big_blind(self, player): print 'big blind is %s' % player def set_small_blind(self, player): print 'small blind is %s' % player class Parser(object): ''' This class parses the source data. It interprets the data and generates callback events to the output handler. This class doesn't know anything about the output format. ''' def __init__(self, handler): self.handler = handler self.regexes = [ (r'Hand Start', self.start), (r'Seat (\d+) : (\w+) has \$([\d.]+)', self.assign_seat), (r'(\w+) is the dealer', self.set_dealer), (r'(\w+) posted small blind', self.set_small_blind), (r'(\w+) posted big blind', self.set_big_blind), ] def parse(self, lines): for line in lines: for regex, func in self.regexes: match = re.search(regex, line) if match: func(match) def start(self, match): self.handler.start() def assign_seat(self, match): num, name, dollars = match.group(1, 2, 3) num = int(num) dollars = float(dollars) self.handler.assign_seat(num, name, dollars) def set_dealer(self, match): self.handler.set_dealer(match.group(1)) def set_small_blind(self, match): self.handler.set_small_blind(match.group(1)) def set_big_blind(self, match): self.handler.set_big_blind(match.group(1)) # Some test data data = '''Failure To Launch 8161071-72989 Holdem No Limit $0.50/$1 [May 17 03:26:33] : Hand Start. [May 17 03:26:33] : Seat 1 : bnb3 has $92.50 [May 17 03:26:33] : Seat 2 : pineaa has $15.25 [May 17 03:26:33] : Seat 3 : prowlerslim has $107.50 [May 17 03:26:33] : Seat 4 : Marcelluz has $174.74 [May 17 03:26:33] : Seat 5 : texredfsh has $35.25 [May 17 03:26:33] : Seat 6 : aloo has $98.37 [May 17 03:26:33] : aloo is the dealer. [May 17 03:26:34] : bnb3 posted small blind. [May 17 03:26:34] : pineaa posted big blind. [May 17 03:26:34] : Game '''.splitlines() # Make a handler handler = Handler() # Make a parser and feed it the data Parser(handler).parse(data) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tutor FAQ
Here's a small batch of questions/answers for the tutor FAQ. Let me know if you have any corrections or clarifications. I'll post them to the web site in a couple of days. Mike - How much code should I post? Post as much relevent code as you can. However, the consensus seems to be that the more code you post, the less likely you'll get someone to review it. A max of 100 lines is suggested. If you have more code, you might post your code at http://www.rafb.net/paste or a similar site. - How do I dynamically name my objects? How do I name my objects based on user input? Rather than performing voodoo by dynamically creating variables, your best bet is to use a dictionary with the keys being the name of the object or user input and the values being the objects. - Why doesn't my special method add, init, or cmp.. work? Remember to use two underscores before and after the method name __add__, __init__, __cmp__. ___ 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
Kent,>OK, just looking at this, I'm guessing that you might want some kind of >data to represent the players, maybe something to represent the pot, >maybe something to represent the cards on the table. It really depends >on what kind of output you want to get from this. Can you post an >example of the desired output?Here is an example of the type of output I am looking for. First here is the hand history I used(slightly different then the othe format I showed you)* Hand History for Game 3736569968 *$100 NL Texas Hold'em - Monday, March 13, 22:21:11 ET 2006Table Table 97262 (No DP) (Real Money)Seat 4 is the buttonTotal number of players : 6Seat 2: xxxdoinkxxx ( $133.90 )Seat 3: zinc25 ( $57.08 )Seat 4: UltimateGW ( $143.50 )Seat 6: Dewez ( $101.85 )Seat 1: vulturesrow ( $115.75 )Seat 5: TableATM ( $69 )TableATM posts small blind [$0.50].Dewez is sitting out.vulturesrow posts big blind [$1].** Dealing down cards **Dealt to vulturesrow [ Kd Kc ]Dewez has left the table.xxxdoinkxxx calls [$1].zinc25 folds.UltimateGW folds.TableATM folds.vulturesrow raises [$3].xxxdoinkxxx calls [$3].** Dealing Flop ** [ 9d, 5c, 3h ]vulturesrow checks.xxxdoinkxxx checks.** Dealing Turn ** [ 5h ]>You have options at Clementson (No DP) Table!.vulturesrow bets [$6].xxxdoinkxxx calls [$6].** Dealing River ** [ 8s ]>You have options at Clementson (No DP) Table!.NL_DERB has joined the table.vulturesrow bets [$15].xxxdoinkxxx raises [$30].vulturesrow calls [$15].xxxdoinkxxx shows [ Qd, Kh ] a pair of fives.vulturesrow shows [ Kd, Kc ] two pairs, kings and fives.vulturesrow wins $78.50 from the main pot with two pairs, kings and fives.>You have options at Clementson (No DP) Table!.Then I ran through a converter located here: http://www.neildewhurst.com/hand-converter/Party PokerNo Limit Holdem Ring gameBlinds: $0.50/$16 players[url="">[b]Stack sizes:[/b]UTG: $133.90UTG+1: $57.08CO: $143.50Button: $69SB: $101.85Hero: $115.75[b]Pre-flop:[/b] ([i]6 players[/i]) Hero is BB with K:diamond: K:club: UTG calls, [i]3 folds[/i], [color:#cc]Hero raises to $3[/color], UTG calls.[b]Flop:[/b] 9:diamond: 5:club: 3:heart: ([i]$6.5, 3 players[/i])Hero checks, UTG checks.[b]Turn:[/b] 5:heart: ([i]$6.5, 3 players[/i])[color:#cc]Hero bets $6[/color], UTG calls.[b]River:[/b] 8:spade: ([i]$18.5, 3 players[/i])[color:#cc]Hero bets $15[/color], [color:#cc]UTG raises to $30[/color], Hero calls.[b]Results:[/b]Final pot: $78.5[color:#ff]UTG shows Qd Kh [/color][color:#ff]Hero shows Kd Kc [/color]I wont lie, I found your "simple" example a bit mind blowing, maybe I need to work through some more tutorials lol. Still plugging away, thanks so much for helping this novice out. Cheers,Chris New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.___ 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
Chris Delgado wrote: > Here is an example of the type of output I am looking for. OK, I think you have your work cut out for you :-) I still think my basic approach can work but the output handler is going to have to keep track of a fair amount of stuff as it gets parse events. The good news is you can build it up a line at a time - start with a program that converts the first line correctly, then make it two lines, etc. > I wont lie, I found your "simple" example a bit mind blowing, maybe I > need to work through some more tutorials lol. Still plugging away, > thanks so much for helping this novice out. Yes, it uses a lot of...hmm...at least novice-level concepts - cooperating classes, regular expressions and first-class functions, for a few. You said you have read a couple of books and you seemed at least comfortable with the idea that you might need classes and regular expressions so I didn't explain it much. Feel free to ask questions about the parts you don't understand. I wonder if maybe you need to write some code? You talk about *reading* but you haven't mentioned *writing*. You can't learn to program without writing programs - that would be like learning to write a foreign language by reading books in the language - it helps but it won't get you there! So if you have just been reading, I suggest you try writing a few small programs as warmups. Good luck! Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor