Re: [Tutor] automatically add it to all the classes

2006-10-30 Thread Alan Gauld

"anil maran" <[EMAIL PROTECTED]> wrote
> All the classes in my webpy application have the following lines
> is there anyway to automatically add it to all the classes in 
> code.py,
> user.py

Without more information about your application we can't give
a definitive answer.

But if they inherit from a common ancestor you could put the
code there.

Alternativelyyou could create a mixin class that all other
classes inherit using multiple inheritance.

Alternatively you could create a function and call that from
all classes.

Alternatively you could create a new class that does what
you want and create an instance in the constructor of each
of the other classes.

Alternatively you could create a global variable and store
everything there, maybe using a dictionary or list if necessary.

There are other possibilities too but we really don't know
enough about what you are trying to do to be able to say
anything more specific..

HTH,


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





> If it is too basic, please pardon my naivette.
> thanks
> John
> These are the lines shared by all classes,
>@checkaccess(auth=True)
>
>sess = web.ctx.environ['com.saddi.service.session'].session
> meta_desc = 'myMetaData'
> title = 'title'
> session=web.cookies()
>
> in a class
> class index:
>@checkaccess(auth=True)
>def GET(self):
> sess = web.ctx.environ['com.saddi.service.session'].session
> meta_desc = 'myMetaData'
> title = 'title'
> session=web.cookies()
>
>
> Anil
>
> -
> We have the perfect Group for you. Check out the handy changes to 
> Yahoo! Groups.





> ___
> 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] line number when reading files using csv module

2006-10-30 Thread Duncan Gibson
Duncan Gibson wrote:
> > 
> > import csv
> > 
> > class MyReader(object):
> > 
> > def __init__(self, inputFile):
> > self.reader = csv.reader(inputFile, delimiter=' ')
> > self.lineNumber = 0
> > 
> > def __iter__(self):
> > self.lineNumber += 1
> > return self.reader.__iter__()
> >
> > Is there some other __special__ method that I need to forward to the
> > csv.reader, or have I lost all control once __iter__ has done its job?

Kent Johnson wrote:
> __iter__() should return self, not self.reader.__iter__(), otherwise 
> Python is using the actual csv.reader not your wrapper. And don't 
> increment line number here.
> 
> You lost control because you gave it away.


Thanks Kent. The penny has dropped and it makes a lot more sense now.

I was looking for at __iter__ as a special function that *created* an
iterator, but all it really does is signal that the returned object
will implement the iterator interface, and the next() method in
particular. 

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


[Tutor] am I a dope? - nasty_exception_str =.....

2006-10-30 Thread Michael Daly
Hello python tutor
when I tried to start a program called 'zope' that depends on python, I got
this message at the bottom of a lot of 'traceback'*, and 'zope' didn't
start:

nasty_exception_str = Exception.__str__.im_func
AttributeError: 'wrapper_descriptor' object has no 
attribute 'im_func'

zope seemed to install OK in the same dir (/home/digium400p/zope) to which I
directed (via prefix option) the python 2.5 install. I did this because
python 2.3.4 is also installed in the default location on the operating
system (which is centos 4.4), and I wanted to keep it that way. Zope
requires at least python 2.4.3

I didn't use the 'make altinstall' option for the python 2.5  install-should
I redo this?

*this is the output:

Traceback (most recent call last):
  File "/home/digium400p/zope/lib/python/Zope2/Startup/zopectl.py", 
line 322, in 
main()
  File "/home/digium400p/zope/lib/python/Zope2/Startup/zopectl.py", 
line 280, in main
options.realize(args)
  File "/home/digium400p/zope/lib/python/Zope2/Startup/zopectl.py", 
line 91, in realize
ZDOptions.realize(self, *args, **kw)

etc etc, finally ending in

File "/home/digium400p/zope/lib/python/DocumentTemplate/html_quote.py
", line 4, in 
from ustr import ustr
File "/home/digium400p/zope/lib/python/DocumentTemplate/ustr.py", 
line 18, in 
nasty_exception_str = Exception.__str__.im_func
AttributeError: 'wrapper_descriptor' object has no 
attribute 'im_func'


Any help would be great
Signed..

...very compused



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


Re: [Tutor] automatically add it to all the classes

2006-10-30 Thread Kent Johnson
anil maran wrote:
>   All the classes in my webpy application have the following lines
> is there anyway to automatically add it to all the classes in code.py,
> user.py
> If it is too basic, please pardon my naivette.
> thanks
> John
> These are the lines shared by all classes,
>@checkaccess(auth=True)
> sess = web.ctx.environ['com.saddi.service.session'].session
> meta_desc = 'myMetaData'
> title = 'title'
> session=web.cookies()
> in a class
> class index:
>@checkaccess(auth=True)
>def GET(self):
> sess = web.ctx.environ['com.saddi.service.session'].session
> meta_desc = 'myMetaData'
> title = 'title'
> session=web.cookies()

If this is an entire method that is shared by all your classes, then you 
can make a base class that contains the method. If the method doesn't 
need access to member attributes (doesn't use self) then it doesn't have 
to be part of the class definition, it can be a standalone function in a 
utility module.

If just part of a method is shared by all the classes, see if you can 
put the shared code into a separate method and then use one of the 
approaches described above.

If neither of those will work then please give a little more context.

Kent

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


Re: [Tutor] re-import

2006-10-30 Thread Kent Johnson
Glenn T Norton wrote:
> jhl wrote:
> 
>> Hi-
>>
>> How is the 1st import of a module removed so that new edits on the 
>> module can be re-imported?
>>
> Read about reload here:
> http://docs.python.org/lib/built-in-funcs.html

Make sure you understand the limitations of reload(). In particular, 
names that are imported using 'from xxx import *' or 'from xxx import 
yyy' will not be updated if you reload(xxx), and objects created from 
class definitions in xxx will still refer to the old classes. You can 
read a little more about it here:
http://www.python.org/doc/faq/programming/#when-i-edit-an-imported-module-and-reimport-it-the-changes-don-t-show-up-why-does-this-happen

Kent

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


[Tutor] documentation/sourceforge bug help

2006-10-30 Thread C or L Smith
I know this is off topic, but can anyone give me a hand? I have a sourceforge 
account. I want to make a correction to the python documentation. I click on 
the appropriate link at the bottom of the documentation page and then the bug 
tracker link on the page that I am sent to which takes me to 

http://sourceforge.net/bugs/?group_id=5470

"Login and Submit New" appears just under the "Tracker" tab on that page as 
does the message ""Please log in!" at the bottom of the detailed summary text 
box. Clicking on either of them just gets me into a loop, returning me to the 
bug page but treating me as though I have not logged in. I don't get an 
"incorrect password/user error. I just am sent back to the bug page as though 
nothing has happened. If I go ahead and try to submit the bug, it doesn't let 
me because I am trying to do so "anonymously.

Can anyone help me figure out how to actually get logged in so I can file the 
report?

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


Re: [Tutor] name is not defined error (fwd)

2006-10-30 Thread Kent Johnson
Danny Yoo wrote:
> 
> -- Forwarded message --
> Date: Sun, 29 Oct 2006 12:33:58 -0500
> From: Kristinn Didriksson <[EMAIL PROTECTED]>
> To: Danny Yoo <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] name is not defined error
> 
> Hi Danny,
> Thanks :)
> The program works now. I'll take a look at those threads.
> Here is what the book says " This function (eval) takes any string and 
> evaluates it as if it were a Python expression." I took that to mean that it 
> would turn a sting into an integer. Oops.

eval() evaluates a Python expression and returns a value. This is 
similar to what happens when you enter text on the command line. eval() 
will take a string like '123' and turn it into the integer 123. eval() 
will also take the string 'import shutil;shutil.rmtree("/")' and turn it 
into a really bad day. A better way to convert a string that represents 
an integer into an integer is to use the int() function.

Danny's warnings apply, I just wanted to clarify eval() a bit.

Kent

> it is a little confusing to get started, but lots of practice will change 
> that.
> Thanks for your help.
> Regards,
> Kristinn
> 
> On Oct 29, 2006, at 12:15 PM, Danny Yoo wrote:
> 
>>
>>> It is my understanding that eval turns a string into a number and then I 
>>> can 
>>> do math operations on it.
>> Hi Kristinn,
>>
>> No, no, that's not what it does.  *grin*
>>
>> Where did you read about eval() from?  If you saw it in a beginner's 
>> tutorial, tell us who the guilty party is so we can knock some sense into 
>> that tutorial.
>>
>> Don't use eval(): it's "unsafe" in the sense that it does something much 
>> more 
>> than what one might expect. I won't say too much more about it at the 
>> moment, 
>> but if you're interested, see the threads:
>>
>>http://mail.python.org/pipermail/tutor/2001-September/008967.html
>>http://mail.python.org/pipermail/tutor/2004-December/033828.html
>>
>> for examples.  Again, I have to say this again: don't use eval() unless you 
>> really know what you're doing.
>>
>>
>> Anyway, I think you're looking for the ord() function:
>>
>>http://docs.python.org/lib/built-in-funcs.html#l2h-55
>>
>> Its inverse is the chr() function:
>>
>>http://docs.python.org/lib/built-in-funcs.html#l2h-15
>>
>> Good luck!
> ___
> 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] Matching on multiple log lines

2006-10-30 Thread Kent Johnson
wesley chun wrote:
>> so it's guaranteed that 'Writing Message to'
>> will always be followed by 'TRANSPORT_STREAM_ID'
>> before the next occurrence of 'Writing Message to'
>> and all text between can be ignored,
>> and we increment the counter if and only if
>> there is a newline immediately after 'TRANSPORT_STREAM_ID'
>> yes?
> 
> 
> just throwing this out there... would anyone do something like a
> open('log.txt', 'w').write(str(len(re.split(r'Writing Message
> to([\w\d\s:/\.]+?)TRANSPORT_STREAM_IDParameter value:
> 0160\r?\n'))), or is this unseemly due the fact that the file may be
> very large?

If the log file can be read into memory then a regex-based solution 
might work well though your code looks a bit scrambled to me. Rather 
than re.split() I would use re.findall().

To solve this line-by-line I would make a simple state machine that 
looks for lines of interest and moves through the states Begin, 
Found_Transport_Stream_Id and Found_Writing_Message.

Kent
> 
> advantages i see here include: no counter to maintain since you get
> the one answer at the end, your python code is not iterating thru the
> file one line at a time (the faster C code in 're' is), you auto
> matically skip the TRANSPORT_STREAM_IDs that are *not* followed by a
> NEWLINE, etc.
> 
> just wondering,
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
> http://corepython.com
> 
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


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


[Tutor] Does it helps to learn "Regular Expressions" or ...

2006-10-30 Thread Asrarahmed Kadri
Hi Folks,
 
Is it useful to know re module and its functions..??
 
Or the string module has enough utilities to accomplish string manipulation..!!!
 
Any suggestions??
 
Regards,
Asrarahmed
-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] documentation/sourceforge bug help

2006-10-30 Thread Danny Yoo


On Mon, 30 Oct 2006, C or L Smith wrote:

> Can anyone help me figure out how to actually get logged in so I can 
> file the report?

Do you happen to have cookies disabled?  You might need to enable them, 
since that's what SF will use to track your login status.  I'm getting the 
feeling that it's a cookie-management issue, but I have no real evidence 
for this yet.

Let's try isolating the problem separate from bug submission.  Can you log 
into SF by using their page at:

 https://sourceforge.net/account/login.php?return_to=%2Fmy%2F

If this doesn't work with your current setup, another option to try is to 
switch your web browser and see if that has any effect.  Firefox 2.0 just 
came out, so you can try it and see if that helps.


But you should really get in touch with the SF folks; they'd probably be 
able to diagnose this more effectively than us on Tutor.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Does it helps to learn "Regular Expressions" or ...

2006-10-30 Thread Danny Yoo

> Is it useful to know re module and its functions..??

HI Asrarahmed,

Yes.  Most people find them to be invaluable in their day-to-day work. 
The problem is that they're powerful enough that they look like an 
all-in-one tool: it's tempting to use them, even when they are the wrong 
tool for the job. *grin* So at least know about regular expressions, 
enough to know when and when not to use them.

You might want to look at the Regex HOWTO:

  http://www.amk.ca/python/howto/regex/

to get more familiar with regular expressions.



> Or the string module has enough utilities to accomplish string 
> manipulation..!!!

For simple things, I'd stick with the methods in strings.  For other 
complicated tasks, regular expressions may be the right tool.  But for 
anything that deals with structure (i.e. HTML, XML, JSON), using a real 
parser for that language is more appropriate.  (Those parsers will usually 
be built on top of regular expressions, to hide some ugliness from you.)

Concretely, if anyone asks you to if they can use regular expressions to 
parse XML, try to convince them to look into the ElementTree library 
first.


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


Re: [Tutor] Does it helps to learn "Regular Expressions" or ...

2006-10-30 Thread Asrarahmed Kadri
Thanks a lot, Danny.
Yeah, my goal is to do XML parsing and for that I will be using ElementTree.
As you pointed out, regular expressions are very powerful, so I better get some idea of about them.
 
Cheers.
Asrarahmed 
On 10/30/06, Danny Yoo <[EMAIL PROTECTED]> wrote:
> Is it useful to know re module and its functions..??HI Asrarahmed,Yes.  Most people find them to be invaluable in their day-to-day work.
The problem is that they're powerful enough that they look like anall-in-one tool: it's tempting to use them, even when they are the wrongtool for the job. *grin* So at least know about regular expressions,
enough to know when and when not to use them.You might want to look at the Regex HOWTO: http://www.amk.ca/python/howto/regex/to get more familiar with regular expressions.
> Or the string module has enough utilities to accomplish string> manipulation..!!!For simple things, I'd stick with the methods in strings.  For othercomplicated tasks, regular expressions may be the right tool.  But for
anything that deals with structure (i.e. HTML, XML, JSON), using a realparser for that language is more appropriate.  (Those parsers will usuallybe built on top of regular expressions, to hide some ugliness from you.)
Concretely, if anyone asks you to if they can use regular expressions toparse XML, try to convince them to look into the ElementTree libraryfirst.Good luck!
-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python decorators

2006-10-30 Thread Kent Johnson
euoar wrote:
> Could somebody explain or point to a good place to learn what are python 
> decorators, and when should they be used?

http://www.python.org/doc/2.4.4/whatsnew/node6.html
http://wiki.python.org/moin/PythonDecoratorLibrary
http://www.phyast.pitt.edu/~micheles/python/documentation.html

Kent

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


Re: [Tutor] basic question ...

2006-10-30 Thread Kent Johnson
Danny Yoo wrote:
> If you want to get an overview of the extent of Python's library, try the 
> table of contents:
> 
>  http://www.python.org/doc/lib/
> 
> There's a heck of a lot of stuff there, so asking someone to memorize it 
> is ridiculous.  Still, it can help to scan through it sometimes to get a 
> better idea of what services the Library provides.  I've often been amazed 
> at the gems in there.  ("bisect?  Wow, I don't have to code my own binary 
> search anymore!)

Section 2.1 Built-in Functions and Chapter 3 Built-in Types are well 
worth at least skimming and revisiting. All of the global functions such 
as dir(), len(), open(), etc, etc are documented in section 2.1. 
Built-in types such as str, list and dict are documented in chapter 3.

Kent

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


Re: [Tutor] problem importing class

2006-10-30 Thread Kent Johnson
Danny Yoo wrote:
>>> This isn't the first time this kind of problem has hit people.  This
>>> problem is well known and is the subject of a Python Enhancement Proposal
>>> (PEP 328).  If you're using Python 2.5, you can use a new feature called
>>> 'absolute_import' to avoid the import problem.  See:
>>>
>>>  http://docs.python.org/whatsnew/pep-328.html
>>>
>>> for more details.
>> Hmm, I don't see how that would help since AFAICT shawn's site.py is not 
>> in a package. Or maybe I don't understand what you are suggesting?
> 
> Hi Kent,
> 
> I don't think I replied back to you on this one!  Python loads up 
> 'site.py' on startup if called without the '-S' option:
> 
>  http://docs.python.org/lib/module-site.html
> 
> So imagine if we're a program, and we run Python on it.  For some reason 
> --- at least on startup --- Python places precendence on the modules 
> located in Python's library directory.  So we pick up the Standard 
> Library's site.py, which is then cached in sys.modules like any other 
> module import.
> 
> Later on, if we try to 'import site', Python reuses the already-loaded 
> site.py (because it's already cached in sys.modules) , regardless if 
> there's a 'site.py' module in the current working directory.  The reason 
> PEP 328 can be a solution here is because, if the absolute_import feature 
> were on, we'd be able to do:
> 
>  from . import site
> 
> which would pick up the correct relative path.

This only works for code that is in a package, when you want to import a 
module in the same package. It doesn't work for code that is not in a 
package. For example,

F:\Tutor>cat site.py
print 'imported site.py'

F:\Tutor>cat siteimporter.py
from __future__ import absolute_import
from . import site

F:\Tutor>py siteimporter.py

F:\Tutor>C:\Python25\python siteimporter.py
Traceback (most recent call last):
   File "siteimporter.py", line 2, in 
 from . import site
ValueError: Attempted relative import in non-package

> 
> 
> Concretely, here's what probably happened with the original poster:
> 
> ##
> mumak:~ dyoo$ echo "print 'hi'" > site.py
> mumak:~ dyoo$ python
> Python 2.3.5 (#1, Mar 20 2005, 20:38:20)
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
 import site
 print site.__file__
> /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site.pyc
> ###
> 
> Note that the 'site.py' in the current directory was not used.  I have no 
> idea why.  I suspect that this has some relation to the way that site.py 
> is handled by a special case in the Python interpreter, but I have really 
> no clue.

site.py is a special case just in being loaded automatically. Other than 
that this is standard behaviour. If you import a module that has already 
been imported, you will get a reference to the already-imported module, 
sys.path is not searched again. Since the library module site has 
already been imported when your program starts, 'import site' will 
always return a reference to the library module.

Kent

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


Re: [Tutor] documentation/sourceforge bug help

2006-10-30 Thread Senthil_OR
C or L Smith wrote:
> I know this is off topic, but can anyone give me a hand? I have a
> sourceforge account. I want to make a correction to the python
> documentation. I click on the appropriate link at the bottom of the
> documentation page and then the bug tracker link on the page that I
> am sent to which takes me to
> 
> http://sourceforge.net/bugs/?group_id=5470

1) Log in to http://sf.net with your account.
2) Click the above link to submit a bug.
3) There you go!

I was able do it.

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


Re: [Tutor] line number when reading files using csv module

2006-10-30 Thread Kent Johnson
Duncan Gibson wrote:
> Duncan Gibson wrote:
>>> import csv
>>>
>>> class MyReader(object):
>>> 
>>> def __init__(self, inputFile):
>>> self.reader = csv.reader(inputFile, delimiter=' ')
>>> self.lineNumber = 0
>>>
>>> def __iter__(self):
>>> self.lineNumber += 1
>>> return self.reader.__iter__()
>>>
>>> Is there some other __special__ method that I need to forward to the
>>> csv.reader, or have I lost all control once __iter__ has done its job?
> 
> Kent Johnson wrote:
>> __iter__() should return self, not self.reader.__iter__(), otherwise 
>> Python is using the actual csv.reader not your wrapper. And don't 
>> increment line number here.
>>
>> You lost control because you gave it away.
> 
> 
> Thanks Kent. The penny has dropped and it makes a lot more sense now.
> 
> I was looking for at __iter__ as a special function that *created* an
> iterator, but all it really does is signal that the returned object
> will implement the iterator interface, and the next() method in
> particular. 

I think you might still be a tiny bit confused. __iter__() is not just a 
marker, it does return an iterator. It helps if you distinguish two 
cases - iterable and iterator.

An iterable object is one for which iter(obj) returns an iterator. An 
iterator is an object with a next() method. As a special case, iterators 
are also iterable - if obj is already an iterator, then iter(obj) is 
just obj.

In modern Python (since 2.2) iter() is implemented by calling the 
special method __iter__() which should return an iterator. For a 
sequence like a list, __iter__() will return a new iterator object. 
Again, as a special case, __iter__() for an iterator returns the 
iterator itself.

You might want to read this:
http://www.python.org/doc/2.2.3/whatsnew/node4.html

I hope I am shedding light here :-)
Kent

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


Re: [Tutor] python decorators

2006-10-30 Thread euoar
Kent Johnson escribió:
> euoar wrote:
>> Could somebody explain or point to a good place to learn what are 
>> python decorators, and when should they be used?
>
> http://www.python.org/doc/2.4.4/whatsnew/node6.html
> http://wiki.python.org/moin/PythonDecoratorLibrary
> http://www.phyast.pitt.edu/~micheles/python/documentation.html
>
> Kent
>
>
Thank you for the links


__ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y móviles desde 1 céntimo por minuto. 
http://es.voice.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem importing class

2006-10-30 Thread Danny Yoo
> This only works for code that is in a package, when you want to import a
> module in the same package. It doesn't work for code that is not in a
> package. For example,
>
> F:\Tutor>cat site.py
> print 'imported site.py'
>
> F:\Tutor>cat siteimporter.py
> from __future__ import absolute_import
> from . import site
>
> F:\Tutor>py siteimporter.py
>
> F:\Tutor>C:\Python25\python siteimporter.py
> Traceback (most recent call last):
>   File "siteimporter.py", line 2, in 
> from . import site
> ValueError: Attempted relative import in non-package

Hi Kent,


Yikes!  Really?

Thank you for the correction; I completely misread the intention of PEP 
328 then.


But now I'm very miffed and unhappy.  Darn it, then that means this issue 
isn't repaired after all.  Most beginner programmers won't use packages, 
and so we'll still see the same problems pop up all the time.  Why is this 
restricted just to packages?  Let me see...

 http://mail.python.org/pipermail/python-list/2006-October/367267.html

Hmmm...  Is that the issue then?  It being the main module?  I'm now 
reading PEP 338 and looking at the section "Import Statements and the Main 
module":

 http://www.python.org/dev/peps/pep-0338/

... ok.  Good grief.  Then the current state of affairs still doesn't 
address the common case problem that we see on Tutor on module imports. 
The PEPs maintain that this is the situation for Python 2.5, emphasizing 
that this might be revisited in 2.6, which gives me some fleeting hope 
that this might get fixed in the future.

I apologize about giving the bad advice.  I was really hoping never to see 
another import problem again.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] paypal alternative

2006-10-30 Thread Over Stock
International Money Transfer  money transfer.
Send money to anyone with an email address!

http://www.vegacash.com/


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


Re: [Tutor] Matching on multiple log lines

2006-10-30 Thread Matthew Warren
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson
> Sent: 30 October 2006 11:55
> Cc: tutor@python.org
> Subject: Re: [Tutor] Matching on multiple log lines
> 
> wesley chun wrote:
> >> so it's guaranteed that 'Writing Message to'
> >> will always be followed by 'TRANSPORT_STREAM_ID'
> >> before the next occurrence of 'Writing Message to'
> >> and all text between can be ignored,
> >> and we increment the counter if and only if
> >> there is a newline immediately after 'TRANSPORT_STREAM_ID'
> >> yes?
> > 
> > 
> > just throwing this out there... would anyone do something like a
> > open('log.txt', 'w').write(str(len(re.split(r'Writing Message
> > to([\w\d\s:/\.]+?)TRANSPORT_STREAM_IDParameter value:
> > 0160\r?\n'))), or is this unseemly due the fact that the file may be
> > very large?
> 
> If the log file can be read into memory then a regex-based solution 
> might work well though your code looks a bit scrambled to me. Rather 
> than re.split() I would use re.findall().
> 
> To solve this line-by-line I would make a simple state machine that 
> looks for lines of interest and moves through the states Begin, 
> Found_Transport_Stream_Id and Found_Writing_Message.
> 
> Kent

Exactly how I have solved this in the past writing a general purpose
tool for scanning logs for things. More code, but much easier to follow.

--

[BEGIN silly disclaimer]


This email is confidential and may be privileged. If you are not the intended 
recipient please notify the sender immediately and delete the email from your 
computer. 

You should not copy the email, use it for any purpose or disclose its contents 
to any other person.
Please note that any views or opinions presented in this email may be personal 
to the author and do not necessarily represent the views or opinions of Digica.
It is the responsibility of the recipient to check this email for the presence 
of viruses. Digica accepts no liability for any damage caused by any virus 
transmitted by this email.

UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK
Reception Tel: + 44 (0) 115 977 1177
Support Centre: 0845 607 7070
Fax: + 44 (0) 115 977 7000
http://www.digica.com

SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South 
Africa
Tel: + 27 (0) 21 957 4900
Fax: + 27 (0) 21 948 3135
http://www.digica.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] documentation/sourceforge bug help

2006-10-30 Thread C or L Smith
Danny Yoo wrote:
| On Mon, 30 Oct 2006, C or L Smith wrote:
| 
|| Can anyone help me figure out how to actually get logged in so I can
|| file the report?
| 
| Do you happen to have cookies disabled?  You might need to enable
| them, since that's what SF will use to track your login status.  I'm
| getting the feeling that it's a cookie-management issue, but I have
| no real evidence for this yet.
| 
Yes, I have them enabled.

| Let's try isolating the problem separate from bug submission.  Can
| you log into SF by using their page at:
| 
| https://sourceforge.net/account/login.php?return_to=%2Fmy%2F
| 
Yes, I get sent to "My" page. From there I don't know how to navigate to the 
bug tracker page other than by using the direct link: 

http://sourceforge.net/bugs/?group_id=5470

But something different happens tonight when I put https instead of http: I am 
able to successfully be recognized as being logged in on the bug tracker page 
(there isn't a message telling me to log in first) BUT when I submit the bug, 
it tells me that anonymous submissions are not allowed. :-(  I was able to file 
a report to sourceforge on an page with nearly identical layout. And on this 
page, it took the report. I wonder if I have to be recognized as a group member 
of the python project


| If this doesn't work with your current setup, another option to try
| is to switch your web browser and see if that has any effect. 

I tried setting the agent to Internet Explorer (but didn't actually try 
internet explorer) and that didn't work.

I'll let you know if I am ever successful with this.

Thanks for the tips,

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


Re: [Tutor] paypal alternative

2006-10-30 Thread Danny Yoo


On Mon, 30 Oct 2006, Over Stock wrote:

> International Money Transfer  money transfer.

[disgusting advertisement cut]

[META: admin]

This is crass, and deserves an appropriate response.

I'm kicking 'Over Stock' off the python-tutor mailing list.  I'm now CCing 
the other list admins on the other python mailing lists to see if this 
'overstock' person has done similiar nonsense.

Actions taken:

 * Unsubscribed [EMAIL PROTECTED]
 * Added [EMAIL PROTECTED] to banned list.
 * Contacted [EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] am I a dope? - nasty_exception_str =.....

2006-10-30 Thread Alan Gauld
"Michael Daly" <[EMAIL PROTECTED]> wrote
> when I tried to start a program called 'zope' that depends on 
> python,

Hmm, Zope is rather more than a mere program.
It is a very powerful environment containing lots of fairly
sophisticated bits n pieces. Did you read through all the
Zope installation and configuration stuff (READMEs and the like)
before trying to start it? There should be a tutorial/beginners
guide for Zope somewhere on-line.

> zope seemed to install OK in the same dir (/home/digium400p/zope)
>  which I directed (via prefix option) the python 2.5 install. I did 
> this because
> python 2.3.4 is also installed in the default location on the 
> operating
> system (which is centos 4.4), and I wanted to keep it that way. Zope
> requires at least python 2.4.3

I'm not sure what the current Zope default is, but it used to want
a directory of its own...

> I didn't use the 'make altinstall' option for the python 2.5 
> install-should
> I redo this?

Probably not.

> Traceback (most recent call last):
>  File "/home/digium400p/zope/lib/python/Zope2/Startup/zopectl.py",
> line 322, in 
>main()
>  File "/home/digium400p/zope/lib/python/Zope2/Startup/zopectl.py",
> line 280, in main
>options.realize(args)
>  File "/home/digium400p/zope/lib/python/Zope2/Startup/zopectl.py",
> line 91, in realize
>ZDOptions.realize(self, *args, **kw)

Looks like some config options may need to be set to tell it
about your local environment.

>nasty_exception_str = Exception.__str__.im_func
> AttributeError: 'wrapper_descriptor' object has no
> attribute 'im_func'

But I have no idea exactl what. I only used Zope once several
years ago. I did the tutorial, it worked. I deleted Zope having
decided it was way overkill for what I was doing!

Alan G. 


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


Re: [Tutor] Does it helps to learn "Regular Expressions" or ...

2006-10-30 Thread Alan Gauld

"Asrarahmed Kadri" <[EMAIL PROTECTED]> wrote 
> 
> Is it useful to know re module and its functions..??

Yes.

> Or the string module has enough utilities to accomplish string
> manipulation..!!!

The string module is deprecated but (most of) its features are now 
found as methods of string objects. However these are not always
enough fopr all tasks and thats where regex comes in.

In my own programming I probably only use a Python regex once 
or twice a month, but in Awk I use them at least every week... So 
if you use python for the kind of things I do in awk then you will 
use them much more often...

My tutor has a basic intro to regex, and there is a more 
detailed HowTo online linked from the python site.

-- 
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] Using sys.exit()

2006-10-30 Thread Dick Moores
I'd like to know how to use sys.exit() to quit a program.

Here's a simple example:

import sys

c = 0
while True:
 c += 1
 if c > 1:
sys.exit()

Now, this will certainly exit, but not without a lot of extra noise. 
Is there a way to use it the way I want to? Maybe with an argument? 
I'm writing a script, which in a couple of places I can't use "break" to quit.

Thanks,

Dick Moores

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


[Tutor] Running multiple version of Python on 1 windows machine

2006-10-30 Thread Todd Dahl
At work I have installed Python 2.4 but at home I have Python 2.5.
Until this point I didn't think nothing of it but now I have run into
a issue.

I have some code that I have worked on at work that uses the pySQLite
module which doesn't support 2.5, yet. I can run my code at work but I
can't even install the module at home.

So my question is how do I configure my machine at home so I can have
multiple versions of python running so I can run this code. Or is this
a bad and/or confusing thing to do.

Thanks

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


[Tutor] Suggestions about documenting a function

2006-10-30 Thread Jorge Azedo
I'm writing a function that generates a list with user defined length, 
that consists only of non-repeating random integers in a user defined range.
Even I don't understand what I just wrote, so I'm just going to post the 
code and an example of the results :P

## Test module
## Last revision 31 October 2006

import random

def randomList(n1,n2,len):
'''n1-n2 range of numbers, len - length of the final list

Returns a list'''

i=0
rndlist=[]
if len > n2:
return 'The length of the list must be greater than n2'
else:
while i < len:
rand=random.randint(n1,n2)
if rndlist.count(rand) == 0:
rndlist.append(rand)
i=i+1
return rndlist

randomList(1,9,9)
[9, 8, 1, 4, 7, 6, 5, 3, 2]

Not sure if the indentation in this message is correct, but the module 
works, so that's not the problem. What I really want to ask is: Any 
suggestions on how to improve the documentation part of the module? I'd 
like to warn the user about the fact that len must be greater than n2 
before he runs it, but I can't think of a short enough way to say it so 
that it still appears in that little window that shows up when  you 
start writing the arguments to a function.
Sorry if this is confusing
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggestions about documenting a function

2006-10-30 Thread Luke Paireepinart
Jorge Azedo wrote:
> I'm writing a function that generates a list with user defined length, 
> that consists only of non-repeating random integers in a user defined range.
> Even I don't understand what I just wrote, so I'm just going to post the 
> code and an example of the results :P
>
> ## Test module
> ## Last revision 31 October 2006
>
> import random
>
> def randomList(n1,n2,len):
> '''n1-n2 range of numbers, len - length of the final list
>
> Returns a list'''
>
> i=0
> rndlist=[]
> if len > n2:
> return 'The length of the list must be greater than n2'
> else:
> while i < len:
> rand=random.randint(n1,n2)
> if rndlist.count(rand) == 0:
> rndlist.append(rand)
> i=i+1
> return rndlist
It doesn't seem like this code does what it should, does it?
I mean, if you did randomList(9,9,9)
wouldn't it go into an infinite loop?
And why does the length have to be greater than n2? that doesn't make sense.
What if I want to have 5 random numbers from within the 10 to 100 range?
randomList(10,100,5) wouldn't work.
Does this function really meet the requirements you need?
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running multiple version of Python on 1 windows machine

2006-10-30 Thread Kent Johnson
Todd Dahl wrote:
> At work I have installed Python 2.4 but at home I have Python 2.5.
> Until this point I didn't think nothing of it but now I have run into
> a issue.
> 
> I have some code that I have worked on at work that uses the pySQLite
> module which doesn't support 2.5, yet. I can run my code at work but I
> can't even install the module at home.
> 
> So my question is how do I configure my machine at home so I can have
> multiple versions of python running so I can run this code. Or is this
> a bad and/or confusing thing to do.

pysqlite is included in the standard library in Python 2.5, that is why 
there is no support on the pysqlite web site.

The package name is different, you can write the code with conditional 
imports e.g.

try
   import sqlite3 as sqlite # Python 2.5
except ImportError:
   from pysqlite2 import dbapi2 as sqlite

If changing the code is not an option you might be able to fake it out 
by making a pysqlite2.dbapi2 module that just contains
   from sqlite3 import *

I haven't tried any of this so I could be off base. I'm assuming that 
the bundled version is the same as the one you have at work other than 
the package name

You don't say what OS you are running but under Windows it is trivial to 
have multiple versions of Python installed, I have 2.3, 2.4 and 2.5. 
They are each in their own directories, all in the system path. I have 
aliases called py23, py24 and py25 that let me launch the version I 
want. I'm pretty sure you can do something similar with other OSes.

Kent

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


Re: [Tutor] Suggestions about documenting a function

2006-10-30 Thread John Fouhy
On 31/10/06, Jorge Azedo <[EMAIL PROTECTED]> wrote:
> def randomList(n1,n2,len):
> '''n1-n2 range of numbers, len - length of the final list
>
> Returns a list'''
>
> i=0
> rndlist=[]
> if len > n2:
> return 'The length of the list must be greater than n2'

Comment --- think about raising an exception here, instead of
returning an error message string.

> Not sure if the indentation in this message is correct, but the module
> works, so that's not the problem. What I really want to ask is: Any
> suggestions on how to improve the documentation part of the module? I'd
> like to warn the user about the fact that len must be greater than n2
> before he runs it, but I can't think of a short enough way to say it so
> that it still appears in that little window that shows up when  you
> start writing the arguments to a function.
> Sorry if this is confusing

Not sure what you mean about the "little window" -- is that an IDLE
thing? (I don't use IDLE, sorry)

Another comment -- I would avoid using 'len' as the name of an
argument, since 'len' is also the builtin length function.  It's not
an error to reuse the name, but most python programmers would expect
len to be the builtin when reading code.  For example, instead of
n1,n2,len, I would probably do something like:

def randomList(lo, hi, n)

Comment three -- as Luke points out, you probably need another
constraint to avoid looping endlessly.  Perhaps 'hi-lo <= (n+1)'.

Fourth comment -- you could enforce your range constraints by using assert.  ie:

def randomList(lo, hi, n):
assert lo <= hi
assert 0 <= n <= hi
assert hi-lo <= n+1

What about this:

def randomList(lo, hi, n):
 """Return n distinct random integers taken from range(lo, hi+1), where n <= hi.

 lo, hi, n :: int
 output :: [int]

 Constraints:
  lo <= hi
  0 <= n <= hi
  hi-lo <= n+1

 >>> sorted(randomList(1, 9, 9)) == range(1, 10)
 >>> randomList(1, 10, 0) == []
 >>> randomList(4, 3, 2)
 AssertionError
 >>> randomList(7, 8, 5)
 AssertionError
 >>> randomList(-5, 7, 9)
 AssertionError
 """

(those things at the end are doctests.  Read about them in the doctest
module.  Also, I haven't tested these doctests :-) )

(incidentally, apart from your condition on n <= hi, your function is
equivalent to:

def randomList(lo, hi, n):
return random.sample(range(lo, hi+1), n)

)

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


Re: [Tutor] Using sys.exit()

2006-10-30 Thread Dick Moores
At 05:06 PM 10/30/2006, Dick Moores wrote:
>I'd like to know how to use sys.exit() to quit a program.
>
>Here's a simple example:
>
>import sys
>
>c = 0
>while True:
>  c += 1
>  if c > 1:
> sys.exit()
>
>Now, this will certainly exit, but not without a lot of extra noise.
>Is there a way to use it the way I want to? Maybe with an argument?
>I'm writing a script, which in a couple of places I can't use "break" to quit.

I just found this: 


So the "noise" from sys.exit() is from using it "inside" Wing IDE. At 
the command line, the exit is silent.

Sorry for the disturbance.

Dick


>Thanks,
>
>Dick Moores
>
>___
>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] Suggestions about documenting a function

2006-10-30 Thread Jorge Azedo
Thanks for your help guys. It will take me some time to understand 
exactly what you suggested to fix the function (I'm still a newb at 
this) but thanks for your help. I'll keep you posted on the updates :)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using sys.exit()

2006-10-30 Thread Chris Hengge
Try using SPE, I've really liked it for some of extra features inside it like TODO tags that are automanaged. Also, its written in python, so thats kinda  cool factor. It's also free. 
On 10/30/06, Dick Moores <[EMAIL PROTECTED]> wrote:
At 05:06 PM 10/30/2006, Dick Moores wrote:>I'd like to know how to use sys.exit() to quit a program.>>Here's a simple example:>>import sys>>c = 0>while True:>  c += 1
>  if c > 1:> sys.exit()>>Now, this will certainly exit, but not without a lot of extra noise.>Is there a way to use it the way I want to? Maybe with an argument?>I'm writing a script, which in a couple of places I can't use "break" to quit.
I just found this:
So the "noise" from sys.exit() is from using it "inside" Wing IDE. Atthe command line, the exit is silent.Sorry for the disturbance.Dick>Thanks,>>Dick Moores
>>___>Tutor maillist  -  Tutor@python.org>http://mail.python.org/mailman/listinfo/tutor
___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


[Tutor] question about pylab

2006-10-30 Thread shawn bright
hey there,i am trying to use a graph and chart app called matplotlib, but i cannot figgure out how to have it plot a simple chart over time.the docs say to use the function plot_date() but i cannot seem to get the values to agree. 
I am sending datetimes to the charting app for x, and the y is a list of values that the our equipment reports. sometimes there are lots of reports in a row, and i would like the chart to show it like that instead of plotting out every time as an evenly spaced tick on the x scale. Does this make any sense, what i am after here? Anyway, if any of you have much experience with this sort of thing, or may suggest a package (pylab is my first attempt) please send me some advice.
thanks for your time,sk
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor