Re: [Tutor] Fill in a web form

2006-03-18 Thread Alan Gauld
Hi David,

You lost me there.

What does a late train ghave to do with filling in web forms?!

> Is there a way in python to automatically put values in a web page ?  
> For example I used to travel on a train (I live in the UK) that is 
> always late.  Is there a way to automatically to do this ?

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


Re: [Tutor] Mysql BLOB strangeness?

2006-03-18 Thread Brian Gustin
Oh. just found the original question.. :)

OK perhaps this would be more helpful if you were to manually query 
mysql on command line and paste the results it outputs here.

what I am betting is your method to get the data out of teh query is 
doing exactly what you tell it to.. :)

but this hinges on the answer to "what is the original row of data 
returned by commandline mysql query"

keep in mind Mysql returns a result set as an array (a list or 
dictionary, when it is associative, if you will)

what your code is doing is taking the row (array) and appending it to an 
additional list..

and where you print the whole, you are basically printing out the 
multi-dimensional array, and I am betting the *last element* returned 
non-null in the mysql query is the content field.. :)

but again, it depends on what the actual content is..

run these two in mysql command line:

mysql> show create table report;
mysql> select * from report limit 1;

and let me know the results.. :)

I doubt that blob vs. text has anything to do with this issue :)

Bri!

Adam Cripps wrote:
> I'm trying to build a mini-CMS for my class to manage a single
> webpage, using CGI and mysql. The children will be storing their main
> content in a BLOB within a Mysql database.
> 
> When I query the content column, I get a strange return like this:
> 
> array('c', 'This is a test ')
> 
> - when the only text I entered in was 'This is a test'.
> 
> When I query mysql directly through a prompt, I get 'This is a test'.
> 
> Does a CGI query get mangled text from a blob? My other VARCHAR
> columns are fine.
> 
> Code:
> 
> def query(statement):
> results = []
> mycursor.execute(statement)
> myrowcount = int(mycursor.rowcount)
> for i in range (0, myrowcount):
> myrow = mycursor.fetchone()
> results.append(myrow)
> return results
> 
> reportquery = "select id, title, content, published from report"
> reportlist = query(reportquery)
> print "" + str(reportlist) + ""
> 
> 
> id = primary key, integer, not null
> title = varchar(255)
> content = blob
> published = char(1), default ='n'
> 
> I've tried using looking at
> reportlist[0][2][1], but that just returns 'T' - which is obviously
> the T in 'This'.
> 
> TIA
> Adam
> --
> http://www.monkeez.org
> PGP key: 0x7111B833
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> !DSPAM:441ac610153321413855301!
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fill in a web form

2006-03-18 Thread Kent Johnson
David Holland wrote:
> Is there a way in python to automatically put values in a web page ?  
> For example I used to travel on a train (I live in the UK) that is 
> always late.  Is there a way to automatically to do this ?

Can you be more specific? Do you want to script the browser so it 
displays a page (try PAMIE for IE or PyXPCOM for Mozilla) or do you want 
to write a program that fetches the data and displays it (urllib2 or 
mechanize/ClientForm to fetch the data, BeautifulSoup to parse the 
response and get what you want).

Google any of the above for details or ask again here.

Kent

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


Re: [Tutor] Fill in a web form

2006-03-18 Thread Michael Janssen
On 3/18/06, David Holland <[EMAIL PROTECTED]> wrote:

> Is there a way in python to automatically put values in a web page ?  For
> example I used to travel on a train (I live in the UK) that is always late.
> Is there a way to automatically to do this ?
> I can't think of  how to do it.

You don't "fill" the form fields, but rather you perform the same
action the browser would performs with a filled form.

You must look into the html-form-tag and its action- and
method-attributes. "Action" is the url to the script receiving the
filled form. Method tells the browser how to send the data: "get"
means to generate an url like "www.google.com?q=python', ie an url
with the content of the form. Method "post" means to send the data
"inline". urllib2.urlopen handles this (its data parameter for "post"
data). Perhaps urllib.urlencode is of interest for you (before
generating a get-url, urlencode the data, so that it renders a sane
url).

This answere is a bit short and might leaves you with a lot of open
questions. If so, ask :-)

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


Re: [Tutor] Mysql BLOB strangeness?

2006-03-18 Thread Brian Gustin
you'd grab a blob the same way you'd grab a text data type- the only 
difference being the data you insert. for example, make a string of 
letters only, insert it into both a blob and a text data type- you can 
get the data out exactly as is either way , however if you attempt to 
put binary data into a text data type, it gets corrupted (char types 
will pad data with spaces to fill out the length specifier, varchar will 
not pad, but *will* truncate trailing spaces, as will text , and in 
binary data- trailing spaces are critical - they are a binary character, 
and the alteration of a single byte in a binary file will render it 
useless)  - it's much like taking a compiled C binary and trying to read 
it in a text editor - you get a long string of incomprehensible 
characters - putting such data in a text field in mysql would render the 
code un-executable, however Blob fields dont care about spaces either 
leading or trailing- it just stores *precisely* what you give it to store.

Ideally, if you think your data will exceed 255 characters in any given 
data type and it will be alphanumeric, non-binary (say, a text file) 
you would use TEXT field type, if you were gonna do something like store 
a JPG image , or even a compiled binary (cant imagine why) you would use 
BLOB field.

Most of this information is readily available at the mysql manual, and 
as far as I know, Python could care less what database type you are 
using, it can get data from mysql as binary or integer or string or 
float, whatever you specify it to be.. I know that with php (my primary 
language, still learning python) data types are automatically converted, 
and with my limited work to date with python/mysql (using both 
python-mysqldb and the ADOdb abstraction layer for python) I have had no 
issues with handling data - when I get an integer from mysql that is of 
type integer, the value I get in python is also integer..

One thing I have been trying to research/find out is a de-cryption 
algorithm using our known key, to reverse mysql's own des_encrypt 
function - we have data stored in a mysql 4.0 table that uses that 
function, which is not supported in mysql 4.1 and 5 , preventing us from 
upgrading that one machine, and Ive been trying to find a way to match 
the DES3 encryption algorithm that mysql uses, (with our known key/seed 
of course) with little luck so far .. but in all my work, Ive never 
noticed any problem in handling data types- but then I read the mysql 
manual pretty throughly, and in my work (extremely high traffic 
production websites) , MySQL optimization and understanding is 
critical.. so maybe something seems trivially simple and obvious to me, 
that may actually need some explanation ?

In short, whether I am working with blob or text, I would query teh 
table and properly type cast the variable or object to the data type I 
am extracting (if I know data is binary, I get it as a raw string, for 
example, if I know data is like an image or a compiled binary file, I 
would handle it as such, rather than making python process it - the 
object would just contain a reference to the location of the data which 
was extracted in the mysql query...)  but then again, I do very little 
work with binary, and dont store files or images to a database in the 
first place.. :)

in case I misunderstood your question- (it could also be read as how you 
extract the data itself from the mysql array result set) - that depends 
heavily on the type of query and method of fetching data, but as far as 
I know, you can just fetch a single piece of data from mysql as a single 
object, and assign it a reference... but that depends heavily on how you 
structure your query and has more to do with mysql than with python 
itself :)

Bri!



Adam Cripps wrote:
> On 3/17/06, Brian Gustin <[EMAIL PROTECTED]> wrote:
> 
>>if the data is not binary, you can use TEXT type - accepts all readable
>>characters and data, BLOB type is more for binary data storage, and
>>MYSQL's Varchar type only stores up to 255 characters. (65,536 bits, or
>>64Kbits)
>>
>>If you are storing Binary data (DES-3 encrypted data, or image data, for
>>example (a silly idea, IMHO, but some people store image data in
>>databases), then you would use BLOB, but I prefer to use TEXT type for
>>plain ol' storage of text or characters (say an html page or template,
>>etc) rather than the binary BLOB type, although BLOB would be a space
>>savings if the data will be quite large, and you will have many rows)
>>
>>HTH
>>Bri!
>>
> 
> 
> Thanks - this makes sense. I will convert the table to text and see
> how I get on.
> 
> However, there is still a learning point that might be missed here -
> how does Python grab BLOB data-types, and how do you manipulate them?
> If it were a file, would you just be able to grab the file without the
> array?
> 
> Adam
> 
> --
> http://www.monkeez.org
> PGP key: 0x7111B833
> 
> !DSPAM:441be3c3320518690210016!
> 
> 
_

[Tutor] ANN: 2006 Python training courses, San Francisco

2006-03-18 Thread w chun
*** 50% DISCOUNT for STUDENTS / TEACHERS ***

For those of you who already know Python or other languages but are
learning Python, WE are giving 4 more Python training courses (held
near the San Francisco airport) for the remainder of this year. 
Please forward this message  to anyone else you know who may be
interested.

For the first time, there will be an "advanced" Python course
available to the public.  In fact, we've added the March intro course
date for those prepping to take the advanced class in May.  You may
register for any of the 4 courses/dates below.

(Intensive) Introduction to Python
March 29-31, 2006
August 16-18, 2006

Advanced Python Programming
May 17-19, 2006
November 8-10, 2006

LOCALS: it'll be at a hotel with BART and CalTrain access (San Bruno
stations) as well as having 101/280/380 freeway access

VISITORS: free shuttle directly from the San Francisco airport, nice
facilities, food, wireless, etc.

DISCOUNTS available. for more info and details, go to
http://cyberwebconsulting.com and click "Python training."

cheers,
-wesley

ps. a great big public THANKS to Rob Stephenson for putting together
the short video clip of one of our training sessions for your viewing
pleasure on a video iPod or PC/Mac!

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using cmd

2006-03-18 Thread Kent Johnson
Christopher Spears wrote:
> I just completed an assignment out of Learning Python
> in which I used the Cmd class from the cmd module to
> create a little shell:
> My main question concerns the naming of functions such
> as:
> 
> def do_ls(self, line):
> if line == '': dirs = [os.curdir]
> else: dirs = line.split()
> for dirname in dirs:
> print 'Listing of %s:' % dirname
> print '\n'.join(os.listdir(dirname))
> 
> Originally, I called the function 'ls', but when I did
> that, the function didn't work when I typed 'ls' at
> the prompt.  When I looked in the back of the book, I
> saw the name the authors gave their function, which
> was 'do_ls'.  When I changed the function's name to
> do_ls, the function worked when I typed 'ls' at the
> prompt.  Does anyone know why this happened?

Cmd uses introspection (using the built-in function getattr()) to find 
the handler methods. For a command named 'ls' it looks for a method 
'do_ls' to handle the command. You can also provide 'help_ls' to respond 
to the user command 'help ls'. This naming convention is built-in to Cmd 
so you have to use it for the module to work correctly.

Kent

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


[Tutor] Fill in a web form

2006-03-18 Thread David Holland
Is there a way in python to automatically put values in a web page ?  For example I used to travel on a train (I live in the UK) that is always late.  Is there a way to automatically to do this ? I can't think of  how to do it.   First they came for the Danes, but I did not speak out because I am not a Dane.
		Win a BlackBerry device from O2 with Yahoo!. Enter now.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using cmd

2006-03-18 Thread Alan Gauld

>I just completed an assignment out of Learning Python
> in which I used the Cmd class from the cmd module to
> create a little shell:

> Originally, I called the function 'ls', but when I did
> that, the function didn't work when I typed 'ls' at
> the prompt.  When I looked in the back of the book, I
> saw the name the authors gave their function, which
> was 'do_ls'.  When I changed the function's name to
> do_ls, the function worked when I typed 'ls' at the
> prompt.  Does anyone know why this happened?

Its just how the module works - many GUI frameworks 
adopt a similar convention - eg Visual Basic command handlers.

My guess os that cmd builds the command string then uses eval() to 
execute the function, but I could be wrong. But in general frameworks 
like cmd will either:
1) expect some kind of standard naming scheme 
(like cmd apparently does) or
2) Have some form of function registration mechanism so that code 
looks like

def someFunc(): 
# blah, blah
registerFunc("someCommand', someFunc)

def another():
   # and more here
registerFunc("another", another)

Or sometimes as a table:

def foo(): # blah
def baz(): # more blah

registerFuncs( {"commandFoo": foo, "commandBaz": baz})

wxPython (Or more accurately its underlying framework, wxWidgets) 
uses this second approach, for example. As does Microsoft in their 
MFC C++ framework.

HTH

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] walking down directories

2006-03-18 Thread Alan Gauld
>I am trying to write a function that takes a
> directory's name, finds any subdirectories, and then
> prints out the size of the files in all found
> directories.

> As you see, the problem is that there is another
> directory under testFiles called testDir, but the
> function doesn't check the directory for files.  The
> function needs to find every directory (including
> subdirectories within directories).  Any hints?  

You mean like the os.walk fiunction does?

Take a look at the OS topic in my tutor for an example
of using os.walk - its about quarter oif the way down.

Alan G.

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


Re: [Tutor] Mysql BLOB strangeness?

2006-03-18 Thread Adam Cripps
On 3/17/06, Brian Gustin <[EMAIL PROTECTED]> wrote:
> if the data is not binary, you can use TEXT type - accepts all readable
> characters and data, BLOB type is more for binary data storage, and
> MYSQL's Varchar type only stores up to 255 characters. (65,536 bits, or
> 64Kbits)
>
> If you are storing Binary data (DES-3 encrypted data, or image data, for
> example (a silly idea, IMHO, but some people store image data in
> databases), then you would use BLOB, but I prefer to use TEXT type for
> plain ol' storage of text or characters (say an html page or template,
> etc) rather than the binary BLOB type, although BLOB would be a space
> savings if the data will be quite large, and you will have many rows)
>
> HTH
> Bri!

Thanks - this makes sense. I will convert the table to text and see
how I get on.

However, there is still a learning point that might be missed here -
how does Python grab BLOB data-types, and how do you manipulate them?
If it were a file, would you just be able to grab the file without the
array?


--
http://www.monkeez.org
PGP key: 0x7111B833
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test If File System is mounted in Linux

2006-03-18 Thread Pawel Kraszewski
Dnia piątek, 17 marca 2006 19:22, Bill Campbell napisał:

> If you're sure it's a Linux system, fine.  Like /etc/mtab, this isn't
> portable.  Looking at some of the systems we have here:

Fortezza mentioned it the way I assumed he has Linux:

>> If there a semi-standard way to test if a file system has been mounted
>> or not using Python? In the Linux command line, I can type "mount" and
>> see all mounted file system, and then see if the one I am looking for is

But, generally - you are right. Each system has its own rules for accessing 
mount table. Anyway - this would be a great exercise to make a portable 
pure-python library to get this information.

-- 
 Pawel
 www.kraszewscy.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor