[Tutor] James D Mcclatchey is out of the office.

2008-07-30 Thread James D Mcclatchey

I will be out of the office starting  07/30/2008 and will not return until
08/04/2008.

I will respond to your message when I return.


***IMPORTANT NOTICE: This communication, including any attachment, contains 
information that may be confidential or privileged, and is intended solely for 
the entity or individual to whom it is addressed.  If you are not the intended 
recipient, you should delete this message and are hereby notified that any 
disclosure, copying, or distribution of this message is strictly prohibited.  
Nothing in this email, including any attachment, is intended to be a legally 
binding signature.***

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


[Tutor] help with augumented assignment y += 1

2008-07-30 Thread Norman Khine

Hello,

I am writing a poll application, which has two XML files:

1) survey.xml

?xml version=1.0 encoding=UTF-8?
survey
question code=a1 type=MCQ
  titleIs an augumented assignment such as 'x = x + 1' the same as x 
+= 1?/title

  optionYes/option
  optionNo/option
  optionDon't know/option
/question
question code=a2 type=MAQ
  titleThe statement 'x *= y + 1' is equivalent to:/title
  option'x = (x * y) + 1'/option
  option'x = x * (y + 1)/option
  option'x = (y + 1) * x'/option
  optionAll of the above/option
/question
/survey

2) respons.xml

?xml version=1.0 encoding=UTF-8?
response
attempt username=1 date=2008-07-28 14:40
  question code=a1
answer1/answer
  /question
  question code=a2
answer2/answer
answer3/answer
  /question
/attempt
attempt username=5 date=2008-07-28 15:00
  question code=a1
answer1/answer
  /question
  question code=a2
answer1/answer
answer2/answer
  /question
/attempt
attempt username=3 date=2008-07-28 14:47
  question code=a1
answer3/answer
  /question
  question code=a2
answer4/answer
  /question
/attempt
/response

Here is the code I have so far, poll.py:



from folder import Folder
from handlers import Text
...

class Survey(Text):

Here we create the actual survey.xml file


def new(self):
self.questions = {}

def _load_state_from_file(self, file):


def to_str(self, encoding='UTF-8'):
lines = ['?xml version=1.0 encoding=%s?\n' % encoding,
 'survey\n']
# Business functions
# Questions
questions = self.questions
codes = questions.keys()
codes.sort()
for code in codes:
lines.append(questions[code].to_str(encoding))
lines.append('/survey')
return ''.join(lines)


class Response(Text):

Here we create the actual response.xml file


def new(self):
self.attempts = {}

def _load_state_from_file(self, file):
# TEST 015
attempts = {}

def to_str(self, encoding='UTF-8'):
lines = ['?xml version=1.0 encoding=%s?' % encoding,
 'response']
attempts = self.attempts
for username in attempts:
for attempt in attempts[username]:
lines.append(
'attempt username=%s date=%s mark=%2.2f'
% (username, attempt.date.strftime('%Y-%m-%d 
%H:%M'), attempt.mark))

questions = attempt.questions
for question_code in questions:
lines.append('  question code=%s' % question_code)
for answer in questions[question_code]:
lines.append('answer%s/answer' % answer)
lines.append('  /question')
lines.append('/attempt')
lines.append('/response')
return '\n'.join(lines)

def get_analysis(self):
attempts = self.attempts
for username in attempts:
user = []
question = []
for attempt in attempts[username]:
user.append(username)
questions = attempt.questions
answers = []
for question_code in questions:
for answer in questions[question_code]:
answers.append(answer)
question.append(question_code)

# [SEE NOTE 1]
print user, question, answers


class Attempt(object):

def __init__(self, username=None, date=None):
self.username = username
self.date = date
self.questions = {}


class Poll(Folder):

def new(self):
Folder.new(self)
self.cache['.survey'] = Survey()
self.cache['.response'] = Response()

def get_definition(self):
return self.get_handler('.survey')
definition = property(get_definition, None, None, '')

def get_results(self):
return self.get_handler('.response')
results = property(get_results, None, None, '')

def fill_form(self, context):
user = context.user
...

def analyse(self, context):
user, root = context.user, context.root
questions = self.definition.questions

results = [{'question': x,
'title': y.title,
'options': [y.options]}
 for x, y in questions.items()]
# [SEE NOTE 2]
print results




[NOTE 1] In the Response class I have a function 'get_analysis':

def get_analysis(self):
attempts = self.attempts


This returns:
['1'] ['1', '2', '2', '2'] [1, 1, 2, 4]
['0'] ['1', '2', '2'] [2, 2, 3]


[NOTE 2] In the Poll class, I have a function 'analyse':

   def analyse(self, context):
user, root = context.user, context.root
questions = self.definition.questions
...
This returns:

[{'question': 'a1', 'options': [[u'Yes', u'No', uDon't know]], 
'title': uIs 

Re: [Tutor] How to run a Python program under Windows.

2008-07-30 Thread bob gailer

Morgan Thorpe wrote:

Hey Again.

Okay i don't think my sad explantion did help at all.
Would you be able to explain step by step what i need to do to run the simplest 
of simple program's everyone else has asked about where it is and what not. 
According to them i have everything where it needs to be.
  


You have had a response from me and from Alan Gauld.

We have both offered advice and asked questions.

We can't do anything more for you until you try our advice and let us 
know where or how it is not helping, and answer our questions.


We realty want to help, and we need your cooperation to help effectively.



I like to think i'm reasonable at most computer things or anything to do with 
them i've built 3 working computers and i'm working on another with a friend 
and still this stumps me.
  


Skill with hardware has little to do with software skills.

Of the 4 or 5 replies i think that you would be most help.
  


We all can help.

AND PLEASE as I asked, reply to the list not just me.


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

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


Re: [Tutor] help with augumented assignment y += 1

2008-07-30 Thread Emile van Sebille

Norman Khine wrote:

Hello,

I am writing a poll application, which has two XML files:


Is this entire question consistent?  I ask because when you get to 
asking your question below, it sounds like you're trying to tie together 
two outputs:


snip and paste from below

 This returns:
 ['1'] ['1', '2', '2', '2'] [1, 1, 2, 4]
 ['0'] ['1', '2', '2'] [2, 2, 3]

...and

 This returns:
 [{'question': 'a1', 'options': [[u'Yes', u'No', uDon't know]],
 'title': uIs an augumented assignment such as 'x=x + 1' the same as x
 += 1?}, {'question': 'a2', 'options': [[u'x=(x * y) + 1', u'x=x
 *(y + 1), u'x=(y + 1) * x', u'All of the above']], 'title': uThe
 statement 'x *= y + 1' is equivalent to:}]

The second is clearly the survey -- it's the first I question.  How do 
those two lines relate to the xml response?


If you could coalesce your example into a single executable or clearly 
relate those two lines to the xlm response it (presumably) derives from 
there's a better chance you'll get a more helpful reply.


Regards,

Emile

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


Re: [Tutor] help with augumented assignment y += 1

2008-07-30 Thread Emile van Sebille

Norman Khine wrote:

Hi,
Appologies, there was a typo, in that the first line is:

['1'] ['a1', 'a2', 'a2', 'a2'] [1, 1, 2, 4]


Yes -- that helps.

So, working from your xml samples, by doing something like:

responses = [ [a,b,c] for a,b,c in responseAnalysisGenerator ]

you can end up with responses and survey that look like:

responses = [
  [['1'],['a1', 'a2'],[1, [2,3]]],
  [['5'],['a1', 'a2'],[1, 2]],
  [['3'],['a1', 'a2'],[3, 4]]
  ]

survey = [{'question': 'a1',
  'options': [[u'Yes',
   u'No',
   uDon't know]],
   'title': uIs an augumented assignment such as \
   'x = x + 1' the same as x += 1?},
 {'question': 'a2',
  'options': [[u'x = (x * y) + 1',
   u'x = x * (y + 1),
   u'x = (y + 1) * x',
   u'All of the above']],
  'title': uThe statement 'x *= y + 1' is equivalent to:}]

Now the questions evolves to extracting the appropriate formatted output
from these two structures.  This can take place in many ways and is 
directly a function of the range of questions you'd want to answer.  In 
addition to the totals by question, one of your output formats appeared 
to be a restatement by user of the survey.  This suggests a class 
structure where you initialize the class with something like:


myAnalyzer = SurveyAnalyzer(survey,responses)

and let it respond to queries like:

sampleRecap = myAnalyzer.recap()
sampleRecap = myAnalyzer.userResponse('3')

Does this help?

Emile

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


[Tutor] Communication between threads

2008-07-30 Thread James
All,

I'm looking for some thoughts on how two separate threads can
communicate in Python. From what I've read in a few Python books,
sharing data between threads can be done by writing and reading a
global variable in the parent of both threads. Is this the best way?
Is it the *only* way?

Also, any thoughts on how to best use notify()? I've found very
little documentation on how to best use notify() when dealing with
multiple threads. (many of the documents I've found explain how to use
notifyAll(), but I'm unsure broadcasting a message to all threads
like that is the best way to deal with a problem)

Sorry this question is so broad; threading (properly) seems to be a
complex subject and it seems I'm in over my head. I've read tons of
documents, however, and am still rather unclear about all the tiny
parts of the big picture.

Thoughts? :)

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


[Tutor] understanding join

2008-07-30 Thread Steve Poe

Hi tutor list,

Just trying to add some clarity to the built-in function strings using  
join. The Python help
screen says it returns a string which is a concatenation of strings in  
sequence. I am concatenating

the string I am working on that maybe an issue of its own.

Here's my example:

string ='ab'

so, if I type:

print  string.join(string)

aabb

but if string is 'abc'

print string.join(string)
aabcbabcc


print string ='a' returns on a in this example, whit string='a '  
returns aa. So, I am not catching

the pattern.

Thanks.

Steve



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


Re: [Tutor] Communication between threads

2008-07-30 Thread Emile van Sebille

James wrote:

All,

I'm looking for some thoughts on how two separate threads can
communicate in Python. From what I've read in a few Python books,
sharing data between threads can be done by writing and reading a
global variable in the parent of both threads. Is this the best way?
Is it the *only* way?


I happened to see an article on this -- let's see...

http://www.ibm.com/developerworks/aix/library/au-threadingpython/index.html

Specifically the queues discussion.

HTH,

Emile

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


Re: [Tutor] understanding join

2008-07-30 Thread John Fouhy
On 31/07/2008, Steve Poe [EMAIL PROTECTED] wrote:
 Hi tutor list,

  Just trying to add some clarity to the built-in function strings using
 join. The Python help
  screen says it returns a string which is a concatenation of strings in
 sequence. I am concatenating
  the string I am working on that maybe an issue of its own.
[...]
  but if string is 'abc'

  print string.join(string)
  aabcbabcc

Hi Steve,

First up, a quick comment: There is a string module in the standard
library, and it has a function called join().  So it's generally a
good idea not to use 'string' as a variable name, as it can confuse
people :-)

Now, to your question: your string is 'abc'.  It doesn't matter that
you're using a string to join itself; what you've written is identical
to:

 'abc'.join('abc')
'aabcbabcc'

Let's change the call slightly to make things more clear:

 'abc'.join('ABC')
'AabcBabcC'

Does that make the pattern more clear?

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


Re: [Tutor] understanding join

2008-07-30 Thread John Fouhy
On 31/07/2008, Steve Poe [EMAIL PROTECTED] wrote:
  Good point. I guess I am surprised a little that Python does not error
  on that you cannot assign a variable to a module name.  I know I need
  to learn proper coding techniques.

Well, that wouldn't really work because you don't know what other
modules people have.

  Okay, I can see the order of the join is the same as mine, but
  the join still seems to be out of sequence.  I am thinking it should be
  'abcABC' or 'ABCabc' not at the beginning, middle, and end of the
  original string. At least, I am trying to wrap my head around its
  usefulness.

Say I have a sequence seq and a string s, and I call s.join(seq).
Here's what it does:

s.join(seq) == seq[0] + s + seq[1] + s + seq[2] + s + ...  + seq[-2] +
s + seq[-1]

So if you call 'abc'.join('ABC'), you get:

   'ABC'[0] + 'abc' + 'ABC'[1] + 'abc' + 'ABC'[2]

which is:

   'A' + 'abc' + 'B' + 'abc' + 'C'

Hope this helps.

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


Re: [Tutor] understanding join

2008-07-30 Thread Kent Johnson
 On 31/07/2008, Steve Poe [EMAIL PROTECTED] wrote:
  Okay, I can see the order of the join is the same as mine, but
  the join still seems to be out of sequence.  I am thinking it should be
  'abcABC' or 'ABCabc' not at the beginning, middle, and end of the
  original string. At least, I am trying to wrap my head around its
  usefulness.

Does this look useful?

In [3]: people = [ 'Tom', 'Dick', 'Harry' ]

In [4]: ', '.join(people)
Out[4]: 'Tom, Dick, Harry'

Your confusion is in thinking about the string 'ABC' as a single
entity. For the purposes of join(), it is a sequence of three letters.
The argument to join() is a sequence of strings, not a single string.

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


[Tutor] checking for expected types from input file

2008-07-30 Thread Bryan Fodness
I am populating a dictionary from an input file, and would like to create an
error code if a string is sent to a variable that expects a float or int.

INPUT = {}
for line in open(infile):
input_line = line.split(' = ')
INPUT[input_line[0].strip()] = input_line[1].strip()

if INPUT.has_key('ReferencePositionX'):
refx = float(INPUT['ReferencePositionX'])/10
refy = float(INPUT['ReferencePositionY'])/10
refz = float(INPUT['ReferencePositionZ'])/10

I have many variables of different types, and I want to do a check in
case something like ReferencePositionX = abc occurs.

-- 
The game of science can accurately be described as a never-ending insult to
human intelligence. - João Magueijo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] checking for expected types from input file

2008-07-30 Thread Steve Poe

Bryan,

How about checking your input to see if they are digits or not?
 input_data = '123ABC'
 print input_data.isdigit()
False
 input_data = '1234567889'
 print input_data.isdigit()
True
 input_data = '123ABC'
 print input_data.isdigit()
False

or something like:

while INPUT.has_key('ReferencePositionX').isdigit() =='True':

refx = float(INPUT['ReferencePositionX'])/10
refy = float(INPUT['ReferencePositionY'])/10
refz = float(INPUT['ReferencePositionZ'])/10




Steve

On Jul 30, 2008, at 6:43 PM, Bryan Fodness wrote:

I am populating a dictionary from an input file, and would like to  
create an error code if a string is sent to a variable that expects  
a float or int.


INPUT = {}
for line in open(infile):
input_line = line.split(' = ')
INPUT[input_line[0].strip()] = input_line[1].strip()

if INPUT.has_key('ReferencePositionX'):
refx = float(INPUT['ReferencePositionX'])/10
refy = float(INPUT['ReferencePositionY'])/10
refz = float(INPUT['ReferencePositionZ'])/10

I have many variables of different types, and I want to do a check  
in case something like ReferencePositionX = abc occurs.


--
The game of science can accurately be described as a never-ending  
insult to human intelligence. - João Magueijo

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


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


Re: [Tutor] checking for expected types from input file

2008-07-30 Thread Alan Gauld


Bryan Fodness [EMAIL PROTECTED] wrote

I have many variables of different types, and I want to do a check 
in

case something like ReferencePositionX = abc occurs.


In Python its usual to tackle that using try/except.
If you get a TypeError then try type conversion.
The saying goes somethinng like:
Its better to ask forgivness than permission

Alan G. 



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


Re: [Tutor] understanding join

2008-07-30 Thread Alan Gauld


Steve Poe [EMAIL PROTECTED] wrote


Your explanation is very help. It does make be wonder the usefulness
of join with strings. Do you have a practical example/situation?


Its not really intended for strings but it needs to work that way to
be consistent because strings are just another type of collection
in Python and we want to treat collections (or sequences)
as consistently as possible.

But there are times when you want to separate the characters
of a string out for display and inserting a space or a comma
using join is convenient. It would be extremely rare to use

mystring.joing(mystring)

It is usually

myseparator.join(mysequence)

HTH
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


[Tutor] key/value order in dictionaries

2008-07-30 Thread Steve Poe

Hi tutor list,

In dictionaries, I know that the keys are immutable, and the values
can change  What about the place/order of the key/order?  I thought
that they were sequential and they do not change.


 D={AAA:1234,BBB:3456,CCC:7890}
 print D
{'AAA': 1234, 'BBB': 3456, 'CCC': 7890}
 D={}
 D={AAA:1234,BBB:3456,CCC:7890,DDD:,EEE:,FFF: 
}

 print D
{'AAA': 1234, 'BBB': 3456, 'EEE': , 'FFF': , 'CCC': 7890,  
'DDD': }


If I know the key, then I can find the value, so the order it is in  
the dictionary
should not matter. I am just curious  why this happens.  If I have (4)  
key/value
pairs, the display order is the same as I entered the them. With 5 or  
more key/value

dictionaries, the printed result is not sequential.

Any thoughts?

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