Re: [Tutor] Python Editors .. which do you reccomend for a amateur?

2007-08-05 Thread Alan Gauld

Alan Gauld [EMAIL PROTECTED] wrote


 %PYTHON%\lib\site-packages\wx-2.6-msw-unicode\wx\py

 Just drag a shortcut to the file into the menu or onto the desktop.

I forgot to mention that it helps to change  the file extension to 
.pyw
to avoid the console window popping up.

Alan G 


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


[Tutor] Python Challenge

2007-08-05 Thread bhaaluu
Greetings:

Here's a fun site, though probably geared more for intermediate
Python programmers, than for beginners:

http://www.pythonchallenge.com/

It's 33 levels of riddles that can be solved with Python in some way
or another. =) So you have the site up in your browser, and your
Python interpreter up, and you try to solve each riddle to get to
the next level. There isn't much mouse work involved... you can't
*click* your way through it. You have to think of Python solutions
to solve each riddle. Each riddle is a combination of a picture and
a clue, or hint. Read the hint, and study the picture carefully to
figure out what to do.

Happy Programming!
-- 
bhaaluu at gmail dot com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Newbie College Student

2007-08-05 Thread TheSarge

Hi All,

Been tasked with an assignment that is kicking my butt. We have been asked
to write a py utilizing cgi to ask for simplistic web form guestbook
information (name and email). I think I am lost on whether or not my actual
py script needs to link to a cgi script or if I can do it all in a py
script. It needs to log entries to a text file and everytime I think I have
it working I go to my text file and it remains empty. I don't know if I can
post my script code in here so if I can not then my apologies forthcoming.
Any help or advice is most appreciated.

py script:

#!c:\python25\python.exe
import cgi, cgitb, os

temp = 
html
body
form action=sample.cgi
First Name: input type=text name=fnamebr
Last Name: input type=text name=lnamebr
Email:  input type=text name=emailbr
hr
input type=submit
/form
/body/html



path = 'c:\\file'
# Create instance of FieldStorage 
form = cgi.FieldStorage() 

# Get data from field 'name' 
fname = form.getvalue('fname') 

# Get data from field 'address' 
lname = form.getvalue('lname') 

# Get data from field 'email' 
email = form.getvalue('email')

if not os.path.isdir(path):
os.mkdir(path)
e=open(path + '\\' + 'logbook.txt','a')
e.write(%s#%s#%s\n % (fname,lname,email))
e.close()
print 'Done'


What am I doing wrong? Been working on this two weekends in a row and the
assignment is already late.

Thanks,

TheSarge
-- 
View this message in context: 
http://www.nabble.com/Newbie-College-Student-tf4220394.html#a12006185
Sent from the Python - tutor mailing list archive at Nabble.com.

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


Re: [Tutor] more encoding confusion

2007-08-05 Thread Jon Crump
Kent, Many thanks again, and thanks too to Paul at
http://tinyurl.com/yrl8cy.

That's very effective, thanks very much for the detailed explanation;
however, I'm a little surprised that it's necessary. I would have thought
that there would be some standard module that included a unicode 
equivalent
of the builtin method isupper().

On Fri, 3 Aug 2007, Kent Johnson wrote:

  What sort of re test can I do to catch lines whose defining
  characteristic is that they begin with two or more adjacent utf-8
  encoded capital letters?

 First you have to decode the file to a Unicode string.
 Then build the set of matching characters and build a regex. For 
example,
 something like this:

 data = open('data.txt').read().decode('utf-8').splitlines()

 uppers = u''.join(unichr(i) for i in xrange(sys.maxunicode)
if unichr(i).isupper())

I modified uppers to include only the latin characters, and added the
apostrophe to catch placenames like L'ISLE.

 upperRe = u'^[%s]{2,}' % uppers

 for line in data:
  if re.match(upperRe, line):


 With a tip of the hat to
 http://tinyurl.com/yrl8cy

 Kent

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


Re: [Tutor] more encoding confusion

2007-08-05 Thread Kent Johnson
Jon Crump wrote:
 
 Kent, Many thanks again, and thanks too to Paul at 
 http://tinyurl.com/yrl8cy.
 
 That's very effective, thanks very much for the detailed explanation; 
 however, I'm a little surprised that it's necessary. I would have 
 thought that there would be some standard module that included a unicode 
 equivalent of the builtin method isupper().

Hmm...actually, isupper() works fine on unicode strings:
In [18]: s='H\303\211RON'.decode('utf-8')
In [21]: print 'H\303\211RON'
HÉRON
In [22]: s.isupper()
Out[22]: True

:-)


 I modified uppers to include only the latin characters, and added the 
 apostrophe to catch placenames like L'ISLE.

Then you are back to needing a regular expression I think.

Kent

PS Please use Reply All to reply on-list.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie College Student

2007-08-05 Thread Bob Gailer
TheSarge wrote:
 Hi All,

 Been tasked with an assignment that is kicking my butt. We have been asked
 to write a py utilizing cgi to ask for simplistic web form guestbook
 information (name and email). I think I am lost on whether or not my actual
 py script needs to link to a cgi script or if I can do it all in a py
 script. It needs to log entries to a text file and everytime I think I have
 it working I go to my text file and it remains empty. I don't know if I can
 post my script code in here so if I can not then my apologies forthcoming.
   
We welcome code. Without it we can't begin to help. Also if you get an 
exception please post the traceback also.
 Any help or advice is most appreciated.

 py script:

 #!c:\python25\python.exe
 import cgi, cgitb, os

 temp = 
 html
 body
 form action=sample.cgi
 First Name: input type=text name=fnamebr
 Last Name: input type=text name=lnamebr
 Email:  input type=text name=emailbr
 hr
 input type=submit
 /form
 /body/html


 
 path = 'c:\\file'
 # Create instance of FieldStorage 
 form = cgi.FieldStorage() 

 # Get data from field 'name' 
 fname = form.getvalue('fname') 

 # Get data from field 'address' 
 lname = form.getvalue('lname') 

 # Get data from field 'email' 
 email = form.getvalue('email')

 if not os.path.isdir(path):
 os.mkdir(path)
 e=open(path + '\\' + 'logbook.txt','a')
 e.write(%s#%s#%s\n % (fname,lname,email))
 e.close()
 print 'Done'


 What am I doing wrong? 
I assume you included the form html as a comment, and that the actual 
form is sent to the browser first, then the actual cgi program starts 
with path =

The only problem I see is that the code to write the file is bypassed 
when the path already exists. You should be able to fix that with some 
changes to indentation.
 Been working on this two weekends in a row and the
 assignment is already late.
   
Next time ask sooner. We don't DO homework for students, but are glad to 
help when we see your effort and specific problems.

It is good that you imported the cgitb module. Just add
cgitb.enable()
to activate it.



-- 
Bob Gailer
510-978-4454 Oakland, CA
919-636-4239 Chapel Hill, NC


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


Re: [Tutor] Newbie College Student

2007-08-05 Thread Alan Gauld

TheSarge [EMAIL PROTECTED] wrote

 information (name and email). I think I am lost on whether or not my 
 actual
 py script needs to link to a cgi script or if I can do it all in a 
 py

Your python script is a CGI script and it needs to run under a web 
server.
There is a simple CGI server in the Python library that you can use 
for
testing...

 #!c:\python25\python.exe
 import cgi, cgitb, os

 temp = 
 html
 body
 form action=sample.cgi
 First Name: input type=text name=fnamebr
 Last Name: input type=text name=lnamebr
 Email:  input type=text name=emailbr
 hr
 input type=submit
 /form
 /body/html


 
 path = 'c:\\file'
 # Create instance of FieldStorage
 form = cgi.FieldStorage()

 # Get data from field 'name'
 fname = form.getvalue('fname')

 # Get data from field 'address'
 lname = form.getvalue('lname')

The comments seem to be wrong, assuming the html
in temp ids the same as is in the html file that calls this?

 # Get data from field 'email'
 email = form.getvalue('email')

 if not os.path.isdir(path):
os.mkdir(path)
e=open(path + '\\' + 'logbook.txt','a')
e.write(%s#%s#%s\n % (fname,lname,email))
e.close()
 print 'Done'

Bob has already pointed out the bug here...

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


Re: [Tutor] more encoding confusion

2007-08-05 Thread Jon Crump

On Sun, 5 Aug 2007, Kent Johnson wrote:

Hmm...actually, isupper() works fine on unicode strings:
In [18]: s='H\303\211RON'.decode('utf-8')
In [21]: print 'H\303\211RON'
HÉRON
In [22]: s.isupper()
Out[22]: True

:-)


I modified uppers to include only the latin characters, and added the 
apostrophe to catch placenames like L'ISLE.


Then you are back to needing a regular expression I think.



Ah! I'm finally starting to get it. My problem wasn't with a regex to test 
the line, my problem was with reading the file in as utf-8 to begin with. 
When I take your advice and decode() right from the start using:


open('textfile').read().decode('utf-8').splitlines()

instead of

input = open('textfile', 'r')
text = input.readlines()

Then the regex problem does not even arise. Now I can use this instead:

for line in data:
if line[0:2].isupper():

as you point out, isupper() works just fine on unicode strings; it also 
seems to consider the apostrophe uppercase as well because this catches 
not only HÉRON, but L'ISLE as well.


Now my only glitch is that line.title() screws up placenames like STOKE 
(BISHOP'S), turning it into Stoke (Bishop'S).___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor