[Tutor] learning how to convert script to python
I am learning python at the moment--this is something I would like to work on/convert. It's a poker application that opens a table for you every x-minutes. The project has been discontinued and I would like to convert it to python, then use it. Can you tell me what language this is--lisp or autohotkey? What do I need to learn so I can convert these? Thanks! ; Thois TableOpener for PokerStars v1.05 > ; Opens new cash game tables from the lobby every x seconds (if there are > less tables opened than your predefined settings). A great tool for > multi-tablers. > ; Customize the variables below (between the lines) > ; 'Thois' on PS for donations > > ; Customizable variables (between the lines) > ;-- > rowheight := 13 ;In the PokerStars lobby go to View > Text Size: For Medium & > smaller:13, For smallest:12, For Larger:15, For Largest:17 > recheck := 50 ;How often the script should open up new tables (if needed), > 50=10seconds, 25=5seconds etc... Try not to set this too low for CPU > performance issues > ;-- > > Gui, Font, s8, Arial > Gui, Add, Text,, Number Of Tables: > Gui, Add, Edit > Gui, Add, UpDown, vnumberoftablestokeepopen Range1-24, 12 > Gui, Add, Checkbox, venabledisable, Run! > Gui, Show,, Thois TableOpener for PokerStars v1.00 > Gui, Submit, NoHide > > numberofloopinstances := recheck - 1 > > Loop > { > Gui, Submit, NoHide > SendMessage, 0x115, 0, 0, PokerStarsListClass1, PokerStars Lobby > numberofloopinstances := numberofloopinstances + 1 > if (numberofloopinstances = recheck) > { > numberofloopinstances := 0 > WinGet, numberofwindows, Count, ahk_class PokerStarsTableFrameClass,,Lobby > beffen := numberoftablestokeepopen - numberofwindows > if (beffen > 0 AND enabledisable = 1) > { > Loop > { > ControlGet, tablesinthelobby, Hwnd, , PokerStarsListClass1, > PokerStars Lobby > yclick := 1 + (rowheight * A_Index) - rowheight > PostLeftClick(1, yclick, tablesinthelobby) > ControlClick, PokerStarsButtonClass10, PokerStars Lobby > Sleep, 500 > WinGet, numberofwindows, Count, ahk_class > PokerStarsTableFrameClass,,Lobby > beffen := numberoftablestokeepopen - numberofwindows > if (beffen = 0) > { > break > } > } > } > } > Sleep, 200 > } > > ; Hotkeys (disabled) > > ;~Xbutton1:: ;Endlessly cycles between all tables in the stack the cursor is > pointing at (brings the front table to the back), disabled (remove ; marks to > enable) > ;MouseGetPos,,,tableID > ;WinGetClass, classoftableid, ahk_id %tableID% > ;if (classoftableid = "PokerStarsTableFrameClass") > ; { > ; WinSet, Bottom,, ahk_id %tableID% > ; } > ;return > > ;~Xbutton2:: ;Closes the table the mouse is pointing at (also clicks the OK > warning button), disabled (remove ; marks to enable) > ;MouseGetPos,,,tableID > ;WinGetClass, classoftableid, ahk_id %tableID% > ;if (classoftableid = "PokerStarsTableFrameClass"); > ; { > ; WinClose, ahk_id %tableID% > ; Sleep,20 > ; ControlClick, Button1, Table, OK > ; } > ;return > > ;Juks rocks - I deactivated WinActivate so that the Lobby doesnt steal focus > PostLeftClick(x, y, table_id, activate=1) { > ; ### JUK: Send the down left click, then the mouse-up messages. > ; NOTE: This is relative to the top left of the client area and NOT the top > left of the > ; window (ie: It *doesn't* include the title-bar like AHK's MouseClick > does!!!). > If activate > ; WinActivate, ahk_id%table_id% > PostMessage, 0x201, 0x0001, ((y<<16)^x), , ahk_id%table_id% > PostMessage, 0x202 , 0, ((y<<16)^x), , ahk_id%table_id% > } > > GuiClose: > ExitApp > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Class methods
"David Merrick" wrote Is it possible too have crit1 = Critter("Dave") crit2 = Critter("Sweetie") farm = [crit1,crit2] #List# and then be able to use Critters methods on farm? No, Marc has already answered that. class Critter(object): """A virtual pet""" def __init__(self, name, hunger = 0, boredom = 0): # __ denotes private method def __pass_time(self): self.hunger += 1 self.boredom += 1 self.__str__() def __str__(self): print("Hunger is",self.hunger, "Boredom is " ,self.boredom) print("Unhappines is ",self.hunger + self.boredom," and Mood is ",self.mood) This is a really bad idea. Please do not do this, it will almost certainly lead to problems later. __str__ should return a string. It should not print anything. Then you can simply call print (self) at the end of the pass_time method or call print (farm[0]) in your external code. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Critter
"Vincent Balmori" wrote I'm on the Critter Caretake problem that involves handling more than one critter. I have looked At David Merrick's threads for some answers, Given that David hasn't solved the problem yet that may not be the best source! :-) difference is that he created a whole new class to handle it, He has now reverted to a simple list. made more critter objects. The only problem I have left is to have my actions (play and eat) apply to all my creatures ALL AT ONCE, instead of one at a time like it is in my code right now. You can't. You can only apply the methods to one critter at a time. You can write code to wrap it all up into a convenient single call, but that code will still need to call each item separately. There is no such thing as a "call all" mechanism in Python. BTW, You have the same issue as David with __str__. __str__() should return a string, it should not print anything itself. If you sdo that you can then, in your main code write print(crit1) instead of crit1.__str__() This makes using objects much more like using other data types. Also in your init method: def __init__(self, name, hunger = 0, boredom = 0): hunger = random.randint(0,15) boredom = random.randint(0,15) These two lines mean you throw away the values being passed in to the constructor, so you might as well not have them. And... self.name = name self.hunger = hunger self.boredom = boredom Since you just assign them to the attributes you might as well just do the call to randint() here and delete the first two lines completely. Finally in play() def play(self, fun = 4): while self.boredom >= 3: fun = int(input("\n How long do you want to play?: ")) if fun > 5: int(input("\n How long do you want to play?: ")) You ignore the value of fun passed into the method. (And in your code never pass a value) So again you could just lose the fun parameter. Then if fun > 5 you ask the user for a value, convert it to an int then throw it away so it does no good. You probably should assign the new value to fun. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] learning how to convert script to python
"Jim Syyap" wrote The project has been discontinued and I would like to convert it to python, then use it. Can you tell me what language this is--lisp or autohotkey? No idea what autohotkey looks like but it certainly is NOT Lisp. What do I need to learn so I can convert these? Python and whatever the language is. But you will also need to convert all of the support modules that the code uses - like Gui for example, and they might be written in a different language - like C perhaps. Its an interesting challenge but it could be bigger than you think! Be prepared for the long run. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ Gui, Font, s8, Arial Gui, Add, Text,, Number Of Tables: Gui, Add, Edit Gui, Add, UpDown, vnumberoftablestokeepopen Range1-24, 12 Gui, Add, Checkbox, venabledisable, Run! Gui, Show,, Thois TableOpener for PokerStars v1.00 Gui, Submit, NoHide numberofloopinstances := recheck - 1 Loop { Gui, Submit, NoHide SendMessage, 0x115, 0, 0, PokerStarsListClass1, PokerStars Lobby numberofloopinstances := numberofloopinstances + 1 if (numberofloopinstances = recheck) { numberofloopinstances := 0 WinGet, numberofwindows, Count, ahk_class PokerStarsTableFrameClass,,Lobby beffen := numberoftablestokeepopen - numberofwindows ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 88, Issue 103
Thanks that should help ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Critter
Last thing I need to do solve is the __str__ problem. I can print the name fine, but everytime I try to put in the self.hunger and self.boredom values I get: TypeError: Can't convert 'int' object to str implicitly http://old.nabble.com/file/p31940427/critter_caretaker3.py critter_caretaker3.py Alan Gauld wrote: > > > "Vincent Balmori" wrote > >> I'm on the Critter Caretake problem that involves handling more than >> one >> critter. I have looked At David Merrick's threads for some answers, > > Given that David hasn't solved the problem yet that may not > be the best source! :-) > >> difference is that he created a whole new class to handle it, > > He has now reverted to a simple list. > >> made more critter objects. The only problem I have left is to have >> my >> actions (play and eat) apply to all my creatures ALL AT ONCE, >> instead of one >> at a time like it is in my code right now. > > You can't. You can only apply the methods to one critter at a time. > You can write code to wrap it all up into a convenient single call, > but that code will still need to call each item separately. There is > no such thing as a "call all" mechanism in Python. > > BTW, You have the same issue as David with __str__. > __str__() should return a string, it should not print anything itself. > If you sdo that you can then, in your main code write > > print(crit1) > > instead of > > crit1.__str__() > > This makes using objects much more like using other data types. > > Also in your init method: > > def __init__(self, name, hunger = 0, boredom = 0): > hunger = random.randint(0,15) > boredom = random.randint(0,15) > > These two lines mean you throw away the values being > passed in to the constructor, so you might as well not > have them. And... > > self.name = name > self.hunger = hunger > self.boredom = boredom > > Since you just assign them to the attributes you might as well > just do the call to randint() here and delete the first two lines > completely. > > Finally in play() > > def play(self, fun = 4): > while self.boredom >= 3: > fun = int(input("\n How long do you want to play?: ")) > if fun > 5: > int(input("\n How long do you want to play?: ")) > > You ignore the value of fun passed into the method. > (And in your code never pass a value) So again you could > just lose the fun parameter. > > Then if fun > 5 you ask the user for a value, convert it to an > int then throw it away so it does no good. You probably should > assign the new value to fun. > > HTH, > > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- View this message in context: http://old.nabble.com/Critter-tp31933791p31940427.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Zipping files and Mysql
I am trying to write a script that will dump a mysql db and then zip the file. I do know about mysqldb, but I was wondering if there is anything native to the libraries that will allow me to do this without using a seperate piece. Then after I gather the DBs, I need to zip them. I wrote the following, but wanted to know if I am heading in the correct direction. zipfile.zipfile(/myfiles/my_db/, w, zip_stored) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] nested list query
Suppose i have the following nested list: >>> x [['19600894', '1', 'chr15_76136768', 'MISSENSE'], ['19600894', '2', 'chr15_76136768', 'MISSENSE'], ['18467762', '1', 'chr14_23354066', 'MISSENSE']] How do i obtain from nested list x (given above), the following nested list z: >>> z [['chr15_76136768', 'MISSENSE'], ['chr14_23354066', 'MISSENSE']] -- In other words, if the third element of an element of x is the same, then i wish to combine it into a single element. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Critter
On 27 June 2011 19:52, Vincent Balmori wrote: > > Last thing I need to do solve is the __str__ problem. I can print the name > fine, but everytime I try to put in the self.hunger and self.boredom values > I get: > > TypeError: Can't convert 'int' object to str implicitly > > OK, so if Python can't convert an int to a str implicitly, then it's up to you to do it *explicitly*, by using the str() conversion function or perhaps by using a format string operation. #For example: a_number = 123 print(a_number) a_number_str = str(a_number) print(a_number_str) a_number_str_nicely_formatted = 'The number value is %4d.' % a_number print(a_number_str_nicely_formatted) Additionally I'd like to point out that your solution is fixed to 3 critters, whilst using a list would allow you to have a variable number of critters and add more if you wanted them while the program was running and without having to go and modify your program to do so. So, I'd suggest that you try to figure out how to eliminate managing your 3 critters via 3 explicit variables and instead store them in a list, and enhancing the program so you can add critters from the menu. (If this is expanding the scope of the excercise beyond what is intended then please ignore my suggestion.) Regards Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Beginner troubleshooting py2exe
Hello! I'm trying to follow the introductory tutorial on using py2exe at http://py2exe.org/index.cgi/Tutorial. It's very straightforward except that I keep getting an error when I come to step #3 and I don't know what I need to do about it: I'm running Python 2.7 on Windows Vista (32-bit). I've installed Python in C:\Python27 and py2exe in C:\Python27\Lib\site-packages\py2exe. When I reach step #3 in the tutorial and run my setup script that I just wrote from the tutorial's guidelines, I get the following error: C:\Python27>python setup.py py2exe running py2exe *** searching for required modules *** *** parsing results *** creating python loader for extension 'unicodedata' (C:\Python27\DLLs\unicodedata .pyd -> unicodedata.pyd) creating python loader for extension 'select' (C:\Python27\DLLs\select.pyd -> se lect.pyd) creating python loader for extension '_hashlib' (C:\Python27\DLLs\_hashlib.pyd - > _hashlib.pyd) creating python loader for extension 'bz2' (C:\Python27\DLLs\bz2.pyd -> bz2.pyd) *** finding dlls needed *** Traceback (most recent call last): File "setup.py", line 6, in setup(console=['hello.py']) File "C:\Python27\lib\distutils\core.py", line 152, in setup dist.run_commands() File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run self._run() File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 305, in _run dlls = self.find_dlls(extensions) File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 389, in find_dl ls self.dll_excludes) File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 1021, in find_d ependend_dlls import py2exe_util ImportError: DLL load failed: %1 is not a valid Win32 application. After this error occurs I checked my directories and saw that the dist and build folders were created inside the C:\Python27 folder as predicted in the tutorial, but they don't contain any folders or files. I'm assuming this is a problem with something system not being able to locate the proper file, but I have exactly no idea how to solve it. Advice? Enlightenmnet? Thanks very much. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Critter
"Vincent Balmori" wrote Last thing I need to do solve is the __str__ problem. I can print the name fine, but everytime I try to put in the self.hunger and self.boredom values I get: TypeError: Can't convert 'int' object to str implicitly That's right you need to do it explicitly. Either by using str() or by using a format string. (see the thread yesterday for that topic) See one of my earlier posts for the code using a format string. Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] nested list query
"Vikram K" wrote Suppose i have the following nested list: x [['19600894', '1', 'chr15_76136768', 'MISSENSE'], ['19600894', '2', 'chr15_76136768', 'MISSENSE'], ['18467762', '1', 'chr14_23354066', 'MISSENSE']] How do i obtain from nested list x (given above), the following nested list z: z [['chr15_76136768', 'MISSENSE'], ['chr14_23354066', 'MISSENSE']] Since it is not clear what exact algorithm you are following to derive the second from the first I'll take the brute force sinplistic route: [x[0][-2:],x[-1][-2:]] Now, I'm pretty sure you have a more complex algorithm that just using the first and last elements of the list, but since I don't know what it is, this will have to do... -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner troubleshooting py2exe
Just curious. Going by the last line of the error generated, it says something you tried to import is not a valid windows application. Can you confirm you installed the right py2exe for python 2.7 on Win32? You may want to check that to be sure. The last line of your error stack should point you in the direction to go. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Esther Showalter Sender: tutor-bounces+delegbede=dudupay@python.org Date: Mon, 27 Jun 2011 18:27:10 To: Subject: [Tutor] Beginner troubleshooting py2exe ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor