Re: [Tutor] [tutor] creating list of tuples

2008-02-26 Thread Alan Gauld

Varsha Purohit [EMAIL PROTECTED] wrote

One small point.

  for x in file:
value=0
tup = ()

There ia no point in creating an emnpty tuuple. Tuples 
are immutable so this tuple will simply be thrown away.
It doesnm't do much harm, but it does no good either.

for developerAgent in developers:
#print developerAgent.disutility
value +=developerAgent.disutility
tup = (value,globalVar.cntr)

This creates a brand new tuple and is all that is needed.

BTW going by the names used are you sure a list of 
tuples is what you need? It looks like maybe a dictionary 
could be used instead storing the values against the cntr 
as a key. That would perform the role of borth list and 
tuple and make retrieval of the values easier later.

Just a thought.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
Temorarily at:
http://uk.geocities.com/[EMAIL PROTECTED]/
Normally:
http://www.freenetpages.co.uk/hp/alan.gauld

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


[Tutor] How do I get GASP

2008-02-26 Thread Jim Morcobe
Hi,

I'd like to download a copy of GASP to run on Windows XP.  Is there a 
simple Windows installer available anywhere so I can do it with minimal 
effort?

Jim



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


Re: [Tutor] How do I get GASP

2008-02-26 Thread Alan Gauld
Jim Morcobe [EMAIL PROTECTED] wrote


 I'd like to download a copy of GASP to run on Windows XP.  Is there 
 a
 simple Windows installer available anywhere so I can do it with 
 minimal
 effort?

OK, I'll bite.
What is GASP and why are you asking on a Python mailing list?

I googled but came up with a mix of anti-smoking devices,
Golf swing improvemt programmes and a small wb site
design outfit among others.

What are you talking about?

-- 
Alan Gauld
Author of the Learn to Program web site
Temorarily at:
http://uk.geocities.com/[EMAIL PROTECTED]/
Normally:
http://www.freenetpages.co.uk/hp/alan.gauld 


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


[Tutor] file transfer through serial modem -- pythin code

2008-02-26 Thread Govind
Hi All,

I am new to python.
I want to transfer files over serial modem.so can I have some sample python 
code or any helpful links so that I can implement it.
All help will be highly appreciated.
 
Thanks  Regards,
Govind Goyal
Adya Systems  Software Pvt. Ltd.
212, IInd Floor, Okhla Industrial Estate III,
New Delhi - 110020 , India
Ph: 91.11.41602431 
Email ID-  [EMAIL PROTECTED]
  
Disclaimer: The information contained in this message is confidential and may 
be legally privileged. The message is intended solely for the addressee(s). If 
you are not the intended recipient, you are hereby notified that any use, 
dissemination, or reproduction is strictly prohibited and may be unlawful. If 
you are not the intended recipient, please contact the sender by return e-mail 
and destroy all copies of the original message.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file transfer through serial modem -- pythin code

2008-02-26 Thread Chris Fuller
You probably want to start with PySerial:
http://pyserial.sourceforge.net/

But, the details really depend on the application.. what are you talking to at 
the other end?  Do you need a general terminal program?

You can probably find xmodem and zmodem libraries, but if you control both 
ends, rolling your own would be easy enough, just be sure to check for data 
corruption.  Zmodem is preferred, since Xmodem can pad the end of the file 
with NULLs.

If you are working through a modem, you will need to be familiar with the 
Hayes AT Command Set.  Google is your friend.

Answering incoming calls is harder, you need access to the modem control lines 
(or you can tell the modem to answer manually).  This is a platform specific 
problem.

You might start out with a null modem cable between two computers (or even the 
same computer, with two serial ports), just to get familiar with the system.


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


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-26 Thread bob gailer
Andrei Petre wrote:
 https://www.spoj.pl/problems/DIV15/
I wrote my own version and submitted it. I got NZEC also.

The evidence pointed to a character in the test data other than 0123456789.

So I contrived a way to test for this and found that to be true. I don't 
know what the character is or which test case it is in but there is at 
least one bad character, and it is  chr(32) (i.e. a control character).

After revising my program to eliminate these bad characters I now get 
wrong answer. So now I revise my algorithm.

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

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


[Tutor] rss feed reader, but having trouble with unicode

2008-02-26 Thread Tom
I'm trying to write a little rss feed reader, but having trouble with
unicode. I would appreciate some help as I feel I'm going round in
circles.

Even when the save command works, ElementTree won't or vice-versa. You
can see what I've been trying from my commented out lines. I think
there is a problem with my understanding of unicode, so feel free to
enlighten me. What encoding is the xml string before I do anything?
Does my approach below make any sense???

import urllib, re, os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'djsite.settings'
from djsite.djapp.models import Feed
from xml.etree import ElementTree

url = 'http://www.osirra.com/rss/rss20/1'
#'http://www.michaelmoore.com/rss/mikeinthenews.xml'
#'http://www.michaelmoore.com/rss/mustread.xml'

f = urllib.urlopen(url)
xml = f.read()
f.close()

feed = Feed.objects.get(url=url)

if xml:
ms = re.findall('\\?xml version\=\[^]+\ encoding\=\([^]+)\\?\', xml)
if ms:
encoding = ms[0]
else:
encoding = 'utf-8'
print 'using encoding:', encoding

#xml = xml.encode(encoding, 'replace')
##xml = xml.decode(encoding, 'replace')
#xml = unicode(xml, encoding)
#xml = unicode(xml)

elem = ElementTree.fromstring(xml)
#do stuff with elem...

feed.xml = xml
feed.save()


Thanks for your time :-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I get GASP

2008-02-26 Thread Alan Gauld

Michael Connors [EMAIL PROTECTED] wrote

 What are you talking about?
 
 This maybe:
 
 https://launchpad.net/gasp-code

Yep, that looks more likely.

I still can't help though. The downloadds page says 
no up to date Win installer exists just unzip the source.

Alan G

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


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-26 Thread bob gailer
I will share my algorithm just for the heck of it and to see if you see 
any problem.

Underlying theory:
  Divisible by 15 == divisible by 3 and divisible by 5
  If a number is divisible by 3 any rearrangement of its digits is also 
divisible by 3.
  Therefore to get the largest number, put the digits in descending order.
  If the number is not divisible by 3 it can be made divisible by 3 by 
removing one or 2 non-multiple-of-3 digits
  To be divisible by 5 the rightmost digit must be 0 or 5. If it is 
neither then a 5 must be moved from the interior to the end.
   
s = the test case input

If there are no '0's and no '5's  in s then impossible.

Convert s (string) to a list, sort it, reverse it. If rightmost digit is 
not '0' or '5', remove a '5' from the list
(we will append it at checkout)

On a parallel path:

i = int(s)  # make numeric
r = i % 3 # get modulo
if r == 0 # divisible by 3 (regardless of the order of the digits)
  proceed to checkout
else
  attempt to remove one or two digits to bring the modulo to 0
  if possible remove just 1 digit (the lower the better) (the candidates 
are, for r ==1-1,4,7  r==2-2,5,8)
  otherwise if possible remove 2 digits (the lower the better) (the 
candidates are, for r ==2-1,4,7  r==1-2,5,8)
  otherwise impossible

checkout:
  if we removed a '5' from the list, append it
  join and print the list

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

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


Re: [Tutor] How do I get GASP

2008-02-26 Thread Kent Johnson

 Alan Gauld [EMAIL PROTECTED] wrote: 
 
 Michael Connors [EMAIL PROTECTED] wrote
 
  What are you talking about?
  
  This maybe:

In which case
- download from 
http://dev.laptop.org/pub/gasp/releases/SOURCES/python-gasp-0.1.1.tar.bz2
- unpack
- copy the 'gasp' folder (NOT python-gasp-0.1.1, rather the subfolder called 
'gasp') to your site-packages folder, e.g.
C:\Python25\lib\site-packages

Kent

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


Re: [Tutor] rss feed reader, but having trouble with unicode

2008-02-26 Thread rui
Hello Tom,

Try doing this:

xml = unicode(xml, encoding, ignore)
elem = ElementTree.fromstring(xml.encode(utf8))

  #do stuff with elem...

  feed.xml = xml
  feed.save()


  Thanks for your time :-)
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor




-- 
Rui
http://ruivaldo.wordpress.com

Rubi? Aquela novela do SBT?
~ Carla Perez sobre Ruby

Em Python, tudo é objeto, além de lindo e maravilhoso.
~ Caetano Veloso sobre Python
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-26 Thread bob gailer
Note I cc: [EMAIL PROTECTED] Please do so also so the other tutors can 
follow the discussion.

Andrei Petre wrote:
 the theory seems just like mine :)

 your way to implement it looks fine ( although it supports some 
 optimization :))

 But:

 - i don't understand :
  i = int(s)
  where s = the test case input (= a LIST ??)
s is a string

   you should summs up the elements of the list
In the pursuit of performance I chose int(s) as being potentially a lot 
faster than looping over all the chars, applying int() to each and summing.

 - it's not very clear in your implementation what happens with the 
 case : 815. try it
I get 15. However 875 gives a wrong answer! Turns out that if the 
rightmost digit is not 0 I must remove a 5 even if that is the rightmost 
digit!

Even after fixing that I still get wrong answer!

 and in one of your posts, you said:

 The evidence pointed to a character in the test data other than 
 0123456789.

 So I contrived a way to test for this and found that to be true. I don't
 know what the character is or which test case it is in but there is at
 least one bad character, and it is  chr(32) (i.e. a control character).
 i don't understand , in your

 i don't really understand that. you are trying to say that the tests 
 from the online judge are not exactly good ?
Yes that's exactly what I'm saying. At least one test case has a 
non-decimal character.
  

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

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


Re: [Tutor] crashed with Runtime Error: NZEC (non-zero exit code)

2008-02-26 Thread Alan Gauld

bob gailer [EMAIL PROTECTED] wrote

 i don't really understand that. you are trying to say that the 
 tests
 from the online judge are not exactly good ?
 Yes that's exactly what I'm saying. At least one test case has a
 non-decimal character.

Which actually makes it a very good test since thats
exactly the kind of thing you should be testing for :-)
A test suite that only checks valid data is a bad test.

Alan G. 


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


Re: [Tutor] [tutor] Question on multithreading

2008-02-26 Thread Kent Johnson
Varsha Purohit wrote:
 Hello,
 i have a gui program in wxpython where i am spawning two threads. 
 one for the mainloop of gui and other for some background tasks.

It is unusual to start a new thread for the GUI. Usually the GUI is run
in the main application thread.

 I have 
 to stop the background running thread once its work is done.

A thread will stop when its run() method returns, so if you want the
thread to do some work, then stop, just have the run() method terminate.

 is there any method called stop() to 
 stop the threads

No.

 Also, i want to see if the thread is alive or not.. 
 but i donno where should i put the isAlive() method associated with the 
 thread.. i tried putting it in the code where thread does execution but 
 apparently it is not the correct place.

You should put isAlive() in the code that cares whether the other thread
is alive...it won't be useful to put the call to isAlive() in the thread
you are testing, it will always be alive when the method is called!


 Here is the code...
 
 class GuiScript(threading.Thread):
 def __init__(self):
 self.run()
 def run(self):
 app = wx.PySimpleApp()
 MainWindow().Show()
 app.MainLoop()

 class RunScript(threading.Thread):
 def run(self):
 imFile=test()

Do you have code to instantiate and start the threads? The above only
defines two thread classes, it doesn't actually start any threads.

 and when the stop button is pressed the two threads should stop 
 executing... so i have written code like this...
 
 def OnCloseWindow(self,event):
 GuiScript().Stop()

This creates a GuiScript thread - by calling GuiScript() - then calls
Stop() on the thread. The thread is never started and I don't know what
Stop() is...

wxPython has a Threads.py example that might be worth studying.
Here is a threading intro:
http://www.wellho.net/solutions/python-python-threads-a-first-example.html

Kent

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


[Tutor] List Box for Web

2008-02-26 Thread Dinesh B Vadhia
I know this isn't the right forum to ask but I'll try as someone might know.

For my web application, I need a list box with a search capability.  An example 
is the Python documentation (hit the F1 key under Windows from IDLE) and 
specifically the Index list ie. context-sensitive search through a list of 
phrases, but for use on a web page. 

Does anyone know if there are any open source UI widgets for such a capability?

Any help/pointers appreciated. 

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


Re: [Tutor] List Box for Web

2008-02-26 Thread Luciano Ramalho
On Wed, Feb 27, 2008 at 2:21 AM, Dinesh B Vadhia
[EMAIL PROTECTED] wrote:
 For my web application, I need a list box with a search capability.  An
 example is the Python documentation (hit the F1 key under Windows from IDLE)
 and specifically the Index list ie. context-sensitive search through a list
 of phrases, but for use on a web page.

 Does anyone know if there are any open source UI widgets for such a
 capability?

On the web, such functionality goes way beyond a mere widget, as it
requires communication between the client browser and a web server.
The server side of this is straightforward. It's the client that may
be complicated in case you want to give users immediate feedback as
they type. If that is so, you'd need to use AJAX.

Anyhow, because Python does not run in browsers, you will not find a
solution to this using only Python. I suggest you study how web apps
work and start playing with Python modules and frameworks for
server-side web programming. I'd start with the cgi module to make
sure you understand the basics before progressing to more
sophisticated and magical frameworks.

Cheers,

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