[Tutor] Suggestions required on Gaming

2006-10-04 Thread Arun Kumar PG
Hi All Python lovers!I want to develop a Car racing game using Python. I was looking for the libraries which I should use for the same. Some of the options are below and I want you suggestions about the best set of tools and APIs as per your experiences:
- PyGame- Panda3D- Pixie for rendering- RenderMan- What else ?I will really appreciate if you guys could please let me know the right set of tools and APIs as per your experience.Thanks,
- Arun
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggestions required on Gaming

2006-10-04 Thread Luke Paireepinart
Arun Kumar PG wrote:
> Hi All Python lovers!
>
>
> I want to develop a Car racing game using Python. I was looking for 
> the libraries which I should use for the same. Some of the options are 
> below and I want you suggestions about the best set of tools and APIs 
> as per your experiences:
>
> - PyGame
> - Panda3D
> - Pixie for rendering
> - RenderMan
> - What else ?
>
> I will really appreciate if you guys could please let me know the 
> right set of tools and APIs as per your experience.
Need more info.
There are many types of car-racing games.
Do you want it to be 3d, 2d? first-person, third-person, top-down, etc.
The correct tool is the one which does the specific job best.
We don't know what the job is so we can't help you choose a tool.
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggestions required on Gaming

2006-10-04 Thread Arun Kumar PG
Thanks Luke.I want to make a 3-D car race game between two players. And yes its gonna  be a networked game where each user will be using his/her own PC and playing.- Arun
On 10/4/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
Arun Kumar PG wrote:> Hi All Python lovers!>>> I want to develop a Car racing game using Python. I was looking for> the libraries which I should use for the same. Some of the options are
> below and I want you suggestions about the best set of tools and APIs> as per your experiences:>> - PyGame> - Panda3D> - Pixie for rendering> - RenderMan> - What else ?
>> I will really appreciate if you guys could please let me know the> right set of tools and APIs as per your experience.Need more info.There are many types of car-racing games.Do you want it to be 3d, 2d? first-person, third-person, top-down, etc.
The correct tool is the one which does the specific job best.We don't know what the job is so we can't help you choose a tool.-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggestions required on Gaming

2006-10-04 Thread Arun Kumar PG
Also, my idea is to have a centralised Python server which acts as a dispachter to send the coordinate and other information to the gaming clients.On 10/4/06, 
Arun Kumar PG <[EMAIL PROTECTED]> wrote:
Thanks Luke.I want to make a 3-D car race game between two players. And yes its gonna  be a networked game where each user will be using his/her own PC and playing.- Arun

On 10/4/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote:

Arun Kumar PG wrote:> Hi All Python lovers!>>> I want to develop a Car racing game using Python. I was looking for> the libraries which I should use for the same. Some of the options are
> below and I want you suggestions about the best set of tools and APIs> as per your experiences:>> - PyGame> - Panda3D> - Pixie for rendering> - RenderMan> - What else ?
>> I will really appreciate if you guys could please let me know the> right set of tools and APIs as per your experience.Need more info.There are many types of car-racing games.Do you want it to be 3d, 2d? first-person, third-person, top-down, etc.
The correct tool is the one which does the specific job best.We don't know what the job is so we can't help you choose a tool.-Luke


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggestions required on Gaming

2006-10-04 Thread Luke Paireepinart
Arun Kumar PG wrote:
> Thanks Luke.
>
> I want to make a 3-D car race game between two players. And yes its 
> gonna  be a networked game where each user will be using his/her own 
> PC and playing.
If you want it to be 3d, you have a couple'o choices...
Pygame with the PyopenGL interface,
Panda3d,
Soya,
PyOgre,
and perhaps others.
The only one I've used was Panda3d, and I didn't get very far, so I 
can't comment on that.  I can say, though,
I've played Disney's Toontown game, which is a 3d mmorpg made with 
Panda3d, so yes, it's possible to make 3d networked games in Python :)

 >Also, my idea is to have a centralised Python server which acts as a 
dispachter to send the coordinate and other information to the gaming 
clients.

For your networking, you'll probably want to use Twisted.

