[Tutor] Avoiding repetetive pattern match in re module

2006-01-05 Thread Intercodes
Hello everyone,    Iam new to this mailing list as well as python(uptime-3 weeks).Today I learnt about RE from 
http://www.amk.ca/python/howto/regex/.This one was really helpful. I started working out with few examples on my own. The first one was to collect all the HTML tags used in an HTML file. I wrote this code.--

import refile1=open(raw_input("\nEnter The path of the HTML file: "),"r")ans=""while 1:    data="">    if data="">        break    ans=ans+data    
    ans1=re.sub(r' .*?',">",ans)  # to make tags such as  to relmatch=re.findall(r'<[^/]?[a-zA-Z]+.*?>',ans1)print match-
I get the output but with tags repeated. I want to display all the tags used in a file ,but no repetitions.Say the output to one of the HTML file I got was : "
"Instead of writing a new 'for,if' loop to filter the repetetive tags from the list, is there something that I can add in the re itself to match the pattern only once?
Thank You-- Intercodes

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


[Tutor] Python RE uses DFA or NFA for string check?

2006-01-10 Thread Intercodes
Hello everyone,This question is just out of curiosity. I am working with this dragon book. From what I have learnt so far, RE uses either NFA or DFA to check whether the string is accepted or not. (Correct?)
So what does the Python's RE module use to check the correctness of the string, NFA or DFA?-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python RE uses DFA or NFA for string check?

2006-01-10 Thread Intercodes
Thanks Mr.Tim. That was helpful :)On 1/10/06, Tim Peters <[EMAIL PROTECTED]> wrote:
[Intercodes]> This question is just out of curiosity. I am working with this dragon book.> From what I have learnt so far, RE uses either NFA or DFA to check whether> the string is accepted or not. (Correct?)
In the world of "computer science" regular expressions, yes.  But thethings _called_ "regular expressions" in programming languages aregenerally richer than those.  For example, almost all regexp
implementations support backreferences, and backreferences allowrecognizing languages that computer-science regexps cannot.  Forexample,^(a*)b+\1$recognizes strings that begin and end with the same number of a's,
separated by one or more b's.  It's "the same number" part that'sbeyond a pure regexp's abilities.> So what does the Python's RE module use to check the correctness of the> string, NFA or DFA?
Neither, but it's much closer to NFA than to DFA.  Most regexpimplementations in most languages supporting such a thing areimplemented via backtracking search.  Jeffrey Friedl's "MasteringRegular Expressions" is more useful than the dragon book if you want
insight into how most programming-language regexp implementationsactually work:http://www.oreilly.com/catalog/regex/To increase confusion ;-), Friedl calls backtracking search "NFA" in that book.
-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How does [::-1] work?

2006-01-18 Thread Intercodes
Hello Everyone,There was a query in this list regarding reversing a string and someone suggested that [::-1] does that.I tried that _expression_ in my intepreter and various other combination but still can't comprehend how the _expression_ works. I could understand[:] ,  [n:] or  [:n] .  But what meaning does it have in using two colons inside array index while slicing?. A concise explanation would suppress my curiosity.
Thank You.-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How does [::-1] work?

2006-01-18 Thread Intercodes
John,>Basically, the syntax is [start:stop:step] I have read some 2 or 3 introductory tutorials on python and have never found this syntax or maybe I forgot to note this one. This one seems certainly useful in some cases.
> HTH!yes, it does.!-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] mod_python and other web frameworks

2006-01-25 Thread Intercodes
Hello everyone,Disclaimer:  Beginner.I have an idea of coding a web application and decided to do it entirely with python (reddit style). I started looking for web programming in python and somehow I saw mod_python first. Iam perusing the help document now.
Few minutes of browsing confused my mind entirely , since it seems there are about 20 different web frameworks available for python. I am left clueless as to pick which one. I have an soft side towards the one I picked first.
Considering yourself as a beginner to python  ,do you prefer mod_python over all other framework?. Say if you want to create a blog , will mod_python suffice? And is mod_python and cgi (the python lib) different?
-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mod_python and other web frameworks

2006-01-25 Thread Intercodes
Lolo,Thanks for the boost up. I am looking at PSP now and it seems promising. 3 days is impossible for me :) ...maybe a week or more. I will certainly have a look at 'mighty' once I am familiar with mod_python. 
List: I am still open to suggestions.Thank You.Intercodes--On 1/26/06, Lolo <
[EMAIL PROTECTED]> wrote:Hi guys,I'm using PSP module from mod_python for professional
stuff.It's quick and easy to use, so it will be easy tocreate your blog in 3 or 4 days.You can put directly your python code in an html webpage.But currently i take a look at migthy(
http://www.myghty.org/index.myt), it's a very cooltemplating framework. And you can use it withmod_python.Have a nice day ...-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mod_python and other web frameworks

2006-01-25 Thread Intercodes
Liam, I checked the wiki video sometime back. If my memory wont fail me, the guy there never used a single line of python code ;) (I may be wrong) It seemed a totally new language that he used to create that wiki.
Iam more inclined to code a lot rather than deal with such high abstraction, as I would like to improve my programming skills and get good python knowledge. I think ill give these two a try once I have some website running under something that uses more python code. 
Thanks for your time.Thank You,IntercodesOn 1/26/06, Liam Clarke <[EMAIL PROTECTED]
> wrote:Hi,I recommend checking out the Turbogears 20 minute Wiki tutorial,
although I'd hold off using it until the 0.9 release comes out withsome useful changes.When you use it, it sits behind mod_python and responds to requests made.You can see a Turbogears error message here - :D
http://digitalsouth.net.nz/~cyresse/index.htm that I've been playingwith. Normally it works. ;)Django is also worth having a look at, but it's a bit sharper to learn
The Turbogears Google group is really supportive, by the way.-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mod_python and other web frameworks

2006-01-25 Thread Intercodes
Thanks for the input guys. I think ill go with Quixotemod_pythonpostgresXHTMLIll let you know if I have done something useful with the above four :DTYIntercodes
>If you're looking to do some Python coding to put your site together,>you might take a gander at Quixote>(http://www.mems-exchange.org/software/quixote/
).  From what I've>seen, it's the closest thing to coding a web site in Python.  It works>best with SCGI, but also with regular CGI and mod_python.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mod_python and other web frameworks

2006-01-26 Thread Intercodes
 Christian,You are certainly right. I couldn't get anything apart from "Hello world" coding in mod_python. The mod_python manual is also bit vague, not for beginners. I wonder why there aren't any good tutorials on mod_python.
I am having a look at quixote as a developer in this list suggested. I would take a look at cherrypy if quixote is too deep for me.Thanks for your time and the example. I believe your website is written completely in cherrypy. Working on so many projects ,nice work.
Intercodes# simple exampleimport cherrypyimport time
class MySection(object):@cherrypy.exposedef index(self):yield "Hello, world!"yield "Check the time"# if you are using Python 
2.3, you do the following to expose a method#   index.exposed = True@cherrypy.exposedef time(self):return "The current time is %s" % self.get_time()
# this method is not exposed and thus not accessible from the webdef get_time(self):return time.ctime()# mount the class at the server rootcherrypy.root = MySection()cherrypy.server.start
()# end of exampleYou can then run that script and visit http://localhost:8080/.  Thatwill call the "index" method of the MySection object mounted at theserver root.  You can also visit 
http://localhost:8080/time.  However,http://localhost:8080/get_time is _not_ available to the web, because itis not "exposed".
Anyhow, CherryPy is very pythonic and flexible.  Use whatever DB youwant (or flat files or ...).  Use whatever templating language you want(or just return html from your methods.Anyhow, that's probably more info than you wanted.  Good luck!
Christianhttp://www.dowski.comps And "as a beginner", I would _not_ start with something likemod_python ;-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] smtplib with yahoo smtp server

2006-01-31 Thread Intercodes
Hello everyone,I am working with a registration system for my website in mod_python. I needed to send mail to registered users for confirmation. Since I can't use my ISP's smtp server, I used yahoo's smtp server and my yahoo username and password  to connect and send mail using this script (see below). But I get the following error.
"Traceback (most recent call last):  File "mail.py", line 12, in ?    session = smtplib.SMTP(smtpserver)  File "/usr/lib/python2.4/smtplib.py", line 255, in __init__    addr = 
socket.gethostbyname(socket.gethostname())socket.gaierror: (-2, 'Name or service not known')"I got this script from some website I can't remember and just changed some values to get it to work. Is is possible to send mail like this? Is there any other easy way to do this?
Thanks for your time.---





import smtplib

smtpserver = 'smtp.mail.yahoo.com'
AUTHREQUIRED = 1 smtpuser = 
'[EMAIL PROTECTED]' 
smtppass = '[snip]'  

RECIPIENTS = ['[EMAIL PROTECTED]']
SENDER = '[EMAIL PROTECTED]'
mssg = "mod python"

session = smtplib.SMTP(smtpserver)
if AUTHREQUIRED:
session.login(smtpuser, smtppass)
smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)-- Intercodes

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


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Intercodes
Ewald, First off, thanks for stopping by. >The connection via the 
smtplib.SMTP() could be established.  I dont think so. I think it fails before the login().-->>> ex=
smtplib.SMTP('smtp.mail.yahoo.com')Traceback (most recent call last):  File "", line 1, in ?  File "/usr/lib/python2.4/smtplib.py", line 241, in __init__
    (code, msg) = self.connect(host, port)  File "/usr/lib/python2.4/smtplib.py", line 289, in connect    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):socket.gaierror: (-2, 'Name or service not known')
 >>> socket.gethostname()'linux'->>> 
socket.gethostbyname(socket.gethostname())Traceback (most recent call last):  File "", line 1, in ?socket.gaierror: (-2, 'Name or service not known')
>>>-- linux:/srv/www/htdocs/konnect # nslookup smtp.mail.yahoo.com
Server: 203.145.184.13Address:    203.145.184.13#53Non-authoritative answer:smtp.mail.yahoo.com canonical name = 
smtp.plus.mail.yahoo.com.smtp.plus.mail.yahoo.com    canonical name = smtp.plus.mail.yahoo4.akadns.net
.Name:   smtp.plus.mail.yahoo4.akadns.netAddress: 216.136.173.18 -
Thank you,--Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Intercodes
Ewald, 
> -->>>> ex= smtplib.SMTP('smtp.mail.yahoo.com <http://smtp.mail.yahoo.com
>')> Traceback (most recent call last):>   File "", line 1, in ?>   File "/usr/lib/python2.4/smtplib.py", line 241, in __init__> (code, msg) = self.connect
(host, port)>   File "/usr/lib/python2.4/smtplib.py", line 289, in connect> for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):> socket.gaierror: (-2, 'Name or service not known')
>> I am sorry , that's a mistake on my part. This output corresponds to a  typo input data. The error you saw previously was the original one (the one with error on line 255...). I corrected the typo while posting it ( ..I thought the error was same)
 -->the call should be 
socket.getaddrinfo( "smtp.mail.yahoo.com", 25, 0, >socket.SOCK_STREAM ); >>>socket.getaddrinfo('
smtp.mail.yahoo.com',25,0,socket.SOCK_STREAM)[(2, 1, 6, '', ('216.136.173.18', 25))]--
How do you resolve your hostnames ( /etc/nsswitch.conf gives the order of hostname resolution )
My nssswitch.conf --passwd: compatgroup:  compathosts:  files dnsnetworks:   files dnsservices:   filesprotocols:  files
rpc:    filesethers: filesnetmasks:   filesnetgroup:   filespublickey:  filesbootparams: filesautomount:  files nisaliases:    files -
>This should resolve your own local hostname!>The socket.gethostbyname
() is a call into a shared object of Python and this >would use ( So think I ) the standard-Libraries for resolution.You totally lost me here :) -
>Is "linux" a valid hostname?>Does "ping linux" succeed.
I suppose not.linux:/srv/ # ping linuxping: unknown host linux--
-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Intercodes
Ewald,>Here, I think is a strange problem. You can not resolve your own hostname.
>Is there no entry in /etc/hosts for linux with the IP-Address of your server?>If not, try to insert such an entry. 
Thanks for all your suggestions. I inserted my IP address for 'linux' into /etc/hosts. Now smtplib.SMTP() works. But the authentication fails. I tried all combinations of user/pass , but no joy.I tried using gmail (
smtp.gmail.com), but it too shows some TLS error or something.I ve searched google , but every script that is available for smtplib uses either sendmail or use their own/isp smtp server. None for connecting to yahoo/gmail/hotmail or other servers using authentication.
But anyway, ill try hotmail next. (If I can't get this smtp to work, I have to manually send mails to users :p, disastrous. ) Thanks for your time.-- Intercodes

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