Re: [Tutor] Class Nesting

2012-02-06 Thread Steven D'Aprano
On Mon, Feb 06, 2012 at 08:17:05PM -0500, Greg Nielsen wrote:
[...]
>  So here is the problem, to create an object, you need to assign it to
> a variable, and you need to know what that variable is to call upon it
> later, so to have a object build a second object, it would need to somehow
> create a variable name, and you would somehow have to know what name it
> picked. Unless perhaps you had a Star Cluster list which had all of your
> created Star System objects, each with their own list of Planets which you
> could use list to call upon maybe

Yes, that's exactly the way to do it. Rather than assigning each object to 
a name:

cluster1 = StarCluster()
cluster2 = StarCluster()
...


you can work with a list of clusters:

clusters = [StarCluster(), StarCluster(), ...]


You can then operate on then one at a time. Say you want to do something to
the 3rd cluster. Remembering that Python starts counting positions at zero,
you would write something like:

clusters[2].name = "Local Cluster 12345"  # give the cluster a name

If your StarCluster objects are mutable (and if you don't know what that 
means, don't worry about it, by default all classes are mutable), you can 
grab a temporary reference to a cluster while working on it:

for cluster in clusters:  # work on each one sequentially
if cluster.stars == []:
print("Cluster %s has no stars." % cluster.name)

Here I have assumed that each cluster is given a list of stars. Something 
like this:

class StarCluster(object):
def __init__(self):
self.name = "no name yet"
self.stars = []
def add_star(self, *args, **kw_args):
self.stars.append(Star(*args, **kw_args))


Here I have given the StarCluster a method, "add_star", which takes an 
arbitrary 
set of arguments, passes them on to the Star class, and adds the resultant 
star to the list.

class Star(object):
def __init__(self, name="no name yet", kind="red giant", planets=None):
if planets is None:
planets = []
self.planets = planets
self.name = name
self.kind = kind


sol = Star(
"Sol", "yellow dwarf", 
['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 
 'Uranus', 'Neptune']  # ha ha, Pluto can bite me
)


I hope this helps,



-- 
Steven

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


Re: [Tutor] Lists/raw_input

2012-02-06 Thread Christian Witts

On 2012/02/07 07:40 AM, Michael Lewis wrote:
I want to prompt the user only once to enter 5 numbers. I then want to 
create a list out of those five numbers. How can I do that?


I know how to do it if I prompt the user 5 different times, but I only 
want to prompt the user once.


Thanks.

--
Michael



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
You can take your input from your user in one line seperated by 
something like a space and then split it after you capture it so for eg.


user_input = raw_input('enter 5 numbers seperated by a space each: ')
list_from_input = user_input.split() # Split by default splits on 
spaces, otherwise you need to specify the delimiter
# Then you can validate the list to ensure all 5 are actually numbers, 
otherwise prompt the user to re-enter them


Hope that help.
--

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


Re: [Tutor] Lists/raw_input

2012-02-06 Thread Andre' Walker-Loud
Hi Michael,

I bet there is a better way (which I would like to see), but here is what I 
have come up with for my own uses.

"""
ints = []
u_in = False
while u_in == False:
try:
u_input = raw_input('please enter 5 integers, space separated\n 
   ')
for n in u_input.split():
ints.append(int(n))
u_in = True
except:
print('input error, try again')
"""

The while loop is set up in case your user inputs a float or string instead of 
just integers.  You can also imagine putting checks in case you want exactly 5 
integers, etc.


Cheers,

Andre




On Feb 6, 2012, at 9:40 PM, Michael Lewis wrote:

> I want to prompt the user only once to enter 5 numbers. I then want to create 
> a list out of those five numbers. How can I do that?
> 
> I know how to do it if I prompt the user 5 different times, but I only want 
> to prompt the user once.
> 
> Thanks.
> 
> -- 
> Michael 
> 
> ___
> 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] Lists/raw_input

2012-02-06 Thread Michael Lewis
I want to prompt the user only once to enter 5 numbers. I then want to
create a list out of those five numbers. How can I do that?

I know how to do it if I prompt the user 5 different times, but I only want
to prompt the user once.

Thanks.

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


Re: [Tutor] Class Nesting

2012-02-06 Thread Dave Angel

On 02/06/2012 08:17 PM, Greg Nielsen wrote:

Hello List,

  My name is Greg, and while working on a project I've come across a
rather interesting problem. I'm trying to create a rough model of a star
cluster and all of the stars and planets contained within. Kind of a cool
project; hopefully it should work a little like this. I create a Star
Cluster object, which goes through a list of positions and decides if it
should build a Star System there. If it does, it then creates a Star System
object at that position which in turn calls upon and creates several Planet
objects to reside inside of it. All in all, about 64 positions to check, on
average 24 Star Systems, each with between 2 and 9 planets.
  So here is the problem, to create an object, you need to assign it to
a variable, and you need to know what that variable is to call upon it
later, so to have a object build a second object, it would need to somehow
create a variable name, and you would somehow have to know what name it
picked. Unless perhaps you had a Star Cluster list which had all of your
created Star System objects, each with their own list of Planets which you
could use list to call upon maybe
  I have a general grasp on the idea of nesting and calling upon objects
which you don't know the name of, but this goes far beyond my level of
understanding. Can anyone shed some light on how this would work, or
perhaps point me in the right direction of some documentation on this?
Thanks for the help, and I hope this is not too difficult of a question.

Greg



Since you talk of creating a StarCluster object, presumably you know how 
to make a class.  So in the class definition, you can define attributes 
that each instance has.  One of those attributes can be a list.  So the 
list has a name, but not the individual items in the list.


Generally, it's best to create an empty list attribute in the 
initializer of the class.  Then whatever class method wants to create 
these items can simply append them to the list.


At this point, you should write some code, and it'll either work, or 
you'll tell us what part of it you can't understand.


--

DaveA

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


[Tutor] Class Nesting

2012-02-06 Thread Greg Nielsen
Hello List,

 My name is Greg, and while working on a project I've come across a
rather interesting problem. I'm trying to create a rough model of a star
cluster and all of the stars and planets contained within. Kind of a cool
project; hopefully it should work a little like this. I create a Star
Cluster object, which goes through a list of positions and decides if it
should build a Star System there. If it does, it then creates a Star System
object at that position which in turn calls upon and creates several Planet
objects to reside inside of it. All in all, about 64 positions to check, on
average 24 Star Systems, each with between 2 and 9 planets.
 So here is the problem, to create an object, you need to assign it to
a variable, and you need to know what that variable is to call upon it
later, so to have a object build a second object, it would need to somehow
create a variable name, and you would somehow have to know what name it
picked. Unless perhaps you had a Star Cluster list which had all of your
created Star System objects, each with their own list of Planets which you
could use list to call upon maybe
 I have a general grasp on the idea of nesting and calling upon objects
which you don't know the name of, but this goes far beyond my level of
understanding. Can anyone shed some light on how this would work, or
perhaps point me in the right direction of some documentation on this?
Thanks for the help, and I hope this is not too difficult of a question.

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


Re: [Tutor] Question on how to do exponents

2012-02-06 Thread Steven D'Aprano
On Mon, Feb 06, 2012 at 04:54:57PM -0800, William Stewart wrote:
> Hello everyone, I am making a calculator and I need to know how to make it do 
> exponents and remainders
> How can I input this info in python?
> Any help would be appreciated

You can do exponents either with the ** operator or the pow() 
function:

py> 2**4
16
py> pow(3, 5)
243


The pow() function is especially useful for advanced mathematics where 
you want to perform exponents modulo some base:

py> pow(3, 5, 2)
1

That is, it calculates the remainder when divided by 2 of 3**5 *without* 
needing to calculate 3**5 first. This is especially useful when 
the intermediate number could be huge:

py> pow(1357924680, 2468013579, 1256711)
418453L


To get the remainder, use the % operator or the divmod() function:

py> 17 % 2
1
py> divmod(17, 2)
(8, 1)


Hope this helps.

P.S. please don't hijack threads by replying to an existing message, as 
it could lead to some people not seeing your email. It is better to 
start a new thread by using "New Message", not with "Reply".


-- 
Steven

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


Re: [Tutor] Question on how to do exponents

2012-02-06 Thread Nate Lastname
Exponents and remainder (modulus) are **(or ^) and % respectively.  I.E.;
d = a ** b (exponent)
c = a % b (modulus)

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


[Tutor] Question on how to do exponents

2012-02-06 Thread William Stewart
Hello everyone, I am making a calculator and I need to know how to make it do 
exponents and remainders
How can I input this info in python?
Any help would be appreciated
Thanks

--- On Mon, 2/6/12, Steven D'Aprano  wrote:


From: Steven D'Aprano 
Subject: Re: [Tutor] Sandbox Game
To: "tutor" 
Date: Monday, February 6, 2012, 7:50 PM


On Mon, Feb 06, 2012 at 09:13:48AM -0500, Nate Lastname wrote:
> Hello List,
> 
> I am quite sorry for my attitude.  I will look more thoroughly into the
> search results.  Thanks for the link to Epik.  I had found this, but I
> didn't realize that it was Python.  I apologize once again, and thank you
> for your help.  I did give you a link to a sandbox game (powdertoy.co.uk)
> as an example of what I wanted, but that must not have been delivered
> properly.

Thank you for the gracious apology, and welcome to the group!

Don't worry about asking stupid questions, we don't mind them so long as 
you make an effort to solve them yourself first, and that you learn from 
them as you go.


-- 
Steven

___
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


Re: [Tutor] Sandbox Game

2012-02-06 Thread Steven D'Aprano
On Mon, Feb 06, 2012 at 09:13:48AM -0500, Nate Lastname wrote:
> Hello List,
> 
> I am quite sorry for my attitude.  I will look more thoroughly into the
> search results.  Thanks for the link to Epik.  I had found this, but I
> didn't realize that it was Python.  I apologize once again, and thank you
> for your help.  I did give you a link to a sandbox game (powdertoy.co.uk)
> as an example of what I wanted, but that must not have been delivered
> properly.

Thank you for the gracious apology, and welcome to the group!

Don't worry about asking stupid questions, we don't mind them so long as 
you make an effort to solve them yourself first, and that you learn from 
them as you go.


-- 
Steven

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


Re: [Tutor] what is the basic difference

2012-02-06 Thread Alan Gauld

On 06/02/12 19:12, Debashish Saha wrote:

what is the basic difference between the commands
import pylab as *


Are you sure you don't mean

from pylab import *

???

The other form won't work because * is not a valid name in Python.
You should ghet a syntax error.


import matplotlib.pyplot as plt


This is just an abbreviation to save typing matplotlib.pyplot
in front of every reference to the module names.


import numpy as np


as above


import numpy as *


again an error.

--
Alan G
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] Sandbox Game

2012-02-06 Thread Nate Lastname
Thanks, Greg.  I actually have two projects on the pygame website, and
I already have a great book, too.  But thank you very much :D

-- 
My Blog - Defenestration Coding

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


Re: [Tutor] Sandbox Game

2012-02-06 Thread Greg Nielsen
Nate,

 I myself am a newer programmer with most of my experience in the use
of pygame, perhaps I could help point you in the right direction. First,
there is a lot of cool stuff over at the main pygame website, and a lot of
the users will post projects with images, general overviews, and a link to
their main codebase / content. It might take some searching, but you could
definitely find something similar to what you are working on there.
 While finding something similar to what you are working on would
really help you out, something you might find even better is this book by
Andy Harris
http://www.amazon.com/Game-Programming-Line-Express-Learning/dp/0470068221/ref=sr_1_5?s=books&ie=UTF8&qid=1328564353&sr=1-5
It's
an amazing resource that takes you from installing python to creating your
own games and even a game engine. There is a good chance that your local
library has a copy. If you are serious about learning game programming in
python, this is what you need to read.
 Lastly, speaking from experience. Start small. Just like Bob said,
start with just the absolute basics and slowly add to your program. Mr.
Harris' book demonstrates this in Chapter 7 perfectly. So check out
pygame's website and check out that book from your library. I promise it
will help you get started.

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


Re: [Tutor] Sandbox Game

2012-02-06 Thread Nate Lastname
Hold on... I just found one!  It's not ideal, but it will work at
least for a base -
http://www.pygame.org/project-pysand-1387-2577.html.  Thanks again,
all, for your excellent help!

The Defenestrator

On 2/6/12, Nate Lastname  wrote:
> Some more info:
>
> It's in pygame.
> It's 2d.
> I cannot find any python versions out there.  Yes, there is a
> graphical interface, and yes, it is a user-controlled game.
> Thank you all for your help!
>
> The Defenestrator
>
> On 2/6/12, bob gailer  wrote:
>> On 2/6/2012 11:16 AM, Nate Lastname wrote:
>>> Hey all,
>>>
>>> The basic idea is that there are different types of sand.  They fall
>>> and move (or don't, if they are solid) and interact with each other in
>>> different ways.  I.E.; there is a lava type;  it falls, and when it
>>> hits other sand types, it heats them up.  If it gets cold, it becomes
>>> sand.
>> Thanks for a top-level overview. I have no practical experience with
>> game /programming /, just some general concepts which I offer here, and
>> leave it to others to assist.
>>
>> You might add more specifics - do you want a graphics display? User
>> interaction? Anything you add to your description helps us and helps you
>> move to your goal.
>>
>> I suggest you start simple, get something working then add another
>> feature.
>>
>> Simple? Could be as simple as 1 grain falling till it hits bottom. Does
>> it have an initial velocity? Does it accelerate under the pull of
>> gravity? Velocity means speed and direction. What happens when it hits
>> bottom?
>>
>> Then add a 2nd grain. What happens if the 2 collide?
>>
>> What is your update rate (how often do you recompute the positions of
>> all the grains)? What is the smallest increment of position change?
>>
>> I assume you will create a class for each type of sand grain. with
>> relevant properties and methods.
>>
>> You will need a program that runs in a loop (probably with a sleep) to
>> -  update positions and  velocities of each grain (by invoking class
>> methods)
>> -  detect and manage collisions
>> -  display each grain (by invoking class methods)
>>
>> If you are using a graphics package I assume you will have a "canvas" on
>> which you will draw some kind of object to represent a particular class
>> of grain at the current x,y(,z?) coordinates of each grain.
>>
>> It is possible to change the base class of an object on-the-fly, so a
>> lava drop could become a sand grain.
>>
>> That's all for now. Good coding!
>>
>> I don't want to copy the game
>>
>> Is there a Python version out there?
>>> , I want to make my own to play around with Py(thon/game).
>>>
>>
>>
>> --
>> Bob Gailer
>> 919-636-4239
>> Chapel Hill NC
>>
>>
>
>
> --
> My Blog - Defenestration Coding
>
> http://defenestrationcoding.wordpress.com/
>


-- 
My Blog - Defenestration Coding

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


Re: [Tutor] Sandbox Game

2012-02-06 Thread Nate Lastname
Some more info:

It's in pygame.
It's 2d.
I cannot find any python versions out there.  Yes, there is a
graphical interface, and yes, it is a user-controlled game.
Thank you all for your help!

The Defenestrator

On 2/6/12, bob gailer  wrote:
> On 2/6/2012 11:16 AM, Nate Lastname wrote:
>> Hey all,
>>
>> The basic idea is that there are different types of sand.  They fall
>> and move (or don't, if they are solid) and interact with each other in
>> different ways.  I.E.; there is a lava type;  it falls, and when it
>> hits other sand types, it heats them up.  If it gets cold, it becomes
>> sand.
> Thanks for a top-level overview. I have no practical experience with
> game /programming /, just some general concepts which I offer here, and
> leave it to others to assist.
>
> You might add more specifics - do you want a graphics display? User
> interaction? Anything you add to your description helps us and helps you
> move to your goal.
>
> I suggest you start simple, get something working then add another feature.
>
> Simple? Could be as simple as 1 grain falling till it hits bottom. Does
> it have an initial velocity? Does it accelerate under the pull of
> gravity? Velocity means speed and direction. What happens when it hits
> bottom?
>
> Then add a 2nd grain. What happens if the 2 collide?
>
> What is your update rate (how often do you recompute the positions of
> all the grains)? What is the smallest increment of position change?
>
> I assume you will create a class for each type of sand grain. with
> relevant properties and methods.
>
> You will need a program that runs in a loop (probably with a sleep) to
> -  update positions and  velocities of each grain (by invoking class
> methods)
> -  detect and manage collisions
> -  display each grain (by invoking class methods)
>
> If you are using a graphics package I assume you will have a "canvas" on
> which you will draw some kind of object to represent a particular class
> of grain at the current x,y(,z?) coordinates of each grain.
>
> It is possible to change the base class of an object on-the-fly, so a
> lava drop could become a sand grain.
>
> That's all for now. Good coding!
>
> I don't want to copy the game
>
> Is there a Python version out there?
>> , I want to make my own to play around with Py(thon/game).
>>
>
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
>


-- 
My Blog - Defenestration Coding

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


Re: [Tutor] Backwards message program

2012-02-06 Thread bob gailer

On 2/6/2012 2:05 PM, myles broomes wrote:
Im trying to code a program where the user enters a message and it is 
returned backwards. Here is my code so far:





message = input("Enter your message: ")

backw = ""
counter = len(message)

while message != 0:
backw += message[counter-1]
counter -= 1

print(backw)
input("\nPress enter to exit...")




I run the program, type in my message but get back the error code:

'IndexError: String out of range'

I was thinking that maybe the problem is that each time a letter is 
taken from 'message' and added to 'backw', the length of message 
becomes a letter shorter
1 - message never changes. Why did you think letters were "taken" from 
it? They are copied.

2 - comparing an integer to a string is always False


--
Bob Gailer
919-636-4239
Chapel Hill NC
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what is the basic difference

2012-02-06 Thread Dave Angel

On 02/06/2012 02:12 PM, Debashish Saha wrote:

what is the basic difference between the commands
import pylab as *
import matplotlib.pyplot as plt
import numpy as np
import numpy as *
import pylab as *pollutes your global namespace with all kinds of 
symbols.  If you don't know them all, you might accidentally use one of 
them in your own code, and wonder why things aren't working the way you 
expected.


Better is
   import pylab

and then use  pylab.something  to access a symbol from pylab

Some prefer
import pylab as pab
 (or something)

and then use   pab.something to save some typing.

import matplotlib.pyplot as plt

looks in the matplotlib *package" for the module pyplot, then imports it 
with a shortcut name of plt




--

DaveA

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


Re: [Tutor] Backwards message program

2012-02-06 Thread Dave Angel

On 02/06/2012 02:05 PM, myles broomes wrote:

Im trying to code a program where the user enters a message and it is returned 
backwards. Here is my code so far:





message = input("Enter your message: ")

backw = ""
counter = len(message)

while message != 0:
 backw += message[counter-1]
 counter -= 1
print(backw)
input("\nPress enter to exit...")





I run the program, type in my message but get back the error code:

'IndexError: String out of range'

I was thinking that maybe the problem is that each time a letter is taken from 
'message' and added to 'backw', the length of message becomes a letter shorter 
but for whatever reason the variable 'counter' doesnt change when its supposed 
to be minused by 1 letter so its always bigger than message if that makes 
sense. Any help is much appreciated and thanks in advance.

Myles Broomes


First, what's the python version and OS?   If you run that program under 
2.x, it'll quit a lot sooner.  So I figure Python 3.2


Next, don't retype the message, copy& paste it.  Your retype missed an 
important word of the message, and you didn't include the traceback, 
which is also important.


Now to your problem:  You never change message, so the while loop never 
terminates (except with the exception when it tries an index that's too 
far negative.  The obvious answer is to terminate the loop when counter 
goes negative.  But it might also be readable to terminate it when the 
two strings have the same length.


There are many other ways to reverse a string, but I wanted to show you 
what went wrong in this particular code.


If I were an instructor, the next thing I'd suggest is to ask you how to 
use a for-loop, instead of a while.  Or to look up the slice syntax, and 
see what the restrictions are of getting substrings from that.


--

DaveA

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


[Tutor] what is the basic difference

2012-02-06 Thread Debashish Saha
what is the basic difference between the commands
import pylab as *
import matplotlib.pyplot as plt
import numpy as np
import numpy as *
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Backwards message program

2012-02-06 Thread myles broomes

Im trying to code a program where the user enters a message and it is returned 
backwards. Here is my code so far:
 



 
message = input("Enter your message: ")
 
backw = ""
counter = len(message)
 
while message != 0:
backw += message[counter-1]
counter -= 1
print(backw)
input("\nPress enter to exit...")
 



 
I run the program, type in my message but get back the error code:
 
'IndexError: String out of range'
 
I was thinking that maybe the problem is that each time a letter is taken from 
'message' and added to 'backw', the length of message becomes a letter shorter 
but for whatever reason the variable 'counter' doesnt change when its supposed 
to be minused by 1 letter so its always bigger than message if that makes 
sense. Any help is much appreciated and thanks in advance.

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


Re: [Tutor] Trouble with encoding/decoding a file

2012-02-06 Thread ALAN GAULD
That's not too surprising. Text files use an end-of-file character combination. 
You might be lucky and not encounter that set of bytes in your file or you 
might be unlucky and find it, in which case the file gets truncated. 
That's why you need the binary setting, to ensure you read the 
whole file!
 
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/



>
> From: Tony Pelletier 
>To: Alan Gauld  
>Cc: tutor@python.org 
>Sent: Monday, 6 February 2012, 18:40
>Subject: Re: [Tutor] Trouble with encoding/decoding a file
> 
>
>
>
>
>On Mon, Feb 6, 2012 at 1:13 PM, Alan Gauld  wrote:
>
>On 06/02/12 15:11, Tony Pelletier wrote:
>>
>>Hi,
>>>
>>>I've been tasked with getting the encoded value using a SOAP call and
>>>then writing the file out.  I first used the interpreter to do so like such:
>>>
>>>import base64
>>>
>>>encoded = 'super long encoded string'
>>>data = base64.b64decode(encoded)
>>>outfile = open('test.xls', 'w')
>>>
>>
>>
>>Have you tried opening as a binary file?
>>>Excel .xls uses binary data...
>
>
>Unbelievable.  In the snippet you quoted above, it didn't matter.  That one 
>always worked, but changing it in the code I wrote, it totally fixed it.  :)
>
>
>Thanks! 
>
>>-- 
>>Alan G
>>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
>>
>
>
>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise with classes

2012-02-06 Thread Dave Angel

On 02/06/2012 01:24 PM, Tonu Mikk wrote:

Now I get an error:  NameError: global name 'self' is not define.

Tonu


Put your remarks after the stuff you quote.  You're top-posting, which 
makes the reply difficult to follow.


Use copy/paste to describe an error message.  You retyped the one above, 
and added a typo.  Include the whole error, which includes the stack trace.


If you had followed Nate's advice, you couldn't have gotten that error 
at all, so you'll also need to post the code that actually triggers the 
error.






--

DaveA

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


Re: [Tutor] Trouble with encoding/decoding a file

2012-02-06 Thread Tony Pelletier
On Mon, Feb 6, 2012 at 1:13 PM, Alan Gauld wrote:

> On 06/02/12 15:11, Tony Pelletier wrote:
>
>> Hi,
>>
>> I've been tasked with getting the encoded value using a SOAP call and
>> then writing the file out.  I first used the interpreter to do so like
>> such:
>>
>> import base64
>>
>> encoded = 'super long encoded string'
>> data = base64.b64decode(encoded)
>> outfile = open('test.xls', 'w')
>>
>
>
> Have you tried opening as a binary file?
>> Excel .xls uses binary data...
>
>
Unbelievable.  In the snippet you quoted above, it didn't matter.  That one
always worked, but changing it in the code I wrote, it totally fixed it.  :)

Thanks!

>
> --
> Alan G
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise with classes

2012-02-06 Thread Tonu Mikk
Now I get an error:  NameError: global name 'self' is not define.

Tonu

On Mon, Feb 6, 2012 at 10:19 AM, Nate Lastname  wrote:

> Hey Tonu,
>
> The problem is that in your statement definition, you are not
> including the self argument.  Your definition needs to be something
> like:
> def dolt(self):
>   # Do stuff.
> For more info on the self keyword, see
> http://docs.python.org/tutorial/classes.html, section 9.3.2.
>
> On 2/6/12, Tonu Mikk  wrote:
> > Alan, thanks for explaining about passing objects to classes.  This is an
> > important concept for me to understand.
> >
> > I tried running the code, but run into an error that I could not resolve:
> >
> > TypeError: doIt() takes no arguments (1 given).
> >
> > Tonu
> >
> > On Thu, Feb 2, 2012 at 7:09 PM, Alan Gauld  >wrote:
> >
> >> On 02/02/12 17:36, Tonu Mikk wrote:
> >>
> >>  So far I have searched for info on how to pass variables from one class
> >>> to another and have been able to create a small two class program
> >>> (attached).   But I seem unable to generalize from here and apply this
> >>> to the game exercise.  What would you suggest for me to try next?
> >>>
> >>
> >> Remember that OOP is about creating objects from classes.
> >> You can pass an object to another rather than just the
> >> variables, in fact its preferable!
> >>
> >> Also remember that you can create many objects from one class.
> >> So just because you have one Room class doesn't mean you are
> >> stuck with one room object. You can have many and each can
> >> be connected to another.
> >>
> >> You can get rooms to describe themselves, you can enter a room.
> >> You might even be able to create new rooms or destroy existing ones.
> These
> >> actions can all be methods of your Room class.
> >>
> >> Here is an example somewhat like yours that passes objects:
> >>
> >> class Printer:
> >>   def __init__(self,number=0):
> >>  self.value = number
> >>   def sayIt(self):
> >>  print self.value
> >>
> >> class MyApp:
> >>   def __init__(self, aPrinter = None):
> >>   if aPrinter == None: # if no object passed create one
> >>  aPrinter = Printer()
> >>   self.obj = aPrinter  # assign object
> >>   def doIt()
> >>   self.obj.sayIt() # use object
> >>
> >> def test()
> >>   p = Printer(42)
> >>   a1  MyApp()
> >>   a2 = MyApp(p)   # pass p object into a2
> >>   a1.doIt()   # prints default value = 0
> >>   a2.doIt()   # prints 42, the value of p
> >>
> >> test()
> >>
> >> HTH,
> >>
> >> --
> >> Alan G
> >> 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<
> http://mail.python.org/mailman/listinfo/tutor>
> >>
> >
> >
> >
> > --
> > Tonu Mikk
> > Disability Services, Office for Equity and Diversity
> > 612 625-3307
> > tm...@umn.edu
> >
>
>
> --
> My Blog - Defenestration Coding
>
> http://defenestrationcoding.wordpress.com/
>



-- 
Tonu Mikk
Disability Services, Office for Equity and Diversity
612 625-3307
tm...@umn.edu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise with classes

2012-02-06 Thread Alan Gauld

On 06/02/12 16:12, Tonu Mikk wrote:

Alan, thanks for explaining about passing objects to classes.  This is
an important concept for me to understand.

I tried running the code, but run into an error that I could not resolve:

TypeError: doIt() takes no arguments (1 given).


Sorry the code was only meant for illustration and had not nbeen tested.
I forgot the self in the definition of doit()... And probably other 
stuff too!


Alan G.

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


Re: [Tutor] Trouble with encoding/decoding a file

2012-02-06 Thread Alan Gauld

On 06/02/12 15:11, Tony Pelletier wrote:

Hi,

I've been tasked with getting the encoded value using a SOAP call and
then writing the file out.  I first used the interpreter to do so like such:

import base64

encoded = 'super long encoded string'
data = base64.b64decode(encoded)
outfile = open('test.xls', 'w')



Have you tried opening as a binary file?
Excel .xls uses binary data...

--
Alan G
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] python editor

2012-02-06 Thread Alan Gauld

On 06/02/12 17:17, bob gailer wrote:

On 2/6/2012 10:25 AM, Kapil Shukla wrote:


Please also suggest a free editor for python which can at least repeat
previous command with a key stroke


That depends on the editor's mode of operation.
In an editor like vi (elvis, vim etc) there is a repeat key (the period)
that repeats most things because most things are a "command" - even 
inserting text. but in a so called modeless editor (most modern ones)
repeat will be restricted to things that are recognised as atomic 
operations, like search/replace, change case etc. And some of those will 
only be valid when text is selected (so not really modeless!).


Other editors like emacs allow you to specify how often an action is 
repeated. So esc-16 n will insert 16 n's for example.


You would need to be more specific in terms of what you want in a repeat 
operation.


--
Alan G
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] Sandbox Game

2012-02-06 Thread bob gailer

On 2/6/2012 11:16 AM, Nate Lastname wrote:

Hey all,

The basic idea is that there are different types of sand.  They fall
and move (or don't, if they are solid) and interact with each other in
different ways.  I.E.; there is a lava type;  it falls, and when it
hits other sand types, it heats them up.  If it gets cold, it becomes
sand.
Thanks for a top-level overview. I have no practical experience with 
game /programming /, just some general concepts which I offer here, and 
leave it to others to assist.


You might add more specifics - do you want a graphics display? User 
interaction? Anything you add to your description helps us and helps you 
move to your goal.


I suggest you start simple, get something working then add another feature.

Simple? Could be as simple as 1 grain falling till it hits bottom. Does 
it have an initial velocity? Does it accelerate under the pull of 
gravity? Velocity means speed and direction. What happens when it hits 
bottom?


Then add a 2nd grain. What happens if the 2 collide?

What is your update rate (how often do you recompute the positions of 
all the grains)? What is the smallest increment of position change?


I assume you will create a class for each type of sand grain. with 
relevant properties and methods.


You will need a program that runs in a loop (probably with a sleep) to
-  update positions and  velocities of each grain (by invoking class 
methods)

-  detect and manage collisions
-  display each grain (by invoking class methods)

If you are using a graphics package I assume you will have a "canvas" on 
which you will draw some kind of object to represent a particular class 
of grain at the current x,y(,z?) coordinates of each grain.


It is possible to change the base class of an object on-the-fly, so a 
lava drop could become a sand grain.


That's all for now. Good coding!

I don't want to copy the game

Is there a Python version out there?

, I want to make my own to play around with Py(thon/game).




--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] python editor

2012-02-06 Thread bob gailer

On 2/6/2012 10:25 AM, Kapil Shukla wrote:

Please also suggest a free editor for python which can at least repeat 
previous command with a key stroke


It is better to ask an unrelated question in a separate email, with its 
own relevant subject.


Please give an example of what you mean by "epeat previous command". I 
can think of several unrelated meanings.


Personally I prefer an IDE. My favorites are PyCharm ($) and Python for 
Windows (free).


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Problem with smtplib

2012-02-06 Thread bob gailer

On 2/6/2012 6:05 AM, Nikolay Moskvin wrote:

Hi, all
I have a problem with sending mail via smtp. This error does not always
happen. Does somebody seen this stacktrace?

I've seen many like that. It means exactly what it says.

"Connection unexpectedly closed"

Most likely something went awry with the internet connection between 
your computer and the SMTP server. Best strategy I know of is to trap 
the exception and retry, but for a limited # of times.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] exercise with classes

2012-02-06 Thread Nate Lastname
Hey Tonu,

The problem is that in your statement definition, you are not
including the self argument.  Your definition needs to be something
like:
def dolt(self):
   # Do stuff.
For more info on the self keyword, see
http://docs.python.org/tutorial/classes.html, section 9.3.2.

On 2/6/12, Tonu Mikk  wrote:
> Alan, thanks for explaining about passing objects to classes.  This is an
> important concept for me to understand.
>
> I tried running the code, but run into an error that I could not resolve:
>
> TypeError: doIt() takes no arguments (1 given).
>
> Tonu
>
> On Thu, Feb 2, 2012 at 7:09 PM, Alan Gauld wrote:
>
>> On 02/02/12 17:36, Tonu Mikk wrote:
>>
>>  So far I have searched for info on how to pass variables from one class
>>> to another and have been able to create a small two class program
>>> (attached).   But I seem unable to generalize from here and apply this
>>> to the game exercise.  What would you suggest for me to try next?
>>>
>>
>> Remember that OOP is about creating objects from classes.
>> You can pass an object to another rather than just the
>> variables, in fact its preferable!
>>
>> Also remember that you can create many objects from one class.
>> So just because you have one Room class doesn't mean you are
>> stuck with one room object. You can have many and each can
>> be connected to another.
>>
>> You can get rooms to describe themselves, you can enter a room.
>> You might even be able to create new rooms or destroy existing ones. These
>> actions can all be methods of your Room class.
>>
>> Here is an example somewhat like yours that passes objects:
>>
>> class Printer:
>>   def __init__(self,number=0):
>>  self.value = number
>>   def sayIt(self):
>>  print self.value
>>
>> class MyApp:
>>   def __init__(self, aPrinter = None):
>>   if aPrinter == None: # if no object passed create one
>>  aPrinter = Printer()
>>   self.obj = aPrinter  # assign object
>>   def doIt()
>>   self.obj.sayIt() # use object
>>
>> def test()
>>   p = Printer(42)
>>   a1  MyApp()
>>   a2 = MyApp(p)   # pass p object into a2
>>   a1.doIt()   # prints default value = 0
>>   a2.doIt()   # prints 42, the value of p
>>
>> test()
>>
>> HTH,
>>
>> --
>> Alan G
>> 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
>>
>
>
>
> --
> Tonu Mikk
> Disability Services, Office for Equity and Diversity
> 612 625-3307
> tm...@umn.edu
>


-- 
My Blog - Defenestration Coding

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


Re: [Tutor] decimal precision in python

2012-02-06 Thread Modulok
For money, you should probably use the builtin module 'decimal' instead:

http://docs.python.org/library/decimal.html

There's also the third party module 'mpmath' which provides arbitrary precision
floating point arithmetic.

http://mpmath.googlecode.com/svn/trunk/doc/build/index.html

-Modulok-

On 2/6/12, Kapil Shukla  wrote:
> i tried writing a small code to calculate option price using the binomial
> tree model. I compared my results with results of the same program in
> excel. There seems to be a minor difference due to decimal precision as
> excel is using 15 decimal precision and python (both 2.7 and 3.1) using 11.
> (at least that's what shown on shell)
>
> can some one guide me whats the equivalent of using a double datatype on
> python and i can't use long() in 3.1 any more.
>
> Please also suggest a free editor for python which can at least repeat
> previous command with a key stroke
>
> regards
> kapil
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sandbox Game

2012-02-06 Thread Nate Lastname
Hey all,

The basic idea is that there are different types of sand.  They fall
and move (or don't, if they are solid) and interact with each other in
different ways.  I.E.; there is a lava type;  it falls, and when it
hits other sand types, it heats them up.  If it gets cold, it becomes
sand.

I don't want to copy the game, I want to make my own to play around
with Py(thon/game).  Thanks for your help!

-- 
My Blog - Defenestration Coding

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


Re: [Tutor] exercise with classes

2012-02-06 Thread Tonu Mikk
Alan, thanks for explaining about passing objects to classes.  This is an
important concept for me to understand.

I tried running the code, but run into an error that I could not resolve:

TypeError: doIt() takes no arguments (1 given).

Tonu

On Thu, Feb 2, 2012 at 7:09 PM, Alan Gauld wrote:

> On 02/02/12 17:36, Tonu Mikk wrote:
>
>  So far I have searched for info on how to pass variables from one class
>> to another and have been able to create a small two class program
>> (attached).   But I seem unable to generalize from here and apply this
>> to the game exercise.  What would you suggest for me to try next?
>>
>
> Remember that OOP is about creating objects from classes.
> You can pass an object to another rather than just the
> variables, in fact its preferable!
>
> Also remember that you can create many objects from one class.
> So just because you have one Room class doesn't mean you are
> stuck with one room object. You can have many and each can
> be connected to another.
>
> You can get rooms to describe themselves, you can enter a room.
> You might even be able to create new rooms or destroy existing ones. These
> actions can all be methods of your Room class.
>
> Here is an example somewhat like yours that passes objects:
>
> class Printer:
>   def __init__(self,number=0):
>  self.value = number
>   def sayIt(self):
>  print self.value
>
> class MyApp:
>   def __init__(self, aPrinter = None):
>   if aPrinter == None: # if no object passed create one
>  aPrinter = Printer()
>   self.obj = aPrinter  # assign object
>   def doIt()
>   self.obj.sayIt() # use object
>
> def test()
>   p = Printer(42)
>   a1  MyApp()
>   a2 = MyApp(p)   # pass p object into a2
>   a1.doIt()   # prints default value = 0
>   a2.doIt()   # prints 42, the value of p
>
> test()
>
> HTH,
>
> --
> Alan G
> 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
>



-- 
Tonu Mikk
Disability Services, Office for Equity and Diversity
612 625-3307
tm...@umn.edu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sandbox Game

2012-02-06 Thread bob gailer

On 2/6/2012 9:16 AM, Nate Lastname wrote:
P.S.:  I also would like to say that I am a noob at Python, Pygame, 
and the list.  I'll try not to post more stupid questions, though. 

We are here to help the newcomers. Questions are not "stupid".

The easier you make it for us to answer the more likely you are to get 
answers. We volunteer our time to help you; we are not paid money for 
our service.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Sandbox Game

2012-02-06 Thread bob gailer

On 2/6/2012 9:13 AM, Nate Lastname wrote:

Hello List,

I am quite sorry for my attitude.  I will look more thoroughly into 
the search results.  Thanks for the link to Epik.  I had found this, 
but I didn't realize that it was Python.  I apologize once again, and 
thank you for your help.  I did give you a link to a sandbox game 
(powdertoy.co.uk ) as an example of what I 
wanted, but that must not have been delivered properly.
The link came thru fine. I expected some description of the game rather 
than having to download something. I am reluctant todownload unknowns. I 
even tried the Play Online and got to another messy connfusing site,


Could you give an overview of the game?

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] decimal precision in python

2012-02-06 Thread Dave Angel

On 02/06/2012 10:25 AM, Kapil Shukla wrote:

i tried writing a small code to calculate option price using the binomial
tree model. I compared my results with results of the same program in
excel. There seems to be a minor difference due to decimal precision as
excel is using 15 decimal precision and python (both 2.7 and 3.1) using 11.
(at least that's what shown on shell)

can some one guide me whats the equivalent of using a double datatype on
python and i can't use long() in 3.1 any more.

Please also suggest a free editor for python which can at least repeat
previous command with a key stroke

regards
kapil


A Python float is equivalent to a C double;  it's already about 18 
digits, using the IEEE binary hardware available on most modern 
systems.  However, it's a binary value, so it'll round in different 
places than the decimal values that Excel probably uses.


You might want to read this: 
http://docs.python.org/tutorial/floatingpoint.html


From the subject you choose, you are apparently asking for a decimal 
package.  You can use the python decimal package if you actually need 
the round-off to be according to decimal's quirks.  Certainly that's 
easier (and slower) to deal with.  Or you can use decimal because you 
need more than about 18 digits.  It defaults to 28, but you can set it 
higher or lower.   import decimal.


http://docs.python.org/library/decimal.html 




For a free editor that's python friendly, I'd suggest Komodo Edit,
http://www.activestate.com/komodo-edit

I use the non-free Komodo-ide, which is based on the free editor.




--

DaveA

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


Re: [Tutor] decimal precision in python

2012-02-06 Thread James Reynolds
On Mon, Feb 6, 2012 at 10:25 AM, Kapil Shukla wrote:

> i tried writing a small code to calculate option price using the binomial
> tree model. I compared my results with results of the same program in
> excel. There seems to be a minor difference due to decimal precision as
> excel is using 15 decimal precision and python (both 2.7 and 3.1) using 11.
> (at least that's what shown on shell)
>
> can some one guide me whats the equivalent of using a double datatype on
> python and i can't use long() in 3.1 any more.
>
> Please also suggest a free editor for python which can at least repeat
> previous command with a key stroke
>
> regards
> kapil
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
Have you looked into the decimal module? (you need to import decimal)

http://docs.python.org/library/decimal.html

You can specify the amount of precision needed.

Also, i would suggest using 3.2, if it's not too late in your project.

As for editors, I hear VIM is good. I use Eclipse as an IDE personally.
People seem to have some fairly definite ideas on what editor other people
should use, bordering on religious fanaticism.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decimal precision in python

2012-02-06 Thread Steve Willoughby

On 06-Feb-12 07:25, Kapil Shukla wrote:

i tried writing a small code to calculate option price using the
binomial tree model. I compared my results with results of the same
program in excel. There seems to be a minor difference due to decimal
precision as excel is using 15 decimal precision and python (both 2.7
and 3.1) using 11. (at least that's what shown on shell)


If you need lots of precision, you might consider using the decimal 
class.  It'll cost you speed vs. the native floating-point type but 
won't cause you round-off errors.


natively, Python uses IEEE double-precision math for all float objects.

For a float value x, instead of just printing it, try this:

print('{0:.30f}'.format(x))


can some one guide me whats the equivalent of using a double datatype on
python and i can't use long() in 3.1 any more.


Equivalent to what degree?  Python's float class generally will get you 
where you need to go.  Also the int type automatically extends to 
arbitrary-precision integer values so you don't need explicit "long" 
type anymore.  (Unless I misunderstood your question there.)



Please also suggest a free editor for python which can at least repeat
previous command with a key stroke


I use vim, which has that feature.  I suspect any editor worth its salt 
does, or could be programmed to.



--
Steve Willoughby / st...@alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] decimal precision in python

2012-02-06 Thread Kapil Shukla
i tried writing a small code to calculate option price using the binomial
tree model. I compared my results with results of the same program in
excel. There seems to be a minor difference due to decimal precision as
excel is using 15 decimal precision and python (both 2.7 and 3.1) using 11.
(at least that's what shown on shell)

can some one guide me whats the equivalent of using a double datatype on
python and i can't use long() in 3.1 any more.

Please also suggest a free editor for python which can at least repeat
previous command with a key stroke

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


[Tutor] Trouble with encoding/decoding a file

2012-02-06 Thread Tony Pelletier
Hi,

I've been tasked with getting the encoded value using a SOAP call and then
writing the file out.  I first used the interpreter to do so like such:

import base64

encoded = 'super long encoded string'
data = base64.b64decode(encoded)
outfile = open('test.xls', 'w')
outfile.write(data)
outfile.close

And that all worked just fine.  The difference here is I am cutting and
pasting the encoded value into a string from notepad++.

So, I then did the following which I can't get working.  It keeps telling
me "excel found unreadable content in the file' essentially being corrupt
and I can't tell what I'm doing wrong.

try:
eventresult = service.client.service.EventQueryById(event, 'true')
filename = eventresult.Event[0].EventFileArgs.EventFileArg[0].UserFileName
encodedfile =
str(eventresult.Event[0].EventFileArgs.EventFileArg[0].EncodedValue)
encodedstring = encodedfile.encode('utf-8')
str_list = []
for line in encodedstring:
line = line.strip()
str_list.append(line)
string = ''.join(str_list)
print string
data = base64.b64decode(string)
txtfile = open('trp.txt', 'w')
txtfile.write(string)
outfile = open(filename, 'w')
outfile.write(data)
outfile.close()
except suds.WebFault as e:
print e.fault.detail

The txt file is only there to make sure I'm writing out one long string
which is what I'm pasting in so I'm assuming that's correct.  Any help is
greatly appreciated.

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


Re: [Tutor] Sandbox Game

2012-02-06 Thread Nate Lastname
P.S.:  I also would like to say that I am a noob at Python, Pygame, and the
list.  I'll try not to post more stupid questions, though.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sandbox Game

2012-02-06 Thread Nate Lastname
Hello List,

I am quite sorry for my attitude.  I will look more thoroughly into the
search results.  Thanks for the link to Epik.  I had found this, but I
didn't realize that it was Python.  I apologize once again, and thank you
for your help.  I did give you a link to a sandbox game (powdertoy.co.uk)
as an example of what I wanted, but that must not have been delivered
properly.

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


[Tutor] Problem with smtplib

2012-02-06 Thread Nikolay Moskvin
Hi, all
I have a problem with sending mail via smtp. This error does not always 
happen. Does somebody seen this stacktrace?
smtp.sendmail(send_from, send_to, msg.as_string())
  File "/usr/local/lib/python2.7/smtplib.py", line 725, in sendmail
(code, resp) = self.data(msg)
  File "/usr/local/lib/python2.7/smtplib.py", line 482, in data
(code, repl) = self.getreply()
  File "/usr/local/lib/python2.7/smtplib.py", line 352, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
-- 
Best regards,
Nikolay Moskvin
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor