Re: [Tutor] digging more into metaclasses

2006-07-13 Thread Alan Gauld
> are metaclasses like templates in C++
> thanks for your explanations

No, there is no direct concept of metaclasses in C++.
You need to ook to languages like Lisp and Smaltalk for those.

The nearest you get to meta-classes in C++ is static members 
and methods. But they don't allow you to alter things like method 
lookup algorithms etc. Very few, if any, statically typed languages 
support meta programming in a full sense.

Alan G.

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


[Tutor] Python Programming Books

2006-07-13 Thread Grady Henry
I have three books on Python programming, "Learning Python" by O'Reilly, 
"Beginning Python" by Hetland, and "Python in a Nutshell" by O'Reilly.  Are 
these good (recommended) books?  Any others that might be recommended? 


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


Re: [Tutor] Help with strings and lists.

2006-07-13 Thread John Fouhy
On 14/07/06, Alan Collins <[EMAIL PROTECTED]> wrote:
> You now want columns 1, 5, and 7 printed and aligned (much like a
> spreadsheet). For example:
>
> Monday547757699 100%
> Wednesday 77449 100%

Let me attempt to be the first to say:

String substitutions!!!

The docs are here: http://docs.python.org/lib/typesseq-strings.html

At their simplest, you can do things like:

s = '%s || %s || %s' % (columns[0], columns[4], columns[6])

This will print:

Monday || 547757699 || 100%

Next, you can specify padding as well:

s = '%12s || %12s || %5s' % (columns[0], columns[4], columns[6])

and the first string will be padded with spaces to 12 characters, the
second to 12, and the last to 5.  You can change which side it pads on
by specifying negative field widths --- eg, %-12s instead of %12s.
(one will produce "  Monday", the other "Monday  ".  I forget
which.)

Next, you can tell python to read the field width from a variable:

s = '%*s || %*s || %*s' % (12, columns[0], 12, columns[4], 5, columns[6])
(ie: width first)

So all you need to do is find the maximum field width (have a look at
list comprehensions and the max() function), then use string
formatting operators to lay everything out :-)

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


Re: [Tutor] email anonymizing

2006-07-13 Thread Luke Paireepinart
One way to do it:
have your form submit the body of the email,the email address, and a 
checkbox value of whether they want to anonymize it.
have a SQL table called Anonymize and if they want to anonymize the 
e-mail do
'SELECT anon FROM Anonymize WHERE email = %s' % email_from_form_submisson

to get the original email from the anonymous one do
'SELECT email FROM Anonymize WHERE anon = %s' % anon_email_value

beyond that, give us more info and we'll try to help.
Are you having trouble with SQL queries?  Are you having trouble with 
Python?
Are you having trouble with your SQL module in Python?
I suggest you try to write the program and when you get stuck,
try to find help in FAQs or the documentation of whichever module is 
giving you trouble,
and if you still can't determine what to do, we'll give ya a hand.

The thing is, there are a bunch of different ways you could do what 
you're trying to do.
First of all, you can use any database system you wanted, mySQL, 
PostgreSQL, MS ACCESS, etc etc.
Or you could even use single/multiple files, in single or multiple 
directories, depending.
You could try to anonymize the email client-side using Javascript or 
serverside using Python.

Why do you think Python is the best thing to user here?
It sounds like PHP would be better.  It's designed for this kind of thing.

You need to plan out what you're trying to do and figure out what the 
best solution is.
It's much easier for us to help you with the implementation when you 
have the design already.

That said, here's what I'd do (I don't have my Python Apache server 
running so this is going to be from memory I.E. probably not working code)
And it uses mysqldb because that's the database module I'm familiar with.

#!/usr/bin/python
#blah.cgi
#blah.cgi gets the user's e-mail address and anonymizes it.  Tru dat.

dbuser,dbpass = 'bob','pass'

print "Content-Type: text/plain\r\n\r\n"
print ""
import cgi, MySQLdb
from random import randint
info = cgi.FieldStorage()
try:
#if this fails then this is their first time accessing the page.
email=form.getfirst("email","").upper()
#okay it didn't fail so we have their email now.
#let's check the database to see if their email is there.
database = MySQLdb.connect(host="localhost", user=dbuser,passwd=dbpass)
cursor = database.cursor()
cursor.execute('SELECT anon FROM Anonymize WHERE email = %s' % email)
tmp = cursor.fetchall()
if tmp == ():#or whatever the 'fetchall' method returns if it can't 
find the entry...  
   tmp = "[EMAIL PROTECTED]" % random.randint(1000,)#make their 
random address.
   #TODO: make sure the randomly-generated key here isn't already in 
use.
   cursor.execute("INSERT INTO Anonymize (email,anon) VALUES 
('%s','%s')" % (email,tmp))#adds their crap to the table.
   
print "The e-mail address '%s' anonymized is '%s'" % (email,tmp)

except:
print """

   
   

"""
print ''

Hope that works.
Also, if you haven't already, you should read 
http://www.catb.org/~esr/faqs/smart-questions.html
-Luke

anil maran wrote:
> 1) how much programming experience you have.
> i have programmed in cfor about 1 year or so
> 2) how new to Python are you.
> very new 1 week
> 3) why do you want to solve this problem in Python?
> i m tryin to do a web app so i want to do in python
> 4) what can you apply from other languages you know (you refer to Java 
> and C++) to this problem
> i dont know how to go about this, and hence i was asking for possible solns 
> from u guys
> 5) have you written any Python code toward solving this problem?
> no i havent 
> 6) do you need help in how to do string substitutions? how to randomly 
> generate names? how to store persistently and retrieve mappings of real 
> to anonymous addresses?
> this is exactly what i want
> 7) anything else you can tell us so we can give specific help.
> i want to store the mapping in postgres table or a disk file/
> i want to input the user email and choice via a form and then 
> take it to a func called anon(email_id, choice)
> if choice == yes:
>   geneate new anon email id correspondin to email_id
>   create or update a translation table to hold the link
>   return the anon email to create the new page with anon email id
>
> much like craiglist does
>
>
> */Bob Gailer <[EMAIL PROTECTED]>/* wrote:
>
> Luke Paireepinart wrote:
> > anil maran wrote:
> >
> >> hi i m trying to anonymize emails
> >>
> > hi.
> >
> >> everytime someone enters
> >> [EMAIL PROTECTED]
> >>
> >> i want to generate
> >>
> >> [EMAIL PROTECTED] and use this email in the web application
> >>
> >> I want to do this in python
> >> can you please explain how to do this
> >>
> > Yes.
> >
> > Are you trying to anonymize their e-mail before it's sent to the
> server
> > or server-side?
> > More info please.
> > Are you using python cgi?
> >
> To amplify Luke's and others'

[Tutor] Help with strings and lists.

2006-07-13 Thread Alan Collins
Hi,

I do a far bit of data manipulation and decided to try one of my 
favourite utilities in Python. I'd really appreciate some optimization 
of the script. I'm sure that I've missed many tricks in even this short 
script.

Let's say you have a file with this data:

Monday 7373 3663657 2272 547757699 reached 100%
Tuesday 7726347 552 766463 2253 under-achieved 0%
Wednesday 9899898 8488947 6472 77449 reached 100%
Thursday 636648 553 22344 5699 under-achieved 0%
Friday 997 3647757 78736632 357599 over-achieved 200%

You now want columns 1, 5, and 7 printed and aligned (much like a 
spreadsheet). For example:

Monday547757699 100%
Wednesday 77449 100%
...

This script does the job, but I reckon there are better ways.  In the 
interests of brevity, I have dropped the command-line argument handling 
and hard-coded the columns for the test and I hard-coded the input file 
name.

---
"""
PrintColumns

Print specified columns, alignment based on data type.

The script works by parsing the input file twice.  The first pass gets 
the maximum length of
all values on the columns.  This value is used to pad the column on the 
second pass.

"""
import sys

columns = [0] # hard-code the columns to be printed.
colwidth = [0]  # list into which the maximum field lenths will 
be stored.

"""
This part is clunky.  Can't think of another way to do it without making 
the script
somewhat longer and slower. What it does is that if the user specifies 
column 0, all
columns will be printed.  This bit builds up the list of columns, from 1 
to 100.
"""

if columns[0] == 0:
 columns = [1]
 while len(columns) < 100:
 columns.append(len(columns)+1)

"""
First pass.  Read all lines and determine the maximum width of each 
selected column.
"""
infile = file("mylist", "r")
indata = infile.readlines()
for myline in indata:
 mycolumns = myline.split()
 colindex = 0
 for column in columns:
 if column <= len(mycolumns):
 if len(colwidth)-1 < colindex:
 colwidth.append(len(mycolumns[column-1]))
 else:
 if colwidth[colindex] < len(mycolumns[column-1]):
 colwidth[colindex] = len(mycolumns[column-1])
 colindex += 1
infile.close()

"""
Second pass. Read all lines and print the selected columns.  Text values 
are left
justified, while numeric values are right justified.
"""
infile = file("mylist", "r")
indata = infile.readlines()
for myline in indata:
 mycolumns = myline.split()
 colindex = 0
 for column in columns:
 if column <= len(mycolumns):
 if mycolumns[column-1].isdigit():
 x = mycolumns[column-1].rjust(colwidth[colindex]) + ' '
 else:
 x = mycolumns[column-1].ljust(colwidth[colindex]+1)
 print x,
 colindex += 1
 print ""
infile.close()
---

Any help greatly appreciated.
Regards,
Alan.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] email anonymizing

2006-07-13 Thread anil maran
1) how much programming experience you have.i have programmed in cfor about 1 year or so2) how new to Python are you.very new 1 week3) why do you want to solve this problem in Python?i m tryin to do a web app so i want to do in python4) what can you apply from other languages you know (you refer to Java and C++) to this problemi dont know how to go about this, and hence i was asking for possible solns from u guys5) have you written any Python code toward solving this problem?no i havent 6) do you need help in how to do string substitutions? how to randomly generate names? how to store persistently and retrieve mappings of real to anonymous addresses?this is exactly what i want7) anything else you can tell us so we can give specific help.i want to store the mapping in postgres table or a disk file/i want to input the user email and choice via a form and then take it to a func called anon(email_id, choice)if choice == yes:  geneate new anon email id correspondin to email_id  create or update a translation table to hold the link  return the anon email to create the new page with anon email idmuch like craiglist doesBob Gailer
 <[EMAIL PROTECTED]> wrote: Luke Paireepinart wrote:> anil maran wrote:>   >> hi i m trying to anonymize emails>> > hi.>   >> everytime someone enters>> [EMAIL PROTECTED] i want to generate [EMAIL PROTECTED] and use this email in the web application I want to do this in python>> can you please explain how to do this>> > Yes.>> Are you trying to anonymize their e-mail before it's sent to the server > or server-side?> More info please.> Are you using python cgi?>   To amplify Luke's and others' questions - we need a lot more information, and at this point in the process it seems painfully slow to extract it from you. If
 you want our help please tell us:1) how much programming experience you have.2) how new to Python are you.3) why do you want to solve this problem in Python?4) what can you apply from other languages you know (you refer to Java and C++) to this problem5) have you written any Python code toward solving this problem?6) do you need help in how to do string substitutions? how to randomly generate names? how to store persistently and retrieve mappings of real to anonymous addresses?7) anything else you can tell us so we can give specific help.> ___> Tutor maillist  -  Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor>>   -- Bob Gailer510-978-4454 
		Yahoo! Music Unlimited - Access over 1 million songs.
Try it free. ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] email anonymizing

2006-07-13 Thread Bob Gailer
Luke Paireepinart wrote:
> anil maran wrote:
>   
>> hi i m trying to anonymize emails
>> 
> hi.
>   
>> everytime someone enters
>> [EMAIL PROTECTED]
>>
>> i want to generate
>>
>> [EMAIL PROTECTED] and use this email in the web application
>>
>> I want to do this in python
>> can you please explain how to do this
>> 
> Yes.
>
> Are you trying to anonymize their e-mail before it's sent to the server 
> or server-side?
> More info please.
> Are you using python cgi?
>   
To amplify Luke's and others' questions - we need a lot more 
information, and at this point in the process it seems painfully slow to 
extract it from you. If you want our help please tell us:
1) how much programming experience you have.
2) how new to Python are you.
3) why do you want to solve this problem in Python?
4) what can you apply from other languages you know (you refer to Java 
and C++) to this problem
5) have you written any Python code toward solving this problem?
6) do you need help in how to do string substitutions? how to randomly 
generate names? how to store persistently and retrieve mappings of real 
to anonymous addresses?
7) anything else you can tell us so we can give specific help.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   


-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] email anonymizing

2006-07-13 Thread John Fouhy
On 14/07/06, anil maran <[EMAIL PROTECTED]> wrote:
> i want to know how to generate
> [EMAIL PROTECTED] =>  [EMAIL PROTECTED]
> and then how do i do the translation
> [EMAIL PROTECTED] => [EMAIL PROTECTED]

Hi Anil,

Do you have any programming experience in other languages?

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


[Tutor] digging more into metaclasses

2006-07-13 Thread anil maran
hi guysare metaclasses like templates in C++thanks for your explanations 
	
		Sneak preview the  all-new Yahoo.com. It's not radically different. Just radically better. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] email anonymizing

2006-07-13 Thread anil maran
hithe user inputs the email in a formand then they have an option to anonymize itthe server has a copy of their original and anonymous email idand the anon email is posted on the relevant pagewhen some1 needs to contact them, they would email the anon email id, the server or py program will take the ano email id and lookup real email id and send out the emaili want to know how to generate[EMAIL PROTECTED] =>  [EMAIL PROTECTED]and then how do i do the translation[EMAIL PROTECTED] => [EMAIL PROTECTED]thanksanilLuke Paireepinart <[EMAIL PROTECTED]> wrote: anil maran wrote:> hi i m trying to anonymize emailshi.> everytime someone enters> [EMAIL PROTECTED]>> i want to generate>> [EMAIL PROTECTED] and use this
 email in the web application>> I want to do this in python> can you please explain how to do thisYes.Are you trying to anonymize their e-mail before it's sent to the server or server-side?More info please.Are you using python cgi? __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] hi

2006-07-13 Thread anil maran
hi you wonderful energetic pygurusi need to send out lot of emails and sms messages from a python programplease let me know if you know of any library like java sms library or possible solutionsi m clueless and lost herethanks a lot 
		Yahoo! Music Unlimited - Access over 1 million songs.
Try it free. ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] piping to system commands

2006-07-13 Thread Gabriel Farrell
I'm trying to create a master dictionary in aspell, and I can do so
with the following:

inFile = tempfile.NamedTemporaryFile()
inFile.write(wordList)
inFile.flush()
command = 'aspell --lang=en --dont-validate-words create master %s < %s' % \
('./dict.cwl', inFile.name)
os.system(command)

or, in 2.4, instead of os.system(command):

retcode = subprocess.call(command, shell = True)

I'm wondering, is there a way to do this more directly, without the
need for a temp file, and in a way where I the stdout coming from
aspell won't go to sys.stdout?  The following seems to work, but the
end of the input gets cut off.

command = 'aspell --lang=en --dont-validate-words create master ./dict.cwl'
pipe = subprocess.Popen(command, stdin = subprocess.PIPE, shell=True).stdin
pipe.write()
pipe.flush()
pipe.close()

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


Re: [Tutor] parsing

2006-07-13 Thread Carlo Capuano

Hi!

Give a look at http://www.crummy.com/software/BeautifulSoup/

BeautifulSoup is a python module designed for parsing html

Carlo
 
what is ITER? www.iter.org
 
 
>>
>>  First, excuse me my English... English is not my native
>>language, but
>>  I hope
>>  that I will be able to describe my problem.
>>
>>  I am new in python for web, but I want to do such thing:
>>
>>  Suppose I have a html-page, like this:
>>  """
>>  TITLE
>>  
>>  body_1
>>  1_1
>>  2_1
>>  div_one_1
>>  p_1
>>  p_2
>>  div_one_2
>>  
>>  sp_text
>>  div_one_2
>>  div_one_3
>>  
>>  3_1
>>  2_2
>>  p_3
>>  body_2
>>  END
>>  
>>  td_1
>>  td_2
>>  td_3
>>  td_4
>>  ...
>>  
>>
>>  """
>>
>>  I want to get all info from this html in a dictionary
that
>>looks like
>>  this:
>>
>>  rezult = [{'title':['TITLE'],
>>  {'body':['body_1', 'body_2']},
>>  {'h1':['1_1', 'END']},
>>  {'h2':['2_1', '2_2']},
>>  {'h3':['3_1']},
>>  {'p':['p_1', 'p_2']},
>>  {'id_one':['div_one_1', 'div_one_2', 'div_one_3']},
>>  {'span_sp_1':['sp_text']},
>>  {'td':['td_1', 'td_3', 'td_4']},
>>  {'td_sp_2':['td_2']},
>>  
>>  ]
>>
>>  Huh, hope you understand what I need.
>>  Can you advise me what approaches exist to solve tasks
of such
>>type...
>>  and
>>  may be show some practical examples
>>  Thanks in advance for help of all kind...
>>
>>
>>
>>  Try ElementTree or Amara.
>>  http://effbot.org/zone/element-index.htm
>>  http://uche.ogbuji.net/tech/4suite/amara/
>>
>>  If you only cared about contents, BeautifulSoup is the answer.
>>
>>  Ismael
>>  ___
>>  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] parsing

2006-07-13 Thread Johan Geldenhuys




rezult is not a dictionary in your example, it's a list. You can create
a dictionary with all your keys and values:

rezult ={
'title': 'TITLE', 
'body':['body_1', 'body_2'], 
'h1':['1_1', 'END'], 
'h2':['2_1', '2_2'],
'h3':['3_1'],
'p':['p_1', 'p_2'],
'id_one':['div_one_1', 'div_one_2', 'div_one_3'],
'span_sp_1':['sp_text'],
'td':['td_1', 'td_3', 'td_4'],
'td_sp_2':['td_2']
}

How to get it out of your HTML page, I don't know.


Johan


Ismael Garrido wrote:

  Сергій wrote:
  
  
First, excuse me my English... English is not my native language, but 
I hope
that I will be able to describe my problem.

I am new in python for web, but I want to do such thing:

Suppose I have a html-page, like this:
"""
TITLE

body_1
1_1
2_1
div_one_1
p_1
p_2
div_one_2

sp_text
div_one_2
div_one_3

3_1
2_2
p_3
body_2
END

td_1
td_2
td_3
td_4
...


"""

I want to get all info from this html in a dictionary that looks like 
this:

rezult = [{'title':['TITLE'],
{'body':['body_1', 'body_2']},
{'h1':['1_1', 'END']},
{'h2':['2_1', '2_2']},
{'h3':['3_1']},
{'p':['p_1', 'p_2']},
{'id_one':['div_one_1', 'div_one_2', 'div_one_3']},
{'span_sp_1':['sp_text']},
{'td':['td_1', 'td_3', 'td_4']},
{'td_sp_2':['td_2']},

]

Huh, hope you understand what I need.
Can you advise me what approaches exist to solve tasks of such type... 
and
may be show some practical examples
Thanks in advance for help of all kind...

  
  
Try ElementTree or Amara.
http://effbot.org/zone/element-index.htm
http://uche.ogbuji.net/tech/4suite/amara/

If you only cared about contents, BeautifulSoup is the answer.

Ismael
___
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] abs beginner first project

2006-07-13 Thread Alan Gauld
> Also, when I reply to a message, should I 'cc:' to [EMAIL PROTECTED], add 
> an extra 'to:' field with [EMAIL PROTECTED], or change the original 'to:' 
> field to [EMAIL PROTECTED]
> What is the difference between 'cc:' and 'to:'?

To indicates the primary recipient, CC is a carbon copy for 
information.
It follows standard (ancient) office practice of sending the original
version of a letter to the main recipient and a carbon copy 
(literally)
to the other people who need to know (like your boss maybe)

So in general you will send the reply to the OP and CC to the list.
But in practice most mailers have a Reply-All button that will do
whats needed automatically!

Also a few folks don't like getting two copies if they read the list,
so they would prefer you sent the reply to the list only. As a
digest user I prefer two copies since the digest only comes in
much later. Which just shows you can't please everyone... :-)

Alan G 


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