Re: [Tutor] parsing Spreadsheet document

2009-12-10 Thread Alan Gauld


Christopher Spears cspears2...@yahoo.com wrote


I want to fill a database with the contents of a spreadsheet.
The spreadsheet was created by OpenOffice and is a .sxc document.
 I think the best approach is to save the spreadsheet as a .csv document



If you have control over the document then yes I'd go that way too.

You could save in Excel format and use pyExelerator etc as an
alternative option.

Alan G. 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Still making Cribbage game, NEED HELP Please

2009-12-10 Thread Christopher schueler

I  am still working on my cribbage game.. 

 

if you want rules or an outline of the rules/project information,

it is HERE - http://jongarvin.com/cawthra/files/ics3u/cribbage_project.pdf

 

I have attached a copy of what i have so far..

i have built a deck with 52 cards AND made a dictionary containing each card 
and its value such as Jacks and kings worth a value of 10.

 

I was wondering if people could give me ways to finish this project WITHOUT 
CLASSES because we havent learnd them yet OR could somebody right their own 
program for this cribbage game so i can compare or get ideas from your coding.

 

This also contains my PSUEDOCODE if anybody wants to review how i did things or 
what certain things do

 

 

MY CODE for Cribbage::

 

 

 

from random import*


## December 2 - Jan 20, 2010
## Last mode 8/12/09
## Program by John Dananhy, Phil Sulinski  Chris Schueler 4
## We present the Tech-Sauve Cribbage game

##Sudo Code
#Functions
#DisplayTitle
#Printing the rules of how to play cribbage
#GetPlayer names
#ask of there names and set it to a variable named Player1/2
#Build the deck
#loop through 52 times
#call from two diffrent arrays holding the suite and card number
#combined the suite and card value to create a new variable
#append the new variable to the empty array Deck
#return the new values
#Main Program
#ask the user if they would like to learn to play
#if yes print the DisplayTitle function
#otherwise continue with the main program
#Get the players' names from the function GetPlayer1/2
#Creating the array holding the diffrent values of the cards (numbers)
#Creating the array holding the diffrent suite values
#these are the arrays that the Build_Deck function uses
#sorts the suits in order
#creates the various empty arrays that the program will use
#Defining the winning value
#Using the function Builed_Deck to build the deck
#Player1's hand is randomly drawn from the deck and appended to the array 
P1hand
#That card is removed from the deck so it won't be taken twice
#The same is done for Player2
#Next the top card is drawn by randomly selecting a card from the deck
#Player1 is asked to select a card from their hand to put in the crib
#this is repeated telling Player1 to take another card from his hand
#These cards are appended to the array crib and removed from the 
Players hand
#This is repeated for Player2
#Print all the values to the screen

#Displays title and instructions
def DisplayTitle():
print
print Welcome to Tech-Sauve Cribbage
print 
printInsctructions
print 
print 1) Only played with two players (for now)   
print 2) The program starts with a full deck of 52 cards
print 3) Deals out 6 cards to each player with a Suit letter
print 4) Then asks each player what 2 cards they want to discard to the 
crib
print 5) Then the program saves the crib in a temporary deck
print 6) Players start showing cards to get an ammount equal to 31
print 7) Once all the cards have been played, program counts the score
print 8) Then the program will count all possible scores in each hand
printAnd it will add the players points to their total score
print 9) First player to reach a score of 121 wins the game
#Gets players names
def GetPlayer1():
print
Player1 = str(raw_input(Player 1's name ))
return Player1
def GetPlayer2():
print
Player2 = str(raw_input(Player 2's name ))
return Player2
#Building the deck
def Build_Deck():
for R in range (0,52):
cardnumb = numbers[R]
cardsuit = suits[R]
card = str(numbers[R])+str(suits[R])
#All cards are put into the deck
Deck.append(card)
return Deck,numbers,suits,card,cardnumb,cardsuit


##DICTIIONARY CARD VALUES
cards = {AH : 1,2H : 2,3H : 3,4H : 4,5H : 5,6H : 6,7H : 7,8H : 
8,9H:9,10H : 10,JH : 10,QH : 10,KH : 10,\
AC : 1,2C : 2,3C : 3,4C : 4,5C : 5,6C : 6,7C : 7,8C : 
8,9C:9,10C : 10,JC : 10,QC : 10,KC : 10,\
AD : 1,2D : 2,3D : 3,4D : 4,5D : 5,6D : 6,7D : 7,8D : 
8,9D:9,10D : 10,JD : 10,QD : 10,KD : 10,\
AS : 1,2S : 2,3S : 3,4S : 4,5S : 5,6S : 6,7S : 7,8S : 
8,9S:9,10S : 10,JS : 10,QS : 10,KS : 10}

 

##Variables Needed  sorts the deck
numbers = [A,2,3,4,5,6,7,8,9,10,J,Q,K]*4
suits = [H,C,S,D]*13
suits.sort()
##List of arrays used
Deck = []
P1hand = []
P1value = []
P2hand = []
P2value = []
Crib = []
CribValue = []
TCvalue = []
##Setting start scores
P1_score = 0
P2_score = 0
Winner = 121
ele = 51
##Building the deck
Deck,numbers,suits,card,cardnumb,cardsuit = Build_Deck()

## MAIN PROGRAM
##~
##Asks 

[Tutor] Rép. : parsing Spreadsheet document

2009-12-10 Thread Luhmann
If you just want to load the data into python one time, rather than connecting 
to the file, it would be more handy to paste the cells from the clipboard. 
Here's how I do it on windows:

from win32clipboard import * #(pywin32 module required)
def pastetable():   OpenClipboard() try: a=GetClipboardData(13) except: 
CloseClipboard()return None CloseClipboard()
a=a.split('\r\n')   for n, b in enumerate(a):   
a[n]=b.split('\t')  return a


  __
Obtenez l#39;adresse de courriel parfaite: @ymail.com or @rocketmail.com. 
Obtenez votre nouvelle adresse maintenant à  
http://cf.new.mail.yahoo.com/addresses.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sound problems

2009-12-10 Thread Dave Angel

Tim Goddard wrote:

I'm still learning, and this may be better served on a pygame mailing
list but I thought I'd try here first.

I'm following the python programming for absolute beginners which uses
livewires and pygame to do some simple games.  My difficulty comes
from not using the module versions used in the book and using the
latest online offerings.

The book creates a simple program to play music and sound in a console
environment.

initially the code was (shortened for brevity):

from livewires import games

# load a sound file
missile = games.load_sound(missile.wav)

#load the music file
games.load_music(theme.mid)

choice == None
while choice != 0:
print 
1 - play missile sound
2 - play music

choice = raw_input(Choose your selection: )
if choice == 1:
missile.play()
elif choice == 2:
games.play_music()

Which gives an error because the load_music is not part of the latest
games.py module.  So after reading through games.py I discovered that
most of it is a pass through to pygames.  Also the sound does not
play.

My modified code which plays music but still not sound is:
from livewires import games
# If I don't keep the above line, I get an error that pygame.mixer is
not initialized properly

import pygame

# load a sound file
missile = pygame.mixer.Sound('pickup.wav')

# load the music file
pygame.mixer.music.load(theme.mid)

menu code

if choice == 1:
missile.play(3)  # loop .wav three times.
print Playing missile sound

elif choice == 2:
pygame.mixer.music.play()
print Playing theme music

My question is why won't the sound play in the console?  When I use
the same code in a program with a screen, it plays normally.

Thanks in advance!

  
If I may make a guess (I've never used pygame), I'd suggest that the 
sound playing logic counts on using the event loop for its timing.  So 
without an event loop, no sound.


DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread Wayne Werner
On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld alan.ga...@btinternet.comwrote:


 Remember, in testing you are not trying to prove it works but rather to
 demonstrate that it doesn't!


So in that way it's a bit like the the scientific method (or exactly like)?
You create a hypothesis and design tests to invalidate your hypothesis...
and if they fail to invalidate you may have a valid hypothesis. Simply
replace hypothesis with program and you get the testing procedure?

-Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sound problems

2009-12-10 Thread Wayne Werner
On Thu, Dec 10, 2009 at 8:40 AM, Dave Angel da...@ieee.org wrote:

 If I may make a guess (I've never used pygame), I'd suggest that the sound
 playing logic counts on using the event loop for its timing.  So without an
 event loop, no sound.


Also, livewires is a pretty ancient - AFAICT they haven't had a new release
in over a year. Pygame is a little more active in its development and is
really easy enough with so much documentation there's no reason to learn
livewires.

Here's a simple example of playing a midi file with pygame only:

import pygame

pygame.init()
pygame.mixer.music.load('ISawHerStandingThere.mid')
pygame.mixer.music.set_endevent(pygame.QUIT)
pygame.mixer.music.play()

while True:
event = pygame.event.poll()
if event.type == pygame.QUIT:
print 'Quitting'
break


Of course, replace ISawHerStandingThere.mid with whatever music file you
want to play...

HTH,
Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread Kent Johnson
On Thu, Dec 10, 2009 at 11:20 AM, Wayne Werner waynejwer...@gmail.com wrote:

 On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld alan.ga...@btinternet.com
 wrote:

 Remember, in testing you are not trying to prove it works but rather to
 demonstrate that it doesn't!

 So in that way it's a bit like the the scientific method (or exactly like)?
 You create a hypothesis and design tests to invalidate your hypothesis...
 and if they fail to invalidate you may have a valid hypothesis. Simply
 replace hypothesis with program and you get the testing procedure?
 -Wayne

Nice analogy! And like with a scientific hypothesis, you can never be
sure your program is correct, only that all your attempts to prove it
incorrect has failed.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread spir
Wayne Werner waynejwer...@gmail.com dixit:

 On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld alan.ga...@btinternet.comwrote:
 
 
  Remember, in testing you are not trying to prove it works but rather to
  demonstrate that it doesn't!
 
 
 So in that way it's a bit like the the scientific method (or exactly like)?
 You create a hypothesis and design tests to invalidate your hypothesis...
 and if they fail to invalidate you may have a valid hypothesis. Simply
 replace hypothesis with program and you get the testing procedure?
 
 -Wayne
 
 

programming is modelizing -- like a scientist's job

Denis


la vita e estrany

http://spir.wikidot.com/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] parsing Spreadsheet document

2009-12-10 Thread Emile van Sebille

On 12/9/2009 10:05 PM Christopher Spears said...

I want to fill a database with the contents of a spreadsheet.  The spreadsheet 
was created by OpenOffice and is a .sxc document.  What is the best way to do 
this?  I think the best approach is to save the spreadsheet as a .csv document 
and then just parse the file.  Am I on the right track here?


OpenOffice can be scripted with python, and if you're planning on 
pushing the data with python anyway, I think I'd look at writing it as 
an OpenOffice script...


Emile


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What books do you recommend?

2009-12-10 Thread Becky Mcquilling
Good points.  I guess being as new as I am I'm not always sure of the
obvious way to do something or what I think is right, may not be an having
explained examples are best, particularly after I've spent time solving the
problem.

But others may not find this useful.  I admit that learning this stuff does
not come particularly easy to me, so I tend to need more hand holding than
others.

Becky

On Wed, Dec 9, 2009 at 7:34 PM, Che M pine...@hotmail.com wrote:



  But the reason I ask this, is because there are SO many different
 approaches you could
  take to a single problem,

 I guess that depends a lot on what sorts of problems you are thinking in
 terms of.  At least in many cases, perhaps one of the points of the Zen of
 Python is useful:

 There should be one--and preferably only one--obvious way to do it.

 I myself have been trying to stick to that for now; to learn some standard
 ways to do certain things, to not reinvent the wheel but instead to use the
 standard library and modules to do what I need done (since someone already
 needed it done before and coded it well then).Yes, gaining more
 flexibility in how you could approach something is also good, but for
 learning I have tried to establish a core of basic approaches first, and
 alternate approaches second.  I feel that if it works, it's readable,
 simple, and re-usable, I put it in the toolbox.


  how do you know which is correct or why one is better than the
  other?  You can dig yourself in to holes with more complex problems, and
 not understand
  why.

 This list is one good resource for comparing notes on correctness of
 approach.  You'll see people ask if something is Pythonic or not, etc.



 --
 Windows 7: Unclutter your desktop. Learn 
 more.http://www.microsoft.com/windows/windows-7/videos-tours.aspx?h=7secslideid=1media=aero-shake-7secondlistid=1stop=1ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_7secdemo:122009

 ___
 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


[Tutor] Trying to send a URL via XMPP

2009-12-10 Thread Stephen Nelson-Smith
Hi,

I'm trying to send a message to a user via XMPP - but I want them to
receive a clickable word.

I'm using Python 2.4 on RHEL 5.4 and  python-xmpp-0.4.1-6 from EPEL.

I've tried variations on:

 jid = xmpp.protocol.JID('motherin...@jabber.sekrit.org.uk')
 cl = xmpp.Client(jid.getDomain())
 cl.connect()
 cl.auth(jid.getNode(),'notgoodenough')
 cl.send(xmpp.protocol.Message(snelsonsm...@jabber.sekrit.org.uk, html 
 xmlns='http://jabber.org/protocol/xhtml-im'body 
 xmlns='http://www.w3.org/1999/xhtml'pa 
 href='http://rt.sekrit.org.uk/rt3/Ticket/Display.html?id=#77'Ticket #77 
 updated./a/p/body/html))

But every time I just receive the raw html

Any idea what I am doing wrong?

S.

-- 
Stephen Nelson-Smith
Technical Director
Atalanta Systems Ltd
www.atalanta-systems.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Trying to send a URL via XMPP

2009-12-10 Thread Wayne Werner
On Thu, Dec 10, 2009 at 3:29 PM, Stephen Nelson-Smith sanel...@gmail.comwrote:

 Hi,

 I'm trying to send a message to a user via XMPP - but I want them to
 receive a clickable word.

 I'm using Python 2.4 on RHEL 5.4 and  python-xmpp-0.4.1-6 from EPEL.

 I've tried variations on:

  jid = xmpp.protocol.JID('motherin...@jabber.sekrit.org.uk')
  cl = xmpp.Client(jid.getDomain())
  cl.connect()
  cl.auth(jid.getNode(),'notgoodenough')
  cl.send(xmpp.protocol.Message(snelsonsm...@jabber.sekrit.org.uk,
 html xmlns='http://jabber.org/protocol/xhtml-im'body xmlns='
 http://www.w3.org/1999/xhtml'pa href='
 http://rt.sekrit.org.uk/rt3/Ticket/Display.html?id=#77'Ticket #77
 updated./a/p/body/html))

 But every time I just receive the raw html

 Any idea what I am doing wrong?


I don't know anything about xmpp, but you could try receiving a message and
inspecting how that is built?

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What books do you recommend?

2009-12-10 Thread Alan Gauld


Becky Mcquilling ladymcse2...@gmail.com wrote


Good points.  I guess being as new as I am I'm not always sure of the
obvious way to do something or what I think is right,


One thing to remember is that it is always subjective.
There is no such thing as an absolute right way to do it
There are too many factors and virtually all solutions reflect
a set of compromises by the designer

But others may not find this useful.  I admit that learning this stuff 
does

not come particularly easy to me,


Its not easy to learn a new way of thinking and thats essentially
what programming is.  Some people will always find it easier
and some harder but it is fundamentally a challenging activity
for everyone - and that's part of what makes it fun!

--
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] More on unit testing - tests for external data...

2009-12-10 Thread Modulok
So, this, 'test environment', this is just like a directory where I
place my code and associated files to test for the existence (and
non-existence) of various stuff, right? Any real-world examples/case
studies to point to?

It seems like there are a lot of people on this list interested in
getting more familiar with unit testing, but not a whole lot of
non-trivial, python-specific examples being passed around. I can write
a function in a programming 101 class that accepts two arguments and
returns a value by computing the hypotenuse of a triangle (or
whatever). I can then build a unit-test for that making sure it fails
and passes as needed. Cake. But jump into the real-world where many
things are not so trivial, and I'm at a loss for where this
unit-testing business all fits in.

Basically, I'm trying to become a better programmer. (Who isn't?) I'd
like to transition from 'hacky but gets the job done' or 'oh my God it
actually works' to 'eloquent and bulletproof'. Without some kind of a
mentor or vast array of tutorials to lay down the law when I screw up,
or pass on some kind of approval when I get something right -  it's
been frustrating as hell.

Case studies/tutorials anyone?

Thanks!
-Modulok-

On 12/10/09, spir denis.s...@free.fr wrote:
 Wayne Werner waynejwer...@gmail.com dixit:

 On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld
 alan.ga...@btinternet.comwrote:

 
  Remember, in testing you are not trying to prove it works but rather to
  demonstrate that it doesn't!
 

 So in that way it's a bit like the the scientific method (or exactly
 like)?
 You create a hypothesis and design tests to invalidate your hypothesis...
 and if they fail to invalidate you may have a valid hypothesis. Simply
 replace hypothesis with program and you get the testing procedure?

 -Wayne



 programming is modelizing -- like a scientist's job

 Denis
 

 la vita e estrany

 http://spir.wikidot.com/
 ___
 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