def startElement(self, name, attrs):
self.__downstream.startElement(name, attrs)
return
I want prevent it from shuffling attributes, i.e. preserve original
file's attribute order. Is there any ContentHandler.features*
responsible for that?
I suspect
,
infidel
--
http://mail.python.org/mailman/listinfo/python-list
I find it useful in certain situations. In particular, I have used it
along with cx_Oracle to provide a python module that dynamically
mirrors a package of stored procedures in the database. Basically I
had class StoredProcedure(object) and each instance of this class
represented a particular
On Jul 5, 8:58 am, Hardy [EMAIL PROTECTED] wrote:
I experience a problem with append(). This is a part of my code:
for entity in temp:
md['module']= entity.addr.get('module')
md['id']=entity.addr.get('id')
md['type']=entity.addr.get('type')
I am trying to build a GUI using the Tix module. What I want is a
paned window with a tree in the left pane and a notebook in the right
pane. I keep getting an error that I don't understand when adding
these widgets to the panes:
PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310
I figured it out after finding an example somewhere:
import Tix
app = Tix.Tk(Demo)
panes = Tix.PanedWindow(app)
left = panes.add('left')
right = panes.add('right')
tree = Tix.Tree(left)
notebook = Tix.NoteBook(right)
tree.pack()
notebook.pack()
panes.pack()
app.mainloop()
--
# writing/reading CSV files, tuple-unpacking, cmp() built-in
import csv
writer = csv.writer(open('stocks.csv', 'wb'))
writer.writerows([
('GOOG', 'Google, Inc.', 505.24, 0.47, 0.09),
('YHOO', 'Yahoo! Inc.', 27.38, 0.33, 1.22),
('CNET', 'CNET Networks, Inc.', 8.62, -0.13, -1.49)
])
On Jun 11, 11:30 am, Radamand [EMAIL PROTECTED] wrote:
This has been driving me buggy for 2 days, i need to be able to
iterate a list of items until none are left, without regard to which
items are removed. I'll put the relevant portions of code below,
please forgive my attrocious naming
# reading CSV files, tuple-unpacking
import csv
#pacific.csv contains:
#1,CA,California
#2,AK,Alaska
#3,OR,Oregon
#4,WA,Washington
#5,HI,Hawaii
reader = csv.reader(open('pacific.csv'))
for id, abbr, name in reader:
print '%s is abbreviated: %s' % (name, abbr)
--
ActivePython 2.5.1.1 as well:
PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit
(Intel)] on win32.
Portions Copyright 1994-2006 Mark Hammond - see 'Help/About PythonWin'
for further copyright information.
from pickle import dumps
from cPickle import dumps as cdumps
print
On Apr 23, 9:30 am, Grant Edwards [EMAIL PROTECTED] wrote:
I need to be able to generate a PDF report which consists
mostly of vector images (which I can generate as encapsulated
Postscript, PDF, or SVG). What I need is a way to combine
these figures into a single PDF document. Right now the
And then you have discussion and yet again, there is no perlmonks.org
for Python. We have this, IRC, and what else?
There's also http://planet.python.org, which is an aggregator of python
blogs that I check many times a day for new posts.
--
http://mail.python.org/mailman/listinfo/python-list
Yes I believe so but in fromfile I want to call the appropriate
method depending on the in a parameter in fromfile...
like:
class baseClass:
def fromfile(self, fileObj, byteOrder=None, explicit=False):
if explicit:
call fromfile of explicit class
else:
call
try:
if int(text) = 0: raise ValueError
Hmm, I'm actually not so sure about this line now. It doesn't seem right
to raise a ValueError when the result of the expression is negative,
because even though it's a problem for my program, it isn't really a
ValueError, right?
It's
One of the most stupid language-definition decisions that most people
have come across is the Makefile format.
snippage/
Hope that goes some way to explaining one possible reason why rational
people can consistently react in horror to the issue.
Ah, thanks for that. This peek into history
All societies demonise outsiders to some extent. It's an unfortunate
human (and animal) trait.
Which is why I questioned it.
So just block your ears when the propaganda vans with the loud-speakers
on top drive past your dwelling :-)
Funny how using python makes me feel like a member of some
Also, I've noticed that files are being found within hidden
directories. I'd like to exclude hidden directories from the walk, or
at least not add anything within them. Any advice?
The second item in the tuple yielded by os.walk() is a list of
subdirectories inside the directory indicated by
Where are they-who-hate-us-for-our-whitespace? Are they really that
stupid/petty? Are they really out there at all? They almost sound
like a mythical caste of tasteless heathens that we have invented.
It just sounds like so much trivial nitpickery that it's hard to
believe it's as common as
The time to crush our enemies has come.
This is the Jihad! Death to the infidels
Whoa, dude, let's not get carried away now, 'k?
Looking-over-his-shoulder-ly y'rs,
infidel
--
http://mail.python.org/mailman/listinfo/python-list
Here's how I would do it:
def Validate(self, parent):
try:
text_ctrl = self.GetWindow()
text = text_ctrl.GetValue()
if not text: raise ValueError
if int(text) = 0: raise ValueError
return True
except ValueError,
import types
class OldStyle: pass
...
type(OldStyle) == types.ClassType
True
--
http://mail.python.org/mailman/listinfo/python-list
Any idea? Do you have a naming convention for generators?
Sometimes I use the prefix 'iter', like dictionaries have .items() and
.iteritems(). sometimes I use 'x', like range() vs. xrange(). You
could simply use 'i' like some of the functions in the iteritems module
(imap(), izip(), etc). I
Is there any built-in Hash implementation in Python? I am looking for a
container that I can access to it's items by name. Something like this:
Print container[memeberName]
You obviously haven't read the tutorial, they're called dictionaries
in Python
I am asking this because I learned that
is there any typical usage that shows their difference?
I think the general idea is to use lists for homogenous collections and
tuples for heterogenous structures.
I think the database API provides a good usage that shows their
differences. When you do cursor.fetchall() after executing a
You could also use the assert statement:
if foo and bar:
... assert i = 10, if foo and bar then i must not be greater than
10
...
--
http://mail.python.org/mailman/listinfo/python-list
Bell, Kevin wrote:
Does anyone have any suggestions on printing pdf's? These pdf's don't
change much, so if it be more straight forward to convert them to jpgs,
or another format, then that'd be fine too.
I use GhostScript and GSPrint to send PDFs to our printer in a Windows
environment.
If you want the user to be able to (re)define them in config.py, why
not just define them there in the first place? I may be wrong, but I
think global means module level rather than interpreter level.
--
http://mail.python.org/mailman/listinfo/python-list
dirpath is just a string, so there's no sense in putting it in a list
and then iterating over that list.
If you're trying to do something with each file in the tree:
for dir, subdirs, names in os.walk(rootdir):
for name in names:
filepath = os.path.join(dir, name) + -dummy
if
Alvin A. Delagon wrote:
I'm a simple python webserver based on CGIHTTPServer module:
import CGIHTTPServer
import BaseHTTPServer
import SocketServer
import sys
import SQL,network
from config import *
class
ThreadingServer(SocketServer.ThreadingMixIn,BaseHTTPServer.HTTPServer):
pass
I'm doing some experiments with the SimpleXMLRPCServer in Python,
and I've found it to be an excellent way to do high-level network
operations.
However, is there a way to enable two-way communication using XML-RPC?
By that I mean, can the server contact all the clients?
To do that you'd
Daniel Crespo wrote:
Hi to all,
I want to print a PDF right from my python app transparently. With
transparently I mean that no matter what program handles the print
petition, the user shouldn't be noticed about it.
For example, when I want to print a PDF, Adobe Acrobat fires and keep
i am using a tuple because i am building lists.
I don't understand
if i just use (food +
drink) then while drink is unique food remains the same do i get this:
(burger, coke)
(burger, 7up)
(burger, sprite)
I don't understand what you're saying here.
food and drink are both strings.
tuple is the name of the built-in type, so it's not a very good idea to
reassign it to something else.
(food + drink + '\n') is not a tuple, (food + drink + '\n',) is
There's no reason to use tuples here, just do this:
data.append(food + drink)
f.write('\n'.join(data))
--
Happy holidays to my fellow Pythonistas.
Love,
Saint Infidel the Skeptic
--
http://mail.python.org/mailman/listinfo/python-list
I'm using the Windows version of Python and IDLE. When I debug my .py
file, my modification to the .py file does not seem to take effect
unless I restart IDLE. Saving the file and re-importing it doesn't help
either. Where's the problem?
import only reads the file the first time it's called.
of my projects is structured like this:
C:\src\py
infidel\
__init__.py
models\
__init__.py
basemodel.py
views\
__init__.py
baseview.py
controllers\
__init__.py
Now the controllers package can do imports
Just an idea: because in CherryPy it is running in multithreading mode?
If you are using threads together with COM stuff, you will have to
add pythoncom.CoInitialize() and pythoncom.CoUninitialize() calls
in your code -- for each thread.
That worked perfectly. Thanks a million!
I used to
I've been trying to get my CherryPy server to authenticate users
against our network. I've managed to cobble together a simple function
that uses our LDAP server to validate the username and password entered
by the user:
# ldap.py
from win32com.client import GetObject
ADS_SECURE_AUTHENTICATION
I have a stored procedure that has a single output parameter. Why do I
have to pass it a string big enough to hold the value it is to receive?
Why can't I pass an empty string or None?
import cx_Oracle as oracle
connection = oracle.connect('usr/[EMAIL PROTECTED]')
cursor =
vb_bv wrote:
Does Pyton PL/SQL programming language of Oracle support?
Thx
PL/SQL is only supported *inside* Oracle databases. Python can be used
to call PL/SQL procedures (I recommend the cx_Oracle module), but you
can't run Python inside the database like PL/SQL.
--
Thanks for your answers.
I would like to document with Python PL/SQL of programs, so similarly
as javadoc for Java.
I do not know whether it is possible. If yes, I would like to know how.
All of the source code for procedures and packages in an oracle
database can be retreived from the
Python has spoiled me. I used to periodically try out new languages
just for fun, but since learning Python, it's become a lot less
interesting. I find myself preferring to just try new ideas or
techniques in Python rather than searching for new languages to dabble
in. The last few I've
http://dictionary.reference.com/search?q=pythonic
http://thesaurus.reference.com/search?r=2q=pythonic
--
http://mail.python.org/mailman/listinfo/python-list
Hello, I am learning python for work from knowing java,c#,c. I had a
couple questions.
1) IntegerClass - to instantiate this class how come I use i =
IntegerClass.IntegerClass() and then this works while i =
IntegerClass() i.method. I receive an error.
It depends on what IntegerClass is.
I can replace all None values with the string 'Null', there's no
problem, but I can't detect the DateTime type object I retrieve from
the database.
I have something like this:
def xmlrpc_function():
conn = adodb.NewADOConnection('postgres')
conn.Connect(host,user,password,database)
Ok, so it turns out that the problem the cherrypy.lib.autoreload module
is having, is that kid imports elementtree and on my machine the
elementtree modules are inside a zip file (.egg). So the path to the
elementtree __init__.py file is not a valid OS path because everything
after the .egg file
I did an svn update of cherrypy this morning, and now when I try
running a server, the log window just keeps reporting the autoreloader
restarting over and over:
2005/10/19 12:42:33 HTTP INFO SystemExit raised: shutting down
autoreloader
2005/10/19 12:42:33 HTTP INFO CherryPy shut down
2005/10/19
Ok, the problem seems to be with my cherrypy importing Kid. If I
import the kid module or any of my compiled kid template modules, then
I get the autoreloader infinite loop. Is anyone else experiencing this
effect?
--
http://mail.python.org/mailman/listinfo/python-list
I may have found the source of my infinite loop when importing kid
modules from my cherrypy server. Here is some code from the
autoreloader module of cherrypy:
def reloader_thread():
mtimes = {}
def fileattr(m):
return getattr(m, __file__, None)
while RUN_RELOADER:
By Denise Kalette
Associated Press
MIAMI - The alligator has some foreign competition at the top of the
Everglades food chain, and the results of the struggle are horror-movie
messy.
A 13-foot Burmese python recently burst after it apparently tried to
swallow a live 6-foot alligator whole,
SELECT
VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY,VO_DESCRIPTION + \
FROM D014800 LEFT OUTER JOIN D014900 ON (VA_MK_NUMBER_VER =
VO_MAKE_NO) AND (VA_MK_YEAR = VO_YEAR) + \
WHERE (((VA_MK_YEAR)=?) AND ((VA_MK_DESCRIP)=?) AND
((VO_MODEL)=?))
Doesn't look like you have a space
import shutil
#variables
s = shutil
toHPU = /etc/sysconfig/network/toHPU.wifi
wlan = /etc/sysconfig/network/ifcfg-wlan-id-00:0e:38:88:ba:6d
toAnyWifi = /etc/sysconfig/network/toAny.wifi
wired = /etc/sysconfig/network/ifcfg-eth-id-00:0b:db:1b:e3:88
def toHPU():
I see what's happening, but I'm at a loss to figure out what to do
about it. Any help would be appreciated.
Try giving the buttons different name attributes.
--
http://mail.python.org/mailman/listinfo/python-list
Angelic Devil wrote:
I'm building a file parser but I have a problem I'm not sure how to
solve. The files this will parse have the potential to be huge
(multiple GBs). There are distinct sections of the file that I
want to read into separate dictionaries to perform different
operations on.
If that were so, Pythonistas could never write a recursive function!
No, presumably at the writing of the edition of _Learning Python_ that
he is reading, Python did not have nested scopes in the language, yet.
One could always write a recursive function provided it was at the
top-level of
import __main__
if __name__!='__main__':
print 1
print 2
when i run test.py, i got
2
on the screen.
now, i have some question about the code, 1. since no __main__ module at
all, why it's legal to write import __main__?
__main__ is the module that the interpreter starts executing.
Learning Python wrote:
A example in learning Python by Mark Lutz and David Ascher
about function scope
example like this:
def outer(x):
def inner(i):
print i,
if i: inner(i-1)
inner(x)
outer(3)
Here supposely, it should report error, because the function
but... i see it doesn't work for some commands, like man python (it
gets stuck on the if line)...
.readlines() won't return until it hits end-of-file, but the man
command waits for user input to scroll the content, like the more or
less commands let you view pages of information on a terminal.
Here's one technique I use to run an external command in a particular
module:
stdin, stdout, stderr = os.popen3(cmd)
stdin.close()
results = stdout.readlines()
stdout.close()
errors = stderr.readlines()
stderr.close()
if errors:
I have just recently discovered CherryPy and Kid (many kudos to the
respective developers!) and am tinkering with them to see what I can
come up with.
The application I eventually want to write will eventually require the
python code to call stored procedures in a database which means I'll
need
It might make more sense if you could find out exactly what that one
argument contains.
--
http://mail.python.org/mailman/listinfo/python-list
I am very new to Python, but have done plenty of development in C++ and
Java.
And therein lies the root of your question, I believe.
One thing I find weird about python is the idea of a module. Why is this
needed when there are already the ideas of class, file, and package?
One reason is
in Python equality rebinds the name
Assignment (=) rebinds the name. Equality (==) is something else
entirely.
--
http://mail.python.org/mailman/listinfo/python-list
I think you have to call type.__new__ like this:
def __new__(cls, year, month, day, *args, **kw):
print new called
try:
return _datetime.__new__(cls, year, month, day, *args,
**kw)
except ValueError:
return type.__new__(cls, ...)
Are you sure
Are you sure you can specify arbitrary arguments to the __new__ method?
I thought they had to be the class object, the tuple of bases, and the
dictionary of names.
Nevermind, I think I was imagining metaclasses rather than just regular
overriding of __new__
--
I'm not sure I understand why you would want to. Just don't define
__iter__ on your newstyle class and you'll get the expected behavior.
--
http://mail.python.org/mailman/listinfo/python-list
Why not define an Iterator method in your Base class that does the
iteration using __getitem__, and any subclass that wants to do
something else just defines its own Iterator method? For that matter,
you could just use the __iter__ methods of Base and Concrete instead of
a separate method.
--
Something like this:
class Base(object):
... def __getitem__(self, key):
... return key
... def __iter__(self):
... yield self[1]
... yield self['foo']
... yield self[3.0]
...
class ConcreteIterable(Base):
... def __iter__(self):
...
Do you have control over the eggs.so module? Seems to me the best
answer is to make the start method return a connection object
conn1 = eggs.start('Connection1')
conn2 = eggs.start('Connection2')
--
http://mail.python.org/mailman/listinfo/python-list
def class Colour:
def __init__(self, blue=0, green=0, red=0):
# pseudo-Python code borrowing concept with from Pascal
with self:
blue = blue
green = green
red = red
And now you can see why Python doesn't support this idiom.
Maybe it
dict((x, None) for x in alist)
--
http://mail.python.org/mailman/listinfo/python-list
Why in the name of all that is holy and just would you need to do such
a thing?
--
http://mail.python.org/mailman/listinfo/python-list
I don't think that makes any sense. How could you possibly create such
a circular relationship between things in any language? Besides, if I
understand metaclasses at all, only other metaclasses can be bases of a
metaclass.
Why not use python classes to represent the other system's types with a
God made me an atheist, who are you to question His wisdom?
-- Saint Infidel the Skeptic
--
http://mail.python.org/mailman/listinfo/python-list
because i need the representations of the other systems types to
themselves be python classes, and so i need a metaclass to make sure
they follow certain rules. This metaclass is for that system what type
is for python
I think that's exactly the same thing I just said. More or less.
Although
Oh great, just when I thought I was starting to grok this mess.
--
http://mail.python.org/mailman/listinfo/python-list
Ok, forget everything I've said. The more I think about this the less
I understand it. I'm way out of my league here.
sitting-down-and-shutting-up-ly y'rs,
infi
--
http://mail.python.org/mailman/listinfo/python-list
carlos Supose that I want to create two methos (inside a
carlos class) with exactly same name, but number of
carlos parameters different
That isn't polymorphism, that's function overloading.
carlos Look, I don't want to use things like:
carlos
carlos def myMethod(self, myValue=None):
I think perhaps you are asking for something that the OCI doesn't
provide. At least I'd be rather surprised if it did. I know that the
SQL syntax doesn't provide for such a mechanism.
And really, it all boils down to the list comprehension:
in_clause = ', '.join([':id%d' % x for x in
Here's a slight variation of tiissa's solution that gives the callable
a reference to the actual widget instead of just it's name:
from Tkinter import Tk, Button
class say_hello:
def __init__(self, widget):
self.widget = widget
def __call__(self):
print 'Hello,',
from Tkinter import Tk, Button
def say_hello(event):
print 'hello!'
print event.widget['text']
root = Tk()
button1 = Button(root, text='Button 1')
button1.bind('Button-1', say_hello)
button1.pack()
button2 = Button(root, text='Button 2')
button2.bind('Button-1', say_hello)
button2.pack()
You can use the Content-Length header to tell the server how long the
string is.
--
http://mail.python.org/mailman/listinfo/python-list
cx_Oracle rocks
--
http://mail.python.org/mailman/listinfo/python-list
That just means the urllib.socket module doesn't have any function
named setdefaulttimeout in it.
It appears there might be something wrong with your socket module as
mine has it:
py import urllib
py f = urllib.socket.setdefaulttimeout
py f
built-in function setdefaulttimeout
--
You can use the new 'sorted' built-in function and custom compare
functions to return lists of players sorted according to any criteria:
players = [
... {'name' : 'joe', 'defense' : 8, 'attacking' : 5, 'midfield' : 6,
'goalkeeping' : 9},
... {'name' : 'bob', 'defense' : 5, 'attacking' :
First, if you're going to loop over each line, do it like this:
for line in file('playerlist.txt'):
#do stuff here
Second, this statement is referencing the *second* item in the list,
not the first:
match = ph.match(list[1])
Third, a simple splitting of the lines by some delimiter
There's no Resume Next in python. Once you catch an exception, the
only way you can go is forward from that point.
So if B.CallingMethod catches an exception that was raised in
A.CalledMethod, all it could do is try calling A.CalledMethod again, it
can't jump back to the point where the
I've notice the same thing. It seems that it will return as much as it
can that matches the grammar and just stop when it encounters something
it doesn't recognize.
--
http://mail.python.org/mailman/listinfo/python-list
Acrobat is stupid like this. I haven't yet found a way to prevent it
from launching a new window, so I gave up and went with GhostScript and
GSPrint instead. Works fabulously.
--
http://mail.python.org/mailman/listinfo/python-list
Of course I meant to put a break out of the loop after the print
statement. Duh on me.
--
http://mail.python.org/mailman/listinfo/python-list
It took me a while to figure out what the translated code was trying
to do. Here's a quick example that I think accomplishes the same
thing:
for i, n in enumerate(x for x in xrange(998) if x % 2 == 0):
... if i == 1:
... print n
...
2
--
Not that my opinion is worth anything in these matters, but I like the
upper-left example at http://exogen.cwru.edu/python.png the best (out
of the samples I've seen thus far). I don't like the gear shape, and
I think adding a coil or circle around the head detracts somewhat
from the look. I
92 matches
Mail list logo