[FAQTS] Python Knowledge Base Update -- November 29th, 2000

Fiona Czuczman fiona at sitegnome.com
Wed Nov 29 14:00:28 CET 2000


Hi Guys!

The updates for November into http://python.faqts.com

regards,

Fiona


## Unanswered Questions ########################################


-------------------------------------------------------------
How do i add an ORBit interface to my python application to permit querying from a CGI script?
http://www.faqts.com/knowledge-base/view.phtml/aid/6696
-------------------------------------------------------------
Slimy



-------------------------------------------------------------
How do I dial ISP(ppp) from python?
http://www.faqts.com/knowledge-base/view.phtml/aid/6535
-------------------------------------------------------------
Rick Barnich



-------------------------------------------------------------
Is there a startup.py or autoexec.py for pythonwin.
http://www.faqts.com/knowledge-base/view.phtml/aid/6445
-------------------------------------------------------------
steve t



## New Entries #################################################


-------------------------------------------------------------
What IDEs, debuggers, and other development tools are available for Python?
http://www.faqts.com/knowledge-base/view.phtml/aid/6433
-------------------------------------------------------------
Stephan Deibel


There are a number of options for those that want to go beyond the basic
debugging tools that come with Python itself, or want more than the
commonly used text editors like emacs or vi: 

Commercial
 
1) http://www.wingide.com/wingide -- Wing IDE provides a graphical
debugger with remote debug capability, source module and class browser,
source editor with autocompletion, syntax hilighting and an emacs mode,
and a project manager.

2) http://www.pythonworks.com -- PythonWorks is a rapid application
development environment with editor, debugger, TkInter-based user
interface layout tools, and deployment manager.

3) http://www.activestate.com/Products/VisualPython.html -- VisualPython
is a plug in for Microsoft's development environment, Visual Studio 7.

Open Source

5) http://www.python.org/windows/pythonwin/ -- PythonWin is a Python
distribution specifically for Microsoft Windows that includes support
for MFC development, and a graphical environment with source editor,
command shell, and a number of other features.

6) http://www.python.org/idle/ -- IDLE is a TkInter-based integrated
development environment for Python, currently in early release form.

7) http://boa-constructor.sourceforge.net/ -- Boa Constructor, a rapid
application development environment with WXPython-based GUI development
capabilities, currently in (very?) early release form.


-------------------------------------------------------------
How do you POST data to an HTTPS: server?  Any examples?
http://www.faqts.com/knowledge-base/view.phtml/aid/6511
-------------------------------------------------------------
Jose Correia


I have managed to find an answer myself to this question.  This is a 
solution for the Windows environment.  It involves using COM and MSIE 
and requires no manual handling of either SSL or cookies, etc.  It's 
really painfully easy once you get pointed in the right direction.

My special thanks to Michal Wallace whose newsgroup posting a while 
back answering someone else's question helped get me on the right 
track. (some parts below are cut directly from his posting).

Instructions:

1) Install Win32 extensions.
2) Once you have them installed:
   - open pythonwin
   - load the "COM Makepy utility" under the Tools menu
   - in the window that pops up, double click on:
     "Microsoft Internet Controls"
   This generates a magical python module for you...

3) Now, in the python window, type:
   >>> from win32com.client import Dispatch
   >>> ie = Dispatch("InternetExplorer.Application")
   >>> ie.Visible = 1    #Shows you the window so you can see what's 
happening.
  >>> ie.Navigate("https://www.suretrade.com/cgi-bin/login")  #The URL 
(secure or otherwise) you want to get to, this one used as an example 
is my online broker's secure URL.

  ... Well, it shows up in the browser... But how to get the
  text?
  "Tools/COM Browser"
     "Registered Type Libraries"
        "Microsoft Internet Controls"
            "Type Library"
                "IWebBrowser2"

  Hmmm. That seems to show a bit more info, but we still don't
  know what to do with it.. Let's go to msdn and see if we can
  look that control up... Here it is:
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/ifaces/I
WebBrowser2/IWebBrowser2.asp

4) Looks like we want the "get Document" thing. Back to python.
>>> ie.Document
<COMObject Document>

Cool!

>>> doc = ie.Document

According to the MSDN docs, this is just a normal DHTML document
object.  For a list of controls and things you can do with this go to:
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_do
cument.asp

>>> doc.url
'https://www.suretrade.com/cgi-bin/login'

>>> print doc.body.innerHTML
[it works!]
doesn't print the WHOLE HTML document, granted, just the body..  but
you can basically script it as if it were client side DHTML because
you're using the same engine. You may not need to grab it..  Huh.

5) Now to enter the data into the required fields:
>>> doc.LoginForm.UserID.value="Jabba"

A few notes here.  LoginForm is the NAME of the form, UserID is the 
NAME of the INPUT field in the form, value is the actual value in the 
field.  Flip to you browser and you'll see the text magically appear in 
the input fields in the browser.  To get the values from the field just 
refer to it:
>>> doc.LoginForm.UserID.value
'Jabba'

>>> doc.LoginForm.Passwd.value="password" (what else?)

>>> doc.LoginForm.destination.value = "/cgi-bin/order?action=Stock&"
This just sets an optional value in the dropdown box.

6) Now submit the form data:
>>> doc.LoginForm.submit()

And you're at the next screen, all logged on and ready to party!

7) Finally, to get rid of it:
>>> del doc      # Kills the object.
>>> ie.Quit()    # Kills the browser session.

You'll have to put in checks to verify whether the page is fully loaded 
(i.e. if doc.readyState == 'complete':) before submitting data and so 
on to make it more robust, but as a way of actually getting connected 
with results I think this should help anyone get started.

HTH any other newbies to Python/COM/web programming/etc (like me).


## Edited Entries ##############################################


-------------------------------------------------------------
Is there a Python MySQL module for use under Windows?
http://www.faqts.com/knowledge-base/view.phtml/aid/4188
-------------------------------------------------------------
Fiona Czuczman, Gerhard Haering
Stefan Franke,Steve Cook

You will find a version of MySQLdb (version 0.2.2) compiled for Win32
at http://home.t-online.de/home/err666/
It works fine for me connecting to MySQL 3.23/Win2k and
MySQL 3.22/Linux.

Now, you will also find a brand-new version of MySQLdb 0.3.0b2 for 
Python 2.0 there. Please give me feedback at haering_python<at>gmx.de 
wether these builds work for you.


-------------------------------------------------------------
Why are there no operators equivalent to C's   , --,  =, etc.?
http://www.faqts.com/knowledge-base/view.phtml/aid/3378
-------------------------------------------------------------
Fiona Czuczman, Dave Brueck
Fredrik Lundh, Peter Schneider-Kamp, Michael Hudson

if you write things like "var = var + 1" a lot, you might be missing 
some important python idioms...

here are a few, in no specific order:

    for item in sequence:
        ...

    sequence = map(operation, sequence)

    sequence.append(item)

    for index in range(size):
        ...

    for item1, item2 in map(None, sequence1, sequence):
        ...

    for index in range(start, stop, step):
        ...

    n = sequence.count(item)

    for index in range(len(sequence)):
        ...

    sequence.remove(item)

    for index in range(len(sequence)-1, -1, -1):
        ...

(also note that most basic types are *immutable*, so it's not entirely 
clear how things like ++ and += should work.

Michael Hudson wrote a patch for the +=, -=, *=, /= and some other
of these operators.

A patch can be found at:

http://starship.python.net/crew/mwh/aug-patch.html
http://www-jcsu.jesus.cam.ac.uk/~mwh21/aug-patch.html

As of Python 2.0, the above operators are officially part of the 
language.


-------------------------------------------------------------
How does assignment work in Python?
http://www.faqts.com/knowledge-base/view.phtml/aid/1334
-------------------------------------------------------------
Nathan Wallace, Dave Brueck, Fiona Czuczman
Fredrik Lundh

In many programming languages, a variable is a small region of memory in
which you can put things of a given type.

However, in Python, a variable is a name which can point to any existing
object.  Variables don't have types (but objects do).

When you assign a new object to a variable, you just change the name so
it points to the new object.

The old object is not affected by this (in fact, it doesn't even notice,
unless the assigment means that nobody cares about the object anymore,
in which case it's destroyed)

Python 2.0 now supports augmented assignment, which lets you do stuff 
like: x += 1 instead of x = x + 1

This has two subtle differences from the longer type of assignment:
(1) In augmented assignment, x is evaluated only once
(2) When possible, augmented assignment performs the operation in-
place, which means that instead of creating a new object to hold the 
new result, the existing object is modified.


-------------------------------------------------------------
How do I find the byte length of a float, double or an int?
Are all standard python float, double, ints, etc of a fixed format?
http://www.faqts.com/knowledge-base/view.phtml/aid/2638
-------------------------------------------------------------
Fiona Czuczman, Dave Brueck
Tim Peters

You can't find the byte length short of reading the source code.

A Python float is a C double.
Python doesn't have a double type.
A Python int is a C long.

Every Python object also comes with some amount of object hair, like a
refcount and a pointer to its type object ... again, you have to read 
the source to get the full story.

*But*, if you're interested in byte length because you want to send the 
data as a network message or if you want to store data in a file or 
array and calculate an offset into that array, you can use the struct 
module, which lets you pack data into a string of bytes. You can 
optionally tell it to put the bytes in network order so that it will 
work on any platform, and you can also use the struct.calcsize method 
to see how much space the packed version will use.

There is also the array module for storing homogeneous data, and it has 
an itemsize method, but the value returned can vary by platform.







More information about the Python-list mailing list