Re: [Tutor] single executable

2005-08-01 Thread Alan G
> http://starship.python.net/crew/theller/moin.cgi/SingleFileExecutable
>
> that seems to indicate what I want is possible and it is available.

While it is possible to build single exe programs its questionable
whether the effort involved is worthwhile. Only the very smallest
programs can ever be built that way because any significant 
application
needs support files - config and data files etc. Many applications
actually have multiple executables(client/server apps for example)

None of these can be bundled as a single file exe. They must be
packaged with an installer.

There are also significant snags with single exes. For example if you
(or even seveal  other folks) distribute many such Python programs
you are installing puthon multiple times on the users computers.
There will also be duplication of wxPython if you use that, Tcl DLLs
if you use Tkinter etc etc. Now disk space is cheap so thats not
a huge issue but these big combined files are also slow to start
and tend to consume lots of memory when running. Thats why most
commercial apps come as an exe and lots of DLLs (several hundred
for MS Word!), its much more efficient to run.

So although a single exe seems like a good idea its worth
remembering that there is a downside too.

Alan G

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


Re: [Tutor] Is input a Python function or command?

2005-08-01 Thread Nathan Pinno
Just remembered that input is for integers! Oops! Shouldn't have asked! And 
in_file makes more sense because I'm loading a file with it.
- Original Message - 
From: "Nathan Pinno" <[EMAIL PROTECTED]>
To: "Luke P" <[EMAIL PROTECTED]>
Cc: "Tutor mailing list" 
Sent: Sunday, July 31, 2005 8:05 PM
Subject: Re: [Tutor] Is input a Python function or command?


> Thanks Luke. Saved me quite a headache. I will use in_file instead. Makes
> more sense anyway.
> - Original Message - 
> From: "luke p" <[EMAIL PROTECTED]>
> To: "Nathan Pinno" <[EMAIL PROTECTED]>
> Sent: Sunday, July 31, 2005 7:59 PM
> Subject: Re: [Tutor] Is input a Python function or command?
>
>
> why do you want to use input as a variable?
>
> did you try testing it on the interactive prompt?
 input
> (built-in function input)
hello = "test"
input()
> hello
> "test"
>
> so yep it's a builtin function.
>
> try to come up with more explanatory names.
> or just name all your variables "tmp" and "temp" and "x".
>
> or you can just overwrite the input function n the namespace.
>
> I'm sure some people would consider these approaches evil, however, so
> you probably shouldn't do it unless your code is for your use only.
>
> HTH,
> Luke
>
>
> On 7/31/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:
>> Is input a Python function or command? I need to know because I'm 
>> planning
>> to use it as a variable, and don't want to get an error.
>>
>> Thanks,
>> Nathan
>> ___
>> 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 maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python FTP GUI - Possible project ?

2005-08-01 Thread Matt Williams
Dear List,

Does anyone know of a Python FTP GUI tool ? Preferably based around
pyGTK+ ?

I've had a look (Google, vaults of Parnassus, etc.) but haven't found
one.

If there isn't one, then would people consider it a useful project for
newbie programmers (like myself). There have often been questions along
the lines of "Where can I find projects to get involved in", and I
thought this might help.

Thanks,

Matt


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


Re: [Tutor] Python FTP GUI - Possible project ?

2005-08-01 Thread Liam Clarke
Hi Matt, 

If you're au fait with pyGTK+, that combined with the ftplib module
syou should be able to build a decent GUI based FTP programme somewhat
easily, although I can guarantee that if you don't know pyGTK+ too
well, you'll end up having several screen-smashing moments, followed by
a zen like realisation or two...

Shouldn't be overly hard, not that I'm familiar with pyGTK+. I would
recommend learning ftplib thoroughly, and perhaps go through a free FTP
client and log what it does, so you can replicate the behaviour in your
programme. Some FTP programmes automatically request directory
listings, some don't, etc. etc. 

One of my first projects with a GUI involved using the IMAP email protocol, good stuff to play with.

Regards, 

Liam ClarkeOn 8/1/05, Matt Williams <[EMAIL PROTECTED]> wrote:
Dear List,Does anyone know of a Python FTP GUI tool ? Preferably based aroundpyGTK+ ?I've had a look (Google, vaults of Parnassus, etc.) but haven't foundone.If there isn't one, then would people consider it a useful project for
newbie programmers (like myself). There have often been questions alongthe lines of "Where can I find projects to get involved in", and Ithought this might help.Thanks,Matt
___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
-- 'There is only one basic human right, and that is to do as you damn well please.And with it comes the only basic human duty, to take the consequences.'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python FTP GUI - Possible project ?

2005-08-01 Thread Kristian Rink
Matt Williams schrieb:
> Dear List,
> 
> Does anyone know of a Python FTP GUI tool ? Preferably based around
> pyGTK+ ?

Though just loosely related to the original post, if you're not
completely familiar with pyGTK+, you might want to think about using
pythoncard as GUI framework instead. IIRC it is built around wxwidgets
(which itself uses GTK+ atop X11), so it should seamlessly integrate in
any GTK+ environment, but it is amazingly easy to get started with.

Cheers,
Kris

-- 
Kristian Rink * http://www.fotolog.net/kawazu * http://zimmer428.net
icq: 48874445 * jab: [EMAIL PROTECTED] * fon: ++49 176 2447 2771
"Sei Du selbst die Veränderung, die Du in der Welt wünschst." (Gandhi)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python FTP GUI - Possible project ?

2005-08-01 Thread Liam Clarke
May I second the vote for Pythoncard. Although I'm not sure how easily you could represent directories...
On 8/1/05, Kristian Rink <[EMAIL PROTECTED]> wrote:
Matt Williams schrieb:> Dear List,>> Does anyone know of a Python FTP GUI tool ? Preferably based around> pyGTK+ ?Though just loosely related to the original post, if you're notcompletely familiar with pyGTK+, you might want to think about using
pythoncard as GUI framework instead. IIRC it is built around wxwidgets(which itself uses GTK+ atop X11), so it should seamlessly integrate inany GTK+ environment, but it is amazingly easy to get started with.
Cheers,Kris--Kristian Rink * http://www.fotolog.net/kawazu * http://zimmer428.neticq: 48874445 * jab: 
[EMAIL PROTECTED] * fon: ++49 176 2447 2771"Sei Du selbst die Veränderung, die Du in der Welt wünschst." (Gandhi)___Tutor maillist  -  
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor-- 'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Send attachment

2005-08-01 Thread Jorge Louis De Castro



Thanks for the reply
 
I did try your approach at first but then, Martin 
Walsh on this mailing list hinted at something way simpler and elegant, a 
solution that actually adjusts itself to the default mail client of the 
user.
 
It consists of creating an .eml file with all the 
blurb that goes with it (save an email message as a draft and open it to 
see what needs to go there).
 
Then it is a simple matter of calling 
os.startfile() and the OS will open the file with whatever 
program is associated with those extensions, typically the default mail 
client.
 

> import os> os.startfile('foo.eml')
 
I think it's neat, it does what I want in an 
elegant way, and it keeps me from mixing languages and all that 
jazz.
 
chrs
j.
 

  - Original Message - 
  From: 
  Liam Clarke 
  
  To: Jorge Louis De Castro 
  Cc: tutor@python.org 
  Sent: Friday, July 22, 2005 12:45 
AM
  Subject: Re: [Tutor] Send 
attachment
  If it's Outlook, you can use the 
  win32python library to control it via ActiveX/COM+http://starship.pythonnet/crew/mhammond/Here's 
  an example using VB to control Outlook - http://support.microsoft.com/?kbid=220595The 
  language differs, but the basic principle remains the same. Create an 
  Application.Outlook object, and then use it's methods. I know there's 
  a way to use the default mail client ( as in Excel VBA's - 
  application.showdialog(xlDialogs.SendMail) ) but blowed if I can figure it 
  out. The above VBA bit automatically attaches the open spreadsheet, so unsure 
  if you can hijack it. Good luck, and if you google how to use the 
  default email client, let me know!Liam Clarke
  On 7/22/05, Jorge Louis 
  De Castro <[EMAIL PROTECTED]> 
  wrote:
  
Hello,
 
Any ideas how I can use Python and 
the Windows API to open a PC's mail client and send an 
attachment?
The idea is saving some data onto a file and 
then invoke the email client (OE or Outlook or whatever is the default on 
the machine) with the recipient's address filled in and the file ready to be 
sent as an attachment. 
Kinda like when we right-click on a file and 
select the "send to mail recipient" behavior.
Been reading docs, trying out samples, and 
googling this for a few days to no avail.
 
Cheers
jorge___Tutor 
maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python FTP GUI - Possible project ?

2005-08-01 Thread Andreas Kostyrka
Am Montag, den 01.08.2005, 20:24 +1200 schrieb Liam Clarke:
> Hi Matt, 
> 
> If you're au fait with pyGTK+, that combined with the ftplib module
> syou should be able to build a decent GUI based FTP programme somewhat
> easily, although I can guarantee that if you don't know pyGTK+ too
> well, you'll end up having several screen-smashing moments, followed
> by a zen like realisation or two...
> 
> Shouldn't be overly hard, not that I'm familiar with pyGTK+. I would
> recommend learning ftplib thoroughly, and perhaps go through a free
> FTP client and log what it does, so you can replicate the behaviour in
Well, for a really useful client, he should probably consider either
PyCurl or Twisted. Or be ready to do some thread hacking ;)

Andreas
>  your programme. Some FTP programmes automatically request directory
> listings, some don't, etc. etc. 
> 
> One of my first projects with a GUI involved using the IMAP email
> protocol, good stuff to play with.
> 
> Regards, 
> 
> Liam Clarke
> 
> On 8/1/05, Matt Williams <[EMAIL PROTECTED]> wrote:
> Dear List,
> 
> Does anyone know of a Python FTP GUI tool ? Preferably based
> around
> pyGTK+ ?
> 
> I've had a look (Google, vaults of Parnassus, etc.) but
> haven't found
> one.
> 
> If there isn't one, then would people consider it a useful
> project for 
> newbie programmers (like myself). There have often been
> questions along
> the lines of "Where can I find projects to get involved in",
> and I
> thought this might help.
> 
> Thanks,
> 
> Matt
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> -- 
> 'There is only one basic human right, and that is to do as you damn
> well please.
> And with it comes the only basic human duty, to take the
> consequences.' 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python FTP GUI - Possible project ?

2005-08-01 Thread Kent Johnson
Matt Williams wrote:
> Dear List,
> 
> Does anyone know of a Python FTP GUI tool ? Preferably based around
> pyGTK+ ?
> 
> I've had a look (Google, vaults of Parnassus, etc.) but haven't found
> one.

Googling 'python ftp client' gives http://ftpcube.sourceforge.net/ as well as 
several resources that might be useful if you decide to write your own.

Kent

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


Re: [Tutor] Socket Programming

2005-08-01 Thread Joseph Quigley
Hi Dan,

Danny Yoo wrote:

>##
>clientsocket.recv()
>##
>
>should work better.
>  
>
Ok well I tried your examples but they didn't work. I still get:
TypeError: recv() takes at least 1 argument (0 given)

How can I fix this?

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


Re: [Tutor] Socket Programming

2005-08-01 Thread Adam Bark
You have to put in how many bytes of data you want to recieve in clientsocket.recv() eg. clientsocket.recv(1024) for 1kB.On 7/31/05, Joseph Quigley <
[EMAIL PROTECTED]> wrote:Hi Dan,
Danny Yoo wrote:>##>clientsocket.recv()>##>>should work better.>>Ok well I tried your examples but they didn't work. I still get:TypeError: recv() takes at least 1 argument (0 given)
How can I fix this?___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


[Tutor] Re; Socket Programming

2005-08-01 Thread Joseph Quigley
Hi Kent,

I have Python in a nutshell but I haven't read much. Thanks for tellling me.


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


Re: [Tutor] Socket Programming

2005-08-01 Thread Joseph Quigley
Hi Johan,

Johan Geldenhuys wrote:

> I have more advanced examples if you want them, but start here and 
> look at the socket lib and you can start using select if you want to 
> wait for stuff from the server or client.
>
> Johan



I'd love to see your examples. Could you send them directly to me as an 
attachment? I've got a question... how can I add more clients? I'm 
trying to make a type of bot.
Thanks for your help. Your example worked perfectly!

Joe

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


[Tutor] question on numarray across platforms

2005-08-01 Thread Xiangyi Meng
Hi there,

I ran across this error when running a few lines of 
code in debian python, but this runs perfectly in
windows python. Basically I created a dummy matrix
called "gamma" (using kroneckerproduct in numarray)
and printed out its mean.  Here is the code:
gamma = kroneckerproduct(ones((N, 1)),identity(T))
print gamma.mean()

and Here is the error message:
Traceback (most recent call last):
  File "vul_prov.py", line 149, in ?
VLs = mv_prov(hhc, idyrisk, provid, 1)
  File
"/home/meng/China/Extent/Data/Urban2002/Empirics/tmp/vulnerability.py",
line 605, in mv_prov
print gamma.mean()
  File
"/usr/lib/python2.4/site-packages/numarray/numarraycore.py",
line 1137, in mean
return self.sum()/(self.nelements()*1.0)
  File
"/usr/lib/python2.4/site-packages/numarray/numarraycore.py",
line 1133, in sum
return ufunc.add.reduce(ufunc.add.areduce(self,
type=type).flat, type=type)
IndexError: too many indices.

Thank you for helping on this! Oh, btw, the version
for python in both platforms is 2.4.1

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


[Tutor] mailman

2005-08-01 Thread Mohammad Moghimi
I want to install mailman.
when I try to configure it I got this error message:
checking for --with-python... no
checking for python... /usr/bin/python
checking Python interpreter... /usr/bin/python
checking Python version... 2.4
checking that Python has a working distutils... configure: error:

* Distutils is not available or is incomplete for /usr/bin/python
* If you installed Python from RPM (or other package manager)
* be sure to install the -devel package, or install Python
* from source.  See README.LINUX for details

I downloaded Distutil from python.org
http://www.python.org/sigs/distutils-sig/download/Distutils-1.0.2.tar.gz

I wanted to install this one but I got another error message in running
python setup.py install

Traceback (most recent call last):
  File "setup.py", line 30, in ?
    packages = ['distutils', 'distutils.command'],
  File "/home/soccer/mohammad/python/Distutils-1.0.2/distutils/core.py", line 101, in setup
    _setup_distribution = dist = klass(attrs)
  File "/home/soccer/mohammad/python/Distutils-1.0.2/distutils/dist.py", line 130, in __init__
    setattr(self, method_name, getattr(self.metadata, method_name))
AttributeError: DistributionMetadata instance has no attribute 'get___doc__'

How can I solve this problem?!
-- Mohammaddo you Python?!!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] visibility of variables

2005-08-01 Thread Victor Reijs

Hello all of you,

I have problems with the visibility of variables in python. I am
used to the idea of Javascript and other languages where one can define
global variables if they are defined outside a function. It seems Python
is not doing that, but how can I make it work?

I think it needs some twist in my mind to get used to it, but I still
don't grasp it. Can you help?

I have attached a program that is not functioning as I would like to
have it functioning.
It seems that the 'gementenkleur' in funct1 and funct2 are the value of
gemetenkleur at the start of the program, but they don't chance after
the definition of gemetenkleur=bmifrao1.bmp

I 'know' this is something particular to Python, by how can I work
around this? I could add gemetenkleur in the argument list of the funct1
and funct2 functions, but in my case I don't want this (funct1 will be a
function to be used in scipy.fmin, and I have the idea that only the
simplex can be as an argument).

Is there a good page on the web that described this visibility issue (or
does it have a different name?) of Python? The delveintopython.pdf does
not help me and also a tutorial of hetland.org (Instant python:
instant-python.php.htm ) seems not to speak the right language for me;-).

Hope someone can help me. I have the idea this is essential to
understand before continuing more in Python.


All the best,


Victor






bmifrao1bmp=[(41, 37, 33), (63, 56, 53), (107, 97, 92), (228, 226, 222), (81, 
64, 107), (107, 131, 82), (236, 207, 71), (158, 58, 42)]
print 'original bmifrao1bmp ',bmifrao1bmp
#gemetenkleur=[(41, 37, 33), (63, 56, 53), (107, 97, 92), (228, 226, 222), (81, 
64, 107), (107, 131, 82), (236, 207, 71), (158, 58, 42)]
gemetenkleur=[[47,46,47],[62,65,61],[116,114,114],[238,233,232],[65,62,116],[0,144,75],[245,211,0],[207,65,60]]
endkleur=[[47,46,47],[62,65,61],[116,114,114],[238,233,232],[65,62,116],[0,144,75],[245,211,0],[207,65,60]]


def funct1():
print 'gemetenkleur in func1: ',gemetenkleur
a=funct2(gemetenkleur)

def funct2(kleuren):
   print 'kleuren in funct2 (should be same as gemetenkleur): ',kleuren
   return 1

def Do():
   gemetenkleur=bmifrao1bmp[:]
   print 'gemetenkleur has to be from now bmifrao1bmp: ',gemetenkleur
   funct1()
   
Do()   

  


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


Re: [Tutor] visibility of variables

2005-08-01 Thread Kent Johnson
Victor Reijs wrote:
> Hello all of you,
> 
> I have problems with the visibility of variables in python. I am
> used to the idea of Javascript and other languages where one can define
> global variables if they are defined outside a function. It seems Python
> is not doing that, but how can I make it work?
> 
> I think it needs some twist in my mind to get used to it, but I still
> don't grasp it. Can you help?

In function Do() you must add the declaration
  global gemetenkleur

See 
http://www.python.org/doc/faq/programming.html#how-do-you-set-a-global-variable-in-a-function
 and the entry that follows it for some explanation.

Kent

> 
> I have attached a program that is not functioning as I would like to
> have it functioning.
> It seems that the 'gementenkleur' in funct1 and funct2 are the value of
> gemetenkleur at the start of the program, but they don't chance after
> the definition of gemetenkleur=bmifrao1.bmp
> 
> I 'know' this is something particular to Python, by how can I work
> around this? I could add gemetenkleur in the argument list of the funct1
> and funct2 functions, but in my case I don't want this (funct1 will be a
> function to be used in scipy.fmin, and I have the idea that only the
> simplex can be as an argument).
> 
> Is there a good page on the web that described this visibility issue (or
> does it have a different name?) of Python? The delveintopython.pdf does
> not help me and also a tutorial of hetland.org (Instant python:
> instant-python.php.htm ) seems not to speak the right language for me;-).
> 
> Hope someone can help me. I have the idea this is essential to
> understand before continuing more in Python.
> 
> 
> All the best,
> 
> 
> Victor
> 
> 
> 
> 
> 
> 
> 
> 
> 
> bmifrao1bmp=[(41, 37, 33), (63, 56, 53), (107, 97, 92), (228, 226, 222), (81, 
> 64, 107), (107, 131, 82), (236, 207, 71), (158, 58, 42)]
> print 'original bmifrao1bmp ',bmifrao1bmp
> #gemetenkleur=[(41, 37, 33), (63, 56, 53), (107, 97, 92), (228, 226, 222), 
> (81, 64, 107), (107, 131, 82), (236, 207, 71), (158, 58, 42)]
> gemetenkleur=[[47,46,47],[62,65,61],[116,114,114],[238,233,232],[65,62,116],[0,144,75],[245,211,0],[207,65,60]]
> endkleur=[[47,46,47],[62,65,61],[116,114,114],[238,233,232],[65,62,116],[0,144,75],[245,211,0],[207,65,60]]
> 
> 
> def funct1():
> print 'gemetenkleur in func1: ',gemetenkleur
> a=funct2(gemetenkleur)
> 
> def funct2(kleuren):
>print 'kleuren in funct2 (should be same as gemetenkleur): ',kleuren
>return 1
> 
> def Do():
>gemetenkleur=bmifrao1bmp[:]
>print 'gemetenkleur has to be from now bmifrao1bmp: ',gemetenkleur
>funct1()
>
> Do()   
> 
>   
> 
> 
> 
> 
> 
> 
> ___
> 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] visibility of variables

2005-08-01 Thread Victor Reijs
THANKS Kent.
It seems I used the wrong keywords to find answer to my question. This 
page is very very helpfull! I now works indeed. THANKS for your fast help.

All the best,

Victor

Kent Johnson wrote:
>>I have problems with the visibility of variables in python. I am
>>used to the idea of Javascript and other languages where one can define
>>global variables if they are defined outside a function. It seems Python
>>is not doing that, but how can I make it work?
>>
>>I think it needs some twist in my mind to get used to it, but I still
>>don't grasp it. Can you help?
> 
> In function Do() you must add the declaration
>   global gemetenkleur
> 
> See 
> http://www.python.org/doc/faq/programming.html#how-do-you-set-a-global-variable-in-a-function
>  and the entry that follows it for some explanation.

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


[Tutor] question on string

2005-08-01 Thread Gilbert Tsang
Hi there,

I would like to construct some string objects using the cprintf-style 
format:

command_string = "diff -u %s %s > %s.patch" % ( src, dst, file )

Of course it is illegal in python but I couldn't figure out a way to 
construct strings with that kind of formatting and substitution.

I have been looking and couldn't discover string constructor such as

command_string = string( "diff -u %s %s > %s.patch" % ( src, dst, file ) )

 From the documentation on docs.python.org, the closest is string 
Template (but my python installation doesn't come with this module). Any 
insights on initializing string in this manner?


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


Re: [Tutor] When I run this code, it just keeps repeating.

2005-08-01 Thread Bob Gailer


At 06:55 PM 7/30/2005, Nathan Pinno wrote:
...
    elif cal_opt == 4:
    X = input("First
number:" )
    Y = input("Second
number:" )
    if Y == 0:
    print
"Division by zero ot allowed!"
    Y =
input("Second number:" )
    else:
    print
X, "/", Y, "= ",X / Y
Note that you give user a 2nd try but that input never reaches the print
statement.
The following might be a bit of a stretch, but consider creating a list
of lists to store the various menu options. 
Doing this separates the high-level menu from lower-level code which is
now not repetitive. To add/modify menu items one just extends/edits the
list. Here's a "simple" example which ignores some things but
gives you the idea. Warning untested code:
menuItems = [
 ["Add", "First number:", "Second
number:",  "+", lambda(x,y:x+y)],
 ["Subtract", "First number:", "Second
number:",  "-", lambda(x,y:x-y)],
 ["Exit"]]
# first item is the main menu prompt, 
# 2nd and 3rd are the input prompts, 
# 4th is the string representation of the operator, 
# 5th is an anonymous function to do the calculation.
def menu():
  print "CALCULATE MENU"
  for option, menuItem in enumerate(menuItems):
    print str(option + 1) + ")",
menuItem[0]
def cal():
  cal_opt = int(raw_input("Option: "))
  if 1 <= cal_opt <= len(menuItems):
    menuItem = menuItems[cal_opt - 1]
    if menuItem[0] = "Exit":return False
    prompt1, prompt2, oper, func =  
menuItem[1:]
    X = input(prompt1)
    Y = input(prompt2)
    print X, oper, Y, "= ", func(X, Y)
  else:
    print "That's not an option. Try
again."
  return True
print "Mini Calculator"
print "By Nathan Pinno"
print
while True:
  menu()
  if not cal(): break

Bob Gailer
phone 510 978 4454 

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


Re: [Tutor] question on string

2005-08-01 Thread Kent Johnson
Gilbert Tsang wrote:
> Hi there,
> 
> I would like to construct some string objects using the cprintf-style 
> format:
> 
> command_string = "diff -u %s %s > %s.patch" % ( src, dst, file )
> 
> Of course it is illegal in python but I couldn't figure out a way to 
> construct strings with that kind of formatting and substitution.

Actually that is correct as written! (though 'file' is a poor choice of 
variable name as it shadows the built-in file() function...)

 >>> src = 'mySource'
 >>> dst = 'myNewSource'
 >>> file = 'diff.out'
 >>> command_string = "diff -u %s %s > %s.patch" % ( src, dst, file )
 >>> command_string
'diff -u mySource myNewSource > diff.out.patch'

See http://docs.python.org/lib/typesseq-strings.html for details on string 
formatting.

Kent

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


Re: [Tutor] Is input a Python function or command?

2005-08-01 Thread Danny Yoo


> Thanks Luke. Saved me quite a headache. I will use in_file instead.
> Makes more sense anyway.


Hi Nathan,

Just wanted to chime in here: you may have fewer issues with name
conflicts if you use more functions.

For example:

##
>>> def test():
... input = 42
... print input
...
>>> test()
42
>>> input

##


What this tries to so is that functions offer a little bit of isolation:
within a function, you can usually just use names with abandon, because it
won't affect the outside world.  We'd say here that test() uses 'input' as
a "local" variable.


Of course, if we try to do something like:

##
>>> def test():
... input = 42
... s = input("hi, what's your age? ")
...
>>> test()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 3, in test
TypeError: 'int' object is not callable
##

we should expect to see trouble within the function, since we've
overwritten 'input'.


However, outside the function, we're still good:

##
>>> input("hello: ")
hello: 42
42
##


So that's one benefit of doing work in functions: we can box things in so
that, if we make a mistake, our mistake is isolated to the function, and
not to the outside world.


Hope this helps!

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


Re: [Tutor] cant get started

2005-08-01 Thread Danny Yoo


On Mon, 1 Aug 2005, Alan G wrote:

> I'm cc'ing this back to the tutor list because others may spot things
> I miss.
>
> >K something must be wrong cause I typed python and it said "python is
> >not
> > defined" so any ideas


Hi Alan,


Are you sure that F22AceRaptor isn't trying to type 'python' at the
interactive interpreter?

##
>>> python
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'python' is not defined
##

I think that F22AceRaptor is already in Python and may simply not realise
it.  *grin*


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


Re: [Tutor] question on string

2005-08-01 Thread ZIYAD A. M. AL-BATLY
On Mon, 2005-08-01 at 10:42 -0700, Gilbert Tsang wrote:
> Hi there,
> 
> I would like to construct some string objects using the cprintf-style 
> format:
> 
> command_string = "diff -u %s %s > %s.patch" % ( src, dst, file )
> 
> Of course it is illegal in python but I couldn't figure out a way to 
> construct strings with that kind of formatting and substitution.
> 
> I have been looking and couldn't discover string constructor such as
> 
> command_string = string( "diff -u %s %s > %s.patch" % ( src, dst, file ) )
> 
>  From the documentation on docs.python.org, the closest is string 
> Template (but my python installation doesn't come with this module). Any 
> insights on initializing string in this manner?
> 
> 
> Thanks, Gilbert.
"file" is a reserved word!  This is why it's not working for you!
Change "file" to something else, like "result" for example.

Here:
>>> src = 'file1.c'
>>> dst = 'file2.c'
>>> result = "result"
>>> command_string = "diff -u %s %s > %s.patch" % (src, dst, result)
>>> command_string
'diff -u file1.c file2.c > result.patch'

Is this what you want?

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


Re: [Tutor] Socket Programming

2005-08-01 Thread Joseph Quigley
Hi,

Ok. But what if I wanted to send a 1 mb message? Could I leave 
.recv(1) in and send 'Hi!' as well or would I have to change it?
Thanks,
JQ

Adam Bark wrote:

> You have to put in how many bytes of data you want to recieve in 
> clientsocket.recv() eg. clientsocket.recv(1024) for 1kB.


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


Re: [Tutor] question on numarray across platforms

2005-08-01 Thread Danny Yoo


On Mon, 1 Aug 2005, Xiangyi Meng wrote:
>
> I ran across this error when running a few lines of code in debian
> python, but this runs perfectly in windows python.

Hi Xiangyi,

This seems a bit specific to numarray; you may want to ask the Numeric
discussion group:

http://sourceforge.net/mailarchive/forum.php?forum_id=4890

Offhand, I can't see anything wrong here, and it sounds bizarre that
you're getting different results between Windows and Debian Linux --- that
sounds like a severe bug.


When you ask the Numeric discussion group, also show what the
numarray.__version__ variable looks like.  For reference, here's the
version of numarray on my system:

##
>>> import numarray
>>> numarray.__version__
'1.3.1'
##

Do this for both your Windows environment and your Debian Linux
environment, and make sure you get the same version number.  If the
version numbers differ, then that may explain why you're getting different
results from your program.


Good luck to you!

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


[Tutor] Color text in Text widget

2005-08-01 Thread sunny sunny
Hi all,

How do I add color to the text in the Text widget? I tried using the
ASCII sequence but it didnt work.

For example, I want to add:
 This is  red , but this is  blue 

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


Re: [Tutor] mailman

2005-08-01 Thread Danny Yoo


On Mon, 1 Aug 2005, Mohammad Moghimi wrote:

> I want to install mailman.

[cut]

Hi Mohammad,

This is the python-tutor mailing list: we help in teaching how to program
in Python.  However, we aren't the technical support group for the Mailman
mailing list software, and we probably won't be able to help you because
we have no special knowledge of their product.

Try asking the 'Mailman Users' list instead:

http://list.org/lists.html

Good luck to you.

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


Re: [Tutor] question on string

2005-08-01 Thread Danny Yoo


On Mon, 1 Aug 2005, Kent Johnson wrote:

> > I would like to construct some string objects using the cprintf-style
> > format:
> >
> > command_string = "diff -u %s %s > %s.patch" % ( src, dst, file )
> >
> > Of course it is illegal in python but I couldn't figure out a way to
> > construct strings with that kind of formatting and substitution.
>
> Actually that is correct as written! (though 'file' is a poor choice of
> variable name as it shadows the built-in file() function...)


[text cut]

Just as a side note, building command strings like this is usually not a
good idea, just because of issues like shell quotation.

Unfortunately, there are a lot of examples on the web that do use string
interpolation to build up command lines, but there is usually a better
way:  Python comes with a subprocess module which can take a list of
arguments.  For example:

##
>>> import subprocess
>>> p = subprocess.Popen(['wc', '-l', '/usr/share/dict/words'],
...  stdout=subprocess.PIPE)
>>>
>>> p.stdout.read()
'234937 /usr/share/dict/words\n'
##

The advantage of passing a list instead of a formatted string here is that
we don't have to worry if our files contains spaces in their names.


Hope this helps!

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


[Tutor] counting problem

2005-08-01 Thread cgw501
hi,

I have large txt file with lines like this:

['DDB0216437']  116611749 ZZZ   100

What I want to do is quickly count the number of lines that share a value 
in the 4th column and 5th (i.e. in this line I would count all the line 
that have '9' and 'ZZZ'). Anyone got any ideas for the quickest way to do 
this? The solution I have is really ugly. thanks,

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


Re: [Tutor] Color text in Text widget

2005-08-01 Thread Jorge Louis de Castro
I found a way to do it but I'm not sure it is the cleanest. Maybe someone 
else on this list can offer a better solution.

I use the text's configuration to define tags that I apply to sections of 
the text. For example:

txtBox = Text(self, width=80, height=20)
# configuration for red
txtBox.tag_config("r", foreground="red")
# configuration for blue
txtBox.tag_config("b", foreground="blue")

txtBox.insert(END,"I am red ", "r")
txtBox.insert(END,"and I am blue\n", "b")

Hope that helps
jorge

>From: sunny sunny <[EMAIL PROTECTED]>
>To: tutor@python.org
>Subject: [Tutor] Color text in Text widget
>Date: Mon, 1 Aug 2005 15:35:52 -0400
>
>Hi all,
>
>How do I add color to the text in the Text widget? I tried using the
>ASCII sequence but it didnt work.
>
>For example, I want to add:
>  This is  red , but this is  blue 
>
>Thanks.
>Santosh.
>___
>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] counting problem

2005-08-01 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> hi,
> 
> I have large txt file with lines like this:
> 
> ['DDB0216437']116611749 ZZZ   100
> 
> What I want to do is quickly count the number of lines that share a value 
> in the 4th column and 5th (i.e. in this line I would count all the line 
> that have '9' and 'ZZZ'). Anyone got any ideas for the quickest way to do 
> this? The solution I have is really ugly. thanks,

This should get you started. It assumes that there is no whitespace embedded in 
the fields. Add error handling and options to taste.

Kent

count = 0
f = open('data.txt')
for line in f:
  data = line.split()
  if data[3] == '9' and data[4] == 'ZZZ':
count += 1
f.close()
print count

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


Re: [Tutor] Socket Programming

2005-08-01 Thread Adam Bark
Hi Joe you can use 1 and just send 'Hi!' as long as something else
isn't likely to be sent at the same time. It will just read what is in
that socket when you call it so if something else that you don't want
is there just behind what you're after then you could end up with that
as well.On 8/1/05, Joseph Quigley <[EMAIL PROTECTED]> wrote:
Hi,Ok. But what if I wanted to send a 1 mb message? Could I leave.recv(1) in and send 'Hi!' as well or would I have to change it?Thanks,JQAdam Bark wrote:> You have to put in how many bytes of data you want to recieve in
> clientsocket.recv() eg. clientsocket.recv(1024) for 1kB.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] I've run into a jam on the exercise on file I/O

2005-08-01 Thread Nathan Pinno



Hey all,
I've seem to run into a jam while working on the exercise on file 
I/O.
Here's the error:
Filename to save: university.txtTraceback (most recent call 
last):  File "D:\Python22\grades.py", line 99, in 
?    save_grades(students,filename)  File 
"D:\Python22\grades.py", line 51, in save_grades    
out_file.write(x+","+max_points[x]+"\n")TypeError: sequence index must be 
integer
 
And the code:
max_points = [25,25,50,25,100]assignments = ['hw ch 1','hw ch 
2','quiz   ','hw ch 3','test']students = {'#Max':max_points}
 
def print_menu():    print "1. Add 
student"    print "2. Remove student"    
print "3. Print grades"    print "4. Record 
grade"    print "5. Load Grades"    print 
"6. Save Grades"    print "9. Exit"
 
def print_all_grades():    print 
'\t',    for i in 
range(len(assignments)):    print 
assignments[1],'\t',    print    keys = 
students.keys()    keys.sort()    for x in 
keys:    print 
x,'\t',    grades = 
students[x]    
print_grades(grades)
 
def print_grades(grades):    for i in 
range(len(grades)):    print 
grades[i],'\t\t',    print
 
def choice():    return int(raw_input("Menu Choice: 
"))
 
def school():    return raw_input("Student: ")
 
def load_grades(students,filename):    in_file = 
open(filename, "r")    while 
1:    in_line = 
in_file.readline()    if in_line == 
"":    
break    in_line = 
in_line[:-1]    [students,max_points] 
= string.split(in_line,",")    
max_points[students] = grade    in_file.close()
 
def save_grades(students,filename):    out_file = 
open(filename, "w")    for x in 
students.keys():    
out_file.write(x+","+max_points[x]+"\n")    
out_file.close
 
print "Grade Tracking Program."while 1:    
print_menu()    menu_choice = choice()    
if menu_choice == 1:    print "Add 
student"    name = 
school()    students[name] = 
[0]*len(max_points)    elif menu_choice == 
2:    print "Remove 
student"    name = 
school()    if 
students.has_key(name):    
del students[name]    
else:    
print "Student: ",name," not found."    elif menu_choice == 
3:    print_all_grades()
 
    elif menu_choice == 
4:    print "Record 
Grade"    name = 
school()    if 
students.has_key(name):    
grades = 
students[name]    
print "Type in the number of the grade to 
record"    
print "Type in a 0 (zero) to 
exit"    for 
i in 
range(len(assignments)):    
print i+1,' 
',assignments[i],'\t',    
print    
print_grades(grades)    
which = 
1234    while 
which != 
-1:    
which = int(raw_input("Change which Grade: 
"))    
which = 
which-1    
if 0 <= which < 
len(grades):    
grade = int(raw_input("Grade: 
"))    
grades[which] = 
grade    
elif which != 
-1:    
print "Invalid Grade 
Number"    
else:    
print "Student not found"    elif menu_choice == 
5:    filename = raw_input("Filename 
to load: ")    
load_grades(students,filename)    elif menu_choice == 
6:    filename = raw_input("Filename 
to save: ")    
save_grades(students,filename)    elif menu_choice == 
9:    break    
else:    print "That's not a 
choice!"print "Goodbye."
What's the problem, and how is it fixed?
 
Thanks,
Nathan Pinno,Crew, Camrose McDonalds and owner/operator of 
Woffee
BEGIN:VCARD
VERSION:2.1
N:Pinno;Nathan;Paul;Mr.
FN:Pinno, Nathan Paul
ORG:Woffee;Executive
TITLE:Owner/operator
TEL;CELL;VOICE:7806085529
ADR;WORK:;President/CEO
LABEL;WORK:President/CEO
ADR;HOME:;;Box 1783;Camrose;Alberta;T4V1X7;Canada
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:Box 1783=0D=0ACamrose, Alberta T4V1X7=0D=0ACanada
X-WAB-GENDER:2
URL;HOME:http://falcon3166.tripod.com
URL;WORK:http://falcon3166.tripod.com/Woffee.htm
BDAY:19850221
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
REV:20050801T203918Z
END:VCARD
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] counting problem

2005-08-01 Thread Danny Yoo


On Mon, 1 Aug 2005, Kent Johnson wrote:

> [EMAIL PROTECTED] wrote:
> > hi,
> >
> > I have large txt file with lines like this:
> >
> > ['DDB0216437']  116611749 ZZZ   100
> >
> > What I want to do is quickly count the number of lines that share a
> > value in the 4th column and 5th (i.e. in this line I would count all
> > the line that have '9' and 'ZZZ'). Anyone got any ideas for the
> > quickest way to do this? The solution I have is really ugly. thanks,


A dictionary approach may also be useful.  The following example should
help illustrate the technique:

##
>>> def histogram(iterable):
... """Returns a list of counts of each unique element in iterable."""
... d = {}
... for x in iterable:
... d[x] = d.get(x, 0) + 1
... return d.items()
...
>>> histogram("this is a test of the emergency broadcast system this is
only a test")
[('a', 4), (' ', 13), ('c', 2), ('b', 1), ('e', 7), ('d', 1), ('g', 1),
 ('f', 1), ('i', 4), ('h', 3), ('m', 2), ('l', 1), ('o', 3), ('n', 2),
 ('s', 9), ('r', 2), ('t', 9), ('y', 3)]
##

This is a fairly straightforward way of doing letter-frequency stuff.  We
can see from the histogram that the letters {'d', 'f', 'g', 'l'] are
solitary and occur only once.

This tallying approach can also be applied to the original poster's
question with the columns of a text file, as long as we figure out what we
want to tally up.


Good luck!

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


Re: [Tutor] I've run into a jam on the exercise on file I/O

2005-08-01 Thread Adam Bark
>>> max_points = [25,25,50,25,100]
>>> assignments = ['hw ch 1','hw ch 2','quiz   ','hw ch 3','test']
>>> students = {'#Max':max_points}
>>> students
{'#Max': [25, 25, 50, 25, 100]}

The problem is the key in students is a list not an integer.On 8/1/05, Nathan Pinno <[EMAIL PROTECTED]
> wrote:






Hey all,
I've seem to run into a jam while working on the exercise on file 
I/O.
Here's the error:
Filename to save: university.txtTraceback (most recent call 
last):  File "D:\Python22\grades.py", line 99, in 
?    save_grades(students,filename)  File 
"D:\Python22\grades.py", line 51, in save_grades    
out_file.write(x+","+max_points[x]+"\n")TypeError: sequence index must be 
integer
 
And the code:
max_points = [25,25,50,25,100]assignments = ['hw ch 1','hw ch 
2','quiz   ','hw ch 3','test']students = {'#Max':max_points}
 
def print_menu():    print "1. Add 
student"    print "2. Remove student"    
print "3. Print grades"    print "4. Record 
grade"    print "5. Load Grades"    print 
"6. Save Grades"    print "9. Exit"
 
def print_all_grades():    print 
'\t',    for i in 
range(len(assignments)):    print 
assignments[1],'\t',    print    keys = 
students.keys()    keys.sort()    for x in 
keys:    print 
x,'\t',    grades = 
students[x]    
print_grades(grades)
 
def print_grades(grades):    for i in 
range(len(grades)):    print 
grades[i],'\t\t',    print
 
def choice():    return int(raw_input("Menu Choice: 
"))
 
def school():    return raw_input("Student: ")
 
def load_grades(students,filename):    in_file = 
open(filename, "r")    while 
1:    in_line = 
in_file.readline()    if in_line == 
"":    
break    in_line = 
in_line[:-1]    [students,max_points] 
= string.split(in_line,",")    
max_points[students] = grade    in_file.close()
 
def save_grades(students,filename):    out_file = 
open(filename, "w")    for x in 
students.keys():    
out_file.write(x+","+max_points[x]+"\n")    
out_file.close
 
print "Grade Tracking Program."while 1:    
print_menu()    menu_choice = choice()    
if menu_choice == 1:    print "Add 
student"    name = 
school()    students[name] = 
[0]*len(max_points)    elif menu_choice == 
2:    print "Remove 
student"    name = 
school()    if 
students.has_key(name):    
del students[name]    
else:    
print "Student: ",name," not found."    elif menu_choice == 
3:    print_all_grades()
 
    elif menu_choice == 
4:    print "Record 
Grade"    name = 
school()    if 
students.has_key(name):    
grades = 
students[name]    
print "Type in the number of the grade to 
record"    
print "Type in a 0 (zero) to 
exit"    for 
i in 
range(len(assignments)):    
print i+1,' 
',assignments[i],'\t',    
print    
print_grades(grades)    
which = 
1234    while 
which != 
-1:    
which = int(raw_input("Change which Grade: 
"))    
which = 
which-1    
if 0 <= which < 
len(grades):    
grade = int(raw_input("Grade: 
"))    
grades[which] = 
grade    
elif which != 
-1:    
print "Invalid Grade 
Number"    
else:    
print "Student not found"    elif menu_choice == 
5:    filename = raw_input("Filename 
to load: ")    
load_grades(students,filename)    elif menu_choice == 
6:    filename = raw_input("Filename 
to save: ")    
save_grades(students,filename)    elif menu_choice == 
9:    break    
else:    print "That's not a 
choice!"print "Goodbye."
What's the problem, and how is it fixed?
 
Thanks,
Nathan Pinno,Crew, Camrose McDonalds and owner/operator of 
Woffee

___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] I've run into a jam on the exercise on file I/O

2005-08-01 Thread Nathan Pinno



Maybe I should use assignments instead?

  - Original Message - 
  From: 
  Adam Bark 
  
  To: Nathan Pinno 
  Cc: tutor@python.org 
  Sent: Monday, August 01, 2005 2:47 
  PM
  Subject: Re: [Tutor] I've run into a jam 
  on the exercise on file I/O
  >>> max_points = [25,25,50,25,100]>>> 
  assignments = ['hw ch 1','hw ch 2','quiz   ','hw ch 
  3','test']>>> students = {'#Max':max_points}>>> 
  students{'#Max': [25, 25, 50, 25, 100]}The problem is the key in 
  students is a list not an integer.
  On 8/1/05, Nathan 
  Pinno <[EMAIL PROTECTED] 
  > wrote:
  
Hey all,
I've seem to run into a jam while working on the exercise on file 
I/O.
Here's the error:
Filename to save: university.txtTraceback (most recent call 
last):  File "D:\Python22\grades.py", line 99, in 
?    save_grades(students,filename)  File 
"D:\Python22\grades.py", line 51, in save_grades    
out_file.write(x+","+max_points[x]+"\n")TypeError: sequence index must 
be integer
 
And the code:
max_points = [25,25,50,25,100]assignments = ['hw ch 1','hw ch 
2','quiz   ','hw ch 3','test']students = 
{'#Max':max_points}
 
def print_menu():    print "1. Add 
student"    print "2. Remove 
student"    print "3. Print grades"    
print "4. Record grade"    print "5. Load 
Grades"    print "6. Save Grades"    
print "9. Exit"
 
def print_all_grades():    print 
'\t',    for i in 
range(len(assignments)):    print 
assignments[1],'\t',    print    keys 
= students.keys()    keys.sort()    
for x in keys:    print 
x,'\t',    grades = 
students[x]    
print_grades(grades)
 
def print_grades(grades):    for i in 
range(len(grades)):    print 
grades[i],'\t\t',    print
 
def choice():    return int(raw_input("Menu Choice: 
"))
 
def school():    return raw_input("Student: ")
 
def load_grades(students,filename):    in_file = 
open(filename, "r")    while 
1:    in_line = 
in_file.readline()    if in_line 
== "":    
break    in_line = 
in_line[:-1]    
[students,max_points] = 
string.split(in_line,",")    
max_points[students] = grade    in_file.close()
 
def save_grades(students,filename):    out_file = 
open(filename, "w")    for x in 
students.keys():    
out_file.write(x+","+max_points[x]+"\n")    
out_file.close
 
print "Grade Tracking Program."while 1:    
print_menu()    menu_choice = 
choice()    if menu_choice == 
1:    print "Add 
student"    name = 
school()    students[name] = 
[0]*len(max_points)    elif menu_choice == 
2:    print "Remove 
student"    name = 
school()    if 
students.has_key(name):    
del students[name]    
else:    
print "Student: ",name," not found."    elif menu_choice 
== 3:    print_all_grades()
 
    elif menu_choice == 
4:    print "Record 
Grade"    name = 
school()    if 
students.has_key(name):    
grades = 
students[name]    
print "Type in the number of the grade to 
record"    
print "Type in a 0 (zero) to 
exit"    
for i in 
range(len(assignments)):    
print i+1,' 
',assignments[i],'\t',    
print    
print_grades(grades)    
which = 
1234    
while which != 
-1:    
which = int(raw_input("Change which Grade: 
"))    
which = 
which-1    
if 0 <= which < 
len(grades):    
grade = int(raw_input("Grade: 
"))    
grades[which] = 
grade    
elif which != 
-1:    
print "Invalid Grade 
Number"    
else:    
print "Student not found"    elif menu_choice == 
5:    filename = 
raw_input("Filename to load: 
")    
load_grades(students,filename)    elif menu_choice == 
6:    filename = 
raw_input("Filename to save: 
")    
save_grades(students,filename)    elif menu_choice == 
9:    break    
else:    print "That's not a 
choice!"print "Goodbye."
What's the problem, and how is it fixed?
 
Thanks,
Nathan Pinno,Crew, Camrose McDonalds and owner/operator of 
Woffee___Tutor 
maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I've run into a jam on the exercise on file I/O

2005-08-01 Thread Adam Bark
No sorry scratch that last one I was being stupid. The key is a string
but max_points is a list so the list index max_points[x] is effectively
looking for max_points[student].

def save_grades(students,filename):
    out_file = 
open(filename, "w")
    for x in 
students.keys():
    
out_file.write(x+","+max_points[x]+"\n")    
out_file.closeOn 8/1/05, Adam Bark <[EMAIL PROTECTED]> wrote:
>>> max_points = [25,25,50,25,100]
>>> assignments = ['hw ch 1','hw ch 2','quiz   ','hw ch 3','test']
>>> students = {'#Max':max_points}
>>> students
{'#Max': [25, 25, 50, 25, 100]}

The problem is the key in students is a list not an integer.On 8/1/05, Nathan Pinno <
[EMAIL PROTECTED]
> wrote:






Hey all,
I've seem to run into a jam while working on the exercise on file 
I/O.
Here's the error:
Filename to save: university.txtTraceback (most recent call 
last):  File "D:\Python22\grades.py", line 99, in 
?    save_grades(students,filename)  File 
"D:\Python22\grades.py", line 51, in save_grades    
out_file.write(x+","+max_points[x]+"\n")TypeError: sequence index must be 
integer
 
And the code:
max_points = [25,25,50,25,100]assignments = ['hw ch 1','hw ch 
2','quiz   ','hw ch 3','test']students = {'#Max':max_points}
 
def print_menu():    print "1. Add 
student"    print "2. Remove student"    
print "3. Print grades"    print "4. Record 
grade"    print "5. Load Grades"    print 
"6. Save Grades"    print "9. Exit"
 
def print_all_grades():    print 
'\t',    for i in 
range(len(assignments)):    print 
assignments[1],'\t',    print    keys = 
students.keys()    keys.sort()    for x in 
keys:    print 
x,'\t',    grades = 
students[x]    
print_grades(grades)
 
def print_grades(grades):    for i in 
range(len(grades)):    print 
grades[i],'\t\t',    print
 
def choice():    return int(raw_input("Menu Choice: 
"))
 
def school():    return raw_input("Student: ")
 
def load_grades(students,filename):    in_file = 
open(filename, "r")    while 
1:    in_line = 
in_file.readline()    if in_line == 
"":    
break    in_line = 
in_line[:-1]    [students,max_points] 
= string.split(in_line,",")    
max_points[students] = grade    in_file.close()
 
def save_grades(students,filename):    out_file = 
open(filename, "w")    for x in 
students.keys():    
out_file.write(x+","+max_points[x]+"\n")    
out_file.close
 
print "Grade Tracking Program."while 1:    
print_menu()    menu_choice = choice()    
if menu_choice == 1:    print "Add 
student"    name = 
school()    students[name] = 
[0]*len(max_points)    elif menu_choice == 
2:    print "Remove 
student"    name = 
school()    if 
students.has_key(name):    
del students[name]    
else:    
print "Student: ",name," not found."    elif menu_choice == 
3:    print_all_grades()
 
    elif menu_choice == 
4:    print "Record 
Grade"    name = 
school()    if 
students.has_key(name):    
grades = 
students[name]    
print "Type in the number of the grade to 
record"    
print "Type in a 0 (zero) to 
exit"    for 
i in 
range(len(assignments)):    
print i+1,' 
',assignments[i],'\t',    
print    
print_grades(grades)    
which = 
1234    while 
which != 
-1:    
which = int(raw_input("Change which Grade: 
"))    
which = 
which-1    
if 0 <= which < 
len(grades):    
grade = int(raw_input("Grade: 
"))    
grades[which] = 
grade    
elif which != 
-1:    
print "Invalid Grade 
Number"    
else:    
print "Student not found"    elif menu_choice == 
5:    filename = raw_input("Filename 
to load: ")    
load_grades(students,filename)    elif menu_choice == 
6:    filename = raw_input("Filename 
to save: ")    
save_grades(students,filename)    elif menu_choice == 
9:    break    
else:    print "That's not a 
choice!"print "Goodbye."
What's the problem, and how is it fixed?
 
Thanks,
Nathan Pinno,Crew, Camrose McDonalds and owner/operator of 
Woffee

___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] visibility of variables

2005-08-01 Thread Alan G
> I have problems with the visibility of variables in python. I am
> used to the idea of Javascript and other languages where one can 
> define
> global variables if they are defined outside a function. It seems 
> Python
> is not doing that, but how can I make it work?

Kent has answered the question of how to do it in Python but I would
point out that using global variables is, in general, considered
bad practice. It is best to minimise their use as muh as possible
and pass data into functions and return values from them.

There usually are a few globals in any program so don't worry
too much about them. BUt on the otherhand if most of your functions
are writing to global variables then your program design probably
needs rethinking!

> around this? I could add gemetenkleur in the argument list of the 
> funct1
> and funct2 functions, but in my case I don't want this (funct1 will 
> be a
> function to be used in scipy.fmin, and I have the idea that only the
> simplex can be as an argument).

Passing the values as arguments would IMHO be much better in your case
Consider your code, slightly rewritten (with shorter names! :-) to 
reflect
what I think you are trying to do:

b=[(1,2,3),(3,4,5),(5,6,7)]

def funct1(g):
print 'g in func1: ',g
a=funct2(g)
print a

def funct2(k):
   print 'k in funct2 (should be same as g): ',k
   return 1

def Do(b,f):
   g=b[:]
   print 'g has to be from now b: ',g
   f(g)
   return g

G = Do(b,funct1)
print G

> Hope someone can help me. I have the idea this is essential to
> understand before continuing more in Python.

You might also look at the 'What's in a Name' topic in my tutor
for more on this (There is a slightly old German translation too).

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] try except continue

2005-08-01 Thread tpc247
hi guys, so I've been running through Alan's code, and for a while I
suspected that the try block must be the first line of code after the
loop in order to be executed.  The reason I say this is I wanted to
see for myself Alan's assertion that the continue skips to the next
iteration, instead of continuing with the rest of the try block, so I
did the following:

def f():
if error:
raise ValueError
else:
print "I'm in f()"

def g():
print "I'm in g()"


def h():
error = True
print "error is: ", error
n = 5
while n:
print "n is: ", n
n -= 1
try:
f()
g()
except ValueError:
error = False
continue

and I got the following as output:

>>> h()
error is:  True
n is:  5
n is:  4
n is:  3
n is:  2
n is:  1

I gathered that since I didn't see the output of f() and g(), then
those two functions must have never executed, and thus the try block
must have never executed.  However, when I moved the try block to be
the first line after the loop:

def h():
error = True
print "error is: ", error
n = 5
while n:
try:
f()
g()
except ValueError:
error = False
continue
print "n is: ", n
n -= 1

I got the following as output:

>>> h()
error is:  True

Traceback (most recent call last):
  File "", line 1, in -toplevel-
h()
  File "", line 9, in h
except ValueError:
KeyboardInterrupt

and I actually had to press Ctrl-C to stop the never terminating
program.  I simply wanted to confirm Alan's assertion that continue
will cause the loop to skip to the next iteration, but it seems I
can't seem to get my f() and g() to print even though they were able
to before.  Am I doing something wrong ?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I've run into a jam on the exercise on file I/O

2005-08-01 Thread Danny Yoo


On Mon, 1 Aug 2005, Nathan Pinno wrote:

> I've seem to run into a jam while working on the exercise on file I/O.
> Here's the error:
> Filename to save: university.txt
> Traceback (most recent call last):
>   File "D:\Python22\grades.py", line 99, in ?
> save_grades(students,filename)
>   File "D:\Python22\grades.py", line 51, in save_grades
> out_file.write(x+","+max_points[x]+"\n")
> TypeError: sequence index must be integer


Hi Nathan,


I'll try to capture what I think of when I see error messages like this,
to better illustrate how to take something like this, and puzzle it
through.


Let's take a close look at the error message, first:

> TypeError: sequence index must be integer

Python doesn't like some place where we're doing an indexing operation.
Where would that be?


Let's look at the line that Python pointed out, around line 99.

> out_file.write(x+","+max_points[x]+"\n")

The only indexing operation I can see here is the subexpression:

max_points[x]

and the error makes sense if if 'x' isn't a number.  Let's take a look at
where 'x' is being assigned, and see if we're assigning it to a
non-number.


> def save_grades(students,filename):
> out_file = open(filename, "w")
> for x in students.keys():
> out_file.write(x+","+max_points[x]+"\n")
> out_file.close

Ok, 'x' comes from the keys of our 'students' dictionary.  Now our problem
turns into: are the keys of the students dictionary numbers, or are they
something else?


At a high level, we're trying to determine: is our use of max_points[x] in
the save_grades() function the thing that's broken, or is the value 'x'
that's broken?

For the moment, we'll follow 'x', and if that turns out ok, then we should
go back to save_grades() and see what it's trying to write out.  (We can
do things in the other order, too, of course.  Flip a coin.  *grin*)


Let's look at how 'students' is being constructed, since the values of 'x'
comes from the keys of the 'students' dictionary.

##
> max_points = [25,25,50,25,100]
> assignments = ['hw ch 1','hw ch 2','quiz   ','hw ch 3','test']
> students = {'#Max':max_points}
##

Ok.  We certainly see that one of the keys in the 'students' dictionary
isn't a number, so at least we can confirm the error message.  '#Max', for
example, is certainly not a number.


What is 'students' supposed to represent?  That is, can we try describing
what the keys are supposed to be, and what the values are supposed to be?

I will guess that you're thinking of it more like a table, with:

#Max | [25, 25, 50, 25, 100]
-+---
   Danny | [20, 20, 40, 20, 90]
   Nick  | [25, 25, 49, 24, 99]


where the keys are student names, and the values are their respective test
scores.  It might be good to rename 'students' to 'student_grades' then,
to make that relationship more clear.


Anyway, in that case, the 'students' dictionary actually looks fine: it
contains the right thing.  Ok, let's go back to the definition of
save_grades():

> def save_grades(students,filename):
> out_file = open(filename, "w")
> for x in students.keys():
> out_file.write(x+","+max_points[x]+"\n")
> out_file.close

and, for the moment, let's completely ignore the body of the function, and
just imagine: what do we imagine should happen when we save the grades to
disk?  It should read off the students (the "student to grades")
dictionary, and write it to disk.

Let's look back at the body of save_grades() now.  How does max_points
relate to writing out all of the students and their grades to disk?  Does
it really matter, or did we mean to use a different value?



Please feel free to ask questions on any point of this.  Good luck!

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


Re: [Tutor] question on string

2005-08-01 Thread Alan G
> I would like to construct some string objects using the 
> cprintf-style format:
>
> command_string = "diff -u %s %s > %s.patch" % ( src, dst, file )

Should work - assuming the 3 variables are defined! Although file
is a bad name for a variable since its also the name of the
function for opening files!

> Of course it is illegal in python but I couldn't figure out a way to 
> construct strings with that kind of formatting and substitution.

What makes you think it is illegal? Did you get an error?
If so what did it look like (full text please).

> I have been looking and couldn't discover string constructor such as
>
> command_string = string( "diff -u %s %s > %s.patch" % ( src, dst, 
> file ) )

You don't need a constructor as such just use the quotes as in the 
first
attempt above.

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] question on string

2005-08-01 Thread Bob Gailer


At 10:42 AM 8/1/2005, Gilbert Tsang wrote:
Hi there,
I would like to construct some string objects using the cprintf-style
format:
command_string = "diff -u %s %s > %s.patch" % ( src, dst,
file )
Of course it is illegal in python 
How did you conclude that? "diff -u %s %s > %s.patch" % (
src, dst, file ) is a Python _expression_, and will do what you
want!
See
http://docs.python.org/lib/typesseq-strings.html
for the official documentation.
but I couldn't figure out a way to 
construct strings with that kind of formatting and substitution.
I have been looking and couldn't discover string constructor such as
command_string = string( "diff -u %s %s > %s.patch" % ( src, dst, file ) )
 From the documentation on docs.python.org, the closest is string 
Template (but my python installation doesn't come with this module). Any 
insights on initializing string in this manner?

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

Bob Gailer
phone 510 978 4454 

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


Re: [Tutor] counting problem

2005-08-01 Thread Alan G
> What I want to do is quickly count the number of lines that share a 
> value in the 4th column and 5th (i.e. in this line I would count all 
> the line that have '9' and 'ZZZ'). Anyone got any ideas for the 
> quickest way to do this? The solution I have is really ugly. thanks,

Pesonally I'd just use awk:

$ awk '$4==9 && $5=="ZZZ" {count++} END {printf count}' myfile.dat

Should do it.

Alan G. 

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


Re: [Tutor] Color text in Text widget

2005-08-01 Thread Alan G
> I use the text's configuration to define tags that I apply to 
> sections of the text. For example:
>
> txtBox = Text(self, width=80, height=20)
> # configuration for red
> txtBox.insert(END,"I am red ", "r")

I don't know if it's the absolute best way but I didn't know you could
do that and I think its pretty neat! Pesonally I'd have been manually
changing the foreground colour before each insert!

Thanks for sharing.

Alan G.

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


Re: [Tutor] question on string

2005-08-01 Thread Gilbert Tsang




Thank you all for the enthusiastic responses. It must have been other
part of the script since the command string construction now works. I
also realized that "file" is a poor choice of variable name. Thanks
Danny for telling me about the subprocess module.

Best regards, Gilbert.


ZIYAD A. M. AL-BATLY wrote:

  On Mon, 2005-08-01 at 10:42 -0700, Gilbert Tsang wrote:
  
  
Hi there,

I would like to construct some string objects using the cprintf-style 
format:

command_string = "diff -u %s %s > %s.patch" % ( src, dst, file )

Of course it is illegal in python but I couldn't figure out a way to 
construct strings with that kind of formatting and substitution.

I have been looking and couldn't discover string constructor such as

command_string = string( "diff -u %s %s > %s.patch" % ( src, dst, file ) )

 From the documentation on docs.python.org, the closest is string 
Template (but my python installation doesn't come with this module). Any 
insights on initializing string in this manner?


Thanks, Gilbert.

  
  "file" is a reserved word!  This is why it's not working for you!
Change "file" to something else, like "result" for example.

Here:
>>> src = ''
>>> dst = 'file2.c'
>>> result = "result"
>>> command_string = "diff -u %s %s > %s.patch" % (src, dst, result)
>>> command_string
'diff -u file1.c file2.c > result.patch'

Is this what you want?

Ziyad.
  




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


[Tutor] Question

2005-08-01 Thread Nathan Pinno



Hi all,
 
Just curious to wonder if Python can be used to write a program to check an 
HTTP mail server for mail, and check more than one server, even if they are 
using different proxies, i.e. HTTP for one and SMTP for the other.
 
Thanks,
Nathan Pinno,Crew, Camrose McDonalds and owner/operator of 
Woffee
BEGIN:VCARD
VERSION:2.1
N:Pinno;Nathan;Paul;Mr.
FN:Pinno, Nathan Paul
ORG:Woffee;Executive
TITLE:Owner/operator
TEL;CELL;VOICE:7806085529
ADR;WORK:;President/CEO
LABEL;WORK:President/CEO
ADR;HOME:;;Box 1783;Camrose;Alberta;T4V1X7;Canada
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:Box 1783=0D=0ACamrose, Alberta T4V1X7=0D=0ACanada
X-WAB-GENDER:2
URL;HOME:http://falcon3166.tripod.com
URL;WORK:http://falcon3166.tripod.com/Woffee.htm
BDAY:19850221
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
REV:20050801T213328Z
END:VCARD
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform

2005-08-01 Thread Jeff Peery
thanks for the help. I think I'm understanding this a bit better. although I still don't completely understand the output. here is an example... for the input I have 1024 samples taken from a 1 Hz square wave with amplitude = 1.  for the output I would expect an infinite number of frequencies. the output from FFT.fft(myData).real is this:
 
.
.
.
-0.498 10.0 2-0.498 30.0 4-0.498 50.0 6-0.498 70.0 8-0.498 90.0 10-0.498 110.0 12-0.498 130.0 14-0.498 150.0 16-0.498 17
.
..
 
I'm not sure why the output alternates from 0 and 0.498. I would expect 0.498 at all frequencies? why the oscillation?
 
Christian Meesters <[EMAIL PROTECTED]> wrote:
Jeff Peery wrote:>> Hello, I have a signal that I want to do a fourier transform on. I > tried using FFT.fft(data).real but I don't understand the output. > what is output from this function, and why doesn't it require > amplitude and time as inputs?Hi Jeff,As Danny wrote, your input are real numbers and your output will be complex numbers. I don't want to point you to the numarray documentation once more, but you might to check out this: http://mathworld.wolfram.com/FourierSeries.html as for why you get complex numbers back. (To get only the real value part try real_fft() in numarrayl.)In general in numerical computation your input is simply a series of real numbers - of equal spacing in the dimension you want to consider. Which dimension you choose (amplitudes and time/phase or amplitudes and
 spacial frequencies and so on) is up to you. It depends on your physical or mathematical question. IMHO the best introduction you can get on Fourier Transforms & programming can be found in Numerical Recipies (here the "Numerical Recipies in C"-link http://www.library.cornell.edu/nr/bookcpdf.html - check chapter 12).Have fun with FFTs!CheersChristian___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform

2005-08-01 Thread Danny Yoo


On Mon, 1 Aug 2005, Jeff Peery wrote:

> thanks for the help. I think I'm understanding this a bit better.
> although I still don't completely understand the output. here is an
> example... for the input I have 1024 samples taken from a 1 Hz square
> wave with amplitude = 1.  for the output I would expect an infinite
> number of frequencies. the output from FFT.fft(myData).real is this:

[data cut]

> I would expect 0.498 at all frequencies? why the oscillation?


That actually sounds fine.  By a square wave, you mean something like:

---  ---  ---
  |  |  | |
  |  |  | |
   --   ---

and according to the MathWorld documentation that Christian mentioned,

http://mathworld.wolfram.com/FourierSeries.html

according to analysis, the square wave does have a Fourier transform that
oscillates the way that you've observing:

http://mathworld.wolfram.com/FourierSeriesSquareWave.html

where the coefficients are zero on the even n.  So I think you're actually
getting correct values there.


Good luck!

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


Re: [Tutor] fourier transform

2005-08-01 Thread Jeff Peery
ok, this makes more sense. what I want to know is the amplitude for the output frequencies. I'm using import FFT, and FFT.fft(). the first element of the output is the DC constant? not sure what this is. is the amplitude for all other elements plus the DC equal to the actual amplitude?
 
thanks.Pawel Kraszewski <[EMAIL PROTECTED]> wrote:
> Hello, I have a signal that I want to do a fourier transform on. I tried> using FFT.fft(data).real but I don't understand the output. what is output> from this function, and why doesn't it require amplitude and time as> inputs?Please write the package you use for FFT. Standard Python doesn't have one. Perhaps you use some custom Python? Like Enthought Python? If so, the exhaustive guide is delivered with it in CHM (windows help) format.1. In general FFT algorithms require you to supply just N complex values (complex contains both amplitude and phase of signal). If you supply real values, the system assumes phase=0 for each sample and takes given value for amplitude.2. You DO supply a time information, you just didn't think of it this way: each consecutive sample is taken one fixed clock tick later, so p!
 osition
 of sample in data gives you the time it was taken.3. Results of FFT are in the form of complex vector of the same length as data. Starting from position 0 it gives you an constant (DC factor), position 1 an amplitude and phase (remember - complex number gives you both amplitude and phase) of wave of the length table/2 and so on. If you take real value of this, you discard part of the information. AFAIR - taking real part gives you sine component, taking imaginary part gives you cosine component, taking absolute value gives you total amplitude and taking angle gives you phase.4. The answer is symmetrical - usually you take only half of it. I don't remember the exact difference between the halves, but you may find it in any article on FFT.Best regards,Pawel Kraszewski___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform

2005-08-01 Thread Jeff Peery
ok, this makes more sense. what I want to know is the amplitude for the output frequencies. I'm using import FFT, and FFT.fft(). the first element of the output is the DC constant? not sure what this is. is the amplitude for all other elements plus the DC equal to the actual amplitude?
 
thanks.Pawel Kraszewski <[EMAIL PROTECTED]> wrote:
> Hello, I have a signal that I want to do a fourier transform on. I tried> using FFT.fft(data).real but I don't understand the output. what is output> from this function, and why doesn't it require amplitude and time as> inputs?Please write the package you use for FFT. Standard Python doesn't have one. Perhaps you use some custom Python? Like Enthought Python? If so, the exhaustive guide is delivered with it in CHM (windows help) format.1. In general FFT algorithms require you to supply just N complex values (complex contains both amplitude and phase of signal). If you supply real values, the system assumes phase=0 for each sample and takes given value for amplitude.2. You DO supply a time information, you just didn't think of it this way: each consecutive sample is taken one fixed clock tick later, so p!
 osition
 of sample in data gives you the time it was taken.3. Results of FFT are in the form of complex vector of the same length as data. Starting from position 0 it gives you an constant (DC factor), position 1 an amplitude and phase (remember - complex number gives you both amplitude and phase) of wave of the length table/2 and so on. If you take real value of this, you discard part of the information. AFAIR - taking real part gives you sine component, taking imaginary part gives you cosine component, taking absolute value gives you total amplitude and taking angle gives you phase.4. The answer is symmetrical - usually you take only half of it. I don't remember the exact difference between the halves, but you may find it in any article on FFT.Best regards,Pawel Kraszewski___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] try except continue

2005-08-01 Thread Alan G
-- code here -
def f():
  if error:
raise ValueError
  else:
print "I'm in f()"

def g():
  print "I'm in g()"


def h():
  error = True
  print "error is: ", error
  n = 5
  while n:
print "n is: ", n
n -= 1
try:
  f()
  g()
except ValueError:
error = False
continue

h()

--

The above fails because error is a local variable in h() so is not 
visible
in f(). If we pass error as an argument to f it works as expected:

$ python testry.py
error is:  True
n is:  5
n is:  4
I'm in f()
I'm in g()
n is:  3
I'm in f()
I'm in g()
n is:  2
I'm in f()
I'm in g()
n is:  1
I'm in f()
I'm in g()

It sounds like you are still struggling with this concept however.
Is there anything specificly that you don;t feel comfortable with?

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] I've run into a jam on the exercise on file I/O

2005-08-01 Thread Nathan Pinno
What if I were to use ID's for the students and use the ID's as the sequence 
index, and link the students and their grades to the IDs?

Just a suggestion,
Nathan Pinno
- Original Message - 
From: "Danny Yoo" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>
Cc: "Tutor" 
Sent: Monday, August 01, 2005 3:03 PM
Subject: Re: [Tutor] I've run into a jam on the exercise on file I/O


>
>
> On Mon, 1 Aug 2005, Nathan Pinno wrote:
>
>> I've seem to run into a jam while working on the exercise on file I/O.
>> Here's the error:
>> Filename to save: university.txt
>> Traceback (most recent call last):
>>   File "D:\Python22\grades.py", line 99, in ?
>> save_grades(students,filename)
>>   File "D:\Python22\grades.py", line 51, in save_grades
>> out_file.write(x+","+max_points[x]+"\n")
>> TypeError: sequence index must be integer
>
>
> Hi Nathan,
>
>
> I'll try to capture what I think of when I see error messages like this,
> to better illustrate how to take something like this, and puzzle it
> through.
>
>
> Let's take a close look at the error message, first:
>
>> TypeError: sequence index must be integer
>
> Python doesn't like some place where we're doing an indexing operation.
> Where would that be?
>
>
> Let's look at the line that Python pointed out, around line 99.
>
>> out_file.write(x+","+max_points[x]+"\n")
>
> The only indexing operation I can see here is the subexpression:
>
>max_points[x]
>
> and the error makes sense if if 'x' isn't a number.  Let's take a look at
> where 'x' is being assigned, and see if we're assigning it to a
> non-number.
>
>
>> def save_grades(students,filename):
>> out_file = open(filename, "w")
>> for x in students.keys():
>> out_file.write(x+","+max_points[x]+"\n")
>> out_file.close
>
> Ok, 'x' comes from the keys of our 'students' dictionary.  Now our problem
> turns into: are the keys of the students dictionary numbers, or are they
> something else?
>
>
> At a high level, we're trying to determine: is our use of max_points[x] in
> the save_grades() function the thing that's broken, or is the value 'x'
> that's broken?
>
> For the moment, we'll follow 'x', and if that turns out ok, then we should
> go back to save_grades() and see what it's trying to write out.  (We can
> do things in the other order, too, of course.  Flip a coin.  *grin*)
>
>
> Let's look at how 'students' is being constructed, since the values of 'x'
> comes from the keys of the 'students' dictionary.
>
> ##
>> max_points = [25,25,50,25,100]
>> assignments = ['hw ch 1','hw ch 2','quiz   ','hw ch 3','test']
>> students = {'#Max':max_points}
> ##
>
> Ok.  We certainly see that one of the keys in the 'students' dictionary
> isn't a number, so at least we can confirm the error message.  '#Max', for
> example, is certainly not a number.
>
>
> What is 'students' supposed to represent?  That is, can we try describing
> what the keys are supposed to be, and what the values are supposed to be?
>
> I will guess that you're thinking of it more like a table, with:
>
>#Max | [25, 25, 50, 25, 100]
>-+---
>   Danny | [20, 20, 40, 20, 90]
>   Nick  | [25, 25, 49, 24, 99]
>
>
> where the keys are student names, and the values are their respective test
> scores.  It might be good to rename 'students' to 'student_grades' then,
> to make that relationship more clear.
>
>
> Anyway, in that case, the 'students' dictionary actually looks fine: it
> contains the right thing.  Ok, let's go back to the definition of
> save_grades():
>
>> def save_grades(students,filename):
>> out_file = open(filename, "w")
>> for x in students.keys():
>> out_file.write(x+","+max_points[x]+"\n")
>> out_file.close
>
> and, for the moment, let's completely ignore the body of the function, and
> just imagine: what do we imagine should happen when we save the grades to
> disk?  It should read off the students (the "student to grades")
> dictionary, and write it to disk.
>
> Let's look back at the body of save_grades() now.  How does max_points
> relate to writing out all of the students and their grades to disk?  Does
> it really matter, or did we mean to use a different value?
>
>
>
> Please feel free to ask questions on any point of this.  Good luck!
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform (fwd)

2005-08-01 Thread Danny Yoo


-- Forwarded message --
Date: Mon, 1 Aug 2005 16:21:33 -0700 (PDT)
From: Jeff Peery <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] fourier transform

Danny, thanks for the help. Yes, for an odd square wave the b's of the fourier 
series are non zero for even values and zero for odd values of n. these are the 
coefficients for the fourier series.  Although I beleive the fft (fourier 
transform) should return the amplitude of frequencies that exist. so for 
example a fft on a 10 hz sin wave with amplitude equal 2 should return all zero 
amplitudes except for at 10 hz there should be a spike with amplitude 2.  
although... this would be bn = 2 for n=1 in the fourier series. If I sample 
this same signal and use FFT.fft() on it the result is not all zeros except at 
10 hz. so I guess I'm still confused as to what the output is telling me. 
thanks again for everyones help.

Danny Yoo <[EMAIL PROTECTED]> wrote:


On Mon, 1 Aug 2005, Jeff Peery wrote:

> thanks for the help. I think I'm understanding this a bit better.
> although I still don't completely understand the output. here is an
> example... for the input I have 1024 samples taken from a 1 Hz square
> wave with amplitude = 1. for the output I would expect an infinite
> number of frequencies. the output from FFT.fft(myData).real is this:

[data cut]

> I would expect 0.498 at all frequencies? why the oscillation?


That actually sounds fine. By a square wave, you mean something like:

--- --- ---
| | | |
| | | |
-- ---

and according to the MathWorld documentation that Christian mentioned,

http://mathworld.wolfram.com/FourierSeries.html

according to analysis, the square wave does have a Fourier transform that
oscillates the way that you've observing:

http://mathworld.wolfram.com/FourierSeriesSquareWave.html

where the coefficients are zero on the even n. So I think you're actually
getting correct values there.


Good luck!


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


[Tutor] I need advice.

2005-08-01 Thread Nathan Pinno



Hey all,
 
I want to write a program that will convert time in any 
other time zone to my time zone. Would it be better to use the 
Python time molecule or just a whole bunch of if statements?
 
Waiting eagerly for an answer,
Nathan Pinno,Crew, Camrose McDonalds and owner/operator of 
Woffee
BEGIN:VCARD
VERSION:2.1
N:Pinno;Nathan;Paul;Mr.
FN:Pinno, Nathan Paul
ORG:Woffee;Executive
TITLE:Owner/operator
TEL;CELL;VOICE:7806085529
ADR;WORK:;President/CEO
LABEL;WORK:President/CEO
ADR;HOME:;;Box 1783;Camrose;Alberta;T4V1X7;Canada
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:Box 1783=0D=0ACamrose, Alberta T4V1X7=0D=0ACanada
X-WAB-GENDER:2
URL;HOME:http://falcon3166.tripod.com
URL;WORK:http://falcon3166.tripod.com/Woffee.htm
BDAY:19850221
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
REV:20050802T010103Z
END:VCARD
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question about BASIC and Python

2005-08-01 Thread Nathan Pinno



Hi all,
 
I had a co-worker say to me at work that Python was related to or based 
upon BASIC. Is this true, and if not, how can I tell my friend why they are 
similar?
 
Nathan Pinno,Crew, Camrose McDonalds and owner/operator of 
Woffee
BEGIN:VCARD
VERSION:2.1
N:Pinno;Nathan;Paul;Mr.
FN:Pinno, Nathan Paul
ORG:Woffee;Executive
TITLE:Owner/operator
TEL;CELL;VOICE:7806085529
ADR;WORK:;President/CEO
LABEL;WORK:President/CEO
ADR;HOME:;;Box 1783;Camrose;Alberta;T4V1X7;Canada
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:Box 1783=0D=0ACamrose, Alberta T4V1X7=0D=0ACanada
X-WAB-GENDER:2
URL;HOME:http://falcon3166.tripod.com
URL;WORK:http://falcon3166.tripod.com/Woffee.htm
BDAY:19850221
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
REV:20050802T011312Z
END:VCARD
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform (fwd)

2005-08-01 Thread Danny Yoo

Hi Jeff,


> Yes, for an odd square wave the b's of the fourier series are non zero
> for even values and zero for odd values of n. these are the coefficients
> for the fourier series.  Although I beleive the fft (fourier transform)
> should return the amplitude of frequencies that exist. so for example a
> fft on a 10 hz sin wave with amplitude equal 2 should return all zero
> amplitudes except for at 10 hz there should be a spike with amplitude 2.


Up to this point, I agree with you.



> although... this would be bn = 2 for n=1 in the fourier series.

But at this point, I'm not so sure.

I was expecting coefficient bn to be the contribution at n hertz.  n=0 is
the contribution from the steady state, so for n=1, I didn't expect to get
the contribution from the 10hz wave, but the 1hz one instead.  I'm
hesitant about this because I really don't remember anything from my EE
intro class... *grin*


I think we're straying a bit wildly from Python tutorial material, but
let's try an example and check something out.  I want to sample points
from the function:

f(x) = sin(x) + sin(2x) + sin(3x)

between [0, 2pi].  Let's see...

##
>>> import math
>>> def f(x):
... return math.sin(x) + math.sin(2*x) + math.sin(3*x)
...
>>> def build_sample(f, n):
... sample = []
... x = 0
... while x < 2*math.pi:
... sample.append(f(x))
... x = x + 2*math.pi / float(n)
... return sample
...
##


This build_sample function will make things nicer to take arbitrary
samples of any function.

##
>>> sample = build_sample(f, 2000)
##


I'll take a sample of 2000 points, just to make the function sorta smooth
to the FFT function.  Ok, let's see what the FFT gives us here:

##
>>> import numarray.fft
>>> frequences = numarray.fft.fft(sample)
>>> frequences[0].real
-5.0942902674044888e-11
>>> frequences[1].real
1.5720366156507799
>>> frequences[2].real
3.1424651347438695
>>> frequences[3].real
4.7037495618800307
>>> frequences[4].real
-0.016650764926842861
>>> frequences[5].real
-0.012744203044761522
>>> frequences[6].real
-0.011435677529394448
##

And to me, this looks like frequences[0] contains the steady state values,
frequences[1] the frequency contribution from 1Hz, and so on.  (I have to
admit that I don't quite understand what the values mean yet.)


Let's try another test:

##
>>> def f(x):
... return 42 + math.sin(2*x)
...
>>> sample = build_sample(f, 2)
>>> frequences = numarray.fft.fft(sample)
>>> frequences[0].real
840041.814
>>> frequences[1].real
0.00010469890965382478
>>> frequences[2].real
3.1415140090902716
>>> frequences[3].real
-0.00056553943694630812
>>> frequences[4].real
-0.00041889401962948863
##


Again, I have to plead a huge amount of ignorance here: I don't quite
understand what the real components of the frequencies is supposed to
mean.  *grin*


But it does look like the FFT is sensitive to our f() function at the
right frequences --- it's giving us some honking huge value at the steady
state, and another blip at frequences[2].

Finally, we can try a square wave:

##
>>> def square(x):
... if x > math.pi:
... return -1
... return 1
...
>>> freqs = numarray.fft.fft(build_sample(square, 1000))
>>> freqs[0].real
-1.0
>>> freqs[1].real
2.901501133008
>>> freqs[2].real
-0.6060055012559
>>> freqs[3].real
2.113516016997
>>> freqs[4].real
-0.99984240375361688
##

Interesting: I do see some kind of oscillation here, but don't quite
understand what it means.  What happens if we push the sample rate higher?

##
>>> t = numarray.fft.fft(build_sample(square, 10))
>>> t = numarray.fft.fft(build_sample(square, 10))
>>> t[0].real
-1.0
>>> t[1].real
2.9013506
>>> t[2].real
-0.604174983
>>> t[3].real
2.11217117
>>> t[4].real
-0.9998418203995
>>> t[5].real
2.999753002307
>>> t[6].real
-0.99964464928
>>> t[7].real
2.999516338782
##


Hmmm... the numbers seem to be about the same.  What if we drop them down
really low?

##
>>> t = numarray.fft.fft(build_sample(square, 10))
>>> t[0].real
2.0
>>> t[1].real
-4.4408920985006262e-15
>>> t[2].real
2.0
>>> t[3].real
-1.2382749738730321e-15
>>> t[4].real
2.0
>>> t[5].real
2.276408226284e-17
>>> t[6].real
2.0
##

Odd.  Now the odd components look really small!  So sample rate does
appear to be pretty important: otherwise, we get some weird results from
the FFT.

Then again, maybe they're not "weird": maybe I'm just misinterpreting the
results again.  *grin* I wish I knew more about the FFT!  I do have the
excellently whimsical book "Who is Fourier?" in my bookshelf, but haven't
made the time to read it yet.


Talk to you later!

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


[Tutor] terminology question

2005-08-01 Thread Dick Moores
Why are list comprehensions called that?

Thanks,

Dick Moores
[EMAIL PROTECTED]

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


Re: [Tutor] terminology question

2005-08-01 Thread jfouhy
Quoting Dick Moores <[EMAIL PROTECTED]>:

> Why are list comprehensions called that?

Because that's what they're called in Haskell, I guess..

It's historical, based on the term "set comprehension" from mathematics, also
known as "set builder notation": http://en.wikipedia.org/wiki/Set_comprehension

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


Re: [Tutor] terminology question

2005-08-01 Thread Dick Moores
[EMAIL PROTECTED] wrote at 21:52 8/1/2005:
>Quoting Dick Moores <[EMAIL PROTECTED]>:
>
> > Why are list comprehensions called that?
>
>Because that's what they're called in Haskell, I guess..

This Haskell, I suppose?


>It's historical, based on the term "set comprehension" from mathematics, 
>also
>known as "set builder notation": 
>http://en.wikipedia.org/wiki/Set_comprehension

And I was a math major..

Thanks!

Dick

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


Re: [Tutor] Question about BASIC and Python

2005-08-01 Thread Liam Clarke
Erm erm erm having used Visual Basic, XBasic and QBasic, I
can honestly say, that about the only similarity is that VB is more or
less object orientated, and that they use modules. 

On 8/2/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:







Hi all,
 
I had a co-worker say to me at work that Python was related to or based 
upon BASIC. Is this true, and if not, how can I tell my friend why they are 
similar?
 
Nathan Pinno,Crew, Camrose McDonalds and owner/operator of 
Woffee

___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor-- 'There is only one basic human right, and that is to do as you damn well please.And with it comes the only basic human duty, to take the consequences.'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about BASIC and Python

2005-08-01 Thread Bob Gailer


At 06:13 PM 8/1/2005, Nathan Pinno wrote:
Hi all,
 
I had a co-worker say to me at work that Python was related to or based
upon BASIC. Is this true, and if not, how can I tell my friend why they
are similar?
There are many versions of BASIC (Beginners All-Purpose Symbolic
Instruction Code) (or something like that). What most have in common with
Python (and a lot of other programming languages) is:
variables of various data types
statements
expressions with numeric, string, relational and boolean operations
sequential execution
control structures for conditionals and loops
subroutines
input/output
arrays
some BASIC versions also add
exception handling
an attempt at OO
Python differs in
the use of indentation to convey control structure
dictionaries
object-oriented to the max
builtin object methods
all items are objects
all objects may be dynamically altered
object properties may be added anytime
modules
big library of modules
and many more

Bob Gailer
phone 510 978 4454 

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


[Tutor] QUESTION

2005-08-01 Thread Jane MUIRI
Hi!
I'd like to know what kind of Python I can download. I've tried but in vain!
My computer is windows xp servixe pack 1, version 2002.
Please, tell me what to do.
Jane.

_
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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


Re: [Tutor] Question about BASIC and Python

2005-08-01 Thread Nathan Pinno



Thanks Bob and Liam. I was wondering myself.

  - Original Message - 
  From: 
  Bob 
  Gailer 
  To: Nathan Pinno ; Tutor mailing list 
  
  Sent: Monday, August 01, 2005 11:09 
  PM
  Subject: Re: [Tutor] Question about BASIC 
  and Python
  At 06:13 PM 8/1/2005, Nathan Pinno wrote:
  Hi all, I had a 
co-worker say to me at work that Python was related to or based upon BASIC. 
Is this true, and if not, how can I tell my friend why they are 
  similar?There are many versions of BASIC (Beginners 
  All-Purpose Symbolic Instruction Code) (or something like that). What most 
  have in common with Python (and a lot of other programming languages) 
  is:variables of various data typesstatementsexpressions with 
  numeric, string, relational and boolean operationssequential 
  executioncontrol structures for conditionals and 
  loopssubroutinesinput/outputarrayssome BASIC versions also 
  addexception handlingan attempt at OOPython differs inthe 
  use of indentation to convey control 
  structuredictionariesobject-oriented to the maxbuiltin object 
  methodsall items are objectsall objects may be dynamically 
  alteredobject properties may be added anytimemodulesbig library of 
  modulesand many more
  Bob Gailerphone 510 978 4454 

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


Re: [Tutor] I need advice.

2005-08-01 Thread Danny Yoo


On Mon, 1 Aug 2005, Nathan Pinno wrote:

> I want to write a program that will convert time in any other time zone
> to my time zone. Would it be better to use the Python time molecule or
> just a whole bunch of if statements?

Hi Nathan,

I'd recommend looking at the 'datetime' Python module.  Getting this stuff
right is hard, so unless you really want to learn how time conversions
work, take advantage of the library.  There's something there that does do
time zones:

http://www.python.org/doc/lib/datetime-tzinfo.html
http://www.python.org/doc/lib/tzinfo-examples.txt

Good luck!

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


Re: [Tutor] QUESTION

2005-08-01 Thread Liam Clarke
This link - http://www.python.org/ftp/python/2.4.1/python-2.4.1.msi
straight from the python.org website is for a Windows installer.

May I also recommend this - http://wiki.python.org/moin/BeginnersGuide

The Python Beginner's Guide?

Good luck, 

Liam ClarkeOn 8/2/05, Jane MUIRI <[EMAIL PROTECTED]> wrote:
Hi!I'd like to know what kind of Python I can download. I've tried but in vain!My computer is windows xp servixe pack 1, version 2002.Please, tell me what to do.Jane._
Express yourself instantly with MSN Messenger! Download today it's FREE!http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
-- 'There is only one basic human right, and that is to do as you damn well please.And with it comes the only basic human duty, to take the consequences.'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice.

2005-08-01 Thread Nathan Pinno
I forgot to tell that I use Python 2.2.3. When I first got Python, I got 
2.4.1, but it refused to run the second time. So I went and got 2.2.3. Your 
answer would make sense if I had 2.4.1, but I don't.
- Original Message - 
From: "Danny Yoo" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>
Cc: "Tutor mailing list" 
Sent: Monday, August 01, 2005 11:41 PM
Subject: Re: [Tutor] I need advice.


>
>
> On Mon, 1 Aug 2005, Nathan Pinno wrote:
>
>> I want to write a program that will convert time in any other time zone
>> to my time zone. Would it be better to use the Python time molecule or
>> just a whole bunch of if statements?
>
> Hi Nathan,
>
> I'd recommend looking at the 'datetime' Python module.  Getting this stuff
> right is hard, so unless you really want to learn how time conversions
> work, take advantage of the library.  There's something there that does do
> time zones:
>
>http://www.python.org/doc/lib/datetime-tzinfo.html
>http://www.python.org/doc/lib/tzinfo-examples.txt
>
> Good luck!
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor