Re: [Tutor] pymssql or ODBC

2006-09-14 Thread Chris Hengge
OK, so ODBC wont work.. thats not what I thought it was apparently... 

So... the question remains... how do I use Windows built in
authorization in my connection string for an MS SQL2000 server?

On Thu, 2006-09-14 at 22:53 -0500, Luke Paireepinart wrote:
> Chris Hengge wrote:
> > 4.5 hours... all I'm seeing are a few other libraries, none of which
> > mention having windows authentication :/
> >
> > On Thu, 2006-09-14 at 16:12 -0700, Chris Hengge wrote:
> >   
> >> Does anyone know how to make pymssql use windows authentication? 
> >>  
> >> 
> No, but if you know how to do it using mssql syntax it's probably the 
> same for python.
> AFAICT the db libraries just give you an interface into the db's 
> interpreter (if you'd call it that?)
> and  you pass it all the stuff you want it to do.  Is that not how 
> pymssql works?
> >> Also, can anyone point me to a simple ODBC guide for SQL? 
> >>  
> >> I'd like to use ODBC if I can so that users of my software dont have
> >> to install extra libraries to use my utilities. 
> >>  
> >> Thanks.
> >> 
> >
> > ___
> > 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] tuples versus lists

2006-09-14 Thread Bob Gailer
John Fouhy wrote:
> Generally, you should use a tuple when you have different things that
> you want to clump together to make one data structure.  Whereas you
> should use a list when you have multiple things that are the same,
> that you want to iterate over.
>   
Different perspective: tuples are immutable, lists are not. One may 
change a list by various techniques; one may not change a tuple.

tuples may be used as dictionary keys; lists may not
tuples are found on the right of % (formatting); lists are not


-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] pymssql or ODBC

2006-09-14 Thread Chris Hengge
Now that I've looked, its just a wrapper for _mssql, but this still
isn't a solution. 

On Thu, 2006-09-14 at 22:53 -0500, Luke Paireepinart wrote:
> Chris Hengge wrote:
> > 4.5 hours... all I'm seeing are a few other libraries, none of which
> > mention having windows authentication :/
> >
> > On Thu, 2006-09-14 at 16:12 -0700, Chris Hengge wrote:
> >   
> >> Does anyone know how to make pymssql use windows authentication? 
> >>  
> >> 
> No, but if you know how to do it using mssql syntax it's probably the 
> same for python.
> AFAICT the db libraries just give you an interface into the db's 
> interpreter (if you'd call it that?)
> and  you pass it all the stuff you want it to do.  Is that not how 
> pymssql works?
> >> Also, can anyone point me to a simple ODBC guide for SQL? 
> >>  
> >> I'd like to use ODBC if I can so that users of my software dont have
> >> to install extra libraries to use my utilities. 
> >>  
> >> Thanks.
> >> 
> >
> > ___
> > 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] pymssql or ODBC

2006-09-14 Thread Chris Hengge
I'm not sure how it works... all the modules I've seen just seem to be
wrappers for odbc... but I can't find any information on connection
strings.. I guess I could just try the same connection string I use for
c#.

On Thu, 2006-09-14 at 22:53 -0500, Luke Paireepinart wrote:
> Chris Hengge wrote:
> > 4.5 hours... all I'm seeing are a few other libraries, none of which
> > mention having windows authentication :/
> >
> > On Thu, 2006-09-14 at 16:12 -0700, Chris Hengge wrote:
> >   
> >> Does anyone know how to make pymssql use windows authentication? 
> >>  
> >> 
> No, but if you know how to do it using mssql syntax it's probably the 
> same for python.
> AFAICT the db libraries just give you an interface into the db's 
> interpreter (if you'd call it that?)
> and  you pass it all the stuff you want it to do.  Is that not how 
> pymssql works?
> >> Also, can anyone point me to a simple ODBC guide for SQL? 
> >>  
> >> I'd like to use ODBC if I can so that users of my software dont have
> >> to install extra libraries to use my utilities. 
> >>  
> >> Thanks.
> >> 
> >
> > ___
> > 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] pymssql or ODBC

2006-09-14 Thread Luke Paireepinart
Chris Hengge wrote:
> 4.5 hours... all I'm seeing are a few other libraries, none of which
> mention having windows authentication :/
>
> On Thu, 2006-09-14 at 16:12 -0700, Chris Hengge wrote:
>   
>> Does anyone know how to make pymssql use windows authentication? 
>>  
>> 
No, but if you know how to do it using mssql syntax it's probably the 
same for python.
AFAICT the db libraries just give you an interface into the db's 
interpreter (if you'd call it that?)
and  you pass it all the stuff you want it to do.  Is that not how 
pymssql works?
>> Also, can anyone point me to a simple ODBC guide for SQL? 
>>  
>> I'd like to use ODBC if I can so that users of my software dont have
>> to install extra libraries to use my utilities. 
>>  
>> Thanks.
>> 
>
> ___
> 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] pymssql or ODBC

2006-09-14 Thread Chris Hengge
4.5 hours... all I'm seeing are a few other libraries, none of which
mention having windows authentication :/

On Thu, 2006-09-14 at 16:12 -0700, Chris Hengge wrote:
> Does anyone know how to make pymssql use windows authentication? 
>  
> Also, can anyone point me to a simple ODBC guide for SQL? 
>  
> I'd like to use ODBC if I can so that users of my software dont have
> to install extra libraries to use my utilities. 
>  
> Thanks.

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


Re: [Tutor] tuples versus lists

2006-09-14 Thread John Fouhy
Generally, you should use a tuple when you have different things that
you want to clump together to make one data structure.  Whereas you
should use a list when you have multiple things that are the same,
that you want to iterate over.

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


Re: [Tutor] Problems serving up PDF

2006-09-14 Thread Luke Paireepinart

>> One note, you should be using \r\n instead of \n.
>> 
>
>   Both development and deployment are on a linux OS, so
>   this is the correct procedure. However, I don't think that
>   using '\r' does any harm on *nix 
>   in fact, it would be the more portable approach. 
>   Thanks for pointing that out.
>
>   
Yes, but when developing a server-side CGI script that's returning HTML 
with headers,
you're supposed to always use '\r\n' no matter
what platforms the browsers or the server run on.  It's part of some 
specification I'd guess.

>> Also, you're putting \r\n\r\n after your header, right?
>> 
>  
>Not sure what you mean. Either of the functions provide the
>header. Could you explain further?
>regards
>tim
>   
I by no means claim to be an expert at web development.
However, I wrote a few simple CGI scripts, and when you're making a header,
it goes something like this:

Content-type: text/plain\r\n
\r\n
\r\n
\r\n
\r\n
 hello \r\n
\r\n
\r\n
Hi\r\n
\r\n
\r\n

You need those two extra returns so that the browser knows it's done 
reading the header
and it should start decoding the html code.
That's all I was referring to.
I don't know if you are supposed to use \r\n always or just in the 
header section,
but I bet browsers would handle either case just fine.

That's just my opinion on all this stuff.
Use \n if it works, I guess.
If you think I might be right, investigate further.
HTH,
-Luke
> [snip]
>
>   

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


Re: [Tutor] tuples versus lists

2006-09-14 Thread Michael P. Reilly
Tuples, like other immutable data types, are hashable (assuming the contents are immutable as well), and so they can be used as keys to dictionaries.  Lists cannot be used this way.
>>> {['a']: 'a'}Traceback (most recent call last):  File "", line 1, in ?TypeError: list objects are unhashable>>> {('a',): 'a'}{('a',): 'a'}>>> 
  -ArcegeOn 9/14/06, Tim Johnson <[EMAIL PROTECTED]> wrote:
* Kermit Rose <[EMAIL PROTECTED]> [060914 18:29]:> Hello Brian.>> Today I read through chapter five of the python tutorial and discovered> that tuples are not the same thing as lists.
>> This surprised me.>> I do not see any difference in the capability of lists and tuples.  Hi Kermit:  Tuples are "read-only" - you can't modify a tuple,  you can produce a tuple from a list by using the
  tuple() function.  you can produce a list from a tuple by using the  list() function - but the original tuple is unchanged.  You can return multiple values from a function  using tuples.>
> Why would you use one in preference to the other?  I use tuples as above and where I don't want data  changed...  tim--Tim Johnson <[EMAIL PROTECTED]
>  http://www.alaska-internet-solutions.com___Tutor maillist  -  
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor-- There's so many different worlds,So many different suns.
And we have just one world,But we live in different ones.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tuples versus lists

2006-09-14 Thread Tim Johnson
* Kermit Rose <[EMAIL PROTECTED]> [060914 18:29]:
> Hello Brian.
> 
> Today I read through chapter five of the python tutorial and discovered 
> that tuples are not the same thing as lists.
> 
> This surprised me. 
> 
> I do not see any difference in the capability of lists and tuples.
 
  Hi Kermit:

  Tuples are "read-only" - you can't modify a tuple,

  you can produce a tuple from a list by using the 
  tuple() function.
  you can produce a list from a tuple by using the
  list() function - but the original tuple is unchanged.
   
  You can return multiple values from a function
  using tuples. 
> 
> Why would you use one in preference to the other?

  I use tuples as above and where I don't want data
  changed...

  tim
-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] tuples versus lists

2006-09-14 Thread Kermit Rose
Hello Brian.

Today I read through chapter five of the python tutorial and discovered 
that tuples are not the same thing as lists.

This surprised me. 

I do not see any difference in the capability of lists and tuples.

Why would you use one in preference to the other?


Kermit   <   [EMAIL PROTECTED]   >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems serving up PDF

2006-09-14 Thread Tim Johnson
* Luke Paireepinart <[EMAIL PROTECTED]> [060914 17:37]:
> >   
> Sounds like it's working to me.
> > On Internet Explorer 6, Windows XP, the user experience is different.
> > IE ignores the file name, and does no progress reporting, but does
> > "understand" the file type.
> >   
> Sounds like it's working to me.
> 
> 
> As far as I can tell, it seems to me like you have some file (example .wmv)
> that I.E. is saying 'okay I know how to open this' and it tries to do 
> something with it.
> Firefox, humble as it is, admits that it doesn't know what to do and 
> just lets you download it.
> If this is the case, then it's a configuration issue with IE that's 
> making it attempt to open the file.
> You could just as well configure Firefox to automatically open these 
> files too, although
> that doesn't mean that it'll work :)
> 
> So unless you can be more specific, I'd say that it's just a difference 
> in the browser and not a problem
> with your code at all.  Do I not understand correctly?
> HTH,
 
  Hey Luke:
  I also posted this to a forum:
  One expert response reads like this:

  "I think that's just the way Mozilla acts." 

  Actually, I like the way Firefox does it. Looks like we just live
  with the differences.
  thanks again
  tim
-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems serving up PDF

2006-09-14 Thread Tim Johnson
* Luke Paireepinart <[EMAIL PROTECTED]> [060914 17:36]:
> Tim Johnson wrote:
> >Hi: 
> >
> >This is *not* really a python problem, but :-) since this
> >is such an helpful list and others may have the same issue...
> >
> >I have a python script which searches a server for a pdf file
> >and if found, reads the file to stdout, as one would read html
> >to stdout.
> >  
> >The question is really about the proper content-type:
> >
> >Both of the following functions have been tried:
> >
> >def pdf_header1(file_name,length):
> >""" Serve a PDF document via CGI with content length."""
> >print (
> >'Content-type: application/pdf\n'
> >'Content-Length: %d\n'
> >'Content-Disposition: attachment;filename="%s"\n'
> >) % (length,file_name)
> >
> >def pdf_header(file_name,length):
> >""" Serve a PDF document via CGI with content length."""
> >print (
> >'Content-type: application/pdf\n'
> >'Content-Disposition: inline; filename=%s\n'
> >'Content-length: %d\n'
> >) % (file_name,length)
> >
> >  
 
 Hi Luke:

> You have a cgi script on your server that searches itself for a file and 
> serves it to the user?
  
   Correct.

> One note, you should be using \r\n instead of \n.

  Both development and deployment are on a linux OS, so
  this is the correct procedure. However, I don't think that
  using '\r' does any harm on *nix 
  in fact, it would be the more portable approach. 
  Thanks for pointing that out.

> Also, you're putting \r\n\r\n after your header, right?
 
   Not sure what you mean. Either of the functions provide the
   header. Could you explain further?
   regards
   tim

> >Regardless of which is used, on Mozilla, I have the following
> >response: 
> >  A dialog that names the file, identifies the filetype, and
> >  gives a choice of whether to download or open the file.
> >  when the choice is made, progress is reported via another
> >  window and the selected action occurs when download is finished.
> >  
> Sounds like it's working to me.
> >On Internet Explorer 6, Windows XP, the user experience is different.
> >IE ignores the file name, and does no progress reporting, but does
> >"understand" the file type.
> >  
> Sounds like it's working to me.
> 
> 
> As far as I can tell, it seems to me like you have some file (example .wmv)
> that I.E. is saying 'okay I know how to open this' and it tries to do 
> something with it.
> Firefox, humble as it is, admits that it doesn't know what to do and 
> just lets you download it.
> If this is the case, then it's a configuration issue with IE that's 
> making it attempt to open the file.
> You could just as well configure Firefox to automatically open these 
> files too, although
> that doesn't mean that it'll work :)
> 
> So unless you can be more specific, I'd say that it's just a difference 
> in the browser and not a problem
> with your code at all.  Do I not understand correctly?
> HTH,
> -Luke
> >Does anyone have any experience with this issue? Or could anyone
> >recommend a more appropriate place to post this question?
> >Thanks
> >tim
> >
> >  

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] RfC822 or email module

2006-09-14 Thread STREET Gideon (SPARQ)

Morning all,

I'm currently trying to figure out a way of downloading email and
passing it into a SQLite database.  I've got the downloading email side
worked out using a variation of popmail.py from one of the python books
I've got.

Also worked out how to talk to the database from Alan Gauld's tutor
(Thanks Alan, your webpage is probably one of most valuable pages I've
come across).

What I'm trying to do is split out the email headers (from, date and
subject) and store them in their respective fields and the message body
in another field.  Was wondering which python module, email of rfc822,
would be the most useful?  Lot's of doco around these two but there
appears to be some overlap.

Cheers

Gideon

This e-mail (including any attachments) may contain confidential or
privileged information and is intended for the sole use of the person(s) to
whom it is addressed. If you are not the intended recipient, or the person
responsible for delivering this message to the intended recipient, please
notify the sender of the message or send an e-mail to
mailto:[EMAIL PROTECTED] immediately, and delete all copies. Any
unauthorised review, use, alteration, disclosure or distribution of this
e-mail by an unintended recipient is prohibited. Ergon Energy accepts no
responsibility for the content of any e-mail sent by an employee which is of
a personal nature.

Ergon Energy Corporation Limited  ABN 50 087 646 062
Ergon Energy Pty Ltd  ABN 66 078 875 902
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems serving up PDF

2006-09-14 Thread Luke Paireepinart
Tim Johnson wrote:
> Hi: 
>
> This is *not* really a python problem, but :-) since this
> is such an helpful list and others may have the same issue...
>
> I have a python script which searches a server for a pdf file
> and if found, reads the file to stdout, as one would read html
> to stdout.
>   
> The question is really about the proper content-type:
>
> Both of the following functions have been tried:
>
> def pdf_header1(file_name,length):
> """ Serve a PDF document via CGI with content length."""
> print (
> 'Content-type: application/pdf\n'
> 'Content-Length: %d\n'
> 'Content-Disposition: attachment;filename="%s"\n'
> ) % (length,file_name)
>
> def pdf_header(file_name,length):
> """ Serve a PDF document via CGI with content length."""
> print (
> 'Content-type: application/pdf\n'
> 'Content-Disposition: inline; filename=%s\n'
> 'Content-length: %d\n'
> ) % (file_name,length)
>
>   
You have a cgi script on your server that searches itself for a file and 
serves it to the user?
One note, you should be using \r\n instead of \n.
Also, you're putting \r\n\r\n after your header, right?
> Regardless of which is used, on Mozilla, I have the following
> response: 
>   A dialog that names the file, identifies the filetype, and
>   gives a choice of whether to download or open the file.
>   when the choice is made, progress is reported via another
>   window and the selected action occurs when download is finished.
>   
Sounds like it's working to me.
> On Internet Explorer 6, Windows XP, the user experience is different.
> IE ignores the file name, and does no progress reporting, but does
> "understand" the file type.
>   
Sounds like it's working to me.


As far as I can tell, it seems to me like you have some file (example .wmv)
that I.E. is saying 'okay I know how to open this' and it tries to do 
something with it.
Firefox, humble as it is, admits that it doesn't know what to do and 
just lets you download it.
If this is the case, then it's a configuration issue with IE that's 
making it attempt to open the file.
You could just as well configure Firefox to automatically open these 
files too, although
that doesn't mean that it'll work :)

So unless you can be more specific, I'd say that it's just a difference 
in the browser and not a problem
with your code at all.  Do I not understand correctly?
HTH,
-Luke
> Does anyone have any experience with this issue? Or could anyone
> recommend a more appropriate place to post this question?
> Thanks
> tim
>
>   

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


[Tutor] Problems serving up PDF

2006-09-14 Thread Tim Johnson
Hi: 

This is *not* really a python problem, but :-) since this
is such an helpful list and others may have the same issue...

I have a python script which searches a server for a pdf file
and if found, reads the file to stdout, as one would read html
to stdout.

The question is really about the proper content-type:

Both of the following functions have been tried:

def pdf_header1(file_name,length):
""" Serve a PDF document via CGI with content length."""
print (
'Content-type: application/pdf\n'
'Content-Length: %d\n'
'Content-Disposition: attachment;filename="%s"\n'
) % (length,file_name)

def pdf_header(file_name,length):
""" Serve a PDF document via CGI with content length."""
print (
'Content-type: application/pdf\n'
'Content-Disposition: inline; filename=%s\n'
'Content-length: %d\n'
) % (file_name,length)

Regardless of which is used, on Mozilla, I have the following
response: 
  A dialog that names the file, identifies the filetype, and
  gives a choice of whether to download or open the file.
  when the choice is made, progress is reported via another
  window and the selected action occurs when download is finished.

On Internet Explorer 6, Windows XP, the user experience is different.
IE ignores the file name, and does no progress reporting, but does
"understand" the file type.

Does anyone have any experience with this issue? Or could anyone
recommend a more appropriate place to post this question?
Thanks
tim

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] arrays

2006-09-14 Thread John Fouhy
On 15/09/06, federico ramirez <[EMAIL PROTECTED]> wrote:
> an array to order the keys and then display it in order but..python orders
> the array like this
>
> ['_1', '_10', '_11', '_12', '_13', '_2', '_3', '_4', '_5', '_6', '_7', '_8',
> '_9']
>
> and i want
>
> ['_1', '_2', '_3', '_4', '_5', '_6', '_7', '_8', '_9','_10', '_11', '_12',
> '_13']

Hi,

First, just a terminology note -- in python, these are called lists, not arrays.

> arr = []
> for key in db.keys():
> arr += [key]
> arr.sort()
> arr.reverse()

db.keys() returns a _new_ list, so there is no need to do this step;
you could just write:
arr = db.keys()

Now, since your keys are strings, python is sorting them
lexicographically, which is why (for instance) '_10' comes before
'_2'.  You need to tell python to change its sort order.

You can do this in a couple of ways.  If you have python2.4 or
greater, you can use the key= keyword argument to sort, like this:

def keyToInt(s):
"""Convert '_10' to 10, '_2' to 2, etc. """
return int(s[1:])
arr.sort(key=keyToInt)

If you have an earlier version of python, you can define your own
comparison function:

def myCmp(x, y):
return cmp(keyToInt(x), keyToInt(y))
arr.sort(myCmp)

You can also use the decorate-sort-undecorate idiom, which may be
faster than a custom comparison function if the list is very large.

decorated = [(keyToInt(s), s) for s in arr]
decorated.sort()
arr = [x[1] for x in decorated]

> for i in range(len(db)):
> print db[arr[i]],''

In python, you can iterate over lists directly.  ie, since arr is your
list of keys:

for key in arr:
print db[key], ''

HTH!

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


[Tutor] How to split a file (was (no subject))

2006-09-14 Thread Bob Gailer
[EMAIL PROTECTED] wrote:
> This is the first time I have posted to this list so I hope I am asking
> appropriate question in acceptable way. Want I want to do is take a file and
> cut it into pieces so each piece is a new unique file; the new files would be
> one line (newline) from the file I want to cut up. The file  I want to cut up
> has 3900 lines. This is as far as I have got.
Others have provided the "answer". Since you are new to the list I will 
add the request that you provide a meaningful subject line so we can 
track the various threads.

-- 
Bob Gailer
510-978-4454

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


[Tutor] arrays

2006-09-14 Thread federico ramirez
Hi all! Im started with python some days ago, im trying to make a basic
cgi script, with dbm, and dbm returns a dictionary witout order, so i
put it in an array to order the keys and then display it in order
but..python orders the array like this

['_1', '_10', '_11', '_12', '_13', '_2', '_3', '_4', '_5', '_6', '_7', '_8', '_9']

and i want

['_1', '_2', '_3', '_4', '_5', '_6', '_7', '_8', '_9','_10', '_11', '_12', '_13']

here its the code i use

///

#!/usr/bin/python

print "Content-Type: text/html\n\n"

import cgi, dbm

def startpage(title):
    print '''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    http://www.w3.org/1999/xhtml">
    
    
    ''',title,'''
    
    '''
    
def endpage():
    print """
    """

def main():
    form = cgi.FieldStorage()
    if(form.has_key("name") and form["name"].value != ""):
        db = dbm.open("dbm", "c")
        db.close()
        dbread = dbm.open("dbm", "r")
        leng = len(dbread)+1
        dbread.close()
        db = dbm.open("dbm", "c")
        name = "_"+str(leng)
        db[name] = form["name"].value
        db.close()
        print "Info saved. Now, read it?"
    elif(form.has_key("read") and form["read"].value == "true"):
        db = dbm.open("dbm", "r")
        arr = []
        for key in db.keys():
            arr += [key]
        arr.sort()
        arr.reverse()
        for i in range(len(db)):
            print db[arr[i]],''
        db.close()
    else:
        print """
        
        
        """

startpage("Test Page")
main()
endpage()

//

Thanks in advanced-- Best Regards.fedekiller
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] <> and chomp

2006-09-14 Thread allison . william
Thanks for all the responses guys.  I was actually able to figure out the
 
infile = open('infilename.txt', 'r')
for line in infile:

Just wasn't  sure if it was Pythonic or not.
Had no clue about the 

line = line.rstrip('\n')

so thanks again.  I'll get to reading those links.

P.S.
David, I'm sure you're right.   I'll  eventually learn both.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] show all dbm data

2006-09-14 Thread Alan Gauld
> Hi, im have just started programming python with cgi and i will try 
> to use
> dbm as a db to practise

dbm is pretty low level, I'd recommend using the shelve module as
a layer above dbm. Basically shelve makes a file look like a
dictionary.

Not the answer you asked for but since you don't intend to use
dbm long term its probably a better solution!

Alan G. 


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


Re: [Tutor] Methods and classes

2006-09-14 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote
> You have to distinguish between a method (a function that is part of 
> a
> class definition) and a standalone function (not part of any class).
> Python allows both. Standalone functions don't have a 'self' 
> parameter;
> class methods always do (you can give it a different name but if you
> omit it you will get a runtime error when you call the method).

Just to be picky, instance methods need a self parameter.
class methods (ie methods that belong to the class as a whole
rather than the individual instances(objects)) do not need a self
parameter.

>>> class C:
...  def s_m(x): print x
...  s_m = staticmethod(s_m)   # make it a static or class method
...  def __init__(self,y): self.y = y
...  def i_m(self,x): print x, self.y
...
>>> c = C(27)
>>> C.s_m(42)  # call via class
42
>>> c.s_m(42) # call via instance
42
>>> c.i_m(42)
42 27
>>>

And just to be even more picky Python actually distinguishes
between static methods (as above) and what it specifically
calls class methods, whereby the latter have an attribute similar
to self, but instead of holding the instance it holds a reference
to the original class object! (most OOP languages do not have
such fine grained distinctions on class methods)

So to summarise there are 4 types of function/method definition:
1) Ordinary functions - can have any parameters, including none
2) static methods - ordinary functions bound to a class object
3) class methods - static methods with a class reference as first 
parameter
4) instance methods - a function bound to an instance of the class
   and with an instance reference as the first parameter.

2,3 and 4 must all be defined inside a class definition.

[ And if you use decorators you can add to that list, but I won't go 
there! :-) ]

Finally the double underscore that you refer to is a Python
convention (but strongly adhered to) which indicates a special
function used by Python internally and not normally called by
the programmer..

__init__ is the initialisation function called automatically when
an instance is created. Because it is specifc to the instance
it has a self at the front. It can also take other values which will
initialise internal values of the instance, like my self.y above.

Others allow you to define how standard operators will work
for your own classes, thus __add__, __mul__, __cmp__ etc

If you define an __add__() method in your class, you can
then add two instances using the + sign:

class M:
   def __add__(self,another):
   return 42

m = M()
n = M()
print m+n   # python calls M.__add__(m,n) under the covers



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] (no subject)

2006-09-14 Thread Luke Paireepinart
John Fouhy wrote:
> On 15/09/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>   
>> This is the first time I have posted to this list so I hope I am asking
>> appropriate question in acceptable way. Want I want to do is take a file and
>> cut it into pieces so each piece is a new unique file; the new files would be
>> one line (newline) from the file I want to cut up. The file  I want to cut up
>> has 3900 lines. This is as far as I have got.
>> 
>
> So, you want to create 3900 different files, then?
>
> What do you want to call these files?
>
> You can iterate through each line of a file like this:
>
> input = open('/Users/timothy/Desktop/t' , 'r')
> for line in input:
> # ...
>   
Good example, except you shouldn't use 'input' since it's a builtin.
:D
Cheers.
-Luke
> So, in the body of the for loop, all you would need to do is decide
> what to call the new file, open the file, write line to it, and then
> close it.
>
>   

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


Re: [Tutor] (no subject)

2006-09-14 Thread John Fouhy
On 15/09/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> This is the first time I have posted to this list so I hope I am asking
> appropriate question in acceptable way. Want I want to do is take a file and
> cut it into pieces so each piece is a new unique file; the new files would be
> one line (newline) from the file I want to cut up. The file  I want to cut up
> has 3900 lines. This is as far as I have got.

So, you want to create 3900 different files, then?

What do you want to call these files?

You can iterate through each line of a file like this:

input = open('/Users/timothy/Desktop/t' , 'r')
for line in input:
# ...

So, in the body of the for loop, all you would need to do is decide
what to call the new file, open the file, write line to it, and then
close it.

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


[Tutor] pymssql or ODBC

2006-09-14 Thread Chris Hengge
Does anyone know how to make pymssql use windows authentication? 
 
Also, can anyone point me to a simple ODBC guide for SQL? 
 
I'd like to use ODBC if I can so that users of my software dont have to install extra libraries to use my utilities. 
 
Thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Input mask for console?

2006-09-14 Thread Chris Hengge
The chosen solution was posted by kent... he said getpass.getpass().
 
As far as a "sample" password... how do I display something I was asking how to hide? =P
 
>>> Enter Password: "nothing seen here" =D 
On 9/14/06, Tiago Saboga <[EMAIL PROTECTED]> wrote:
Em Quarta 13 Setembro 2006 21:55, Chris Hengge escreveu:> nevermind.. figured it out.. Thanks.
Hi Chris,It's not just for you, but I'd like to make a comment. When you write to thislist, remember that other people read your questions too, and may beinterested in the answers. By the way, I've learned a lot here just by
reading the q&a. But if we want it to be really useful to everybody, weshould try to post good questions (in your case, it was ok, but it could bebetter: you could have given the example of the password in the first mail)
*and* post the choosen solution.Thanks!Tiago.>> On Wed, 2006-09-13 at 19:48 -0400, Kent Johnson wrote:> > Chris Hengge wrote:> > > I need either a way to mask the input from a console, or a method to
> > > not display the typed characters to the screen. Someone point me in the> > > right direction?> >> > getpass.getpass() ?> >> > Kent> >> > ___
> > Tutor maillist  -  Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor>> ___
> Tutor maillist  -  Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what happens when...

2006-09-14 Thread Alan Gauld
def human_move(human):  # <= here is board removed
legal = legal_moves(board)

where does the board come from here?
If you had it as a parameter then thats where it would come from.
Without a parameter you need to have a global variable called board.

The parameters are the communications context between 
your function and the world outside. Everything that your function 
needs to operate should be passed into it (or local to it.) At least 
thats the ideal.

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


[Tutor] (no subject)

2006-09-14 Thread timothyh
This is the first time I have posted to this list so I hope I am asking
appropriate question in acceptable way. Want I want to do is take a file and
cut it into pieces so each piece is a new unique file; the new files would be
one line (newline) from the file I want to cut up. The file  I want to cut up
has 3900 lines. This is as far as I have got.
>>> output = open('/Users/timothy/Desktop/d' , 'w')
>>> input = open('/Users/timothy/Desktop/t' , 'r')
>>> l = input.readlines()
>>> output.writelines(l)
>>> output.close()
What I did was copy file r to file d. What I think I need is a for or while
expression that as each readlines is occuring it will be output as one seperate
file. Also I think I need to import sys.stdout and somehow have the readlines be
piped through that or maybe sys.argv used in some way, but these are rather
vague intuitions---can't think how to put this together.
Is what I want to do stated clearly and is this the sort of questions to ask
here?
Thank-you, Timothy

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


Re: [Tutor] python for web developing

2006-09-14 Thread Andrei
federico ramirez wrote:
> Hello! I have heard that python is very good for web development, but 
> you need frameworks, like django or turbogears.

There are also more lightweight frameworks, like web.py (http://webpy.org).

> Im a php programmer, and i want to make another dinamic site with sql, 
> in python, but i need sql object or other sql...
> And i cant get a host with it, a free host just to test it.

If you want to test, I think your own PC can do the job just fine. I 
don't know of any free generic Python hosts. Webfaction (run by the 
author of CherryPy, which is part of TurboGears) seems to have decent 
support for all kinds of Python things, but it's paid - if they allow a 
1-month account, you could try it out for very little money over there.

Yours,

Andrei

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


[Tutor] show all dbm data

2006-09-14 Thread federico ramirez
Hi, im have just started programming python with cgi and i will try to use dbm as a db to practiseBut i cant figure out how to diplay all the data from it..this is the code im using/#!/usr/bin/python
print "Content-Type: text/html\n\n"import cgi, dbmdef startpage(title):    print '''
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    http://www.w3.org/1999/xhtml">        
    ''',title,'''        '''    def endpage():    print """    """def main():
    form = cgi.FieldStorage()    if(form.has_key("name") and form["name"].value != ""):        try:            db = dbm.open("dbm", "c")            db["name"] = form["name"].value
            db.close()            print "Info saved. Now, read it?"        except:            print cgi.print_exceptions()    elif(form.has_key("read") and form["read"].value == "true"):
        try:            db = dbm.open("dbm", "r")            for key in db.keys():                print key        except:            print cgi.print_exceptions()    else:
        print """                
        """startpage("Test Page")main()endpage()/Thanks in advance-- Best Regards.fedekiller
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] <> and chomp

2006-09-14 Thread Dave Kuhlman
On Thu, Sep 14, 2006 at 12:14:27PM -0400, William Allison wrote:
> Hi,
> I'm new to programming and started with Perl but have been reading a lot
> of good things about Python.  Thought I would switch before I have too
> much time invested in Perl.
> Anyway, my question is, is there something in Python similar to the
> diamond operator and chomp from Perl?  I'm trying to read in from a file
> line by line and get rid of the '\n' at the end of each line.
> Thanks,
> Will

Consider:

infile = open('infilename.txt', 'r')
for line in infile:
line = line.rstrip('\n')
o
o
o
infile.close()

A few notes:

- See http://docs.python.org/lib/built-in-funcs.html for more on
  built-in functions and open() in particular.

- See http://docs.python.org/lib/string-methods.html for more on
  string operations and rstrip() in particular.

- rstrip() with no arguments strips all whitespace on the right.

- A file object (returned by the open() function) is an iterator; it
  obeys the iterator protocol.  That's why you can use it in the
  "for" statement above.

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] <> and chomp

2006-09-14 Thread Kent Johnson
William Allison wrote:
> Hi,
> I'm new to programming and started with Perl but have been reading a lot
> of good things about Python.  Thought I would switch before I have too
> much time invested in Perl.
> Anyway, my question is, is there something in Python similar to the
> diamond operator and chomp from Perl?  I'm trying to read in from a file
> line by line and get rid of the '\n' at the end of each line.

for line in open('somefile.txt'):
   line = line.rstrip('\n')
   # do something with line

You could also use line = line.rstrip() which removes all trailing white 
space including \n, or line.strip() which removes leading and trailing 
white space.

Kent

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


Re: [Tutor] <> and chomp

2006-09-14 Thread David Rock
* William Allison <[EMAIL PROTECTED]> [2006-09-14 12:14]:
> Hi,
> I'm new to programming and started with Perl but have been reading a lot
> of good things about Python.  Thought I would switch before I have too
> much time invested in Perl.
> Anyway, my question is, is there something in Python similar to the
> diamond operator and chomp from Perl?  I'm trying to read in from a file
> line by line and get rid of the '\n' at the end of each line.

fileinput() is similar to <>
http://docs.python.org/lib/module-fileinput.html

rstrip() is similar to chomp
http://docs.python.org/lib/string-methods.html#l2h-201

These aren't exact matches, but they are close.

-- 
David Rock
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Clipboard manager for windows

2006-09-14 Thread János Juhász

Hi Derick,

>So I need a way to hijaak the Ctrl-C and Ctrl-V
shortcuts and have my
>application run in the system tray. I don't need
a gui other than changing
>the context menu (which I believe is done in the
registry) - although, I'd
>probably need to use wxPython for using the system
tray - unless by catching
>the shortcut keys, I can call the program...

I have tested it without hijaak the Ctrl-C and Ctrl-V
It is seem to be easier to set up a shortcut to in-place
filtering
on the current content of the clipboard.

I just have played with the sample you showed:


### text.py My small clipboard coverter ###
import win32clipboard as w 
import win32con
import re

def getText(): 
    w.OpenClipboard() 
    d=w.GetClipboardData(win32con.CF_TEXT)

    w.CloseClipboard() 
    return d 
 
def setText(aType,aString): 
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(aType,aString) 
    w.CloseClipboard()

def myFilter(text):
    comma = re.compile(',')
    return comma.sub('\t', text)

def myTester(text):
    ### context sensitivity
    return ',' in text
    
text = getText()
if myTester(text):
    setText(win32con.CF_TEXT, myFilter(text))
### My small clipboard coverter ###

I have saved this python script into my devel folder,
created a shortcut on the windows desktop,
set up a shortcut key for it with Ctrl-Alt-T.
When I start this program with the shortcut key, it
simple makes 
the replace in-place on the current content of the
clipboard, 
that can be put into excel after it.

Copy this to the clipboard:
a,b,c,d,e
1,2,3,4,5
run the script
Paste the clipboard to excel
Viola :)

You can make it with wxPython and give the choice
for the
user on the visual surface to choose from more filters.

It also could be interesting, to
make the tab delimited clipboard content from the filenames.
>>> w.OpenClipboard()
>>> w.GetClipboardData(win32con.CF_HDROP)
(u'D:\\devel\\tutor\\data.txt',)
>>> w.CloseClipboard()




Yours sincerely, 
__
János Juhász 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] <> and chomp

2006-09-14 Thread William Allison
Hi,
I'm new to programming and started with Perl but have been reading a lot
of good things about Python.  Thought I would switch before I have too
much time invested in Perl.
Anyway, my question is, is there something in Python similar to the
diamond operator and chomp from Perl?  I'm trying to read in from a file
line by line and get rid of the '\n' at the end of each line.
Thanks,
Will

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


Re: [Tutor] Excluding branches while walking directory tree

2006-09-14 Thread Kent Johnson
William O'Higgins Witteman wrote:
> On Wed, Sep 13, 2006 at 11:34:25AM -0400, Kent Johnson wrote:
>> William O'Higgins Witteman wrote:
>>> I have to walk a directory tree and examine files within it.  I have a
>>> set of directory names and filename patterns that I must skip while
>>> doing this walk.  How do I create a set of rules to skip files or
>>> directory branches?  I'm looking for something reasonably scalable, 
>>> 'cause I'm sure to need to update these rules in the future.
> 
> First, thanks to Kent and Dave for their thoughts - a big help and much
> appreciated.  Notes and results below, for archival posterity (so at
> least *I'll* know where to look for it :-)
> 
>> def matchesAny(name, tests):
>>   for test in tests:
>> if fnmatch.fnmatch(name, test):
>>   return True
>>   return False
> 
> fnmatch was a good choice for this in my case, because I have to do
> case-insensitive matching of very simple patterns, but re or glob would 
> provide more power if needed. 

> I originally put the return False inside
> the conditional with else - but that meant that unless my name matched
> on the last test in tests, it would always return False.  Not what I
> wanted.  The above works very nicely without the return False line.

If you leave out the return False you get an implicit return None. None 
is interpreted as False in a conditional so it has the same result. I 
would prefer to make it explicit.

> 
>> for dirpath, dirnames, filenames in os.walk(baseDir):
>>   # Note use of slice assignment - you have to modify the caller's list
>>   dirnames[:] = [ name for name in dirnames if not matchesAny(name, 
>> dirsToSkip) ]
>>
>>   filenames = [name for name in filenames if not matchesAny(name, 
>> filesToSkip) ]
>>
>>   for name in filenames:
>> # whatever file processing you want to do goes here
> 
> The above approach was not quite what I needed, because I had a list of
> exclusion criteria and a list of inclusion criteria, but both could be
> applied to the whole path.  Therefore, I used this approach:
> 
> for dirpath, dirnames, filenames in os.walk(fs_path):
>   """Filter the list of filenames to exclude elements in ToSkip"""
>   filenames[:] = [name for name in filenames if not 
> matches(os.path.join(dirpath,name),ToSkip)]
>   """Filter the list of filenames to exclude elements not in ToKeep"""
>   filenames[:] = [name for name in filenames if 
> matches(os.path.join(dirpath,name),ToKeep)]
>   
>   for fname in filenames:
> # do what needs to be done

Another way to write this that might be a little easier to read is this:
for fname in filenames:
   if matches(os.path.join(dirpath,name),ToSkip):
 continue
   if not matches(os.path.join(dirpath,name),ToKeep):
 continue

   # process the file
or even

   if matches(os.path.join(dirpath,name),ToSkip) or not 
matches(os.path.join(dirpath,name),ToKeep):
 continue

> 
> This is getting me just the results I was looking for, and I have to
> say, I'm pretty pleased.  Thanks again.

Python rocks :-)

Kent

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


Re: [Tutor] Excluding branches while walking directory tree

2006-09-14 Thread William O'Higgins Witteman
On Wed, Sep 13, 2006 at 11:34:25AM -0400, Kent Johnson wrote:
>William O'Higgins Witteman wrote:
>> I have to walk a directory tree and examine files within it.  I have a
>> set of directory names and filename patterns that I must skip while
>> doing this walk.  How do I create a set of rules to skip files or
>> directory branches?  I'm looking for something reasonably scalable, 
>> 'cause I'm sure to need to update these rules in the future.

First, thanks to Kent and Dave for their thoughts - a big help and much
appreciated.  Notes and results below, for archival posterity (so at
least *I'll* know where to look for it :-)

>def matchesAny(name, tests):
>   for test in tests:
> if fnmatch.fnmatch(name, test):
>   return True
>   return False

fnmatch was a good choice for this in my case, because I have to do
case-insensitive matching of very simple patterns, but re or glob would 
provide more power if needed.  I originally put the return False inside
the conditional with else - but that meant that unless my name matched
on the last test in tests, it would always return False.  Not what I
wanted.  The above works very nicely without the return False line.

>for dirpath, dirnames, filenames in os.walk(baseDir):
>   # Note use of slice assignment - you have to modify the caller's list
>   dirnames[:] = [ name for name in dirnames if not matchesAny(name, 
>dirsToSkip) ]
>
>   filenames = [name for name in filenames if not matchesAny(name, 
>filesToSkip) ]
>
>   for name in filenames:
> # whatever file processing you want to do goes here

The above approach was not quite what I needed, because I had a list of
exclusion criteria and a list of inclusion criteria, but both could be
applied to the whole path.  Therefore, I used this approach:

for dirpath, dirnames, filenames in os.walk(fs_path):
  """Filter the list of filenames to exclude elements in ToSkip"""
  filenames[:] = [name for name in filenames if not 
matches(os.path.join(dirpath,name),ToSkip)]
  """Filter the list of filenames to exclude elements not in ToKeep"""
  filenames[:] = [name for name in filenames if 
matches(os.path.join(dirpath,name),ToKeep)]
  
  for fname in filenames:
# do what needs to be done

This is getting me just the results I was looking for, and I have to
say, I'm pretty pleased.  Thanks again.
-- 

yours,

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


Re: [Tutor] Input mask for console?

2006-09-14 Thread Tiago Saboga
Em Quarta 13 Setembro 2006 21:55, Chris Hengge escreveu:
> nevermind.. figured it out.. Thanks.

Hi Chris,

It's not just for you, but I'd like to make a comment. When you write to this 
list, remember that other people read your questions too, and may be 
interested in the answers. By the way, I've learned a lot here just by 
reading the q&a. But if we want it to be really useful to everybody, we 
should try to post good questions (in your case, it was ok, but it could be 
better: you could have given the example of the password in the first mail) 
*and* post the choosen solution.

Thanks!

Tiago.


>
> On Wed, 2006-09-13 at 19:48 -0400, Kent Johnson wrote:
> > Chris Hengge wrote:
> > > I need either a way to mask the input from a console, or a method to
> > > not display the typed characters to the screen. Someone point me in the
> > > right direction?
> >
> > getpass.getpass() ?
> >
> > Kent
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> ___
> 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] How do I open my browser from within a Python program

2006-09-14 Thread Simon Brunning
On 9/14/06, nimrodx <[EMAIL PROTECTED]> wrote:
> Basically a dumb question I can't seem to find the answer to.
>
> How do I execute a bash command from within a python program.

Well, this question doesn't match the subject line. So, *two* answers.

To open a web browser from within a python program, you want something like:

import webbrowser
webbrowser.open('www.google.com')

To run a shell command - well, it depends. If you don't care about
reading the output or so on, you can just do:

import os
os.system('ls')

If you want to access the input and/or output streams, or to wait for
the shell command to finish, or anything even remotely complex, look
at the subprocess module.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I open my browser from within a Python program

2006-09-14 Thread Kent Johnson
nimrodx wrote:
> Basically a dumb question I can't seem to find the answer to.
> 
> How do I execute a bash command from within a python program.

To open your browser you can use the webbrowser module. To run any 
external program use os.system(). To run an actual bash command (as 
opposed to starting an external program as you might do with bash) you 
would have to run bash as the external program; I'm not sure of the 
details on that.

Kent

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


[Tutor] How do I open my browser from within a Python program

2006-09-14 Thread nimrodx
Basically a dumb question I can't seem to find the answer to.

How do I execute a bash command from within a python program.

I've been looking through my book on python, and the docs, but can't 
seem to find something so basic (sure it is
there, but I am not looking for the correct terms, I guess).

Sorry,

Matt

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


Re: [Tutor] GDAL- Help

2006-09-14 Thread Kent Johnson
Nagendra Singh wrote:
> Hi,
> 
> I am just starting to learn Python and I want to perform some GIS
> tasks which requires the gdal module (http://www.gdal.org/). I have
> installed FWTools which also comes with a built in Python interface
> but I also have a stand alone version of Python which I use. I am
> trying to use the gdal module but I keep getting an error message that
> gdal module is not found,even after appending the module using the
> sys.path.append command. Can you anyone please let me know how do I
> use the gdal module in the python I have (I dowlloaded it from
> activestate) or I have to use the Python which comes with gdal but it
> does not offer me the IDE.

I would look at how GDAL is installed in the FWTools Python and try to 
duplicate that installation in the other Python. Look for files and 
directories in Lib\site-packages and copy them to the site-packages for 
your other install.

Kent

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


Re: [Tutor] List manipulation

2006-09-14 Thread Kent Johnson
Srinivas Iyyer wrote:
> Thank you Bob for your email.
> Sorry for the confusion. 
> here is what I ment:
> 
> test = ['10\t15', '16\t20', '25\t35', '45\t50',
> '55\t60', '61\t65', '75\t80']

>>> I would get:
>>> 10  20
>>> 25  35
>>> 45  50
>>> 55  65
>>> 75  80

Here is my take on it:

test = ['10\t15', '16\t20', '25\t35', '45\t50','55\t60', '61\t65', '75\t80']

pairs = [ map(int, x.split('\t')) for x in test ]

i = iter(pairs)

last = i.next()

for current in i:
 if current[0] == last[1]+1:
 last = [last[0], current[1]]
 else:
 print last
 last = current

print last


You can also wrap this in a generator which yields the desired pairs, so 
they can be printed or put in a list or whatever:

def compress(pairs):
 i = iter(pairs)

 last = i.next()

 for current in i:
 if current[0] == last[1]+1:
 last = [last[0], current[1]]
 else:
 yield last
 last = current

 yield last


for pair in compress(pairs):
 print pair


Kent

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


[Tutor] Clipboard manager for windows

2006-09-14 Thread Derick Van Niekerk
Hey,I came accross this explanation of how the windows clipboard can be handled with Python:http://www.bigbold.com/snippets/posts/show/724I want to write myself a simple text filter for pasting csv into excel, pasting syntax highlighted code as html and custom formatting text with regular expressions before pasting it. There are free programs that come close to what I need but the filters aren't as customizable as I'd like - allthough they are more complicated than I need. Take a look at 
http://www.clipmagic.com/ and http://www.snapfiles.com/get/clippy.htmlClippy is the closest to what I need.So I need a way to hijaak the Ctrl-C and Ctrl-V shortcuts and have my application run in the system tray. I don't need a gui other than changing the context menu (which I believe is done in the registry) - although, I'd probably need to use wxPython for using the system tray - unless by catching the shortcut keys, I can call the program...
Any ideas? Anybody ever done something like this?-d-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using my own installed python version in my directory tree.

2006-09-14 Thread Ewald Ertl
Hi
Ziad Rahhal wrote:
> Hi,
> 
> I installed pythin on Linux operating system but on my own tree
> directory. Now I want to get rid (not deleting)
> the default python installation, which means I want my own python
> version to be recognized when I use "python" command.
> 
> PYTHONPATH has nothing to do with that since it just points to modules.
> I tried to set the PATH to $HOME/python/bin but this
> didn't work.
> 
Who did you set the PATH?
I'm using different installations of python on solaris.

PATH=/where/python/is:$PATH
export PATH

After setting the PATH variable, does "which python" find your desired
python interpreter?


HTH Ewald

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


Re: [Tutor] what happens when...

2006-09-14 Thread josip
When I remove board I get message: global name 'board' is not defined.  Ok I understand that.  But I would like to get some explaination to understand better.     Thanks!John Fouhy <[EMAIL PROTECTED]> wrote:  On 14/09/06, josip <[EMAIL PROTECTED]>wrote:>> Hi all!> Can You explain me what happens when in this function I remove board arg:> def human_move(board, human)?> What is doing that argument?Have you tried removing the argument and running the code? What errormessage do you get? What do you think it means?-- John. 
		Stay in the know. Pulse on the new Yahoo.com.  Check it out. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor