[Tutor] assert() question

2008-07-05 Thread Dick Moores


I have a module, mycalc.py, which is a collection of functions designed
to be imported independently.
I've heard about using assert() to check up on whether things are still
working correctly, or something like that. So I've begun to write some
assert() expressions(?)  and put them at the bottom of the
module.
if __name__ ==
'__main__':  

assert(numberCommas('7657657.7554') == '7,657,657.7554')

assert(intCommas(76576577554) == '76,576,577,554')

assert(nextNPrimes(1,10) == [10039L, 10061L,
10063L, 10091L, 10121L, 10163L,
10169L, 10177L, 10189L, 10193L])

maxDiffBetPrimes(101)

printTime(1215322947.0320001, 1215322934.0398701)

printTime(1215323947.0320001, 1215323011.4567342)

printTime(1215322947.0320001, 1215312921.0054233)
OUTPUT:
For primes up through 101, max diff is 8
between the 1 pair(s) of primes [(89, 97)]
Time was 12.99 seconds
Time was 15 minutes, 35 seconds
Time was 2 hours, 47 minutes, 6 seconds
The top three work silently, but I found that I could not figure out
how to use assert() with the functions that print rather than return.
E.g., maxDiffBetPrimes() and printTime(). Is there a
way?
If it'll help, here's printTime():
def printTime(timeEnd, timeStart):
    from mycalc import hmsToText
    timeElapsed = timeEnd - timeStart
    if timeElapsed > 60:
    print "Time was",
hmsToText(timeElapsed)
    else:
    print "Time was %.4g
seconds" % timeElapsed
Thanks,
Dick Moores


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


Re: [Tutor] module paths

2008-07-05 Thread Gonzalo Garcia-Perate
That's what I thought but no. There is an install of 2.4 but not in
use. /usr/local/bin/Python points to ->
/Library/Frameworks/Python.framework/Versions/2.5/bin/python

feedparser is installed in
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages

both the interactive interpreter and the one used by textmate/terminal
report to be using Python 2.5

the output of sys.path from textmate looks like this:
['/Users/gonzillaaa/Sites/python_rss',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/setuptools-0.6c5-py2.5.egg',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/simplejson-1.9.1-py2.5-macosx-10.3-i386.egg',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/python_twitter-0.5-py2.5.egg',
'/Users/gonzillaaa/Sites/python_rss',
'/Users/gonzillaaa/development/Python', '/Users/gonzillaaa/bin',
'/Library/Frameworks/Python.framework/Versions/Current/bin',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages',
'/Users/gonzillaaa/Sites',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload']


there are some duplicates but nothing missing that I can see. The
output of sys.path form the interactive interpreter looks like this:

['', 
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/setuptools-0.6c5-py2.5.egg',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/simplejson-1.9.1-py2.5-macosx-10.3-i386.egg',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/python_twitter-0.5-py2.5.egg',
'/Users/gonzillaaa/Sites/python_rss',
'/Users/gonzillaaa/development/Python', '/Users/gonzillaaa/bin',
'/Library/Frameworks/Python.framework/Versions/Current/bin',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages',
'/Users/gonzillaaa/Sites',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload']



2008/7/6 arsyed <[EMAIL PROTECTED]>:
> I copy/pasted your script and it ran fine on my end. Is it possible that
> you've got more than one installation of python and the feedparser module is
> installed somewhere other than for the python interpreter at
> /usr/local/bin/python (since that's what your script references)? Perhaps
> trying "python parse.py" will help since your code when you invoke the
> python shell.
>
> On 7/5/08, Gonzalo Garcia-Perate <[EMAIL PROTECTED]> wrote:
>>
>> I'm looking at python after a long time. I wanted to build a quick
>> parser for some rss feeds and have started using feedparser.
>>
>> When I test my code on the python interactive shell things work fine
>> but when I try to write it into a file I get the following error:
>> AttributeError: 'module' object has no attribute 'parse'
>>
>> this is what I run on the shell:
>> import feedparser
>> >>> d = feedparser.parse("http://tedblog.typepad.com/tedblog/atom.xml";)
>> >>> d
>> {'feed': {'updated': u'2008-07-04T14:11:15Z', 'updated_parsed': (2008,
>> 7, 4, 14, 11, 15, 4, 186, 0), 'links': [{'href':
>> u'http://blog.ted.com/', 'type': u'text/html', 'rel': u'alternate'},
>> {'href': u'http://feeds.feedburner.com/TEDBlog', 'type':
>> u'application/atom+xml', 'rel': u'self'}], 'title': u'TED | TEDBlog',
>> etc.
>>
>> This is what my script (which fails looks like...):
>> #!/usr/local/bin/python
>> import feedparser
>>
>> d = feedparser.parse("http://tedblog.typepad.com/tedblog/atom.xml";)
>> d['feed']['title']
>>
>> I'm trying to ring this form within textmate or form the terminal at
>> different locations as (./parse.py)
>>
>> thanks
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>

Re: [Tutor] module paths

2008-07-05 Thread arsyed
I copy/pasted your script and it ran fine on my end. Is it possible that
you've got more than one installation of python and the feedparser module is
installed somewhere other than for the python interpreter at
/usr/local/bin/python (since that's what your script references)? Perhaps
trying "python parse.py" will help since your code when you invoke the
python shell.



On 7/5/08, Gonzalo Garcia-Perate <[EMAIL PROTECTED]> wrote:
>
> I'm looking at python after a long time. I wanted to build a quick
> parser for some rss feeds and have started using feedparser.
>
> When I test my code on the python interactive shell things work fine
> but when I try to write it into a file I get the following error:
> AttributeError: 'module' object has no attribute 'parse'
>
> this is what I run on the shell:
> import feedparser
> >>> d = feedparser.parse("http://tedblog.typepad.com/tedblog/atom.xml";)
> >>> d
> {'feed': {'updated': u'2008-07-04T14:11:15Z', 'updated_parsed': (2008,
> 7, 4, 14, 11, 15, 4, 186, 0), 'links': [{'href':
> u'http://blog.ted.com/', 'type': u'text/html', 'rel': u'alternate'},
> {'href': u'http://feeds.feedburner.com/TEDBlog', 'type':
> u'application/atom+xml', 'rel': u'self'}], 'title': u'TED | TEDBlog',
> etc.
>
> This is what my script (which fails looks like...):
> #!/usr/local/bin/python
> import feedparser
>
> d = feedparser.parse("http://tedblog.typepad.com/tedblog/atom.xml";)
> d['feed']['title']
>
> I'm trying to ring this form within textmate or form the terminal at
> different locations as (./parse.py)
>
> thanks
> ___
> 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] Exploring the Standard Library

2008-07-05 Thread arsyed
This might work:

>>> import os
>>> print os.__file__
c:\devtools\Python25\lib\os.pyc

Also, you might find Doug Hellman's "Python Module Of The Week" helpful:

http://www.doughellmann.com/projects/PyMOTW/




On 7/5/08, Nathan Farrar <[EMAIL PROTECTED]> wrote:
>
>  I'd like to spend some time exploring the standard library.  I'm running
> python on Ubuntu.  How would I find the location of the modules (find /
> -name "os.py" does not yield results)?
>
> 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] Wave error (solved)

2008-07-05 Thread Alex Krycek
Per someone's suggestion I changed my wave files from 32 bit to 16 bit. I
can now open (and manipulate) them without any error. I'm not sure why it
worked but it worked.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] my first object model, using an interface

2008-07-05 Thread tpc247
Dear fellow Python enthusiasts:

I want to run an idea by you to see if I understand modeling objects
adequately, after reading Alan Gauld's excellent tutorial and two brief
articles about interfaces in Python, here:

 http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm

http://dirtsimple.org/2004/12/python-interfaces-are-not-java.html
 http://nedbatchelder.com/text/pythonic-interfaces.html

I am attempting to model the following:
a correspondence school has asked me to help them solve a problem.  When the
school sends a student by mail a package containing several courses, each
course having several pieces of gradable homework, when a specific threshold
of homework completed and submitted by the student is met or exceeded,
another package is sent to the student by mail.  Now, this aforementioned
threshold, i.e., an integer indicating percentage, can vary, and is not just
for the totality of homework in the package, but also for certain courses
with many pieces of homework.  For example, say the school sends student Joe
a package (package_1) containing courses A, B and C_sub1.  A, B & C_sub1
have 10 pieces of gradable homework, and the school wants that we can set a
threshold for the totality of homework for package1, as well as a threshold
for C_sub1 alone.  When the thresholds are met or exceeded, independently,
then we send package_2 and C_sub2, respectively.  I envisioned a nascent
object model and noted the following observations:

- a Watchable interface that, when implemented, signifies that the
implementing object has a threshold and associated package.
- a Package class, that can be seen as a container for courses and/or one
part of a course
- a Course class, that can be seen as a container for gradable homework
- a Homework class, that has a flag to indicated whether it has been
received by the school
- most Packages are Watchable (except the last Package object), and only one
or two Courses in a Package need to be Watchable

Two questions:
1) Should I create a first-class Watchable interface object, and then have
my Package and Course objects implement it if they need to ?  If I start
with a Watchable interface, do I handle the name-space conflict, i.e.,
Package(object) vs Package(Watchable), by defining a Package class, and a
W_Package class that implements Watchable, and likewise for Course ?
2) am I even thinking the right way about attacking this problem ?  I am
curious what your experience in writing easy to maintain software might tell
you about my nascent object model.

class Watchable(object):
def set_threshold(self, an_int):
raise NotImplemented
def get_threshold(self):
raise NotImplemented
def set_associated_load(self, a_load):
raise NotImplemented
def get_associated_load(self):
raise NotImplemented

class Package(object):
def __init__(self, courses):
self.set_courses(courses)
def set_courses(self, courses):
self.courses = courses
def get_courses(self):
return self.courses

class Course(Watchable):
def __init__(self, name, homework):
self.name = name
self.homework = homework
def get_name(self):
return self.name
def get_homework(self):
return self.homework

class Homework(object):
def __init__(self, name):
self.name = name
self.academically_received = False
def set_academically_received(self):
self.academically_received = True
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Voice Text To Speech and Wav File Make and Save

2008-07-05 Thread FT

Hi!

I got my text to speech to work better, will in the future remove the
buttons and only have the file menu.
It seems to work fine and now use sub menu's for voice settings.

What will be needed as an event to capture the cursor movement inside
the text box. How do I get the key and cursor events so I can speak when
doing ctrl cursor or up/down cursor events to say lines, words, and letters?
I have tried getting the key event but gets ignored, so I need the
proper kind and location to catch the text box key events. I erased my test,
but below and attached are the complete setup.

Bruce



desc="""Using two nested sizers, the main one with vertical layout
and the embedded one with horizontal layout
For setting voice parms:"""
#Editor.py
import wx
import os
import Sapi5
tts = Sapi5.Create( {"name":"Mary"})
purge = tts._purge
async = tts._async
punc = tts._punc
MN=0
ID=1
HK=2
KD=3
MF=4
MF2=5
DW_ID=1000
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
self.dirname=os.getcwd()  #SEARCH FROM PRESENT DIRECTORY!
self.filename=""
self.items4menu = {"File": [
{MN:"Open", ID:102, HK:"&Open", KD:" Open a file to edit",
MF:self.OnOpen},
{MN:"Save", ID:103, HK:"&Save", KD:" save file to disk",
MF:self.OnSave},
{MN:"Edit", ID:104, HK:"&Edit", KD:" Do editing",
MF:self.OnEdit},
{MN:"About", ID:101, HK:"&About", KD:" Information about this
program", MF:self.OnAbout},
{MN:"Exit", ID:109, HK:"E&xit", KD:" Terminate the program",
MF:self.OnExit}
],  #END OF FILE MENU!
"Voice": [
{MN:"Read", ID:202, HK:"&Read", KD:" Open a file to read",
MF:self.OnWav2Read},
{MN:"Save", ID:203, HK:"&Save", KD:" save text to audio file",
MF:self.OnSave2Wav},
{MN:"Text", ID:204, HK:"Te&xt", KD:" read text field",
MF:self.OnRead},
{MN:"Quit", ID:205, HK:"&Quit", KD:" Stop Reading",
MF:self.OnQuitRead}
],  #END OF VOICE MENU!
"Settings": [
{MN:"Voice", ID:302, HK:"&Speaker", KD:" Name for voice.",
MF:self.OnVoice, MF2:self.OnClick},
{MN:"Rate", ID:303, HK:"&Rate", KD:" Rate for voice.",
MF:self.OnVoice, MF2:self.OnClick},
{MN:"Pitch", ID:304, HK:"&Pitch", KD:" Pitch for voice.",
MF:self.OnVoice, MF2:self.OnClick},
{MN:"Volume", ID:305, HK:"&Volume", KD:" Volume for voice.",
MF:self.OnVoice, MF2:self.OnClick}
],  #END OF SETTINGS MENU!
"Down": [
{MN:"Down", ID:DW_ID, HK:"&Down", KD:" Lower Setting.",
MF:self.OnVoice, MF2:self.OnClick}
]  #END OF DOWN MENU!
}  #END OF ITEMS FOR MENU!
self.buttons4voice = [
{MN:"Voice", ID:111, HK:"&Voice", KD:" Voice Change",
MF:self.OnEnter, MF2:self.OnClick},
{MN:"Rate", ID:112, HK:"&Rate", KD:" Rate For Voice Adjust",
MF:self.OnEnter, MF2:self.OnClick},
{MN:"Pitch", ID:113, HK:"&Pitch", KD:" Pitch Of Voice Adjust",
MF:self.OnEnter, MF2:self.OnClick},
{MN:"Volume", ID:114, HK:"&Loudness", KD:" Volume Loudness
Adjust", MF:self.OnEnter, MF2:self.OnClick}
]  #END OF ITEM FOR BUTTONS!
wx.Frame.__init__(self, parent, wx.ID_ANY, title)
self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.CreateStatusBar()  #A Statusbar in the bottom of the window
#Setting up the menu.
filemenu = wx.Menu()
for o in self.items4menu["File"]:
filemenu.Append( o[ID], o[HK], o[KD])
filemenu.AppendSeparator()
voicemenu = wx.Menu()
for o in self.items4menu["Voice"]:
voicemenu.Append( o[ID], o[HK], o[KD])
voicemenu.AppendSeparator()
setting_menu = wx.Menu()
for o in self.items4menu["Settings"]:
down_menu = wx.Menu()
down_menu.Append( o[ID], o[HK], o[KD])
d = self.items4menu["Down"][0]
down_menu.Append( d[ID]+o[ID], d[HK], d[KD])
setting_menu.AppendMenu( o[ID], o[HK]+" Setting", down_menu)
setting_menu.AppendSeparator()
voicemenu.AppendMenu(-1, "&VoiceSettings", setting_menu)
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append( filemenu,"&File") # Adding the "filemenu" to the
MenuBar
menuBar.Append( voicemenu,"&Voice") # Adding the "voicemenu" to the
MenuBar
self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
self.data4menu = {}
for o in self.items4menu["File"]:
wx.EVT_MENU(self, o[ID], o[MF])
self.data4menu[ o[ID]] = o
for o in self.items4menu["Voice"]:
wx.EVT_MENU(self, o[ID], o[MF])
self.data4menu[ o[ID]] = o
for o in self.items4menu["Settings"]:
wx.EVT_MENU(self, o[ID], o[MF])
self.data4menu[ o[ID]] = o
wx.EVT_MENU(self, o[ID]+DW_ID, o[MF])
self.data4menu[ o[ID]+DW_ID] = o

Re: [Tutor] Tutor Digest, Vol 53, Issue 18

2008-07-05 Thread Alan Gauld


"kinuthiA muchanE" <[EMAIL PROTECTED]> wrote


python on Ubuntu.  How would I find the location of the modules
(find /  -name "os.py" does not yield results)?


Not all modules are implemented as .py files.
Some are compiled C libraries. Thus searching 
for .py will not find all Python modules. Also you may only 
have the compiled python installed although thats less likely.


You can find any module by importing it and asking 
for its file:



import os
os.__file__

'/usr/lib/python2.5/os.pyc'




HTH,

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

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


[Tutor] Wave module

2008-07-05 Thread Alex Krycek
Hello,

I'm trying to join two .wav files with the wave module. But when I try to
use wave.open(filename, "rb") I receive the following error:

Traceback (most recent call last):
  File "", line 1, in 
  File "F:\PortablePython1.0\lib\wave.py", line 483, in open
return Wave_read(f)
  File "F:\PortablePython1.0\lib\wave.py", line 162, in __init__
self.initfp(f)
  File "F:\PortablePython1.0\lib\wave.py", line 143, in initfp
self._read_fmt_chunk(chunk)
  File "F:\PortablePython1.0\lib\wave.py", line 264, in _read_fmt_chunk
raise Error, 'unknown format: %r' % (wFormatTag,)
wave.Error: unknown format: 85

I read somewhere that there are various wave formats, only some supported by
Python. Is this true? If so, is there any way I can convert my wave files
into a supported kind?


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


[Tutor] module paths

2008-07-05 Thread Gonzalo Garcia-Perate
I'm looking at python after a long time. I wanted to build a quick
parser for some rss feeds and have started using feedparser.

When I test my code on the python interactive shell things work fine
but when I try to write it into a file I get the following error:
AttributeError: 'module' object has no attribute 'parse'

this is what I run on the shell:
import feedparser
>>> d = feedparser.parse("http://tedblog.typepad.com/tedblog/atom.xml";)
>>> d
{'feed': {'updated': u'2008-07-04T14:11:15Z', 'updated_parsed': (2008,
7, 4, 14, 11, 15, 4, 186, 0), 'links': [{'href':
u'http://blog.ted.com/', 'type': u'text/html', 'rel': u'alternate'},
{'href': u'http://feeds.feedburner.com/TEDBlog', 'type':
u'application/atom+xml', 'rel': u'self'}], 'title': u'TED | TEDBlog',
etc.

This is what my script (which fails looks like...):
#!/usr/local/bin/python
import feedparser

d = feedparser.parse("http://tedblog.typepad.com/tedblog/atom.xml";)
d['feed']['title']

I'm trying to ring this form within textmate or form the terminal at
different locations as (./parse.py)

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


Re: [Tutor] Script Name/Path Information

2008-07-05 Thread Josh Rosen

How about the following:

import os
print os.path.abspath(__file__)		# the full absolute path to the  
current module's file
print os.path.split(os.path.abspath(__file__))		# if you need the  
individual components of the path.



On Jul 5, 2008, at 11:00 AM, Monika Jisswel wrote:


import sys  #a module that gives access to the system
import os#a module that gives access to the os

print sys.argv[0]   #prints file name of the script
print os.getcwd()   #print current working directory
print os.getcwd()+sys.argv[0]   #




2008/7/5 Nathan Farrar <[EMAIL PROTECTED]>:
I'm new to python and wondering if there is a way to reference  
information about the script that is running.  For example, if I was  
running a script named "FileInfo.py" from the directory "/home/ 
username", I'm looking for attributes such that something similar to:


print self.name
print self.path

would output:

FileInfo.py
/home/username

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


Re: [Tutor] Tutor Digest, Vol 53, Issue 18

2008-07-05 Thread kinuthiA muchanE

On Sat, 2008-07-05 at 20:23 +0200, [EMAIL PROTECTED] wrote:
> Message: 7
> Date: Sat, 05 Jul 2008 12:23:36 -0600
> From: Nathan Farrar <[EMAIL PROTECTED]>
> Subject: [Tutor] Exploring the Standard Library
> To: Python Tutor 
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="us-ascii"
> 
> I'd like to spend some time exploring the standard library.  I'm
> running
> python on Ubuntu.  How would I find the location of the modules
> (find /
> -name "os.py" does not yield results)?
In Ubuntu, you can find all the documentation in the /usr/share/doc
directory. Therefore, for python you will find it
in /usr/share/doc/python. Furthermore, to find the location of some
documentation, in the terminal enter dpkg -L , in your
case, just type dpkg -L python and you will be rewarded with paths for
all python related documentation.

Does this help?
Kinuthia...
> 
> Thanks!
> Nathan

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


Re: [Tutor] Script Name/Path Information

2008-07-05 Thread Steve Willoughby

Monika Jisswel wrote:

import sys  #a module that gives access to the system
import os#a module that gives access to the os

print sys.argv[0]   #prints file name of the script
print os.getcwd()   #print current working directory
print os.getcwd()+sys.argv[0]   #


but os.getcwd() returns the current working directory, not necessarily 
the directory containing the script.  os.getcwd()+sys.argv[0] will quite 
often not yield a useful result.  Even if it did, os.path.join is better 
than + when joining pathnames.







2008/7/5 Nathan Farrar <[EMAIL PROTECTED]>:


 I'm new to python and wondering if there is a way to reference information
about the script that is running.  For example, if I was running a script
named "FileInfo.py" from the directory "/home/username", I'm looking for
attributes such that something similar to:

print self.name
print self.path

would output:

FileInfo.py
/home/username

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


Re: [Tutor] Exploring the Standard Library

2008-07-05 Thread Monika Jisswel
import sys
print sys.path

but no one recommends starting with python from there. you're better of
reading the python.org/doc files.



2008/7/5 Nathan Farrar <[EMAIL PROTECTED]>:

>  I'd like to spend some time exploring the standard library.  I'm running
> python on Ubuntu.  How would I find the location of the modules (find /
> -name "os.py" does not yield results)?
>
> 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


Re: [Tutor] Exploring the Standard Library

2008-07-05 Thread amingv
The python interpreter can give you this information; just type:

import sys
for i in sys.path:
print i

And search in the lib directories it shows.

You might also be interested in the std library reference at docs.python.org.

--
Amin Rainmaker--- Begin Message ---
I'd like to spend some time exploring the standard library.  I'm running
python on Ubuntu.  How would I find the location of the modules (find /
-name "os.py" does not yield results)?

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


Re: [Tutor] loops, variables and strings

2008-07-05 Thread bob gailer

James wrote:

All,

I'm trying to do something pretty simple, but I can't seem to get
Python to behave nicely. :)

I'd like to automate a script that sends out three or four lists in an
e-mail. I have a function dedicated to sending e-mail that will take a
string variable, slap it in a message, and send it on its merry way.

The issue, however, is that I can't format the string I want
correctly. I'd like to do something similar to the following:

myString = """Hello. Below is an automated e-mail with important statistics.

The following user accounts expired today:
 - 
 - 
...

The following user accounts will expire within the next 7 days:
 - 
 - 
...

The following user accounts will expire in the next month:
 - 
 - """

I've written some code that actually does include a list of users, like this:

myString = """Hello. Below is an automated e-mail with important statistics.

The following user accounts expired today:
%s

The following user accounts will expire within the next 7 days:
%s

The following user accounts will expire in the next month:
%s""" % (expiredAccounts,toExpire7,toExpire30,),

  
Remove the trailing , in the last line. It is causing myString to be a 
tuple.



Of course in this scenario, the variables in the parenthesis are
strings with newlines in them. But when I do a 'print myString', it
shows everything in one line, including the '\n' characters at the end
of every user account listed.

Thoughts on what I may be doing wrong?



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

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


[Tutor] Exploring the Standard Library

2008-07-05 Thread Nathan Farrar
I'd like to spend some time exploring the standard library.  I'm running
python on Ubuntu.  How would I find the location of the modules (find /
-name "os.py" does not yield results)?

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


Re: [Tutor] loops, variables and strings

2008-07-05 Thread Monika Jisswel
maybe StringIO ?

MsgBody = StringIO.StringIO()
print >> MsgBody, "Hello. Below is an automated e-mail with important
statistics."
print >> MsgBody, ""#empty line
print >> MsgBody, ""#empty line
print >> MsgBody, "The following user accounts expired today:"
print >> MsgBody, " - " % (var1, Name1)
print >> MsgBody, " - " % (var2, Name2)
...
< More code here >
...

MSGBODY = MsgBody.getvalue()  # use MSGBODY in you Email.




2008/7/5 James <[EMAIL PROTECTED]>:

> All,
>
> I'm trying to do something pretty simple, but I can't seem to get
> Python to behave nicely. :)
>
> I'd like to automate a script that sends out three or four lists in an
> e-mail. I have a function dedicated to sending e-mail that will take a
> string variable, slap it in a message, and send it on its merry way.
>
> The issue, however, is that I can't format the string I want
> correctly. I'd like to do something similar to the following:
>
> myString = """Hello. Below is an automated e-mail with important
> statistics.
>
> The following user accounts expired today:
>  - 
>  - 
> ...
>
> The following user accounts will expire within the next 7 days:
>  - 
>  - 
> ...
>
> The following user accounts will expire in the next month:
>  - 
>  - """
>
> I've written some code that actually does include a list of users, like
> this:
>
> myString = """Hello. Below is an automated e-mail with important
> statistics.
>
> The following user accounts expired today:
> %s
>
> The following user accounts will expire within the next 7 days:
> %s
>
> The following user accounts will expire in the next month:
> %s""" % (expiredAccounts,toExpire7,toExpire30,),
>
> Of course in this scenario, the variables in the parenthesis are
> strings with newlines in them. But when I do a 'print myString', it
> shows everything in one line, including the '\n' characters at the end
> of every user account listed.
>
> Thoughts on what I may be doing wrong?
>
> Thanks!
> - j
> ___
> 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] Script Name/Path Information

2008-07-05 Thread Monika Jisswel
import sys  #a module that gives access to the system
import os#a module that gives access to the os

print sys.argv[0]   #prints file name of the script
print os.getcwd()   #print current working directory
print os.getcwd()+sys.argv[0]   #




2008/7/5 Nathan Farrar <[EMAIL PROTECTED]>:

>  I'm new to python and wondering if there is a way to reference information
> about the script that is running.  For example, if I was running a script
> named "FileInfo.py" from the directory "/home/username", I'm looking for
> attributes such that something similar to:
>
> print self.name
> print self.path
>
> would output:
>
> FileInfo.py
> /home/username
>
> ... 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] Script Name/Path Information

2008-07-05 Thread Nathan Farrar
I'm new to python and wondering if there is a way to reference
information about the script that is running.  For example, if I was
running a script named "FileInfo.py" from the directory
"/home/username", I'm looking for attributes such that something similar
to:

print self.name
print self.path

would output:

FileInfo.py
/home/username

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


[Tutor] loops, variables and strings

2008-07-05 Thread James
All,

I'm trying to do something pretty simple, but I can't seem to get
Python to behave nicely. :)

I'd like to automate a script that sends out three or four lists in an
e-mail. I have a function dedicated to sending e-mail that will take a
string variable, slap it in a message, and send it on its merry way.

The issue, however, is that I can't format the string I want
correctly. I'd like to do something similar to the following:

myString = """Hello. Below is an automated e-mail with important statistics.

The following user accounts expired today:
 - 
 - 
...

The following user accounts will expire within the next 7 days:
 - 
 - 
...

The following user accounts will expire in the next month:
 - 
 - """

I've written some code that actually does include a list of users, like this:

myString = """Hello. Below is an automated e-mail with important statistics.

The following user accounts expired today:
%s

The following user accounts will expire within the next 7 days:
%s

The following user accounts will expire in the next month:
%s""" % (expiredAccounts,toExpire7,toExpire30,),

Of course in this scenario, the variables in the parenthesis are
strings with newlines in them. But when I do a 'print myString', it
shows everything in one line, including the '\n' characters at the end
of every user account listed.

Thoughts on what I may be doing wrong?

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


Re: [Tutor] graphs & diagrams in python

2008-07-05 Thread Kent Johnson
On Fri, Jul 4, 2008 at 3:54 PM, Monika Jisswel
<[EMAIL PROTECTED]> wrote:
> Hi Again,
>
> What is the best library for drawing graphs & diagrams to ilustrate some
> statistics ?

A few possibilities here:
http://wiki.python.org/moin/GraphicsAndImages

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