Re: [Tutor] MySqldb problem

2009-01-20 Thread Chris Babcock
On 20 Jan 2009 11:10:14 -
"Manoj kumar"  wrote:

> i am a newbie to python programming. i just know basics of the
> language. i came across MySqldb. i able to manipulate database with
> MySqldb but i wasn't able to add files in database through the lib
> MySqldb.

Right. Whatever you want to do in the database, you'll have to have a
user defined in MySQL with the necessary permissions and have that user
configured in your program.


Details:

Generally, you want to follow the principle of least permissions for
security in your app. Almost all database apps need select privileges
for their database user. A good many need insert, update and/or delete
privileges. Dynamically generated tables aren't sound relational
design, so your tables should be created using an administrative user
for the database rather than giving the MySQL user defined for your app
unnecessary privileges. As long as you're in development and no
untrusted users have access to the app, do what you want. Before
setting it wild or running it as server, whatever it does, replace the
user that you've defined as having "ALL" privilege on the database with
one that has only those privileges needed for what the app does.


Alternative:

Also, MySqldb is the manual way to use a MySQL database. It's fine if
you want to generate query strings manually because you know what
you're doing and you're sure that your code will never be used with a
different database. The problem for a new user is that using MySqldb
means learning Python and SQL at the same time to build your app. You
aren't learning Python because you're a mental masochist. You're
learning Python because it's an easy way to get programs working.

A more Pythonic way to work with databases would be to use an Object
Relational Mapper like SQLAlchemy. The simple explanation is that the
ORM lets you just work with objects in your app instead of generating
query strings. This approach also gets you a lot of other features for
free like independence from being database specific and protection from
SQL injection attacks.

Chris

-- 

Thank you everyone! USAK is live on its new connection.
So far you have given $198 towards next quarter.

To make a donation, use this link (opens on PayPal):
http://tinyurl.com/USAK2009
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SMTP Module Help

2009-01-07 Thread Chris Babcock
On Wed, 07 Jan 2009 15:47:25 +0100
Ole Henning Jensen  wrote:

> Marco Petersen wrote:
> > I'm using Python 2.5.4. I wanted to try out the SMTP module. I
> > tried to send an email through my Gmail account but it keeps saying
> > that the connection was refused.

> > error: (10061, 'Connection refused')
> > 
> > 
> > Can anyone help me with this?
> > 
> 
> I must admit that I know nothing of the SMTP module, but I do know
> that with gmail you need to use an SSL secure connection on port 995.

Yes, 995 is the port for POPS. For inbound mail, you probably want to
use IMAPS on port 993. The original question is about SMTP, however.

Google is offering SMTP submission over TLS on ports 465 and 587. Port
465 was defined as SMTP over SSL in some reference works, but the IETF
still has it listed for a router protocol. Port 587 has been reserved
for mail submission. More importantly for home users, your ISP should
NOT block port 587 (RFC 4409).

Best,
Chris

-- 

Thank you everyone! USAK is live on its new connection.
So far you have given $198 towards next quarter.

To make a donation, use this link (opens on PayPal):
http://tinyurl.com/USAK2009


signature.asc
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Word Frequency Chart

2008-12-24 Thread Chris Babcock
On Tue, 23 Dec 2008 19:17:33 -0800 (PST)
Ishan Puri  wrote:

> Hello,
> I am a beginner with Python but I understand a lot of
> linguistics. I am a high school student. I needed help (from the
> beginning) making a word frequency chart that I can use to chart out
> the numerical frequencies of words. Usually I can understand the code
> if it is annotated well, but I am not familiar with the functions and
> so forth. It would be awesome if someone could make a program that
> would chart frequencies for me. I have the corpora already. If the
> program could have something like "Type filename:" when I run it that
> would be fantastic. I have pylab as well, so the code could include
> something that would make the chart when I type in the filename. That
> would be great. Thank you. 

The Natural Language Toolkit is the place to look:

http://www.nltk.org/

This is a *deep* resource for lexical analysis. You'll probably want to
follow the examples in the book first and try them with your corpora as
you go.

Chris

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


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread Chris Babcock

> Loops, then? The  code this is based off of  had the second line of
> actual code (between "room = 1" and "if room ==1") as "while true:",
> but when I include this, it gives an error at that line. Is there
> another way to do that? Maybe "while room != 4.2"?

What you had before was...

room = 1
if room == 1
  # Room 1 stuff
elif... #Stuff that never got executed
# End of program.


Try...

room = 1
while 1:
  if room == 1:
# Room 1 stuff
  elif room == 2:
# Room 2 stuff

Your switching variable can't be the loop control and you do need to be
in a loop for the conditional expression to be evaluated again after
you've changed the value of room.

Chris


-- 


Make a difference in the world and support more Diplomacy projects and
services then you can shake a dagger at, please read:

http://members.bluegoosenews.com/diplomacy/blog/2008/09/24/a_special_note_for_diplomacy_players
 - or - 
http://tinyurl.com/3wx6lb 

Blue Goose is willing to give me $250 to support various services and
projects in the Diplomacy hobby. The blog post above will tell you why
they are doing this, what I will do with the money, and what you can do
to help me get it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question on DOMImplementation Objects

2008-09-30 Thread Chris Babcock
Does the DOMImplementation interface support schemas? 

I'm tweaking an example from a book to process a flat file registration
database:

from xml.dom import implementation

class RegistrationParser:
  def parseFile(self, fileAsString):

# Create DocType Declaration
doctype = implementation.createDocumentType('registrations', '',
'archive.xsd')

# Create empty DOM Document and get root element
doc = implementation.createDocument('', 'registrations', doctype)
elemDoc = doc.documentElement

. . . 


If I leave archive.xsd out of createDocumentType will it just generate
an XML document without validation?

Chris

-- 


Make a difference in the world and support more Diplomacy projects and
services then you can shake a dagger at, please read:

http://members.bluegoosenews.com/diplomacy/blog/2008/09/24/a_special_note_for_diplomacy_players
 - or - 
http://tinyurl.com/3wx6lb 

Blue Goose is willing to give me $250 to support various services and
projects in the Diplomacy hobby. The blog post above will tell you why
they are doing this, what I will do with the money, and what you can do
to help me get it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mod_python, mod_wsgi, web.py, django! What to use?

2008-09-28 Thread Chris Babcock
> So, lets say I want to develop a distributable web application (such
> as phpBB or Drupal) for Python. What platform (mod_wsgi, mod_python)
> would I use to reach as many users as possible, and on top of that,
> which (if any) framework should I use to develop this web application?

A lot of applications run on Apache with mod_wsgi or mod_python or as
stand alone applications with or without mod_proxy. For my own
environment, which usually involves some static pages and PHP apps, I
prefer mod_wsgi. If you go the framework route then your application
should end up being agnostic to this detail of the deployment.

I happen to like the TurboGears 2 framework. It implements Pylons with
a number of sane choices in the development environment. Using the SQL
Alchemy ORM means that I define my data in Python and call the mapper
instead of defining both a Python data structure and an SQL schema.
Where portability is an issue Alchemy takes care of it transparently.
Genshi is the default template engine for TG2. The performance is
adequate for me and that choice allows me to have non-Pythonista
friends work on the user interface.

> Also, what are some popular python web applications (forums, cms)
> that I could take example of? What did they use?

They used PHP. :-/

I think that Python suffered for a while because it was too easy to
write frameworks. For a long time it was a truism that there were as
many Python frameworks as developers. I think that made Python an
inconsistent performer for web applications, but mod_wsgi makes Python's
relative performance under Apache compared to other web scripting
languages a non-issue for the first time.

> What is currently lacking in Python's web application selection?

E-Commerce:

http://www.oreillynet.com/onlamp/blog/2007/08/fear_and_loathing_with_low_end.html

In Python e-commerce, the only significant player is Satchmo. There's
an alpha release for a plug-able CMS built on TG2 due for release next
week. I'd love to see an e-commerce plug-in.

Chris

-- 


Make a difference in the world and support more Diplomacy projects and
services then you can shake a dagger at, please read:

http://members.bluegoosenews.com/diplomacy/blog/2008/09/24/a_special_note_for_diplomacy_players
 - or - 
http://tinyurl.com/3wx6lb 

Blue Goose is willing to give me $250 to support various services and
projects in the Diplomacy hobby. The blog post above will tell you why
they are doing this, what I will do with the money, and what you can do
to help me get it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor