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/)

unluckyboy 06-14-2012 02:05 PM

Re: ** Python Support Thread **
 
lots of time to do work today. goal is to make program to go through oddsportal.com or sbr and get the pinny line for each NFL game over last few years and also the scores

unluckyboy 06-14-2012 02:08 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by TheIrishThug (Post 33278124)
I've never used beautiful soup or elementtree, but the answer is not regex.

how do you know if you dont have experience with either of those?

lol okay i have made a program succesfully parsing HTML with regex. although admittedly that was because i was too n00bie to understand those libraries. i will take your advice though and go about it as you say...

TheIrishThug 06-14-2012 02:38 PM

Re: ** Python Support Thread **
 
The point is that regex is desigened to to work with a specific class of text and HTML is not that type. As stated by other answers in that thread, regex can be used when you are trying to parse a very speceific sub-set of HTML. However, if you are trying to do something more complex or do not have control of the input format, using a framework specifically designed for parsing HTML will make your life easier.

As for an actual recomendation, I've seen beautiful soup used and talked about frequently and never heard of elementtree. So based on that, I suspect it would be easier to get help with any potential issues if you use beautiful soup.

unluckyboy 06-14-2012 05:19 PM

Re: ** Python Support Thread **
 
hey sorry if i ask too many questions. i have no formal instruction in programming and am learning this as i go along with no deep understanding of what is happening. after 2 hours of work i figured out how to get BeautifulSoup version 3 on my computer by downloading it, extracting the .tar.gz file and then run the setup file that it has which builds a file BeautifulSoup which i can cut and paste into the python/lib directory

however, i am trying to get BeautifulSoup version 4 on here and when i extract and run the setup file it doesn't build a BeautifulSoup file which i can use. here is the documentation which i don't understand. i don't know where to run these commands or what they do or what pip is. i downloaded easy install but still can't get this to work.

Quote:

If you’re using a recent version of Debian or Ubuntu Linux, you can install Beautiful Soup with the system package manager:

$ apt-get install python-beautifulsoup4

Beautiful Soup 4 is published through PyPi, so if you can’t install it with the system packager, you can install it with easy_install or pip. The package name is beautifulsoup4, and the same package works on Python 2 and Python 3.

$ easy_install beautifulsoup4

$ pip install beautifulsoup4

(The BeautifulSoup package is probably not what you want. That’s the previous major release, Beautiful Soup 3. Lots of software uses BS3, so it’s still available, but if you’re writing new code you should install beautifulsoup4.)

If you don’t have easy_install or pip installed, you can download the Beautiful Soup 4 source tarball and install it with setup.py.

$ python setup.py install

If all else fails, the license for Beautiful Soup allows you to package the entire library with your application. You can download the tarball, copy its bs4 directory into your application’s codebase, and use Beautiful Soup without installing it at all.

I use Python 2.7 and Python 3.2 to develop Beautiful Soup, but it should work with other recent versions.

Neko 06-14-2012 08:08 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by unluckyboy (Post 33281649)
hey sorry if i ask too many questions. i have no formal instruction in programming and am learning this as i go along with no deep understanding of what is happening. after 2 hours of work i figured out how to get BeautifulSoup version 3 on my computer by downloading it, extracting the .tar.gz file and then run the setup file that it has which builds a file BeautifulSoup which i can cut and paste into the python/lib directory

Your process should roughly go like this:

Code:

/users/home/unlucky> tar xzf mypackage.tgz
/users/home/unlucky> cd mypackage
/users/home/unlucky> sudo python setup.py install
/users/home/unlucky> python
>>> import mypackage
>>> print "yay it worked"
>>> exit()
/users/home/unlucky>

You should never have to manually copy the files anywhere.

Alternatively install pip: http://www.saltycrane.com/blog/2010/...ll-pip-ubuntu/

and then from the command line:
Code:

/users/home/unlucky> sudo pip install beautifulsoup4

Jbrochu 06-14-2012 09:42 PM

Re: ** Python Support Thread **
 
Thanks Neko. I'm going to need to install some packages soon and that info will be helpful.

tyler_cracker 06-14-2012 10:02 PM

Re: ** Python Support Thread **
 
i haven't used beautiful soup but people at work like it.

we mostly use pyquery at work. it has been adequate for my (simple) needs.

unluckyboy 06-17-2012 12:44 PM

Re: ** Python Support Thread **
 
beautifulsoup is so much better than elementtree, with elementtree can't even access a tag's siblings so gay

tyler_cracker 06-17-2012 12:50 PM

Re: ** Python Support Thread **
 
preventing incest is gay? these kids today...

unluckyboy 06-17-2012 01:11 PM

Re: ** Python Support Thread **
 
how does this work when i tried to setup lxml myself i couldn't, how does this program work?

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

Colombo 06-18-2012 12:21 PM

Re: ** Python Support Thread **
 
I wrote a program in python which runs math-intensive simulations. I usually run 7,500 simulations when I run this code.

The problem is it runs slow and I want to improve it. I spent a good amount of time setting up a threading process, where I had 50-75 simulations running at once. However I discovered that this didn't speed up my program at all. It ran just as a fast using a loop where I did 1 simulation per loop.

Is this because the CPU only has a limited amount of processors (1?) capable of running math calculations, so the threads just end up waiting on each other (effectively mimicking a loop where 1 simulation happens per iteration)?

Colombo 06-18-2012 04:18 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by Colombo (Post 33339717)
I wrote a program in python which runs math-intensive simulations. I usually run 7,500 simulations when I run this code.

The problem is it runs slow and I want to improve it. I spent a good amount of time setting up a threading process, where I had 50-75 simulations running at once. However I discovered that this didn't speed up my program at all. It ran just as a fast using a loop where I did 1 simulation per loop.

Is this because the CPU only has a limited amount of processors (1?) capable of running math calculations, so the threads just end up waiting on each other (effectively mimicking a loop where 1 simulation happens per iteration)?

This answers my question I believe: http://stackoverflow.com/questions/3...and-performace

Neko 06-18-2012 09:57 PM

Re: ** Python Support Thread **
 
yeah...definitely the GIL.

Here are some options for speeding up your calculations


- If your simulations aren't dependent on each other, just run multiple python interpreters.

- Use numpy especially if you're working with matricies

- Use the multiprocessing module instead of threading. This will allow you to run multiple simulations in parallel.

- Try Scipy.weave

- Rewrite any hotspots in your code using Cython. You can very easily get some big gains (like orders of magnitude better in some cases)

- Write performance critical parts in C and make them accessible via a dll and then use ctypes to call them.

- Write a full fledged C-extension

RoundTower 06-19-2012 12:50 AM

Re: ** Python Support Thread **
 
before you try any of this, the first step imo is to identify the bottlenecks. There may be 20 different parts of your code that could be sped up tenfold, but only one or two that will actually give a significant increase in your overall running time.

Start with the profile or cProfile modules in the standard library.

Neko 06-19-2012 12:59 AM

Re: ** Python Support Thread **
 
yeah that's a good point to make. Profiling (use cProfile rather than profile) your program to find out where it's spending most of its time is the obvious first step.

unluckyboy 06-19-2012 08:16 PM

Re: ** Python Support Thread **
 
here is a programming problem i am having a problem with. i have data for 1300 football games. for each game i have the spread, and what the result was compared to the spread. it is set up as a list of lists now [(game1_spread, game1_result_compared_to_spread), (game2_spread, game2_result_compared_to_spread), etc.]

i want to take this information and make a printout with these two pieces of data:

spread: game1_result_compared_to_spread==0/total_games_with_this_spread
spread2: game1_result_compared_to_spread==0/total_games_with_this_spread
etc. for each spread

how can i get this?

unluckyboy 06-19-2012 09:09 PM

Re: ** Python Support Thread **
 
okay did it i will post solution and appreciate feedback

Acemanhattan 06-21-2012 02:28 PM

Re: ** Python Support Thread **
 
Brand new to programming, just started going through the MIT opencourse and have some questions regarding Python.

If I open "Python Shell" and from there open "New Window" is this where I will be writing my programs? I then save it there and use the F5 function to run it in the shell correct?

Why when I am using that "New Window" does it automatically indent sentences that I don't think it should? For example I type the following for the first line:

outstanding_balance = int(raw_input("What is your outstanding balance?")

When I press enter it indents me about 7 tab spaces on the next line like:

outstanding_balance = int(raw_input("What is your outstanding balance?")
print "What is your outstanding balance?"


also if I'm not mistaken my first command is saying that whatever the user inputs when prompted, it will be turned from a string into an integer correct? And the second command should print the prompt for the user, correct?

When I try to run that code I get a syntax error.

Edit to add: 2+2 isn't displaying the indent the way I'm intending to show it, imagine "print" starting directly under "raw_input"

Colombo 06-21-2012 04:28 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by Acemanhattan (Post 33393599)
Brand new to programming, just started going through the MIT opencourse and have some questions regarding Python.

If I open "Python Shell" and from there open "New Window" is this where I will be writing my programs? I then save it there and use the F5 function to run it in the shell correct?

Why when I am using that "New Window" does it automatically indent sentences that I don't think it should? For example I type the following for the first line:

outstanding_balance = int(raw_input("What is your outstanding balance?")

When I press enter it indents me about 7 tab spaces on the next line like:

outstanding_balance = int(raw_input("What is your outstanding balance?")
print "What is your outstanding balance?"


also if I'm not mistaken my first command is saying that whatever the user inputs when prompted, it will be turned from a string into an integer correct? And the second command should print the prompt for the user, correct?

When I try to run that code I get a syntax error.

Edit to add: 2+2 isn't displaying the indent the way I'm intending to show it, imagine "print" starting directly under "raw_input"

Ok, for starters I'm not quite sure what you mean by "Python shell" and "New Window", but I can answer your other questions.

As for this line:
Code:

outstanding_balance = int(raw_input("What is your outstanding balance?")
The indent is happening because your parenthesis aren't balanced. You need one ")" to close the "raw_input(" function, and another ")" to close the "int(" function.

Quote:

also if I'm not mistaken my first command is saying that whatever the user inputs when prompted, it will be turned from a string into an integer correct? And the second command should print the prompt for the user, correct?

When I try to run that code I get a syntax error.
Yes you are correct. The int() function will convert an object (in this case a String) into an integer. Hint: Type "help(int())" in your python shell.

The reason you are getting an error could be for a few reasons. As I said before you need to close your open parenthesis. In addition, the int() function will only work on a properly formatted String.

Try the following:
int('1')
int('3.4')
int('two')

Xhad 06-21-2012 05:22 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by tyler_cracker (Post 33322827)
preventing incest is gay? these kids today...

That reminded me of this exchange for some reason...

tyler_cracker 06-22-2012 12:02 AM

Re: ** Python Support Thread **
 
hahahahha

Quote:

If that 6 were really a 9 and we were playing lowball and a 7 turns then I would have bottom pair which would be like top pair so I call
Quote:

A7 is not the nut seven-high, it's the 5th-nut Ace high. Duh.
MUCH LOVE FROM ME.

fluorescenthippo 06-22-2012 10:59 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by Acemanhattan (Post 33393599)
Brand new to programming, just started going through the MIT opencourse and have some questions regarding Python.

If I open "Python Shell" and from there open "New Window" is this where I will be writing my programs? I then save it there and use the F5 function to run it in the shell correct?


Yea im doing this course too and thought the compiler they use seems kinda crappy unless im missing something.

i do the same as you but i dont know how to run the debugger from a new window and a few other things.

unluckyboy 06-23-2012 12:46 AM

Re: ** Python Support Thread **
 
god i hate elementtree and namespaces

tyler_cracker 06-23-2012 12:49 AM

Re: ** Python Support Thread **
 
heh, and you're just scraping it. imaging trying to write it! :)

unluckyboy 06-23-2012 01:02 AM

Re: ** Python Support Thread **
 
http://odds.sbrfeeds.com/events/?new...d&version=1.0&

can i get some help here, i have this page. how can i access the elements <side-name> using Xpath? how can i get access the element <side-name> where it's text equals "Jacksonville"


All times are GMT -4. The time now is 03:50 PM.

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

Copyright © 2008-2020, Two Plus Two Interactive