Failed to create bitmap image
Hello, i'm using python 2.5 on vista, when i compile my script i got this error. wx._core.PyAssertionError: C++ assertion "image.Ok()" failed at ..\..\src\msw\bitmap.cpp(799) in wxBitmap::CreateFromImage(): invalid image Any idea about this error message ? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: python at command prompt
On Sat, 03 Nov 2007 22:51:05 GMT, Tim Roberts <[EMAIL PROTECTED]> wrote: >Ton van Vliet <[EMAIL PROTECTED]> wrote: >> >>There's could also be an issue with entering 'python' at the command >>line, and not 'python.exe'. Once the PATH is setup correctly, try to >>enter 'python.exe', and check whether that works. >> >>IMHO, to get any 'program-name' (without the .exe extension) to work, >>one needs to: >>1. register the executable with windows (doesn't work for python) or >>2. make sure the the PATHEXT environment variable is set correctly, >>and includes the .EXE extension (on my w2k system it looks like: >>.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH) please note that I state 1 *or* 2 >You're confusing two things here. Executables (.exe) are always available, >and do not need to be registered to be run without the extension. but *only* if the PATHEXT environment variable is setup correctly >It is possible to have Windows execute "abc.py" when you type "abc", and >that DOES require registering the .py extension and adding .py to the >PATHEXT environment variable. There are executables (.exe) that have a 'registering' option builtin, and need to be registered to have their capabilities made available using the /regserver switch (possibly related to OLE/COM services, but I'm not an expert here ;-) see: http://consumer.installshield.com/kb.asp?id=Q108199 (last para) >A very useful thing to do, by the way. I have many command line tools for >which I have forgotten whether they are batch files, small executables, or >Python scripts. And that's how it should be. -- Ton -- http://mail.python.org/mailman/listinfo/python-list
parsing string to a list of objects - help!
Hi, I really hope someone can help me -- I'm stuck.
I have written three versions of code over a week and still can't get past
this problem, it's blocking my path to getting other code written.
This might be a little hairy, but I'll try to keep it short.
Situation:
I want to pass a string to a function which will parse it and generate
objects in a list.
Each object is a "property" which keeps members like x,y,r,g,b etc.
Each element in the final list describes a frame in an animation.
I want to be able to pass only the properties of key moments (key frames) in
time to the function. Along with that is passed the *way* each moment
changes into the next.
The form I am using is like this:
t=Thing()
t.propLayout("#---#---#==_##_")
prop1 = Property(x=10,y=10,r=1,g=1,b=1,a=0)
prop2 = Property(x=20,y=10,r=0,g=0,b=1,a=1)
prop3 = Property(x=10,y=100,r=1,g=1,b=1,a=1)
prop4 = Property(x=100,y=200,r=1,g=1,b=1,a=1)
t.setProps(prop1,prop1,prop2,prop3,prop4)
So setProps is the parser and it creates a proplist within t.
My short-hand for this:
# is a property
- is a 'tween' (where the property before it influences it)
= is a property exactly the same as the one before it.
_ (underscore) is a blank frame
Things like this can be expressed:
1234567890123
#---#--#===_#
(4 keyframes, #'s. 13 frames, lifetime.)
In words that would say:
Frame 1, make a property.
Frame 2 to 4 tweening : copy previous property (from 1) and advance the
members by the average (calculated by getting the range between 1 and 5 and
going through each member variable (x,y,z,r,g,b) and dividing etc. This
means looking ahead.)
Frame 5, make a property
Frame 6 to 7 tweening.
Frame 8, make a property
Frame 9 to 11, copy property from 8
Frame 12, make a blank
Frame 13, make a property.
So, the animation will proceed: Start at 1, move/morph to 5, move/morph to
8, remain static to 11, go away for 12 and appear somewhere at 13.
It seems so simple, but I just cannot nail it down. Each time I end up with
a mess of string[index] and if else tests within while loops that seem to
work until I get to a test string that breaks it all.
I'm sure there must be a better way to formalize this little 'language' and
break it down into a list of property objects that exactly describes the
string -- catching user errors too.
The rules:
Tweens : must start and end in # signs: ##
Static : must start with a # : #===
No other chars can be within a range: #==_= is bad. #--=--# is bad.
Odds:
Singles: things like ### are valid. This means each is a frame somewhere,
implying they will jump around (i.e. not be statics)
Blanks : are simple - they are properties for every underscore
I have glanced around at parsing and all the tech-speak confuses the heck
out of me. I am not too smart and would appreciate any help that steers
away from cold theory and simply hits at this problem.
Donn.
--
http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > As far as I know, all it would take to allow modules to be callable > would be a single change to the module type, the equivalent of: > > def __call__(self, *args, **kwargs): > try: > # Special methods are retrieved from the class, not > # from the instance, so we need to see if the > # instance has the right method. > callable = self.__dict__['__call__'] > except KeyError: > return None # or raise an exception? > return callable(self, *args, **kwargs) > The error should throw "TypeError: 'module' object is not callable" just as it does today. Also, it shouldn't pass self through to callable: modules have functions not methods. -- http://mail.python.org/mailman/listinfo/python-list
Re: __file__ vs __FILE__
interestingly... I wanted to reuse this code so i wrote function in a file def getParentDir(): import os return os.path.dirname(os.path.abspath(__file__)) and called this function, in another file, its giving me parent directory of file where this function is defined.? how to reuse this piece of code then? or am i doing something wrong? btw using __path__[0], I can get the parent directory of file too... sandip On Nov 5, 5:09 am, Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > On 3 Nov, 15:46, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > > > > > En Sat, 03 Nov 2007 10:07:10 -0300, Giampaolo Rodola' <[EMAIL PROTECTED]> > > escribió: > > > > On 3 Nov, 04:21, klenwell <[EMAIL PROTECTED]> wrote: > > >> In PHP you have the __FILE__ constant which gives you the value of the > > >> absolute path of the file you're in (as opposed to the main script > > >> file.) > > > This is not really 'one-line' since you have to import two modules > > > first, but it looks nicer...: > > > > import sys, os > > > print sys.argv[0] # absolute file name > > > print os.path.dirname(sys.argv[0]) # absolute dir name > > > Note that this returns the location of the *main* script, not the current > > module, as the OP explicitely asked for. > > > -- > > Gabriel Genellina > > Whoops! You're right. -- http://mail.python.org/mailman/listinfo/python-list
Re: Descriptors and side effects
[EMAIL PROTECTED] a écrit :
> Hello everyone,
>
> I'm trying to do seemingly trivial thing with descriptors: have
> another attribute updated on dot access in object defined using
> descriptors.
>
> For example, let's take a simple example where you set an attribute s
> to a string and have another attribute l set automatically to its
> length.
>
class Desc(str):
> def __init__(self,val):
> self.s=val
> self.l=len(val)
> print "creating value: ", self.s
> print "id(self.l)", id(self.l)
> def __set__(self, obj, val):
> self.s=val
> self.l=len(val)
> print "setting value:", self.s, "length:", self.l
> def __get__(self, obj, type=None):
> print "getting value:", self.s, "length:", self.l
> return self.l
>
>
class some(str):
> m=Desc('abc')
> l=m.l
First point : I don't get why Desc and some derive from str. Second
point: I don't get why you're storing the value and it's length in the
descriptor itself - obviously, you can't expect one descriptor instance
to be mapped to 2 distinct attributes. Third point: you understand that,
the way you wrote it, your descriptor will behave as a class (ie:shared)
attribute, don't you. Fourth point: if you hope some.l to be rebound
when m.l is, then you should learn Python basics before trying to jump
into descriptors.
The obvious, simple way to some your problem is to use a couple of
properties:
class Some(object):
@apply
def m():
def fget(self):
return self._m
def fset(self, val):
self._m = val
self._l = len(val)
return property(**locals())
@apply
def l():
def fget(self):
return self._l
def fset(self):
raise AttributeError("%s.l is readonly" % self)
def __init__(self, m):
self.m = m
Now if you absolutely insist on using custom descriptors, you'll need
two of them: one to manage access to s, and the second to manage access
to l (which btw is a very bad name):
class DescS(object):
def __init__(self, val):
self._default = val
def __set___(self, obj, val):
obj._s = val
obj._l = len(val)
def __get__(self, obj, cls):
if obj is None:
return self # or self._default, or whatever
try:
return obj._s
except AttributeError:
return self._default
class DescL(object):
def __init__(self, descS):
self._descS = descS
def __get__(self, obj, cls):
if obj is None:
return self # or self._default, or whatever
try:
return obj._l
except AttributeError:
return len(self._descS._default)
class Test(object):
m = DescS('abc')
l = DescL(m)
(nb : not tested)
--
http://mail.python.org/mailman/listinfo/python-list
Re: achieving performance using C/C++
Hi all, I'd be very interseted in a good tutorial for using C/C++ to optimize python code too ! Thanks in advance. sandipm wrote: > I did fair amount of programming in python but never used c/c++ as > mentioned below. > any good tutorials for using C/C++ to optimize python codebase for > performance? > how widely do they use such kind of mixed coding practices? > > sandip > > -- Forwarded message -- > From: "D.Hering" > . > . > . > . > Python is very easily extended to near C speed. The Idea that FINALLY > sunk in, was that I should first program my ideas in Python WITHOUT > CONCERN FOR PERFOMANCE. Then, profile the application to find the > "bottlenecks" and extend those blocks of code to C or C++. Cython/ > Pyrex/Sip are my preferences for python extension frameworks. > . > . > . > . -- http://mail.python.org/mailman/listinfo/python-list
Re: parsing string to a list of objects - help!
On Nov 5, 3:00 am, Donn Ingle <[EMAIL PROTECTED]> wrote:
>
> I have glanced around at parsing and all the tech-speak confuses the heck
> out of me. I am not too smart and would appreciate any help that steers
> away from cold theory and simply hits at this problem.
>
Donn -
Here is a pyparsing version that I hope is fairly easy-to-read and
tech-speak free:
from pyparsing import *
frame = Literal("#")
tween = Word("-") # that is, it is a "word" composed of 1 or more -'s
copy = Literal("=")
blank = Literal("_")
animation = OneOrMore((frame + Optional(
(tween + FollowedBy(frame)) |
OneOrMore(copy | blank) ) ) )
test = "#---#--#===_#"
print animation.parseString(test)
This prints the following:
['#', '---', '#', '--', '#', '=', '=', '=', '_', '#']
>From here, the next step would be to define classes that these matched
tokens could be converted to. Pyparsing allows you to attach a method
to individual expressions using setParseAction - if you pass a class
instead of a method, then class instances are returned. For these
tokens, you could write:
class Prop(object):
def __init__(self,tokens):
pass
class Tween(object):
def __init__(self,tokens):
self.tween = tokens[0]
self.tweenLength = len(self.tween)
class CopyPrevious(object):
def __init__(self,tokens):
pass
class Blank(object):
def __init__(self,tokens):
pass
frame.setParseAction(Prop)
tween.setParseAction(Tween)
copy.setParseAction(CopyPrevious)
blank.setParseAction(Blank)
And now calling animation.parseString(test) returns a sequence of
objects representing the input string's frames, tweens, etc.:
[<__main__.Prop object at 0x00B9D8F0>, <__main__.Tween object at
0x00BA5390>, <__main__.Prop object at 0x00B9D9B0>, <__main__.Tween
object at 0x00BA55F0>, <__main__.Prop object at 0x00BA5230>,
<__main__.CopyPrevious object at 0x00BA58F0>, <__main__.CopyPrevious
object at 0x00BA59D0>, <__main__.CopyPrevious object at 0x00BA5AB0>,
<__main__.Blank object at 0x00BA5B70>, <__main__.Prop object at
0x00BA5510>]
Now you can implement behavior in these 4 classes to implement the
tweening, copying, etc. behavior that you want, and then walk through
this sequence invoking this animation logic.
-- Paul
--
http://mail.python.org/mailman/listinfo/python-list
Re: parsing string to a list of objects - help!
Wow Paul, you have given me much to chew. I'll start testing it in my slow way -- it looks so simple! Thank you. \d -- http://mail.python.org/mailman/listinfo/python-list
Re: Is pyparsing really a recursive descent parser?
On 2007-11-05, Just Another Victim of the Ambient Morality <[EMAIL PROTECTED]> wrote: > "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> There are different kinds of recursion. Compare: > > While interesting, none of this actually addresses the > point I was making. I wasn't saying that there was no > recursion (at least, not in this paragraph), I was saying that > it wasn't recursing through what I thought it should be > recursing through. It recurses through a set of rules without > any regard to how these rules interact with each other. That's > why it fails to parse valid strings. In my opinion, it should > recurse through appropriate combinations of rules to determine > validity, rather than by arbitrary > categorization... OK. I thought you were saying that, without backtracking there's no recursion. Never mind! > I guess that all the And and Or class in pyparsing call > methods of each other from each other, even if they are doing > so from different instantiations. I still say they're not > recursing through the right things... Backtracking seems orthoganal to recursion, to me. I'm not sure one needs to start again with a naive approach just to avoid any parser theory. For a user of a parser it is quite important whether she has to wait 50 seconds for a parse to run or 50 milliseconds. I don't like to compromise speed for implementation simplicity here. >>> >>> Finally, I can't believe you complain about potential speed >>> problems. First, depending on the size of the string, it's >>> likely to be the difference between 2ms and 200ms. Secondly, >>> if speed were an issue, you wouldn't go with a recursive >>> descent parser. You'd go with LALR or the many other parsing >>> techniques available. Recursive descent parsing is for those >>> situations where you need correctness, regardless of execution >>> time. These situations happen... >> >> RDP is plenty fast; speed has never been one of it's >> disadvantages, as far as I know. Today there are many >> excellent parser generators and compiler builders that compose an >> RDP under the hood, e.g., Antlr and Gentle. > > I think I read somewhere that LALR was O(n) while RDP was > O(e^n). Most people would consider that, at least, slower... To my knowledge, most RDPs are LL(1), which is O(n). As you increase the amount of lookahead (a backtracking RDP is, I suppose, be a brute-force way of getting infinite lookahead), the complexity increases. > I think your examples may exemplify how little speed > matters rather than how fast RDPs are... > > Also, it should probably be noted that bubble sort is very > fast for nearly sorted lists; much faster than quicksort. So, > while it shouldn't be the default sorting algorithm, you could > have it somewhere in the library... Yes, bubble-sort runs fast in certain circumstances; you wouldn't want to be bereft of it completely. Backtracking parsers do probably have their place in the pantheon. I don't want PyParsing to do backtracking by default, though it might be a useful option. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: parsing string to a list of objects - help!
Paul,
I quickly slapped your example into a py file for a first-glance test and
the first part works, but the second gives me the error below. Could I have
an old version of pyparser? I will dig into it anyway, just being lazy :)
code:
from pyparsing import *
frame = Literal("#")
tween = Word("-") # that is, it is a "word" composed of 1 or more -'s
copy = Literal("=")
blank = Literal("_")
animation = OneOrMore((frame + Optional(
(tween + FollowedBy(frame)) |
OneOrMore(copy | blank) ) ) )
test = "#---#--#===_#"
print animation.parseString(test)
class Prop(object):
def __init__(self,tokens):
pass
class Tween(object):
def __init__(self,tokens):
self.tween = tokens[0]
self.tweenLength = len(self.tween)
class CopyPrevious(object):
def __init__(self,tokens):
pass
class Blank(object):
def __init__(self,tokens):
pass
frame.setParseAction(Prop)
tween.setParseAction(Tween)
copy.setParseAction(CopyPrevious)
blank.setParseAction(Blank)
animation.parseString(test)
result:
containers:$ python parser.py
['#', '---', '#', '--', '#', '=', '=', '=', '_', '#']
Traceback (most recent call last):
File "parser.py", line 39, in ?
animation.parseString(test)
File "/usr/lib/python2.4/site-packages/pyparsing.py", line 620, in
parseString
loc, tokens = self.parse( instring.expandtabs(), 0 )
File "/usr/lib/python2.4/site-packages/pyparsing.py", line 562, in parse
loc,tokens = self.parseImpl( instring, loc, doActions )
File "/usr/lib/python2.4/site-packages/pyparsing.py", line 1768, in
parseImpl
loc, tokens = self.expr.parse( instring, loc, doActions )
File "/usr/lib/python2.4/site-packages/pyparsing.py", line 562, in parse
loc,tokens = self.parseImpl( instring, loc, doActions )
File "/usr/lib/python2.4/site-packages/pyparsing.py", line 1390, in
parseImpl
loc, resultlist = self.exprs[0].parse( instring, loc, doActions )
File "/usr/lib/python2.4/site-packages/pyparsing.py", line 588, in parse
tokens = self.parseAction( instring, tokensStart, retTokens )
TypeError: __init__() takes exactly 2 arguments (4 given)
--
http://mail.python.org/mailman/listinfo/python-list
Re: parsing string to a list of objects - help!
Wow Paul, you have given me much to chew. I'll start testing it in my slow way -- it looks so simple! Thank you. \d -- http://mail.python.org/mailman/listinfo/python-list
Re: Assertion for python scripts
On Nov 2, 11:22 pm, Carl Banks <[EMAIL PROTECTED]> wrote: > On Nov 2, 2:14 pm, matthias <[EMAIL PROTECTED]> wrote: > > > Here is my question: How do I maintain debug / release builds that > > allow me to switch > > debug stmts, like assert, on / off ? > > If you want to distribute a single-file optimized version, perhaps > embedding the Python code as a here-file in a shell script would work > for you. For example: > > #!/bin/sh > exec python -O < > assert False > > EOF Not long after I made this suggestion, I suddenly found myself in a situation where I wanted to do something like this (temporarily: I needed to disable a pointer check that a buggy C++ extension was causing). Here's what I ended up with, after falling in a few pits: #!/bin/sh MALLOC_CHECK_=0 /usr/bin/python2.4 - "$@" <<'SCRIPT'
Re: achieving performance using C/C++
On Nov 5, 7:40 am, sandipm <[EMAIL PROTECTED]> wrote: > I did fair amount of programming in python but never used c/c++ as > mentioned below. > any good tutorials for using C/C++ to optimize python codebase for > performance? > how widely do they use such kind of mixed coding practices? [...] Since you are fluent in Python I also suggest you to start with Pyrex[1]/Cython[2]. This will let you to express your ideas more naturally (in a Python-based language) and interface with C code base without delving much into reference counting, manual parameters conversion and low-level exception handling. You will find some tutorials and links to resources and mailing lists on the projects websites, and if you specify your problem a bit more then probably someone will be able to give you more precise references. For alternatives take a look at [3] and [4]. Try also scanning the Python Package Index[5] for 'binding', 'wrapper', 'lib' or 'pyrex' keywords or browse for C/C++ Programming Language category as this will return some examples of Python extensions. [1] http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ [2] http://www.cython.org/ [3] http://www.python.org/doc/faq/extending/#writing-c-is-hard-are-there-any-alternatives [4] http://docs.python.org/lib/module-ctypes.html [5] http://pypi.python.org fw -- http://mail.python.org/mailman/listinfo/python-list
Re: (MAC) CoreGraphics module???
On Sun, 04 Nov 2007 15:56:21 -0600, Robert Kern <[EMAIL PROTECTED]> wrote: >David C. Ullrich wrote: >> On Fri, 02 Nov 2007 14:09:25 -0500, Robert Kern >> <[EMAIL PROTECTED]> wrote: >> >>> David C. Ullrich wrote: [???] >>> Okay, which version of OS X do you have? In 10.3 and 10.4 it used to be >>> here: >>> /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/CoreGraphics.py >>> >>> I notice that in 10.5, it no longer exists, though. >> >> Um, surely that doesn't mean that there's no CoreGraphics >> available in 10.5? > >The CoreGraphics C library still exists, of course. The Python module they >provided does not. Right - I was referring to the Python module. Why would they do such a thing? (Never mind, I don't imagine you know.) Hmm, I saw somewhere the other day that PyObjC comes with 10.5. Maybe that means there's no longer any point to a separate CoreGraphics.py? David C. Ullrich -- http://mail.python.org/mailman/listinfo/python-list
Downloading file from cgi application
Hi, I'm writing a cgi application in Python that generates a PDF file for the user and then allows them to download that file. Currently I'm just writing the PDF file to the 'htdocs' directory and giving the user a link to this file to download it. But the problem is that another user could simply come along and download a file that isn't their file by typing the address into the address bar. I don't want to delete the file after it is downloaded either because I'd like the user to be able to download it again if necessary. Is there any way around this problem? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
> -- Forwarded message -- > From: "D.Hering" <[EMAIL PROTECTED]> > To: [email protected] > Date: Sun, 04 Nov 2007 19:42:16 -0800 > Subject: Re: Python good for data mining? > On Nov 3, 9:02 pm, Jens <[EMAIL PROTECTED]> wrote: > > I'm starting a project indatamining, and I'm considering Python and > > Java as possible platforms. > > > > I'm conserned by performance. Most benchmarks report that Java is > > about 10-15 times faster than Python, and my own experiments confirms > > this. I could imagine this to become a problem for very large > > datasets. > > > I really like Python for a number of reasons, and would like to avoid > > Java. I've been working with databases -- many in the terabyte size -- for over 20 years and my advice to you is to learn how to use SQL to do most of the work for you. There is (almost) nothing you can't do with a good database (we use Oracle and Postgres, but I hear that MySQL is good, too). We have over 100 stored procedures and some of our queries are a bit long; some with over 30 JOINS, but our queries are fast enough. We even generate XML and EDI-X12 directly from the database via stored procedures. I used to pull as much as I could back from the database and them manipulate it with C using abstract data types and record layouts with lots of pointers. Now I use Python to access the base and let the database do most of the heavy lifting. Life is good. --greg -- http://mail.python.org/mailman/listinfo/python-list
Re: how does google search in phrase
On Nov 4, 6:21 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > hi my friends; > google can searching in phrase but it is imposible. it have a lot of > page in data base and quadrillions sentence it can't search in > fulltxt all of them .it need a super algorithm. ý need the algorithm > now. if you have a idea ,pls share to me Ummm... What? Do you want to use Google or create another Google? > thanks > (sorry for my bad english :( ) -- http://mail.python.org/mailman/listinfo/python-list
Re: how does google search in phrase
Here is a detailed explanation: http://www.google.com/technology/pigeonrank.html -- http://mail.python.org/mailman/listinfo/python-list
Re: python at command prompt
On Mon, 05 Nov 2007 11:03:36 +1100, "[david]" <[EMAIL PROTECTED]> wrote: >Tim Roberts wrote: >> Ton van Vliet <[EMAIL PROTECTED]> wrote: >>> There's could also be an issue with entering 'python' at the command >>> line, and not 'python.exe'. Once the PATH is setup correctly, try to >>> enter 'python.exe', and check whether that works. >>> >>> IMHO, to get any 'program-name' (without the .exe extension) to work, >>> one needs to: >>> 1. register the executable with windows (doesn't work for python) or >>> 2. make sure the the PATHEXT environment variable is set correctly, >>> and includes the .EXE extension (on my w2k system it looks like: >>> .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH) >> >> You're confusing two things here. Executables (.exe) are always available, >> and do not need to be registered to be run without the extension. >> >> It is possible to have Windows execute "abc.py" when you type "abc", and >> that DOES require registering the .py extension and adding .py to the >> PATHEXT environment variable. >> >> A very useful thing to do, by the way. I have many command line tools for >> which I have forgotten whether they are batch files, small executables, or >> Python scripts. And that's how it should be. > >That is, > >"Executables (.exe) are always available," >... provided that the PATHEXT environment variable >has not been set incorrectly... Right >and >"Executables ... do not need to be registered" Right also, however they may be 'registered' to get a 'similar' kind of response: If you have a look at the following registry key: HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths you may find several 'registered' applications that can be launched without appending the .exe extension from the 'start|run' menu If you want to experiment for yourself: (needless to say: be carefull) 1. Select a small stand-alone .exe application of your choice 2. *copy* the .exe into some directory that is not on your PATH (e.g. d:\temp) 3. Rename the application (e.g. to 'eppo.exe') 4. Open regedit and add an 'eppo.exe' to the above mentioned 'App Paths' key 5. Modify its (Default) value to 'd:\temp\eppo.exe' >From now on you can just enter 'eppo' at 'Start|Run' entry field, to launch the application To make entering 'eppo' working at the command prompt, the directory in which the eppo.exe is located must be in the (search) PATH, even if the PATHEXT is *not* setup correctly. If the applications directory is not on your PATH, you may still start it with 'start eppo' I definitely am not an expert in this area, so may someone else may come with a better explanation of this .exe registering stuff, I'm sure there's more involved (like setting of the 'open with' keys, registering COM servers, etc) but I just wanted to bring up that 'registering' executables is not *that* uncommon. HTH ;-) -- Ton -- http://mail.python.org/mailman/listinfo/python-list
pyparsing frames and tweens - take 2
Paul,
> frame = Literal("#")
> tween = Word("-") # that is, it is a "word" composed of 1 or more -'s
> copy = Literal("=")
> blank = Literal("_")
>
> animation = OneOrMore((frame + Optional(
> (tween + FollowedBy(frame)) |
> OneOrMore(copy | blank) ) ) )
I found that this form insists on having a # in char 0. How could it be
changed to take a bunch of blanks before the first frame?
# ?
I have tried:
animation = OneOrMore(
Optional ( blank | frame ) +
Optional( (tween + FollowedBy(frame) ) | OneOrMore(copy | blank) )
)
And permutations thereof, but it goes into a black hole.
\d
--
http://mail.python.org/mailman/listinfo/python-list
Re: how does google search in phrase
On Nov 5, 7:14 am, Jeff <[EMAIL PROTECTED]> wrote: > Here is a detailed explanation: > > http://www.google.com/technology/pigeonrank.html Ha ha... Hilarious. -- http://mail.python.org/mailman/listinfo/python-list
Re: Downloading file from cgi application
Store the file in a database. When an authorized user clicks the
link, send the proper headers ('Content-Type: application/pdf') and
then print the file.
--
http://mail.python.org/mailman/listinfo/python-list
Re: achieving performance using C/C++
On Nov 5, 8:51 am, Filip Wasilewski <[EMAIL PROTECTED]> wrote: > On Nov 5, 7:40 am, sandipm <[EMAIL PROTECTED]> wrote:> I did fair amount of > programming in python but never used c/c++ as > > mentioned below. > > any good tutorials for using C/C++ to optimize python codebase for > > performance? > > how widely do they use such kind of mixed coding practices? > > [...] > > Since you are fluent in Python I also suggest you to start with > Pyrex[1]/Cython[2]. This will let you to express your ideas more > naturally (in a Python-based language) and interface with C code base > without delving much into reference counting, manual parameters > conversion and low-level exception handling. > > You will find some tutorials and links to resources and mailing lists > on the projects websites, and if you specify your problem a bit more > then probably someone will be able to give you more precise > references. > > For alternatives take a look at [3] and [4]. Try also scanning the > Python Package Index[5] for 'binding', 'wrapper', 'lib' or 'pyrex' > keywords or browse for C/C++ Programming Language category as this > will return some examples of Python extensions. > > [1]http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ > [2]http://www.cython.org/ > [3]http://www.python.org/doc/faq/extending/#writing-c-is-hard-are-there-... > [4]http://docs.python.org/lib/module-ctypes.html > [5]http://pypi.python.org > > fw You might be interested also in ShedSkin. It is a python to c++ compiler, and it lets you write extension modules in a restricted subset of python that get automatically translated to c++. It's still a work in progress although very usable in its current state (and extremely easy to use). Its main advantage, compared to Pyrex, is that you don't need to know c or c++ at all to use it. Pyrex requires some knowledge about c and its data types in order to take advantage of its capabilities. On the other hand, with shedskin you just code in python (getting rid of its most dynamic features), and this code gets automatically compiled to a c++ extension module, directly usable from cpython. Check it out: http://mark.dufour.googlepages.com/ Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: achieving performance using C/C++
http://artfulcode.nfshost.com/files/extending_python_with_pyrex.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Downloading file from cgi application
sophie_newbie wrote: > Hi, > > I'm writing a cgi application in Python that generates a PDF file for > the user and then allows them to download that file. Currently I'm > just writing the PDF file to the 'htdocs' directory and giving the > user a link to this file to download it. But the problem is that > another user could simply come along and download a file that isn't > their file by typing the address into the address bar. I don't want to > delete the file after it is downloaded either because I'd like the > user to be able to download it again if necessary. Is there any way > around this problem? If the user needs to be authenticated, yes. Just encode the username in the pdf-name (on the FS that is, what name you give the downloaded file is unrelated). Then just allow to download the pdf by a user with the right name. Diez -- http://mail.python.org/mailman/listinfo/python-list
Library package import question
Hello, I have a python library package 'Foo', which contains alot of submodules: Foo/: __init__.py module1.py: class Bar() class Hmm() module2.py class Bee() class Wax() module3.py etc etc To prevent namespace pollution, I want to import and use this library in the following way: import Foo (...) t = Foo.module2.Bee() To accomplish this, I put explicit imports in __init__.py: import module1 import module2 import module3 what Im wondering about, is if its a more refined way of doing this, as the explicit imports now need to be manually maintained if the library grows. I've tried to use __all__, but this only seems to work with "from Foo import *" and it causes modules to be imported directly into the namespace of course. Thanks for input. -Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: how does google search in phrase
[EMAIL PROTECTED] wrote: > hi my friends; > google can searching in phrase but it is imposible. it have a lot of > page in data base and quadrillions sentence it can't search in > fulltxt all of them .it need a super algorithm. ı need the algorithm > now. if you have a idea ,pls share to me use pylucene or similar stuff. It can do that for you. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Downloading file from cgi application
You could also just store the files outside of the document root if
you don't want to worry about a database. Then, as Jeff said, just
print the proper Content-Type header and print the file out.
On Nov 5, 2007, at 8:26 AM, Jeff wrote:
> Store the file in a database. When an authorized user clicks the
> link, send the proper headers ('Content-Type: application/pdf') and
> then print the file.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
On 5 Nov., 04:42, "D.Hering" <[EMAIL PROTECTED]> wrote: > On Nov 3, 9:02 pm, Jens <[EMAIL PROTECTED]> wrote: > > > > > I'm starting a project indatamining, and I'm considering Python and > > Java as possible platforms. > > > I'm conserned by performance. Most benchmarks report that Java is > > about 10-15 times faster than Python, and my own experiments confirms > > this. I could imagine this to become a problem for very large > > datasets. > > > How good is the integration with MySQL in Python? > > > What about user interfaces? How easy is it to use Tkinter for > > developing a user interface without an IDE? And with an IDE? (which > > IDE?) > > > What if I were to use my Python libraries with a web site written in > > PHP, Perl or Java - how do I intergrate with Python? > > > I really like Python for a number of reasons, and would like to avoid > > Java. > > > Sorry - lot of questions here - but I look forward to your replies! > > All of my programming is data centric. Data mining is foundational > there in. I started learning computer science via Python in 2003. I > too was concerned about it's performance, especially considering my > need for literally trillions of iterations of financial data tables > with mathematical algorithms. > > I then leaned C and then C++. I am now coming home to Python realizing > after my self-eduction, that programming in Python is truly a pleasure > and the performance is not the concern I first considered to be. > Here's why: > > Python is very easily extended to near C speed. The Idea that FINALLY > sunk in, was that I should first program my ideas in Python WITHOUT > CONCERN FOR PERFOMANCE. Then, profile the application to find the > "bottlenecks" and extend those blocks of code to C or C++. Cython/ > Pyrex/Sip are my preferences for python extension frameworks. > > Numpy/Scipy are excellent libraries for optimized mathematical > operations. Pytables is my preferential python database because of > it's excellent API to the acclaimed HDF5 database (used by very many > scientists and government organizations). > > As for GUI framework, I have studied Qt intensely and would therefore, > very highly recommend PyQt. > > After four years of intense study, I can say that with out a doubt, > Python is most certainly the way to go. I personally don't understand > why, generally, there is any attraction to Java, though I have yet to > study it further. Thanks a lot! I agree, Python is a pleasure to program in. So what you're saying is, don't worry about performance when you start coding, but use profiling and optimization in C/C++. Sounds reasonable. It's been 10 years ago since I've done any programming in C ++, so I have to pick up on that soon I guess. I've used NumPy for improving my K-Means algorithm, and it now runs 33% faster than "pure" Python. I guess it could be improved upon further. I will have a look at PyQt! -- http://mail.python.org/mailman/listinfo/python-list
Re: Downloading file from cgi application
On Nov 5, 1:50 pm, Jeff McNeil <[EMAIL PROTECTED]> wrote:
> You could also just store the files outside of the document root if
> you don't want to worry about a database. Then, as Jeff said, just
> print the proper Content-Type header and print the file out.
>
> On Nov 5, 2007, at 8:26 AM, Jeff wrote:
>
> > Store the file in a database. When an authorized user clicks the
> > link, send the proper headers ('Content-Type: application/pdf') and
> > then print the file.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
Thanks alot, you guys sure know your stuff!
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyObjC with Xcode 3.0 Leopard
flyfree wrote: > I got an error during making a python application with xcode 3.0 in OS > X Leopard. > > (KeyError: 'NSUnknownKeyException - [ > valueForUndefinedKey:]: this class is not key value coding-compliant > for the key calculatedMean.') > > The application is a simple example of how to use the PyObjC with > xcode 2.0. > http://developer.apple.com/cocoa/pyobjc.html > > Could you give any hint to start to dig into it? > The PythonMac or PyObjc lists are probably a better place to ask this kind of question. -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: pyparsing frames and tweens - take 2
Donn - The exception you posted is from using an old version of pyparsing. You can get the latest from SourceForge - if you download the Windows binary install, please get the docs package too. It has a full doc directory (generated with epydoc), plus example scripts for a variety of applications. There is also an e-book available from O'Reilly that just came out in early October. To add an optional lead-in of one or more blanks,just change animation from: animation = OneOrMore((frame + Optional( (tween + FollowedBy(frame)) | OneOrMore(copy | blank) ) ) ) to: animation = Optional(OneOrMore(blank)) + \ OneOrMore((frame + Optional( (tween + FollowedBy(frame)) | OneOrMore(copy | blank) ) ) ) I modified your test, and there were no problems parsing strings with and without the leading '_'s. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
httplib.HTTPSConnection with timeout support (pyton 2.5.1)
Hi, I am using a HTTPS connection to invoke a cgi-script. I want to use a timeout between the sending the request and receiving the response, so what I want to do is when the request is send, the client should wait for a specified time, drop the connection and then do some thing else. I found out that the timout should work on HTTPS connection (python 2.5), and thus tried to use it, but that does not seems to work. The cgi-script receives the request, do some work, and returns the response, but not within the "timelimit" the client wants, and the timeout set for the HTTPS conncetion does not apply at all. Could be becasue the timeout is only used on the (TCP/IP) connection and not the request/response communication? Is there a way to use timeout as the way I want to (between sending the request and receiving the response)? Thanks.. /Omar -- http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
On Nov 3, 9:02 pm, Jens <[EMAIL PROTECTED]> wrote: > How good is the integration with MySQL in Python? I think it's very good. However, I'm not sure how good SQL really is for data mining, depending on what you mean by that. Please have a look at nucular for this kind of thing -- I've advertised it as a "full text search engine" but the intended use is close to some varieties of data mining. http://nucular.sourceforge.net/ The mondial demo is the closest thing to data mining currently live: http://www.xfeedme.com/nucular/mondial.py/go?FREETEXT=hol If you find that you need some functionality that is missing, it may be easy to add. Let me know. For example the underlying indexing methodology can be manipulated in many clever ways to get different performance characteristics. -- Aaron Watters === When at first you don't succeed give up and blame your parents. -- seen on a tee shirt -- http://mail.python.org/mailman/listinfo/python-list
Re: Descriptors and side effects
[EMAIL PROTECTED] wrote: > Hello everyone, > > I'm trying to do seemingly trivial thing with descriptors: have > another attribute updated on dot access in object defined using > descriptors. [snip] > A setter function should have updated self.l just like it updated > self.s: > > def __set__(self, obj, val): > self.s=val > self.l=len(val) > print "setting value:", self.s, "length:", self.l > > Yet it didn't happen. > [snip] I noticed that Python will block all attribute overrides (either via __dict__ through setattr) if the property has a __set__ method. The standard property has this method and there is no way that I can find to defeat it. So, here is what I use: class ConstProperty(object): """ Provides a property that keeps its return value. The function will only be called on the first access. After that the same value can be used over and over again with no function call penalty. If the cached value needs to be cleared, simply del the attribute. >>> class MyClass(object): ... def __init__(self, x): ... self.x = x ... @ConstProperty ... def y(self): ... print "HERE" ... return self.x ** 2 ... >>> obj = MyClass(5) >>> obj.y HERE 25 >>> obj.y 25 """ def __init__(self, fn): self.fn = fn def __get__(self, target, cls=None): if target is None: return self.fn # Helps pydoc else: obj = self.fn(target) setattr(target, self.fn.__name__, obj) return obj This is a little different than what you originally posted, but hopefully it is close enough to be helpful. Cheers! Rich -- http://mail.python.org/mailman/listinfo/python-list
Python thinks file is empty
I am writing a file in python with writelines
f = open('/home/john/myfile',"w")
f.writelines("line1\n")
f.writelines("line2\n")
f.close()
But whenever I try to do anything with the file in python it finds no
data. I am trying ftp, copying the file...the resultant file is always
0 bytes, although if I look at the original file on the unix command
line, its fine
e.g.
shutil.copyfile('/home/john/myfile', '/home/john/myfile2')
Any ideas what the problem is?
--
http://mail.python.org/mailman/listinfo/python-list
Re: pyparsing frames and tweens - take 2
Here is a first cut at processing the parsed objects, given a list of
Property objects representing the frames at each '#':
class Property(object):
def __init__(self,**kwargs):
self.__dict__.update(kwargs)
def copy(self):
return Property(**self.__dict__)
@staticmethod
def tween(prev,next,n,i):
dt = 1.0/(n+1)
x = prev.x + (next.x-prev.x)*dt*(i+1)
y = prev.y + (next.y-prev.y)*dt*(i+1)
r = prev.r + (next.r-prev.r)*dt*(i+1)
g = prev.g + (next.g-prev.g)*dt*(i+1)
b = prev.b + (next.b-prev.b)*dt*(i+1)
a = prev.a + (next.a-prev.a)*dt*(i+1)
return Property(x=x,y=y,r=r,g=g,b=b,a=a)
@staticmethod
def makeBlank():
return Property(x=0,y=0,r=0,g=0,b=0,a=0)
def __repr__(self):
return "Property(x=%(x).3f, y=%(y).3f, r=%(r).3f, g=%(g).3f, b=
%(b).3f, a=%(a).3f)" % self.__dict__
def makeAllFrames(propFrameList, animationList):
ret = []
propFrameIndex = 0
for animIndex,animObj in enumerate(animationList):
if isinstance(animObj, Prop):
ret.append( propFrameList[propFrameIndex] )
propFrameIndex += 1
if isinstance(animObj, Blank):
ret.append( Property.makeBlank() )
if isinstance(animObj, CopyPrevious):
ret.append( ret[-1].copy() )
if isinstance(animObj, Tween):
# compute delta x,y,r,g,b,a between prev frame and next
frame
prev = propFrameList[propFrameIndex-1]
next = propFrameList[propFrameIndex]
numFrames = animObj.tweenLength
print `prev`, `next`
tweens = [ Property.tween(prev,next,numFrames,i) for i in
range(numFrames) ]
ret += tweens
return ret
prop1 = Property(x=10,y=10,r=1,g=1,b=1,a=0)
prop2 = Property(x=20,y=10,r=0,g=0,b=1,a=1)
prop3 = Property(x=10,y=100,r=1,g=1,b=1,a=1)
prop4 = Property(x=100,y=200,r=1,g=1,b=1,a=1)
propFrames = [ prop1, prop2, prop3, prop4 ]
allFramesList = makeAllFrames( propFrames, animation.parseString("#---
#--#===_#") )
from pprint import pprint
pprint( allFramesList )
Gives:
[Property(x=10.000, y=10.000, r=1.000, g=1.000, b=1.000, a=0.000),
Property(x=12.500, y=10.000, r=0.750, g=0.750, b=1.000, a=0.250),
Property(x=15.000, y=10.000, r=0.500, g=0.500, b=1.000, a=0.500),
Property(x=17.500, y=10.000, r=0.250, g=0.250, b=1.000, a=0.750),
Property(x=20.000, y=10.000, r=0.000, g=0.000, b=1.000, a=1.000),
Property(x=16.667, y=40.000, r=0.333, g=0.333, b=1.000, a=1.000),
Property(x=13.333, y=70.000, r=0.667, g=0.667, b=1.000, a=1.000),
Property(x=10.000, y=100.000, r=1.000, g=1.000, b=1.000, a=1.000),
Property(x=10.000, y=100.000, r=1.000, g=1.000, b=1.000, a=1.000),
Property(x=10.000, y=100.000, r=1.000, g=1.000, b=1.000, a=1.000),
Property(x=10.000, y=100.000, r=1.000, g=1.000, b=1.000, a=1.000),
Property(x=0.000, y=0.000, r=0.000, g=0.000, b=0.000, a=0.000),
Property(x=100.000, y=200.000, r=1.000, g=1.000, b=1.000, a=1.000)]
-- Paul
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
On Nov 5, 1:51 pm, Jens <[EMAIL PROTECTED]> wrote: > On 5 Nov., 04:42, "D.Hering" <[EMAIL PROTECTED]> wrote: > > > On Nov 3, 9:02 pm, Jens <[EMAIL PROTECTED]> wrote: > > > I then leaned C and then C++. I am now coming home to Python realizing > > after my self-eduction, that programming in Python is truly a pleasure > > and the performance is not the concern I first considered to be. > > Here's why: > > > Python is very easily extended to near C speed. The Idea that FINALLY > > sunk in, was that I should first program my ideas in Python WITHOUT > > CONCERN FOR PERFOMANCE. Then, profile the application to find the > > "bottlenecks" and extend those blocks of code to C or C++. Cython/ > > Pyrex/Sip are my preferences for python extension frameworks. > > > Numpy/Scipy are excellent libraries for optimized mathematical > > operations. Pytables is my preferential python database because of > > it's excellent API to the acclaimed HDF5 database (used by very many > > scientists and government organizations). > > So what you're saying is, don't worry about performance when you start > coding, but use profiling and optimization in C/C++. Sounds > reasonable. It's been 10 years ago since I've done any programming in C > ++, so I have to pick up on that soon I guess. "Premature optimization is the root of all evil", to quote a famous person. And he's right, as most people working larger codes will confirm. As for pytables: it is the most elegant programming interface for HDF on any platform that I've encountered so far. Most other platforms stay close the HDF5 library C-interface, which is low-level, and quite complex. PyTables was written with the end-user in mind, and it shows. One correction though: PyTables is not a database: it is a storage for (large) arrays, datablocks that you don't want in a database. Use a database for the metadata to find the right file and field within that file. Keep in mind though that I mostly work with externally created HDF-5 files, not with files created in pytables. PyTables Pro has an indexing feature which may be helpful for datamining (if you write the hdf-5 files from python). Maarten -- http://mail.python.org/mailman/listinfo/python-list
Re: Low-overhead GUI toolkit for Linux w/o X11?
On Nov 3, 2007 6:06 PM, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2007-11-03, David Bolen <[EMAIL PROTECTED]> wrote: > > Grant Edwards <[EMAIL PROTECTED]> writes: > > > >> I'm looking for GUI toolkits that work with directly with the > >> Linux frambuffer (no X11). It's an embedded device with > >> limited resources, and getting X out of the picture would be a > >> big plus. > > > > Sounds like a reasonably modern "embedded" system since traditionally > > neither X (nor Python) would likely have even been plausible in such > > environments. > > Yes, it's "modern" enough to run Linux/X11 -- horsepower-wise > it's sort of in the PDA class of devices. wxWidgets has been > tried, but it's pretty sluggish. Hence the search for something > a littler lighter weight. Using Python is probably going to be > a little bit of a stretch, but using open-source libraries and > something like Python for the application langauge seems to be > an important part of the business model. > There's a DFB port of wx, although I'm not sure how much attention it's received lately. I know it's been actually used for at least one application. Gtk can also run directly on a framebuffer - that's what openmoko does, for example. > > Depending on the higher level GUI functionality you require > > That's still a bit up in the air. Routines to render text > would be nice, as would sprite graphics. I don't think text > entry or much in the way of windowing is required. > Sounds like a full scale widget toolkit is quite a bit heavier than you need, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python thinks file is empty
On Nov 5, 9:19 am, loial <[EMAIL PROTECTED]> wrote:
> I am writing a file in python with writelines
>
> f = open('/home/john/myfile',"w")
> f.writelines("line1\n")
> f.writelines("line2\n")
> f.close()
>
> But whenever I try to do anything with the file in python it finds no
> data. I am trying ftp, copying the file...the resultant file is always
> 0 bytes, although if I look at the original file on the unix command
> line, its fine
>
> e.g.
>
> shutil.copyfile('/home/john/myfile', '/home/john/myfile2')
>
> Any ideas what the problem is?
This works for me on Windows. I can open the file I create in notepad
and it has the correct text within it. I also tried using shutil to
copy it and that worked too.
How are you opening the file in Python? If you open it using the 'w'
flag, it'll just erase the file...
Mike
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python thinks file is empty
loial wrote:
> I am writing a file in python with writelines
>
> f = open('/home/john/myfile',"w")
> f.writelines("line1\n")
> f.writelines("line2\n")
> f.close()
>
> But whenever I try to do anything with the file in python it finds no
> data. I am trying ftp, copying the file...the resultant file is always
> 0 bytes, although if I look at the original file on the unix command
> line, its fine
>
> e.g.
>
> shutil.copyfile('/home/john/myfile', '/home/john/myfile2')
>
> Any ideas what the problem is?
A failure to copy/paste the lines as you had them? Or perhaps
accessing the file before it's been closed/flushed? Or perhaps
you're opening it in write-mode after you've closed the file
(thus overwriting your content with a blank file)?
As shown in the below session, it works for me:
[EMAIL PROTECTED]:~/tmp$ python
Python 2.4.4 (#2, Apr 5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> f = open('test.txt', 'w')
>>> f.writelines('hello\n')
>>> f.writelines('world\n')
>>> f.close()
>>> import shutil
>>> shutil.copyfile('test.txt', 'test2.txt')
>>>
[EMAIL PROTECTED]:~/tmp$ cat test.txt
hello
world
[EMAIL PROTECTED]:~/tmp$ cat test2.txt
hello
world
#
You may also want to use f.write() rather than f.writelines()
which seems to be your usage. f.writelines() is used for writing
an iterable of strings. Thus, it would be used something like
this trivial example:
f.writelines(['hello\n', 'world\n'])
To confuse matters, it happens to work in your example, because a
string is an iterable that returns each character in that string
as the result, so code like this
f.writelines('hello\n')
is effectively doing something like this
f.write('h')
f.write('e')
f.write('l')
f.write('l')
f.write('o')
f.write('\n')
(unless writelines is optimized to smarten up the code here)
-tkc
--
http://mail.python.org/mailman/listinfo/python-list
How can i find the form name without "nr=0"
Im using mechanize method for retrieving the form so that i may log into it. I need to find a way to get the form name. Its not listed anywhere in the html source.The reason i need to do this is because im tryin not to use the for loop below. Someone told me that the form name should be listed in the 'print form' portion of the codes output. I dont believe the form name is listed there also. Any ideas/help would be great. Thank you in advance for your time. for form in self._br.forms(): print form self._br.select_form(nr=0) self._br['username'] = Crawler.usrname self._br['password'] = line.strip() response=self._br.submit() if 'incorrect' in response.read(): print 'password incorrect =', line.strip() this is the output of 'print form' https://somesite.com/login.html application/x-www-form- urlencoded =Secure Login) (readonly)> > -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i find the form name without "nr=0"
scripteaze wrote: > Im using mechanize method for retrieving the form so that i may log > into it. I need to find a way to get the form name. Its not listed > anywhere in the html source.The reason i need to do this is because im > tryin not to use the for loop below. Someone told me that the form > name should be listed in the 'print form' portion of the codes output. > I dont believe the form name is listed there also. Any ideas/help > would be great. Thank you in advance for your time. > > for form in self._br.forms(): > print form > self._br.select_form(nr=0) > self._br['username'] = Crawler.usrname > self._br['password'] = line.strip() > response=self._br.submit() > if 'incorrect' in response.read(): > print 'password incorrect =', line.strip() How do you expect the form to be named if there is no name given in the HTML source? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python launcher not working on Mac after Leopard upgrade?
On Nov 3, 7:57 am, André <[EMAIL PROTECTED]> wrote: > I just installed Leopard on my Mac. I already was using Python 2.5. > I can run a Python script from a terminal window by typing "python > script.py" as one would expect ... but not using the Python launcher > either directly or indirectly (by double clicking on a Python icon). > Has anyone else observed this and, more importantly, found a fix for > this problem? > > André My guess is the environmental settings have changed somehow. You may be able to edit the shortcut's properties somehow to make it work, but I don't have a Mac, so I can't say for sure. Reinstalling the main Python distro would probably fix the issue. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding GNU Readline after installation?
> > I really just want to get my "up arrow" history working... > > Google for "rlwrap". Thanks for the rlwrap tip - much easier than reinstalling Python (for the short term). For anyone interested, I installed it and put this in my .bashrc file: alias python='rlwrap python' Now I have my up-arrow history functionality. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Descriptors and side effects
Rich Harkins a écrit :
> [EMAIL PROTECTED] wrote:
>> Hello everyone,
>>
>> I'm trying to do seemingly trivial thing with descriptors: have
>> another attribute updated on dot access in object defined using
>> descriptors.
>
> [snip]
>
>> A setter function should have updated self.l just like it updated
>> self.s:
>>
>> def __set__(self, obj, val):
>> self.s=val
>> self.l=len(val)
>> print "setting value:", self.s, "length:", self.l
>>
>> Yet it didn't happen.
>>
> [snip]
>
> I noticed that Python will block all attribute overrides (either via
> __dict__ through setattr) if the property has a __set__ method.
It doesn't "block", it controls access to... Of course, if the __set__
method is a no-op, then nothing will happen.
> The
> standard property has this method and there is no way that I can find to
> defeat it.
"defeat" ? Why don't you just pass the appropriate fset function to
property ?
> So, here is what I use:
>
> class ConstProperty(object):
> """
> Provides a property that keeps its return value. The function will
> only be called on the first access. After that the same value can
> be used over and over again with no function call penalty. If the
> cached value needs to be cleared, simply del the attribute.
>
> >>> class MyClass(object):
> ... def __init__(self, x):
> ... self.x = x
> ... @ConstProperty
> ... def y(self):
> ... print "HERE"
> ... return self.x ** 2
> ...
> >>> obj = MyClass(5)
> >>> obj.y
> HERE
> 25
> >>> obj.y
> 25
> """
>
> def __init__(self, fn):
> self.fn = fn
>
> def __get__(self, target, cls=None):
> if target is None:
> return self.fn# Helps pydoc
> else:
> obj = self.fn(target)
> setattr(target, self.fn.__name__, obj)
> return obj
>>> m = MyClass(5)
>>> m.__dict__
{'x': 5}
>>> m.y
HERE
25
>>> m.__dict__
{'y': 25, 'x': 5}
>>> m.x = 42
>>> m.y
25
>>> m.__dict__
{'y': 25, 'x': 42}
>>>
I'm sorry, but this looks like a very complicated way to do a simple thing:
class MySimpleClass(object):
def __init__(self, x):
self.x = x
self.y = x ** 2
--
http://mail.python.org/mailman/listinfo/python-list
Re: Low-overhead GUI toolkit for Linux w/o X11?
On 2007-11-05, Chris Mellon <[EMAIL PROTECTED]> wrote: >> Yes, it's "modern" enough to run Linux/X11 -- horsepower-wise >> it's sort of in the PDA class of devices. wxWidgets has been >> tried, but it's pretty sluggish. Hence the search for >> something a little lighter weight. Using Python is probably >> going to be a little bit of a stretch, but using open-source >> libraries and something like Python for the application >> langauge seems to be an important part of the business model. > > There's a DFB port of wx, One where wx draws it's own widgets? I hadn't found that. I'll have to take a look at that as well. > although I'm not sure how much attention it's received lately. > I know it's been actually used for at least one application. > Gtk can also run directly on a framebuffer - that's what > openmoko does, for example. Yup, I just found the GtkFB project yesterday. That might be an option as well. Persumably one could run wxWidgets on top of that -- I'm not sure if the sluggishness of the wxWidgets based stuff was due to wx/gtk or X11 (or a combination of both). >>> Depending on the higher level GUI functionality you require >> >> That's still a bit up in the air. Routines to render text >> would be nice, as would sprite graphics. I don't think text >> entry or much in the way of windowing is required. > > Sounds like a full scale widget toolkit is quite a bit heavier > than you need, though. Probably. The only UI input device is a set a half-dozen hard buttons next to the display, so a lot of the mouse/keyboard dependant features in GUI toolkits won't be of any benefit. -- Grant Edwards grante Yow! HUGH BEAUMONT died at in 1982!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Poor python and/or Zope performance on Sparc
On Nov 3, 2:35 pm, joa2212 <[EMAIL PROTECTED]> wrote: > Result: Almost even worse. The application is not scaling at all. > Every time you start a request it is hanging around on one cpu and is > devouring it at about 90-100% load. The other 31 CPUs which are shown > in "mpstat" are bored at 0% load. > Like others already pointed out: Performance is going to suffer if you run something that's single-threaded on a T1000. We've been using the T1000 for a while (but not for python) and it's actually really fast. The performance is way better than the 8 cores imply. In fact, it'll do work that's not too far from 32 times the work of a single thread. Of course, it all depends on what your application is like, but try experimenting a bit with parallelism. Try changing from 4 up to 64 parallel working processes to see what kind of effects you'll get. I'm guessing that whatever caching of persistent data you can do will be a good thing as well as the disk might end up working really hard. -- http://mail.python.org/mailman/listinfo/python-list
wxPython ListCtrl
Hello,
How can I Insert image with string in ListCtrl with this example:
# Import ftputil module - like ftplib
from ftputil import FTPHost
# Create connection
ftp=FTPHost("ftp.someserver.com","user","password")
# LIST ALL FILES/FOLDERS ON SERVER
for item in ftp._dir("/"):
# Now check if item is file /folder
if item is file insert this image: wx.ART_NORMAL_FILE and if
the item is folder insert this image
wx.ART_FOLDER
...how can I do the same on server with GenericDirCtrl?
Regards,
Vedran
--
http://mail.python.org/mailman/listinfo/python-list
Re: How can i find the form name without "nr=0"
On Nov 5, 8:52 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > scripteaze wrote: > > Im using mechanize method for retrieving the form so that i may log > > into it. I need to find a way to get the form name. Its not listed > > anywhere in the html source.The reason i need to do this is because im > > tryin not to use the for loop below. Someone told me that the form > > name should be listed in the 'print form' portion of the codes output. > > I dont believe the form name is listed there also. Any ideas/help > > would be great. Thank you in advance for your time. > > > for form in self._br.forms(): > > print form > > self._br.select_form(nr=0) > > self._br['username'] = Crawler.usrname > > self._br['password'] = line.strip() > > response=self._br.submit() > > if 'incorrect' in response.read(): > > print 'password incorrect =', line.strip() > > How do you expect the form to be named if there is no name given in the HTML > source? > > Diez- Hide quoted text - > > - Show quoted text - Well, i wasnt sure if you could have a form without a form name, i was just thinking that it had one but maybe hidden and that i could retrieve it -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i find the form name without "nr=0"
> > Well, i wasnt sure if you could have a form without a form name, i was > just thinking that it had one but maybe hidden and that i could > retrieve it How hidden? HTML source is ... THE source. there is nothing hidden in there. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython ListCtrl
On Nov 5, 11:00 am, [EMAIL PROTECTED] wrote:
> Hello,
>
> How can I Insert image with string in ListCtrl with this example:
>
> # Import ftputil module - like ftplib
> from ftputil import FTPHost
> # Create connection
> ftp=FTPHost("ftp.someserver.com","user","password")
>
> # LIST ALL FILES/FOLDERS ON SERVER
> for item in ftp._dir("/"):
># Now check if item is file /folder
> if item is file insert this image: wx.ART_NORMAL_FILE and if
> the item is folder insert this image
> wx.ART_FOLDER
>
> ...how can I do the same on server with GenericDirCtrl?
>
> Regards,
> Vedran
I would recommend looking at the wxPython demo as it shows how to add
pictures to the listctrl there. You'll probably need to look at
wx.ArtProvider to get the correct syntax for using its images:
http://wxpython.org/docs/api/wx.ArtProvider-class.html
You might also find the wiki's entry on listctrls helpful:
http://wiki.wxpython.org/ListControls
Of course, it sounds like you're making your own FTP client, so I
would use one of the treectrl variants rather than a listctrl. See the
TreeListCtrl, the TreeMixin or the CustomTreeCtrl.
The demo also shows code for the GenericDirCtrl. See
http://www.wxpython.org/download.php
You may also find the wxPython user's group more helpful for wxPython
specific inquiries: http://www.wxpython.org/maillist.php
Mike
--
http://mail.python.org/mailman/listinfo/python-list
instance as a sequence
suppose i want to make foo.childNodes[bar] available as foo[bar] (while still providing access to the printxml/printprettyxml() functions and other functionality of dom/minidom instance). What is a good way to accomplish that? -- http://mail.python.org/mailman/listinfo/python-list
Re: Descriptors and side effects
Bruno Desthuilliers wrote:
[snip]
> I'm sorry, but this looks like a very complicated way to do a simple thing:
>
> class MySimpleClass(object):
>def __init__(self, x):
> self.x = x
> self.y = x ** 2
>
>
Sure, for the absurdly simplified case I posed as an example. ;)
Here's another:
class Path(tuple):
@ConstProperty
def pathstr(self):
print "DEBUG: Generating string"
return '/'.join(self)
def __add__(self, other):
if isinstance(other, tuple):
return Path(tuple.__add__(self, other))
else:
return Path(tuple.__add__(self, (other,)))
>>> ROOT = Path(())
>>> path = ROOT + 'x' + 'y' + 'z'
>>> path.pathstr
DEBUG: Generating string
/x/y/z
>>> path.pathstr
/x/y/z
Basically, you can use ConstProperty above for items you don't want to
calculate automatically, but only when someone actually WANTS it. After
it is applied, then the penalties for function call of the property and
the computation are wiped out once the second access is requested.
Now, in the original example, len() might be considered too little for
this use and should be just generated in the constructor "for free".
OTOH, that assumes that __len__ hasn't been overridden to do something
more complicated and time consuming. If the antecedent object is
static, and the derivative consequent is also static, then ConstProperty
works very well and shouldn't cost more on the first access than any
other built-in property function.
BTW, another use is to avoid creating lots of unnecessary objects for
free unless they are accessed. Another quickie example:
class Node(object):
hasChildList = False
hasAttributesDict = False
@ConstProperty
def children(self):
self.hasChildList = True
return []
@ConstProperty
def attributes(self):
self.hasAttributesDict = True
return {}
The extra class/object attributes can be used to test for whether the
associated objects were created. When used in a large tree, not
creating a lot of extra lists and dictionaries can save a lot of memory
and CPU as the children and attributes are not created or explored
unless they were manipulated.
Rich
--
http://mail.python.org/mailman/listinfo/python-list
Re: Descriptors and side effects
Bruno Desthuilliers wrote:
> Rich Harkins a écrit :
>> [EMAIL PROTECTED] wrote:
>>> Hello everyone,
>>>
>>> I'm trying to do seemingly trivial thing with descriptors: have
>>> another attribute updated on dot access in object defined using
>>> descriptors.
>> [snip]
>>
>>> A setter function should have updated self.l just like it updated
>>> self.s:
>>>
>>> def __set__(self, obj, val):
>>> self.s=val
>>> self.l=len(val)
>>> print "setting value:", self.s, "length:", self.l
>>>
>>> Yet it didn't happen.
>>>
>> [snip]
>>
>> I noticed that Python will block all attribute overrides (either via
>> __dict__ through setattr) if the property has a __set__ method.
>
> It doesn't "block", it controls access to... Of course, if the __set__
> method is a no-op, then nothing will happen.
>
>> The
>> standard property has this method and there is no way that I can find to
>> defeat it.
>
> "defeat" ? Why don't you just pass the appropriate fset function to
> property ?
>
>> So, here is what I use:
>>
>> class ConstProperty(object):
>> """
>> Provides a property that keeps its return value. The function will
>> only be called on the first access. After that the same value can
>> be used over and over again with no function call penalty. If the
>> cached value needs to be cleared, simply del the attribute.
>>
>> >>> class MyClass(object):
>> ... def __init__(self, x):
>> ... self.x = x
>> ... @ConstProperty
>> ... def y(self):
>> ... print "HERE"
>> ... return self.x ** 2
>> ...
>> >>> obj = MyClass(5)
>> >>> obj.y
>> HERE
>> 25
>> >>> obj.y
>> 25
>> """
>>
>> def __init__(self, fn):
>> self.fn = fn
>>
>> def __get__(self, target, cls=None):
>> if target is None:
>> return self.fn # Helps pydoc
>> else:
>> obj = self.fn(target)
>> setattr(target, self.fn.__name__, obj)
>> return obj
>
>
>
> >>> m = MyClass(5)
> >>> m.__dict__
> {'x': 5}
> >>> m.y
> HERE
> 25
> >>> m.__dict__
> {'y': 25, 'x': 5}
> >>> m.x = 42
> >>> m.y
> 25
> >>> m.__dict__
> {'y': 25, 'x': 42}
> >>>
>
>
> I'm sorry, but this looks like a very complicated way to do a simple thing:
>
> class MySimpleClass(object):
>def __init__(self, x):
> self.x = x
> self.y = x ** 2
>
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: instance as a sequence
[EMAIL PROTECTED] wrote: > suppose i want to > make foo.childNodes[bar] available as foo[bar] > (while still providing access to the printxml/printprettyxml() > functions > and other functionality of dom/minidom instance). > > What is a good way to accomplish that? Using element-tree. That already gives you the iterable and __getitem__-functionality. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: instance as a sequence
On Nov 5, 11:32 am, [EMAIL PROTECTED] wrote: > suppose i want to > make foo.childNodes[bar] available as foo[bar] > (while still providing access to the printxml/printprettyxml() > functions > and other functionality of dom/minidom instance). > > What is a good way to accomplish that? define __getitem__(self, index) method on foo's class, and have the method return foo.childNodes[index]. If you don't have access to foo's class, then just do this: foo.__getitem__ = delegatingGetItemMethod and define delegatingGetItemMethod as described above. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: instance as a sequence
On Nov 5, 9:40 am, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Nov 5, 11:32 am, [EMAIL PROTECTED] wrote: > > > suppose i want to > > make foo.childNodes[bar] available as foo[bar] > > (while still providing access to the printxml/printprettyxml() > > functions > > and other functionality of dom/minidom instance). > > > What is a good way to accomplish that? > > define __getitem__(self, index) method on foo's class, and have the > method return foo.childNodes[index]. > > If you don't have access to foo's class, then just do this: > > foo.__getitem__ = delegatingGetItemMethod > > and define delegatingGetItemMethod as described above. > could i plug it into the (exiting) xml.dom.minidom class rather than the instance? -- http://mail.python.org/mailman/listinfo/python-list
Re: (MAC) CoreGraphics module???
David C. Ullrich wrote: > On Sun, 04 Nov 2007 15:56:21 -0600, Robert Kern > <[EMAIL PROTECTED]> wrote: > >> David C. Ullrich wrote: >>> On Fri, 02 Nov 2007 14:09:25 -0500, Robert Kern >>> <[EMAIL PROTECTED]> wrote: >>> David C. Ullrich wrote: > [???] Okay, which version of OS X do you have? In 10.3 and 10.4 it used to be here: /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/CoreGraphics.py I notice that in 10.5, it no longer exists, though. >>> Um, surely that doesn't mean that there's no CoreGraphics >>> available in 10.5? >> The CoreGraphics C library still exists, of course. The Python module they >> provided does not. > > Right - I was referring to the Python module. > > Why would they do such a thing? (Never mind, I don't > imagine you know.) Apple was using it in their fax software. I'm not sure they ever intended it to be used by people external to Apple, though. They certainly never documented it. I imagine they are no longer using it in their fax software. > Hmm, I saw somewhere the other day that PyObjC comes with 10.5. > Maybe that means there's no longer any point to a separate > CoreGraphics.py? No, they're different things. PyObjC does wrap a Cocoa drawing API, but that API does not cover nearly as much of the CoreGraphics API as CoreGraphics.py did. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
On 5 Nov., 16:29, Maarten <[EMAIL PROTECTED]> wrote: > On Nov 5, 1:51 pm, Jens <[EMAIL PROTECTED]> wrote: > "Premature optimization is the root of all evil", to quote a famous > person. And he's right, as most people working larger codes will > confirm. I guess I'll have to agree with that. Still, I would like to get some kind of indication of if it's a good idea to use NumPy from the start of the project - for example. It depends on the situation of course. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
Jens wrote: > On 5 Nov., 16:29, Maarten <[EMAIL PROTECTED]> wrote: >> On Nov 5, 1:51 pm, Jens <[EMAIL PROTECTED]> wrote: > >> "Premature optimization is the root of all evil", to quote a famous >> person. And he's right, as most people working larger codes will >> confirm. > > I guess I'll have to agree with that. Still, I would like to get some > kind of indication of if it's a good idea to use NumPy from the start > of the project - for example. Yes. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
On 5 Nov., 16:29, Maarten <[EMAIL PROTECTED]> wrote: > As for pytables: it is the most elegant programming interface for HDF > on any platform that I've encountered so far. Most other platforms > stay close the HDF5 library C-interface, which is low-level, and quite > complex. PyTables was written with the end-user in mind, and it shows. > One correction though: PyTables is not a database: it is a storage for > (large) arrays, datablocks that you don't want in a database. Use a > database for the metadata to find the right file and field within that > file. Keep in mind though that I mostly work with externally created > HDF-5 files, not with files created in pytables. PyTables Pro has an > indexing feature which may be helpful for datamining (if you write the > hdf-5 files from python). > PyTables? Wow! Looks amazing - I'll have to try that out soon. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: __file__ vs __FILE__
On Nov 5, 1:07 am, sandipm <[EMAIL PROTECTED]> wrote: > interestingly... > I wanted to reuse this code so i wrote function in a file > > def getParentDir(): > import os > return os.path.dirname(os.path.abspath(__file__)) > > and called this function, in another file, its giving me parent > directory of file where this function is defined.? This is true. __file__ is defined at the module level where the function is defined. > how to reuse this piece of code then? or am i doing something wrong? > You have a few choices. You could implement it wherever you need it which might actually be nice from a OO point of view. You could modify the function above to accept a parameter and operate on the __file__ attribute of that parameter. Or, you could use the inspect module to look at the stack and operate on the __file__ attribute of the caller. The first one is obvious to implement, although it will only apply to modules you have implemented. The second one I think someone has already posted a solution to. Here is how to implement the third one (this is also usable with a parameter). [code] import inspect import os def getpardir(obj=None): if obj is None: obj = inspect.stack()[1][0] return os.path.dirname(inspect.getfile(obj)) [/code] Some may choose to stay away from this sort of thing though, since inspecting the stack can tend to feel a bit like voo-doo. Passing a parameter is probably your best bet IMHO. Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
On Nov 4, 4:36 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > > > How good is the integration with MySQL in Python? > > Pretty good - but I wouldn't call MySQL a serious RDBMS. I would disagree with this, for this particular case. I think it's probably better than most other rdbms's for apps like data mining where you don't need transactional support, especially if you use the table implementations that don't support ACID transactions. -- Aaron Watters === http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=segmentation%20fault -- http://mail.python.org/mailman/listinfo/python-list
Re: (MAC) CoreGraphics module???
Robert Kern wrote: > David C. Ullrich wrote: >> On Sun, 04 Nov 2007 15:56:21 -0600, Robert Kern >> <[EMAIL PROTECTED]> wrote: >> >>> David C. Ullrich wrote: On Fri, 02 Nov 2007 14:09:25 -0500, Robert Kern <[EMAIL PROTECTED]> wrote: > David C. Ullrich wrote: >> [???] > Okay, which version of OS X do you have? In 10.3 and 10.4 it used to be > here: > /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/CoreGraphics.py > > I notice that in 10.5, it no longer exists, though. Um, surely that doesn't mean that there's no CoreGraphics available in 10.5? >>> The CoreGraphics C library still exists, of course. The Python module they >>> provided does not. >> Right - I was referring to the Python module. >> >> Why would they do such a thing? (Never mind, I don't >> imagine you know.) > > Apple was using it in their fax software. I'm not sure they ever intended it > to > be used by people external to Apple, though. Could be, > They certainly never documented it. cuz most of the stuff they include _is_ much better (ie at least somewhat) documented. Very sad. > I imagine they are no longer using it in their fax software. > >> Hmm, I saw somewhere the other day that PyObjC comes with 10.5. >> Maybe that means there's no longer any point to a separate >> CoreGraphics.py? > > No, they're different things. PyObjC does wrap a Cocoa drawing API, but that > API > does not cover nearly as much of the CoreGraphics API as CoreGraphics.py did. > -- http://mail.python.org/mailman/listinfo/python-list
Re: instance as a sequence
On Nov 5, 9:59 am, [EMAIL PROTECTED] wrote: > On Nov 5, 9:40 am, Paul McGuire <[EMAIL PROTECTED]> wrote: > > > On Nov 5, 11:32 am, [EMAIL PROTECTED] wrote: > > > > suppose i want to > > > make foo.childNodes[bar] available as foo[bar] > > > (while still providing access to the printxml/printprettyxml() > > > functions > > > and other functionality of dom/minidom instance). > > > > What is a good way to accomplish that? > > > define __getitem__(self, index) method on foo's class, and have the > > method return foo.childNodes[index]. > > > If you don't have access to foo's class, then just do this: > > > foo.__getitem__ = delegatingGetItemMethod > > > and define delegatingGetItemMethod as described above. > > could i plug it into the (exiting) xml.dom.minidom class rather than > the instance? If you want that type of functionality it is better to just create a new class, inherit from Document and use the new class. class MyDocument(xml.dom.minidom.Document): def __getitem__(self, index): #blah ... You could then do this: `xml.dom.minidom.Document = MyDocument', but changing the Document class itself, especially for such a trivial improvement is just confusing to whoever might be reading your code. Like another poster said, if you want a more convenient way to modify and read XML use ElementTree. minidom works the way it does because it it following a W3C specification. If you start modifying it for convenience you will 1. break the specification and 2. reinvent the wheel because there already exists more convenient means of accessing XML. Matt -- http://mail.python.org/mailman/listinfo/python-list
Thread Profiling
Are there any good thread profilers available that can profile a thread as it is running instead of after execution is completed? I would like to find a python class which looks at a currently running thread and if its memory exceeds a certain amount than kill it. Ideally I would like the program to track memory used not just by that thread, but by any threads or processes that it may spawn. If there isn't anything like that, then something that lets me set the maximum memory allowed to be allocated within a thread would be acceptable also. Thanks in advance, James Howard -- http://mail.python.org/mailman/listinfo/python-list
IDLE won't color code!
Please help! IDLE color codes only the shell, not the open files! How can I solve this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
Aaron Watters a écrit : > On Nov 4, 4:36 pm, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > >>>How good is the integration with MySQL in Python? >> >>Pretty good - but I wouldn't call MySQL a serious RDBMS. > > > I would disagree with this, for this particular case. > I think it's probably better > than most other rdbms's for apps > like data mining where you don't need > transactional support, Mmm... Yes, probably right. -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE won't color code!
On Nov 5, 12:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Please help! > IDLE color codes only the shell, not the open files! How can I solve > this? My first guess is that idle is opening files without the .py extension. If that isn't it, what operating system are you using? What version of python and idle are you using? James Howard -- http://mail.python.org/mailman/listinfo/python-list
Functions as Objects, and persisting values
Please help me understand the mechanics of the following behavior.
>>> def d():
header = 'I am in front of '
def e(something):
print header + something
return e
>>> f = d()
>>> f('this')
I am in front of this
>>> del(d)
>>> f('this')
I am in front of this
The way I understand it, function d is an object, as is e. However I
don't quite grok the exact relationship between e and d. Is e
considered to be a subclass of 'd', so that it has access to it's
parent's __dict__ object, in order to access the value of 'header'? Or
is this persistence managed in a different fashion?
--
http://mail.python.org/mailman/listinfo/python-list
Re: IDLE won't color code!
On Nov 5, 9:41 pm, JamesHoward <[EMAIL PROTECTED]> wrote: > On Nov 5, 12:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > Please help! > > IDLE color codes only the shell, not the open files! How can I solve > > this? > > My first guess is that idle is opening files without the .py > extension. If that isn't it, what operating system are you using? > What version of python and idle are you using? > > James Howard Thank you James, from the bottom of my heart :) Now I just need to get around to controlling pygame... -- http://mail.python.org/mailman/listinfo/python-list
Re: instance as a sequence
[EMAIL PROTECTED] a écrit :
> On Nov 5, 9:40 am, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
>>On Nov 5, 11:32 am, [EMAIL PROTECTED] wrote:
>>
>>
>>>suppose i want to
>>>make foo.childNodes[bar] available as foo[bar]
>>>(while still providing access to the printxml/printprettyxml()
>>>functions
>>>and other functionality of dom/minidom instance).
>>
>>>What is a good way to accomplish that?
>>
>>define __getitem__(self, index) method on foo's class, and have the
>>method return foo.childNodes[index].
>>
>>If you don't have access to foo's class, then just do this:
>>
>>foo.__getitem__ = delegatingGetItemMethod
>>
>>and define delegatingGetItemMethod as described above.
>>
>
> could i plug it into the (exiting) xml.dom.minidom class rather than
> the instance?
from xml.dom import minidom
minidom.Node.__getitem__ = lambda self, index: self.childNodes[index]
doc = minidom.parseString("")
doc[0]
=>
But ElementTree might be a better choice still...
--
http://mail.python.org/mailman/listinfo/python-list
Pydev 1.3.10 Released
Hi All, Pydev and Pydev Extensions 1.3.10 have been released Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev Extensions: - * Code-analysis: Doesn't report 'statement without effect' within list comprehension. * Context insensitive code completion: Shows contents of zips/eggs/jars * Go to definition: Working with zips/eggs/jars. Release Highlights in Pydev: -- * Symlinks supported in the system pythonpath configuration. * Egg/zip files are now supported. * The creation of a project in a non-default location is now allowed within the workspace * JDT used to get completions from jars (but referencing other java projects is still not supported). * Configuration of pythonpath allows multiple selection for removal. * Configuration of pythonpath allows multiple jars/zips to be added at once. * When configuring the pythonpath, the paths are sorted for selection. * The file extensions that pydev recognizes for python can now be customized. * Patch by Carl Robinson: Code-folding for elements such as for, try, while, etc. * Removed the go to next/previous problem annotation (Eclipse 3.3 already provides a default implementation for it). What is PyDev? --- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny -- Software Developer ESSS - Engineering Simulation and Scientific Software http://www.esss.com.br Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Functions as Objects, and persisting values
Falcolas schrieb:
> Please help me understand the mechanics of the following behavior.
>
def d():
> header = 'I am in front of '
> def e(something):
> print header + something
> return e
>
f = d()
f('this')
> I am in front of this
del(d)
f('this')
> I am in front of this
>
> The way I understand it, function d is an object, as is e. However I
> don't quite grok the exact relationship between e and d. Is e
> considered to be a subclass of 'd', so that it has access to it's
> parent's __dict__ object, in order to access the value of 'header'? Or
> is this persistence managed in a different fashion?
The "thing" you observe here is a called a closure. It consists of the
local variables surrounding e. So as long as you keep a reference to e,
you keep one to the variables of d itself.
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Re: Descriptors and side effects
Rich Harkins a écrit :
> Bruno Desthuilliers wrote:
> [snip]
>
>>I'm sorry, but this looks like a very complicated way to do a simple thing:
>>
>>class MySimpleClass(object):
>> def __init__(self, x):
>> self.x = x
>> self.y = x ** 2
>>
>>
>
>
> Sure, for the absurdly simplified case I posed as an example. ;)
>
> Here's another:
>
> class Path(tuple):
Ok, for an immutable type, it might eventually work.
> @ConstProperty
> def pathstr(self):
> print "DEBUG: Generating string"
> return '/'.join(self)
import os.path
help(os.path)
> def __add__(self, other):
> if isinstance(other, tuple):
> return Path(tuple.__add__(self, other))
> else:
> return Path(tuple.__add__(self, (other,)))
>
>
ROOT = Path(())
path = ROOT + 'x' + 'y' + 'z'
path.pathstr
>
> DEBUG: Generating string
> /x/y/z
>
path.pathstr
>
> /x/y/z
>>> p = Path(('home', 'bruno'))
>>> p += ['toto', 'tata']
>>> p.pathstr
DEBUG: Generating string
Traceback (most recent call last):
File "", line 1, in ?
File "/usr/tmp/python-8690chu", line 31, in __get__
File "/usr/tmp/python-8690chu", line 40, in pathstr
TypeError: sequence item 2: expected string, list found
>>>
> Basically, you can use ConstProperty above for items you don't want to
> calculate automatically, but only when someone actually WANTS it.
Which is easy to do with properties too.
> After
> it is applied, then the penalties for function call of the property and
> the computation are wiped out once the second access is requested.
Agreed. But I wouldn't use such a scheme for mutable types - which are
still the common case.
> Now, in the original example, len() might be considered too little for
> this use and should be just generated in the constructor "for free".
> OTOH, that assumes that __len__ hasn't been overridden to do something
> more complicated and time consuming. If the antecedent object is
> static, and the derivative consequent is also static,
You mean 'immutable', I assume...
> then ConstProperty
> works very well and shouldn't cost more on the first access than any
> other built-in property function.
>
> BTW, another use is to avoid creating lots of unnecessary objects for
> free unless they are accessed. Another quickie example:
>
> class Node(object):
> hasChildList = False
> hasAttributesDict = False
>
> @ConstProperty
> def children(self):
> self.hasChildList = True
> return []
>
> @ConstProperty
> def attributes(self):
> self.hasAttributesDict = True
> return {}
Hmm... Perhaps not such a bad idea after all !-)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python thinks file is empty
En Mon, 05 Nov 2007 12:57:15 -0300, Tim Chase
<[EMAIL PROTECTED]> escribió:
> To confuse matters, it happens to work in your example, because a
> string is an iterable that returns each character in that string
> as the result, so code like this
>
>f.writelines('hello\n')
>
> is effectively doing something like this
>
>f.write('h')
>f.write('e')
>f.write('l')
>f.write('l')
>f.write('o')
>f.write('\n')
>
> (unless writelines is optimized to smarten up the code here)
As of 2.5.1, it's not :(
writelines is perhaps one of the worst used functions in Python. It'b been
there for ages (since 1.5.2 at least) but a lot of people does not know it
even exists (and roll their own, *always* slower; map(f.write, lines)
appears to be the favorite spelling...) or, if they are aware of it, use
it wrongly as you pointed out above.
Perhaps some of them come from Delphi/Pascal, looking for something
similar to writeln, and writelines is the closest match...
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: Functions as Objects, and persisting values
[snip] > The "thing" you observe here is a called a closure. It consists of the > local variables surrounding e. So as long as you keep a reference to e, > you keep one to the variables of d itself. > > Diez More specifically though it keeps references to the requested variables only: def closed(): x = global_x y = "Y_VAR" def inner(): return y return inner class Destroyable(object): def __del__(self): print "DESTROYED" global_x = Destroyable() inner = closed() print inner() del global_x print inner() print "HERE" You will get: Y_VAR DESTROYED Y_VAR HERE If the entire dict of closed() was kept you would have seen: Y_VAR Y_VAR HERE DESTROYED Since closed hadn't been destroyed yet: thus there was only one reference remaining to global_x after closed() and inner() were called. Rich -- http://mail.python.org/mailman/listinfo/python-list
Python-URL! - weekly Python news and links (Nov 5)
QOTW: "I've just done my first serious work in Python/IDLE, a small dot pre-processor for software modeling diagrams and I am very enthused. It should be called Pytho; it has the positive qualities of Play-Do and Lego: you get ideas squishing it through your fingers and it snaps together nicely to build things." - Jonathan Cronin http://mail.python.org/pipermail/idle-dev/2007-November/002639.html "[R]esumable functions are a honking great idea." - Alan Kennedy Aspect programming and why it's not widely used in Python: http://groups.google.com/group/comp.lang.python/browse_thread/thread/af82d7fa8fdf5a28 "Statement coverage is the weakest measure of code coverage" http://groups.google.com/group/comp.lang.python/browse_thread/thread/e9f723a6287c783 Enjoy Colorado. Develop games. Learn Python: http://coloradogamedev.org/ Is pyparsing really a recursive descent parser? (mostly for lawyers...): http://groups.google.com/group/comp.lang.python/browse_thread/thread/acbb81ad2226777e Marshal vs pickle as a general serializer: http://groups.google.com/group/comp.lang.python/browse_thread/thread/c208159805798cda Where do they teach Python in academics courses in universities? http://groups.google.com/group/comp.lang.python/browse_thread/thread/64458d1e81573a16 http://catherinedevlin.blogspot.com/2007/11/python-at-mit.html Tcl and Python: Why is the former so widely used in electronics? Why not Python? http://groups.google.com/group/comp.lang.python/browse_thread/thread/8785a34470f2c183 Why isn't len a list method instead of a function (again!): http://groups.google.com/group/comp.lang.python/browse_thread/thread/edeb2f17720dc3da Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html Steve Bethard continues the marvelous tradition early borne by Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim Lesher of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/
Re: Descriptors and side effects
Bruno Desthuilliers wrote: > Which is easy to do with properties too. True enough. It's the caching of the return value that's the value add of course. ;) > >> After >> it is applied, then the penalties for function call of the property and >> the computation are wiped out once the second access is requested. > > Agreed. But I wouldn't use such a scheme for mutable types - which are > still the common case. > In many cases, yeah. Though I use a lot of immutable stuff in some of my pet projects and such. ConstProperty is definitely not meant as a replacement for property, only when something constant can be derived from something else constant, especially when the derivation is expensive. >> Now, in the original example, len() might be considered too little for >> this use and should be just generated in the constructor "for free". >> OTOH, that assumes that __len__ hasn't been overridden to do something >> more complicated and time consuming. If the antecedent object is >> static, and the derivative consequent is also static, > > You mean 'immutable', I assume... Yeah, that's probably the better term. [snip] Again, I've used it quite a bit for various things and it's worked well for the sort of thing the OP was requesting. Of course, your mileage may vary. :) Cheers! Rich PS: Sorry about the weird reposts. Thunderbird chaos. -- http://mail.python.org/mailman/listinfo/python-list
Re: Functions as Objects, and persisting values
Falcolas a écrit :
> Please help me understand the mechanics of the following behavior.
>
>
def d():
>
> header = 'I am in front of '
> def e(something):
> print header + something
> return e
>
>
f = d()
f('this')
>
> I am in front of this
>
del(d)
f('this')
>
> I am in front of this
>
> The way I understand it, function d is an object,
Right.
> as is e.
Right.
> However I
> don't quite grok the exact relationship between e and d.
>
> Is e
> considered to be a subclass of 'd',
Nope.
> so that it has access to it's
> parent's __dict__ object, in order to access the value of 'header'? Or
> is this persistence managed in a different fashion?
As Diez said, it's called a lexical closure. A lexical closure is a
function that captures and carries the lexical scope it was defined in
with it - it 'closes over' it's environnement. Each time you call d, it
returns a new function object (using the same code object) with a
different environnement. You'll find this environement in f.func_closure.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
Maarten <[EMAIL PROTECTED]> writes: > > "Premature optimization is the root of all evil", to quote a famous > person. And he's right, as most people working larger codes will > confirm. > But note that it's "premature optimization...", not "optimization..." :) -- http://mail.python.org/mailman/listinfo/python-list
dictionary viewer
-- http://mail.python.org/mailman/listinfo/python-list
>>> CIA Squashes Democracy in Pakistan <<
http://www.youtube.com/watch?v=BdB2r1ss5Wk http://www.jewwatch.com/ <- excellent source for well researched news on world events and the big movers of history -- http://mail.python.org/mailman/listinfo/python-list
Re: Python launcher not working on Mac after Leopard upgrade?
On Nov 5, 11:57 am, [EMAIL PROTECTED] wrote: > On Nov 3, 7:57 am, André <[EMAIL PROTECTED]> wrote: > > > I just installed Leopard on my Mac. I already was using Python 2.5. > > I can run a Python script from a terminal window by typing "python > > script.py" as one would expect ... but not using the Python launcher > > either directly or indirectly (by double clicking on a Python icon). > > Has anyone else observed this and, more importantly, found a fix for > > this problem? > > > André > > My guess is the environmental settings have changed somehow. You may > be able to edit the shortcut's properties somehow to make it work, but > I don't have a Mac, so I can't say for sure. Reinstalling the main > Python distro would probably fix the issue. > > Mike I had tried both ... with no success. Just a minor pain, but still... André -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i find the form name without "nr=0"
b> > Well, i wasnt sure if you could have a form without a form name, i was > > just thinking that it had one but maybe hidden and that i could > > retrieve it > > How hidden? HTML source is ... THE source. there is nothing hidden in there. > Is it possible then to have a form with no name and if so, how can i access this form -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary viewer
On Nov 5, 3:10 pm, Erika Skoe <[EMAIL PROTECTED]> wrote: > That's funny, I can't see anything. -- http://mail.python.org/mailman/listinfo/python-list
Eclipse3.3 with Pydev 1.3.10 Mylar problem, have Mylyn
Right now I am trying to install pydev 1.3.10 on Eclipse 3.3. I am getting an Mylar error org.eclipse.mylar (2.0.0.v20070403-1300) or something needed. Mylyn is mylar, now. How do you disable the mylar dependency, so that Mylyn is used by PyDev? -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread Profiling
On Nov 5, 2007 1:32 PM, JamesHoward <[EMAIL PROTECTED]> wrote: > Are there any good thread profilers available that can profile a > thread as it is running instead of after execution is completed? > > I would like to find a python class which looks at a currently running > thread and if its memory exceeds a certain amount than kill it. Killing a non-cooperative thread is undefined behavior. You can't do it with the Python threading API and even OS thread implementations that permit it don't guarantee that your process will be in a sane state afterward. > Ideally I would like the program to track memory used not just by that > thread, but by any threads or processes that it may spawn. > > If there isn't anything like that, then something that lets me set the > maximum memory allowed to be allocated within a thread would be > acceptable also. > Memory isn't allocated on a per-thread basis and there's not really any way to know what should be charged to a particular thread. That's on top of the normal caveats about trying to judge memory usage within Python > Thanks in advance, > James Howard > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary viewer
2007/11/5, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > On Nov 5, 3:10 pm, Erika Skoe <[EMAIL PROTECTED]> wrote: > > > > That's funny, I can't see anything. Of course, it's an empty dict! tzz, *shaking head* martin -- http://noneisyours.marcher.name http://feeds.feedburner.com/NoneIsYours -- http://mail.python.org/mailman/listinfo/python-list
Re: Library package import question
2007/11/5, Frank Aune <[EMAIL PROTECTED]>: > To prevent namespace pollution, I want to import and use this library in the > following way: > > import Foo > (...) > t = Foo.module2.Bee() from x import y as z that has always worked for me to prevent pollution... -- http://noneisyours.marcher.name http://feeds.feedburner.com/NoneIsYours -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread Profiling
Try passing the verbose=1 flag when creating the tread! On 11/6/07, Chris Mellon <[EMAIL PROTECTED]> wrote: > > On Nov 5, 2007 1:32 PM, JamesHoward <[EMAIL PROTECTED]> wrote: > > Are there any good thread profilers available that can profile a > > thread as it is running instead of after execution is completed? > > > > I would like to find a python class which looks at a currently running > > thread and if its memory exceeds a certain amount than kill it. > > Killing a non-cooperative thread is undefined behavior. You can't do > it with the Python threading API and even OS thread implementations > that permit it don't guarantee that your process will be in a sane > state afterward. > > > Ideally I would like the program to track memory used not just by that > > thread, but by any threads or processes that it may spawn. > > > > If there isn't anything like that, then something that lets me set the > > maximum memory allowed to be allocated within a thread would be > > acceptable also. > > > > Memory isn't allocated on a per-thread basis and there's not really > any way to know what should be charged to a particular thread. That's > on top of the normal caveats about trying to judge memory usage within > Python > > > > Thanks in advance, > > James Howard > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com/ http://www.jewelerslounge.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse3.3 with Pydev 1.3.10 Mylar problem, have Mylyn
In the dialog where you select pydev (in the installation -- it'll appear in the 5th screenshot at http://fabioz.com/pydev/manual_101_install.html), you can expand it and uncheck mylyn... I'll update the install instructions to better specify that... Cheers, Fabio On 11/5/07, crybaby <[EMAIL PROTECTED]> wrote: > > Right now I am trying to install pydev 1.3.10 on Eclipse 3.3. I am > getting an Mylar > error org.eclipse.mylar (2.0.0.v20070403-1300) or something needed. > Mylyn is mylar, now. > > How do you disable the mylar dependency, so that Mylyn is used by > PyDev? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Library package import question
En Mon, 05 Nov 2007 10:34:26 -0300, Frank Aune <[EMAIL PROTECTED]> escribió: > I have a python library package 'Foo', which contains alot of submodules: > > Foo/: > __init__.py > module1.py: > class Bar() > class Hmm() > module2.py > class Bee() > class Wax() > module3.py > etc etc > > To prevent namespace pollution, I want to import and use this library in > the > following way: > > import Foo > (...) > t = Foo.module2.Bee() > > To accomplish this, I put explicit imports in __init__.py: > > import module1 > import module2 > import module3 > > what Im wondering about, is if its a more refined way of doing this, as > the > explicit imports now need to be manually maintained if the library grows. > I've tried to use __all__, but this only seems to work with "from Foo > import > *" and it causes modules to be imported directly into the namespace of > course. If I understand your question right, you want some way to automatically enumerate and import all *.py files inside your package. Try this inside Foo/__init__.py: def import_all_modules(): "Import all modules in this directory" import os.path pkgdir = os.path.dirname(__file__) for filename in os.listdir(pkgdir): modname, ext = os.path.splitext(filename) if ext=='.py' and modname!='__init__': __import__(modname, globals()) import_all_modules() del import_all_modules -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: >>> CIA Squashes Democracy in Pakistan <<
On Mon, 05 Nov 2007 21:43:09 +, zionist.news wrote: > http://www.youtube.com/watch?v=BdB2r1ss5Wk > > http://www.jewwatch.com/ <- excellent source for well researched > news on world events and the big movers of history What democracy? Pakistan will be either a military dictatorship or theocratic one. A country with such a high proportion of moslem fundamentalists is not likely to develop into a democracy any time soon. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i find the form name without "nr=0"
On Nov 6, 8:56 am, scripteaze <[EMAIL PROTECTED]> wrote:
> Is it possible then to have a form with no name and if so, how can i
> access this form
Hey scripteaze,
I'm not sure about mechanize, but you might have more success using
another one of the author's modules, ClientForm:
http://wwwsearch.sourceforge.net/ClientForm/
from urllib2 import urlopen
from ClientForm import ParseResponse
response = urlopen("http://wwwsearch.sourceforge.net/ClientForm/
example.html")
forms = ParseResponse(response, backwards_compat=False)
form = forms[0]
As it returns a list of forms, you don't need to have a name to access
it.
Hope this helps.
-alex23
--
http://mail.python.org/mailman/listinfo/python-list
Re: >>> CIA Squashes Democracy in Pakistan <<
On Nov 5, 4:55 pm, Ivar Rosquist <[EMAIL PROTECTED]> wrote: > On Mon, 05 Nov 2007 21:43:09 +, zionist.news wrote: > >http://www.youtube.com/watch?v=BdB2r1ss5Wk > > >http://www.jewwatch.com/ <- excellent source for well researched > > news on world events and the big movers of history > > What democracy? Pakistan will be either a military dictatorship > or theocratic one. A country with such a high proportion of moslem > fundamentalists is not likely to develop into a democracy any time soon. Your understanding is rather shallow. However, my knowledge of history is good enough to see the facts and put them in their proper perspective. The fundamentalist Islam is democratic by nature. (The Coran itself gives rights to the non-moslem people and can be held up by non-moslems to demand their rights.) We see that in Iran. There, a commoner, Ahmadinejad has risen to be the leader by democratic voting. The women are quite educated and as aggressive as the iranian males. The videos and testimonials by the Rabbis of Neturei Karta who visited Iran shows that the jews there live quite well. On the other hand, here, the corporations decide who will get into the white house. The wahhabi puppets in Saudi Arabia and the little estates on the peninsula are dictators imposed by the Anglo-American forces. 911 was staged to prevent a democratic revolution in Saudi Arabia as one of its key objectives, and Osama was scapegoated to pre-empt a democratic revolution like in Iran. If you still insist on Iran as a theocracy, you might compare it with Israel and think about how either treats its minority. Go to youtube and google for neturei karta and find their videos about Iran. -- http://mail.python.org/mailman/listinfo/python-list
is PyUnicode_Decode a part of public api
am i allowed to use PyUnicode_Decode or PyUnicode_DecodeUTF8 in my
code
or that is not advisable?
QString s("foo");
// QString::unicode returns garbage unusable for PyUnicode_FromUnicode
PyObject *uo =
PyUnicode_Decode(s.utf8(), s.length(), "utf8", 0);
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python good for data mining?
On Nov 5, 10:29 am, Maarten <[EMAIL PROTECTED]> wrote: > On Nov 5, 1:51 pm, Jens <[EMAIL PROTECTED]> wrote: > > > > > On 5 Nov., 04:42, "D.Hering" <[EMAIL PROTECTED]> wrote: > > > > On Nov 3, 9:02 pm, Jens <[EMAIL PROTECTED]> wrote: > > > > I then leaned C and then C++. I am now coming home to Python realizing > > > after my self-eduction, that programming in Python is truly a pleasure > > > and the performance is not the concern I first considered to be. > > > Here's why: > > > > Python is very easily extended to near C speed. The Idea that FINALLY > > > sunk in, was that I should first program my ideas in Python WITHOUT > > > CONCERN FOR PERFOMANCE. Then, profile the application to find the > > > "bottlenecks" and extend those blocks of code to C or C++. Cython/ > > > Pyrex/Sip are my preferences for python extension frameworks. > > > > Numpy/Scipy are excellent libraries for optimized mathematical > > > operations. Pytables is my preferential python database because of > > > it's excellent API to the acclaimed HDF5 database (used by very many > > > scientists and government organizations). > > > So what you're saying is, don't worry about performance when you start > > coding, but use profiling and optimization in C/C++. Sounds > > reasonable. It's been 10 years ago since I've done any programming in C > > ++, so I have to pick up on that soon I guess. > > "Premature optimization is the root of all evil", to quote a famous > person. And he's right, as most people working larger codes will > confirm. On Nov 5, 10:29 am, Maarten <[EMAIL PROTECTED]> wrote: > On Nov 5, 1:51 pm, Jens <[EMAIL PROTECTED]> wrote: > > > > > On 5 Nov., 04:42, "D.Hering" <[EMAIL PROTECTED]> wrote: > > > > On Nov 3, 9:02 pm, Jens <[EMAIL PROTECTED]> wrote: > > > > I then leaned C and then C++. I am now coming home to Python realizing > > > after my self-eduction, that programming in Python is truly a pleasure > > > and the performance is not the concern I first considered to be. > > > Here's why: > > > > Python is very easily extended to near C speed. The Idea that FINALLY > > > sunk in, was that I should first program my ideas in Python WITHOUT > > > CONCERN FOR PERFOMANCE. Then, profile the application to find the > > > "bottlenecks" and extend those blocks of code to C or C++. Cython/ > > > Pyrex/Sip are my preferences for python extension frameworks. > > > > Numpy/Scipy are excellent libraries for optimized mathematical > > > operations. Pytables is my preferential python database because of > > > it's excellent API to the acclaimed HDF5 database (used by very many > > > scientists and government organizations). > > > So what you're saying is, don't worry about performance when you start > > coding, but use profiling and optimization in C/C++. Sounds > > reasonable. It's been 10 years ago since I've done any programming in C > > ++, so I have to pick up on that soon I guess. > > "Premature optimization is the root of all evil", to quote a famous > person. And he's right, as most people working larger codes will > confirm. > > As for pytables: it is the most elegant programming interface for HDF > on any platform that I've encountered so far. Most other platforms > stay close the HDF5 library C-interface, which is low-level, and quite > complex. PyTables was written with the end-user in mind, and it shows. > One correction though: PyTables is not a database: it is a storage for > (large) arrays, datablocks that you don't want in a database. Use a > database for the metadata to find the right file and field within that > file. Keep in mind though that I mostly work with externally created > HDF-5 files, not with files created in pytables. PyTables Pro has an > indexing feature which may be helpful for datamining (if you write the > hdf-5 files from python). > > Maarten Hi Maarten, I respectfully disagree that HDF5 is not a DB. Its true that HDF5 on its prima facie is not relational but rather hierarchical. Hierarchical is truely a much more natural/elegant[1] design from my perspective. HDF has always had meta-data capabilities and with the new 1.8beta version available, it is increasing its ability with 'references/links' allowing for pure/partial relational datasets, groups, and files as well as storing self implemented indexing. The C API is obviously much more low level, and Pytables does not yet support these new features. [1] Anything/everything that is physical/virtual, or can be conceived is hierarchical... if the system itself is not random/chaotic. Thats a lovely revelation I've had... EVERYTHING is hierarchical. If it has context it has hierarchy. -- http://mail.python.org/mailman/listinfo/python-list
