Re: [Tutor] question about looping.

2006-10-09 Thread Hugo González Monteverde
Doug Potter wrote:

 for i in routers:
 os.system('/bin/touch' %s) % i
 
 of course this dosn't work.
 
 Is there a simple way to get this done?

Yep, someone already answered that you can create the file in write mode 
and then close it, but I wanted to add a little more in why your 
solution doesn't work.

You're not interpolating the filename INTO the os.system string


The following would work

  for i in routers:
  os.system('/bin/touch %s'%1)

Granted, you should also provide a filename with a full path for simplicity.

HTH

Hugo

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


Re: [Tutor] embedding python

2006-10-09 Thread Alan Gauld
 know a little html not much i can make a page with backround coler a 
 title
 words and pictures as well as links

 but i cant find any tutorials on embedding python useing html i 
 found some
 that use c++ and i think one that used asp

Can you give an example of what you mean by *embedding* Python
using html? You can represent python code inside HTML easily enough.
You can insert Python code into your HTML as script, but it will only
work if the readers browser supports it - only IE at present.
Or you can do server side python code if the server supports it.

What exactly do you have in mind? What were you aiming to achieve?

Alan G 


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


Re: [Tutor] Help me with two dimensional arrays in Python

2006-10-09 Thread János Juhász
Dear Asrarahmed,

I have found the next recipe in the cookbook.
It should be interesting for you :)

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/392153

 Message: 1
 Date: Thu, 05 Oct 2006 10:26:19 -0400
 From: Kent Johnson [EMAIL PROTECTED]
 Subject: Re: [Tutor] Help me with two dimensional arrays in Python
 Cc: tutor@python.org
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed

 Asrarahmed Kadri wrote:
  Its something very close.
  What I want is:
 
  1
  1 1
  1 2 1
  1 3 3 1
  1 4 6 4 1



Yours sincerely, 
__
János Juhász 

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


Re: [Tutor] python RMI

2006-10-09 Thread Picio
Hello,
I was out for the week-end, sorry If I'm so late answering, and sorry
because I wrote my message In italian. Since I have a subscription to
another python mailing-list in italian, I've confused the tutor list
with that.
Thanks, I'm impressed, you were so kind triyng to help me!!

I read the all articles at
http://www.daimi.au.dk/~mailund/scripting2005/lecture-notes/rmi.html
thanks, now I got a very good Idea about RMI and also, web services.

Ps.: Ivan grazie di cuore dell'intervento!

Daniele

2006/10/7, Ivan Furone [EMAIL PROTECTED]:


 Il 07/10/06, Alan Gauld [EMAIL PROTECTED] ha scritto:
 
  PS. Any Italian speakers on the list who can cover this?


 I think I can as far it's possible,Alan! :-)


  Picio [EMAIL PROTECTED] wrote in message
 
 news:[EMAIL PROTECTED]
  Salve,
  dovrei usare python per due progettini universitari, su RMI e l'altro
  sui Web Services.
  Ho notato che esiste PyRO, preferirei però sentire voi sull'argomento:
 
  cosa uso per l'RMI (esiste qualche libreria,modulo)
  cosa uso per i Web Services


 Ciao,
  Per quanto riguarda l'RMI vale la pena di dare un'occhiata a
 quest'esempio,anche se in inglese in quanto il codice e'di per se abbastanza
 comprensibile:

 http://www.daimi.au.dk/~mailund/scripting2005/lecture-notes/rmi.html

 Per quanto riguarda i web services,e'impossibile darti una risposta precisa
 senza poter conoscere i servizi che devi (o dovresti) utilizzare; prova a
 girare nella standard library,magari a guardare XML-RPC come altri ti hanno
 gia'detto;comunque,se cerchi qualcosa di piu'dedicato usa Twisted che
 e'sicuramente l'eccellenza nel campo della programmazione di rete in Python
 per completezza e maturita'del codice.
 Mentre per eventuali ritocchi e implementazione di particolari
 funzionalita'di basso livello esiste dpkt..

 Fai la tua scelta,spero di essere stato esaustivo.
  __


 ___
 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] a Apache-python-postgres kit

2006-10-09 Thread Picio
Hello,
last week I configured three home made servers to host a little python
web app (django based).
Searching on the web about a kit/script to have
Apache+PostgreSQL+Python, I found only Apache2triad. That is a littlel
overweight for me because I got also:

PHP
Perl
Mysql
Slimftpd
Xmail
OpenSSL

and some other staff I really don't need.
Do you know a kit like WAMP or LAMP, that install one of the following
configurations?

1-Apache+Posgtres+Python
2-Lighttpd+Posgtgres+Python

Do you know some docs to help me create myself the kit?
(Something like How to make your own 'wamp' server)

Thanks for any answer
Daniele
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Point in polygon intro please~!

2006-10-09 Thread János Juhász
Hi Michael,


 Subject: Re: [Tutor] Point in polygon intro please~!
 To: Michael Shulman [EMAIL PROTECTED]
 Cc: tutor@python.org
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed

 Michael Shulman wrote:
  Hello, I'm very new to both python and OpenGL, but I'm catching on
  pretty quick,
  and trying to make a little game.  I'm stuck on being able to do this
  point-in-polygon test though.
  Everyone seems to say that I should create a ray and see how many 
sides
  of a polygon it intersects, (even vs odd)
  but I have no idea how to go about setting this up.


If you would like to get the 3D object, that belongs to the given pixel, 
OpenGL gives a simpler way for it with glRenderMode(GL_SELECT);

Converting the 3D objects to poligons, seems to be too difficult,
and not needed.


Take a look after the GL_SELECT mode

http://www.google.hu/search?hl=huq=glRenderMode%28GL_SELECT%29meta=



Yours sincerely, 
__
János Juhász 

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


[Tutor] Handling large arrays/lists

2006-10-09 Thread Duncan Gibson


One part of the application I'm dealing with handles a conceptual
'cube' of data, but is in fact implemented as a single python
list. Items are stored and retrieved - no manipulation at the
moment - by the classical approach of multiplying the appropriate
x, y and z indices with the x, y and z extents to give the unique
index into the single list.

However, now that requirements have moved to include much larger
cubes of data than originally envisaged, this single list has
just become far too slow.

Unfortunately the single list concept is currently a requirement
in the tool, but how it is implemented is open to discussion.

I've been mulling over the documentation for Numeric/numpy to
see whether it makes sense to replace the single standard Python
list with an array or multiarray. The first thing to strike me
is that, in Numeric, the size of an array is fixed. To grow the
'cube' as each x,y slice is added, I can create a new array in
one of three ways, but as far as I can see, each will require
copying all of the data from the old to the new array, so I'm
concerned that any speed benefit gained from replacing a standard
list will be lost to repeated copying.

Have I correctly understood the Numeric array handling?
Does anyone have any suggestions for a more efficient way of
handling a large list of data? Other modules perhaps?

And yes, I know that Numeric has been replaced by numpy, but I
understand that they are very similar, and it's been easier to
find tutorial documentation for Numeric than for numpy.

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


[Tutor] tkinter

2006-10-09 Thread Abdullah Anar
hello,We try to build new software using python and tkinter. We would like to enter some fields using grid style. I mean we want to use rows to see old entries and to enter new one. I hope I could explain, because it also is not easy. I know there is grid to locate buttons, labels and something like these. I hope I could explain I did not mean this grid which is using instead of pack.
we wonder if there is already some classes or widgets to do this.thanks for help from nowAbdullah Anar
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] re-reading file-like objects

2006-10-09 Thread Tiago Saboga
Hi!

I have a problem with file-like objects for months now, and I hoped I could 
cope with it, but I keep using what seems to me like a newbie workaround...

The question is: how can I read a file (more precisely, a file-like object) 
more than one single time? 

In the following example, I want to generate a file in memory and save it with 
ten different names. But I can't do it with shutil.copyfileobj, AFAICS 
because it reads the file with read() method, which can only be used once. If 
it's a real file, on disk, I agree it would not be a clever strategy, reading 
it once for each copy, and I would be happy keeping its content in a 
variable. But if the file is in memory, why can't I simply read it again (or 
better, how can I...)?

successful==
import subprocess

FILESIZE = 20
NUMBER = 10
DIR = '/tmp/pytest'
FILENAME = 'treco.x'

basefilecontents = 
subprocess.Popen(['dd', 'if=/dev/zero', 'count=1', 'bs=%s' % FILESIZE], 
stdout=subprocess.PIPE, bufsize=FILESIZE).stdout.read()

for i in range(NUMBER):
print File number %s % i
newfile = open('%s/%s%s' % (DIR, FILENAME, i), 'w')
newfile.write(basefilecontents)
newfile.close()

=unsuccessful==

import subprocess, shutil

FILESIZE = 20
NUMBER = 10
DIR = '/tmp/pytest'
FILENAME = 'treco.x'

basefile = subprocess.Popen(['dd', 'if=/dev/zero', 'count=1', 'bs=%s' % 
FILESIZE], stdout=subprocess.PIPE, bufsize=FILESIZE).stdout

for i in range(NUMBER):
print File number %s % i
newfile = open('%s/%s%s' % (DIR, FILENAME, i), 'w')
shutil.copyfileobj(basefile, newfile)
newfile.close()

=
The program runs fine, but only the first file has the appropriate content. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] re-reading file-like objects (SOLVED?)

2006-10-09 Thread Tiago Saboga
I keep the original question:

Em Segunda 09 Outubro 2006 09:21, Tiago Saboga escreveu:
 Hi!

 I have a problem with file-like objects for months now, and I hoped I could
 cope with it, but I keep using what seems to me like a newbie workaround...

 The question is: how can I read a file (more precisely, a file-like object)
 more than one single time?

 In the following example, I want to generate a file in memory and save it
 with ten different names. But I can't do it with shutil.copyfileobj, AFAICS
 because it reads the file with read() method, which can only be used once.
 If it's a real file, on disk, I agree it would not be a clever strategy,
 reading it once for each copy, and I would be happy keeping its content in
 a variable. But if the file is in memory, why can't I simply read it again
 (or better, how can I...)

But I strip the code, and post a new one. The solution I found is in the 
seek() method of the file object. And the problem I had is that not all the 
file-like objects have a functional seek() method. It's not the case for the 
object referenced by the stdout attribute of the subprocess.Popen class. So I 
have to copy it in a (seekable) temporary file. As I have already bothered 
you with my question, let's try to make it still useful: is it the right  
(or pythonic) way to do this?

Thanks,

Tiago.

solution
import subprocess, shutil, tempfile

FILESIZE = 20
NUMBER = 10
DIR = '/tmp/pytest'
FILENAME = 'treco.x'

cmd = ['dd', 'if=/dev/zero', 'count=1', 'bs=%s' % FILESIZE]
tempbasefile = tempfile.TemporaryFile()

basefile = subprocess.Popen(
cmd, 
stdout=subprocess.PIPE, 
bufsize=FILESIZE
   ).stdout

shutil.copyfileobj(basefile, tempbasefile)

for i in range(NUMBER):
tempbasefile.seek(0)
print File number %s % i
newfile = open('%s/%s%s' % (DIR, FILENAME, i), 'w')
shutil.copyfileobj(tempbasefile, newfile)
newfile.close()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tkinter

2006-10-09 Thread Alan Gauld
 We try to build new software using python and tkinter. We would like 
 to
 enter some fields using grid style.

Based on the fact that you say:

 these. I hope I could explain I did not mean this grid which is 
 using
 instead of pack.

I assume you mean like a spreadsheet grid of cells?

 we wonder if there is already some classes or widgets to do this.

I'm not aware of such a control but its quite likely someone has
built one. Try asking on the Tkinter mailing list, they are more
likely to know.

Sorry I can't help further,

Alan G. 


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


Re: [Tutor] revisiting struct and bytes again.

2006-10-09 Thread Hugo González Monteverde

 i can make a byte a string or number or whatever now. Up to the number 255.
 I now have a problem with something that comes in as a 4 byte 
 representation of
 the number of seconds since 1970.

Hi Shawn,

That's an epoch time as used in UNIX. Are you sure that what you're 
trying to do cannot be done with the Python time module?

What is it exactly that you're trying to do?

Hugo

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


Re: [Tutor] re-reading file-like objects

2006-10-09 Thread Kent Johnson
Tiago Saboga wrote:
 Hi!
 
 I have a problem with file-like objects for months now, and I hoped I could 
 cope with it, but I keep using what seems to me like a newbie workaround...
 
 The question is: how can I read a file (more precisely, a file-like object) 
 more than one single time? 
 
 In the following example, I want to generate a file in memory and save it 
 with 
 ten different names. But I can't do it with shutil.copyfileobj, AFAICS 
 because it reads the file with read() method, which can only be used once. If 
 it's a real file, on disk, I agree it would not be a clever strategy, reading 
 it once for each copy, and I would be happy keeping its content in a 
 variable. But if the file is in memory, why can't I simply read it again (or 
 better, how can I...)?
 
 successful==
 import subprocess
 
 FILESIZE = 20
 NUMBER = 10
 DIR = '/tmp/pytest'
 FILENAME = 'treco.x'
 
 basefilecontents = 
 subprocess.Popen(['dd', 'if=/dev/zero', 'count=1', 'bs=%s' % FILESIZE], 
 stdout=subprocess.PIPE, bufsize=FILESIZE).stdout.read()
 
 for i in range(NUMBER):
   print File number %s % i
   newfile = open('%s/%s%s' % (DIR, FILENAME, i), 'w')
   newfile.write(basefilecontents)
   newfile.close()

Your input file isn't 'in memory', it is the output of a subprocess. To
read the input again, the subprocess would have to create the output again.

This solution seems fine to me - you read the input file *contents* into 
memory, then write it to multiple files. Why don't you like this approach?

Kent

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


Re: [Tutor] re-reading file-like objects (SOLVED?)

2006-10-09 Thread Kent Johnson
Tiago Saboga wrote:
 But I strip the code, and post a new one. The solution I found is in the 
 seek() method of the file object. And the problem I had is that not all the 
 file-like objects have a functional seek() method. It's not the case for the 
 object referenced by the stdout attribute of the subprocess.Popen class. So I 
 have to copy it in a (seekable) temporary file. As I have already bothered 
 you with my question, let's try to make it still useful: is it the right  
 (or pythonic) way to do this?
 
 Thanks,
 
 Tiago.
 
 solution
 import subprocess, shutil, tempfile
 
 FILESIZE = 20
 NUMBER = 10
 DIR = '/tmp/pytest'
 FILENAME = 'treco.x'
 
 cmd = ['dd', 'if=/dev/zero', 'count=1', 'bs=%s' % FILESIZE]
 tempbasefile = tempfile.TemporaryFile()
 
 basefile = subprocess.Popen(
 cmd, 
 stdout=subprocess.PIPE, 
 bufsize=FILESIZE
).stdout
 
 shutil.copyfileobj(basefile, tempbasefile)
 
 for i in range(NUMBER):
   tempbasefile.seek(0)
   print File number %s % i
   newfile = open('%s/%s%s' % (DIR, FILENAME, i), 'w')
   shutil.copyfileobj(tempbasefile, newfile)
   newfile.close()

This is similar to your first successful solution in a way - you are 
reading the contents of the input file and storing them in a temporary 
location. In the first version you stored the contents in memory; in 
this one you store the contents in a temp file. Unless the data is too 
large to fit in memory I think the first program is preferable, it is 
simpler and will likely be faster.

Kent

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


Re: [Tutor] re-reading file-like objects

2006-10-09 Thread Alan Gauld
 because it reads the file with read() method, which can only be used 
 once. If
 it's a real file, on disk, I agree it would not be a clever 
 strategy, reading
 it once for each copy, and I would be happy keeping its content in a
 variable. But if the file is in memory, why can't I simply read it 
 again (or
 better, how can I...)?

Not all file like objects support the seek() call, often for good
reasons - they are streams for example.

However it sounds like you could use a StringIO buffer object for
what you want and you can reuse that as often as you like.

Look here for more info:

http://docs.python.org/lib/module-StringIO.html

HTH

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




 successful==
 import subprocess

 FILESIZE = 20
 NUMBER = 10
 DIR = '/tmp/pytest'
 FILENAME = 'treco.x'

 basefilecontents =
 subprocess.Popen(['dd', 'if=/dev/zero', 'count=1', 'bs=%s' % 
 FILESIZE],
 stdout=subprocess.PIPE, bufsize=FILESIZE).stdout.read()

 for i in range(NUMBER):
 print File number %s % i
 newfile = open('%s/%s%s' % (DIR, FILENAME, i), 'w')
 newfile.write(basefilecontents)
 newfile.close()

 =unsuccessful==

 import subprocess, shutil

 FILESIZE = 20
 NUMBER = 10
 DIR = '/tmp/pytest'
 FILENAME = 'treco.x'

 basefile = subprocess.Popen(['dd', 'if=/dev/zero', 'count=1', 
 'bs=%s' %
 FILESIZE], stdout=subprocess.PIPE, bufsize=FILESIZE).stdout

 for i in range(NUMBER):
 print File number %s % i
 newfile = open('%s/%s%s' % (DIR, FILENAME, i), 'w')
 shutil.copyfileobj(basefile, newfile)
 newfile.close()

 =
 The program runs fine, but only the first file has the appropriate 
 content.
 ___
 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] What after Learning Python 2nd

2006-10-09 Thread josip
Hi.Hi I have finished Learning Python 2nd ed.  What to do next?   Should I go with Programming Python book or Python Cookbook or?  Or maybe something else?Thanks people!   
		Do you Yahoo!? 
Get on board. You're invited to try the new Yahoo! Mail.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] re-reading file-like objects

2006-10-09 Thread Tiago Saboga
Em Segunda 09 Outubro 2006 10:41, Kent Johnson escreveu:
 Tiago Saboga wrote:
  Hi!
 
  I have a problem with file-like objects for months now, and I hoped I
  could cope with it, but I keep using what seems to me like a newbie
  workaround...
 
  The question is: how can I read a file (more precisely, a file-like
  object) more than one single time?
 
  In the following example, I want to generate a file in memory and save it
  with ten different names. But I can't do it with shutil.copyfileobj,
  AFAICS because it reads the file with read() method, which can only be
  used once. If it's a real file, on disk, I agree it would not be a clever
  strategy, reading it once for each copy, and I would be happy keeping its
  content in a variable. But if the file is in memory, why can't I simply
  read it again (or better, how can I...)?
 
  successful==
  import subprocess
 
  FILESIZE = 20
  NUMBER = 10
  DIR = '/tmp/pytest'
  FILENAME = 'treco.x'
 
  basefilecontents =
  subprocess.Popen(['dd', 'if=/dev/zero', 'count=1', 'bs=%s' % FILESIZE],
  stdout=subprocess.PIPE, bufsize=FILESIZE).stdout.read()
 
  for i in range(NUMBER):
  print File number %s % i
  newfile = open('%s/%s%s' % (DIR, FILENAME, i), 'w')
  newfile.write(basefilecontents)
  newfile.close()

 Your input file isn't 'in memory', it is the output of a subprocess. To
 read the input again, the subprocess would have to create the output again.

 This solution seems fine to me - you read the input file *contents* into
 memory, then write it to multiple files. Why don't you like this approach?

I'm afraid I don't fully understand file objects. I thought I could use it 
just as a file: if I have one, and I want several copies, I just save it with 
several names. So, if Popen.stdout already is a file object, I thought the 
easier way would be to save it with another name. I see that it is more 
complicated.
For this simple example, this solution is fine, and I think the solution 
proposed by Alan (StringIO) is not going to add anything. Would it be faster?

Thanks,

Tiago.
 Kent

 ___
 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] What after Learning Python 2nd

2006-10-09 Thread Rob Andrews
Those are both fine next book choices, and neither should prove a
disapointment.

However, LP should've left you with just enough knowledge to be
dangerous, so I'd encourage you to work on several small projects in
python using what you already know. In the process of taking a crack
at those, you'll surely want to do some things that will give you a
good idea of what resources you need to tackle next.

-Rob A.

On 10/9/06, josip [EMAIL PROTECTED] wrote:
 Hi.

 Hi I have finished Learning Python 2nd ed.
 What to do next?
 Should I go with Programming Python book or Python Cookbook or?
 Or maybe something else?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Variable help

2006-10-09 Thread Tiago Saboga
Hi!

I think your problem was solved, and that the list of lists is the better 
approach indeed. But I'd like to add an answer to a direct question you 
asked:

Em Domingo 08 Outubro 2006 07:47, Tom R. escreveu:
 Basically I want to be able to integrate the value of one variable into
 another variables name. 

I think you would like to do something like: 

=
#!/usr/bin/env python
# use of __get_attribute__() function
class players(object):
player1 = [2,4,8]
player2 = [3,9,27]
player3 = [4,16,64]

count = 2
pl = players()
actual_player_string = player%s % count

if pl.__getattribute__(actual_player_string)[2]==9:
print 'It worked.'
===

I don't know how to do that if player{1,2,3} are not in a class, or if the 
class is not instanciated. But somebody else can possibly show a way. 

Anyway, as I said, I think you don't need it right now.

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


Re: [Tutor] Variable help

2006-10-09 Thread Kent Johnson
Tiago Saboga wrote:
 Hi!
 
 I think your problem was solved, and that the list of lists is the better 
 approach indeed. But I'd like to add an answer to a direct question you 
 asked:
 
 Em Domingo 08 Outubro 2006 07:47, Tom R. escreveu:
 Basically I want to be able to integrate the value of one variable into
 another variables name. 
 
 I think you would like to do something like: 
 
 =
 #!/usr/bin/env python
 # use of __get_attribute__() function
 class players(object):
   player1 = [2,4,8]
   player2 = [3,9,27]
   player3 = [4,16,64]
 
 count = 2
 pl = players()
 actual_player_string = player%s % count
 
 if pl.__getattribute__(actual_player_string)[2]==9:
   print 'It worked.'

Better to use the built-in getattr() function:
geattr(pl, actual_player_string)

 ===
 
 I don't know how to do that if player{1,2,3} are not in a class, or if the 
 class is not instanciated. But somebody else can possibly show a way. 

There are ways to do it but really it's better not to.

Kent

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


Re: [Tutor] What after Learning Python 2nd

2006-10-09 Thread wesley chun
  Hi I have finished Learning Python 2nd ed.
  What to do next?
  Should I go with Programming Python book or Python Cookbook or?
  Or maybe something else?

 However, LP should've left you with just enough knowledge to be
 dangerous, so I'd encourage you to work on several small projects in
 python using what you already know. In the process of taking a crack
 at those, you'll surely want to do some things that will give you a
 good idea of what resources you need to tackle next.


hi josip,

rob is right.  you should really start cranking out some code.

from the book perspective, LP is similar to Beginning Python (Hetland)
or Dive into Python (Pilgrim), all of which are great intros to get
your feet wet with Python.

the two books you suggested point you in different directions:

Programming Python should be used if you want to see many different
case studies using Python in all kinds of ways, most with large bodies
of application code.

The Cookbook is used to see code snippets to perform specific tasks.
the code is usually much shorter are typically not complete
applications.

another (unbiased?) suggestion would be my book, Core Python, which
just came out a few weeks ago.  it takes the 3 books i mentioned above
and dives much deeper into how Python works under the covers, with the
goal of making you more of an effective Python programmer in as short
of a time as possible. plus there are many interesting exercises at
the end of every chapter, a great place to start really getting some
coding under your belt.

hope this helps and good luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core Python Programming, Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What after Learning Python 2nd

2006-10-09 Thread Gabriel Farrell
On Mon, Oct 09, 2006 at 10:51:26AM -0700, josip wrote:
 Hi.

   Hi I have finished Learning Python 2nd ed.
   What to do next? 
   Should I go with Programming Python book or Python Cookbook or?
   Or maybe something else?

   Thanks people!


I went from Learning Python to the Python Cookbook and have been very
happy.  The Cookbook is loaded with great tips in pretty much every
area of programming, and it's great to get so many insights.
I've also been pleasantly surprised by the usefulness of the intros to
each section, written by some of the superstars of the Python
community.

gabe

 
   
 -
 Do you Yahoo!?
  Get on board. You're invited to try the new Yahoo! Mail.
 ___
 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] Menus / Mac

2006-10-09 Thread Joel Levine
I'm trying to learn menus, starting with a textbook example.

The textbook example (pasted below) doesn't work, but doesn't die either:  It 
opens a window that has no menu.

I'm guessing it is a Mac problem.  I've tried it on 3 different Macs, with 
slightly different dates and configurations of Python and its libraries.  Same 
story each time.

But, mailing the same program to someone who pasted it into a PC program -- it 
was fine.  

On the Mac, I'm running straight from Terminal/Unix, that is, I'm not using 
IDLE.

Hard to believe that something this basic would not be running  not be noticed 
-- but I'm at a loss.

The program is below.

Thanks,
Joel Levine


from Tkinter import *

def callback():
print called the callback!

root = Tk()
# create a menu
menu = Menu(root)
root.config(menu=menu)

filemenu = Menu(menu)
menu.add_cascade(label=File, menu=filemenu)
filemenu.add_command(label=New, command=callback)
filemenu.add_command(label=Open..., command=callback)
filemenu.add_separator()
filemenu.add_command(label=Exit, command=callback)
helpmenu = Menu(menu)
menu.add_cascade(label=Help, menu=helpmenu)
helpmenu.add_command(label=About..., command=callback)
mainloop()

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


[Tutor] Seeking good resources for Tkinter

2006-10-09 Thread Asrarahmed Kadri
Hi folks,

I want to learn the GUI programming in Python. Can you suggest some nice web resources as well as books to start.

Thanks in anticipation.

Regards,
Asrar-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Menus / Mac

2006-10-09 Thread John Fouhy
On 09 Oct 2006 15:43:01 -0400, Joel Levine [EMAIL PROTECTED] wrote:
 I'm guessing it is a Mac problem.  I've tried it on 3 different Macs, with 
 slightly different dates and configurations of Python and its libraries.  
 Same story each time.

It works for me :-) (MBPro, Tiger)

Remember that macs have a universal menu bar.  If you click on the
window it created, the menubar at the top should change appropriately.

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


Re: [Tutor] tkinter

2006-10-09 Thread Michael Lange
On Mon, 9 Oct 2006 14:00:26 +0100
Alan Gauld [EMAIL PROTECTED] wrote:

  We try to build new software using python and tkinter. We would like 
  to
  enter some fields using grid style.
 
 Based on the fact that you say:
 
  these. I hope I could explain I did not mean this grid which is 
  using
  instead of pack.
 
 I assume you mean like a spreadsheet grid of cells?
 
  we wonder if there is already some classes or widgets to do this.
 
 I'm not aware of such a control but its quite likely someone has
 built one. Try asking on the Tkinter mailing list, they are more
 likely to know.
 

As far as I know the tktable widget (http://tktable.sourceforge.net) is a quite 
advanced
spreadsheet widget, and there is a Python wrapper module in the demos 
directory, I never used
it though.
Another option is the Tix.Grid, unfortunately there is only a partially 
implememted (and partially broken)
python interface included in the Python-2.5 Tix module.
For more functionality you can try the Tix.Grid wrapper I wrote a while ago 
(http://www.8ung.at/klappnase/TixGrid/TixGrid.html),
however it is not much tested and the tixGrid itself seems to be alpha or beta 
quality, some
methods do not seem to have any effect.

I hope this helps

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


Re: [Tutor] Seeking good resources for Tkinter

2006-10-09 Thread Michael Lange
On Mon, 9 Oct 2006 22:04:17 +0100
Asrarahmed Kadri [EMAIL PROTECTED] wrote:

 Hi folks,
 
 I want to learn the GUI programming in Python. Can you suggest some nice web
 resources as well as books to start.
 
 Thanks in anticipation.
 

Hi Asrar,

for Tkinter a good place to start is the wiki:

http://tkinter.unpy.net/wiki/

Several Tkinter books are mentioned here:

http://tkinter.unpy.net/wiki/books

where John Grayson's Python and Tkinter programming is (although it is a 
little outdated)
still the ultimate resource.
For a start the Tkinter reference from New Mexico Tech 
(http://infohost.nmt.edu/tcc/help/lang/python/tkinter.html)
and Frederik Lundh's book 
(http://www.pythonware.com/library/tkinter/introduction/) are good, too (and 
they are free).

I hope this helps

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


Re: [Tutor] What after Learning Python 2nd

2006-10-09 Thread Alan Gauld
  Hi I have finished Learning Python 2nd ed.
  What to do next? 

Write code.
Lots of code.
Think of a project that will need more than a single file
so you get practice with modules.
Think of a project that can use OOP to practice with objects.
Do some text processing, or write a web client to try out 
regular expressions or HTML parsing.

In other words get some experience under your belt 
before worrying about advanced coding features etc.

  Should I go with Programming Python book or 
 Python Cookbook 

Two very different books!
Personally I would go for Programming Python because I've 
never been a fan of cookbook type books. They tend to 
encourage cut n' paste style reuse where you don't necessarily 
understand the why. I prefer the wider coverage of PP with 
lots of real code. But its a very personal choice, one of 
my colleaguers loves cookbooks and has one for each of 
the different languages we use.

I do recommend a reference book too, like the Beasley or 
Martelli books

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


Re: [Tutor] Seeking good resources for Tkinter

2006-10-09 Thread Alan Gauld
 I want to learn the GUI programming in Python. Can you suggest some 
 nice web
 resources as well as books to start.

It never fails to amaze me how often we get near identical
questions being asked within a few days of each other and then
never mentioned again for weeks!

There are many different GUI toolkits for Python but the two most
commonly used are:

wxPython and
Tkinter.

Tkinter is based ob Tcl/Tk and comes as standard in Python
but has slightly less sophisticated widgets and some folks
don't like its looks.Try the Tkinter Topic Guide in the Documentation
section of the Python web site for links to references and tutorials.
There are some books too.

wxPython has its own web site and is based on a C++
framework called wxWidgets which also has a web site
full of references which are very good if you can read C++.

HTH,

Alan G. 


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


[Tutor] Threaded FTP class

2006-10-09 Thread Bill Burns
Hi all,

I'm trying to make a small, threaded FTP app and I'm running into
a problem.

My program has a GUI (I use PythonCard) and I want the GUI to be
responsive while network operations are going on.

I assumed that if I made a class (shown below) which was sub-classed
from threading.Thread - I wouldn't have any problems.

My GUI class (not shown) has a 'connect' button with a method that
looks like this:

def on_connect_command(self, event):
 Connect to the remote server.
 # getConnectData() - returns a tuple with
 # all of the data we need to connect.
 server, username, password = self.getConnectData()
 # Instantiate my threaded FTP class.
 self.host = FTP(server, username, password)
 self.host.setDaemon(True)
 self.host.start()
 time.sleep(1)

When I hit this button, the GUI is completely responsive while trying to
connect to the remote server. I have no problems and everything works as
expected.

Here's where I get the problem... The GUI class has another method which
looks like this:

def on_getData_command(self, event):
 # getDirectoryData(...) is a method in the
 # FTP() class. It walks a remote directory.
 self.host.getDirectoryData(someDirectory)

When I fire this method - it blocks until getDirectoryData() returns,
which makes the GUI non-responsive. It's *not* hanging due to a network
problem (it will only fire if you're connected to the remote server.)

Why does this one method block? I assumed it would run in the FTP class
thread and I'd have no problems!? What should I do different?

Thanks,

Bill

A simplified version of my FTP class:

code

class FTP(threading.Thread):
 This class requires ftputil which you can download
 from here - http://ftputil.sschwarzer.net/download
 
 def __init__(self, server, username, password):
 threading.Thread.__init__(self)
 self.server = server
 self.username = username
 self.password = password
 self.host = None
 self.connected = False

 def run(self):
 Connects to the remote server and prints a list
 containing files and directories from the current
 directory.

 This does not block the GUI!
 
 try:
 self.host = ftputil.FTPHost(
 self.server,
 self.username,
 self.password)
 data = self.getDirData()
 self.connected = True
 print data
 except ftputil.ftp_error.FTPOSError:
 self.connected = False
 print 'Could not connect to remote server!'

 def getDirData(self):
 Returns a list containing remote 'listdir' output.
 return [d for d in self.host.listdir(self.host.curdir)]

 def getDirectoryData(self, directory):
 Walks the remote directory and then prints a list containing
 the files which were found.

 This blocks the GUI!
 
 if self.connected:
 fileList = []
 self.host.chdir(directory)
 for root, dirs, files in self.host.walk(self.host.curdir):
 for f in files:
 fileList.append(self.host.path.abspath(
 self.host.path.join(root, f)))
 self.host.chdir('..')
 print fileList

 def disconnect(self):
 Disconnect from the remote server.
 self.host.close()
 self.connected = False

/code


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


Re: [Tutor] re-reading file-like objects

2006-10-09 Thread Kent Johnson
Tiago Saboga wrote:
 I'm afraid I don't fully understand file objects. I thought I could use it 
 just as a file: if I have one, and I want several copies, I just save it with 
 several names. So, if Popen.stdout already is a file object, I thought the 
 easier way would be to save it with another name. I see that it is more 
 complicated.

A file-like object doesn't represent a file on disk so much as a data 
stream. It is a place you can read data from or write data to. When you 
call subprocess.Popen(), you get back a data stream representing the 
output of the process you started. You can read through this stream 
once, when you get to the end it's done. Just like when you run the 
process from the console, it just outputs once. If you want to use the 
output more than once you can copy it or save it or run the process again.

Some file-like objects do let you seek to a specific location, but not all.

Kent

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


Re: [Tutor] tkinter

2006-10-09 Thread Paulino
Hi Abdullah!

There is a kind of grid for tkinter that you can find online in the 
python cookbook, search for MultiListbox.

But if you really want a spreadsheet like grid, you'd rather use wx.grid 
from wxPython.

wxPython is much more powerfull than tkinter and is as easy to learn.
You can find lots od doc's in www.wxpython.org.



 Date: Mon, 9 Oct 2006 14:23:32 +0300
 From: Abdullah Anar [EMAIL PROTECTED]
 Subject: [Tutor] tkinter
 To: tutor@python.org
 Message-ID:
   [EMAIL PROTECTED]
 Content-Type: text/plain; charset=iso-8859-1

 hello,

 We try to build new software using python and tkinter. We would like to
 enter some fields using grid style. I mean we want to use rows to see old
 entries and to enter new one. I hope I could explain, because it also is
 not  easy. I know there is grid to locate buttons, labels and something like
 these. I hope I could explain I did not mean this grid which is using
 instead of pack.

 we wonder if there is already some classes or widgets to do this.

 thanks for help from now

 Abdullah Anar
 -- next part --
 An HTML attachment was scrubbed...
 URL: 
 http://mail.python.org/pipermail/tutor/attachments/20061009/41a5ee23/attachment-0001.html
  

   

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


Re: [Tutor] Threaded FTP class

2006-10-09 Thread Kent Johnson
Bill Burns wrote:
 I'm trying to make a small, threaded FTP app and I'm running into
 a problem.
 
 My program has a GUI (I use PythonCard) and I want the GUI to be
 responsive while network operations are going on.
 
 I assumed that if I made a class (shown below) which was sub-classed
 from threading.Thread - I wouldn't have any problems.
 
 My GUI class (not shown) has a 'connect' button with a method that
 looks like this:
 
 def on_connect_command(self, event):
  Connect to the remote server.
  # getConnectData() - returns a tuple with
  # all of the data we need to connect.
  server, username, password = self.getConnectData()
  # Instantiate my threaded FTP class.
  self.host = FTP(server, username, password)
  self.host.setDaemon(True)
  self.host.start()
  time.sleep(1)
 
 When I hit this button, the GUI is completely responsive while trying to
 connect to the remote server. I have no problems and everything works as
 expected.

In this method you create a new thread and start it. The thread's run() 
method is called. It connects to the remote server, fetches and prints a 
directory and returns. At that point (when the run() method returns) the 
FTP thread is dead.
 
 Here's where I get the problem... The GUI class has another method which
 looks like this:
 
 def on_getData_command(self, event):
  # getDirectoryData(...) is a method in the
  # FTP() class. It walks a remote directory.
  self.host.getDirectoryData(someDirectory)
 
 When I fire this method - it blocks until getDirectoryData() returns,
 which makes the GUI non-responsive. It's *not* hanging due to a network
 problem (it will only fire if you're connected to the remote server.)
 
 Why does this one method block? I assumed it would run in the FTP class
 thread and I'd have no problems!? What should I do different?

No, you don't do anything here to make the getDirectoryData() method run 
in a separate thread. Just because the FTP class has (or had) one thread 
at one time doesn't automatically make all of the FTP class methods run 
in a different thread.

There are a few different ways you could handle this. You could have 
each command in the FTP class be smart enough to start a new thread to 
run the command. You don't actually have to subclass threading.Thread, 
you can just create a thread and tell it what method to execute. (Side 
note - this might be a good use for a @run_in_thread decorator.)

You could make a separate class for each command. This would be pretty 
similar to the above solution. You would probably want a base class or 
utility class to hold the common details of connecting and sending a 
command.

You could make a thread that really does keep running, that listens to 
for commands from a Queue. Your GUI thread would put a command in the 
Queue, the daemon thread would pull a command out and execute it.

You could figure out how to do this with Twisted...

HTH,
Kent


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


Re: [Tutor] Threaded FTP class

2006-10-09 Thread Bill Burns
 I'm trying to make a small, threaded FTP app and I'm running into
 a problem.

 My program has a GUI (I use PythonCard) and I want the GUI to be
 responsive while network operations are going on.

 I assumed that if I made a class (shown below) which was sub-classed
 from threading.Thread - I wouldn't have any problems.

 My GUI class (not shown) has a 'connect' button with a method that
 looks like this:

 def on_connect_command(self, event):
  Connect to the remote server.
  # getConnectData() - returns a tuple with
  # all of the data we need to connect.
  server, username, password = self.getConnectData()
  # Instantiate my threaded FTP class.
  self.host = FTP(server, username, password)
  self.host.setDaemon(True)
  self.host.start()
  time.sleep(1)

 When I hit this button, the GUI is completely responsive while trying to
 connect to the remote server. I have no problems and everything works as
 expected.
 
 
 In this method you create a new thread and start it. The thread's run() 
 method is called. It connects to the remote server, fetches and prints a 
 directory and returns. At that point (when the run() method returns) the 
 FTP thread is dead.
 

 Here's where I get the problem... The GUI class has another method which
 looks like this:

 def on_getData_command(self, event):
  # getDirectoryData(...) is a method in the
  # FTP() class. It walks a remote directory.
  self.host.getDirectoryData(someDirectory)

 When I fire this method - it blocks until getDirectoryData() returns,
 which makes the GUI non-responsive. It's *not* hanging due to a network
 problem (it will only fire if you're connected to the remote server.)

 Why does this one method block? I assumed it would run in the FTP class
 thread and I'd have no problems!? What should I do different?
 
 
 No, you don't do anything here to make the getDirectoryData() method run 
 in a separate thread. Just because the FTP class has (or had) one thread 
 at one time doesn't automatically make all of the FTP class methods run 
 in a different thread.
 
 There are a few different ways you could handle this. You could have 
 each command in the FTP class be smart enough to start a new thread to 
 run the command. You don't actually have to subclass threading.Thread, 
 you can just create a thread and tell it what method to execute. (Side 
 note - this might be a good use for a @run_in_thread decorator.)
 
 You could make a separate class for each command. This would be pretty 
 similar to the above solution. You would probably want a base class or 
 utility class to hold the common details of connecting and sending a 
 command.
 
 You could make a thread that really does keep running, that listens to 
 for commands from a Queue. Your GUI thread would put a command in the 
 Queue, the daemon thread would pull a command out and execute it.
 
 You could figure out how to do this with Twisted...
 


Kent,

Thank you for the explanation and ideas!! I wasn't exactly sure how the 
threading was working but you've enlightened me!

Bill

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


[Tutor] multithreading random()

2006-10-09 Thread Dick Moores
Please refer to 
http://www.python.org/doc/current/lib/module-random.html, from which I quote:

The functions supplied by this module are actually bound methods of 
a hidden instance of the random.Random class. You can instantiate 
your own instances of Random to get generators that don't share 
state. This is especially useful for multi-threaded programs, 
creating a different instance of Random for each thread, and using 
the jumpahead() method to make it likely that the generated sequences 
seen by each thread don't overlap.

Could someone point me to an example script where this was done? I'd 
very much like to learn how to do that.

And another question. That page also says, Almost all module 
functions depend on the basic function random(), which generates a 
random float uniformly in the semi-open range [0.0, 1.0). Python uses 
the Mersenne Twister as the core generator. It produces 53-bit 
precision floats and has a period of 2**19937-1. What is a 53-bit 
precision float? Would that be something like a float accurate to 8 
or 9 figures (dividing 53 by 8). Or what?

Thanks,

Dick Moores

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


Re: [Tutor] multithreading random()

2006-10-09 Thread John Fouhy
On 10/10/06, Dick Moores [EMAIL PROTECTED] wrote:
 And another question. That page also says, Almost all module
 functions depend on the basic function random(), which generates a
 random float uniformly in the semi-open range [0.0, 1.0). Python uses
 the Mersenne Twister as the core generator. It produces 53-bit
 precision floats and has a period of 2**19937-1. What is a 53-bit
 precision float? Would that be something like a float accurate to 8
 or 9 figures (dividing 53 by 8). Or what?

Hi Dick,

Have a look here: http://en.wikipedia.org/wiki/Double_precision
and here: http://en.wikipedia.org/wiki/IEEE_floating-point_standard

Basically, floating point numbers are of the form x times 2**y,
where x is a binary number between 1 and 10 (that's binary 10, decimal
2).  53 bits means 53 binary digits of precision (including the
initial 1).

Does that help?

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


Re: [Tutor] multithreading random()

2006-10-09 Thread John Fouhy
On 10/10/06, Dick Moores [EMAIL PROTECTED] wrote:
 Please refer to
 http://www.python.org/doc/current/lib/module-random.html, from which I 
 quote:

 The functions supplied by this module are actually bound methods of
 a hidden instance of the random.Random class. You can instantiate
 your own instances of Random to get generators that don't share
 state. This is especially useful for multi-threaded programs,
 creating a different instance of Random for each thread, and using
 the jumpahead() method to make it likely that the generated sequences
 seen by each thread don't overlap.

 Could someone point me to an example script where this was done? I'd
 very much like to learn how to do that.

Using google's code search, I found this:

def _create_random_generators(self, num, delta, firstseed=None):
Return list of 'num' distinct generators.
Each generator has its own unique segment of delta elements
from Random.random()'s full period.
Seed the first generator with optional arg firstseed (default
is None, to seed from current time).

g = Random(firstseed)
result = [g]
for i in range(num - 1):
laststate = g.getstate()
g = Random()
g.setstate(laststate)
g.jumpahead(delta)
result.append(g)
return result

Although, from looking at the docs you quoted, this may not be correct
for python2.3+.

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