HTH,
-Luke
>
> - Arun
>
>
> On 10/4/06, *Luke Paireepinart* <[EMAIL PROTECTED] 
> > wrote:
>
> Arun Kumar PG wrote:
> > Hi All Python lovers!
> >
> >
> > I want to develop a Car racing game using Python. I was looking for
> > the libraries which I should use for the same. Some of the
> options are
> > below and I want you suggestions about the best set of tools and
> APIs
> > as per your experiences:
> >
> > - PyGame
> > - Panda3D
> > - Pixie for rendering
> > - RenderMan
> > - What else ?
> >
> > I will really appreciate if you guys could please let me know the
> > right set of tools and APIs as per your experience.
> Need more info.
> There are many types of car-racing games.
> Do you want it to be 3d, 2d? first-person, third-person, top-down,
> etc.
> The correct tool is the one which does the specific job best.
> We don't know what the job is so we can't help you choose a tool.
> -Luke
>
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggestions required on Gaming

2006-10-04 Thread Arun Kumar PG
Thanks Luke! This is helpful :)- ArunOn 10/4/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
Arun Kumar PG wrote:> Thanks Luke.>> I want to make a 3-D car race game between two players. And yes its
> gonna  be a networked game where each user will be using his/her own> PC and playing.If you want it to be 3d, you have a couple'o choices...Pygame with the PyopenGL interface,Panda3d,Soya,
PyOgre,and perhaps others.The only one I've used was Panda3d, and I didn't get very far, so Ican't comment on that.  I can say, though,I've played Disney's Toontown game, which is a 3d mmorpg made with
Panda3d, so yes, it's possible to make 3d networked games in Python :) >Also, my idea is to have a centralised Python server which acts as adispachter to send the coordinate and other information to the gaming
clients.For your networking, you'll probably want to use Twisted.HTH,-Luke>> - Arun>>> On 10/4/06, *Luke Paireepinart* <
[EMAIL PROTECTED]> [EMAIL PROTECTED]>> wrote:>> Arun Kumar PG wrote:> > Hi All Python lovers!> >
> >> > I want to develop a Car racing game using Python. I was looking for> > the libraries which I should use for the same. Some of the> options are> > below and I want you suggestions about the best set of tools and
> APIs> > as per your experiences:> >> > - PyGame> > - Panda3D> > - Pixie for rendering> > - RenderMan> > - What else ?
> >> > I will really appreciate if you guys could please let me know the> > right set of tools and APIs as per your experience.> Need more info.> There are many types of car-racing games.
> Do you want it to be 3d, 2d? first-person, third-person, top-down,> etc.> The correct tool is the one which does the specific job best.> We don't know what the job is so we can't help you choose a tool.
> -Luke>>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGKit

2006-10-04 Thread Kent Johnson
Carlos wrote:
> Thanks Luke and Kent,
> 
> To get CGKit running I need to do two different things:
> 
> First the Python Computer Graphics Kit is composed by an 
> "cgkit-2.0.0alpha6.win32-py2.4.exe" file and some dependencies that are 
> PyProtocols, numarray, PyOpenGL, PIL, pygame, PyODE and pySerial, with 
> the exception of PyProtocols I have installed all of them. When I try to 
> install PyProtocols from the command prompt it tells me that " The .NET 
> Framework SDK needs to be installed before building extensions for 
> Python." I went to Microsoft and installed the "Microsoft .NET Framework 
> SDK v2.0", but the problem persists.
> 
> The second part is the Python Maya Plug-In. I think that this is the 
> tricky one, it is asking me to install Py++, that I have already 
> installed. Now my problem comes when I have to compile the source code 
> with Boost.Python, this one asks for Boost Jam and Boost. I have been 
> trying to install this things but still have no clue at how.

Use the compiled plug-in. This page:
http://cgkit.sourceforge.net/mayadoc/install.html
says to copy sourcepy.mll to the Maya plug-in directory.

Python extensions for Windows are usually distributed as binaries 
because so many people do not have the resources and knowledge to 
compile them. I don't see anything in the Maya plugin docs to indicate 
that you have to build it from source.

Kent


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating Adventure Games Python Port - Chapter 2

2006-10-04 Thread Matthew Warren
> =
> import random
> 
> coin1 = 0
> coin2 = 0
> 
> coin1 = random.randint(1, 10)
> coin2 = random.randint(1, 10)
> 
> if coin1 <= 5:
> print "Coin1 is Heads"
> else:
> print "Coin1 is Tails"
> 
> if coin2 <= 5:
> print "Coin2 is Heads"
> else:
> print "Coin2 is Tails"
> =

This one does the same thing. Thought I'd post it to help your learning
along :)

import random
for coin in [1,2]:
if random.randint(0,1):
print "Coin",coin,"is Heads"
else: 
print "Coin",coin,"is Tails"

Matt.


This email is confidential and may be privileged. If you are not the intended 
recipient please notify the sender immediately and delete the email from your 
computer. 

You should not copy the email, use it for any purpose or disclose its contents 
to any other person.
Please note that any views or opinions presented in this email may be personal 
to the author and do not necessarily represent the views or opinions of Digica.
It is the responsibility of the recipient to check this email for the presence 
of viruses. Digica accepts no liability for any damage caused by any virus 
transmitted by this email.

UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK
Reception Tel: + 44 (0) 115 977 1177
Support Centre: 0845 607 7070
Fax: + 44 (0) 115 977 7000
http://www.digica.com

SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South 
Africa
Tel: + 27 (0) 21 957 4900
Fax: + 27 (0) 21 948 3135
http://www.digica.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help

2006-10-04 Thread Matthew Warren
I think eve-online is written in stackless python, they make quite a
dealy about it on their site www.eve-online.com although I cant find the
page myself right now due to filters in the way.


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson
> Sent: 01 October 2006 22:21
> Cc: tutor@python.org
> Subject: Re: [Tutor] Help
> 
> wesley chun wrote:
> >> I am trying to learn a programming language good for 
> programming entire
> >> games (core functions too)
> > 
> > check out the PyGame engine:
> > http://pygame.org
> > 
> > download the games written on top of PyGame that appear to match the
> > functionality you're looking for.  if you learn Python at the same
> > time, tweaking those games and changing their functionality 
> will help
> > you learn it even faster.
> 
> You should also look at the PyGame Challenge web site:
> http://www.pyweek.org/
> 
> I'm not a game writer either but I have a few thoughts...my 
> impression 
> is that Python and PyGame are a good foundation for hobbyist 
> games. The 
> PyGame and PyWeek games are good examples. I doubt that you 
> could write 
> a commercial quality game like Final Fantasy using just these tools 
> though. Commercial games have highly optimized game engines. Some of 
> them use Python as scripting engines for high-level game 
> play; I doubt 
> that any commercial games use Python for their core game engine.
> 
> On the other hand, you are a long way from being able to write Final 
> Fantasy. You need to start small and develop your skills. Python and 
> PyGame should be well suited for this.
> 
> You might want to read this:
> http://tinyurl.com/hc6xc
> 
> which says in part, "Starcraft, Everquest and Quake were all made by 
> teams of professionals who had budgets usually million dollar 
> plus. More 
> importantly though, all of these games were made by people 
> with a lot of 
> experience at making games. They did not just decide to make 
> games and 
> turned out mega-hit games, they started out small and worked 
> their way 
> up. This is the point that anyone who is interested in 
> getting into game 
> development needs to understand and repeat, repeat, repeat until it 
> becomes such a part of your mindset that you couldn't possibly 
> understand life without this self evident, universal truth."
> 
> and here are more links:
> http://en.wikipedia.org/wiki/Game_programming
> http://www-cs-students.stanford.edu/~amitp/gameprog.html
> 
> I found these all by Googling "game programming language"; there are 
> many more interesting links there.
> 
> Good luck,
> Kent
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
>  
> 


This email is confidential and may be privileged. If you are not the intended 
recipient please notify the sender immediately and delete the email from your 
computer. 

You should not copy the email, use it for any purpose or disclose its contents 
to any other person.
Please note that any views or opinions presented in this email may be personal 
to the author and do not necessarily represent the views or opinions of Digica.
It is the responsibility of the recipient to check this email for the presence 
of viruses. Digica accepts no liability for any damage caused by any virus 
transmitted by this email.

UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK
Reception Tel: + 44 (0) 115 977 1177
Support Centre: 0845 607 7070
Fax: + 44 (0) 115 977 7000
http://www.digica.com

SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South 
Africa
Tel: + 27 (0) 21 957 4900
Fax: + 27 (0) 21 948 3135
http://www.digica.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help

2006-10-04 Thread Kent Johnson
Matthew Warren wrote:
> I think eve-online is written in stackless python, they make quite a
> dealy about it on their site www.eve-online.com although I cant find the
> page myself right now due to filters in the way.

Yes, I think you're right that they use stackless. CCP Games was a 
sponsor of the "Need for Speed" Python sprint in Rekjavik last summer 
and Christian Tismer, creator of stackless, was a participant.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [Fwd: guess]

2006-10-04 Thread Kent Johnson
Forwarding to the list

 Original Message 
Subject: guess
Date: Tue, 03 Oct 2006 18:12:08 -0600
From: mike viceano <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]

hey i added another guessing feature that shuld guess the number in the 
most
effective  way
but i keep getting into endless loops thought you might want it
any help with the loops would be great

def number(number):
 ran=input("range  >")
 ran=ran+1
 from random import randrange
 guessed=[]
 guess=randrange(ran)
 print guess
 guessed.append(guess)
 guesses=1
 guessed=[]
 while guess !=number:
 guess=randrange(ran)
 if guess not in guessed:
 guessed.append(guess)
 guesses=guesses+1
 print guess

 print"i got the number",number,"in",guesses,"guesses"



def num(number):
 r=input("range >")
 ran=range(r+1)
 guess=r/2
 print guess
 guesses=1
 while guess!=number:
 if guess < number:
 guess= ((r-guess)/2)+guess
 print guess
 guesses=guesses+1
 elif guess > number:
 guess= ((r-guess)/2)-guess
 print guess
 guesses=guesses+1
 print "i got the number",number,"in",guesses,"guesses"

_
Be seen and heard with Windows Live Messenger and Microsoft LifeCams
http://clk.atdmt.com/MSN/go/msnnkwme002001msn/direct/01/?href=http://www.microsoft.com/hardware/digitalcommunication/default.mspx?locale=en-us&source=hmtagline




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Fwd: guess]

2006-10-04 Thread Andre Engels
2006/10/4, Kent Johnson <[EMAIL PROTECTED]>:

> hey i added another guessing feature that shuld guess the number in the
> most
> effective  way
> but i keep getting into endless loops thought you might want it
> any help with the loops would be great

What's the value of number? Where is it defined? If number is not an
integer or number > ran, then you will indeed end up in an infinite
loop.


--
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help me with two dimensional arrays in Python

2006-10-04 Thread Asrarahmed Kadri
Hi folks,
 
I am stuck.. Please help me with implementing two dimensional array in Python. 
 
Thanks.
 
-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me with two dimensional arrays in Python

2006-10-04 Thread Luke Paireepinart
Asrarahmed Kadri wrote:
>
> Hi folks,
>  
> I am stuck.. Please help me with implementing two dimensional array in 
> Python.
>  
There are no such things as arrays in Python, silly!
I can help you with a two-dimensional list, though :)


Okay, imagine that a list of integers (or any other objects) is a single 
object itself,
that keeps track of the integers (or other objects) for you in whatever 
order you want.
somelist = [1,2,3,4,5]
anotherlist = [6,7,8,9,10]

Now what you want out of a two-dimensional list is
where there are multiple inner lists, with each individual
list being a full row, right?
so...
two_dimensional = [somelist,anotherlist]

Or:
two_dimensional = [ [1,2,3,4,5] , [6,7,8,9,10] ]

This isn't a homework question, right?

Good luck,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me with two dimensional arrays in Python

2006-10-04 Thread Kent Johnson
Asrarahmed Kadri wrote:
> 
> Hi folks,
>  
> I am stuck.. Please help me with implementing two dimensional array in 
> Python.

Nested lists are the simplest way though beware the gotcha shown here:
http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list

You can also use a dict with tuple indices, e.g.
d[1,2] = 3

Numpy is an extension designed for high-performance numerical work, it 
includes a multidimensional array type:
http://numpy.scipy.org//

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Fwd: Re: database web app, what tool?]

2006-10-04 Thread Dave Kuhlman
On Tue, Oct 03, 2006 at 05:05:59PM +1300, Liam Clarke wrote:
> 
> 
>  Original Message 
> Subject:  Re: [Tutor] database web app, what tool?
> Date: Mon, 02 Oct 2006 09:33:28 +0100
> From: [EMAIL PROTECTED]
> To:   Liam Clarke <[EMAIL PROTECTED]>
> References:   <[EMAIL PROTECTED]> 
> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
> 
> 
> 
> Thank you Liam,
> 
> 
> Our web server is IIS, but it would be no problem to use another one for this
> particular purpose.
> 
> I'v been looking for information on how to design tables for the web with
> python, without succes so far. Can you point me any tutorial?
> 

This video is a huge download, but is very well done.  It's also
quite entertaining.  Take a look at "Better Web App Development",
which you can find here:

http://seankelly.tv/videos

It compares Zope/Plone, TurboGears, Django, and others.

Warning: It's done by someone who is very positive about Python,
and is, therefore, quite biased.

And, if you have not already found it, you may want to look at the
following page in the Python Wiki:

http://wiki.python.org/moin/WebFrameworks

Dave


-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me with two dimensional arrays in Python

2006-10-04 Thread Asrarahmed Kadri
 
I am looking for something like this:
 
int arr[5][5]; // C statement; declaring an array of 5 * 5 size
 
Is there an easy and clean way to achieve this in python???
 
Thanks
 
On 10/4/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
Asrarahmed Kadri wrote:>> Hi folks,>> I am stuck.. Please help me with implementing two dimensional array in
> Python.Nested lists are the simplest way though beware the gotcha shown here:http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list
You can also use a dict with tuple indices, e.g.d[1,2] = 3Numpy is an extension designed for high-performance numerical work, itincludes a multidimensional array type:
http://numpy.scipy.org//Kent-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] revisiting struct and bytes again.

2006-10-04 Thread shawn bright
Hey there,this time my question is a bit simpler.i can make a byte a string or number or whatever now. Up to the number 255.I now have a problem with something that comes in as a 4 byte representation of 
the number of seconds since 1970. I have been using ord(byte) to make sense of the messages so far, but i don't know how to add bytes greater than 255.the c program that sends us these defines the variable as an unsigned long int. 
anyone know how to make these four bytes a number of seconds ?thankssk
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me with two dimensional arrays in Python

2006-10-04 Thread Kent Johnson
Asrarahmed Kadri wrote:
>  
> I am looking for something like this:
>  
> int arr[5][5]; // C statement; declaring an array of 5 * 5 size
>  
> Is there an easy and clean way to achieve this in python???

Can you say something about your use case? If I had to guess I would say 
numpy is what you are looking for. Did you look at my suggestions? Are 
you a Python beginner?

Kent

>  
> Thanks
> 
> 
>  
> On 10/4/06, *Kent Johnson* <[EMAIL PROTECTED] > 
> wrote:
> 
> Asrarahmed Kadri wrote:
>  >
>  > Hi folks,
>  >
>  > I am stuck.. Please help me with implementing two dimensional
> array in
>  > Python.
> 
> Nested lists are the simplest way though beware the gotcha shown here:
> 
> http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list
> 
> 
> 
> You can also use a dict with tuple indices, e.g.
> d[1,2] = 3
> 
> Numpy is an extension designed for high-performance numerical work, it
> includes a multidimensional array type:
> http://numpy.scipy.org//
> 
> Kent
> 
> 
> 
> 
> -- 
> To HIM you shall return.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] revisiting struct and bytes again.

2006-10-04 Thread Luke Paireepinart
shawn bright wrote:
> Hey there,
>
> this time my question is a bit simpler.
> i can make a byte a string or number or whatever now. Up to the number 
> 255.
> I now have a problem with something that comes in as a 4 byte 
> representation of
> the number of seconds since 1970.
> I have been using ord(byte) to make sense of the messages so far, but 
> i don't know how to add bytes greater than 255.
>
> the c program that sends us these defines the variable as an unsigned 
> long int.
>
> anyone know how to make these four bytes a number of seconds ?
>
if you used struct it'd be easier, but...
do you know what order the bytes are in?
if they're big-endian just ord each individually and then you'll have a 
4 digit base 256 number
convert this to base 10 so you can see what it is in regular integers
and use the time module to convert.
sorry I can't give more detail, I have to run, i'm late for class.
-Luke
> thanks
>
> sk
>
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] revisiting struct and bytes again.

2006-10-04 Thread Kent Johnson
shawn bright wrote:
> Hey there,
> 
> this time my question is a bit simpler.
> i can make a byte a string or number or whatever now. Up to the number 255.
> I now have a problem with something that comes in as a 4 byte 
> representation of
> the number of seconds since 1970.
> I have been using ord(byte) to make sense of the messages so far, but i 
> don't know how to add bytes greater than 255.
> 
> the c program that sends us these defines the variable as an unsigned 
> long int.
> 
> anyone know how to make these four bytes a number of seconds ?

See the struct module. You may need to know the byte order of the data.

In [1]: from struct import unpack

In [2]: unpack('I', '\x01\x02\x03\x04')
Out[2]: (67305985,)

In [3]: unpack('I', '\x01\x02\x03\x04')
Out[4]: (16909060,)

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me with two dimensional arrays in Python

2006-10-04 Thread Matthew White
Asrarahmed,

How about something like this:

>>> arr = []
>>> arr.append(['Blue', 'Yellow', 'Green', 'Brown', 'White'])
>>> arr[0][0]
'Blue'
>>> arr.append(['Up', 'Down', 'Left', 'Right', 'Center'])
>>> arr[1][4]
'Center'

Is this what you were thinking of?

-mtw


On Wed, Oct 04, 2006 at 06:38:09PM +0100, Asrarahmed Kadri ([EMAIL PROTECTED]) 
wrote:
> I am looking for something like this:
> 
> int arr[5][5]; // C statement; declaring an array of 5 * 5 size
> 
> Is there an easy and clean way to achieve this in python???
> 
> Thanks
> 
> 
> 
> On 10/4/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> >
> >Asrarahmed Kadri wrote:
> >>
> >> Hi folks,
> >>
> >> I am stuck.. Please help me with implementing two dimensional array in
> >> Python.
> >
> >Nested lists are the simplest way though beware the gotcha shown here:
> >
> >http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list
> >
> >You can also use a dict with tuple indices, e.g.
> >d[1,2] = 3
> >
> >Numpy is an extension designed for high-performance numerical work, it
> >includes a multidimensional array type:
> >http://numpy.scipy.org//
> >
> >Kent
> >
> >
> 
> 
> -- 
> To HIM you shall return.

> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] guess]

2006-10-04 Thread Alan Gauld
> def number(number):
> ran=input("range  >")
> ran=ran+1
> from random import randrange
> guessed=[]
> guess=randrange(ran)
> print guess
> guessed.append(guess)
> guesses=1
> guessed=[]  < Why do you reset guessed to an empty list 
> here?

also couldn't the whole chunk above be moved into the loop?
see below

> while guess !=number:
> guess=randrange(ran)
> if guess not in guessed:
> guessed.append(guess)
> guesses=guesses+1
> print guess
>
> print"i got the number",number,"in",guesses,"guesses"

# keep imports outside functions.
from random import randrange

def number(number):
 ran=input("range  >") + 1
 guessed=[]
 guesses = 0   # need to initialise it first
 guess=randrange(ran)
 while guess != number:
 if guess not in guessed:
 guessed.append(guess)
 guesses += 1
 print guess
 guess=randrange(ran)
 print "i got the number",number,"in",guesses,"guesses"

You might also want to add a check to see if ran < number

Also I'm not sure why you don;t count duplicate guesses?
But that's your choice I suppose. However if you counted them
you can remove the list entirely...

Does that help?

-- 
Alan Gauld
Back from vacation... 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Integer division Help requested

2006-10-04 Thread Danny Yoo
>> I feel
>>  7/3  should give -2
>>
>> since  integer  divison returns floor
>
> The floor is the next lowest integer to the float.
> floor(-3.1) will be -4
> floor(3.) will be 3


Hi Joseph,

If it helps, draw out the floor function out on a piece of graph paper.

   ^
   |
  2| x==O
   |
  1|  x==O
   |
<-x==O--->
   |
x==O
   |
 x==O  |
   |
   V

I'm using the "x==O" to try to graphically draw out the half-open 
intervals.

If you believe this diagram, then the results you're seeing from integer 
division should make sense.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me with two dimensional arrays in Python

2006-10-04 Thread Danny Yoo

 I am stuck.. Please help me with implementing two dimensional array 
 in Python.

Hi Asrarahmed,

What do you need a two-dimensional array for?  This is a serious question: 
what's your application?  What are you trying to represent, and why?


As a glib possible answer:  you can use a dictionary to map 2-tuples to 
values.  If you think about it, that's almost what a 2d array does in 
other languages.

##
points = {}
points[(3, 4)] = 1
points[(1, 7)] = 2
##

But this may not be the right approach for your problem.  Tell us more of 
what you are trying to do.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor