Re: html DOM

2008-03-29 Thread Michael Wieher
Was this not of any use?

http://www.boddie.org.uk/python/HTML.html

I think, since HTML is a sub-set of XML, any XML parser could be adapted to
do this... I doubt there's an HTML-specific version, but I would imagine you
could wrap any XML parser, or really, create your own that derives from the
XML-parser-class...



On Sat, Mar 29, 2008 at 6:09 PM, Sam the Cat <[EMAIL PROTECTED]>
wrote:

> Is there a package that would allow me the same or similar functionality
> for
> modifying html code via the DOM model as I have in JavaScript ?  I'd like
> to
> parse an html file, then modify it and save the result.  I am not trying
> to
> do this online, rather I would like to do this on a batch of files stored
> on
> my hard drive.  I have found several packages that allow me to parse and
> dissect html but none that allow me to modify the object and save the
> results -- perhaps I am overlooking the obvious
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Michael Wieher
to me it seems simple.

C uses !=

why does C use !=  because its kind of hard to type the "equal with a
slash"

so if python is supposed to be a simple and easy to use language, use the
simple and easy to understand, standard 'not-equal' operator... Idk, maybe
there's more to it but simple is as simple does, sir

2008/3/29 Lie <[EMAIL PROTECTED]>:

> On Mar 30, 1:24 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> > Lie <[EMAIL PROTECTED]> wrote:
> > > You're forcing your argument too much, both != and <> are NOT standard
> > > mathematics operators -- the standard not-equal operator is >< -- and
> > > I can assure you that both != and <> won't be comprehensible to non-
> > > programmers.
> >
> > My maths may be a bit rusty, but I always thought that the standard not-
> > equal operator was like an = sign but with a diagonal slash through it
> as
> > displayed when you do:
> >
> >print u'\u2260'
>
> Ah yes, that is also used (I completely forgot about that one, my
> math's aren't that sharp anymore) and I think it's used more
> frequently than ><. Some books use >< while most use ≠, but my
> argument was that no math book use != or <> (except in math for
> programmers).
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help me on function definition

2008-03-28 Thread Michael Wieher
No problem...

your def needs a colon..

def function(params):

yours lacks it =) thats all

On Fri, Mar 28, 2008 at 8:47 PM, aeneng <[EMAIL PROTECTED]> wrote:

> Hello everyone,
>
> I am just starting to use python in numerical cacluation.
> I need you to help me to see what's wrong with the following piece of
> codes, which computes the cross product of two vectors and returns
> the result. u and v are two 3x1 matrix.
>
> when I import the function, error message show like this
> >>> import cross
> Traceback (most recent call last):
>  File "", line 1, in ?
>  File "cross.py", line 8
>ppp2=u[2]*v[0]-u[0]*v[2]
>^
> SyntaxError: invalid syntax
>
> WHAT IS WRONG WITH MY CODE?
>
> I appreciate your help.
>
> ##here is the function definition.
> ##cross.py##
> def cross(u,v)
>"""input two vectors u and v in 3-D space,
>   output a cross product of vector w, in column or in row
> accordingly."""
>ppp1,ppp2,ppp3=0.0,0.0,0.0
>ppp1=u[1]*v[2]-u[2]*v[1]
>ppp2=u[2]*v[0]-u[0]*v[2]
>ppp3=u[0]*v[1]-u[1]*v[0]
># store the result of the cross product in u
>u[0]=ppp1
>u[1]=ppp2
>u[2]=ppp3
>return u #return the cross product of vector u x v.
> if __name__=="__main__":
>from cvxopt.base import matrix
>u=matrix([1.0,0.0,0.0],(3,1))
>v=matrix([0.0,1.0,0.0],(3,1))
>print cross(u,v)
>print "file name is %s" %__name__
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: what does ^ do in python

2008-03-26 Thread Michael Wieher
On Wed, Mar 26, 2008 at 1:36 PM, Gabriel Genellina <[EMAIL PROTECTED]>
wrote:

> En Wed, 26 Mar 2008 15:04:44 -0300, David Anderson <[EMAIL PROTECTED]>
> escribió:
>
> > HOw can we use express pointers as in C or python?
>
>   File "english.py", line 345, in parse_sentence
> raise ParserError, "can't parse %r" % sentence
> ParserError: can't parse 'HOw can we use express pointers as in C or
> python?'
>
>>>string = "How can we use express pointers as in C or python?"
>>>import advancedParser
>>>advancedParser.translate(string)

LogicError: indication that we are not outside of python, recursive
self-definition requested.
(segmentation fault)

all sarcasm aside

if you actually meant to ask how to pass by value or pass by reference in
Python, then the simple answer is don't worry about it, Python handle's
things in a natural and intuitive way.

If you have a specific question regarding python's handling of this concept,
ask it, as some instances can be confusing and have gotchyas.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: memory allocation for Python list

2008-03-26 Thread Michael Wieher
Just write it in C and compile it into a .so/pyd =)

2008/3/26, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> dmitrey:
>
> > As I have mentioned, I don't know final length of the list, but
> > usually I know a good approximation, for example 400.
>
>
> There is no reserve()-like method, but this is a fast enough operation
> you can do at the beginning:
>
> l = [None] * 400
>
> It may speed up your code, but the final resizing may kill your
> performance anyway. You can try it. Just using Psyco is probably
> better.
>
> Bye,
> bearophile
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Dimensions of Arrays, Matrices

2008-03-26 Thread Michael Wieher
Google -> "matrix python"

1st response:
http://www.python.org/community/sigs/retired/matrix-sig/
"The purpose of this SIG was to continue development of a Python matrix
type. This effort succeeded and resulted in Numerical
Python,
a high-speed array language for Python"

by following the magic hyperlink I arrive at

http://scipy.org/

which might be too embellished, so I then returned to the retired-sig and
found

http://sourceforge.net/projects/numpy

I'm sure if you dig around in either of those places you'll find more than
you are looking for =)

2008/3/26, Dark Wind <[EMAIL PROTECTED]>:
>
> Hi,
>
> Suppose we have a 3X3 matrix in Mathematica. We can get its dimensions by:
> Dimensions[A]  = {3,3}
> TensorRank[A] = 2
>
> Are there exact functions for these two in Python?
>
> Thank you
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Does python hate cathy?

2008-03-23 Thread Michael Wieher
>
>
> is that farnarkeling about in a __del__ method is *not* a good idea.


Ok that having been said, is accessing an unbound variable of a class and
using it to coordinate between instances of that class common practice?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Does python hate cathy?

2008-03-23 Thread Michael Wieher
I changed the last few lines to read:


 37 kalam.howMany()
 38 c = Person('Catherine', 'F')
 39 #cathy.sayHi()
 40 #cathy.howMany()
 41 #swaroop.sayHi()
 42 #swaroop.howMany()
 43


And I don't get the error.

However if I change line 38 to read
ca = Person('Catherine','F')

It again initializes and then the error occurs.  It isn't random, I can run
the code 10, 20 times with variable name 'c' and no error, and then again
with variable name 'ca' or 'cathy' and the error does occur.

I haven't much experience with __del__() functions but you're right -- this
is strange as all hell.  And I can't even imagine why it would happen at
all.

Obviously it is attempting to access the Person.population() variable.
Which is a logic error, (I think) since well, we have 3 instances of the
class being created and then the unbound variable (ie: a variable not
associated with any instantiation of the class) being incremented and
decremented.

Logically, I think it shouldn't work at all, but somehow this unbound
variable is working but in a very buggy way.

Or am I wrong?  Are unbound class-variables supposed to be used to
coordinate between multiple instantiations of that class?

2008/3/23, George Sakkis <[EMAIL PROTECTED]>:
>
> On Mar 23, 8:01 pm, QS <[EMAIL PROTECTED]> wrote:
> > Hi to all!
> > I am new to python, and I encountered a weird problem.
> >
> > Here is my code
> >
> > ##>8
> > #!/usr/bin/python
> > # Filename: objvar.py
> > class Person:
> > '''Represents a person.'''
> >
> > population = 0
> > #sex = 'F'
> > #age = 22
> > # It is vague here: is this variable going to be a class, or
> > object, variable
> >
> > def __init__(self, name, sex):
> > '''Initializes the person's data.'''
> > self.name = name
> > self.sex = sex
> > print '(Initializing %s )' % self.name
> > # When this person is created, he/she
> > # adds to the population
> > Person.population += 1
> >
> > def __del__(self):
> > '''I am dying.'''
> >
> > print '%s says bye.' % self.name
> > Person.population -= 1
> > if Person.population == 0:
> > print 'I am the last one.'
> > else:
> > print 'There are still %d people left.' %
> > Person.population
> >
> > def sayHi(self):
> >  '''Greeting by the person.
> >
> >  Really, that's all it does.'''
> >
> >  self.age = 25
> >  print 'Hi, my name is %s, and I am %s, and I am age %d ' %
> > (self.name, self.sex, self.age)
> >
> > def howMany(self):
> >  '''Prints the current population.'''
> >  if Person.population == 1:
> >  print 'I am the only person here.'
> >  else:
> >  print 'We have %d persons here.' % Person.population
> >
> > swaroop = Person('Swaroop', 'M')
> > swaroop.sayHi()
> > swaroop.howMany()
> > kalam = Person('Abdul Kalam', 'M')
> > kalam.sayHi()
> > kalam.howMany()
> > cathy = Person('Catherine', 'F')
> > cathy.sayHi()
> > cathy.howMany()
> > swaroop.sayHi()
> > swaroop.howMany()
> >
> > # 8< #
> >
> > When I run this script, I got the following exception:
> > Exception exceptions.AttributeError: "'NoneType' object has no
> > attribute 'population'" in  > <__main__.Person instance at 0xb7d8ac6c>> ignored
> >
> > To to newcomer like me, this message doesn't make much sense. What
> > seems weird to me is that, if I change the variable cathy to something
> > else, like cath, or even cat, then the script will finish gracefully.
> > Why "cathy" is not liked?!!
> >
> > Some of you may have recognized that the code is derived from a sample
> > code in Swaroop's "A byte of python".
> >
> > My python is of version 2.5.1, on Ubuntu.
>
>
> That's really weird... it's reproducible on Windows too. It doesn't
> make any sense why the name of the variable would make a difference.
> My guess is you hit some kind of obscure bug.
>
>
> George
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: List question

2008-03-22 Thread Michael Wieher
If you can't laugh at your own stupidity, being a programmer will lead
directly to insanity. =)

2008/3/22, Zentrader <[EMAIL PROTECTED]>:
>
> > No one meant to laugh at you.  Your naivete was not obvious.  FWIW, a
> > sense of humor is a valuable possession in most Python-related
> > conversations.
>
> Perhaps someone can explain how telling something like this to the OP,
> who thinks this statement will work
> if 'one' and 'two' in f:
> is funny and not mean.  In the words of whoever it was in "Gone With
> The Wind", frankly I don't give a damn (except to not mislead relative
> newbies).  But this has wasted enough of everyone's time.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How can I make a function equal to 0?

2008-03-21 Thread Michael Wieher
Well, you could have a variable f that points at a memory address, such that

>>> def x():
...  return
...
>>> x

>>> x=0
>>> x
0
>>>

but I don't really understand why/what you're trying to do

2008/3/21, Martin Manns <[EMAIL PROTECTED]>:
>
> Hi,
>
> Is there a way to create a function that is equal to 0?
> I try to redefine __cmp__ but I am pretty stuck.
>
> Something like:
>
> >>> def f(): return ""
> ...
> >>> # Some magic
> >>> f == 0
> True
>
> Thanks in advance
>
> Martin
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Code folder with Emacs

2008-03-20 Thread Michael Wieher
I don't use emucks, but in vim its very simple.

:set foldmethod=indent

and instantly anything indented (ie: all python blocks) are folded.

to unfold a fold
zo
to close an opened fold
zc

that outta be enough to get any fellow vim-heads going =)

2008/3/20, Grant Edwards <[EMAIL PROTECTED]>:
>
> Has anybody figured out how to do code folding of Python source
> files in emacs?
>
> I tried "hide-show" minor mode, but it doesn't really work for
> Python code: the only think it knows how to hide/show are
> function bodies.  It can't do normal things like hide/show a
> code block like it can for other languages.
>
> Google also found my "folding mode", but that's based on
> user-inserted tokens and isn't syntax aware.
>
> --
> Grant
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Haskell vs ??

2008-03-20 Thread Michael Wieher
Just to help clear up my own understanding of this discussion, this is
basically a language that obfuscates details and makes low-level decisions
in a "average-best" way, and thus allows for lazy people to write kind of
decent code quickly?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: if __name__ == '__main__':

2008-03-20 Thread Michael Wieher
Well, consider this:

you have a file named .py, built like this:
~
#!/usr/bin/python

def :

return 

if __name__=="__main__":
print "Unit test"
else:
pass #module imported by another module/script
~~

If you type, on command line, >python ./.py
you will see "Unit test" printed to the screen.

if, however you are in another python file and type "import " the
code will, instead, "pass" and nothing will occur.

I hope this helps =)


2008/3/20, Simon Brunning <[EMAIL PROTECTED]>:
>
> On Thu, Mar 20, 2008 at 4:12 PM, Bhagwat Kolde <[EMAIL PROTECTED]> wrote:
> > Hi,
> > I am new to the python and not getting meaning of following line,
> >
> > if __name__ == '__main__':
> >   main()
>
> <
> http://www.python.org/doc/faq/programming/#how-do-i-find-the-current-module-name
> >
>
> --
> Cheers,
> Simon B.
> [EMAIL PROTECTED]
> http://www.brunningonline.net/simon/blog/
> GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Can I run a python program from within emacs?

2008-03-20 Thread Michael Wieher
Well, I suppose you could.  But why bother with learing emacs when you'll
have to switch to vim later anyway?

2008/3/20, jmDesktop <[EMAIL PROTECTED]>:
>
> Hi, I'm trying to learn Python.  I using Aquamac an emac
> implementation with mac os x.  I have a program.  If I go to the
> command prompt and type pythong myprog.py, it works.  Can the program
> be run from within the editor or is that not how development is done?
> I ask because I was using Visual Studio with C# and, if you're
> familiar, you just hit run and it works.  On Python do I use the
> editor for editing only and then run the program from the command
> line?  Thank you.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Deleting Microsoft access database

2008-03-20 Thread Michael Wieher
Are you going to be replacing it with a new database?

Problem: Users are accessing the file.  (as you said, users are opening in
read-only)
Solution: (assuming you will be using a new, better... anything is better
than M$, database) --- put the new database online, redirect your users to
hit the new database, once all connections are closed, delete the Access
database.
Alternate Solution: (if you aren't replacing it) Just turn the database
server off (that will kill any connections) and delete the database, or at
least disable that database from within the server itself (thus closing all
connections) and delete it.

Read only or not, the DB is still open, and can't be deleted while people
are connected.

2008/3/20, Ahmed, Shakir <[EMAIL PROTECTED]>:
>
> I have a Microsoft Access database that I want to delete whether anyone
> is using that file.
>
> The database is already read only mode residing in a server, users are
> opening in read only mode. I want to delete that file, I remove read
> only check but could not delete that file.
>
> Getting error message:
> Cannot delete xxx : It is being used by another person or program.
>
> Any help is highly appreciated.
>
> Thanks
> sa
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python to C/C++

2008-03-19 Thread Michael Wieher
I think py2exe does this, but it might be a bit bloated

2008/3/19, Blubaugh, David A. <[EMAIL PROTECTED]>:
>
>  To All,
>
> Has anyone worked with a translator that will translate python to c/c++
> source code?  I know that there is already one translator of this nature 
> (shedskin
> compiler) out there.  However, it is still in the beta stage of
> development.  Does anyone know of a more developed version of a translator
> of this nature?
>
> Thanks,
>
> David Blubaugh
>
> This e-mail transmission contains information that is confidential and may
> be privileged.   It is intended only for the addressee(s) named above. If
> you receive this e-mail in error, please do not read, copy or disseminate it
> in any manner. If you are not the intended recipient, any disclosure,
> copying, distribution or use of the contents of this information is
> prohibited. Please reply to the message immediately by informing the sender
> that the message was misdirected. After replying, please erase it from your
> computer system. Your assistance in correcting this error is appreciated.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Apache binary error?

2008-03-17 Thread Michael Wieher
yes that was already there, but it kept giving me that every-other problem

i know its the fact the web-browser wasn't passed the "content-type=..." on
the alternate reloads but as to why im lost

in the end i figure its best to just  ignore this and move to the more
beta-test dev stage which involves django, so hopefully that'll just erase
this weird error

and i know the script worked (ie: the content should be being piped to the
page) because the 2nd refresh (or first, alternately) would provide me with
the expected result (ie: a web page)

thanks tho =)

2008/3/17, Graham Dumpleton <[EMAIL PROTECTED]>:
>
> On Mar 18, 4:43 am, Sean Allen <[EMAIL PROTECTED]> wrote:
> > On Mar 17, 2008, at 10:55 AM, Michael Wieher wrote:
> >
> > > have simple webpage running
> >
> > > apache,mod_python
> >
> > > the error is binary
> > > ...binary as in "every other" time I load the page, Firefox keeps
> > > telling me I'm downloading a python script, and asks to open it in
> > > WINE, which is really strange.
> >
> > > then, alternately, it loads the page just fine.  any clues as to why
> > > this is happening?
> > > --
> >
> > for anything like mod_perl,mod_pythonetc the first thing i do when i
> > get really weird errors
> > it move to having only one apache process for testing.
> >
> > might want to start there.
>
> In mod_python handler code:
>
>   req.content_type = 'text/plain'
>
> or otherwise.
>
> If you don't indicate what the response content type is web browsers
> will often try and work it out based on the extension in the URL.
>
> This is presuming you configured Apache correctly and your code is
> actually being executed and you aren't just serving up your code
> instead.
>
> Graham
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: placing a Python com object into Excel

2008-03-17 Thread Michael Wieher
2008/3/17, Mathew <[EMAIL PROTECTED]>:
>
> Hi
> I have seen examples from Mark Hammonds book where a Python COM object
> is accessed from Excel with a VBA script. But, what if I want to Insert
> a Python COM into the Sheet itself?
>
> When I try this, a list of available objects appear. But my object isn't
> on the list.
>
> Anybody have any ideas?


Well,  how are you inserting it?  My experience with MS-Visual Studio is
that you first have to register the COM/ActiveX component with the system in
some way (ie: so that Visual Studio knows it exists) and from there, you
drop it into your application using the GUI.  If Visual Studio hasn't been
told the COM object exists, it won't be able to incorporate it.  Here's a
link describing how to insert a COM object in Visual Studio .NET.

http://support.microsoft.com/kb/307367

If that doesn't help, look for something similar, not sure which version of
VS you're running.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: struct unpack

2008-03-17 Thread Michael Wieher
>
> testValue = '\x02\x00'
> junk = struct.unpack('h', testValue)  #Works
>
> testValue = raw_input("Enter Binary Code..:")  inputting at the
> console '\x02\x00'
> junk = struct.unpack('h', testValue)
>
> error: unpack requires a string argument of length 2


Well, it thinks the length of the testValue is longer than 2.
Why not print out len(testValue) immediately after calling raw_input?
maybe raw_input doesn't recognize hex-values automatically, while a
string='\x??' is recognizable by the interpreter as such.

obviously the issue is raw_input and how it handles input strings... how to
fix?  no idea =)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Missing PyObject definition

2008-03-17 Thread Michael Wieher
2008/3/17, James Whetstone <[EMAIL PROTECTED]>:
>
> Hi,
>
> Yeah, I've included python.h and object.h but the compiler still complain
> about not finding PyObject.  It's weird.So I'm developing and App on
> windows using VS 8.0.  I've intalled Python 2.5 and have added the include
> directory to my project's configuration.  I'm also using boost.python in
> another application to wrap my C++ classes.
>
> Here's the C++ class I'm wrapping:
>
> class widget
> {
>
> public:
>
> widget(const string &name,  unsigned int myint) :
> {
>
> }
>
> static unsigned int __stdcall Callback(void * voidPtr);
> void startMessageHandler();
>void stopMessageHandler();
> virtual void handleMessage(void *message)=0;
>
> };
>
> So the idea here is that the Python user will derive from widget and
> override the virtual method "handleMessage".  A thread is spawned by
> "startMessageHandler()" that does some work and periodically calls
> "handleMessage" passing it a chunk of memory.  This memory is intended to
> be
> zero-copy. Okay, so I've implemeted this class to set up the class for
> Python:
>
> class py_widget : public widget
> {
> public:
> py_widget(PyObject *p, const string &name, unsigned int myint) :
>  self(p),
>  py_widget(name, myint)
>   {
>   }
>
>   void handleMessage(void *message);
>
>   PyObject *self;
>
> };
>
> where handleMessage has the following implementation:
>
> void PyAsyncQueue::handleMessage(void *message)
> {
>  //get the memory block size with a method not shown here
>  int size = getSize(message);
>
> //create a buffer object so the Python users can access memory block
> directly.
>
>  PyObject *obj = PyBuffer_FromReadWriteMemory( message, size ) ;
>
> //now what 
>
>  //I've tried calling the method directly based on some info I found
> some documentation, but this doesn't
> //compile because the compile can't find PyObject.  Also, I really
> know
> what it looks like anyways.
>  //self->attr("handleMessage")(obj);
>
>  //This boost.python call doesn't work either.
>  //call_method(self, "handleMessage", obj);
> }
>
>
> Thanks for your suggestions on this,
> James
>
>
>
> "Jeff Schwab" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > James Whetstone wrote:
> >> I'm trying to access a PyObject directly from C++ for the purpose of
> >> calling method on a Python object that is an intance of a derived C++
> >> class. My problem is that the compiler is complaining about not
> PyObject
> >> not being defined.  Has anyone run into the problem?  Where is PyObject
> >> defined?
> >
> > Are you using Python's C API?
> >
> > Did you #include "Python.h" before using PyObject?
> >
> > PyObject is a C-style struct defined in object.h, which is in turn
> > included by Python.h.  Does your compiler know where to look for those
> > headers?  If you are getting messages of the form "error: cannot find
> > Python.h," then add -Iyour_python_root/include/python2.5 (or whatever
> > version) to the CXXFLAGS variable in your makefile, or to your
> compiler's
> > command line.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If you're using MS-Visual Studio, be sure you really included the file where
you think you did... I ran into some stupidity of my own, trying to put
include files in the "library" path and vice versa.

If you have "Python.h" included properly, you should be able to compile some
small test-code using PyObject.

If you can't, you haven't got it included correctly.  That's where I'd
start.

If there's other bugs in your code, thats a different issue, but if the
compiler can't find class-X defined in file-Y, then you need to double-check
your include, include-path, and so on and so forth.

