Here's a snippet of code for pythoners to enjoy.
Make the Microsoft genie speak text and dance about!
'''
Requires:
--
comtypes from:
http://starship.python.net/crew/theller/comtypes
MS Agent from:
http://www.microsoft.com/msagent
To do:
--
1. List
I have a need to tile a bitmap across an arbitrary quadrilateral, and
apply perspective to it.
The Python Imaging Library (PIL) has an undocumented function that
might work, but I can't figure out how to make it work. You're
supposed to pass it 8 parameters, a b c d e f g h .
What I want is to
Nice as it is, but why not use pylint to check this and many other
coding style issues?
I made this the first time I mangled some code because pychecker said
some modules were not used when they really were. The module wasn't
that complex, only 302 lines, but it got it wrong.
--
'''
DetectUnusedModules.py - Detect modules that were imported but not used
in a file.
When run directly, this class will check all files in the current
directory.
'''
import os
import tokenize
class PrintUnusedModules(object):
state = 0
importlist = None
linenumbers = None
def
'''
I'm in the middle of a refactoring dilemma.
I have several singletons that I'm turning into modules, for ease of
access.
The usual method is noted as 'Module 1' below.
The new method is noted as 'Module 2'.
Is there any reason NOT to do this that I may be unaware of?
It's easier than
Mark Harrison wrote:
Is there a way to automatically print all the instance
data in a class?
print self.__dict__
--
http://mail.python.org/mailman/listinfo/python-list
' it, but you know that will come up to bite me in the
future.
Does anyone have a thought on how I can turn what are basically
function keyword arguments in string form, to a dict, without using
exec or eval?
--Kamilche
--
http://mail.python.org/mailman/listinfo/python-list
Thanks! It's interesting, and nearly what I want, but not quite there.
When I run my sample code through it, I get a syntax error because it's
not a valid expression. If I were to put a 'dict(' in front and a ')'
at the end, THEN it nearly works - but it gives me an
'Unsafe_Source_Error: Line 1.
Ah, finally, that's exactly what I need! Thanks bunches. I was
attempting to modify your first code to fit my needs, but mine was much
longer, and not yet working, a sure clue that yours is a better
solution. :-D
--
http://mail.python.org/mailman/listinfo/python-list
Be sure and use mode = P instead of RGB, like you have in your other
code. P is for palettized images. Don't palettize if you're storing as
JPG, only if you're storing as PNG or some other format that can handle
256 color images.
--
http://mail.python.org/mailman/listinfo/python-list
To reduce the color depth of an image in PIL:
im = im.convert(mode=P, palette=Image.ADAPTIVE)
--
http://mail.python.org/mailman/listinfo/python-list
Heheh, that sounds about right. :-D
I personally haven't used the new stuff yet. Maybe I'm not experienced
enough in Python yet to have encountered the need for them. I've played
with them some, but every time I consider using them, something stops
me. What stops me from using 'setattr' (an old
I have been programming in Python for years, and I'm STILL learning new
features about the language.
I'm looking for the best way to handle events with my own UI developed
in PyGame, and I've programmed up 4 ways to do it so far, and have a
couple more waiting to be done! Python is so amazingly
Because Python doesn't take as many CPU cycles in your brain, it spares
more time for 'big picture' ideas, such as the event handling framework
I'm working on.
--
http://mail.python.org/mailman/listinfo/python-list
import pygame
def main():
SIZE = (300, 200)
WHITE = (255, 255, 255)
pygame.init()
# Create a new grayscale surface
pic = pygame.Surface(SIZE, 0, 8)
palette = tuple([(i, i, i) for i in range(256)])
pic.set_palette(palette)
# Fill it with a gradient
array =
'''
event.py
An event manager using publish/subscribe, and weakrefs.
Any function can publish any event without registering it first, and
any
object can register interest in any event, even if it doesn't exist
yet.
The event manager uses weakrefs, so lists of listeners won't stop them
from being
The following will return a dictionary containing the names and
functions of all the public functions in the current module. If a
function starts with an underscore _, it is considered private and not
listed.
def _ListFunctions():
import sys
import types
d = {}
module =
!
--Kamilche
--
http://mail.python.org/mailman/listinfo/python-list
Yeah, that's what I'm thinking, as well. Showing all the text on an
image is one thing... using that image as the basis of a font engine is
something different.
Luckily, someone has sent me a link to a set of free TrueType fonts -
http://www.gnome.org/fonts , the 'Vera' family. I guess I'll turn
It can only read transparency, it can't write it. I went looking and
found that out a couple weeks ago.
--
http://mail.python.org/mailman/listinfo/python-list
I have a code snippet here that prints a dict in an arbitrary order.
(Certain keys first, with rest appearing in sorted order). I didn't
want to subclass dict, that's error-prone, and overkill for my needs. I
just need something that returns a value like dict.__str__, with a key
ordering I
Does anyone know how to automatically zoom the Idle window when you
start it up? I've tried passing command line parameters, adding code to
PyShell, and more, to no effect.
I suspect the following will be necessary, but I don't know where to
put it:
import ZoomHeight
ZoomHeight.zoom_height(root)
the picture is referenced.
Good job!
--Kamilche
--
http://mail.python.org/mailman/listinfo/python-list
If you wanted to avoid the __getattr__ __setattr__ speed hit, something
like this would work. However, you have to not mind calling a function
to get the data, instead of only getting the attribute:
class Cache(object):
_cache = {}
def __init__(self, filename):
self.filename =
Well, congrats to Google! I think they're the lucky ones, to get him,
and you, both. :-)
--
http://mail.python.org/mailman/listinfo/python-list
acceptance by the programming community at large. (I know
about tKinter, no need to post links to it, thanks.)
--Kamilche
--
http://mail.python.org/mailman/listinfo/python-list
Yeah, I have a system like that on my product. It's a data file loaded
at code startup time, which results in a UI - no need to cut code to
change the interface. It's saved me a lot of time.
I also have a problem with 'designers'. If the GUI designer is as easy
as making an interface was in VB6,
'''
You might find this interesting. Note that the object creation in
main() below could easily be read in from a text file instead,
thus meeting your requirement of not knowing an item's class
until runtime.
Sample output:
{'password': 'Your Password Here', 'type': 'A', 'logonid': 'Your
Logonid
Quite. Although you can sort of see how one might naively arrive at
this
conclusion: one 7-bit char takes 0...127, which when you put it into
an
8-bit byte leaves 128...255 unused for a second char
James
Yep, that's what I was doing. Guess I was too tired to program usefully
last night.
with it!
--Kamilche
'''
import socket
import select
import datetime
_HEADER = '\r\n'.join([
'HTTP/1.0 %s',
'Server: Miniweb-0.1',
'Content-Type: text/html',
'Connection: close',
'Content-Length: %d',
'',
'',
])
_BODY = '\r\n'.join([
'htmlheadtitle%s/title/head
I'm trying to pack two characters into a single byte, and the shifting
in Python has me confused.
Essentially, it should be possible to use a 'packed string' format in
Python, where as long as the characters you're sending are in the ASCII
range 0 to 127, two will fit in a byte.
Here's the code.
To avoid pathname headaches, I've taken to including the following 3
lines at the top of every script that will be double-clicked:
import os, sys
pathname, scriptname = os.path.split(sys.argv[0])
pathname = os.path.abspath(pathname)
os.chdir(pathname)
--
I see what you're attempting to do. However, your code, if it DID run,
would result in a method being added to the object, not the object's
class! Modify the class itself, not the object, as follows:
|class Test:
|def __init__(self):
|self.method()
|
|def m(self):
|print self
|
Thanks, startfile worked great for me!
--
http://mail.python.org/mailman/listinfo/python-list
This script works. But why not make a 'Favorite Search' in ebay, and
have it send you daily email for a year?
--Kamilche
|import urllib
|import smtplib
|
|def main():
|# Perform the search
|results = SearchEbay(['So long and thanks for all the fish',
| 'NOMATCHFOUND
Well, I look forward to seeing the new version. I have the old version
of the Python cookbook, it was very useful!
--
http://mail.python.org/mailman/listinfo/python-list
to be working... but now I'm wondering, what else did it
not change? Can I expect more toes to be blown off?
--Kamilche
--
http://mail.python.org/mailman/listinfo/python-list
That's a powerful advantage - not having to track class instances.
Thanks for the tip! I just got done doing it 'my way' though, now I'll
have to change it. It took me all day! :-D
--
http://mail.python.org/mailman/listinfo/python-list
Would it be possible to just not copy any attribute that starts and
ends with '__'? Or are there some important attributes being copied?
--
http://mail.python.org/mailman/listinfo/python-list
This example worked for me on Windows 2000, after inserting
import threading
from Tkinter import *
import ScrolledText
at the top.
--
http://mail.python.org/mailman/listinfo/python-list
Yeah, but still. If they even had the most basic check, like 'an object
is being referred to on this line, but you're not doing anything with
it' would be handy in catching that. When you use an object like that,
usually you're doing something with it, like assigning it to a variable.
--
Uh, you're right! I wouldn't want to bog Python down with even more
checking at run time. I guess I'm asking for syntax checks that are
typically done only with compiled languages.
It doesn't stop me from using Python, though! Since I don't have syntax
checking, I find I have to test supporting
, it matches my internal idea
of 'pseudocode' to a T. Executable shorthand - does it get any better
than that?
--Kamilche
--
http://mail.python.org/mailman/listinfo/python-list
What a debug nightmare! I just spent HOURS running my script through
the debugger, sprinkling in log statements, and the like, tracking down
my problem.
I called a function without the ending parentheses. I sure do WISH
Python would trap it when I try to do the following:
MyFunc
instead of:
Thomas Rast wrote:
I've found out about a fundamental problem of attribute lookup, the
hard way... Is there anything that can be done about this?
It seems to me that the main problem is you're raising an AttributeError
when an attribute is private. AttributeError is only raised when an
For library modules there are already other and more elegant means.
-Peter
Well, I want to make a script execute without error regardless of where
the current working directory is, and without having to make the user
modify their PYTHONPATH variable or install something in site-packages.
Is
46 matches
Mail list logo