Two Plus Two Poker Forums

Two Plus Two Poker Forums (https://forumserver.twoplustwo.com/)
-   Computer and Technical Help (https://forumserver.twoplustwo.com/48/computer-technical-help/)
-   -   ** Python Support Thread ** (https://forumserver.twoplustwo.com/48/computer-technical-help/python-support-thread-1007515/)

Alex Wice 03-06-2012 03:19 AM

Re: ** Python Support Thread **
 
The Badugi problem in Project Euler was written by me, by the way. :D

clowntable 03-06-2012 11:04 AM

Re: ** Python Support Thread **
 
Haha that's pretty random but I was scrolling through the problems yesterday and was thinking to myself "Badugi?..I guess I'll try that some day"

e i pi 03-06-2012 12:02 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by Alex Wice (Post 31908039)
The Badugi problem in Project Euler was written by me, by the way. :D

crowd sourcing strategies for your bot?

genius ;)

Xhad 03-07-2012 01:03 AM

Re: ** Python Support Thread **
 
fwiw there's a dedicated PE thread here too: http://forumserver.twoplustwo.com/19...group-1024853/

DavidC 03-08-2012 05:33 PM

Re: ** Python Support Thread **
 
searched this thread, textpad didn't come up:

Textpad lets you put in tools like a python compiler, which is pretty awesome, but I got one of the python addons off their site and it didn't seem to work, neither with coloring the script nor with doing the tab indentation to 4!

I don't have the newwest ver of textpad though, but what it says it should do, it does not do.

Anyways, I'm curious if anyone has some tips for writing python using textpad, or if anyone has recommendations for a better editor that would help with the dev process. I'm just trying to get started in programming again after a long hiatus.

DavidC 03-08-2012 05:38 PM

Re: ** Python Support Thread **
 
oh and I know I'm going to ask this anyways later so: How do you divide in python?? Like normal division where 5/2=2.5... Do I have to float() everything every time I want to do that, or at least one thing? :(

Xhad 03-08-2012 06:22 PM

Re: ** Python Support Thread **
 
in python 2, your options are:

-use float()
-make sure division has floats in it (i.e. 5/2.0)
-from __future__ import division

The last one imports Python 3's division behavior, which is / for "true" division (changes int->float if it doesn't divide evenly) and // for floor division (preserves types where possible)

DavidC 03-08-2012 06:46 PM

Re: ** Python Support Thread **
 
how different is python 2 vs 3? I'd be willing to change languages just to get division with less keystrokes. Why was it this way in the first place?

Also I'm looking at pydev and eclipse right now for dev tools, any good? Someone recommended eclipse to me but all I see are java/c stuff for it.
http://www.eclipse.org/downloads/

edit: pydev has a video and it looks great. :) Hopefully can be used with P3

clowntable 03-08-2012 06:49 PM

Re: ** Python Support Thread **
 
In case anyone hasn't seen this yet...
https://gist.github.com/289467

Brilliant imo :)

Xhad 03-08-2012 07:04 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by DavidC (Post 31955266)
how different is python 2 vs 3? I'd be willing to change languages just to get division with less keystrokes. Why was it this way in the first place?

This is a blind guess, but there's something to be said for having it so that when you put two variables of the same type into an operator, the output is also of that type. Python is far from the first language to behave this way which may have been a factor as well. (not saying I don't like the Python 3 behavior better, mind)

Python 2 and Python 3 are barely different really. In fact if you look at programming help forum you'll see people posting code and responders not being able to tell which it is! From what I can tell the main arguments for one or the other are Unicode support (Python 3) and legacy code/library support (Python 2). In particular if you want to do web stuff you may want to stick to Python 2 and cherry pick individual Python 3 features from the __future__ module. Of course if you're on the fence 3 is probably the default since Python 2 is essentially frozen in its last release.

http://wiki.python.org/moin/Python2orPython3
http://docs.python.org/py3k/whatsnew/3.0.html

clowntable 03-08-2012 07:16 PM

Re: ** Python Support Thread **
 
That would be my exact assessment as well Xhad. Well said.

DavidC 03-08-2012 07:44 PM

Re: ** Python Support Thread **
 
Ok, based on the availability of the legacy code I guess py2 and I'll just have to learn to divide the hard way. I'm very picky sometimes! :(

Can I cherry pick the division out of PY3? I don't need to know how yet, just curious (yes/no). :)

How should I write code in this; I'm using windows xp, what editor should I use? I'd like to find something that I can force to tab on 4 and also pydev has a thing where you shift-enter at the end of a line and it indents into the next line for you, which is, of course, amazing. Problem is I have no idea how to download pydev, as they switched to their own site and their sourceforge page is what's refered to (afaik) on their download page, so SF page is broken. But yeah, finding an editor is the next step for me, hopefully a free program.

DavidC 03-08-2012 07:46 PM

Re: ** Python Support Thread **
 
Thanks for answering questions, guys. :)

Xhad 03-08-2012 07:47 PM

Re: ** Python Support Thread **
 
http://docs.python.org/library/__future__.html

In particular, what you want to do is start all your files with:

Code:

from __future__ import division

DavidC 03-08-2012 08:57 PM

Re: ** Python Support Thread **
 
Awesome. :) If I get the editor situation sorted I'll have enough to start writing.

clowntable 03-11-2012 07:15 PM

Re: ** Python Support Thread **
 
Gogo PyCon imo...that 2.5h thingy on game development with pygame is pretty cool if you want to get into it (first 30 minutes by the chick is general game theory stuff, you can skip it if you want to...includes FF7 spoilers as well)
http://pyvideo.org/category/17/pycon-us-2012

JackHighFlop 03-12-2012 07:28 PM

Re: ** Python Support Thread **
 
Does anyone have any idea how I could pass the elements of a list as arguments to a function when the list in question contains an arbitrary number of elements? Arguments separated by a comma, so I can't just pass the whole list. And I can't modify the function because it's from Scipy.

Xhad 03-12-2012 07:33 PM

Re: ** Python Support Thread **
 
Can you give an example of what you're trying to do?

Neko 03-12-2012 07:36 PM

Re: ** Python Support Thread **
 
Is this what you mean?

Code:


def fun(*args):
   
    print args
   
my_args = [1,2,3,4,5]

fun(*my_args)  #prints (1,2,3,4,5)


JackHighFlop 03-12-2012 07:41 PM

Re: ** Python Support Thread **
 
I'm trying to use the statistical functions from Scipy.

scipy.stats.%(parameters[1]).rvs(loc = currentValue, float(parameters[???]), float(parameters[???]))

parameters[0] is something of not directly related.
parameters[1] is the name of the function
parameters[2:] are the optional parameters. They can range from 0 to 4, depending on the function and the user.

I could just use a bunch of if statements for all the different possibilities, but I was wondering if there was something more elegant.

Xhad 03-12-2012 07:49 PM

Re: ** Python Support Thread **
 
Looks like it's as Neko said then. You would pass *parameters[2:] if so.

JackHighFlop 03-12-2012 07:53 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by Xhad (Post 32019722)
Looks like it's as Neko said then. You would pass *parameters[2:] if so.

But would the scipy.stats function really accept it and know how to handle *args?

norm for example : http://docs.scipy.org/doc/scipy/refe...ipy.stats.norm

The best way would be to try it I guess. I shall reboot in Linux and see if it works.

Xhad 03-12-2012 07:55 PM

Re: ** Python Support Thread **
 
Yes.

Code:

def f(a,b,c):
  return a+b+c

print f(*[1,2,3]) # will print 6


JackHighFlop 03-12-2012 08:06 PM

Re: ** Python Support Thread **
 
Thanks! It works (almost). Apparently, my interpolation technique is wrong. How would I call the function that corresponds to the string parameters[1]?

Xhad 03-12-2012 08:08 PM

Re: ** Python Support Thread **
 
you mean parameters[1] is a string and you want to call a function by that name? Sounds like something that could be done with eval:

Code:

instring = 'f'
print eval(instring)(1,2,3)



All times are GMT -4. The time now is 11:10 PM.

Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.

Copyright © 2008-2020, Two Plus Two Interactive