Re: [Tutor] Threading + socket server (blocking IO)

2006-02-06 Thread Matthew Webber
>> The GIL prevents Python from effectively running multiple threads on
multiple processors. 

This statement is slightly misleading. You can run multiple threads on a
multi-processor system quite effectively, the limitation of the GIL is
simply that you can typically utilize only one processor at a time.


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


Re: [Tutor] python help

2006-02-08 Thread Matthew Webber
These sound like homework questions, in which case it would not be right for
us to just give you the answer (and it would not be right for you to ask for
it).

If you can show us what you have tried so far, maybe we can give you some
hints ...



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Natasha Menon
Sent: 08 February 2006 17:19
To: tutor@python.org
Subject: [Tutor] python help


Hi,
 
I have a few doubts in python programming. C if any of u can help me
out. 
 
1. 
In a file called string_stuff.py i have to write a function called
frequencies that takes a string as a parameter and returns a dictionary
where the keys are the characters from the string and each value is an
integer indicating the number of times the key appeared in the string. 
 
2.
Similary in the same file string_stuff.py, have to write a function
called locations that takes a string as a parameter and returns a dictionary
where the keys are the characters from the string and each value is a list
indicating the indices in the string at which the key appears, sorted in
increasing order.
 
3.
In the same file string_stuff.py, write a function called
concordance that takes an open file as a parameter and returns a dictionary
where the keys are the strings from the file and each value is a list of
line numbers of the lines in which the key appeared, sorted in increasing
order. Start counting at 0. Each line number should appear at most once in a
list, even if a word appears twice on a line. You may assume that the input
consists only of alphabetic letters (a-z, A-Z) and whitespace. 
 
 
Id really appreciate if you could help me on these small question. I
am tryin to learn to program in python.
 
Thanks,
Natasha


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


Re: [Tutor] Sqrt is listed as always available.

2006-02-15 Thread Matthew Webber
This works for me under Python 2.4 -
import math
math.sqrt(4)

When you state "Sqrt is listed as always available", where does it say that?
For future problem reports, let us know which Python release you are
running.


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Kermit Rose
Sent: 15 February 2006 08:53
To: tutor@python.org
Subject: [Tutor] Sqrt is listed as always available.



Sqrt is listed as always available.

Why did I get these diagnostics?


>>> Sqrt(J0)

Traceback (most recent call last):
  File "", line 1, in -toplevel-
Sqrt(J0)
NameError: name 'Sqrt' is not defined
>>> 
>>> sqrt(J0)

Traceback (most recent call last):
  File "", line 1, in -toplevel-
sqrt(J0)
NameError: name 'sqrt' is not defined
>>> SQRT(J0)

Traceback (most recent call last):
  File "", line 1, in -toplevel-
SQRT(J0)
NameError: name 'SQRT' is not defined
>>>  


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


Re: [Tutor] Iterate over letters in a word

2006-03-14 Thread Matthew Webber
As a side note, remember that that xor-ing a key with a message is trivial
to break (it's just a variation on the Vigenere cipher first published in
1568). So don't use if for any real applications.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Steve Nelson
Sent: 14 March 2006 15:29
To: tutor@python.org
Subject: [Tutor] Iterate over letters in a word

Hello,

I'm trying to work on some programs to help me understand ciphers and
ultimately cryptography.  I've understood so far, that a simple form
of bit-level cryptography is to split the original message into chunks
the same length as a 'key' and then do an xor.  I'm trying to keep
this really simple so I can understand from first principles - so eg:

"Hello Tutors!" could be split into:

"Hell" "o Tut" "ors!"

and xor'd with "beer"

I think I understand how xor works (thanks to an earlier post) but I'm
not sure how to iterate over each letter in a string.  What is the
recommended way to do this?

Thanks,

S.

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


[Tutor] Halting execution

2006-05-03 Thread Matthew Webber
This has got to be trivial, but I can't find the answer ... I want to stop
execution of my main script half way through. This is just for debugging -
the code in the bottom half of the script generates a whole lot of output
that I don't want. Inserting "break" or "return" doesn't work, but something
like that is what I had in mind.
 
I'm running under ipython on windows, FWIW.
 
Thanks

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


[Tutor] Summing part of a list

2006-05-09 Thread Matthew Webber
I have a list that looks a bit like this -
 
[(u'gbr', 30505), (u'fra', 476), (u'ita', 364), (u'ger', 299),
(u'fin', 6), (u'ven', 6), (u'chi', 3), (u'hun', 3), (u'mar', 3),
(u'lux', 2), (u'smo', 2), (u'tch', 2), (u'aho', 1), (u'ber', 1)]

The list items are tuples, the first item of which is a country code, and
the second of which is a numeric count. The list is guarenteed SORTED in
descending order of the numeric count.

What I need is a list with all the members whose count is less than 3
replaced by a single member with the counts added together. In this case, I
want :
[(u'gbr', 30505), (u'fra', 476), (u'ita', 364), (u'ger', 299),
(u'fin', 6), (u'ven', 6), (u'OTHER', 17)]

Any ideas about neat ways to do this? The simplest way is to just build the
new list with a basic loop over the original list. A slightly more
sophisticated way is to split the original list using a list comprehension
with an IF clause.

I have the feeling that there's probably really neat and more Pythonic way -
there are possibilities like zip, map, itertools. Any hints about what to
look at? Remember that the list is sorted already. If you can point me in
the right direction, I'm sure I can work out the specifics of the code.

Thanks
Matthew



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


Re: [Tutor] Summing part of a list

2006-05-09 Thread Matthew Webber
To expand on my original posting, I came up with this code which works ok :

count_country_aggregated = [cc for cc in count_country if cc[1]>3]
count_country_aggregated.append(('OTHER',sum([cc[1] for cc in count_country
if cc[1]<=3])))

But it uses 2 list comprehensions (therefore 2 passes of the original list).
Surely there is a neater way. 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Matthew Webber
Sent: 09 May 2006 17:22
To: tutor@python.org
Subject: [Tutor] Summing part of a list

I have a list that looks a bit like this -
 
[(u'gbr', 30505), (u'fra', 476), (u'ita', 364), (u'ger', 299),
(u'fin', 6), (u'ven', 6), (u'chi', 3), (u'hun', 3), (u'mar', 3),
(u'lux', 2), (u'smo', 2), (u'tch', 2), (u'aho', 1), (u'ber', 1)]

The list items are tuples, the first item of which is a country code, and
the second of which is a numeric count. The list is guarenteed SORTED in
descending order of the numeric count.

What I need is a list with all the members whose count is less than 3
replaced by a single member with the counts added together. In this case, I
want :
[(u'gbr', 30505), (u'fra', 476), (u'ita', 364), (u'ger', 299),
(u'fin', 6), (u'ven', 6), (u'OTHER', 17)]

Any ideas about neat ways to do this? The simplest way is to just build the
new list with a basic loop over the original list. A slightly more
sophisticated way is to split the original list using a list comprehension
with an IF clause.

I have the feeling that there's probably really neat and more Pythonic way -
there are possibilities like zip, map, itertools. Any hints about what to
look at? Remember that the list is sorted already. If you can point me in
the right direction, I'm sure I can work out the specifics of the code.


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


Re: [Tutor] Summing part of a list

2006-05-09 Thread Matthew Webber
Thanks Kent, I liked the generator solution (I knew there had to be
something like that).

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Kent Johnson
Sent: 09 May 2006 17:54
Cc: tutor@python.org
Subject: Re: [Tutor] Summing part of a list

<< snip >> 

Hmm, must be generator day today. Here is a generator that does what you 
want:

In [1]: data = [(u'gbr', 30505), (u'fra', 476), (u'ita', 364), (u'ger', 
299),
...: (u'fin', 6), (u'ven', 6), (u'chi', 3), (u'hun', 3), (u'mar', 3),
...: (u'lux', 2), (u'smo', 2), (u'tch', 2), (u'aho', 1), (u'ber', 1)]

In [10]: def summarize(data):
: sum = 0
: othersFound = False
: for item in data:
: if item[1] > 3:
: yield item
: else:
: sum += item[1]
: othersFound = True
: if othersFound:
: yield ('OTHER', sum)
:

In [11]: print list(summarize(data))
[(u'gbr', 30505), (u'fra', 476), (u'ita', 364), (u'ger', 299), (u'fin', 
6), (u'ven', 6), ('OTHER', 17)]

<< snip >>


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


Re: [Tutor] doubt plz help

2006-06-06 Thread Matthew Webber
>> Try to rephrase that question. I don't think I was the only one not
understanding what you are asking?

Try to rephrase that response. I'm sure that you understand the double
negative in the second sentence, but many who speak English as a second
language (including, possibly, the original poster) will not!



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


Re: [Tutor] (OT) Monitorising WEB POSTs

2006-06-07 Thread Matthew Webber
Install the Firefox extension called "Live HTTP headers", and look at the
"Generator" tab. This appears to be what you want. 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Peter Jessop
Sent: 07 June 2006 11:00
To: tutor@python.org
Subject: [Tutor] (OT) Monitorising WEB POSTs

I am building a python application to automate information capture
from a web site.
I want to use a python application to request and process the
information instead of using the site's WEB page.
However I am having problems finding out exactly what data the server
expects.
I have a firefox add-in called Web Developer that gives me good
information about the form (fields names etc..)
But what I want to do is find out exactly what POST data my browser is
sending.

I am aware of two ways of doing this.
a) A sniffer to read the udp packet sent from my computer
b) Send the page to my own WEB server

Is there a program or add in that will give me this information
without resorting to the solutions above.

Peter Jessop

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


Re: [Tutor] WinXP IDLE -> open file : how-to change default directory ?

2006-06-16 Thread Matthew Webber
Try right-clicking on the shortcut, select properties, and change the "start
in" value.
Matthew

P.S. When posting to the list, please use plain text format.



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of learner404
Sent: 15 June 2006 20:09
To: tutor@python.org
Subject: [Tutor] WinXP IDLE -> open file : how-to change default
directory ?


Hello,

On WinXP IDLE will always 'open' in Python24 folder at startup.

A beginner friend of mine hate that (personally I use SPE) and I
tried 'quickly' to find a way to configure that for him.

I found all the .cfg files in idlelib and also the .idlerc folder in
the "Documents and settings" but I don't see how to give IDLE a default
directory at startup (or kipping in memory the last one opened). 

How to do that or is it just not possible ?

Thanks 

learner404



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


Re: [Tutor] Python Programming Books

2006-07-14 Thread Matthew Webber
It depends a lot on what your prior programming experience in other
languages is.

I have a large amount of prior programming experience, and I found "Learning
Python" very good. The "Python Cookbook" (Martelli et. al., also O'Reilly)
is very useful for learning the idioms.
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Grady Henry
Sent: 14 July 2006 06:20
To: tutor@python.org
Subject: [Tutor] Python Programming Books

I have three books on Python programming, "Learning Python" by O'Reilly, 
"Beginning Python" by Hetland, and "Python in a Nutshell" by O'Reilly.  Are 
these good (recommended) books?  Any others that might be recommended? 


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


Re: [Tutor] editors

2006-08-18 Thread Matthew Webber
I use Eclipse (www.eclipse.org) with the pydev plugin
(pydev.sourceforge.net). Eclipse is written in Java (you need the JVM to run
it, and a decent amount of memory) and was originally intended for Java
development (that's what most of the docs reflect). It now has plugins
available for other languages. It also has am SVN plugin.
Matthew 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of anil maran
Sent: 18 August 2006 09:57
To: tutor@python.org
Subject: [Tutor] editors

what editors do you guys use?

emacs
vi?
xemacs

are there any plugins to configure autocomplete, i
want something to do good autocomplete such as showing
what type of arguments are available etc
thanks


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