[FAQTS] Python Knowledge Base Update -- July 12th, 2000

fiona at sitegnome.com.bbs fiona at sitegnome.com.bbs
Wed Jul 12 06:10:03 EDT 2000


Greetings,

Here are the latest entries to be entered into http://python.faqts.com

regards,

Fiona Czuczman


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


-------------------------------------------------------------
How do you read from / write to the system clipboard from Tkinter?
http://www.faqts.com/knowledge-base/view.phtml/aid/4668
-------------------------------------------------------------
Fiona Czuczman
richard_chamberlain

I presume that you want to paste or copy into or out of an entry or
text, these widgets already have copy and paste keystrokes assigned to
them (at least they do on windows). So I can do Control-c and that
copies it into the clipboard and Control-p pastes it. so:

from Tkinter import *
root=Tk()
text=Text(root)
text.pack()
root.clipboard_clear()
root.clipboard_append('python rules!')
def paste(event):
    text.event_generate('<Control-v>')
text.bind('<FocusIn>',paste)
root.mainloop()

In this example we append your 'python rules!' to the clipboard and then
wait until the text control gets the focus and then we generate a
<Control-v> event to paste the contents in.


-------------------------------------------------------------
What's the Python equivalent for C's #include "myfile.h"?
http://www.faqts.com/knowledge-base/view.phtml/aid/4669
-------------------------------------------------------------
Fiona Czuczman
Rainer Deyke, Matthew Schinckel

The standard substitute is:

>>> import myfile
or
>>> from myfile import *

However, this is not quite equivalent to #include.  If you really need
behavior identical to #include, you could try the following:

exec open("myfile.h").read()


-------------------------------------------------------------
How can I enumerate drives (local and network) in Python?
http://www.faqts.com/knowledge-base/view.phtml/aid/4670
-------------------------------------------------------------
Fiona Czuczman
richard_chamberlain

On Win32 you can use:

import win32api,string

drives=win32api.GetLogicalDriveStrings()
drives=string.splitfields(drives,'\000')
print drives

GetLogicalDriveStrings returns a string with each drive null terminated
so you can use the string module to separate them into a list.

There is also a win32api.GetLogicalDrives() which returns a bitmask
where each bit represents a drive letter, so 1101 (or 13 in decimal)
would represent (going from right to left) a:\,c:\ and d:\.


-------------------------------------------------------------
What is the difference between the calls PyObject_GetAttr and PyObject_GetAttrString?
http://www.faqts.com/knowledge-base/view.phtml/aid/4671
-------------------------------------------------------------
Fiona Czuczman
Thomas Wouters

PyObject_GetAttrString takes a PyObject pointer and a char pointer,
whereas PyObject_GetAttr takes two PyObject pointers: the second
argument should be a PyString, which is then turned into a char pointer
(using PyString_AS_STRING) and passed to PyObject_GetAttrString.


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


-------------------------------------------------------------
How can I create a stand alone "win32" executable file from a python script?
Is a compiler available anywhere for python for win32?
http://www.faqts.com/knowledge-base/view.phtml/aid/3111
-------------------------------------------------------------
Fiona Czuczman
Daley, MarkX

http://starship.python.net/crew/gmcm/index.html

This link will provide you with a pretty good wrapper that gives you a
one-file installer executable.  I'm pretty sure it's win32.



More information about the Python-list mailing list