Re: [Tutor] Starbucks does not use two-phase commit

2006-01-22 Thread Danny Yoo


On Sat, 21 Jan 2006, Todd Maynard wrote:

 I want to thank you for ruining my plans for a relaxing Saturday
 morning.  As a thread newbie I killed several hours playing around with
 your code.

Hi Todd,

Sorry about that.  I hope you were relaxing in a cafe while playing with
the code.


 One thing I noticed is that sometimes the program would hang, which I
 figured was the Queue code blocking in the Ticket claim function. I used
 exception handling to deal with that situation cleanly.

That's odd.  There shouldn't be anything that blocks the code.  Oh!  Did
you make changes to the test code, or did the hanging occur in the
original code in:

http://mail.python.org/pipermail/tutor/2006-January/044567.html

I'm curious because nothing there should fundamentally block, assuming
that _doJob() doesn't dies badly with an exception.  If _doJob() dies, the
server dies, and that's bad.  *grin*

Do you mind showing what the exception handling looks like in your code?



 I then decided that it wasn't very nice of Starbucks to close after
 accepting my order without giving me my Latte, so I changed that part of
 the code to:

[code cut]

 I am 99.44% sure that this is thread safe, reasoning being:
setting the acceptNew to False and adding the QUIT_NOW happens in the 
 same
 thread so it is impossible for another job to get scheduled after the
 QUIT_NOW - so no thread will end up hanging...

Bad news: no.  *grin*

There's a race condition.  Let's go into some detail with this, since
this is not obvious stuff.

First, let's look at the code again --- I'll label three lines with (a),
(b), and (c), to make it a little easier to see the race.


###
def schedule(self,job):
if self.acceptNew == True:   ## (a)
outputQueue=Queue()
self.queue.put((job,outputQueue))
return Ticket(outputQueue)
else:
 print Server not accepting any new requests.
 return None

def scheduleShutdown(self):  ## (b)
self.queue.put((Server._QUIT_NICELY,None))

def _jobLoop(self):
while True:
print Looping ... 
(nextJob, outputQueue) = self.queue.get()
if nextJob is server._QUIT_NOW:
return
if nextJob is server._QUIT_NICELY:   ## (c)
self.acceptNew = False
self.queue.put((Server._QUIT_NOW,None))
else:
returnValue=self._doJob(nextJob)
outputQueue.put(returnValue)
##


Let's imagine three threads, which I'll name C1, C2, and S.  C1 and C2
will be distinct client threads, and S will be the server thread that runs
through _jobLoop().

Imagine the following scenario.  The server's online, and its work queue
is empty.

1.  C1 calls schedule(), and reaches the line labeled (a).  At this
point, server.acceptNew is True, so it goes into the body of the
if statement.  But wait...

2.  Now we context switch to C2.  C2 calls scheduleShutdown()
in its entirety.  There is now a _QUIT_NICELY element in the
queue.  C2 is done for.

3.  Now we context switch to the server thread S.  It grabs the
_QUIT_NICELY, and puts a _QUIT_NOW.  Let's imagine that S
continues and loops again.  In the next loop through _jobLoop(),
it sees _QUIT_NOW and exits.   S is done for.  Muhahaha.

4.  Now we context switch back to C1 and continue with:

outputQueue = Queue()
self.queue.put((job,outputQueue))
return Ticket(outputQueue)

In this scenario, poor C1 is left holding a ticket that will never cash
out.

One way to fix this problem is to make calling schedule() and
scheduleShutdown() atomic in this sense: if we're calling schedule(), we
shouldn't be able to context switch into a call to scheduleShutdown(), and
visa-versa.

Our troubles started at step 2 of the above scenario, where two clients
jostled for attention.  If we prevent that particular situation --- if we
force all our clients to stand in line to get served --- then we'll be
fine.  So we might look into some synchronizing tool, like a Lock object:

http://www.python.org/doc/lib/lock-objects.html

Concretely, we can add an exclusive Lock object to the server's __init__:

def __init__(self):
self.clientLock = Lock()

and make sure to acquire-and-release in any of our schedule* functions:

def schedule*(self, job):
self.clientLock.acquire()
try:
...
finally:
self.clientLock.release()



 However, I would sleep a little better if you could reassure me that I
 am right, and would sleep even better if you could give me a method to
 test this.

I'm sorry; I can't provide either.  That doesn't mean that such things
don't exist, but only that I don't know about them.  (The only formal
training I've received on this, so far, 

[Tutor] Searching for email id in MySQL giving wrong results

2006-01-22 Thread John Joseph
Hi  
   Thanks to Allan,Danny,Pujo 
   I did my simple python script  for  MySQL , the
scripts add the data , and search for the data and
display 
  I have problem in searching  email id  ,ie 
If search for the  [EMAIL PROTECTED] , I will not get any
result , Guidance and advice needed  for the reason
for this behavior
 I had added my script in this mail 
  Thanks 
 Joseph John 

*

 This program is for to learn 
how to enter data to MySQL using python
How to search 
not using OOP 

  Have  problem in searching email-id 
Why I do not get correct results when 
 searching email id 
   @ string search  containg @ gives empty
results


 


import MySQLdb

def selecter():
choice = None
while choice != 0:
print \

Data Base Entry for the  Testing Env
0   -   Quit
1   -   Enter the Data
2   -   Display The data
3   -   Search The Company 

choice = raw_input(Choice :)
print 

if choice == 0:
print Good Bye ...
elif choice == 1:
dataentry()

elif choice == 2:
datashow()
elif choice == 3:
datasearch()



def dataentry():
name = raw_input(Enter the name of the company )
email_id = raw_input(\n Enter the email ID : )
phone_no = raw_input(Enter the Phone No : )
fax_no  = raw_input(\n Enter the fax no : )

db = MySQLdb.connect(host=localhost,user = john,
passwd = asdlkj, db = 'learnpython')
entry = db.cursor()
#entry.execute(INSERT INTO contact
,(name,email_id,phone_no,fax_no,))
entry.execute(INSERT INTO
contact(name,email_id,phone_no,fax_no) VALUES
(%s,%s,%s,%s),(name,email_id,phone_no,fax_no,))
print  name , email_id , fax_no, phone_no




def datashow():
db = MySQLdb.connect(host=localhost,user = john,
passwd = asdlkj, db = 'learnpython')
entry = db.cursor()
entry.execute(SELECT * from contact)
p = entry.fetchall()
print p

def datasearch():
print Do U want to search by Name , email id , phone
or fax 
choice = None
while choice != 0:
print \

 U want to search the contacts by  
0   -   Quit
1   -   Name 
2   -   email_id
3   -   phone
4   -   fax 

choice = raw_input(Choice :)
print 

if choice == 0:
print Good Bye ...
elif choice == 1:
searchbyname()

elif choice == 2:
searchbyemail()

elif choice == 3:
searchbyphone()
elif choice == 4:
searchbyfax()

def searchbyname():
s_name = raw_input(Enter the name to be searched )
db = MySQLdb.connect(host=localhost,user = john,
passwd = asdlkj, db = 'learnpython')
entry = db.cursor()
entry.execute(SELECT * FROM contact WHERE name =
%s, (s_name,))
p = entry.fetchall()
print p

def searchbyemail():
s_email = raw_input(Enter the Email  to be searched
)
db = MySQLdb.connect(host=localhost,user = john,
passwd = asdlkj, db = 'learnpython')
entry = db.cursor()
entry.execute(SELECT * FROM contact WHERE email_id
= %s, (s_email,))
p = entry.fetchall()
print p


def searchbyphone():
s_phone= raw_input(Enter the Phone no   to be
searched )
db = MySQLdb.connect(host=localhost,user = john,
passwd = asdlkj, db = 'learnpython')
entry = db.cursor()
entry.execute(SELECT * FROM contact WHERE phone_no
 = %s, (s_phone,))
p = entry.fetchall()
print p



def searchbyfax():
s_fax = raw_input(Enter the FAX no  to be searched
)
db = MySQLdb.connect(host=localhost,user = john,
passwd = asdlkj, db = 'learnpython')
entry = db.cursor()
entry.execute(SELECT * FROM contact WHERE fax_no =
%s, (s_fax,))
p = entry.fetchall()
print p

selecter()





___ 
Yahoo! Photos – NEW, now offering a quality print service from just 8p a photo 
http://uk.photos.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starbucks does not use two-phase commit

2006-01-22 Thread Todd Maynard
Well Danny, now I know how I am gonna spend my Sunday

Thanks for the great explanation and the resources.   Of course do you think I 
could manage to get the code to break - of course not Usually I have the 
opposite problem.  Anyways I think that your explanation makes perfect sense.

My problem with your original code is that _jobLoop could sometimes return 
when there where still jobs (from separateCaller) still left in the queue.  
When separateCaller tried to ticket.claim , the self.result = self.q.get() 
would block, causing the program to hang indefinitely.  This is what I was 
trying to prevent by using the timeout in the get() call and then handling 
the possible Empty exception. 

I am now gonna play with this some more to see if I can build a robust/clean 
coffeeshop framework, with customers placing orders with a cashier , the 
cashier passing the orders to a barista and the barista processing the orders 
and delivering to the customers.  The idea of course being that the 
customers, cashier, and baristas each run in different threads.  Then to 
enhance with multiple cashiers and baristas

but first I need to put another pot of coffee on.

If you don't hear from me in a while, I've probably suffered a caffeine 
overdose.  


Thanks for the inspiration,

Todd Maynard


-- 
The tao that can be tar(1)ed
is not the entire Tao.
The path that can be specified 
is not the Full Path.

We declare the names
of all variables and functions.
Yet the Tao has no type specifier.

Dynamically binding, you realize the magic.
Statically binding, you see only the hierarchy.

Yet magic and hierarchy
arise from the same source,
and this source has a null pointer.

Reference the NULL within NULL,
it is the gateway to all wizardry.


On Sunday 22 January 2006 03:13, Danny Yoo wrote:
 On Sat, 21 Jan 2006, Todd Maynard wrote:
  I want to thank you for ruining my plans for a relaxing Saturday
  morning.  As a thread newbie I killed several hours playing around with
  your code.

 Hi Todd,

 Sorry about that.  I hope you were relaxing in a cafe while playing with
 the code.

  One thing I noticed is that sometimes the program would hang, which I
  figured was the Queue code blocking in the Ticket claim function. I used
  exception handling to deal with that situation cleanly.

 That's odd.  There shouldn't be anything that blocks the code.  Oh!  Did
 you make changes to the test code, or did the hanging occur in the
 original code in:

 http://mail.python.org/pipermail/tutor/2006-January/044567.html

 I'm curious because nothing there should fundamentally block, assuming
 that _doJob() doesn't dies badly with an exception.  If _doJob() dies, the
 server dies, and that's bad.  *grin*

 Do you mind showing what the exception handling looks like in your code?

  I then decided that it wasn't very nice of Starbucks to close after
  accepting my order without giving me my Latte, so I changed that part of
  the code to:

 [code cut]

  I am 99.44% sure that this is thread safe, reasoning being:
   setting the acceptNew to False and adding the QUIT_NOW happens in the
  same thread so it is impossible for another job to get scheduled after
  the QUIT_NOW - so no thread will end up hanging...

 Bad news: no.  *grin*

 There's a race condition.  Let's go into some detail with this, since
 this is not obvious stuff.

 First, let's look at the code again --- I'll label three lines with (a),
 (b), and (c), to make it a little easier to see the race.


 ###
 def schedule(self,job):
 if self.acceptNew == True:   ## (a)
 outputQueue=Queue()
 self.queue.put((job,outputQueue))
 return Ticket(outputQueue)
 else:
  print Server not accepting any new requests.
  return None

 def scheduleShutdown(self):  ## (b)
 self.queue.put((Server._QUIT_NICELY,None))

 def _jobLoop(self):
 while True:
 print Looping ... 
 (nextJob, outputQueue) = self.queue.get()
 if nextJob is server._QUIT_NOW:
 return
 if nextJob is server._QUIT_NICELY:   ## (c)
 self.acceptNew = False
 self.queue.put((Server._QUIT_NOW,None))
 else:
 returnValue=self._doJob(nextJob)
 outputQueue.put(returnValue)
 ##


 Let's imagine three threads, which I'll name C1, C2, and S.  C1 and C2
 will be distinct client threads, and S will be the server thread that runs
 through _jobLoop().

 Imagine the following scenario.  The server's online, and its work queue
 is empty.

 1.  C1 calls schedule(), and reaches the line labeled (a).  At this
 point, server.acceptNew is True, so it goes into the body of the
 if statement.  But wait...

 2.  Now we context switch to C2.  C2 calls scheduleShutdown()
 in its 

[Tutor] webcam secrets?

2006-01-22 Thread johnny` walker
i was wondering if there was a way to automatically take a picture from my webcam every oh say 5 minutes?is there anyway of doing this (im very new to programming languages.)___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [webbrowser] some help on an error running mozilla firefox

2006-01-22 Thread Rinzwind
Why does this:  import webbrowser  webbrowser.open('http://www.google.com)give me this: run-mozilla.sh: Cannot execute /opt/firefox/mozilla-firefox-bin.
Is this bacause 'webbrowser' does not know about the identification of 1.5?(I do not want to do it like this:  import os  os.system ('firefox 
http://www.google.com')bacause not all of us use firefox :) )Oh and can I, when I open a new browserwindow, force it to open in the same workspace as I am with my pythonprogram and not inside another workspace where I have a browser window open?
Any enlightment would be appreciated :-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] webcam secrets?

2006-01-22 Thread Rinzwind
That (mosttimes) is a setting in your webcamsoftware and doesn't require coding.WimOn 1/22/06, johnny` walker 
[EMAIL PROTECTED] wrote:i was wondering if there was a way to automatically take a picture from my webcam every oh say 5 minutes?
is there anyway of doing this (im very new to programming languages.)
___Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Totorial announcement

2006-01-22 Thread Alan Gauld
I've just uploaded the completed tutoroial topic on OS access.

It covers most of the common questions asked on this list about determining
file access, launching programs (including use of the new subprocess 
module),
accessing environment variables etc. It also has a short intro to bitmask 
manipulation
and bitwise operators.

I've also updated the zip, tgz and pdf files too.

For those interested in printing out the PDF (someone asked me recently) it
currently runs to 342 pages of A4 but the margins are set so it should
work fine on US Letter paper too.

Enjoy,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] Searching for email id in MySQL giving wrong results

2006-01-22 Thread ZIYAD A. M. AL-BATLY
On Sun, 2006-01-22 at 12:43 +, John Joseph wrote:
 Hi  
Hi John...

Most of your problems in your code seems to be caused by a single
mistake.  Compare the following two strings and you should figure out
what's wrong by yourself:

email_id = '[EMAIL PROTECTED]'

wrong_string = '''SELECT s FROM t WHERE id=%s''' , (email_id)
right_string = '''SELECT s FROM t WHERE id=%s''' % (email_id)

print Wrong:, wrong_string
print Right:, right_string

This is the output:
Wrong: ('SELECT s FROM t WHERE id=%s', '[EMAIL PROTECTED]')
Right: SELECT s FROM t WHERE [EMAIL PROTECTED]

Now, which one is the right one?  And which one is the one you want?


I suggest you study strings more, especially concatenation and '%'.

If you need more help, just post to the mailing list again.
Ziyad.

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


Re: [Tutor] Totorial announcement

2006-01-22 Thread Rinzwind
Excellent guide. I bookmarked it :-) because I plan to use it alot.Oh, how much work (in hours) did it take it to translate your website? WimOn 1/22/06, 
Alan Gauld [EMAIL PROTECTED] wrote:
I've just uploaded the completed tutoroial topic on OS access.It covers most of the common questions asked on this list about determiningfile access, launching programs (including use of the new subprocess
module),accessing environment variables etc. It also has a short intro to bitmaskmanipulationand bitwise operators.I've also updated the zip, tgz and pdf files too.For those interested in printing out the PDF (someone asked me recently) it
currently runs to 342 pages of A4 but the margins are set so it shouldwork fine on US Letter paper too.Enjoy,Alan GAuthor of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld___Tutor maillist-Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Framework recommendations for e-commerce

2006-01-22 Thread Kenneth Kalmer
Greetings list

This is my first post to the list, please excuse me if I mess up...

OK, I'm new to Python, but not new to programming. I have years of PHP
behind me, and some C#  Java (to name the bigger names)...

I'm asking this question here because I'm new, and it must have been
discussed excessively in the python-list by now.

I'm looking for suggestions on a framework for building an e-commerce
solution. Must be relatively painless to extend with new features but
provide a good strong base. The learning curve mustn't be too steep
either :)

I've seen with PHP  Java that there is no single great framework. I'm
looking for the best mix of powerful and fast time to market,
considering I'm a newbie...

So far Zope looks great, and sticking Plone on top seems like a great
idea. I can then only extend Plone and a lot of basics will be covered
for me...

Will I be shooting myself in the foot?

Best

--

Kenneth Kalmer
[EMAIL PROTECTED]

[EMAIL PROTECTED] stats
http://fah-web.stanford.edu/cgi-bin/main.py?qtype=userpageusername=kenneth%2Ekalmer
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] webcam secrets?

2006-01-22 Thread Hugo González Monteverde
Hi Johnny,

As someone already said, it could be possible to do that without going 
into any code, but assuming you want to do it by means of Python...

I assume you're using Windows, are you trying to control another 
application (the one that came with your webcam)? are you trying to 
write a program that accesses the driver for your webcam?

In any case, whatever you're trying to accomplish will have a lot to do 
with what the operating system allows you. May I suggest you take 
another program or exercise more related to programming before you 
become complicated with so mucho weird operating system interfaces?

I suppose webcams are accessed through the TWAIN infterface. There is 
(old) support for python, here:

http://twainmodule.sourceforge.net/docs/

Hugo

johnny` walker wrote:
 i was wondering if there was a way to automatically take a picture from 
 my webcam every oh say 5 minutes?
  
 is there anyway of doing this (im very new to programming languages.)
 
 
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] I'm puzzled

2006-01-22 Thread Vincent Zee
Hi all,

I'm puzzled (:-))

Why will this little program crash when you enter the
enter key?

while True:
a = raw_input('number? ')
if a.isdigit():
print 'isdigit'
elif a[0] == '-' and a[1:].isdigit():
print '- + isdigit'
elif a == 'q':
break
else:
print 'no digit'

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


Re: [Tutor] I'm puzzled

2006-01-22 Thread Danny Yoo

 Why will this little program crash when you enter the enter key?

[program cut]

Hi Vincent,

What do you mean by crash?  Do you get an error message?  If so, can you
show us?


It will also help to think to try playing the situation out without
preconceptions.  In the beginning of the loop, at:

 a = raw_input('number? ')

what does 'a' contain when you hit enter?


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


Re: [Tutor] I'm puzzled

2006-01-22 Thread Shuying Wang
I'm guessing when you did that, you got something like an IndexError.
That's because you didn't check the length of a from raw_input and
accessed a nonexistent array element (a string is an array of
characters). So if you changed the line:
elif a[0] == '-' and a[1:].isdigit():
to :
elif len(a)  1 and a[0] == '-' and a[1:].isdigit():

I expect you'll get what you want.

--Shuying

On 1/23/06, Vincent Zee [EMAIL PROTECTED] wrote:
 Hi all,

 I'm puzzled (:-))

 Why will this little program crash when you enter the
 enter key?

 while True:
 a = raw_input('number? ')
 if a.isdigit():
 print 'isdigit'
 elif a[0] == '-' and a[1:].isdigit():
 print '- + isdigit'
 elif a == 'q':
 break
 else:
 print 'no digit'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I'm puzzled

2006-01-22 Thread bob
At 03:46 PM 1/22/2006, Vincent Zee wrote:
Why will this little program crash when you enter the enter key?

Thank you for including the traceback message in your 2nd post.

Index error means you tried to reference an element of a sequence 
that is not there. a is the empty string when you just hit enter to 
the raw_input request. It therefore has no elements, so a[0] raises 
the exception.

To avoid this test first for len(a)  0.

while True:
 a = raw_input('number? ')
 if a.isdigit():
 print 'isdigit'
 elif a[0] == '-' and a[1:].isdigit():
 print '- + isdigit'
 elif a == 'q':
 break
 else:
 print 'no digit'

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


Re: [Tutor] I'm puzzled

2006-01-22 Thread Hugo González Monteverde
Hi Vincent,

 the program works with any input except when you just hit the enter key.


To be  able to understand why is the crash, take a look at what the 
interpreter tells you:

   File untitled.py, line 12, in ?
 elif a[0] == '-' and a[1:].isdigit():
  IndexError: string index out of range

IndexError is raised whan you try to access an element in a list or 
string, an element that does not exist. In the case where you only press 
enter, what is the content of a How many characters? (hint, you may 
try to

print a

before any evaluation...

Hope that gets you going,

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


Re: [Tutor] python-based system programming and admin?

2006-01-22 Thread Hugo González Monteverde
MMM strange needs...

I'm thinking that perhaps allowing him to run idle and exporting X 
display to the Mac could be an option?

I used to do perl on linux until I found Python, I find it very easy to 
run quick scripts and system stuff without having to learn BASH, sed, 
awk, etc separately, taht way I can do regexp, listings, recursion on 
directories, batch jobs, etc.

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


Re: [Tutor] I'm puzzled

2006-01-22 Thread Vincent Zee
On Sunday, 22 January 2006 at 18:11:09 -0600, Hugo González Monteverde wrote:
 Hi Vincent,
 
  the program works with any input except when you just hit the enter key.
 
 
 To be  able to understand why is the crash, take a look at what the 
 interpreter tells you:
 
File untitled.py, line 12, in ?
  elif a[0] == '-' and a[1:].isdigit():
   IndexError: string index out of range
 
 IndexError is raised whan you try to access an element in a list or 
 string, an element that does not exist. In the case where you only press 
 enter, what is the content of a How many characters? (hint, you may 
 try to
 
Hi Hugo,

thank you for your reply.
What confused me was the fact that the isdigit method didn't complain
about the empty string, so I assumed that indexing an empty string
wouldn't be a problem (:-))

But now I think of it that wouldn't be logical.
Sometimes the 'intelligence' of python makes me lazy (;-))

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


Re: [Tutor] I'm puzzled

2006-01-22 Thread Vincent Zee
On Monday, 23 January 2006 at 10:59:24 +1100, Shuying Wang wrote:
 I'm guessing when you did that, you got something like an IndexError.
 That's because you didn't check the length of a from raw_input and
 accessed a nonexistent array element (a string is an array of
 characters). So if you changed the line:
 elif a[0] == '-' and a[1:].isdigit():
 to :
 elif len(a)  1 and a[0] == '-' and a[1:].isdigit():
 
 I expect you'll get what you want.
 

Hi Shuying,

thank you for your solution.

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


Re: [Tutor] python-based system programming and admin?

2006-01-22 Thread Neal McBurnett
On Sun, Jan 22, 2006 at 06:19:55PM -0600, Hugo González Monteverde wrote:
 I used to do perl on linux until I found Python, I find it very easy to 
 run quick scripts and system stuff without having to learn BASH, sed, 
 awk, etc separately, taht way I can do regexp, listings, recursion on 
 directories, batch jobs, etc.
 
My question is exactly how to let someone do that securely on a remote
machine.  I've looked at ipython now, and I think it is ideal for the
purpose - I just have to tell the user to ssh in and run 'ipython' to
get a familiar and flexible environment.

 I'm thinking that perhaps allowing him to run idle and exporting X 
 display to the Mac could be an option?

The system is a server - doesn't even need X libraries, which are a
significant source of security concerns.

Thanks,

Neal McBurnett http://bcn.boulder.co.us/~neal/
Signed and/or sealed mail encouraged.  GPG/PGP Keyid: 2C9EBA60
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Totorial announcement

2006-01-22 Thread Alan Gauld

 Excellent guide. I bookmarked it :-) because I plan to use it alot.

Glad you like it, as you'll see I have a few more topics planned yet 
but each topic takes from 3-12 weeks to write...

 Oh, how much work (in hours) did it take it to translate your website?

To translate, I don't know, some translators seem to  get through 
the whole thing in a few months, others take a year or more.
I've been working on the English version since 1998 and the 
rewrite to Python 2.3 took over 6 months. Working about 
5-10 hours per week I guess.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


[Tutor] processing a text file w/ OO?

2006-01-22 Thread Michael
Hi.

I'm processing a tab-delimited text file where I read in a file,  
perform a bunch of operations on the items, and then write them out  
again to a fixed-width text file.

I've been doing this with a very functional approach:

- loop over lines
- read line into dictionary
- process dictionary values ( format phone numbers and dates and  
amounts, etc.)
- pad dictionary values with spaces
- write dictionary values out to file

Anyway, this all works fine. Not knowing much about OO, I'm wondering  
if there's a way to approach this from an object-oriented  
perspective. Is there anything to be gained? Or is this type of  
problem best tackled with a functional approach?

TIA.

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


Re: [Tutor] processing a text file w/ OO?

2006-01-22 Thread Pujo Aji
you can use regex if you want.It gives you power to do text processing.OO will give you benefit because your program becomes clearer while it is developedCheers,pujo
On 1/23/06, Michael [EMAIL PROTECTED] wrote:
Hi.I'm processing a tab-delimited text file where I read in a file,perform a bunch of operations on the items, and then write them outagain to a fixed-width text file.I've been doing this with a very functional approach:
- loop over lines- read line into dictionary- process dictionary values ( format phone numbers and dates andamounts, etc.)- pad dictionary values with spaces- write dictionary values out to file
Anyway, this all works fine. Not knowing much about OO, I'm wonderingif there's a way to approach this from an object-orientedperspective. Is there anything to be gained? Or is this type ofproblem best tackled with a functional approach?
TIA.___Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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