Re: [Tutor] Open Source database software

2008-11-25 Thread Alan Gauld


"Mike Meisner" <[EMAIL PROTECTED]> wrote

I'd like to get away from using Microsoft Access.  
I have a number of Access databases to convert.


The obvious choice would be the OpenOffice DB.
I believe it can read Access format - although I've never tried...

1.  A relational database management system for a single user 
(i.e, I don't need client/server and all the extra baggage 


A server based RDBMS is not a lot of extra baggage, 
especially small ones like Firebird but if you really don't 
want a server solution then SQLite which comes with Python
is file based and good enough for anything but enormous 
databases.


3.  A good GUI front end for creating the database, 
creating forms for user data input, queries, reports, etc.


With opensource the GUI tends to be an add on so you 
get a separate choice over which front end you want. 
Personally I don't ever use them so can make no comment, 
I prefer SQL.


Smart enough to easily read and convert an Access 
(.mdb) database file.


THat is likely to be another tool too. Apart from OpenOffice 
I don't think the databases typically feature conversion tools.


everything either in Python or with APIs that Python can 
easily use.


Again SQLite is the obvious choice here but most databases 
can be accessed from Python via the standard DBAPI and a 
suitable driver..


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] Open Source database software

2008-11-25 Thread Kent Johnson
On Mon, Nov 24, 2008 at 7:19 PM, Mike Meisner <[EMAIL PROTECTED]> wrote:

> 3.  A good GUI front end for creating the database, creating forms for user
> data input, queries, reports, etc.

For this you might look at Dabo:
http://dabodev.com/

I haven't worked with it myself but some people like it a lot.

PostgreSQL has pgAdmin which is very nice for basic admin but not for
user applications.

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


[Tutor] [Fwd: Re: My horrible looking program needs improvement.]

2008-11-25 Thread spir

Hello Peter,

Your program's structure is rather well designed... with words and whitespace.
You just need to export each consistent part of your main() into a specialised
section: module, object, function. I would suggest (use the names that make
sense for you, not mine):

* "Config" class that copes with *all* config.
~ read/store to attributes 'period' args
~ read/store ini file 'access' params
~ ...
* "AccessData" class that copes with data -- central thing -- uses config
~ read/store spam
~ read/store htaccess list
~ sort
~ update access list
~ ...
* function to output results -- uses data

I do not have enough time to help you and properly shape these objects. Still,
the AccessData class may look like that.

class AccessData(object):
''' blah blah
'''
def __init__(self):


def update():
''' this method only if process is always
purely sequential & identical
-- then may also contain init actions'''
self.read_spam(self)
self.read_htaccess(self)
self.sorted(self)
self.updated(self)
self.write_to_file
def read_spam(self):
<...>
store on attribute
def read_htaccess(self):
<...>
store on attribute
def sorted(self):
<...>
return sorted
def updated(self):
<...>
return updated?
def write_to_file(self):
<...>

And main() could be (not more!):

def main():
''' blah '''
# config
config = Config()
config.read_args()  # from command line/ optparse
config.get_access() # from ini file /ConfigParser
# update access data
# uses params from config
access_data=AccessData()
access_data.update()
# output: from access_data to ...
output()

Possibly some of the above proposal is wrong or not the best appropriate -- I
did it fast --, then adapt to reality and your taste. I'm rather surprised that 
you are able to cope with such complicated problem as web access, and not to

properly structure your code.
Feel free to ask the list for more help on what a class is, or what it is 
intended for. And why it seems appropriate such alien things in the case of you 
present code.


denis

Ps: Are you dutch?

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


[Tutor] Leaving PHP for Python

2008-11-25 Thread Jason DeBord
Hello All,

This is my first message on the mailing list. I am excited to get started
developing content / backend for the web with Python.

I have a background in PHP, but am convinced that Python is a better, more
powerful language.

I am on a Windows XP machine and I have been using XAMPP for server, php,
mysql...

I installed Python 2.5 and mod_python successfully. I can serve pages with
.py extension to http://localhost .

The following for example:

from mod_python import apache

def handler(req):
req.write("Hello World!")
return apache.OK

Frankly, I don't understand what is going on in the above. This is a bit
different compared to what I am used to.

So, my question, would you all please point me to some introductory
resources, tutorials, books, that focus on Python programming for the web? I
am eventually going to interface with some web services, notably Amazon Web
Services. Also, I'd like to write some server side scripts to serve as a
backend to some Adobe AIR apps.

Any and all advice is extremely appreciated.

Thanks for your time!

Sincerely,

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


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Don Jennings
Oops, I meant to say that django "has EXCELLENT documentation"

Take care,
Don

On 11/25/08, Don Jennings <[EMAIL PROTECTED]> wrote:
> Welcome! I suggest you take a look at django [1]. You'll find that it
> has documentation [2] and an active developer community [3]. Of
> course, for your questions about learning python, you've already found
> a very helpful community : >)
>
> Take care,
> Don
>
> [1]  http://www.djangoproject.com/
> [2] http://docs.djangoproject.com/en/dev/
> [3] http://www.djangoproject.com/community/
>
> On 11/25/08, Jason DeBord <[EMAIL PROTECTED]> wrote:
>> Hello All,
>>
>> This is my first message on the mailing list. I am excited to get started
>> developing content / backend for the web with Python.
>>
>> I have a background in PHP, but am convinced that Python is a better, more
>> powerful language.
>>
>> I am on a Windows XP machine and I have been using XAMPP for server, php,
>> mysql...
>>
>> I installed Python 2.5 and mod_python successfully. I can serve pages with
>> .py extension to http://localhost .
>>
>> The following for example:
>>
>> from mod_python import apache
>>
>> def handler(req):
>> req.write("Hello World!")
>> return apache.OK
>>
>> Frankly, I don't understand what is going on in the above. This is a bit
>> different compared to what I am used to.
>>
>> So, my question, would you all please point me to some introductory
>> resources, tutorials, books, that focus on Python programming for the web?
>> I
>> am eventually going to interface with some web services, notably Amazon
>> Web
>> Services. Also, I'd like to write some server side scripts to serve as a
>> backend to some Adobe AIR apps.
>>
>> Any and all advice is extremely appreciated.
>>
>> Thanks for your time!
>>
>> Sincerely,
>>
>> Jason
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My horrible looking program needs improvement.

2008-11-25 Thread Peter van der Does
On Tue, 25 Nov 2008 13:04:35 +0100
spir <[EMAIL PROTECTED]> wrote:

> Hello Peter,
> 
> Your program's structure is rather well designed... with words and
> whitespace. You just need to export each consistent part of your
> main() into a specialised section: module, object, function. I would
> suggest (use the names that make sense for you, not mine):
> 
> * "Config" class that copes with *all* config.
>   ~ read/store to attributes 'period' args
>   ~ read/store ini file 'access' params
>   ~ ...
> * "AccessData" class that copes with data -- central thing -- uses
> config ~ read/store spam
>   ~ read/store htaccess list
>   ~ sort
>   ~ update access list
>   ~ ...
> * function to output results -- uses data
> 
> I do not have enough time to help you and properly shape these
> objects. Still, the AccessData class may look like that.
> 
> class AccessData(object):
>   ''' blah blah
>   '''
>   def __init__(self):
>   
>   
>   def update():
>   ''' this method only if process is always
>   purely sequential & identical
>   -- then may also contain init actions'''
>   self.read_spam(self)
>   self.read_htaccess(self)
>   self.sorted(self)
>   self.updated(self)
>   self.write_to_file
>   def read_spam(self):
>   <...>
>   store on attribute
>   def read_htaccess(self):
>   <...>
>   store on attribute
>   def sorted(self):
>   <...>
>   return sorted
>   def updated(self):
>   <...>
>   return updated?
>   def write_to_file(self):
>   <...>
> 
> And main() could be (not more!):
> 
> def main():
>   ''' blah '''
>   # config
>   config = Config()
>   config.read_args()  # from command line/ optparse
>   config.get_access() # from ini file /ConfigParser
>   # update access data
>   # uses params from config
>   access_data=AccessData()
>   access_data.update()
>   # output: from access_data to ...
>   output()
>   
> Possibly some of the above proposal is wrong or not the best
> appropriate -- I did it fast -- adapt to reality and your taste. I'm
> rather surprised that you are able to cope with such complicated
> problem as web access, and not to properly structure your code.
> 
> denis
> 
> Ps: Are you dutch?
Thanks Denis,

Those are the kind of pointers I was looking for. I wasn't expecting
somebody to hand me the solution on a silver platter, as a matter of
fact I prefer not to.

The structure is more complicated, IMHO, as finding and writing a
solution.
For me programming is like a spoken language. When learning a new
language you learn the words and the basics of the grammar.

The Internet is full of dictionaries (programming language reference
guides), giving explanations of what functions do but to get to know
the grammar you'll have to read good written programs or ask for
advice :) because there aren't a lot, if any, sites out there that
teach you the grammar.

Right now the program is a book for children, the grammar is easy. I
prefer to write a bit more complex grammar because if I ever decide to
write a bigger program, the kids grammar won't work anymore.

Oh and yes I am Dutch, currently living in the US.

-- 
Peter van der Does

GPG key: E77E8E98

WordPress Plugin Developer
http://blog.avirtualhome.com

GetDeb Package Builder/GetDeb Site Coder
http://www.getdeb.net - Software you want for Ubuntu


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


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Don Jennings
Welcome! I suggest you take a look at django [1]. You'll find that it
has documentation [2] and an active developer community [3]. Of
course, for your questions about learning python, you've already found
a very helpful community : >)

Take care,
Don

[1]  http://www.djangoproject.com/
[2] http://docs.djangoproject.com/en/dev/
[3] http://www.djangoproject.com/community/

On 11/25/08, Jason DeBord <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> This is my first message on the mailing list. I am excited to get started
> developing content / backend for the web with Python.
>
> I have a background in PHP, but am convinced that Python is a better, more
> powerful language.
>
> I am on a Windows XP machine and I have been using XAMPP for server, php,
> mysql...
>
> I installed Python 2.5 and mod_python successfully. I can serve pages with
> .py extension to http://localhost .
>
> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.
>
> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web? I
> am eventually going to interface with some web services, notably Amazon Web
> Services. Also, I'd like to write some server side scripts to serve as a
> backend to some Adobe AIR apps.
>
> Any and all advice is extremely appreciated.
>
> Thanks for your time!
>
> Sincerely,
>
> Jason
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My horrible looking program needs improvement.

2008-11-25 Thread Kent Johnson
On Mon, Nov 24, 2008 at 2:21 PM, Peter van der Does
<[EMAIL PROTECTED]> wrote:
> On Mon, 24 Nov 2008 11:00:59 -0500
> Peter van der Does <[EMAIL PROTECTED]> wrote:
>
>> I wrote my 1st Python program and it works as I want it to work but
>> ,IMHO, it looks horrible.

> OK, I put the code here:
>
> http://pdoes.pastebin.com/m47109194

I would work on breaking this up into functions. The main problem with
this is the need to access the logger. I would make that a module
(global) variable so it is accessible to each function without being
passed as a parameter. Then some possible functions are

- read and parse command line options, returning the options object.
(You might want to combine the command-line options and the Config
options into a single configuration object that can be passed as a
single parameter. A couple of ways to do that:
Set the command-line options into the Config object yourself
http://www.red-dove.com/python_config.html#integrating-with-command-line-options
http://cfgparse.sourceforge.net/

- read the banned IP list, returning spamip
- setup FTP, returning the ftp object
- fetch the access log
- fetch .htaccess
- parse the access log, returning ip_list
- process the .htaccess file

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


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread bob gailer

Jason DeBord wrote:

Hello All,

This is my first message on the mailing list. I am excited to get 
started developing content / backend for the web with Python.


I have a background in PHP, but am convinced that Python is a better, 
more powerful language.


I am on a Windows XP machine and I have been using XAMPP for server, 
php, mysql...


I installed Python 2.5 and mod_python successfully. I can serve pages 
with .py extension to http://localhost .


The following for example:

from mod_python import apache

def handler(req):
req.write("Hello World!")
return apache.OK

Frankly, I don't understand what is going on in the above. 


Exactly what don't you understand. Or ... what DO you understand. There 
is a lot to explain here. Narrowing it down will make it easier.



--
Bob Gailer
Chapel Hill NC 
919-636-4239


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


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Kent Johnson
On Tue, Nov 25, 2008 at 7:43 AM, Jason DeBord <[EMAIL PROTECTED]> wrote:

> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.
>
> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web?

You might start with some general Python tutorials. Try one of these
lists, depending on your background:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
http://wiki.python.org/moin/BeginnersGuide/Programmers

Presumably you have found the mod_python docs? It has a tutorial also:
http://www.modpython.org/live/current/doc-html/

You don't say why you chose mod_python...you should know that writing
directly to mod_python is not the most popular method of writing
Python web apps. It is fine for something simple but for complex apps
you might want to look at one of the Python web frameworks such as
Django, TurboGears or web.py.

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


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread W W
On Tue, Nov 25, 2008 at 6:43 AM, Jason DeBord <[EMAIL PROTECTED]> wrote:

>
> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.


I don't know if you did much OOP (Object Oriented Programming) in PHP, or
anything else, but that's what python does, and does well. There are some
tutorials out there that explain what objects really are... but I read
somewhere that in python /everything/ is an object, and that's pretty much
true to my experience.

The line starting with from is similar to an include statement in php.
Though what you're doing is including "apache" that happens to be inside the
"mod_python" library.

The next line:

def means you're defining a function (or method, if it's in a class, where
it would be def handler(self, req), but that's another story)

handler is the name you're calling the function and req is the name of your
argument. At this point, it really doesn't matter what req is... it's just a
name that will point to (or become a copy of) whatever you pass to it.

In this case, you're passing it a class that has the method "write".
Consider this example(I'm using the IPython active interpreter, so you see
In instead of >>>):

In [15]: class foo:
   : def write(self, mystr):
   : print mystr
   :
   :

In [17]: def handler(req):
   : req.write("Hello World!")
   :
   :

In [18]: x = foo()

In [19]: handler(x)
Hello World!

And then return apache.OK is returning... well, the object "OK" in the
apache class.

Of course, I've never used mod_python/apache, that's just me applying what I
know about python, so I may not be 100% accurate, but I don't think I'm too
far off.


> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web? I
> am eventually going to interface with some web services, notably Amazon Web
> Services. Also, I'd like to write some server side scripts to serve as a
> backend to some Adobe AIR apps.


If you plan on doing much command line/admin type stuff, I'd recommend
"Python for Unix and Linux System Adminstration" by Noah Gift & Jeremy M.
Jones, available through O'Reilly, at least as one resource (ISBN:
978-0-596-51582-9)

Noah spoke at our un-conference in October, and I learned a lot, hence, my
recommendation.

It does a great job of throwing you into a lot of various administration
tasks, which instruction can be applied to (and is also useful for) many
other tasks.

Definitely check out the links others have provided, they'll be packed full
of helpful information, and I hope this helped as well.

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


[Tutor] accessing list from a string

2008-11-25 Thread Bryan Fodness
I have a list in a text file that is in the python format.,

Positions = [2.5,2.8]

and would like to grab the values.

for line in file('list.txt'):
if line == Positions:
x1,x2=Positions

I know this does not work.  Is there a direct way to get my x1 and x2
values.

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


Re: [Tutor] accessing list from a string

2008-11-25 Thread Mark Tolonen
"Bryan Fodness" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

I have a list in a text file that is in the python format.,

Positions = [2.5,2.8]

and would like to grab the values.

for line in file('list.txt'):
if line == Positions:
x1,x2=Positions

I know this does not work.  Is there a direct way to get my x1 and x2 
values.



line = '[2.5,2.8]'
x1,x2 = eval(line)
x1,x2

(2.5, 2.7998)

-Mark 



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


Re: [Tutor] accessing list from a string

2008-11-25 Thread A.T.Hofkamp

Bryan Fodness wrote:

I have a list in a text file that is in the python format.,

Positions = [2.5,2.8]


Why do you use Python format for storing data?
(Python format is for storing programs, usually)



and would like to grab the values.

for line in file('list.txt'):
if line == Positions:
x1,x2=Positions





I know this does not work.  Is there a direct way to get my x1 and x2
values.


You can import the Python file, then get the value of Positions.

import myfile
print myfile.Positions



You can read the lines from the file, and use regular expression matching to 
extract the values. That however brings problems like 'what to do when there 
are more such lines', or 'what to do if there are 3 numbers instead of 2'





In general, it is much easier to use a different file format for storing such 
information, eg you could use a .ini file format instead, and use the 
ConfigParser module to load it.



Sincerely,
Albert

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


Re: [Tutor] Open Source database software

2008-11-25 Thread Marc Tompkins
On Mon, Nov 24, 2008 at 4:19 PM, Mike Meisner <[EMAIL PROTECTED]> wrote:

> I'd like to get away from using Microsoft Access.  I have a number of
> Access databases to convert.
>
There's an open source package out there called "mdbtools", specifically for
working with Access databases.  The Python port (or wrapper?  I don't really
know) of it can be found here:
http://www.parit.ca/software/pscproject.2008-04-21.9636009485

I've never used it, so don't know whether it would be a stable long-term way
to work with MDB files, or whether it would be best to write a one-time
conversion to a different format...


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


Re: [Tutor] python question

2008-11-25 Thread Kent Johnson
On Tue, Nov 25, 2008 at 11:52 AM, Daniel J Kramer
<[EMAIL PROTECTED]> wrote:
> Hi Kent
>
> I have been playing with the ,lower command and am not having much luck.  It
> seems like a simple task, but it is not working for me.  Here is the code
>
> def main():
> score = 0
> print"Welcome to the Music Quiz.  Today's game has 8 rounds for you.
> There will be audio rounds, visual rounds and straight ahead qustions. We
> will begin with the round Journey to the Centre of New York"
> print
> A11 = raw_input ("We see the Ramones on the Bowery with rolled up
> towels under their arms chewing out a rhythm on their bubble gum.  Where are
> they planning to hitch a ride? ")
> A11 = A11.lower()

A11 now contains all lowercase characters.

>   if A11 == "Rockaway Beach" :
try
  if A11 == "rockaway beach":

Kent

PS Please use Reply All to reply to the list.

> score += 5
>  print "Correct"
>  elif A11 == "CBGB" :
>print "That's where they are, not where they are going"
> else:
>print "Wrong, they all hitched a ride to Rockaway Beach"
>
> print "Your total score ", score
>
> main()
>
> Is the placement of the .lower function in the wrong place?  When I run the
> code, the program does not recognize my input and will not give me a score.
> This happens even if I enter text with capitals.  When I remove the .lower
> function Python recognizes my answer, but only if it has capitals.
>
> any suggestions?
>
> cheers
> Daniel
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python question

2008-11-25 Thread Daniel J Kramer
Hi Kent

got it!  Is it because Python must recognize the answer as lower case?
sorry if that might seem like a dumb question, but I am looking to
understand this program.

cheers
Daniel


On Tue, Nov 25, 2008 at 12:38 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> On Tue, Nov 25, 2008 at 11:52 AM, Daniel J Kramer
> <[EMAIL PROTECTED]> wrote:
> > Hi Kent
> >
> > I have been playing with the ,lower command and am not having much luck.
>  It
> > seems like a simple task, but it is not working for me.  Here is the code
> >
> > def main():
> > score = 0
> > print"Welcome to the Music Quiz.  Today's game has 8 rounds for
> you.
> > There will be audio rounds, visual rounds and straight ahead qustions. We
> > will begin with the round Journey to the Centre of New York"
> > print
> > A11 = raw_input ("We see the Ramones on the Bowery with rolled up
> > towels under their arms chewing out a rhythm on their bubble gum.  Where
> are
> > they planning to hitch a ride? ")
> > A11 = A11.lower()
>
> A11 now contains all lowercase characters.
>
> >   if A11 == "Rockaway Beach" :
> try
>  if A11 == "rockaway beach":
>
> Kent
>
> PS Please use Reply All to reply to the list.
>
> > score += 5
> >  print "Correct"
> >  elif A11 == "CBGB" :
> >print "That's where they are, not where they are
> going"
> > else:
> >print "Wrong, they all hitched a ride to Rockaway Beach"
> >
> > print "Your total score ", score
> >
> > main()
> >
> > Is the placement of the .lower function in the wrong place?  When I run
> the
> > code, the program does not recognize my input and will not give me a
> score.
> > This happens even if I enter text with capitals.  When I remove the
> .lower
> > function Python recognizes my answer, but only if it has capitals.
> >
> > any suggestions?
> >
> > cheers
> > Daniel
> >
> >
>



-- 
Daniel J Kramer
Constant Fables
249 12th st #3
Brooklyn, NY 11215
(h) 347 223 4571
(m) 646 427 7430
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python question

2008-11-25 Thread Kent Johnson
On Tue, Nov 25, 2008 at 12:45 PM, Daniel J Kramer
<[EMAIL PROTECTED]> wrote:
> Hi Kent
>
> got it!  Is it because Python must recognize the answer as lower case?

It's because you change the user input to lower case, so you have to
compare it against a lower case answer. Maybe this helps:
In [1]: s="Abc"

In [2]: s.lower()
Out[2]: 'abc'

In [3]: s.lower() == "Abc"
Out[3]: False

In [4]: s.lower() == "abc"
Out[4]: True

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


Re: [Tutor] accessing list from a string

2008-11-25 Thread Lie Ryan
On Tue, 25 Nov 2008 06:59:13 -0800, Mark Tolonen wrote:

> "Bryan Fodness" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> I have a list in a text file that is in the python format.,
>>
>> Positions = [2.5,2.8]
>>
>> and would like to grab the values.
>>
>> for line in file('list.txt'):
>> if line == Positions:
>> x1,x2=Positions
>>
>> I know this does not work.  Is there a direct way to get my x1 and x2
>> values.
> 
 line = '[2.5,2.8]'
 x1,x2 = eval(line)
 x1,x2
> (2.5, 2.7998)
> 

Don't give recommendations on eval without mentioning its danger. eval 
can execute anything a python statement can, and that includes dangerous 
statements that can be of security risk.

Instead, in python 2.6, you may use ast.literal_eval(). Which restrict 
the eval to literal syntax only, and prohibit any function calling.

Alternatively, for previous versions of python, or for more flexibility, 
you may use the safeeval like here: http://lybniz2.sourceforge.net/
safeeval.html

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


[Tutor] Python GIL

2008-11-25 Thread OkaMthembo
Hi all,

I wish to find out what the Global Interpreter Lock is and its relevance
regarding the serving of high traffic Python sites. My understanding from
what i read is that its a state whereby only one interpreter can be invoked
on a physical machine. How does this impact performance of web apps that
receive a high rate of requests? Do scripts wait in some marshalled queue
for a certain period until their turn to be interpreted, or can multiple
simultaneous requests be processed in parallel by the Python interpreter?

Please clear my confusion regarding this topic. Any explanation would be
appreciated.

Best regards,

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


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Spencer Parker
You might also want to look at Pylons...its another excellent web framework
built for Python.  The community around it, I feel, is better than Django.
People are pretty willing to answer any and all questions you have.  It
gives more control to the developer as oppiosed to Django.  I just switched
from Django to Pylons...so far it fits me better.  Not for everyone...ya
know...

On Tue, Nov 25, 2008 at 5:43 AM, Jason DeBord <[EMAIL PROTECTED]> wrote:

> Hello All,
>
> This is my first message on the mailing list. I am excited to get started
> developing content / backend for the web with Python.
>
> I have a background in PHP, but am convinced that Python is a better, more
> powerful language.
>
> I am on a Windows XP machine and I have been using XAMPP for server, php,
> mysql...
>
> I installed Python 2.5 and mod_python successfully. I can serve pages with
> .py extension to http://localhost .
>
> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.
>
> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web? I
> am eventually going to interface with some web services, notably Amazon Web
> Services. Also, I'd like to write some server side scripts to serve as a
> backend to some Adobe AIR apps.
>
> Any and all advice is extremely appreciated.
>
> Thanks for your time!
>
> Sincerely,
>
> Jason
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


Re: [Tutor] Python GIL

2008-11-25 Thread Chris Fuller

Python interpreters running in separate processes have no affect on each 
other.  This is the easiest way to get around the limitations of the GIL.  
The GIL generally has limited effect on multithreaded applications on a 
single-core machine.  It can be a serious bottleneck on multicore machines, 
however.  Other implementations of Python, such as Jython or IronPython, do 
not have the GIL and are not subject to these limitations.  However, any 
modules written in C will not be available unless they have been ported.

A little poking around with google should tell you more.

Cheers

On Tuesday 25 November 2008 15:26, OkaMthembo wrote:
> Hi all,
>
> I wish to find out what the Global Interpreter Lock is and its relevance
> regarding the serving of high traffic Python sites. My understanding from
> what i read is that its a state whereby only one interpreter can be invoked
> on a physical machine. How does this impact performance of web apps that
> receive a high rate of requests? Do scripts wait in some marshalled queue
> for a certain period until their turn to be interpreted, or can multiple
> simultaneous requests be processed in parallel by the Python interpreter?
>
> Please clear my confusion regarding this topic. Any explanation would be
> appreciated.
>
> Best regards,
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread bob gailer
Please always reply all so a copy goes to the tutor list. We all 
participate and learn.


Jason DeBord wrote:

Bob,

Thanks for the reply.

When I said I don't understand the above, that was just to give you 
guys a reference for where I am at.


At my current job I rarely touch the web server. I have just been 
using php for server side development, thus, installing python and 
mod_python was new territory for me, though I managed to get it 
working surprisingly quick. As we speak I am trying to get Django up 
and running. This is proving difficult and I think I am getting ahead 
of myself.


I'm lost with the code below because up to this point all I have ever 
had to do is type in " 


OK - line - by - line commentary:

mod_python is an apache add-on that creates a "long-running" Python 
process. This means the Python interpreter is load once (maximizing 
response time) and there is memory from one invocation by a request to 
the next.



from mod_python import apache


Here mod_python is a python module that cooperates with the add-on. 
import loads the module (once) and brings the object apache from the 
module namespace into the local namespace.  The reference to apache.OK 
is resolved by looking at the imported object for a property (attribute) 
named OK.


def handler(req):
Defines a function handler. Apache by default calls handler for each 
request, and passes the request object (here named req - arbitrarily).

   req.write("Hello World!")
calls the req object's write method passing a character string. The 
write method adds the string to the response under construction.

   return apache.OK

Terminates the function and returns apache.OK (whatever that is).

I believe that returning apache.OK from the handler call tells apache 
that the request is complete and to return the page to the browser.


--
Bob Gailer
Chapel Hill NC 
919-636-4239


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


[Tutor] text file to excel csv file using python programming

2008-11-25 Thread Gilbert
Hi People,

I tried to look for some answers but I see only same data format
processing ( *.txt to *.txt ) in python.
my question is how to convert a text file ( e.g. *.log, *.dlg ) to excel
*.csv using python programming.
 any suggestion and where I can get this information for further
learning.  thanks.

best regards,
Gilbert
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] text file to excel csv file using python programming

2008-11-25 Thread Serdar Tumgoren
Hi Gilbert,
Check out the csv module in python's standard library.

It can convert from .txt into Excel and vice versa

http://www.python.org/doc/2.5.2/lib/module-csv.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] text file to excel csv file using python programming

2008-11-25 Thread Gilbert
Hi Serdar,

  ok thanks for your quick reply. I'll try to check this module.

Hi people & serdar,

   in case you have some websites or books you can recoomend that have some
sample python codes for converting text files ( e.g. *.dlg, *.log ) to
*.csv, kindly share.

best regards,
Gilbert

On Wed, Nov 26, 2008 at 7:21 AM, Serdar Tumgoren <[EMAIL PROTECTED]>wrote:

> Hi Gilbert,
> Check out the csv module in python's standard library.
>
> It can convert from .txt into Excel and vice versa
>
>
> http://www.python.org/doc/2.5.2/lib/module-csv.html
>
> ___
> 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] text file to excel csv file using python programming

2008-11-25 Thread Serdar Tumgoren
Hey Gilbert,
The below link leads to a very basic script I put together with some
assistance from several of the tutors on this list. It might give you a
basic idea on how to use the csv module.

http://forjournalists.com/cookbook/index.php?title=Itemizer
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] text file to excel csv file using python programming

2008-11-25 Thread Gilbert
Hi Serdar,

   I will check on this. thanks a lot.

best regards,
Gilbert

On Wed, Nov 26, 2008 at 7:40 AM, Serdar Tumgoren <[EMAIL PROTECTED]>wrote:

> Hey Gilbert,
> The below link leads to a very basic script I put together with some
> assistance from several of the tutors on this list. It might give you a
> basic idea on how to use the csv module.
>
> http://forjournalists.com/cookbook/index.php?title=Itemizer
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to get smooth, terminal-like interaction over the web

2008-11-25 Thread tchomby
I have an idea for a python program I want to write. I want to make this 
program accessible over the web for people to play with. And that's where I'm 
stuck -- I don't know what module, framework, protocol, or whatever to use to 
webify it.

It's a simple text-based program, the interaction would work perfectly in a 
terminal with the computer printing out lines of text to the user, and the user 
typing in lines of text and pressing return, and this is the kind of 
interaction I want to enable on a web page.

Can anyone point me in the direction I should be looking, if I want to 
implement this kind of interaction over the net using python? I'm aware of CGI 
and HTML forms and the python modules for it, but I think that would require 
the entire page to be reloaded every time there's an input or output. So am I 
looking at ajax, javascript, etc.? I'm a little bit lost, not knowing what's 
available out there.

I'm looking for simplicity and ease of use for a python programmer.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing list from a string

2008-11-25 Thread Alan Gauld


"Bryan Fodness" <[EMAIL PROTECTED]> wrote 


I have a list in a text file that is in the python format.,

   Positions = [2.5,2.8]


When you say "in the Python format" do you mean it 
is real Python codfe or just that it happens to look 
like Python?


If the latter what format is it really? If its a config file then 
the config parser will extract the string based on the key
(positions) for you. But you will still need to convert the 
string "[2.5,2.8]" to a list or tuple.


You could use eval to evaluate the string but that would 
be dangerous since the striong could be a malicious 
piece of code. But you can make it a lot safer by wrapping 
it in a function with known effect, thus:


s = "[2.5,2.8]"  # your string from the file

e = "tuple(" + e + ")"

x,y  = eval(e)# x -> 2.5, y -> 2.8

Now if some crazy code gets read by error the eval 
will throw an error. Its not foolproof but it works for all but 
the most devious attacks.


If you don't like that then it's down to parsing the string 
and I'd suggest a regular expression is best to pull out 
the numbers unless the string is definitely fixed format/length.


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] How to get smooth, terminal-like interaction over the web

2008-11-25 Thread Alan Gauld


"tchomby" <[EMAIL PROTECTED]> wrote


It's a simple text-based program, the interaction would work 
perfectly in a
terminal with the computer printing out lines of text to the user, 
and the user

typing in lines of text and pressing return, and this is the kind of
interaction I want to enable on a web page.


For small apps I'd suggest biting the bullet and learning JavaScript
and coding it in the browser.

The next best thing is either a Java applet - which can be written
in Jython - or an Ajax application. Both of these have a steepish
learning curve which is why I suggest learning JavaScript!

the entire page to be reloaded every time there's an input or 
output. So am I
looking at ajax, javascript, etc.? I'm a little bit lost, not 
knowing what's

available out there.


Yes I think one of JavaScript, Jython, or Ajax will be best.
I believe that Django supports Ajax and I know TurboGears does.
If you go the JavaScript route check out Mochikit which makes
JS more like Python!

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] accessing list from a string

2008-11-25 Thread Kent Johnson
On Tue, Nov 25, 2008 at 3:14 PM, Lie Ryan <[EMAIL PROTECTED]> wrote:

> Instead, in python 2.6, you may use ast.literal_eval(). Which restrict
> the eval to literal syntax only, and prohibit any function calling.

That's very cool, thanks!

> Alternatively, for previous versions of python, or for more flexibility,
> you may use the safeeval like here: http://lybniz2.sourceforge.net/
> safeeval.html

It looks like it wouldn't be hard to port ast.literal_eval to Python 2.5...

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


Re: [Tutor] accessing list from a string

2008-11-25 Thread John Fouhy
On 26/11/2008, Alan Gauld <[EMAIL PROTECTED]> wrote:
>  You could use eval to evaluate the string but that would be dangerous since
> the striong could be a malicious piece of code. But you can make it a lot
> safer by wrapping it in a function with known effect, thus:
>
>  s = "[2.5,2.8]"  # your string from the file
>
>  e = "tuple(" + e + ")"
>
>  x,y  = eval(e)# x -> 2.5, y -> 2.8
>
>  Now if some crazy code gets read by error the eval will throw an error. Its
> not foolproof but it works for all but the most devious attacks.

If I, as an evildoer, can control e, it seems that I could set it to:

,), __import__('os').system('rm -rf /'

I've never thought of myself as all that devious :-)

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


Re: [Tutor] text file to excel csv file using python programming

2008-11-25 Thread Kent Johnson
On Tue, Nov 25, 2008 at 6:16 PM, Gilbert <[EMAIL PROTECTED]> wrote:
> Hi People,
>
> I tried to look for some answers but I see only same data format
> processing ( *.txt to *.txt ) in python.
> my question is how to convert a text file ( e.g. *.log, *.dlg ) to excel
> *.csv using python programming.

This kind of program can be pretty simple, depending on the format of
your text file. It generally will have the form
open input file
open output file
open csv writer for output file

for each line in input:
  split the line into fields
  write the fields to the csv writer

close input file
close output file


The real program may not be much longer than that. I really depends on
what you need to do with the input lines. Can you show an example?

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