[Tutor] data question

2010-10-02 Thread Roelof Wobben


Hello, 
 
As a test I would write a programm where a user can input game-data like 
home-team, away-team, home-score, away-score) and makes a ranking of it. And 
I'm not looking of a OOP solution because im not comfertle with OOP.
 
Now my question is :
 
In which datatype can I put this data in.
 
I thought myself of a dictonary of tuples.
 
Regards,
 
Roelof
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Connecting my users

2010-10-02 Thread Timo

On 01-10-10 11:25, Nitin Pawar wrote:

have a look at this

http://bytes.com/topic/python/answers/826973-peer-peer-chat-program


Thanks, but that still uses a server. And even one that I can't control! 
If it has to be with server interaction, than as little as possible is 
preferred and option to put it on my own.


Cheers,
Timo



On Fri, Oct 1, 2010 at 2:49 PM, Timo > wrote:


Hello,

I have the following idea, but no clue how to implement this.
I want my users to be able to connect to other users (with the
same program) and chat with them and exchange files. Ideally
without server interaction. Now I heard about peer-to-peer and
bittorrent protocol etc. But don't know where to start or that I'm
even at the right path.
So if anyone can point me into the right direction of a framework
or protocol I should use for this, it would be appreciated.

Cheers,
Timo

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




--
Nitin Pawar



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


Re: [Tutor] data question

2010-10-02 Thread Alan Gauld


"Roelof Wobben"  wrote


As a test I would write a programm where a user can input game-data
like home-team, away-team, home-score, away-score) and makes a
ranking of it.



In which datatype can I put this data in.

I thought myself of a dictonary of tuples.


A dictionary would be good for the basic data but I assume there
are more than one of these data items? If so what do they represent?
How would they be used?

We need a bit more information, even some sample datya might help.

It could be a list of dictionaries or even a dictionary of 
dictionaries.


Alan G.


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


Re: [Tutor] data question

2010-10-02 Thread Roelof Wobben




> From: rwob...@hotmail.com
> To: berma...@cfl.rr.com
> Subject: RE: [Tutor] data question
> Date: Sat, 2 Oct 2010 13:09:23 +
>
>
>
>
> 
>> From: berma...@cfl.rr.com
>> To: rwob...@hotmail.com; tutor@python.org
>> Subject: RE: [Tutor] data question
>> Date: Sat, 2 Oct 2010 09:02:41 -0400
>>
>>
>>
>>> -Original Message-
>>> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
>>> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Roelof Wobben
>>> Sent: Saturday, October 02, 2010 4:35 AM
>>> To: tutor@python.org
>>> Subject: [Tutor] data question
>>>
>>>
>>>
>>> Hello,
>>
>>> Now my question is :
>>>
>>> In which datatype can I put this data in.
>>>
>> Perhaps a simple SQLlite database?
>> http://zetcode.com/databases/sqlitetutorial/
>>
>> Hope this helps,
>>
>> Robert
>>
>>
>>
>>> Regards,
>>>
>>> Roelof
>>>
>>> ___
>>> Tutor maillist - Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>

Oke,

Oke, there I can save the input data.
But I have also need a data model for team, played_games, game_points, 
made_points and againts_points.
So I think it cannot be done without using a class for games and one for 
ranking.
And figuring out how I can store the game-data in a text or database file.

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


Re: [Tutor] data question

2010-10-02 Thread Roelof Wobben




> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Sat, 2 Oct 2010 14:10:25 +0100
> Subject: Re: [Tutor] data question
>
>
> "Roelof Wobben" wrote
>
>> As a test I would write a programm where a user can input game-data
>> like home-team, away-team, home-score, away-score) and makes a
>> ranking of it.
>
>> In which datatype can I put this data in.
>>
>> I thought myself of a dictonary of tuples.
>
> A dictionary would be good for the basic data but I assume there
> are more than one of these data items? If so what do they represent?
> How would they be used?
>
> We need a bit more information, even some sample datya might help.
>
> It could be a list of dictionaries or even a dictionary of
> dictionaries.
>
> Alan G.
>
>
> ___
> Tutor maillist - Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Hello Alan, 

What I meant was this:
 
Let's say we have a tournament of 4 teams A,B,C,D
 
They played this games.
 
A - B  20 - 30 
C - D  23 - 67 
 
These data must be stored so I can make a module which make a ranking like this 
:
 
1) C   1 - 2  76 - 23 
2) B   1 - 2   30 - 20
 
I hope you know what I wan
 
 
Roelof
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] data question

2010-10-02 Thread Roelof Wobben

hello, 
 
Still one question.
 
Every game is a dictonary/tuple ?
 
Regards,
 
Roelof


> Date: Sat, 2 Oct 2010 06:24:16 -0700
> From: alan.ga...@btinternet.com
> Subject: Re: [Tutor] data question
> To: rwob...@hotmail.com
>
> OK, So you want a list of games (possibly one per tournament
> if you need to compare across tournies) where for each game
> you store: homeTeam, awayTeam and scores.
>
> Each game could be represented as either a tuple or a dictionary
> depending on how you want to extract the data:
>
> game['home'] or game[0]
>
> The list should probably be a list... :-)
>
> Try defining a short sample database in Python then try
> extracting some values to get a feel for what suits you
> best. Create the data in a module(easier to edit mistakes/changes)
> Then use the>>> prompt to import the data module and play
> around with it.
>
> That way it's easy to change from lists to tuples to dictionaries
> and see what works.
>
> Ultimately this may even be best done using a database but
> that's probably a step too far for you just now.
>
> Alan Gauld
> Author of the Learn To Program website
> http://www.alan-g.me.uk/
>
>
>
>
> - Original Message 
>> From: Roelof Wobben 
>> To: alan.ga...@btinternet.com; tutor@python.org
>> Sent: Saturday, 2 October, 2010 14:15:33
>> Subject: RE: [Tutor] data question
>>
>>
>>
>>
>> 
>>> To: tutor@python.org
>>> From: alan.ga...@btinternet.com
>>> Date: Sat, 2 Oct 2010 14:10:25 +0100
>>> Subject: Re: [Tutor] data question
>>>
>>>
>>> "Roelof Wobben" wrote
>>>
 As a test I would write a programm where a user can input game-data
 like home-team, away-team, home-score, away-score) and makes a
 ranking of it.
>>>
 In which datatype can I put this data in.

 I thought myself of a dictonary of tuples.
>>>
>>> A dictionary would be good for the basic data but I assume there
>>> are more than one of these data items? If so what do they represent?
>>> How would they be used?
>>>
>>> We need a bit more information, even some sample datya might help.
>>>
>>> It could be a list of dictionaries or even a dictionary of
>>> dictionaries.
>>>
>>> Alan G.
>>>
>>>
>>> ___
>>> Tutor maillist - Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>
>> Hello Alan,
>>
>> What I meant was this:
>>
>> Let's say we have a tournament of 4 teams A,B,C,D
>>
>> They played this games.
>>
>> A - B 20 - 30
>> C - D 23 - 67
>>
>> These data must be stored so I can make a module which make a ranking like
>>this :
>>
>> 1) C 1 - 2 76 - 23
>> 2) B 1 - 2 30 - 20
>>
>> I hope you know what I wan
>>
>>
>> Roelof
>>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] data question

2010-10-02 Thread Robert Berman


> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Roelof Wobben
> Sent: Saturday, October 02, 2010 4:35 AM
> To: tutor@python.org
> Subject: [Tutor] data question
> 
> 
> 
> Hello,
 
> Now my question is :
> 
> In which datatype can I put this data in.
> 
Perhaps a simple SQLlite database? 
http://zetcode.com/databases/sqlitetutorial/

Hope this helps,

Robert


 
> Regards,
> 
> Roelof
> 
> ___
> 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] Coin Toss Problems

2010-10-02 Thread bob gailer

 On 10/1/2010 6:52 AM, delegb...@dudupay.com wrote:

This is also a learner's advice, so just give it a shot.
In the first function, set HEADS to 0 and TAILS to 0.
Then if flip==0, heads=heads+1
Return Heads.
Do same for Tails and see if it makes any sense.
Regards.


Isn't Python case sensitive?


--
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] list comprehension, efficiency?

2010-10-02 Thread bob gailer

 [snip]

I ran dis on a for loop and the equivalent comprehension.

I was surprised to see almost identical code.

I had assumed (and now wish for) that a comprehension would be a 
primitive written in C and thus much faster!


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


[Tutor] Using contents of a document to change file names

2010-10-02 Thread Josep M. Fontana
Hi,

This is my first posting to this list. Perhaps this has a very easy answer
but before deciding to post this message I consulted a bunch of Python
manuals and on-line reference documents to no avail. I would be very
grateful if someone could lend me a hand with this.

Here's the problem I want to solve. I have a lot of files with the following
name structure:

A-01-namex.txt
A-02-namey.txt
...
N-09-namez.txt

These are different text documents that I want to process for an NLP project
I'm starting. Each one of the texts belongs to a different century and it is
important to be able to include the information about the century in the
name of the file as well as inside the text.

Then I have another text file containing information about the century each
one of the texts was written. This document has the following structure:

A-01, 1278
A-02, 1501
...
N-09, 1384

What I would like to do is to write a little script that would do the
following:

. Read each row of the text containing information about the centuries each
one of the texts was written
. Change the name of the file whose name starts with the code in the first
column in the following way

A-01-namex.txt --> A-01-namex_13-2.txt

Where 13-1 means: 13th 2nd half. Obviously this information would com
from the second column in the text: 1278 (the first two digits + 1 =
century; if the 3rd and 4th digits > 50, then 2; if < 50 then 1)

Then in the same script or in a new one, I would need to open each one of
the texts and add information about the century they were written on the
first line preceded by some symbol (e.g @13-2)

I've found a lot of information about changing file names (so I know that I
should be importing the os module), but none of the examples that were cited
involved getting the information for the file changing operation from the
contents of a document.

As you can imagine, I'm pretty green in Python programming and I was hoping
the learn by doing method would work.  I need to get on with this project,
though, and I'm kind of stuck. Any help you guys can give me will be very
helpful.

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


Re: [Tutor] Tutor Digest, Vol 80, Issue 11

2010-10-02 Thread Edward Lang


tutor-requ...@python.org wrote:

>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Re: Connecting my users (Timo)
>   2. Re: data question (Alan Gauld)
>   3. Re: data question (Roelof Wobben)
>   4. Re: data question (Roelof Wobben)
>   5. Re: data question (Roelof Wobben)
>   6. Re: data question (Robert Berman)
>   7. Re: Coin Toss Problems (bob gailer)
>
>
>--
>
>Message: 1
>Date: Sat, 02 Oct 2010 12:06:14 +0200
>From: Timo 
>To: Nitin Pawar 
>Cc: tutor@python.org
>Subject: Re: [Tutor] Connecting my users
>Message-ID: <4ca70416.2050...@gmail.com>
>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>On 01-10-10 11:25, Nitin Pawar wrote:
>> have a look at this
>>
>> http://bytes.com/topic/python/answers/826973-peer-peer-chat-program
>
>Thanks, but that still uses a server. And even one that I can't control! 
>If it has to be with server interaction, than as little as possible is 
>preferred and option to put it on my own.
>
>Cheers,
>Timo
>
>>
>> On Fri, Oct 1, 2010 at 2:49 PM, Timo > > wrote:
>>
>> Hello,
>>
>> I have the following idea, but no clue how to implement this.
>> I want my users to be able to connect to other users (with the
>> same program) and chat with them and exchange files. Ideally
>> without server interaction. Now I heard about peer-to-peer and
>> bittorrent protocol etc. But don't know where to start or that I'm
>> even at the right path.
>> So if anyone can point me into the right direction of a framework
>> or protocol I should use for this, it would be appreciated.
>>
>> Cheers,
>> Timo
>>
>> ___
>> Tutor maillist  - Tutor@python.org 
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
>>
>> -- 
>> Nitin Pawar
>>
>
>
>
>--
>
>Message: 2
>Date: Sat, 2 Oct 2010 14:10:25 +0100
>From: "Alan Gauld" 
>To: tutor@python.org
>Subject: Re: [Tutor] data question
>Message-ID: 
>Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>   reply-type=original
>
>
>"Roelof Wobben"  wrote
>
>> As a test I would write a programm where a user can input game-data
>> like home-team, away-team, home-score, away-score) and makes a
>> ranking of it.
>
>> In which datatype can I put this data in.
>>
>> I thought myself of a dictonary of tuples.
>
>A dictionary would be good for the basic data but I assume there
>are more than one of these data items? If so what do they represent?
>How would they be used?
>
>We need a bit more information, even some sample datya might help.
>
>It could be a list of dictionaries or even a dictionary of 
>dictionaries.
>
>Alan G.
>
>
>
>
>--
>
>Message: 3
>Date: Sat, 2 Oct 2010 13:10:03 +
>From: Roelof Wobben 
>To: 
>Subject: Re: [Tutor] data question
>Message-ID: 
>Content-Type: text/plain; charset="iso-8859-1"
>
>
>
>
>
>> From: rwob...@hotmail.com
>> To: berma...@cfl.rr.com
>> Subject: RE: [Tutor] data question
>> Date: Sat, 2 Oct 2010 13:09:23 +
>>
>>
>>
>>
>> 
>>> From: berma...@cfl.rr.com
>>> To: rwob...@hotmail.com; tutor@python.org
>>> Subject: RE: [Tutor] data question
>>> Date: Sat, 2 Oct 2010 09:02:41 -0400
>>>
>>>
>>>
 -Original Message-
 From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
 bounces+bermanrl=cfl.rr@python.org] On Behalf Of Roelof Wobben
 Sent: Saturday, October 02, 2010 4:35 AM
 To: tutor@python.org
 Subject: [Tutor] data question



 Hello,
>>>
 Now my question is :

 In which datatype can I put this data in.

>>> Perhaps a simple SQLlite database?
>>> http://zetcode.com/databases/sqlitetutorial/
>>>
>>> Hope this helps,
>>>
>>> Robert
>>>
>>>
>>>
 Regards,

 Roelof

 ___
 Tutor maillist - Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
>>>
>
>Oke,
>
>Oke, there I can save the input data.
>But I have also need a data model for team, played_games, game_points, 
>made_points and againts_points.
>So I think it cannot be done without using a class for games and one for 
>ranking.
>And figuring out how I can store the game-data in a text or database file

Re: [Tutor] Tutor Digest, Vol 80, Issue 11

2010-10-02 Thread Edward Lang


tutor-requ...@python.org wrote:

>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Re: Connecting my users (Timo)
>   2. Re: data question (Alan Gauld)
>   3. Re: data question (Roelof Wobben)
>   4. Re: data question (Roelof Wobben)
>   5. Re: data question (Roelof Wobben)
>   6. Re: data question (Robert Berman)
>   7. Re: Coin Toss Problems (bob gailer)
>
>
>--
>
>Message: 1
>Date: Sat, 02 Oct 2010 12:06:14 +0200
>From: Timo 
>To: Nitin Pawar 
>Cc: tutor@python.org
>Subject: Re: [Tutor] Connecting my users
>Message-ID: <4ca70416.2050...@gmail.com>
>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>On 01-10-10 11:25, Nitin Pawar wrote:
>> have a look at this
>>
>> http://bytes.com/topic/python/answers/826973-peer-peer-chat-program
>
>Thanks, but that still uses a server. And even one that I can't control! 
>If it has to be with server interaction, than as little as possible is 
>preferred and option to put it on my own.
>
>Cheers,
>Timo
>
>>
>> On Fri, Oct 1, 2010 at 2:49 PM, Timo > > wrote:
>>
>> Hello,
>>
>> I have the following idea, but no clue how to implement this.
>> I want my users to be able to connect to other users (with the
>> same program) and chat with them and exchange files. Ideally
>> without server interaction. Now I heard about peer-to-peer and
>> bittorrent protocol etc. But don't know where to start or that I'm
>> even at the right path.
>> So if anyone can point me into the right direction of a framework
>> or protocol I should use for this, it would be appreciated.
>>
>> Cheers,
>> Timo
>>
>> ___
>> Tutor maillist  - Tutor@python.org 
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
>>
>> -- 
>> Nitin Pawar
>>
>
>
>
>--
>
>Message: 2
>Date: Sat, 2 Oct 2010 14:10:25 +0100
>From: "Alan Gauld" 
>To: tutor@python.org
>Subject: Re: [Tutor] data question
>Message-ID: 
>Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>   reply-type=original
>
>
>"Roelof Wobben"  wrote
>
>> As a test I would write a programm where a user can input game-data
>> like home-team, away-team, home-score, away-score) and makes a
>> ranking of it.
>
>> In which datatype can I put this data in.
>>
>> I thought myself of a dictonary of tuples.
>
>A dictionary would be good for the basic data but I assume there
>are more than one of these data items? If so what do they represent?
>How would they be used?
>
>We need a bit more information, even some sample datya might help.
>
>It could be a list of dictionaries or even a dictionary of 
>dictionaries.
>
>Alan G.
>
>
>
>
>--
>
>Message: 3
>Date: Sat, 2 Oct 2010 13:10:03 +
>From: Roelof Wobben 
>To: 
>Subject: Re: [Tutor] data question
>Message-ID: 
>Content-Type: text/plain; charset="iso-8859-1"
>
>
>
>
>
>> From: rwob...@hotmail.com
>> To: berma...@cfl.rr.com
>> Subject: RE: [Tutor] data question
>> Date: Sat, 2 Oct 2010 13:09:23 +
>>
>>
>>
>>
>> 
>>> From: berma...@cfl.rr.com
>>> To: rwob...@hotmail.com; tutor@python.org
>>> Subject: RE: [Tutor] data question
>>> Date: Sat, 2 Oct 2010 09:02:41 -0400
>>>
>>>
>>>
 -Original Message-
 From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
 bounces+bermanrl=cfl.rr@python.org] On Behalf Of Roelof Wobben
 Sent: Saturday, October 02, 2010 4:35 AM
 To: tutor@python.org
 Subject: [Tutor] data question



 Hello,
>>>
 Now my question is :

 In which datatype can I put this data in.

>>> Perhaps a simple SQLlite database?
>>> http://zetcode.com/databases/sqlitetutorial/
>>>
>>> Hope this helps,
>>>
>>> Robert
>>>
>>>
>>>
 Regards,

 Roelof

 ___
 Tutor maillist - Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
>>>
>
>Oke,
>
>Oke, there I can save the input data.
>But I have also need a data model for team, played_games, game_points, 
>made_points and againts_points.
>So I think it cannot be done without using a class for games and one for 
>ranking.
>And figuring out how I can store the game-data in a text or database file

Re: [Tutor] Tutor Digest, Vol 80, Issue 11

2010-10-02 Thread Edward Lang


tutor-requ...@python.org wrote:

>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Re: Connecting my users (Timo)
>   2. Re: data question (Alan Gauld)
>   3. Re: data question (Roelof Wobben)
>   4. Re: data question (Roelof Wobben)
>   5. Re: data question (Roelof Wobben)
>   6. Re: data question (Robert Berman)
>   7. Re: Coin Toss Problems (bob gailer)
>
>
>--
>
>Message: 1
>Date: Sat, 02 Oct 2010 12:06:14 +0200
>From: Timo 
>To: Nitin Pawar 
>Cc: tutor@python.org
>Subject: Re: [Tutor] Connecting my users
>Message-ID: <4ca70416.2050...@gmail.com>
>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>On 01-10-10 11:25, Nitin Pawar wrote:
>> have a look at this
>>
>> http://bytes.com/topic/python/answers/826973-peer-peer-chat-program
>
>Thanks, but that still uses a server. And even one that I can't control! 
>If it has to be with server interaction, than as little as possible is 
>preferred and option to put it on my own.
>
>Cheers,
>Timo
>
>>
>> On Fri, Oct 1, 2010 at 2:49 PM, Timo > > wrote:
>>
>> Hello,
>>
>> I have the following idea, but no clue how to implement this.
>> I want my users to be able to connect to other users (with the
>> same program) and chat with them and exchange files. Ideally
>> without server interaction. Now I heard about peer-to-peer and
>> bittorrent protocol etc. But don't know where to start or that I'm
>> even at the right path.
>> So if anyone can point me into the right direction of a framework
>> or protocol I should use for this, it would be appreciated.
>>
>> Cheers,
>> Timo
>>
>> ___
>> Tutor maillist  - Tutor@python.org 
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
>>
>> -- 
>> Nitin Pawar
>>
>
>
>
>--
>
>Message: 2
>Date: Sat, 2 Oct 2010 14:10:25 +0100
>From: "Alan Gauld" 
>To: tutor@python.org
>Subject: Re: [Tutor] data question
>Message-ID: 
>Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>   reply-type=original
>
>
>"Roelof Wobben"  wrote
>
>> As a test I would write a programm where a user can input game-data
>> like home-team, away-team, home-score, away-score) and makes a
>> ranking of it.
>
>> In which datatype can I put this data in.
>>
>> I thought myself of a dictonary of tuples.
>
>A dictionary would be good for the basic data but I assume there
>are more than one of these data items? If so what do they represent?
>How would they be used?
>
>We need a bit more information, even some sample datya might help.
>
>It could be a list of dictionaries or even a dictionary of 
>dictionaries.
>
>Alan G.
>
>
>
>
>--
>
>Message: 3
>Date: Sat, 2 Oct 2010 13:10:03 +
>From: Roelof Wobben 
>To: 
>Subject: Re: [Tutor] data question
>Message-ID: 
>Content-Type: text/plain; charset="iso-8859-1"
>
>
>
>
>
>> From: rwob...@hotmail.com
>> To: berma...@cfl.rr.com
>> Subject: RE: [Tutor] data question
>> Date: Sat, 2 Oct 2010 13:09:23 +
>>
>>
>>
>>
>> 
>>> From: berma...@cfl.rr.com
>>> To: rwob...@hotmail.com; tutor@python.org
>>> Subject: RE: [Tutor] data question
>>> Date: Sat, 2 Oct 2010 09:02:41 -0400
>>>
>>>
>>>
 -Original Message-
 From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
 bounces+bermanrl=cfl.rr@python.org] On Behalf Of Roelof Wobben
 Sent: Saturday, October 02, 2010 4:35 AM
 To: tutor@python.org
 Subject: [Tutor] data question



 Hello,
>>>
 Now my question is :

 In which datatype can I put this data in.

>>> Perhaps a simple SQLlite database?
>>> http://zetcode.com/databases/sqlitetutorial/
>>>
>>> Hope this helps,
>>>
>>> Robert
>>>
>>>
>>>
 Regards,

 Roelof

 ___
 Tutor maillist - Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
>>>
>
>Oke,
>
>Oke, there I can save the input data.
>But I have also need a data model for team, played_games, game_points, 
>made_points and againts_points.
>So I think it cannot be done without using a class for games and one for 
>ranking.
>And figuring out how I can store the game-data in a text or database file

Re: [Tutor] function error

2010-10-02 Thread roberto
On Thu, Sep 30, 2010 at 1:45 PM, ALAN GAULD  wrote:
> Copy the code into a text file with a name ending in .py - lets call it
> myfile.py for now
> (if you have not already done so)
>
> From a bash prompt type
>
> $ python myfile.py
>
> Then cut n paste any error messages into an email to the list

well, actually i corrected the code so that the function outOfBounds()
is directly called (as you can see hereafter);
but if you have time to run the code you'll see the same strange
behavior as me (maybe):
when the arrow hits anyone of the window borders, it gets stuck back
and forth indefinitely and never starts the path again

thank you in advance
##
import turtle, random

def checkForward(distance):
old_position = turtle.position()
turtle._pen.up()
# no show/hide turtle methods in my turtle module !
turtle.forward(distance)
forward_failed = outOfBounds()
turtle.setx(old_position[0]); turtle.sety(old_position[1])
turtle._pen.down()
# no show/hide turtle methods in my turtle module !
if outOfBounds() == 'false':
turtle.forward(distance)

def stuck():
return forward_failed

def outOfBounds():
if (abs(turtle.position()[0]) > turtle.window_height()/2) or
(abs(turtle.position()[1]) > turtle.window_width()/2):
return "true"
else:
return "false"

def randomMove2(d1, d2, a1, a2):
 while 1:
 turtle.left(random.uniform(a1,a2))
 checkForward(random.uniform(d1,d2))
 if outOfBounds() == 'true':
 turtle.right(180)
#

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


Re: [Tutor] data question

2010-10-02 Thread Roelof Wobben


Hello Alan, 
 
I think this is what can work : http://www.daniweb.com/code/snippet216750.html
 
I will try it.
 
 
Roelof


> From: rwob...@hotmail.com
> To: alan.ga...@btinternet.com; tutor@python.org
> Subject: RE: [Tutor] data question
> Date: Sat, 2 Oct 2010 13:40:21 +
>
>
> hello,
>
> Still one question.
>
> Every game is a dictonary/tuple ?
>
> Regards,
>
> Roelof
>
> 
>> Date: Sat, 2 Oct 2010 06:24:16 -0700
>> From: alan.ga...@btinternet.com
>> Subject: Re: [Tutor] data question
>> To: rwob...@hotmail.com
>>
>> OK, So you want a list of games (possibly one per tournament
>> if you need to compare across tournies) where for each game
>> you store: homeTeam, awayTeam and scores.
>>
>> Each game could be represented as either a tuple or a dictionary
>> depending on how you want to extract the data:
>>
>> game['home'] or game[0]
>>
>> The list should probably be a list... :-)
>>
>> Try defining a short sample database in Python then try
>> extracting some values to get a feel for what suits you
>> best. Create the data in a module(easier to edit mistakes/changes)
>> Then use the>>> prompt to import the data module and play
>> around with it.
>>
>> That way it's easy to change from lists to tuples to dictionaries
>> and see what works.
>>
>> Ultimately this may even be best done using a database but
>> that's probably a step too far for you just now.
>>
>> Alan Gauld
>> Author of the Learn To Program website
>> http://www.alan-g.me.uk/
>>
>>
>>
>>
>> - Original Message 
>>> From: Roelof Wobben
>>> To: alan.ga...@btinternet.com; tutor@python.org
>>> Sent: Saturday, 2 October, 2010 14:15:33
>>> Subject: RE: [Tutor] data question
>>>
>>>
>>>
>>>
>>> 
 To: tutor@python.org
 From: alan.ga...@btinternet.com
 Date: Sat, 2 Oct 2010 14:10:25 +0100
 Subject: Re: [Tutor] data question


 "Roelof Wobben" wrote

> As a test I would write a programm where a user can input game-data
> like home-team, away-team, home-score, away-score) and makes a
> ranking of it.

> In which datatype can I put this data in.
>
> I thought myself of a dictonary of tuples.

 A dictionary would be good for the basic data but I assume there
 are more than one of these data items? If so what do they represent?
 How would they be used?

 We need a bit more information, even some sample datya might help.

 It could be a list of dictionaries or even a dictionary of
 dictionaries.

 Alan G.


 ___
 Tutor maillist - Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
>>>
>>> Hello Alan,
>>>
>>> What I meant was this:
>>>
>>> Let's say we have a tournament of 4 teams A,B,C,D
>>>
>>> They played this games.
>>>
>>> A - B 20 - 30
>>> C - D 23 - 67
>>>
>>> These data must be stored so I can make a module which make a ranking like
>>>this :
>>>
>>> 1) C 1 - 2 76 - 23
>>> 2) B 1 - 2 30 - 20
>>>
>>> I hope you know what I wan
>>>
>>>
>>> Roelof
>>>   
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using contents of a document to change file names

2010-10-02 Thread Greg
On Sat, Oct 2, 2010 at 11:56 AM, Josep M. Fontana  wrote:

> Then I have another text file containing information about the century each
> one of the texts was written. This document has the following structure:
>
> A-01, 1278
> A-02, 1501
> ...
> N-09, 1384
>
>
To process this, I'd check out the CSV (Comma Separated Values) module.

What I would like to do is to write a little script that would do the
> following:
>
> . Read each row of the text containing information about the centuries each
> one of the texts was written
> . Change the name of the file whose name starts with the code in the first
> column in the following way
>
> A-01-namex.txt --> A-01-namex_13-2.txt
>
> Where 13-1 means: 13th 2nd half. Obviously this information would com
> from the second column in the text: 1278 (the first two digits + 1 =
> century; if the 3rd and 4th digits > 50, then 2; if < 50 then 1)
>
> Then in the same script or in a new one, I would need to open each one of
> the texts and add information about the century they were written on the
> first line preceded by some symbol (e.g @13-2)
>
> I've found a lot of information about changing file names (so I know that I
> should be importing the os module), but none of the examples that were cited
> involved getting the information for the file changing operation from the
> contents of a document.


If it were me, I'd build a string using the information you want, then add
".txt" or whatever to the end of it, then use the os module to change the
filenames.

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


Re: [Tutor] function error

2010-10-02 Thread Joel Goldstick
On Sat, Oct 2, 2010 at 12:43 PM, roberto  wrote:
> On Thu, Sep 30, 2010 at 1:45 PM, ALAN GAULD  wrote:
>> Copy the code into a text file with a name ending in .py - lets call it
>> myfile.py for now
>> (if you have not already done so)
>>
>> From a bash prompt type
>>
>> $ python myfile.py
>>
>> Then cut n paste any error messages into an email to the list
>
> well, actually i corrected the code so that the function outOfBounds()
> is directly called (as you can see hereafter);
> but if you have time to run the code you'll see the same strange
> behavior as me (maybe):
> when the arrow hits anyone of the window borders, it gets stuck back
> and forth indefinitely and never starts the path again
>
> thank you in advance
> ##
> import turtle, random
>
> def checkForward(distance):
>        old_position = turtle.position()
>        turtle._pen.up()
>        # no show/hide turtle methods in my turtle module !
>        turtle.forward(distance)
>        forward_failed = outOfBounds()
>        turtle.setx(old_position[0]); turtle.sety(old_position[1])
>        turtle._pen.down()
>        # no show/hide turtle methods in my turtle module !
>        if outOfBounds() == 'false':
>                turtle.forward(distance)
>
> def stuck():
>        return forward_failed
>
> def outOfBounds():
>        if (abs(turtle.position()[0]) > turtle.window_height()/2) or
> (abs(turtle.position()[1]) > turtle.window_width()/2):
>                return "true"
>        else:
>                return "false"
>
> def randomMove2(d1, d2, a1, a2):
>         while 1:
>                 turtle.left(random.uniform(a1,a2))
>                 checkForward(random.uniform(d1,d2))
>                 if outOfBounds() == 'true':
>                         turtle.right(180)
> #

I copied your code between the hash lines and get this:

  File "my_turtle.py", line 19
if (abs(turtle.position()[0]) > turtle.window_height()/2) or
   ^
SyntaxError: invalid syntax


Is that all of your code?  it seems to be cut off


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


Re: [Tutor] Using contents of a document to change file names

2010-10-02 Thread Emile van Sebille

On 10/2/2010 8:56 AM Josep M. Fontana said...

Hi,

This is my first posting to this list. Perhaps this has a very easy answer
but before deciding to post this message I consulted a bunch of Python
manuals and on-line reference documents to no avail. I would be very
grateful if someone could lend me a hand with this.



Hi Josep,

Break the problem into pieces.

Conceptually, you'll need to:

  -a- get the list of file names to change then for each
  -b- determine the new name
  -c- rename the file

For -a- you'll need glob. For -c- use os.rename.  -b- is a bit more 
involved.  To break -b- down:


  -b1- break out the x-xx portion of the file name
  -b2- look up the corresponding year in the other file
  -b3- convert the year to the century-half structure
  -b4- put the pieces together to form the new file name

For -b2- I'd suggest building a dictionary from your second files 
contents as a first step to facilitate the subsequent lookups.


You haven't included any code and we can't gauge how far along you are, 
so follow up and post the code you write as you go and we'll be better 
able to help out.


Hope this is enough to get you started,

Emile






Here's the problem I want to solve. I have a lot of files with the following
name structure:

A-01-namex.txt
A-02-namey.txt
...
N-09-namez.txt

These are different text documents that I want to process for an NLP project
I'm starting. Each one of the texts belongs to a different century and it is
important to be able to include the information about the century in the
name of the file as well as inside the text.

Then I have another text file containing information about the century each
one of the texts was written. This document has the following structure:

A-01, 1278
A-02, 1501
...
N-09, 1384

What I would like to do is to write a little script that would do the
following:

. Read each row of the text containing information about the centuries each
one of the texts was written
. Change the name of the file whose name starts with the code in the first
column in the following way

 A-01-namex.txt -->  A-01-namex_13-2.txt

 Where 13-1 means: 13th 2nd half. Obviously this information would com
from the second column in the text: 1278 (the first two digits + 1 =
century; if the 3rd and 4th digits>  50, then 2; if<  50 then 1)

Then in the same script or in a new one, I would need to open each one of
the texts and add information about the century they were written on the
first line preceded by some symbol (e.g @13-2)

I've found a lot of information about changing file names (so I know that I
should be importing the os module), but none of the examples that were cited
involved getting the information for the file changing operation from the
contents of a document.

As you can imagine, I'm pretty green in Python programming and I was hoping
the learn by doing method would work.  I need to get on with this project,
though, and I'm kind of stuck. Any help you guys can give me will be very
helpful.

Josep M.




___
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] function error

2010-10-02 Thread Emile van Sebille

On 10/2/2010 10:16 AM Joel Goldstick said...

##
import turtle, random

def checkForward(distance):
old_position = turtle.position()
turtle._pen.up()
# no show/hide turtle methods in my turtle module !
turtle.forward(distance)
forward_failed = outOfBounds()
turtle.setx(old_position[0]); turtle.sety(old_position[1])
turtle._pen.down()
# no show/hide turtle methods in my turtle module !
if outOfBounds() == 'false':
turtle.forward(distance)

def stuck():
return forward_failed

def outOfBounds():
if (abs(turtle.position()[0])>  turtle.window_height()/2) or
(abs(turtle.position()[1])>  turtle.window_width()/2):
return "true"
else:
return "false"

def randomMove2(d1, d2, a1, a2):
 while 1:
 turtle.left(random.uniform(a1,a2))
 checkForward(random.uniform(d1,d2))
 if outOfBounds() == 'true':
 turtle.right(180)
#


I copied your code between the hash lines and get this:

   File "my_turtle.py", line 19
 if (abs(turtle.position()[0])>  turtle.window_height()/2) or
^
SyntaxError: invalid syntax


Is that all of your code?  it seems to be cut off



Do you see it now?  Your reply contained the 10 ten lines or so of code 
that follows.


Emile

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


Re: [Tutor] function error

2010-10-02 Thread Steve Willoughby

On 02-Oct-10 10:32, Emile van Sebille wrote:

File "my_turtle.py", line 19
if (abs(turtle.position()[0])> turtle.window_height()/2) or
^
SyntaxError: invalid syntax


How does Python know that the next line is the continuation of your if 
statement, instead of the beginning of a new line of code?  You didn't 
do anything to indicate continuation, so it takes this as an incomplete 
statement. "If ... stuff ... or... (or what??)"


You need to END that line with a backslash

if (abs(...height()/2) or \
  ...continuation...:

or else make the line break INSIDE a set of parentheses, for Python to 
keep looking to the next line(s) to complete the statement.

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


Re: [Tutor] function error

2010-10-02 Thread Emile van Sebille

On 10/2/2010 10:45 AM Steve Willoughby said...

On 02-Oct-10 10:32, Emile van Sebille wrote:


Well, not really -- this is the OPs code.  I was responding to Joel's 
comment of not seeing the entire post.



File "my_turtle.py", line 19
if (abs(turtle.position()[0]) > turtle.window_height()/2) or
^
SyntaxError: invalid syntax


How does Python know that the next line is the continuation of your if
statement, instead of the beginning of a new line of code?


Because of the paren count -- I didn't actually parse the OPs code and 
so I assumed that, but now I'll assume the line break probably resulted 
post send.


Continuing-to-assume-ly y'rs,

Emile


Here's the code fragment now paren'd...

import turtle, random

def checkForward(distance):
old_position = turtle.position()
turtle._pen.up()
# no show/hide turtle methods in my turtle module !
turtle.forward(distance)
forward_failed = outOfBounds()
turtle.setx(old_position[0]); turtle.sety(old_position[1])
turtle._pen.down()
# no show/hide turtle methods in my turtle module !
if outOfBounds() == 'false':
turtle.forward(distance)

def stuck():
return forward_failed

def outOfBounds():
if ((abs(turtle.position()[0])>turtle.window_height()/2) or
(abs(turtle.position()[1])>  turtle.window_width()/2)):
return "true"
else:
return "false"

def randomMove2(d1, d2, a1, a2):
 while 1:
 turtle.left(random.uniform(a1,a2))
 checkForward(random.uniform(d1,d2))
 if outOfBounds() == 'true':
 turtle.right(180)



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


Re: [Tutor] function error

2010-10-02 Thread roberto
On Sat, Oct 2, 2010 at 7:45 PM, Steve Willoughby  wrote:
> On 02-Oct-10 10:32, Emile van Sebille wrote:
>>>
>>> File "my_turtle.py", line 19
>>> if (abs(turtle.position()[0])> turtle.window_height()/2) or
>>> ^
>>> SyntaxError: invalid syntax
>
> How does Python know that the next line is the continuation of your if
> statement, instead of the beginning of a new line of code?  You didn't do
> anything to indicate continuation, so it takes this as an incomplete
> statement. "If ... stuff ... or... (or what??)"
>

it's a simple editing problem :
my editor and my python idle don't ever complain about that problem,
sorry


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


Re: [Tutor] Using contents of a document to change file names

2010-10-02 Thread Joel Goldstick
On Sat, Oct 2, 2010 at 1:18 PM, Emile van Sebille  wrote:

> On 10/2/2010 8:56 AM Josep M. Fontana said...
>
>  Hi,
>>
>> This is my first posting to this list. Perhaps this has a very easy answer
>> but before deciding to post this message I consulted a bunch of Python
>> manuals and on-line reference documents to no avail. I would be very
>> grateful if someone could lend me a hand with this.
>>
>>
> Hi Josep,
>
> Break the problem into pieces.
>
> Conceptually, you'll need to:
>
>  -a- get the list of file names to change then for each
>  -b- determine the new name
>  -c- rename the file
>
> For -a- you'll need glob. For -c- use os.rename.  -b- is a bit more
> involved.  To break -b- down:
>
>  -b1- break out the x-xx portion of the file name
>  -b2- look up the corresponding year in the other file
>  -b3- convert the year to the century-half structure
>  -b4- put the pieces together to form the new file name
>
> For -b2- I'd suggest building a dictionary from your second files contents
> as a first step to facilitate the subsequent lookups.
>
> You haven't included any code and we can't gauge how far along you are, so
> follow up and post the code you write as you go and we'll be better able to
> help out.
>
> Hope this is enough to get you started,
>
> Emile
>
> I echo Emile's excellent description.  He didn't speak to changing what is
in the file.  I would read from the first file a line at a time and
concatinate the citation date information to that string, then write the
string to a second file that is named according to your desired rule.  Then
copy the rest of the text to the new file.  When you are done, save the new
file and delete the original if you don't need it any longer.

>
>
>
>
>  Here's the problem I want to solve. I have a lot of files with the
>> following
>> name structure:
>>
>> A-01-namex.txt
>> A-02-namey.txt
>> ...
>> N-09-namez.txt
>>
>> These are different text documents that I want to process for an NLP
>> project
>> I'm starting. Each one of the texts belongs to a different century and it
>> is
>> important to be able to include the information about the century in the
>> name of the file as well as inside the text.
>>
>> Then I have another text file containing information about the century
>> each
>> one of the texts was written. This document has the following structure:
>>
>> A-01, 1278
>> A-02, 1501
>> ...
>> N-09, 1384
>>
>> What I would like to do is to write a little script that would do the
>> following:
>>
>> . Read each row of the text containing information about the centuries
>> each
>> one of the texts was written
>> . Change the name of the file whose name starts with the code in the first
>> column in the following way
>>
>> A-01-namex.txt -->  A-01-namex_13-2.txt
>>
>> Where 13-1 means: 13th 2nd half. Obviously this information would com
>> from the second column in the text: 1278 (the first two digits + 1 =
>> century; if the 3rd and 4th digits>  50, then 2; if<  50 then 1)
>>
>> Then in the same script or in a new one, I would need to open each one of
>> the texts and add information about the century they were written on the
>> first line preceded by some symbol (e.g @13-2)
>>
>> I've found a lot of information about changing file names (so I know that
>> I
>> should be importing the os module), but none of the examples that were
>> cited
>> involved getting the information for the file changing operation from the
>> contents of a document.
>>
>> As you can imagine, I'm pretty green in Python programming and I was
>> hoping
>> the learn by doing method would work.  I need to get on with this project,
>> though, and I'm kind of stuck. Any help you guys can give me will be very
>> helpful.
>>
>> Josep M.
>>
>>
>>
>>
>> ___
>> 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
>



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


[Tutor] Networking

2010-10-02 Thread Chris King

 Dear Tutors,
I have attached my 2 programs for networking. It uses socket and 
SocketServer, but it just simplifies it even more. The problem is it 
won't work. The Client raises the error, (with trace back)

Traceback (most recent call last):
  File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 34, in 


print client.recv()
  File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 16, in 
recv

return self.__sock.recv(1024)
error: [Errno 10053] An established connection was aborted by the 
software in your host machine
The server seems to get an error of some sort, but also seems to catch 
and print it. It prints


Exception happened during processing of request from ('127.0.0.1', 1424)
Traceback (most recent call last):
  File "C:\Python26\lib\SocketServer.py", line 281, in 
_handle_request_noblock

self.process_request(request, client_address)
  File "C:\Python26\lib\SocketServer.py", line 307, in process_request
self.finish_request(request, client_address)
  File "C:\Python26\lib\SocketServer.py", line 320, in finish_request
self.RequestHandlerClass(request, client_address, self)
TypeError: 'NoneType' object is not callable

I look at both of the documentations of socket and SocketServer, but I 
couldn't firgue it out. I don't know much about networking. Please Help

Sincerely,
Me
import SocketServer

def echo(self, data, server, client): #the default handling function
client.send(data) #echo

def create_handler(handle_func=echo): #creates an handler
class Handler(SocketServer.BaseRequestHandler): #the handler
def handle(self): #the handle method
handle_func(self, self.request.recv(1024), self.server, self.request) #call the handle method giving self, the data, the server, and the client

def run(handle_func = echo, host='localhost', port=1024): #init function
SocketServer.TCPServer((host, port), create_handler(handle_func)).serve_forever() #serve forever

if __name__ == '__main__': run() #if run directly, run server
import socket

class Client(object): #client object
def __init__(self, host = 'localhost', port = 1024, timeout = None):
self.host = host #set attributes
self.port = port
self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Make a sock
self.connect(self.host, self.port)
self.timeout = timeout

def send(self, data): #send data
if self.closed: raise NotConnectedError, 'The socket isn\'t connected.' #if closed, raise error
self.__sock.send(data)
def recv(self): #receive data
if self.closed: raise NotConnectedError, 'The socket isn\'t connected.' #if closed, raise error
return self.__sock.recv(1024)
def close(self): #close sock
self.__sock.close()
self.closed = True
def connect(self, host, port): #connect or reconnect
self.__sock.connect((host, port))
self.closed = False #set closed to false
def __get_timeout(self): return self.__sock.gettimeout()
def __set_timeout(self, timeout): self.__sock.settimeout(timeout)
timeout = property(__get_timeout, __set_timeout)


class __NotConnectedError(Exception): pass #A ClosedError

if __name__ == '__main__':
client = Client()
while True:
client.send(raw_input('What do you want to send? '))
print client.recv()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Networking

2010-10-02 Thread Evert Rol
> Dear Tutors,
> I have attached my 2 programs for networking. It uses socket and 
> SocketServer, but it just simplifies it even more. The problem is it won't 
> work. The Client raises the error, (with trace back)
> Traceback (most recent call last):
>   File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 34, in 
> 
> print client.recv()
>   File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 16, in recv
> return self.__sock.recv(1024)
> error: [Errno 10053] An established connection was aborted by the software in 
> your host machine
> The server seems to get an error of some sort, but also seems to catch and 
> print it. It prints
> 
> Exception happened during processing of request from ('127.0.0.1', 1424)
> Traceback (most recent call last):
>   File "C:\Python26\lib\SocketServer.py", line 281, in _handle_request_noblock
> self.process_request(request, client_address)
>   File "C:\Python26\lib\SocketServer.py", line 307, in process_request
> self.finish_request(request, client_address)
>   File "C:\Python26\lib\SocketServer.py", line 320, in finish_request
> self.RequestHandlerClass(request, client_address, self)
> TypeError: 'NoneType' object is not callable
> 
> I look at both of the documentations of socket and SocketServer, but I 
> couldn't firgue it out. I don't know much about networking. Please Help

I don't know much about networking, less so about it on Windows; also, I've 
only scanned quickly through the server script, but I notice your 
create_handler() function doesn't return anything. I guess it needs to return 
the Handler class.
The example in the Python docs doesn't use a factory function, but instead 
directly puts the class as the second argument to TCPServer. 
So the second argument needs to be a class, but since your create_handler() 
function returns nothing, you presumably get this NoneType exception.

  Evert

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


Re: [Tutor] function error

2010-10-02 Thread ALAN GAULD




> ##
> import  turtle, random
> 
> def checkForward(distance):
>  old_position = turtle.position()
>  turtle._pen.up()
>  turtle.forward(distance)
> forward_failed =  outOfBounds()

you set forward failed but never use it?

> turtle.setx(old_position[0]);  turtle.sety(old_position[1])
>  turtle._pen.down()
> if outOfBounds() ==  'false':
>  turtle.forward(distance)

If you change outOfVBounds to return a real boolean result you can just say

if outOfBounds():
   etc...

> def  stuck():
> return forward_failed

forward failed does not exist here it is a local variable in checkForward.
If you want to use it like this you need to create it as a global 
variable outside any of the function bodies.


> def  outOfBounds():
> if (abs(turtle.position()[0]) >  turtle.window_height()/2) or
> (abs(turtle.position()[1]) >  turtle.window_width()/2):
> return  "true"
> else:
>  return "false"

You can miss the if statement and just return the expression, 
that will give you a real True/False boolean result which is 
easier to work with than strings.

return (abs(turtle.position()[0]) >  turtle.window_height()/2) or
 (abs(turtle.position()[1]) >  turtle.window_width()/2)

However does this test check for out of bounds in all directions?
What happens if the turtle is travelling west/south rather than 
east/north? It may work but I don't see it.

> def randomMove2(d1, d2, a1,  a2):
>  while 1:

This is usually written as while True: nowadays

>   turtle.left(random.uniform(a1,a2))
>   checkForward(random.uniform(d1,d2))
>  if  outOfBounds() == 'true':
>turtle.right(180)

I don;t know iof any of that solves the probnl;em but it 
might tidy the code a little

HTH,

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


[Tutor] how to learn python from scratch, (for simpe people)?

2010-10-02 Thread a a
Dear Friends,

I am writing for some assistence from an expert. 
I give you a short background to understand my need.
(for your information I work with a macbook normally), but I do have desktop in 
Microsoft)
I am not a programmer. My work has to do with old manuscripts and Philosophy. 
But recently, being in need of building a web site I did learn alone some html, 
dreamweaver, css and I made two web sites who came out pretty good.
So, I have done of it my hobby, since I do like web design.
But now I would like to go further, although remaining always an hobby.
I would like to learn some programming, since I wish to build a program to run 
a database. Mybe more in the future if this goes well. 
I have some text, several books, text format. I want to make a program to vew 
and research these texts. Perhaps on a cd and on a desktop.

On the internet I have read that an easy to learn and yet powerful language to 
start with is python.
Now my questions:
1) Is python enough and complete to build a simple program of the kind 
deskribed above? 
2) Will I be able to build standalone program with it?
2) where do I start learning? SOMETHING AS SIMPE AS POSSIBLE!

Thank you very much
Jerome





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


Re: [Tutor] data question

2010-10-02 Thread ALAN GAULD
> I think this is what can work : http://www.daniweb.com/code/snippet216750.html

> 
> I will try it.

Good, that is exactly the kind of struicture I had in mind.
Just put the data structure in a module, forget about the 
code and import it to the >>> prompt and play with it till 
you are sure you know how to extract any piece of data 
you need, iterate over the structure, add/delete from it 
 etc.

HTH,

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


Re: [Tutor] Getting total counts (Steven D'Aprano)

2010-10-02 Thread aeneas24


Thanks very much for the extensive comments, Steve. I can get the code you 
wrote to work on my toy data, but my real input data is actually contained in 
10 files that are about 1.5 GB each--when I try to run the code on one of those 
files, everything freezes. 

To solve this, I tried just having the data write to a different csv file:

lines = csv.reader(file(src_filename))
csv_writer = csv.writer(file(output_filename, 'w'))
for line in lines:
doc, g1, g2, g3, rating, ratingmax, reviewer, helpful, h_total, word, count 
= line
row = [add_word(g1, word, count), add_word(g2, word, count), add_word(g3, 
word, count)]
csv_writer.writerow(row) 


This doesn't work--I think there are problems in how the iterations happen. But 
my guess is that converting from one CSV to another isn't going to be as 
efficient as creating a shelve database. I have some code that works to create 
a db when I release it on a small subset of my data, but when I try to turn one 
of the 1.5 GB files into a db, it can't do it. I don't understand why it works 
for small data and not big (it makes sense to me that your table approach might 
choke on big amounts of data--but why the shelve() code below?)

I think these are the big things I'm trying to get the code to do:
- Get my giant CSV files into a useful format, probably a db (can do for small 
amounts of data, but not large)
- Extract genre and star-rating information about particular words from the db 
(I seem to be able to do this)
- Get total counts for all words in each genre, and for all words in each 
star-rating category (your table approach works on small data, but I can't get 
it to scale)

def csv2shelve(src_filename, shelve_filename):
# I open the shelve file for writing.
if os.path.exists(shelve_filename):
os.remove(shelve_filename)
# I create the shelve db.
db = shelve.open(shelve_filename, writeback=True) # The writeback stuff is 
a little confusing in the help pages, maybe this is a problem?
# I open the src file.
lines = csv.reader(file(src_filename))
for line in lines:
doc, g1, g2, g3, rating, word, count = line
if word not in db:
db[word] = []
try:
rating = int(rating)
except:
pass
 db[word].append({
"genres":{g1:True, g2:True, g3:True},
"rating":rating,
"count":int(count)
})

db.close()

Thanks again, Steve. (And everyone/anyone else.)

Tyler



-Original Message-
From: tutor-requ...@python.org
To: tutor@python.org
Sent: Sat, Oct 2, 2010 1:36 am
Subject: Tutor Digest, Vol 80, Issue 10


Send Tutor mailing list submissions to
   tutor@python.org
To subscribe or unsubscribe via the World Wide Web, visit
   http://mail.python.org/mailman/listinfo/tutor
r, via email, send a message with subject or body 'help' to
   tutor-requ...@python.org
You can reach the person managing the list at
   tutor-ow...@python.org
When replying, please edit your Subject line so it is more specific
han "Re: Contents of Tutor digest..."

oday's Topics:
   1. Re: (de)serialization questions (Lee Harr)
  2. Re: regexp: a bit lost (Steven D'Aprano)
  3. Re: regexp: a bit lost (Alex Hall)
  4. Re: (de)serialization questions (Alan Gauld)
  5. Re: Getting total counts (Steven D'Aprano)
  6. data question (Roelof Wobben)

-
Message: 1
ate: Sat, 2 Oct 2010 03:26:21 +0430
rom: Lee Harr 
o: 
ubject: Re: [Tutor] (de)serialization questions
essage-ID: 
ontent-Type: text/plain; charset="windows-1256"

>> I have data about zip codes, street and city names (and perhaps later also 
f
>> street numbers). I made a dictionary of the form {zipcode: (street, city)}
>
> One dictionary with all of the data?
>
> That does not seem like it will work. What happens when
> 2 addresses have the same zip code?
You did not answer this question.
Did you think about it?

 Maybe my main question is as follows: what permanent object is most suitable 
o
 store a large amount of entries (maybe too many to fit into the computer's
 memory), which can be looked up very fast.
One thing about Python is that you don't normally need to
hink about how your objects are stored (memory management).
It's an advantage in the normal case -- you just use the most
onvenient object, and if it's fast enough and small enough
ou're good to go.
Of course, that means that if it is not fast enough, or not
mall enough, then you've got to do a bit more work to do.

 Eventually, I want to create two objects:
 1-one to look up street name and city using zip code
So... you want to have a function like:
def addresses_by_zip(zipcode):
?? '''returns list of all addresses in the given zipcode'''
?? 

 2-one to look up zip code using street name, apartment number and city
and another one like:
def zip_by_address(street_name, apt, city):
?? '''returns the zipcode for the given street 

Re: [Tutor] how to learn python from scratch, (for simpe people)?

2010-10-02 Thread Emile van Sebille

On 10/2/2010 8:22 AM a a said...

Dear Friends,

I am writing for some assistence from an expert.
I give you a short background to understand my need.
(for your information I work with a macbook normally), but I do have desktop in 
Microsoft)
I am not a programmer. My work has to do with old manuscripts and Philosophy.
But recently, being in need of building a web site I did learn alone some html, 
dreamweaver, css and I made two web sites who came out pretty good.
So, I have done of it my hobby, since I do like web design.
But now I would like to go further, although remaining always an hobby.
I would like to learn some programming, since I wish to build a program to run 
a database. Mybe more in the future if this goes well.
I have some text, several books, text format. I want to make a program to vew 
and research these texts. Perhaps on a cd and on a desktop.

On the internet I have read that an easy to learn and yet powerful language to 
start with is python.
Now my questions:
1) Is python enough and complete to build a simple program of the kind 
deskribed above?
2) Will I be able to build standalone program with it?
2) where do I start learning? SOMETHING AS SIMPE AS POSSIBLE!

Thank you very much
Jerome




I'd suggest you check out Alan's site at

  http://www.freenetpages.co.uk/hp/alan.gauld/

He hangs out here and you'll be able to get any additional clarification 
you need.


You might also find this helpful

  http://diveintopython.org/toc/index.html

Finally, i'd suggest you start with python2 (vs python3) -- most of the 
info you'll find on the net is python2 and not always up to date for 
python3.


Good luck!

Emile

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


Re: [Tutor] how to learn python from scratch, (for simpe people)?

2010-10-02 Thread Emile van Sebille

On 10/2/2010 4:21 PM Emile van Sebille said...

On 10/2/2010 8:22 AM a a said...

Now my questions:
1) Is python enough and complete to build a simple program of the kind
deskribed above?


Yes


2) Will I be able to build standalone program with it?


Yes


Sorry - Forget to answer your questions.  Python's a great choice.

Regards,

Emile

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


Re: [Tutor] Connecting my users

2010-10-02 Thread Steven D'Aprano
On Sat, 2 Oct 2010 08:06:14 pm Timo wrote:
> On 01-10-10 11:25, Nitin Pawar wrote:
> > have a look at this
> >
> > http://bytes.com/topic/python/answers/826973-peer-peer-chat-program
>
> Thanks, but that still uses a server. And even one that I can't
> control! If it has to be with server interaction, than as little as
> possible is preferred and option to put it on my own.

You obviously didn't read the article carefully enough. It describes a 
peer-to-peer chat program, and I quote from the project page:

"kaishi is a chat program without any central servers. Currently all 
users connected to kaishi are on the same level of the network, meaning 
no user has more control over the others."


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


Re: [Tutor] data question

2010-10-02 Thread Alan Gauld


"Roelof Wobben"  wrote


Perhaps a simple SQLlite database?



Oke, there I can save the input data.
But I have also need a data model for team, played_games, 
game_points,

made_points and againts_points.
So I think it cannot be done without using a class for games and one 
for ranking.


If you use a database you won't need any classes. All you need is the 
data
model in the database and some SQL queries to extract and manipulate 
the
date to produce your reports. But using a SQL database may be more 
than
you can cope with just now IMHO, I'd stick to the basic Python for 
now.


Alan G. 



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


Re: [Tutor] how to learn python from scratch, (for simpe people)?

2010-10-02 Thread Alan Gauld


"a a"  wrote


...building a web site I did learn alone some html, dreamweaver, css


But now I would like to go further, although remaining always an 
hobby.
I would like to learn some programming, since I wish to build a 
program

to run a database. Mybe more in the future if this goes well.




Now my questions:
1) Is python enough and complete to build a simple program of the 
kind deskribed above?


Python is nearly perfect for what you want.


2) Will I be able to build standalone program with it?


That depends on how you define standalone.
In the same way that Visual Basic, Java and any of the .Net family of 
languages do
standalone then yes you can. But you cannot build native executables, 
you need to
have a Python interpreter installed ( there are programs that fake it 
by bundling the
interpreter into the final .exe file but they are non trivial to use.) 
But if you mean can
you create a program that can be launched just by double clicking it 
in Windows
Explorer, then yes you can do that. But ultimately, for web based apps 
its irrelevant

since the code all runs on the server not the users computer.


2) where do I start learning? SOMETHING AS SIMPE AS POSSIBLE!


I don't usually like pushing my own tutorial because there are lots of 
others but
in this case I think it would actually be a good choice given your 
background

and aspirations. Reasons are:
1) It covers Python for absolute beginners
2) It also covers JavaScript which is nearly essential for client 
side(browser)

   web programming
3) It covers database work and networking fundamentals (which very few 
other

   beginners tutorials do)
4) I read this list so can answer questions"! :-)

As to Python v2 or v3, I normally recommend v2 since v3 still lags in 
support
for 3rd party tools but I actually think that for your purposes you 
can go
with either. You will ultimately want to learn a Web framework like 
Django

and that will be a bigger step than moving between Python versions.


HTH,


--
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] list comprehension, efficiency?

2010-10-02 Thread Steven D'Aprano
On Sun, 3 Oct 2010 01:17:39 am bob gailer wrote:

> I ran dis on a for loop and the equivalent comprehension.
>
> I was surprised to see almost identical code.
>
> I had assumed (and now wish for) that a comprehension would be a
> primitive written in C and thus much faster!

How could it be? A list comp is syntactic sugar. It needs to perform the 
same steps as a for-loop, and call an arbitrary Python expression. It's 
not like map() that takes a function object. Unless you had a separate 
primitive for every imaginable Python expression -- which is 
impossible -- list comps need to generate relatively similar code to 
for-loops because they do relatively similar things.

Besides, in recent versions of Python the speed of for-loops is quite 
good. The bottleneck is rarely the loop itself, but the work you do in 
the loop or the size of the loop.


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


Re: [Tutor] Getting total counts (Steven D'Aprano)

2010-10-02 Thread Alan Gauld

 wrote


I can get the code you wrote to work on my toy data, but my real
input data is actually contained in 10 files that are about 1.5 GB
each--when I try to run the code on one of those files, everything 
freezes.


Fot those kind of volumes I'd go for a SQL database every time!
(SQLlite might be OK but I'd be tempted to go to something even
beefier, like MySQL, PostGres or Firebird)

To solve this, I tried just having the data write to a different csv 
file:


For huge data volumes sequential files like csv are always going
to be slow. You need random access, and a full blown database
will probably be the best bet IMHO.


But my guess is that converting from one CSV to another isn't
going to be as efficient as creating a shelve database.


A shelve is fine for very simple lookups but its still basically
a flat file. And the minute you need to access by anything
other than the single key you are back to sequential processing.

HTH,

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


[Tutor] Smart posting - Was: Re: Tutor Digest, Vol 80, Issue 11

2010-10-02 Thread Alan Gauld
"Edward Lang"  wrote 


As the standard header advice says in the very mail that you posted:


When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."



And also


Today's Topics:

  1. Re: Connecting my users (Timo)
  2. Re: data question (Alan Gauld)
  3. Re: data question (Roelof Wobben)
  4. Re: data question (Roelof Wobben)
  5. Re: data question (Roelof Wobben)
  6. Re: data question (Robert Berman)
  7. Re: Coin Toss Problems (bob gailer)


Please, do not post the entire digest. 
We don't have time to wade through it looking for the few lines 
you may have added or commented upon.


You have a delete key. Please use it.

And while I'm having a rant, please do not top-post.
(I don;t know if you are guilty of this particular crime 
because I couldn't see any new content in your mail, 
but it is a common problem...)
Cut out everything but what is relevant and post your 
comments underneath. I know it's contrary to normal 
business practice but it's a lot easier to work with on 
a busy mailing list.


Thankyou,

--
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] Using contents of a document to change file names

2010-10-02 Thread Alan Gauld


"Josep M. Fontana"  wrote

Here's the problem I want to solve. I have a lot of files with the 
following

name structure:

A-01-namex.txt


Then I have another text file containing information about the 
century each
one of the texts was written. This document has the following 
structure:


A-01, 1278

   A-01-namex.txt --> A-01-namex_13-2.txt

   Where 13-1 means: 13th 2nd half. Obviously this information would 
com

from the second column in the text: 1278 (the first two digits + 1 =
century; if the 3rd and 4th digits > 50, then 2; if < 50 then 1)

Then in the same script or in a new one, I would need to open each 
one of
the texts and add information about the century they were written on 
the

first line preceded by some symbol (e.g @13-2)


If you break it into discrete steps it is all petty basic file and 
string processing.


You can rename the file using the os module
You can construct the filename using string methods
You can get the data to put in the filename by reading a file
You can add the new century data by writing a file.

Now tell us which of those operations is giving you the headache?
Or is it the issue of building the overall program structure?

Once we know more about where your specific problem lies we can give
you a better answer.



--
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] Getting total counts (Steven D'Aprano)

2010-10-02 Thread Steven D'Aprano
On Sun, 3 Oct 2010 08:29:29 am aenea...@priest.com wrote:
> Thanks very much for the extensive comments, Steve. I can get the
> code you wrote to work on my toy data, but my real input data is
> actually contained in 10 files that are about 1.5 GB each--when I try
> to run the code on one of those files, everything freezes.

Do you have 15 GB of memory? Actually, more, due to the overhead, the 
operating system, and so forth. If not, then I'm not surprised that 
things freeze.

> To solve this, I tried just having the data write to a different csv
> file:

A 15GB csv file is not the right approach.

> This doesn't work--I think there are problems in how the iterations
> happen. But my guess is that converting from one CSV to another isn't
> going to be as efficient as creating a shelve database.

shelve is not an industrial strength database. It's a serialised 
dictionary. The source code for shelve is ~100 lines of code, plus 
comments and docstrings. Now Python is good, but it's not *that* good 
that it can create a full-strength database in 100 lines of code.

I expect that at the very least you will need to use SQLite. With 15 GB 
of data, you may even find that SQLite isn't powerful enough and you 
may need a full blown Postgresql or MySQL database.


P.S. Please don't quote the entire digest when replying:

> -Original Message-
> From: tutor-requ...@python.org
> To: tutor@python.org
> Sent: Sat, Oct 2, 2010 1:36 am
> Subject: Tutor Digest, Vol 80, Issue 10
[snip approx 150 irrelevant lines]


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


Re: [Tutor] Smart posting - Was: Re: Tutor Digest, Vol 80, Issue 11

2010-10-02 Thread James Mills
On Sun, Oct 3, 2010 at 10:11 AM, Alan Gauld  wrote:
> Please, do not post the entire digest. We don't have time to wade through it
> looking for the few lines you may have added or commented upon.

I'm actually really surprised anyone actually uses and subscribes to
mailing lists and wants to get
digests. It's far easier (for me at least) to just get each email as
it comes in.

--James


-- 
-- James Mills
--
-- "Problems are solved by method"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (de)serialization questions

2010-10-02 Thread Steven D'Aprano
On Sat, 2 Oct 2010 04:08:22 am Albert-Jan Roskam wrote:

> Maybe my main question is as follows: what permanent object is most
> suitable to store a large amount of entries (maybe too many to fit
> into the computer's memory), which can be looked up very fast.

"Very fast" and "cannot fit in main memory" do not go together. Reading 
from disk is 100-1000 times slower than reading from main memory, and 
writing to disk even slower.

The best you can hope for is "fast enough". And that means using a 
database. Which database will depend on what data you are storing, how 
much there is, what you plan to do with it, and many other questions.


> Eventually, I want to create two objects:
> 1-one to look up street name and city using zip code
> 2-one to look up zip code using street name, apartment number and
> city
>
> I stored object1 in a marshalled dictionary. Its length is about
> 450.000 (I live in Holland, not THAT many streets). 

That will probably fit in main memory. If not, add some more memory. 
Even if each address takes 1000 bytes of memory, that's only 450 MB in 
total. Double it for the second object and add 100 MB of overhead and 
you've only got 1 GB in total -- well within the capabilities of a 
server, or even a high-end desktop. Put 4 GB of the fastest memory you 
can find into the machine, and with luck it will be fine.

But the only way to tell for sure will be to try it, and see how much 
memory it takes. Then consider what will happen if you double the 
number of records.

Consider using pickle instead of marshal. marshal is really only 
intended for Python byte-code files.


[...]
> You suggest to simply use a file. I like simple solutions, but
> doesn't that, by definition, require a slow, linear search? I chose a
> dictionary for object1 because hash tables are very fast in terms of
> lookup times. Another option might be to use the bisect module. Not
> sure if using a binary search algoritm is much faster with these
> still relatively small numbers. It's interesting for sure, but I
> don't know whether using bisect would justify the added amount of
> complexity and bug risks.

Oh come on now, bisect is not that complicated! Yes, there's a small 
amount of added complexity, but it's still a simple algorithm. If 
you're seriously considering a linear search over 450 thousand items 
just to avoid doing a binary search, there's something seriously wrong.

Is it worth it? Log base 2 of 45 is less than 19, so the average 
binary search will take 19 lookups. The average linear search will take 
225000 lookups. I'm confident that will be worth it.


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


[Tutor] retrieve google translate sound files through python

2010-10-02 Thread Norman Khine
does anyone know how i can extend this example
http://stackoverflow.com/questions/1136604/how-do-i-use-the-json-google-translate-api
and be able to download the sound file produced by the translation?

thanks

norman

-- 
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor