Re: [Tutor] Help required

2009-09-26 Thread waqas ahmad

Hi, 

First of all thanks a lot for your reply. "search.findall" is not working. here 
is my complete small program.

 

def getAcl(request, pg):
pged = PageEditor(request, pg)
pagetext = pged.get_raw_body()
search=re.compile("^#acl InternationalGroup.*\n", re.M).search(pagetext)
if search:
ret=search.group()
else:
ret='not defined'
return ret


def execute(macro, args):

html="ACL List For International Group:"
all={}
pages = macro.request.rootpage.getPageList()
for pagename in pages:
if Page(macro.request,pagename).isStandardPage():
all[Page(macro.request, 
pagename).link_to(macro.request)]=getAcl(macro.request, pagename)

html+=""
all1=sorted(all.items())
for pg, ac in all1:
if ac != "not defined":
html+="%s" % pg
html+="%s" % ac
html+=""
return macro.formatter.rawHTML(html)



 
Now i explain this.

I have some wiki pages(or you can say documents). 

This python program is giving me list of all those pages, where i have written 
"#acl InternationalGroup:read" line in the pages and these pages may have also 
"CatInternational" line in the page. 

 



Now i want to search all those pages, where i have NOT written "#acl 
InternationalGroup:read" But  i have written only "CatInternational" in the 
page text.

 

I dont know how can i find only those pages where i have written only 
"CatInternational" line in the page. 

 

I shall be veryy thankful to you really for help. 

 

Best Regards, 

Waqas

 

 





Date: Fri, 25 Sep 2009 15:39:27 -0600
Subject: Re: [Tutor] Help required
From: vinces1...@gmail.com
To: waqas...@hotmail.com
CC: python-l...@python.org; tutor@python.org





On Fri, Sep 25, 2009 at 1:56 PM, waqas ahmad  wrote:





 Hi, 
 
I dont know it is the right place to post this question. I need help to change 
one search code line . can you help me please.
 
here is my search method code:
 
search=re.compile("^#acl InternationalGroup.*\n", re.M).search(pagetext)
if search:
ret=search.group()
else:
ret='not defined'
return ret

 
here i am searching for "#acl InternationalGroup" in the pageText and when it 
true is then give me search group.
 
 
I want to change this for following requirement:
 
I want to search  for "#acl InternationalGroup" and  "CatInternational" for 
both in the pageText.
when "#acl InternationalGroup" is not there but only "CatInternational" is 
there. then return me search group.
I shall be thankful to you for any help.
 
Best Regards, 
Waqas





What can you do with the new Windows Live? Find out
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


i think this is what you are looking for:



search=re.compile("(#acl\sInternationalGroup|CatInternational).*\n", 
re.M).search(pagetext)
if search:
ret=search.findall()
else:
ret='not defined'
return ret

  
_
Show them the way! Add maps and directions to your party invites. 
http://www.microsoft.com/windows/windowslive/products/events.aspx___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-26 Thread kevin parks


On Sep 26, 2009, at 11:42 PM, Alan Gauld wrote:



"Kent Johnson"  wrote


It appears to be
http://openbookproject.net/thinkCSpy/ch04.html


So it is, Thats a shame CSpy is one of my favourite "competitors" :-)

Pity it's apparently encouraging the use of eval like this with no  
caveat.


But to the OP, keep with it, its not a bad tutorial, shame about  
this exercise!





Perhaps worth alerting the author? He's a nice guy and i e-mailed him  
many moons ago when i was working through that book with some concerns  
i had. He was really receptive and grateful to get feed back and was  
quick to make changes if he thought they would improv the text. A  
super good dude and it seems, a top notch educator. He tends to credit  
*everyone* who sends in a suggestion, no matter how minor.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-26 Thread Kent Johnson
On Sat, Sep 26, 2009 at 3:59 AM, Alan Gauld  wrote:
> What are you using for a tutorial?

It appears to be
http://openbookproject.net/thinkCSpy/ch04.html

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python win32 drive mapping help

2009-09-26 Thread Alan Gauld

"Vineet Kothari"  wrote

I want to map c:/temp folder of A to C & c:/temp folder of B to C as well 
do

some copying of data and then delete the mapping.

I tried using the code given for mapping:

import win32net

win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:','password':'XXX'
})


Nobody else has mentioned it so I thought I'd point out that this is
a bit simpler (IMHO) if done via WSH COM objects. You just create
a WSH Network Object then call it's methods:

MapNetworkDrive(localName,remotePath)
RemoveNetworkDrive(localName)

There are additional optional parameters for adding to profile or using
another user name etc.

I usually use WSH for most Windows system admin type stuff.
(Although I confess I use VBScript to drive WSH rather than Python!!)
Caveat: WSH is not always installed/enabled on all PCs but nowadays
is usually there. I haven't had a case of it being missing since we
stopped using the Windows 9X series of OS.

Just a thought.

PS.
There are similarly simple methods for adding/removing Printers too.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-26 Thread Alan Gauld


"Kent Johnson"  wrote


It appears to be
http://openbookproject.net/thinkCSpy/ch04.html


So it is, Thats a shame CSpy is one of my favourite "competitors" :-)

Pity it's apparently encouraging the use of eval like this with 
no caveat.


But to the OP, keep with it, its not a bad tutorial, shame about 
this exercise!



--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Reply]need help with conditionals

2009-09-26 Thread Alan Gauld
"Corey Richardson"  wrote 


is a good Tut on conditionals. Boolean is near the top.
http://www.freenetpages.co.uk/hp/alan.gauld/tutbranch.htm


Note that this site will die soon and has not been updated 
for about 2 years. Please use the new url: http://www.alan-g.me.uk/


Note that it currently redirects to geocities but that too is closing 
shortly so it will eventually be the true home for the tutor! (Its 
getting increasingly difficult to find independant (non ISP) free web 
space on the net these days :-( )


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-26 Thread Alan Gauld


 wrote

been really frustrating me. Here's a copy of the problem, and sorry if 
its really
long but its the end question about the logically equivalent expressions 
I'm

stuck on. Anyways, heres a copy of the problem


First send us the real code you have used not a copy of your homework.

And secondly send us the complete error message not a summary.
Python error messages are extremely helpful once you learn how
to read them.

Then we might be able to help.

As Corey said my tutorial contains some stuff on understanding
booleans, but the most useful section for truth tables is in the
Functional Programming topic in the Advanced section.

But this question actually has nothing to do with conditionals
or booleans! :-)

The following Python script prints out the truth table for the any 
boolean

expression in two variables: p and q:

expression = raw_input("Enter a boolean expression in two variables, p 
and q: ")


print " p  q  %s"  % expression
length = len( " p  q  %s"  % expression)
print length*"="

for p in True, False:
   for q in True, False:
   print "%-7s %-7s %-7s" % (p, q, eval(expression))
You will learn how this script works in later chapters. For now, you will 
use it to

learn about boolean expressions. Copy this program to a file named
p_and_q.py,


Thats a terrible name BTW it would be better to call it truthtable.py!


from p_and_q import *


And this is bad practice!

What are you using for a tutorial?
If its not for a class I would consider finding another...

Use the truth_table functions with the following boolean expressions, 
recording

the truth table produced each time:

not(p or q)
not(p and q)
not(p) or not(q)
not(p) and not(q)


Also show us a cut n pasdte of you running the program - so we can see
what you are typing as input. Using eval() like this is very prone to user 
error

and also considered bad practice!

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor