snippsat 661 Master Poster

Just a note that can help.
New from python 2.7 is collections.Counter

>>> from collections import Counter
>>> l = ['j', 'a', 'n', 'k', 'o', 's', 'i', 'e', 'n', 'a', 'p', 'i', 'v', 'o']
>>> Counter(text)
Counter({'a': 2, 'i': 2, 'o': 2, 'n': 2, 'e': 1, 'k': 1, 'j': 1, 'p': 1, 's': 1, 'v': 1})

It also has a most_common feature.

>>> Counter(text).most_common(5)
[('a', 2), ('i', 2), ('o', 2), ('n', 2), ('e', 1)]
>>>
snippsat 661 Master Poster

Look at Qsettings if you want user to change and store settings in your UI.

snippsat 661 Master Poster

You have to run kode in same folder as 'newfile.txt' or you have to give correct path.

f = open('c:/somefolder/newfile.txt','r+')

I do not have a
file there, but I thought you created a file with the same code?

Or as tony mention read(r) dos not create a new file only write(w) dos that.

snippsat 661 Master Poster

WHat is QT?

QT(first link in google)

python and used pyside to compile it?

Pyside(GUI-toolkit) is a licence free versjon of QT.

You seems not so much uppdatet about this thing,so do a little searching.
Python is an easier language to learn and use than C++,python are used in many areas.
http://www.python.org/about/quotes/

snippsat 661 Master Poster

So then what is python used for if you can't create dekstop programs?

Of course you can create dekstop programs with python,in fact python is very good for that.
You have many good GUI toolkit like wxpython,PyQt,PyGTK.
And the god news for python pyside(no licence problem)
http://www.pyside.org/
You can also use java(swing) and .NET(winform) through python.

Some expample of program using this GUI-toolkit.
VLC(QT)
http://www.videolan.org/vlc/screenshots.html
Wxpython/wxwidgets
Dropbox- TrueCrypt - Digsby

In this link code for all GUI-toolkit.
http://www.daniweb.com/software-development/python/threads/191210

vegaseat commented: good info +15
snippsat 661 Master Poster

You have module like py2exe,cxfreeze,gui2exe that will give you(exe) to run without python installed.
If that what you mean.

snippsat 661 Master Poster

A little basic stuff about Class/OOP stuff that can be good to now.
Remeber it`s not called a function but a method,when it belong to Class.

class Active(object):
    ''' Special method __init__() is called auto when you makeing a object(acts as Constructor)'''
    def __init__(self):
        self.players = []
        self.goblins = []

    def put_first(self, first):
        '''This look like a function,put when belong to a Class is called a method'''
        return self.goblins.insert(0, first)

    def __str__(self):
        '''Special method __str__  get used when we use print on a object'''
        return 'players: %s goblins: %s' % (self.players, self.goblins)

#Now let test out this Class in IDLE

Here we se two empty list because stuff under __init__ get called auto when we make an object

>>> a_object = Active() #Class instance,we are making a object
>>> print a_object #print find __str__,and print out object info
players: [] goblins: []
>>>

We put in a couple of goblins.

>>> a_object.goblins.append('Grunt')
>>> a_object.goblins.append('Killer')
>>> print a_object
players: [] goblins: ['Grunt', 'Killer']

Last we are using method put_first to place a goblin first in the list.

>>> a_object.put_first('Gotar')
>>> print a_object
players: [] goblins: ['Gotar', 'Grunt', 'Killer']
>>>
snippsat 661 Master Poster

look like it get and error on try to import numpy.
Try. help('numpy') .

Try this.

try:
    help('modules')
except Exception, e:
    print e

Or

try:
    help('modules')
except ImportError:
    pass

To get it to continue after ImportError.

Place for numpy C:\Python27\Lib\site-packages\numpy So you have to delete this folder is reinstall.
Remeber if you reinstall python,can 3 party modules like numpy not be removed.
You have to do it manually.

snippsat 661 Master Poster
snippsat 661 Master Poster

You have just paste code into IDLE(python shell),that dos not work.
Do this file->new window now copy code under and paste code into the new window you got.

print ("Game Over")
input("Press the enter key to exit.")

Save the file with .py extension(somthing.py)
Now you can press F5 or Run Module from the menu.

IDLE(python shell) you can just type in 1 line and you have to hit enter after every line(if test more than line) and you se output immediately and also without print.

>>> print ("Game Over")
Game Over

>>> ("Game Over")
'Game Over'
>>> 
          
>>> for i in range(3):
...     i
...     
0
1
2
   
>>> a = 'hello'
>>> for word in a:
...     word
...     
'h'
'e'
'l'
'l'
'o'
>>>

Get a god editor make it eaiser to run code like pyscripter.
http://code.google.com/p/pyscripter/

Darion commented: Thankss :) +0
snippsat 661 Master Poster

As postet over using site API can help.

For webscraping are BeautifulSoup and lxml good parser.
Just a quick example with BeautifulSoup,take out price of bean.

#Python 2.x
from BeautifulSoup import BeautifulSoup
import urllib2

url = urllib2.urlopen('http://beans.itcarlow.ie/prices.html')
soup = BeautifulSoup(url)
#print soup #site conteds

tag = soup.find('strong')
print tag  #[<strong>$6.36</strong>]
print tag.string  #$6.36
Thisisnotanid commented: Provided helpful information. +2
snippsat 661 Master Poster

Just a note collections Counter will always sort in descending count order.
Here i also show most_common(),no we now that all word after 'it' has 1 as count.

from collections import Counter
from string import punctuation

text = """\
If you see a turn signal blinking on a car with a southern license plate,
you may rest assured that it was on when the car car car car car was purchased.
"""

text = ''.join([c for c in text if c not in punctuation])
print Counter(text.split()).most_common(6)
#-->[('car', 6), ('a', 3), ('you', 2), ('was', 2), ('on', 2), ('it', 1)]
vegaseat commented: nice +13
Lardmeister commented: good code +6
e-papa commented: Good one. +1
snippsat 661 Master Poster
def myfunc(*args):
    return sum(args)

print myfunc(10,10,1,10,10,10,10,10) #71
snippsat 661 Master Poster

You can look at this example.

'''num.txt-->
1 2 3 4 5
'''

with open('num.txt')as f:
    for item in f:
        n = item.strip().split()
        print sum((int(i) for i in n)) #15

If you use print n before last line you see
So we have stript of newline(\n) and split the number up.
As you see now all number are string.
On the last line convert to integer and use sum() to calulate those numbers.

TrustyTony commented: Good teaching (some 'new reputation') +13
snippsat 661 Master Poster

What OS(operating system) do you us?
For windows the brainless binary install(exe,msi) next,next...finish.

List of diffent OS install at pygame site.
http://www.pygame.org/install.html

e-papa commented: good one. +1
snippsat 661 Master Poster

I'd like to know what it's used for. I think it's mostly used for web application's.

Python is used in all application you can think off.
Python is strong in web application's as you say with many good Web Frameworks.
http://wiki.python.org/moin/WebFrameworks
Pyhon also have strong GUI-toolkit like wxpython,PyQT,PyGTK and bulid-in Tkinter.

I'd also like to know if it has a runtime environment For example, Java's runtime environment is the JVM(Java Virtual Machine), at least I think so.

To run a Java program, you must have Java's Runtime Environment installed on your machine.
To run a Python program, you must have Python's Interpreter installed on your machine.
Allmost all linux distros an mac comes with python pre install.

Python easy to install just 1min and it`t ok on windows.
For stand alone application there are tool like py2exe,cxfreez,Gui2exe,portable python also using installer like inno-setup for making a good looking installer.

Also, is Python a language that's actually used? Like do many companies use Python?

http://www.python.org/about/quotes/

Python is used successfully in thousands of real-world business applications around the world, including many large and mission critical systems. Here are some quotes from happy Python users:

e-papa commented: Goos one. +1
snippsat 661 Master Poster

Dont use file as variable is a reserved keyword for python.
So for this script under to work,test.py an words.txt need to be in same folder.

#test.py
my_file = open('words.txt') #Remeber '' open take string as argument
print my_file.read()
my_file.close()

Let say that words.txt is not in same folder as test.py
Then you need to give correct path to words.txt
Here words.txt is placed in folder c:\test
Remeber not use single \ when give path to file,python can see \ as an escape character.
c:\\test or c:/test not c:\test

#test.py
my_file = open('c:/test/words.txt')
print my_file.read()
my_file.close()

The most common way in python today is to use with open()

with open('words.txt') as f:
    print f.read()

With this method you dont need to close() file object,as you see i do in script over.

e-papa commented: Thanks +1
snippsat 661 Master Poster

Very simply program but I can't get it to work. I know sure how to write the code.

You have to post code,how do you think we can help you?.
We are not mind readers.

but I can't get it to work.

Python always give you Traceback if something goes wrong,this is important to understand.
That you dont get the output you want can be a design fail in code.
But this no one can know,because you just say something dos not work.
An example of Traceback.

>>> k
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
NameError: name 'k' is not defined
>>> #So we need to define k
>>> k = 5
>>> k
5
>>>
snippsat 661 Master Poster

A good python IDE editor will help you more than notepad++.
For windows pyscripter or linux SPE

snippsat 661 Master Poster
#python 3
def main():
    i = int(input())  #input in python 3 return a string
    print(i + 1)      #now it will add 1 to input     

#Call main() function
main()
snippsat 661 Master Poster

http://stackoverflow.com/questions/3270209/how-do-i-make-tkinter-support-png-transparency
Wxpython has good support for transparent image,and may be a better choice.
For me there has never been a choice i find wxpython much better than Tkinter.
The ugly look of Tkinter in windows is not ok at all.
PyQt and pyGTK shold also has support for this.

snippsat 661 Master Poster

You have some mistake,and use code tag.
See if this help.

def main():
    phrase = input("Enter a sentence:")
    words = phrase.split() #Forget ()
    wordCount = len(words)
    print("The total word count is: %s" % wordCount) #You have to include wordCount in print
main()
snippsat 661 Master Poster

Use urlretrieve .

>>> from urllib import urlretrieve
>>> help(urlretrieve)
Help on function urlretrieve in module urllib:

urlretrieve(url, filename=None, reporthook=None, data=None)

Example.

from urllib import urlretrieve
urlretrieve('http://gdimitriou.eu/wp-content/uploads/2008/04/google-image-search.jpg', 'google-image-search.jpg')
debasishgang7 commented: It worked fine..Thanks a lot.. +2
snippsat 661 Master Poster

The problem in python 3 code is that you are comparing integer with string. input() in python 3 return a string same as raw_input() in python 2. input() in python 2 return an integer.
This will work

answer = int(input("> ")) #make input return an integer

Or you can cast it to an integer later.

if int(x) == 1:

Read about the differnce.
http://diveintopython3.org/porting-code-to-python-3-with-2to3.html

Use 4 space as indentation in your code,not 8.

vegaseat commented: nice +13
snippsat 661 Master Poster

1. input ask user for date
2. ouput add three weeks to the input

Look at the datetime module for this.

>>> import datetime
>>> now = datetime.date(2011, 3, 5)
>>> difference1 = datetime.timedelta(days=21)
>>> print "3 weeks in the future is:", now + difference1
3 weeks in the future is: 2011-03-26
>>>
snippsat 661 Master Poster

Look at cgi module.
http://docs.python.org/library/cgi.html
http://www.tutorialspoint.com/python/python_cgi_programming.htm

Most common way to work with HTML/websites is to use one of python Web framework.
http://wiki.python.org/moin/WebFrameworks

snippsat 661 Master Poster

Look at the output -ordi-
fiss gisse hd uc tb oa z
Do you see some character are missing?

I dont know how BirdaoGwra want the output,here are a couple of way.
fissgiss is one word in this,some more work is neede to split that to.
Pickle is way to save and get same output back,look at this.
http://www.daniweb.com/forums/thread343685.html

l = [['fiss','giss'], ['e','h'], ['d','u'], ['c','t'], ['b','o'], ['a','z']]

with open('w.txt', 'w') as f:
    f.writelines(''.join(i) + ' ' for i in l)
#--> fissgiss eh du ct bo az 

#---------------------------------------#
l = [['fiss','giss'], ['e','h'], ['d','u'], ['c','t'], ['b','o'], ['a','z']]

with open('w.txt', 'w') as f:
    f.writelines(''.join(i) + '\n' for i in l)

"""Output-->
fissgiss
eh
du
ct
bo
az
"""

Edit did see you post about output.

l = [['fiss','giss'], ['e','h'], ['d','u'], ['c','t'], ['b','o'], ['a','z']]

with open('w.txt', 'w') as f:
    f.writelines(' '.join(i) + '\n' for i in l)

"""Output-->
fiss giss
e h
d u
c t
b o
a z
"""
BirdaoGwra commented: I learned from him. +2
snippsat 661 Master Poster

Something you can look at,for doing financial calculations look at Decimal module.
http://docs.python.org/library/decimal.html

>>> number = 0.60
>>> print '%.2f' % number
0.60

>>> from decimal import *
>>> Decimal('0.60')
Decimal('0.60')
>>> Decimal('0.60') + Decimal('0.60')
Decimal('1.20')
>>> 
>>> print Decimal('0.60') + Decimal('0.60')
1.20
Archenemie commented: This post was concise and to the point with good examples +2
snippsat 661 Master Poster

what has fileHandle been replaced with in python 3.1

FileHandle is just a variable name used by vega.
You can use whatever name you want.
Here is the same code for python 3

# Testet work for python 3
# read a text file as a list of lines
# find the last line, change to a file you have
fileHandle = open ('test3.txt')
lineList = fileHandle.readlines()
fileHandle.close()
print (lineList)
print ("The last line is:")
print (lineList[len(lineList)-1])
# or simply
print (lineList[-1])

Or if we use an other name than FileHandle just f

# Testet work for python 3
# read a text file as a list of lines
# find the last line, change to a file you have
f = open ('test3.txt')
lineList = f.readlines()
f.close()
print (lineList)
print ("The last line is:")
print (lineList[len(lineList)-1])
# or simply
print (lineList[-1])

Postet over is a more modern solution by tony.
with open() close the file object auto,so no need for close()

danholding commented: very helpfull +1
snippsat 661 Master Poster
import re

text = '''\
#include "hello.h"
#include "d/hello.h"
#include "dir/hello.h"
#include "dir\hello.h"
#include <hello.h>
#include "a\b\c.h"
#include <ref\six\eight.h>
#include "123\456/789.h"
#include "bye.h"
'''

new_text = re.findall(r'\w+\.\w' ,text)
print new_text  #list
print '\n'.join(new_text) #string
print set(new_text)  #No duplicate

"""Output-->
['hello.h', 'hello.h', 'hello.h', 'hello.h', 'hello.h', 'c.h', 'eight.h', '789.h', 'bye.h']
hello.h
hello.h
hello.h
hello.h
hello.h
c.h
eight.h
789.h
bye.h
set(['eight.h', '789.h', 'hello.h', 'c.h', 'bye.h'])
"""
snippsat 661 Master Poster

You are looking for random.shuffle().
To see all method under random module use dir(random)
For help use help(random.shuffle)

>>> random_name = ['Mohamed', 'Ahmed','Aboubakr']
>>> random.shuffle(random_name)
>>> random_name
['Mohamed', 'Aboubakr', 'Ahmed']
>>> random.shuffle(random_name)
>>> random_name
['Ahmed', 'Mohamed', 'Aboubakr']
>>> random.shuffle(random_name)
>>> random_name
['Ahmed', 'Aboubakr', 'Mohamed']
>>>
vegaseat commented: thanks +13
snippsat 661 Master Poster

Use code tag,are you using python 3?
Then you have to change print statement,because as mention many times print is a function in python 3.

#python 3
"""
file_1.txt-->
99 root S 5176 95 41.2 8.3 snmpd

file_2.txt-->
99 root S 5176 95 1.0 8.3 snmpd
"""

with open('file_1.txt') as file_1:
    with open('file_2.txt') as file_2:
        f1 = [float(item.split()[5]) for item in file_1]
        f2 = [float(item.split()[5]) for item in file_2]
        print (f1[0] - f2[0])  # 40.2
snippsat 661 Master Poster

Rember use code tag.

data1 = []
x_org = []
locx = open('test.txt', 'w')
for i in range(9):    
    x_org.append(i)
locx.write('\n'.join([str(i) for i in x_org]))
locx.close()

Can break it up it little so it`s easier to understand.

>>> l = [1, 2, 3, 4, 5, 6, 7, 8]
>>> #We have a list of integer,we much convert into string
>>> #With python List Comprehensions
>>> [str(i) for i in l]
['1', '2', '3', '4', '5', '6', '7', '8']
>>> #Or in a functional style with map
>>> map(str, l)
['1', '2', '3', '4', '5', '6', '7', '8']
>>> #Then join it into a string with \n(new line character)
>>> '\n'.join([str(i) for i in l])
'1\n2\n3\n4\n5\n6\n7\n8'
>>> '\n'.join(map(str, l))
'1\n2\n3\n4\n5\n6\n7\n8'
>>>

locx = open('C:\Temp\Loc', 'w')

Use C:/Temp/test.txt or C:\\Temp\\test.txt and you need a file name loc.txt?
\ Can be used as an Escape Characters an file will not be found.

snippsat 661 Master Poster

richieking this was an 5 years old post.
As Gribouillis posted python has never break anything before release of python 3.
Python 3 has been planned for many years,and is of course the right descion for the evolution of this great language.
But the are very clear that python 2 will for most pepole be the best choice for some years more.

If you look at tiobe over the last 10years rating there are not many languages that has an posetive evolution,python has is one of the few the languages that has an posetive curve.

But we are not in a hurry. Soo many versions for what?

It`s of course to get new features out,and fix some bugs.
If you dont like it just stay with an older version.

I have every version from 2.5 to 3.2 installed on my laptop,that one way to test things out,and stability has never been an issue.

Dont make a mistake. yea... python is not ubuntu but at least the idea of stabilty for a software, system, tool etc are the same.
Long live the snake!!!!!

ubuntu has nothing to do with python stabilty,python has been and are stable on all platform.
And bugs are taken serious in python,look at bug report in python.

snippsat 661 Master Poster

now i can't figure out what does find+1 means..

A clue most programming start indexing/counting at 0.

def find_genes(gene,sequence):
    my_list= []  #Dont use list as a varible name,it`s a python keyword

    count = sequence.count(gene)
    find = sequence.find(gene)
    my_list.append(find)

    while find > -1:
        find = sequence.find(gene,find+1)
        my_list.append(find)
        return count,my_list  #Move to remove -1

text = """\
My name is Fred Flintstone and I am a famous TV
star.I have as much authority as the Pope,I
just don't have as many people who believe it.
Fred
"""
gene = 'Fred'

count,index_word =  find_genes(gene,text)
print '%s occurred %s times,at index %s' % (gene,count,index_word)
snippsat 661 Master Poster

It work fine for me,it has no error so it should work for you to.
In your first code both __int__ statement was wrong should be __init__

import wx

class my_window(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))
    
        self.SetBackgroundColour('BLACK')

if __name__ == "__main__":
    app=wx.PySimpleApp()
    frame=my_window(parent=None,id=-1)
    frame.Show()
    app.MainLoop()
snippsat 661 Master Poster

Should not be so hard to understand it`s a slice method that work on string.
your string[start:end]

>>> s = 'my car'
>>> s[0]
'm'
>>> #m is first,we cont from zero

>>> #So if we want to take out car,we count [start:end]
>>> start = 3
>>> end = 6
>>> s[start:end]
'car'
>>>
snippsat 661 Master Poster
'''
#part.txt
This is a test.
I want to take out this part,of the text
'''

f = open('part.txt')
#readlines() return a list,so string slice wont work [start:end]
print f.readlines()
#--> ['This is a test.\n', 'I want to take out this part,of the text']


f = open('part.txt')
#read() return a string and you can use string slice
print f.read()[35:44]
#--> this part

#Join() as you may now convert a list to string
''.join(['This is a test.\n', 'I want to take out this part,of the text'])[35:44]
#--> this part
snippsat 661 Master Poster

This should help,and try to post some code next time.

>>> from __future__ import division
>>> my_list = [1,2,3,4]
>>> avg = sum(my_list)/len(my_list)
>>> avg
2.5
>>>
snippsat 661 Master Poster

Getters and setters are evil. Evil, evil, I say! Python objects are not Java beans. Do not write getters and setters. This is what the ‘property’ built-in is for. And do not take that to mean that you should write getters and setters, and then wrap them in ‘property’.

http://tomayko.com/writings/getters-setters-fuxors

The link over is follow up from python is Not java.
http://dirtsimple.org/2004/12/python-is-not-java.html

snippsat 661 Master Poster

ran it and I was so happy with it, but then... why on Earth does it tell me that "5" is higher than "24"? Or why does it tell me that "5" is higher than "45"?? Or why "5" is higher than "13"?

Because you are comparing string and not integer.
Python 3 has only input() and it return a string,but you can choose what datatype it shall return with int() float() .

Just an advice.
For beginner there is a massive amout of tutorials/books/forum help that are in python 2.x this is important stuff for learing python.
If you learn python 2.x you learn of course python 3.x,have both installed is a good chooice.
Most pepole still use python 2.x in wait for many 3 part moduls to be rewritten in python 3.

#python 3
>>> x = input('Give a value for \'a\': ')
>>> Give a value for 'a': 5
>>> type(x)
<class 'str'>

>>> x = int(input('Give a value for \'a\': '))
>>> >>> Give a value for 'a': 3
>>> type(x)
<class 'int'>

>>> #Or use float for decimal number
>>> x = float(input('Give a value for \'a\': '))
>>> Give a value for 'a': 5.3  
>>> type(x)
<class 'float'>

>>> #You can also convert later in code
>>>  if float(a) > float(b):
snippsat 661 Master Poster

Use parser BeautifulSoup is good.

from BeautifulSoup import BeautifulSoup

html = '''\
<a href="http://www.gumtree.sg/?ChangeLocation=Y" rel="nofollow">Singapore</a>,
<a href="http://www.gumtree.com.au/?ChangeLocation=Y" rel="nofollow">Australia</a>,
<a href="http://www.gumtree.co.nz/?ChangeLocation=Y" rel="nofollow">New Zealand</a>,
<a href="http://www.gumtree.com" rel="nofollow">England</a>, <a href="http://edinburgh.gumtree.com" rel="nofollow">Scotland</a>,
<a href="http://cardiff.gumtree.com" rel="nofollow">Wales</a>,
<a href="http://www.gumtree.ie" rel="nofollow">Ireland</a>, <a>
'''

soup = BeautifulSoup(html)
links = soup.findAll('a', href=True) # find <a> with a defined href attribute
for link in links:
    print link['href']
    
''' output-->
http://www.gumtree.sg/?ChangeLocation=Y
http://www.gumtree.com.au/?ChangeLocation=Y
http://www.gumtree.co.nz/?ChangeLocation=Y
http://www.gumtree.com
http://edinburgh.gumtree.com
http://cardiff.gumtree.com
http://www.gumtree.ie
'''
Gribouillis commented: very simple +4
snippsat 661 Master Poster
>>> Z = []
>>> X=['a']
>>> Y=['b','c','d','e','f']
>>> for i in Y:
...     Z.append(X[0] + i)
...     
>>> Z
['ab', 'ac', 'ad', 'ae', 'af']
>>>
snippsat 661 Master Poster

Write takes string as argument,if x is a string is shall be ok.
If not ''.join() as tony used be an option.
Remeber to close() the file,if not it will not write anything.
with open() close the file auto,as tony use over.

if x[0:4]=="ATOM":
   print type(x) #Check the type

>>> help(f.write)
Help on built-in function write:

write(...)
    write(str) -> None.  Write string str to file.
    
    Note that due to buffering, flush() or close() may be needed before
    the file on disk reflects the data written.
snippsat 661 Master Poster

@doffing81 i will give som advice about code design.
This can be very important as code grow,to much code in global space can be a real pain.
when you work with function code is local to that function(you have to call it)
Learn to work with function first,of course class is also an option later.
But is important to get comfortable with function.

So some code to show you what i mean.
Look how this work,and a make some documation(called dok_string)

from random import shuffle

def make_deck():
    '''This function retur a sorted deck'''
    rank = 'A23456789TJQK'
    suit = 'CDHS'
    deck = []
    for r in list(rank):
        for s in list(suit):
            card = r + s
            deck.append(card)
    return deck

def shuffle_deck(deck, number=None):
    '''Shuffle deck and return card number(5) return five card'''
    shuffle(deck)
    return [deck.pop() for k in range(number)]

def foo():
    '''Not finsih yet'''
    pass

def main():
    #Here we put it all together
    #Make a note that no code is in global space,this make it eaiser to add remove code
    #We can just add remove function.
    deck = make_deck()
    five_card = shuffle_deck(deck, 5)
    print 'A test give player five card: %s' % five_card
    #-->A test give player five card: ['AH', '5S', '9H', '2S', '9S']

if __name__ == '__main__':
    main()
snippsat 661 Master Poster

For log in use mechanize.
for parsing are beautifulSoup or lxml good choice.

import mechanize
browser = mechanize.Browser()
browser.open(your_url)
browser.select_form(nr=0) #Check form name nr=0 work for many
browser['username'] = "xxxxx"
browser['password'] = "xxxxx"
response = browser.submit()
html = response.read()
print html
snippsat 661 Master Poster

One way to make a deck,that is ok to understand.
@askrabal remember that import statement shall never be inside a class or function.
Import statement shall alway be on top.

rank = 'A23456789TJQK'
suit = 'CDHS'

deck = []
for r in list(rank):
    for s in list(suit):
        card = r + s
        deck.append(card)

print deck

One with list comprehension.

deck = [rank + suit for rank in "A23456789TJQK" for suit in "CDHS"]
print deck

Shuffle deck and deal some card.

>>> from random import shuffle
>>> #Shuffle deck
>>> shuffle(deck)
>>> #Deal out 5 card
>>> [deck.pop() for k in range(5)]
['7S', 'TC', 'TD', '8C', 'QS']
snippsat 661 Master Poster

Something like this.

def foo(num):
    ''' Return an exponential notation'''
    return '%e' % num

print foo(3000000000000000000000000)
#-->3.000000e+24
snippsat 661 Master Poster

indentations 4 space,is important in python.
If you have a good python editor it will auto indent.

import wx

class bucky(wx.Frame):

    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'Frame aka window', size=(400,300))
        panel=wx.Panel(self)

        status=self.CreateStatusBar()
        menubar=wx.MenuBar()
        first=wx.Menu()
        second=wx.Menu()
        first.Append(wx.NewId(),"new window")
        first.Append(wx.NewId(),"Open...")
        menubar.Append(first,"File")
        menubar.Append(second,"edit")
        self.SetMenuBar(menubar)

if __name__=='__main__':
    app=wx.PySimpleApp()
    Frame=bucky(parent=None, id=-1)
    Frame.Show()
    app.MainLoop()
vegaseat commented: excellent observation +12
snippsat 661 Master Poster

BeautifulSoup is a famous python HTML/XML parser.
http://www.crummy.com/software/BeautifulSoup/
BeautifulSoup is only one file BeautifulSoup.py.

build parser like minidom,elementtree should work.
If not 2 of the best is BeautifulSoup and lmxl.
http://codespeak.net/lxml/