Also, don't forget that just because the include directory is on your
project's path, that the actual file itself needs to be included.  When
running in VS 6.0 I had to place my includes in some awfully strange
places.  Redundant includes don't hurt.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Missing PyObject definition

2008-03-17 Thread Michael Wieher
2008/3/17, James Whetstone <[EMAIL PROTECTED]>:
>
> I'm trying to access a PyObject directly from C++ for the purpose of
> calling
> method on a Python object that is an intance of a derived C++ class. My
> problem is that the compiler is complaining about not PyObject not being
> defined.  Has anyone run into the problem?  Where is PyObject defined?
>
> Thanks!
> James


PyObject is definend in 

this is easily google-able =P
-- 
http://mail.python.org/mailman/listinfo/python-list

Apache binary error?

2008-03-17 Thread Michael Wieher
have simple webpage running

apache, mod_python

the error is binary
...binary as in "every other" time I load the page, Firefox keeps telling me
I'm downloading a python script, and asks to open it in WINE, which is
really strange.

then, alternately, it loads the page just fine.  any clues as to why this is
happening?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pycon disappointment

2008-03-16 Thread Michael Wieher
well, like, at least he left a free copy of his book on the web, that was
kinda decent.

2008/3/16, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> On Mar 16, 2:43 pm, Robert Hicks <[EMAIL PROTECTED]> wrote:
> > On Mar 16, 12:38 pm, [EMAIL PROTECTED] wrote:
> >
> > > On Mar 16, 6:10 am, Bruce Eckel <[EMAIL PROTECTED]> wrote:
> >
> > > > I think a lot of people have been caught up in the idea that we need
> > > > to commercialize Python, and ride some kind of wave of publicity the
> > > > way that Java and C# and Rails seem to have done.
> >
> > > This coming from someone who caught the Java wave and rode it for a
> > > decade.
> >
> > Doesn't that make him better to see the problems with it?
>
> Sure, but he dumped C++ (a truly non-commercial language) like a bad
> habit for the latest silver bullet ten years ago.  Complaints against
> Java's commercial nature now ring a bit hollow.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Strange problem with structs Linux vs. Mac

2008-03-16 Thread Michael Wieher
you can specifify which encoding when you unpack the struct, so just try
them till it works, or read the specs on the mac.. i find it quicker to try,
there's only 4-5

2008/3/16, sturlamolden <[EMAIL PROTECTED]>:
>
> On 16 Mar, 18:23, "Martin Blume" <[EMAIL PROTECTED]> wrote:
>
> > This seems to imply that the Mac, although running now on Intel
> > processors, is still big-endian.
>
> Or maybe the struct module thinks big-endian is native to all Macs? It
> could be a bug.
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Strange problem with structs Linux vs. Mac

2008-03-16 Thread Michael Wieher
try twiddling the unpack prefix, they're probably stored in different binary
formats on the disk...

on the struct helppage, is a list of prefixes, can be like

unpack('=HI',data)
unpack('@HI',data)

etc...

find out which one works on each machine

2008/3/16, jasonwiener <[EMAIL PROTECTED]>:
>
> Hi-
>
> I am having a VERY odd problem with unpacking right now.  I'm reading
> data from a binary file and then using a very simple struct.unpack to
> get a long.  Works fine on my MacBook, but when I push it to a Linux
> box,it acts differently and ends up pewking.
>
> here's the code snippet:
> fread.seek(0,0)
> tmp_rebuild = fread.read()
> fread.close()
> tmp_long = tmp_rebuild[0:4]
> print tmp_long.encode('hex')
> print repr(tmp_long)
>
> unpacked_long =  struct.unpack('I',
> tmp_rebuild[0:4])[0]
> print 'unpacked_long: %s' % unpacked_long
>
> my MacBook produces:
> 1ec6f3b4
> '\x1e\xc6\xf3\xb4'
> unpacked_long: 516354996
>
> but on the linux box the same code produces:
> 1ec6f3b4
> '\x1e\xc6\xf3\xb4'
> unpacked_long: 3035874846
>
> the data looks to be the same, but the unpacking seems to treat it
> differently.
>
> Has anyone an idea of why this happens???
>
> Thanks-
> J.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pycon disappointment

2008-03-16 Thread Michael Wieher
2008/3/16, Aaron <[EMAIL PROTECTED]>:
>
>
> > In my opinion, open spaces should have had greater status and billing,
> > with eyes-forward talks and vendor sessions offered only as possible
> > alternatives. Especially, vendor sessions should not be presented as
> > "keynotes"  during plenary sessions. I think it took a little while
> > for people to catch on to the idea that they could have control of
> > their own experience through the open spaces and that the main
> > offerings were not the only option.
>
> This is an excellent suggestion and observation.  Sold sponsorships
> are fine as long as they are billed as such.  Labels on the vendor
> speeches indicated they were sold as ad space would be great, as well
> as more strongly emphasizing the ad hoc discussion spaces.


But vendors often don't label themselves as vendors.  And often, the
researcher or individual in question, who has something worth saying, does
have a professional job of sorts, which might be related to his or her work
or speech.  I've heard people give very long, detailed talks about
interesting topics, that did have a spin on them, but contained worthwhile
information also.  Now, is that to be billed as a "vendor" (and ignored) or
not?
Further, no vendor who is trying to sell a product will allow themselves to
be marked in an obvious way as advertising, knowing that they'll be
ignored.  At least, they certainly won't pay for the time/space to any real
degree, knowing they'll be walking in under a cloud like that.


--
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Advantage of the array module over lists?

2008-03-16 Thread Michael Wieher
I believe the array module provides more functionality than lists.
Perhaps this extra functionality comes with... overhead?  C'est possible.
For example, you can declare an array to contain all items of a type, ie:

>>array.array('f')#array of floats

So, they might be efficient, in that they're more efficient than wrapping
lists on your own, if you *need* the extra power they provide.
Not sure.


2008/3/16, Arnaud Delobelle <[EMAIL PROTECTED]>:
>
> Tobiah <[EMAIL PROTECTED]> writes:
>
> > I checked out the array module today.  It claims that
> > arrays are 'efficient'.  I figured that this must mean
> > that they are faster than lists, but this doesn't seem
> > to be the case:
> >
> >  one.py ##
> > import array
> >
> > a = array.array('i')
> >
> > for x in xrange(1000):
> > a.append(x)
> >
> > for x in a:
> > a[x] += 1
> >
> >  two.py ##
> > a = []
> >
> > for x in xrange(1000):
> > a.append(x)
> >
> > for x in a:
> > a[x] += 1
> >
> > ##
> >
> >
> > ktops:toby:pytest> time python one.py; time python two.py
> >
> > real0m28.116s
> > user0m17.504s
> > sys 0m10.435s
> >
> > real0m23.026s
> > user0m13.027s
> > sys 0m9.777s
> >
> >
> > Perhaps the only advantage is that they take less memory
> > to store a large number of items?  It would seem then, that
> > 'economical' might have been a better choice of word than
> > 'efficient'.
>
> I get an even bigger difference with this test (same as yours, but
> using timeit and using an allegedly more efficient way of initialising
> the array)
>
> >>> def test(arr, n):
> ... a = arr(xrange(n))
> ... for x in a:
> ... a[x] += 1
> ...
> >>> n = 1000
> >>> import timeit
> >>> timeit.Timer('test(list, n)', 'from __main__ import test,
> n').timeit(1)
> 2.4988760948181152
> >>> from array import array
> >>> arr = lambda n: array('i', n)
> >>> timeit.Timer('test(arr, n)', 'from __main__ import test, arr,
> n').timeit(1)
> 5.7419960498809814
> >>>
>
> --
> Arnaud
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Cannot build Python 2.4 SRPM on x64 platform

2008-03-16 Thread Michael Wieher
Sorry I don't have much of a better idea, but if I had this kind of problem
with an RPM, I'd just grab the tarball and start hacking away at ./configure
pre-requirements, trying to use --options to trim it down to the bare
minimal and see if I can get it to load up.

2008/3/16, Eric B. <[EMAIL PROTECTED]>:
>
> Hi,
>
> For those on several python lists, I appologize in advance for
> cross-posting, but I'm really not sure which list is best to ask for
> assistance with this.
>
> Currently, I am trying to build the python2.4 SRPM from Python.org on a
> RHEL4 x64 platform, but the build is failing with a very non-descript
> error message.
>
> 
> + cd /var/tmp/python2.4-2.4-root/usr/bin
> + mv -f pydoc pydoc2.4
> + cd /var/tmp/python2.4-2.4-root/usr/bin
> + mv -f idle idle2.4
> + echo '#!/bin/bash'
> + echo 'exec /usr/bin/python2.4 /usr/lib64/python2.4/idlelib/idle.py'
> + chmod 755 /var/tmp/python2.4-2.4-root/usr/bin/idle2.4
> + cp -a Tools /var/tmp/python2.4-2.4-root/usr/lib64/python2.4
> + rm -f mainpkg.files
> + find /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/lib-dynload -type f
> + sed 's|^/var/tmp/python2.4-2.4-root|/|'
> + grep -v -e '_tkinter.so$'
> error: Bad exit status from /var/tmp/rpm-tmp.55639 (%install)
>
>
> RPM build errors:
> user jafo does not exist - using root
> group jafo does not exist - using root
> user jafo does not exist - using root
> group jafo does not exist - using root
> Bad exit status from /var/tmp/rpm-tmp.55639 (%install)
>
>
> If I try to run /var/tmp/rpm-tmp.55639 manually from the prompt manually
> after the rpmbuild fails, it runs properly to completion.  If I try to
> comment out that last line (find
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/lib-dynload -type f | sed
> 's|^/var/tmp/python2.4-2.4-root|/|' | grep -v -e '_tkinter.so$' ) that
> seems
> to be causing the script to fail, rpmbuild finishes, but with several
> error
> msgs, complaining about missing files in the lib64 directories:
>
> + rm -f /tmp/python-rpm-files.4859
> + /usr/lib/rpm/brp-compress
> + /usr/lib/rpm/brp-strip
> + /usr/lib/rpm/brp-strip-static-archive
> + /usr/lib/rpm/brp-strip-comment-note
> Processing files: python2.4-2.4-1pydotorg
> error: File not found by glob:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/*.txt
> error: File not found by glob:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/*.py*
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/pdb.doc
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/profile.doc
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/curses
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/distutils
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/encodings
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/plat-linux2
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/site-packages
> error: File not found: /var/tmp/python2.4-2.4-root
> /usr/lib64/python2.4/test
> error: File not found: /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/xml
> error: File not found: /var/tmp/python2.4-2.4-root
> /usr/lib64/python2.4/email
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/compiler
> error: File not found: /var/tmp/python2.4-2.4-root
> /usr/lib64/python2.4/bsddb
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/hotshot
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/logging
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/lib-old
> Executing(%doc): /bin/sh -e /var/tmp/rpm-tmp.95118
> + umask 022
> + cd /usr/src/redhat/BUILD
> + cd Python-2.4
> + DOCDIR=/var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
> + export DOCDIR
> + rm -rf /var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
> + /bin/mkdir -p /var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
> + cp -pr Misc/README Misc/cheatsheet Misc/Porting
> /var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
> + cp -pr LICENSE Misc/ACKS Misc/HISTORY Misc/NEWS
> /var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
> + exit 0
> Processing files: python2.4-devel-2.4-1pydotorg
> error: File not found:
> /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/config
> Processing files: python2.4-tools-2.4-1pydotorg
> Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1
> rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(VersionedDependencies) <=
> 3.0.3-1
> Requires: /bin/bash /bin/sh /usr/bin/env
>
>
> Finally, if I try searching for any files in the
> usr/lib64/python2.4/lib-dynload  or usr/lib64/python2.4/idlelib
> directories
> manually, I don't see any files at all in those directories.
>
>
> To me, it seems as though python is either not installing the files in the
> right places, or the script is searching for files in the wrong places,
> but
> I'm completely guessing here.
>
> Has anyone manag

Re: Why doesn't xmlrpclib.dumps just dump an empty value instead of ?

2008-03-16 Thread Michael Wieher
2008/3/16, martin f krafft <[EMAIL PROTECTED]>:
>
> Hi,
>
> xmlrpclib.dumps((None,), allow_none=True) yields
>
>   '\n\n\n\n'
>
> Why doesn't it just yield
>
>   '\n\n\n\n'
>
> Or even just
>
>   '\n\n\n'
>
> Those are valid XML and valid XML-RPC, but  isn't.
>
> Thanks for any thoughts...
>
>
> --
> martin | http://madduck.net/ | http://two.sentenc.es/
>
> a farmer is a man outstanding in his field.
>
> spamtraps: [EMAIL PROTECTED]


No real idea, but to me it seems like a decent way to be double-sure that
you actually got the complete and correct dump-file... otherwise, you might
be just missing part of it... maybe there's a real reason though?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: request for Details about Dictionaries in Python

2008-03-14 Thread Michael Wieher
2008/3/14, Gerardo Herzig <[EMAIL PROTECTED]>:
>
> Saideep A V S wrote:
>
> >Hello Sir,
> >
> >   Thank You a ton. I was looking for this function. As far what I've
> >understood from the "Shelve" module is that, there would be no memory
> >wastage and the whole transactions would be done from and to the file we
> >specify. Am I right?.
> >
> >  My actual task is to build a basic dictionary for two languages and
> store
> >word and its meaning in another language in a file and must be able to
> >access it through on-disk Hash tables. as these would be saving memory
> space
> >for a huge data.
> >
> >so, I hope shelve is the right one, I am searching for., I shall try out
> >with the function.
> >
> >
> >Thank You once again.
> >
> >Cheers,
> >Saideep
> >
> >
> >
> Plz remember allways reply to the python group also. They are many many
> many ones to know more than i do!
> Well, i dont quite think that it would be "no memory wastage", since
> when you read/write from disk, there is memory involved in the process.
>
> I *really* believe that, when data goes huge, a *real* database (like
> postgres, and others) has to come and play the game.
>
> Hope that helps
>
> Gerardo
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I'm not sure if a well-written file/seek/read algorithm is faster than a
relational database...
sure a database can store relations and triggers and all that, but if he's
just doing a lookup for static data, then I'm thinking disk IO is faster for
him?  not sure
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Urgent : How to do memory leaks detection in python ?

2008-03-14 Thread Michael Wieher
2008/3/14, Pradeep Rai <[EMAIL PROTECTED]>:
>
> Dear All,
>
> I am working on the python tools that process a huge amount of GIS data.
> These tools encountering the problem of memory leaks.
>
> Please suggest what are the different ways to detect the memory leaks in
> python ?
>
> This is very critical problem for me. Help needed urgently.
>
> Thanks & Regards,
>
> Pradeep
>

Python doesn't have memory leaks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: find string in file

2008-03-14 Thread Michael Wieher
2008/3/14, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> Hi friends !!
>
> I'm neophite about python, my target is to create a programa that
> find  a specific string in text file.
> How can do it?
>
> Thanks
> fel
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If your only goal is to find a string in a file, just use grep
>grep -i 'string' filename

its a standard linux command =)

But if you must use python

data=file(filename,'r').read()
if string in data:
   return True
return False
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: "Attribute Doesnt Exist" ... but.... it does :-s

2008-03-13 Thread Michael Wieher
2008/3/13, Robert Rawlins <[EMAIL PROTECTED]>:
>
> Hi Guys,
>
> Well thanks for the response, I followed your advice and chopped out all
> the
> crap from my class, right down to the bare __init__ and the setter method,
> however, the problem continued to persist.
>
> However, Robert mentioned something about unindented lines which got me
> thinking so I deleted my tab indents on that method and replaces them with
> standard space-bar indents and it appears to have cured the problem.
>
> Usually my Eclipse IDE throws up an error about this but for some reason
> decided not too this time around, what a PITA.
>
> Thanks for the ideas guys, I appreciate it.
>
> Robert
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> ]
> On Behalf Of Robert Bossy
> Sent: 13 March 2008 15:51
> To: python-list@python.org
> Subject: Re: "Attribute Doesnt Exist" ... but it does :-s
>
> Robert Rawlins wrote:
> >
> > Hello Guys,
> >
> > I've got an awfully aggravating problem which is causing some
> > substantial hair loss this afternoon J I want to get your ideas on
> > this. I am trying to invoke a particular method in one of my classes,
> > and I'm getting a runtime error which is telling me the attribute does
> > not exist.
> >
> > I'm calling the method from within __init__ yet it still seems to
> > think it doesn't exist.
> >
> > Code:
> >
> > # Define the RemoteDevice class.
> >
> > class *remote_device*:
> >
> > # I'm the class constructor method.
> >
> > def *__init__*(/self/, message_list=/""/):
> >
> > /self/.set_pending_list(message_list)
> >
> > def *set_pending_list*(/self/, pending_list):
> >
> > # Set the message list property.
> >
> > /self/.pending_list = message_list
> >
> > And the error message which I receive during the instantiation of the
> > class:
> >
> > File: "/path/to/my/files/remote_device.py", line 22, in __init__
> >
> > self.set_pending_list(message_list)
> >
> > AttributeError: remote_device instance has no attribute
> 'set_pending_list'
> >
> > Does anyone have the slightest idea why this might be happening? I can
> > see that the code DOES have that method in it, I also know that I
> > don't get any compile time errors so that should be fine. I know it
> > mentions line 22 in the error, but I've chopped out a load of non
> > relevant code for the sake of posting here.
> >
> Hi,
> I don't get this error if I run your code. Maybe the irrelevant code
> causes the error: my guess is that there's a parenthesis mismatch or an
> undeindented line.
>
> Btw, calls to set_pending_list will fail since the name "message_list"
> is not defined in its scope. Please follow Chris Mellon's advice.
>
> Cheers,
> RB
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list




All the more reason to use VIM and set it to auto-indent / remove 4 spaces
with tab & backspace. =)
-- 
http://mail.python.org/mailman/listinfo/python-list

(off-topic) JS/DHTML export to XLS format?

2008-03-13 Thread Michael Wieher
Anyone use/know of anything looks like a spreadsheet, lives in a web-browser
and can export to XLS format?
-- 
http://mail.python.org/mailman/listinfo/python-list

string / split method on ASCII code?

2008-03-12 Thread Michael Wieher
Hey all,

I have these annoying textilfes that are delimited by the ASCII char for <<
(only its a single character) and >> (again a single character)

Their codes are 174 and 175, respectively.

My datafiles are in the moronic form

X<>Z

I need to split on those freaking characters.  Any tips on how to make split
work with these things?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Does __import__ require a module to have a .py suffix?

2008-03-12 Thread Michael Wieher
2008/3/12, mrstephengross <[EMAIL PROTECTED]>:
>
> Hi all. I've got a python file called 'foo' (no extension). I want to
> be able to load it as a module, like so:
>
>   m = __import__('foo')
>
> However, the interpreter tells me "No module named foo". If I rename
> it foo.py, I can indeed import it. Is the extension required? Is there
> any way to override that requirement?
>
> Thanks,
> --Steve
>
> --
> http://mail.python.org/mailman/listinfo/python-list


>>> m=__import__('foo')
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named foo
>>> m=__import__('foo.py')
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named foo.py
>>>
[EMAIL PROTECTED]:~/Code/Scratch$ ls
foo
[EMAIL PROTECTED]:~/Code/Scratch$
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: List Combinations

2008-03-12 Thread Michael Wieher
2008/3/12, Gerdus van Zyl <[EMAIL PROTECTED]>:
>
> I have a list that looks like this:
> [['3'], ['9', '1'], ['5'], ['4'], ['2', '5', '8']]
>
> how can I get all the combinations thereof that looks like as follows:
> 3,9,5,4,2
> 3,1,5,4,2
> 3,9,5,4,5
> 3,1,5,4,5
> etc.
>
> Thank You,
> Gerdus
>
> --


list =  [['3'], ['9', '1'], ['5'], ['4'], ['2', '5', '8']]
newList = []
for l in list:
   newList.extend(l)

#newList = [3,9,1,5,4,2,5,8]
list=[]
for l in newList:
if l not in list:
 list.append(l)

#now list is [3,9,1,5,4,2,8]

list.sort()

#now your list is in sorted order

Then, you can just write a series of for loops to spin off your data however
you like.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining the PyObject * of a class

2008-03-11 Thread Michael Wieher
2 things:

1st. there is a python mailing list for people interested in C++ extension
type stuff
2nd. SWIG is useless and overly complicated, its much easier to just
generate your own C++ code by hand, less confusion, and much more clarity.
I find no value in using anything else.
People complain about the "boilerplate" code, but honestly, copy & paste,
change three characters, and you're done.  And you know exactly what is
happening, how when and why.

2008/3/11, Chris Mellon <[EMAIL PROTECTED]>:
>
> On Tue, Mar 11, 2008 at 12:13 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:
> >
> >  "Cooper, Andrew" <[EMAIL PROTECTED]> wrote in message
> >  news:[EMAIL PROTECTED]
> ...
> >
> > | Are there any Python C API experts/SWIG experts out there that can
> help
> >  | me with this issue please.
> >
> > | I',m currently using SWIG to generate a python interface to a C DLL.
> >
> >  Some people have switched to using ctypes for this, and many other SWIG
> >  users have stopped reading clp.  But I hope someone answers who can.
> >
>
>
> Using Pyrex or Cython is likely to be much easier than using SWIG for
> this.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

BitVector read-from-file Question

2008-03-10 Thread Michael Wieher
I'm trying to read in data from large binary files using BitVector (thanks
btw, for whoever mentioned it on the list, its nice)

I'll be reading the data in as requested by the user, in (relatively) small
chunks as needed.

Problem is I can't read the whole file in at once (its ridiculously large)
and the object created by  BitVector(filename="path") doesn't include a
"seek" function (to reset the filepointer)

Any suggestions on how to this without
closing/reopening/reading(offset)/read(data) ? (thats a lot of overhead)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Need Help Building PythonQt on Windows

2008-03-09 Thread Michael Wieher
2008/3/9, Jeff Schiller <[EMAIL PROTECTED]>:
>
> Hello,




I'm creating an application using Qt (4.4 Beta atm).  I have pretty
> close to zero experience with Python (consisting of installing the
> Python interpreter, downloading a python programming and executing it
> on the command-line).
>
> I would like to invoke a Python script from my C++ Qt program and
> capture its output as a C++ structure.  It seems that PythonQt might
> be suitable for my needs.
>
> Being a Qt program, I want this thing to be cross-platform.  I'm
> having trouble getting things set up in Windows.  Has anyone had any
> experience with this?
>
> I've built Qt from source using the mingw32 compiler.  I installed
> Python 2.5 binary.  I am trying to build PythonQt from source.  As per
> http://pythonqt.sourceforge.net/#Building it says I need a "developer
> installation" of Python containing the header files and  the library
> files.  When I look at my system after installing the Python 2.5
> binary, I can see I have header files (C:\Python25\include), a 199k
> python25.lib (C:\Python25\libs) and a 2MB python25.dll
> (C:\Windows\System32\).  Have I got what I need?
>
> I have tried to set up my symbols (PYTHON_PATH, PYTHON_LIB,
> PYTHONQT_ROOT).  I generate the Makefile (using qmake) and it starts
> to build but then it fails:
>
> g++ -enable-stdcall-fixup -Wl,-enable-auto-import
> -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -shared
> -Wl,--out-implib,lib\libPythonQt.a -o lib\PythonQt.dll
> object_script.PythonQt.Debug  -L"c:\Qt\4.4.0-beta1\lib"
> "c:\Python25\libs"/python25.lib -lQtGuid4 -lQtCored4
> ./debug\PythonQt.o: In function `ZN8PythonQtC2Ei':
> C:/PythonQt-1.0/src/PythonQt.cpp:118: undefined reference to
> `_imp__Py_NoSiteFlag'
> ./debug\PythonQt.o: In function `ZN8PythonQtC1Ei':
> C:/PythonQt-1.0/src/PythonQt.cpp:118: undefined reference to
> `_imp__Py_NoSiteFlag'
> ./debug\PythonQt.o: In function
> `ZN15PythonQtPrivate11wrapQObjectEP7QObject':
> C:/PythonQt-1.0/src/PythonQt.cpp:256: undefined reference to
> `_imp___Py_NoneStruct'
> C:/PythonQt-1.0/src/PythonQt.cpp:257: undefined reference to
> `_imp___Py_NoneStruct'
> ./debug\PythonQt.o: In function
> `ZN15PythonQtPrivate7wrapPtrEPvRK10QByteArray':
> C:/PythonQt-1.0/src/PythonQt.cpp:281: undefined reference to
> `_imp___Py_NoneStruct'
> C:/PythonQt-1.0/src/PythonQt.cpp:282: undefined reference to
> `_imp___Py_NoneStruct'
> ./debug\PythonQt.o: In function
> `ZN8PythonQt13introspectionEP7_objectRK7QStringNS_10ObjectTypeE':
> C:/PythonQt-1.0/src/PythonQt.cpp:620: undefined reference to
> `_imp__PyClass_Type'
> C:/PythonQt-1.0/src/PythonQt.cpp:625: undefined reference to
> `_imp__PyClass_Type'
> C:/PythonQt-1.0/src/PythonQt.cpp:625: undefined reference to
> `_imp__PyCFunction_Type'
> ...
>
> Since I'm new to compiling Qt with mingw and completely new to python,
> I was hoping for tips on why I'm getting these errors.  If anyone has
> a better suggestion for a forum/mailing list then please let me know.
>
> Thanks,
> Jeff
>
> --
> http://mail.python.org/mailman/listinfo/python-list



Another thing to be aware of, although this might not be something you need
to worry about, is that there are debug-versions of the python libraries
that are not installed by the MSI installer on windows.  Sadly, the only way
to get these libraries is to compile Python from source on your Windows
machine, being sure to also create the debug libraries at this time.  I
don't know if you need them or not, because the error message you got was
not entirely descriptive.

~mike
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: os.chdir

2008-03-07 Thread Michael Wieher
2008/3/7, Maryam Saeedi <[EMAIL PROTECTED]>:
>
> I have a problem using os.chdir on linux. What should I do if I want to
> change to root directory? The below does not work:
>
> os.chdir("~/dir1")
>
> Thanks
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>>> os.getcwd()
'/home/michael'
>>> os.chdir("/home/")
>>> os.getcwd()
'/home

I guess just be sure your user account has rights to the directory you're
trying to change to and don't screw up the quotes?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: I cannot evaluate this statement...

2008-03-07 Thread Michael Wieher
The parentheses are there for a reason

2008/3/7, Steven D'Aprano <[EMAIL PROTECTED]>:
>
> On Fri, 07 Mar 2008 12:38:11 -0800, waltbrad wrote:
>
> > The script comes from Mark Lutz's Programming Python.  It is the second
> > line of a script that will launch a python program on any platform.
> >
> > import os, sys
> > pyfile = (sys.platform[:3] == 'win' and 'python.exe') or 'python'
> >
> > Okay, run on a win32 machine, pyfile evaluates to python.exe
> >
> > That makes sense. Because the first condition is true and 'python.exe'
> > is true. So the next comparison is 'python.exe' or 'python'  Well,
> > python.exe is true. So that value is returned to pyfile.
> >
> > Now. Run this on linux. The first condition evaluates sys.platform[:3]
> > == 'win' as false. So, the next comparison should be  'False' or
> > 'python'   -- This is because 'and' returns the first false value. But,
> > again, on linux pyfile evaluates to python.exe
>
> Not on my Linux box.
>
>
> >>> import os, sys
> >>> sys.platform
> 'linux2'
> >>> (sys.platform[:3] == 'win' and 'python.exe') or 'python'
> 'python'
>
>
>
> > Where am I going wrong.  And when will this statment make pyfile
> > evaluate to 'python' ?
>
> When the first three letters of sys.platform aren't 'win'.
>
>
>
>
> --
> Steven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regarding coding style

2008-03-07 Thread Michael Wieher
Placing 2 spaces after a period is standard, grammatically correct English,
at least as I was taught...

I don't know who Strunk or White are.  Maybe Mr. Pink has a book you can
refer to instead.

2008/3/7, K Viltersten <[EMAIL PROTECTED]>:
>
> I've been recommended reading of:
> http://www.python.org/dev/peps/pep-0008/
> and in there i saw two things that i
> need to get elaborated.
>
>
> 1. When writing English, Strunk and
> White apply.
>
> Where can i download it? Am i actually
> expected to read the whole book? How
> many people actually do aply it?
>
>
> 2. You should use two spaces after a
> sentence-ending period.
>
> For heavens sake, why? I've always been
> obstructed by the double blanks but
> tolerated them. Now, that i read that
> it actually is a recommendation, i need
> to ask about the purpose.
>
>
> Thanks for the input in advance.
>
> --
> Regards
> Konrad Viltersten
> 
> sleep- a substitute for coffee for the poor
> ambition - lack of sense to be lazy
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: hidden built-in module

2008-03-07 Thread Michael Wieher
2008/3/7, koara <[EMAIL PROTECTED]>:
>
> On Mar 5, 1:39 pm, gigs <[EMAIL PROTECTED]> wrote:
> > koara wrote:
> > > Hello, is there a way to access a module that is hidden because
> > > another module (of the same name) is found first?
> >
> > > More specifically, i have my own logging.py module, and inside this
> > > module, depending on how initialization goes,  i may want to do 'from
> > > logging import *' from the built-in logging.
> >
> > > I hope my description was clear, cheers.
> >
> > > I am using python2.4.
> >
> > you can add your own logging module in extra directory that have
> __init__.py and
> > import it like: from extradirectory.logging import *
> >
> > and builtin: from logging import *
>
>
> Thank you for your reply gigs. However, the point of this namespace
> harakiri is that existing code which uses 'import logging' ...
> 'logging.info()'... etc. continues working without any change.
> Renaming my logging.py file is not an option -- if it were, i wouldn't
> bother naming my module same as a built-in :-)
>
> Cheers.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I've never had a problem like this, but I'd imagine that you could delve
into the inner-workings of import itself and figure a way to make this
happen.  There's probably a logical-order search path it follows, and if you
can find a way to insert your module before the other, in that path, or
modify the path and point its first entry at say, a directory containing
only your module, you'd be in business.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Please keep the full address

2008-03-07 Thread Michael Wieher
I normally find this kind of back & forth useless and annoying spam but the
irony is too much to avoid commenting.

(read the following, then ...)

>
> > > "His" posts?
> >
> > Whatever.  I'm too old to worry about searching for politically correct,
> > gender neutral pronouns.
>
>
> I'm pretty sure even the most PC people wouldn't suggest using a
> masculine pronoun for an inanimate objects.
>
>
> (Ok, some probably would.)
>
> Carl Banks



Mr Banks.  Technically, the sentence should be "...pronoun for inanimate
objects"  .. OR  "...pronoun for an inanimate object."

If you're going to nitpick, then at least do it right.
-- 
http://mail.python.org/mailman/listinfo/python-list

Fwd: OT: Failed saving throw

2008-03-06 Thread Michael Wieher
build a tomb?

...or raid one?

-- Forwarded message --
From: Aahz <[EMAIL PROTECTED]>
Date: 5 Mar 2008 07:36:37 -0800
Subject: OT: Failed saving throw
To: python-list@python.org

For anyone who hasn't heard, E. Gary Gygax died yesterday.  Some people
think we should build a tomb in his honor.  ;-)
--
Aahz ([EMAIL PROTECTED])   <*>
http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of
indirection."  --Butler Lampson

--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Py-Extension Irregularity

2008-03-06 Thread Michael Wieher
Ah.  Well, that is true =)

Still, the fact of the file-pointer shifting more than 16-increments to the
right is insane.  Its a simple read(&struct,16) command.

but you're right, the problem might lie elsewhere.  I forgot that using 0
for a sentinel value in two places can confuse a complier (let alone me.)

I ended up fixing it by resetting the file-pointer to zero on re-entry, and
then manually fseeking() to the correct location each time.  Its one extra
command per iteration, but not a huge speed issue.
I feel bad using a global file object, but its that or I open/close it every
time I call the funct.

Thanks for pointing out that bit of confusion =)

2008/3/6, Gabriel Genellina <[EMAIL PROTECTED]>:
>
> En Thu, 06 Mar 2008 13:54:44 -0200, Michael Wieher
> <[EMAIL PROTECTED]> escribi�:
>
>
> > Observe.
> >
> > Python Code Snippet:
> > 
> > ...
> >  66 while i < (self.nPCodes):
> >  67# print "%s:%s" % (self.nPCodes,i)
> >  68 (c,l,sn,f,fn,sz) = tabmodule.getQuestion(i,self.mx3Path)
> >  69 if _debug and sz>0:
> >  70 _newPtrLoc = tabmodule.getMx3Ptr()
> >  71 _diff = _newPtrLoc-_oldPtrLoc
> >  72 _oldPtrLoc = _newPtrLoc
> >  73 if _diff>16:
> >  74 print _diff
> > 
> >
> > C++ Code Snippet:
> > ---
> > 189 static PyObject*
> > 190 tabmodule_getMx3Ptr(PyObject * self, PyObject * args) {
> > 191 int a;
> > 192 a=mx3File.tellg();
> > 193 return Py_BuildValue("i",a);
> > 194 }
> > ...
> >
> > 189 PyObject *
> > 190 tabmodule_getQuestion(PyObject * self, PyObject * args) {
> > 
> > 208mx3File.read((char*)&m_mdx,16);
> > 
> > 237 //if(m_mdx.size==0)
> > 238 return Py_BuildValue("ii",0,0,0,0,0,0);
> > 239 //return Py_BuildValue("ii",m_mdx.compression,
> > m_mdx.location,
> > m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
> > }
> >
> > Output==
> > [EMAIL PROTECTED]:~/MRI/tabModule$ ./tabModule.py
> > [EMAIL PROTECTED]:~/MRI/tabModule$
> >
> > None.  (ie: the _diff is always 16 or less, which is what is SHOULD be,
> > in
> > fact, it is always 16.)
>
>
> Why do you assert that? With those commented out lines, the last item
> returned by getQuestion (sz) is always 0; nothing is printed because sz==0
> and the python code never enters the outer if. From that evidence I can't
> say anything about _diff.
>
>
> > Observe
> >
> > 237 if(m_mdx.size==0)
> > 238 return Py_BuildValue("ii",0,0,0,0,0,0);
> > 239 return Py_BuildValue("ii",m_mdx.compression, m_mdx.location,
> > m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
> >
> > By uncommenting line 237 and 239, we see:
> > ...
> > 64
> > 80
> > 32
> > 32
> > 32
> > 48
> > 128
> > 160
> > 32
> > 32
> > 64
> > 
> >
> > Most of the numbers are still 16, but _diff is often larger than 16, by
> > some
> > multiple.
>
>
> I'd print m_mdx values in the C++ source.
>
>
> > How in Buddah's name is returning a Py_BuildValue() affecting a file
> > pointer
> > that isn't being used at all in the function
>
>
> I don't think this is the cause...
>
> --
> Gabriel Genellina
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Py-Extension Irregularity

2008-03-06 Thread Michael Wieher
Observe.

Python Code Snippet:

...
 66 while i < (self.nPCodes):
 67# print "%s:%s" % (self.nPCodes,i)
 68 (c,l,sn,f,fn,sz) = tabmodule.getQuestion(i,self.mx3Path)
 69 if _debug and sz>0:
 70 _newPtrLoc = tabmodule.getMx3Ptr()
 71 _diff = _newPtrLoc-_oldPtrLoc
 72 _oldPtrLoc = _newPtrLoc
 73 if _diff>16:
 74 print _diff


C++ Code Snippet:
---
189 static PyObject*
190 tabmodule_getMx3Ptr(PyObject * self, PyObject * args) {
191 int a;
192 a=mx3File.tellg();
193 return Py_BuildValue("i",a);
194 }
...

189 PyObject *
190 tabmodule_getQuestion(PyObject * self, PyObject * args) {

208mx3File.read((char*)&m_mdx,16);

237 //if(m_mdx.size==0)
238 return Py_BuildValue("ii",0,0,0,0,0,0);
239 //return Py_BuildValue("ii",m_mdx.compression, m_mdx.location,
m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
}

Output==
[EMAIL PROTECTED]:~/MRI/tabModule$ ./tabModule.py
[EMAIL PROTECTED]:~/MRI/tabModule$

None.  (ie: the _diff is always 16 or less, which is what is SHOULD be, in
fact, it is always 16.)

Observe

237 if(m_mdx.size==0)
238 return Py_BuildValue("ii",0,0,0,0,0,0);
239 return Py_BuildValue("ii",m_mdx.compression, m_mdx.location,
m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);

By uncommenting line 237 and 239, we see:
...
64
80
32
32
32
48
128
160
32
32
64


Most of the numbers are still 16, but _diff is often larger than 16, by some
multiple.

How in Buddah's name is returning a Py_BuildValue() affecting a file pointer
that isn't being used at all in the function
-- 
http://mail.python.org/mailman/listinfo/python-list

re: What is a class?

2008-03-05 Thread Michael Wieher
You import classes from modules.
-- 
http://mail.python.org/mailman/listinfo/python-list

ActiveX in Webpage?

2008-03-05 Thread Michael Wieher
Hello,

I'm trying to design a python-based web-app from scratch, based on a
standalone MFC application.
Obviously I'll be wrapping a lot of C++ functionality in custom extensions,
but is anyone aware of any documentation/techniques that could help me
"drop" an ActiveX control into a webpage, and just use it?
That, or, of course, a solid bit of writing detailing the idiosyncrasies of
MFC-wrapped Py-Extensions would be useful as well.

-Mike
-- 
http://mail.python.org/mailman/listinfo/python-list