Re: how relevant is C today?

2006-04-10 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 David Rasmussen <[EMAIL PROTECTED]> wrote:

>In my everyday work, I am forced to use a C90 only compiler, and 
>everyday I miss some C++ feature that wouldn't make my program any more 
>complex, quite the opposite. These are features like "const", no default 
>extern linkage, more typesafe enums etc. 

"const" is in C89/C90. As for the others, how about hiding a copy of GCC 
somewhere, just to use to preflight your code before actually building 
it with your compulsory broken compiler? :)
-- 
http://mail.python.org/mailman/listinfo/python-list


wiki engine (just engine) available?

2006-04-10 Thread loguser
Hello,

I'm thinking about embedding a wiki into one of my project. However, I'm
looking just for a wiki-text-processing library, not a complete out-of-box
solution.

Ideal feature set is ReStructureText, some easy way to add custom commands
(to keep my pages integrated in way Trac is doing) and (ideally) docbook
export (althrough I'm ready to write one).

Suggestions, or do this has to be just-another-wiki-project?

Thank You,

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


Re: how relevant is C today?

2006-04-10 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:

>Can anyone shed some light on the secret of Java?

Java and C#/CLR I class as "instant-software-bloat-just-add-water" 
technologies. That is, they are very popular in corporate circles, where 
the users don't get to choose what software they're running.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't pass command-line arguments

2006-04-10 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "BartlebyScrivener" <[EMAIL PROTECTED]> wrote:

>I was used to being able to run scripts by just typing the script name,
>even without the .py extension, but
>
>findmyfiles d:/notes notes*.*   does not work

The MS-DOS foundation on which Windows is built only supports a small 
number of extensions for "executable" files (.COM, .EXE and .BAT), with 
no provision for any extensions to these.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a unicode question?

2006-04-10 Thread Serge Orlov

[EMAIL PROTECTED] wrote:
> Mr. John Machin
>
> This question come form the flow codes. I use the PyXml to build a DOM
> tree.
>
> from xml.dom.ext.reader import HtmlLib
> doc =
> HtmlLib.FromHtmlUrl('http://stock.business.sohu.com/q/nbcg.php?code=600028')
> title_elem = doc.documentElement.getElementsByTagName("TITLE")[0]
> title_string = title_elem.firstChild.data
> print title_string
>
> # the title_string is unicode, but it is not "latin1" code, so I wantto
> change it.

Errr, but the title of the page is written in Chinese and it is not
supposed to be crammed into latin1 encoding. What are you trying to do
with the string after you squeezed Chinese into latin1?

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


Re: how to pipe to variable of a "here document"

2006-04-10 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:

>Question: Is there a DB-API module that can directly connect to the
>database server?

There certainly is for MySQL, which is what I mostly use.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automated Graph Plotting in Python

2006-04-10 Thread per9000
Dear shrub-makers,

if you are want to plot networks (fx. genetic networks) I can recommend
Cytoscape: http://cytoscape.org/ (some kind of openware).

The in-syntax is clean:
node1 linktype1 node2
node2 linktype1 node3
node3 linktype2 node1
etc.

But in general you are going to want to change the layout of the
network after it is plotted. If you are into genetic networks it has a
number of built-in stuff. (For 2D-plots (demand vs time) cytoscape is
not an option.)

I also recommend gnuplot (like everyone else) for making the standard
y-axis, x-axis 2D-plots. It takes some time to learn syntax, but if I
remember correctly it is pretty simple.

/Per

Then when you have found the shrubbery, you must cut down the mightiest
tree in the forest...wth *pause* a herring!

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


Re: Python 2.5 licensing: stop this change

2006-04-10 Thread Flexx
Steve Holden

>>  It was an April Fool's joke. It's not actually true.
>>
> To try and ensure this thread dies for ever, I have added a note to the 
> blog entry at
> 
>   http://pyfound.blogspot.com/2006/04/python-25-licensing-change.html
> 
> noting the fact that this was indeed an April Fool's joke.

"Python Software Foundation News: Python 2.5 Licensing Change
Saturday, April 01, 2006
Python 2.5 Licensing Change"

Look at the date =)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wiki engine (just engine) available?

2006-04-10 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
> Ideal feature set is ReStructureText, some easy way to add custom
> commands (to keep my pages integrated in way Trac is doing) and
> (ideally) docbook export (althrough I'm ready to write one).

What is Trac doing? What kind of commands are you talking about?

You can convert reST to XML, so from there it's a small XSLT step to
Docbook. There are bound to be XSLT files available for that.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't pass command-line arguments

2006-04-10 Thread Sybren Stuvel
Lawrence D'Oliveiro enlightened us with:
> The MS-DOS foundation on which Windows is built only supports a
> small number of extensions for "executable" files (.COM, .EXE and
> .BAT), with no provision for any extensions to these.

Common misconception: screensavers are simply executable files with a
.scr extension. That's why they are often used to carry viruses.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


challenging (?) metaclass problem

2006-04-10 Thread alainpoint
Hi,

I have what in my eyes seems a challenging problem.
Thanks to Peter Otten, i got the following code to work. It is a sort
of named tuple.
from operator import itemgetter
def constgetter(value):
def get(self): return value
return get
def createTuple(*names):
class TupleType(type):
pass
class T(tuple):
__metaclass__ = TupleType
def __new__(cls, *args):
if len(names) != len(args):
raise TypeError
return tuple.__new__(cls, args)
for index, name in enumerate(names):
setattr(T, name, property(itemgetter(index)))
setattr(TupleType, name, property(constgetter(index)))
return T
if __name__ == '__main__':
Point=makeTuple('x','y')
p=Point(4,7)
assert p.x==p[0]
assert p.y==p[1]
assert Point.x==0
assert Point.y==1

Now my problem is the following. I want to write a function called
createDerivedTuple in order to create a class derived from the one
created with the function createTuple, taking the parent class as first
argument:
def createDerivedTuple(parentclass,*names):
... code yet to be figured out 

The usage should be as follows:

DerivedPoint=makeDerivedTuple(Point,'z')
p=DerivedPoint(4,7,9)
assert p.x==p[0]
assert p.y==p[1]
assert p.z==p[2]
assert DerivedPoint.x==0
assert DerivedPoint.y==1
assert DerivedPoint.z==2

I am still a newbie on metaclasses but i am convinced there are elegant
solutions to this challenging problem.

Best regards

Alain

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


Help...TT Python 2.4 decompiler

2006-04-10 Thread 이광진
Title: 메시지



Hello,I am a sofware engineer in Korea.Would 
you kindly give me the way to receive(take) python deccomplier as an urgent 
business?Thanks for help..^^
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how relevant is C today?

2006-04-10 Thread Thomas Bellman
Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:

> "const" is in C89/C90.

Although with slightly different semantics from in C++...  For
instance:

static const int n = 5;
double a[n];

is valid C++, but not valid C.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"When C++ is your hammer, everything !  bellman @ lysator.liu.se
 looks like a thumb."!  Make Love -- Nicht Wahr!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-10 Thread ChaosKCW

Roger Binns wrote:

>
> No.  APSW converts it *to* Unicode.  SQLite only accepts Unicode
> so a Unicode string has to be supplied.  If you supply a non-Unicode
> string then conversion has to happen.  APSW asks Python to
> supply the string in Unicode.  If Python can't do that (eg
> it doesn't know the encoding) then you get an error.

If what you say is true, I have to ask why I get a converstion error
which states it cant convert to ASCII, not it cant convert to UNICODE?


> > Ok if SQLite uses unicode internally why do you need to ignore
> > everything greater than 127,
>
> I never said that.  I said that a special case is made so that
> if the string you supply only contains ASCII characters (ie <=127)
> then the ASCII string is converted to Unicode.  (In fact it is
> valid UTF-8 hence the shortcut).
>
> > the ascii table (256 bit one) fits into
> > unicode just fine as far as I recall?
>
> No, ASCII characters have defined Unicode codepoints.  The ASCII
> character number just happens to be the same as the Unicode
> codepoints.  But there are only 127 ASCII characters.
>
> > Or did I miss the boat here ?
>
> For bytes greater than 127, what character set is used?  There
> are hundreds of character sets that define those characters.
> You have to tell the computer which one to use.  See the Unicode
> article referenced above.

Yes I know there are a million "extended" ASCII charaters sets, which
happen to the bane of all existence. Most computers deal in bytes
nativly and the 7 bit coding still causes problems to this day. But
since the error I get is a converstion error to ASCII, not from ASCII,
I am willing to accept loss of information. You cant code unicode into
ascii without loss of information or two charcater codes. In my mind,
somewhere inside the "cursor.execute" function, it converts to ascii. I
say this because of the error msg recieved.  So I am missing how a
function which supposedly converts evereythin to unicode lands up doing
an ascii converstion ?

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


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-10 Thread ChaosKCW
>
> There's an Oracle environment variable that appears to make a
> difference: NLS_CHARSET, perhaps - it's been a while since I've had to
> deal with Oracle, and I'm not looking for another adventure into
> Oracle's hideous documentation to find out.
>

That is an EVIL setting which should not be used. The NLS_CHARSET
environment variable causes so many headaches its not worth playing
with it at all.

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


wxPython problem

2006-04-10 Thread Hubert Pitura
Hello,

I've installed openSUSE 10 64bit, Python 2.4.3 (from sources) and wxPython
2.6 (from Red Hat's rpms). When I' trying to import wx the error comes up:

>>> import wx
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-ansi/wx/__init__.py", line 
42, in ?
from wx._core import *
  File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-ansi/wx/_core.py", line 4, 
in ?
import _core_
ImportError:
/usr/lib/python2.4/site-packages/wx-2.6-gtk2-ansi/wx/_core_.so: cannot
open shared object file: No such file or directory

What is going on? Any help would be appreciated.

Greetings, Hubert.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-10 Thread Serge Orlov

ChaosKCW wrote:
> Roger Binns wrote:
>
> >
> > No.  APSW converts it *to* Unicode.  SQLite only accepts Unicode
> > so a Unicode string has to be supplied.  If you supply a non-Unicode
> > string then conversion has to happen.  APSW asks Python to
> > supply the string in Unicode.  If Python can't do that (eg
> > it doesn't know the encoding) then you get an error.
>
> If what you say is true, I have to ask why I get a converstion error
> which states it cant convert to ASCII, not it cant convert to UNICODE?

You do get error about convertion to unicode. Quote from you message:

>SQLiteCur.execute(sql, row)
>UnicodeDecodeError: 'ascii' codec can't decode byte 0xdc in position 12: 
>ordinal not in >range(128)

Notice the name of the error: UnicodeDecode or in other words
ToUnicode.


>  So I am missing how a
> function which supposedly converts evereythin to unicode lands up doing
> an ascii converstion ?

When python tries to concatenate a byte string and a unicode string, it
assumes that the byte string is encoded ascii and tries to convert from
encoded ascii to unicode. It calls ascii decoder to do the decoding. If
decoding fails you see message from ascii decoder about the error.

   Serge

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


Re: can't pass command-line arguments

2006-04-10 Thread Duncan Booth
Lawrence D'Oliveiro wrote:

> In article <[EMAIL PROTECTED]>,
>  "BartlebyScrivener" <[EMAIL PROTECTED]> wrote:
> 
>>I was used to being able to run scripts by just typing the script name,
>>even without the .py extension, but
>>
>>findmyfiles d:/notes notes*.*   does not work
> 
> The MS-DOS foundation on which Windows is built only supports a small 
> number of extensions for "executable" files (.COM, .EXE and .BAT), with 
> no provision for any extensions to these.

That is wrong on so many levels:

Windows variants such as NT/2000/XP are not based on MS-DOS in any way.

The default set of "executable" file extensions recognised by Windows is:

   .COM .EXE .BAT .CMD .VBS .VBE .JS .JSE .WSF .WSH

You can change the recognised extensions simply by setting the PATHEXT 
environment variable.

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


Giving your C/C++ Application a Python Command Line...

2006-04-10 Thread Andrew McCall
Hi Folks,

I am building an application under multiple OS's, and I wanted to give
my application

For example, the test application I am working on is a calculator and I
would like to have a menu in the GUI option to open a command line
where you can use Python commands to perfom the functions of the
application within the Python command line.  For example, if I wanted
to clear the display or display the about screen I would be able type
the command in the Python coimmand line.  To do this I think I need to
embed Python in my application, and then expose my C/C++ functions to
Python.

I have read the documents on embedding Python and I can give my
application a command line, but I am having issues exposing my C/C++
functions to Python.

Does anyone know of any tutorials or example code that show how to do
this?

Thanks,

Andrew McCall

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


GridBagSizer

2006-04-10 Thread ncf
Recently, I came across a presentation about wx.GridBagSizer while
trying to look up more info to use it in an application, however, the
presentation noted "Don't use GridBagSizer. Ever."

Can anyone please explain to me why using GridBagSizer would be such a
bad idea? Or is this only applicable when using XRC?

Presentation URI: http://yergler.net/talks/desktopapps_uk/
Presentation Dated: 20APR05
Slide Number: 9 -- "Sanity and Cross-Platform XRC"

-Ws

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


Re: Giving your C/C++ Application a Python Command Line...

2006-04-10 Thread Roman Yakovenko
On 10 Apr 2006 02:15:41 -0700, Andrew  McCall <[EMAIL PROTECTED]> wrote:
> Hi Folks,
>
> I am building an application under multiple OS's, and I wanted to give
> my application
>
> For example, the test application I am working on is a calculator and I
> would like to have a menu in the GUI option to open a command line
> where you can use Python commands to perfom the functions of the
> application within the Python command line.  For example, if I wanted
> to clear the display or display the about screen I would be able type
> the command in the Python coimmand line.  To do this I think I need to
> embed Python in my application, and then expose my C/C++ functions to
> Python.
>
> I have read the documents on embedding Python and I can give my
> application a command line, but I am having issues exposing my C/C++
> functions to Python.
>
> Does anyone know of any tutorials or example code that show how to do
> this?

You have few choices:

boost.python
http://boost.org/libs/python/doc/tutorial/doc/html/python/embedding.html

PyCXX ( embedding only )
http://cxx.sourceforge.net/

> Thanks,
>
> Andrew McCall
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython problem

2006-04-10 Thread sillyemperor

Hubert Pitura wrote:
> Hello,
>
> I've installed openSUSE 10 64bit, Python 2.4.3 (from sources) and wxPython
> 2.6 (from Red Hat's rpms). When I' trying to import wx the error comes up:
>
> >>> import wx
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-ansi/wx/__init__.py", 
> line 42, in ?
> from wx._core import *
>   File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-ansi/wx/_core.py", line 
> 4, in ?
> import _core_
> ImportError:
> /usr/lib/python2.4/site-packages/wx-2.6-gtk2-ansi/wx/_core_.so: cannot
> open shared object file: No such file or directory
>
> What is going on? Any help would be appreciated.
> 
> Greetings, Hubert.


do you install wxWidget?

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


Re: [Newbie] Referring to a global variable inside a function

2006-04-10 Thread bruno at modulix
Ernesto García García wrote:
> Hi experts,
> 
> I've built a class for parsing a user-defined list of files and matching
> lines with a user-defined list of regular expressions. It looks like this:
> 
(snip code)
> 
> But then, when I try to use my class using actions with "memory" it will
> fail:
> 
> 
> import LineMatcher
> 
> global count
> count = 0
> 
> def line_action(line, match_dictionary):
>   count = count + 1
(snip)
> 
> 
> The error is:
> 
(snip)
> UnboundLocalError: local variable 'count' referenced before assignment
> 
> 
> How would you do this?

FWIW, I would *not* use a global.

class LineAction(object):
  def __init__(self):
self.count = 0

  def __call__(self, line, match_dictionary):
self.count +=1

line_action = LineAction()

line_matcher = LineMatcher.LineMatcher()
line_matcher.add_files('*')
line_matcher.add_action(r'(?P.*)', line_action)
line_matcher.go()

HTH
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 or Python 3000?

2006-04-10 Thread Benjamin Niemann
Dennis Lee Bieber wrote:

> On Sun, 9 Apr 2006 22:15:15 -0400, "Tim Peters" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
> 
>> [John Salerno]
>> > Is 'Python 3000' just a code name for version 3.0, or will it really be
>> > called that when it's released?
>> 
>> The smart money is on changing the name to Ecstasy, to leverage
>> marketing publicity from the hallucinogenic club drug of the same
>> name.  "class" will be renamed to "rave", and the license will be
>> changed to prohibit use by people with bipolar disorder.  Either that,
>> or the name will be Python 3.0.
> 
> Or... just to save "3000" as a "time way down the road"... The next
> major version of Python will be: Python PI (and each build will add
> another digit... "3.1, 3.14, 3.141, ...")

That's actually the versioning scheme of TeX, currently being at 3.141592

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-10 Thread Paul Boddie
ChaosKCW wrote:
> >
> > There's an Oracle environment variable that appears to make a
> > difference: NLS_CHARSET, perhaps - it's been a while since I've had to
> > deal with Oracle, and I'm not looking for another adventure into
> > Oracle's hideous documentation to find out.
>
> That is an EVIL setting which should not be used. The NLS_CHARSET
> environment variable causes so many headaches its not worth playing
> with it at all.

Well, at this very point in time I don't remember the preferred way of
getting Oracle, the client libraries and the database adapter to agree
on the character encoding used for communicating data between
applications and the database system. Nevertheless, what you need to do
is to make sure that you know which encoding is used so that if you
either get plain strings (ie. not Unicode objects) out of the database,
or if you need to write plain strings to the database, you can provide
the encoding to the unicode built-in function or to the decode/encode
methods; this is much better than just stripping out characters that
can't be represented by ASCII.

Anyway, despite my objections to digging through Oracle documentation,
I found the following useful documents: the "Globalization Support"
index [1], an FAQ about NLS_LANG [2], and a white paper about Unicode
support in Oracle [3]. It may well be the case that NLS_LANG might help
you do what you want, but since the database systems I have installed
(PostgreSQL, sqlite3) seem to "do Unicode" without such horsing around,
I'm not really able to offer much more advice on this subject.

Paul

[1]
http://www.oracle.com/technology/tech/globalization/index.html
[2]
http://www.oracle.com/technology/tech/globalization/htdocs/nls_lang
faq.htm
[3]
http://www.oracle.com/technology/tech/globalization/pdf/TWP_AppDev_Unicode_10gR2.pdf

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


Is this code snippet pythonic

2006-04-10 Thread jnair
My Tead  Lead  my object counter  code seen below is not  pythonic

 class E(object):
_count = 0
def __init__(self):
E._count += 1
count = property(lambda self: E._count )

def  test():
if __name__ == "__main__":
e1 = E()
print e1.count
e2 = E()
print e2.count
e3 = E()
print e3.count

test()



if  not  waht woutld be the  pythonic way

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


Is this object counter code pythonic

2006-04-10 Thread jnair
My Team  Lead says  my object counter  code seen below is not  pythonic

 class E(object):
_count = 0
def __init__(self):
E._count += 1
count = property(lambda self: E._count )

def  test():
if __name__ == "__main__":
e1 = E()
print e1.count
e2 = E()
print e2.count
e3 = E()
print e3.count

test()



if  not  what would be the  pythonic way

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


Re: best way to install python modules on linux

2006-04-10 Thread Fabian Braennstroem
Hi,

* Robert Kern <[EMAIL PROTECTED]> wrote:
> Fabian Braennstroem wrote:
>> Hi to all,
>> 
>> thanks for your ideas! I just figured out a different way
>> using archlinux 'pacman' (package management tool like apt).
>> As a former archlinux user I am more used to adjust those
>> PKDBUILDs (kind of ebuilds under archlinux) than adjusting
>> debian packages. The downside is that apt does not know
>> anything about those installed packages (just like with
>> easyinstall and checkinstall). I am not sure, if is the best
>> way, but the installation of numpy and scipy almost worked ;-)
>> 
>> Starting numpy gives me:
>>   import numpy
>>   import linalg -> failed: /usr/lib/3dnow/libf77blas.so.2: undefined symbol: 
>> e_wsfe
>> 
>> Which looks pretty odd for me!?
>
> It looks like you are missing linking to the g2c library. If you could post 
> your
> build log to [EMAIL PROTECTED], we'll be glad to help you out.

Thanks for the suggestion. I just tried the source package
from debian experimental, which seems to work.


Greetings!
 Fabian

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


Re: Is this object counter code pythonic

2006-04-10 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> My Team  Lead says  my object counter  code seen below is not  pythonic
>
> class E(object):
>_count = 0
>def __init__(self):
>E._count += 1
>count = property(lambda self: E._count )
>
> def  test():
>if __name__ == "__main__":
>e1 = E()
>print e1.count
>e2 = E()
>print e2.count
>e3 = E()
>print e3.count
>
> test()
>
> if  not  what would be the  pythonic way

why are you using a getter (the property) instead of just exposing the
attribute ?  why not just do

class E(object):
count = 0 # instance counter
def __init__(self):
E.count += 1

?

and this is a bit backwards:

> def  test():
>if __name__ == "__main__":
>/code/
> test()

I suspect you meant to write:

if __name__ == "__main__":
def  test():
/code/
test()

or even

if __name__ == "__main__":
/code/

 



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


Re: how to make a generator use the last yielded value when it regains control

2006-04-10 Thread Azolex
Lonnie Princehouse wrote:
> Here's my take on the thing.  It only prints one term, though.
> 
>   http://www.magicpeacefarm.com/lonnie/code/morris.py.html
>   
>   (a bit too long to post)
> 

excerpt :

def morris(seed, n):
 """..."""
 if n == 1:
 return seed
 else:
 return length_encode(morris(seed,n-1))

What's wrong with the following ?

def morris(seed,n) :
 """..."""
 for k in xrange(n-1) :
 seed=length_encode(seed)
 return seed

or even

def morris(seed,n) :
 return reduce(lambda x,y:y(x),n*[length_encode],seed)

I'd defend using recursion when it allows a more concise expression of 
an algorithm, but not in other cases.

Mmmhhh, btw, strangely, it looks like a hole in the library that you 
can't write eg

morris= lambda seed,n: reduce(operator.__rcall__,n*[length_encode],seed)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference in Python and Ruby interactive shells

2006-04-10 Thread Nick Craig-Wood
Lou Pecora <[EMAIL PROTECTED]> wrote:
>  Impressive, but YIKES, there ought to be a simpler way to do this.  I 
>  think during the development phase editing and reloading would be very 
>  common and you'd want everything updated.

Sorry I missed this thread...

This is what I use which is easy and works just fine.  I only type it
once and then press up arrow to get it back!

  import workinprogress; reload(workinprogress); del(workinprogress); from 
workinprogress import *

That gives you the module and all its globals rebound.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this object counter code pythonic

2006-04-10 Thread jnair
Ok got it .
Thanks a Lot

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


Re: Characters contain themselves?

2006-04-10 Thread Azolex
WENDUM Denis 47.76.11 (agent) wrote:
> 
> While testing recursive algoritms dealing with generic lists I stumbled 
> on infinite loops which were triggered by the fact that (at least for my 
> version of Pyton) characters contain themselves.

Note that the empty string is contained in all strings, including itself.

 >>> bool('')
False
 >>> '' in ''
True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how relevant is C today?

2006-04-10 Thread Azolex
Daniel Nogradi wrote:
>> "The Dice" (find tech jobs) has offerings
>> (last 7 days, U.S. + unrestricted) for:
>>*SQL 14,322
>>C/C++11,968
>>Java 10,143
>>...
> 
> Can anyone shed some light on the secret of Java? How is it that they
> are so high on this list?

Sun invented a roundabout strategy to enroll programmers to Java by 
first attracting the attention of the Wall Street Journal with Hotjava, 
and thus the attention of the programmers' management.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this object counter code pythonic

2006-04-10 Thread jnair
Fredrik is then this a valid "property"  use  case and pythonic  to
get/set a common varibale  across objects

class E(object):
_i = 0
def geti(self) : return E._i
def seti(self,val) : E._i = val
i = property(geti,seti)

if __name__ == "__main__":
e1 = E()
e1.i = 100
e2 = E()
print e2.i

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


Re: Automated Graph Plotting in Python

2006-04-10 Thread WEINHANDL Herbert
[EMAIL PROTECTED] schrieb:
> My python program spits lot of data. I take that data and plot graphs
> using OfficeOrg spredsheet. I want to automate this task as this takes
> so much of time. I have some questions.
>
> 1. Which is the best graph plotting utility in python or linux. Can I
> write a code in such a way that my python code automatically gives me a
> graph. I know little about gnuplot. If you know any better tool without
> much learning curve please tell me in Linux.

if you want to plot graphs :

use pydot the wrapper for graphviz
  http://dkbza.org/pydot.html
  http://www.research.att.com/sw/tools/graphviz/

if you want to plot datas (2d) :
matplotlib
  http://sourceforge.net/projects/matplotlib
or (2d/3d) dislin (=a plotting library with a python-wrapper)
  http://www.dislin.de/

> 2. I want to write a script such that my python code writes to a file,
> some graph utility like gnuplot takes that data from the file and I get
> my graph ready made. Do you think its possible ?
> 
> Any feedback regarding above is appreciated.
> 
> Thanks
> 

happy pythoning

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


Re: Is this object counter code pythonic

2006-04-10 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Fredrik is then this a valid "property"  use  case and pythonic  to
> get/set a common varibale  across objects

No. you do that only if you have some kind of behavior attached - e.g. if
there are database queries to be made for returning a property or something
like that.

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


Re: how relevant is C today?

2006-04-10 Thread bruno at modulix
gregarican wrote:
> Here are a few languages I recommend most programmers should at least
> have a peek at:
> 
(snip)
> 2) Lisp - Along with FORTRAN, one of the oldest programming languages
> still in use. Pure functional programming model 

Err... Even if Lisp is the father of functional programming, it is
definitively not a 'pure' FPL.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a unicode question?

2006-04-10 Thread John Machin
E, it get's worse: not only is the title written in Chinese, it
is encoded as gb2312 -- here is the repr() of the first few chunks:

"\n\n\xd6\xd0\xb9\xfa\xca\xaf\xbb\xaf(600028) :
\xc4\xd
a\xb2\xbf\xc8\xcb\xd4\xb1\xb3\xd6\xb9\xc9 -
\xcb\xd1\xba\xfc\xb9\xc9\xc6\xb1\n\n"

and here is what you get after that_guff.decode('gb2312')

u"\n\n\u4e2d\u56fd\u77f3\u5316(600028) :
\u5185\u90e8\u
4eba\u5458\u6301\u80a1 - \u641c\u72d0\u80a1\u7968\n\n"

The first 2 characters of the title are recognisable both visually on
the browser title and in the unicode as "zhong guo" i.e. China.

BUT the OP's first message is interpreting that gb2312-encoded stuff as
Unicode:
s1 = u'\xd6\xd0\xb9\xfa\xca\xaf\xbb\xaf(600028) '

*SOMEBODY* is seriously deluded, and it ain't me, and it ain't Serge
:-)

... and yes Peter, info travels faster also from China that it does
from Armenia :-())

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


Re: can't pass command-line arguments

2006-04-10 Thread BartlebyScrivener
>> That is wrong on so many levels

Including the level where I observed that I'd already been running
scripts without typing the .py extension for months, it's just that on
some scripts (seems to be the ones with functions defined in them) you
can't pass arguments unless you type the .py extension.

Anyway, thanks all.

rpd

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


Re: PC-104 LINUX 512KB 1MB

2006-04-10 Thread [EMAIL PROTECTED]
err...this is chinese..

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


Re: Is this object counter code pythonic

2006-04-10 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> Fredrik is then this a valid "property"  use  case and pythonic  to
> get/set a common varibale  across objects

A valid poperty use case would be one where you did something that couldn't 
be done without using a property.

In some other languages you cannot simply change a public attribute into a 
property, so you have to decide up front whether an attribute might ever 
need to become a property. Since most programmers have at best only an 
imperfect knowledge of the future, advice for those programming in such 
languages is to never make attributes public.

Python isn't like that: if it needs to be a property, because you must do 
something which special on either setting or accessing the value, then use 
a property. If you don't need a property today, then just use an attribute. 
You can change it into a property tomorrow when you find it needs to be a 
property.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorators, Identity functions and execution...

2006-04-10 Thread Christos Georgiou
On Sun, 09 Apr 2006 11:42:34 -0300, rumours say that Jorge Godoy
<[EMAIL PROTECTED]> might have written:

>Indeed.  This is correct.  Fredrick's comment was related to the lack of
>indentation in your code.

His code was indented fine, as you maybe noticed later on.  The actual
problem was that he had tabs, so Fredrik's Outlook Express (and I guess
other newsreaders too) did not show indentation.

Fredrik suggested already the typical "use spaces, not tabs"; I just thought
that "lack of indentation" was unfair for the OP.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't pass command-line arguments

2006-04-10 Thread Tim Golden

BartlebyScrivener wrote:
> I'm still new at this. I can't get this to work as a script. If I just
> manually insert the values for sys.argv[1] and sys.argv[2] it works
> fine, but I can't pass the variables from the command line. What am I
> doing wrong?  On windows xp, python 2.4.3
>

[... snip code ...]>

Did you see this thread a little while ago?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8ed6d03307df1a6a/60d017deadbac420#60d017deadbac420

In summary, it suggests looking at FTYPE and ASSOC,
and in particular at the %* param to FTYPE

The business of typing the .py or not is as secondary issue,
I suspect, and as someone else pointed out is governed by
the PATHEXT env var.

TJG

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


Re: Automated Graph Plotting in Python

2006-04-10 Thread Neal Becker
Felipe Almeida Lessa wrote:

> Em Sáb, 2006-04-08 às 20:08 -0700, [EMAIL PROTECTED] escreveu:
>> My python program spits lot of data. I take that data and plot graphs
>> using OfficeOrg spredsheet. I want to automate this task as this takes
>> so much of time. I have some questions.
> 
> You can try ReportLab (www.reportlab.org). Great tool.
> 

xmgrace if you have Motif.  Easy enough to pipe your python output to it.

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

Re: Python 3.0 or Python 3000?

2006-04-10 Thread Christos Georgiou
On 9 Apr 2006 20:32:07 -0700, rumours say that "Ray" <[EMAIL PROTECTED]>
might have written:

>Dennis Lee Bieber wrote:
>>  Or... just to save "3000" as a "time way down the road"... The next
>> major version of Python will be: Python PI (and each build will add
>> another digit... "3.1, 3.14, 3.141, ...")
>
>I like this idea a lot. This way, people ALWAYS know what the next
>release's name will be.

Who gave the time machine to the Donald Knuth?  Have we got infiltrators?
Or did he steal it?

In other news, the unnamed chief of the PSU has stat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: challenging (?) metaclass problem

2006-04-10 Thread alainpoint
Now, a tab-free version of my previous post. (Sorry for the
inconvenience)
Hi,


I have what in my eyes seems a challenging problem.
Thanks to Peter Otten, i got the following code to work. It is a sort
of named tuple.
from operator import itemgetter
def constgetter(value):
def get(self): return value
return get
def createTuple(*names):
class TupleType(type):
pass
class T(tuple):
__metaclass__ = TupleType
def __new__(cls, *args):
if len(names) != len(args):
raise TypeError
return tuple.__new__(cls, args)
for index, name in enumerate(names):
setattr(T, name, property(itemgetter(index)))
setattr(TupleType, name, property(constgetter(index)))
return T
if __name__ == '__main__':
Point=makeTuple('x','y')
p=Point(4,7)
assert p.x==p[0]
assert p.y==p[1]
assert Point.x==0
assert Point.y==1


Now my problem is the following. I want to write a function called
createDerivedTuple in order to create a class derived from the one
created with the function createTuple, taking the parent class as first

argument:
def createDerivedTuple(parentclass,*names):
... code yet to be figured out 


The usage should be as follows:


DerivedPoint=makeDerivedTuple(Point,'z')
p=DerivedPoint(4,7,9)
assert p.x==p[0]
assert p.y==p[1]
assert p.z==p[2]
assert DerivedPoint.x==0
assert DerivedPoint.y==1
assert DerivedPoint.z==2


I am still a newbie on metaclasses but i am convinced there are elegant

solutions to this challenging problem. 


Best regards 


Alain

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


Re: Python 3.0 or Python 3000?

2006-04-10 Thread Christos Georgiou
On Sun, 9 Apr 2006 22:15:15 -0400, rumours say that "Tim Peters"
<[EMAIL PROTECTED]> might have written:

>[John Salerno]
>> Is 'Python 3000' just a code name for version 3.0, or will it really be
>> called that when it's released?

>The smart money is on changing the name to Ecstasy, to leverage
>marketing publicity from the hallucinogenic club drug of the same
>name.  "class" will be renamed to "rave", and the license will be
>changed to prohibit use by people with bipolar disorder.

Anything to do with recent rumours about license change?  Will programming
in Python finally be outlawed, as it should be from the start (it's so
pleasing after all, it should be illegal)?  There will be a charge per line
(of code)?  Shall we become code sniffers?

>Either that, or the name will be Python 3.0.

That's what we, as cautious merchands dealing with unknown clients, should
call our product.  Excellent.

PS ("Mwa" + "ha"*sys.maxint) still won't work, though.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't pass command-line arguments

2006-04-10 Thread Duncan Booth
BartlebyScrivener wrote:

>>> That is wrong on so many levels
> 
> Including the level where I observed that I'd already been running
> scripts without typing the .py extension for months, it's just that on
> some scripts (seems to be the ones with functions defined in them) you
> can't pass arguments unless you type the .py extension.
> 
There is a problem (which I think is finally fixed in XP) where you 
couldn't redirect I/O when running Python scripts via PATHEXT, but that 
doesn't sound like your problem.

Defining functions, or not, doesn't sound like it should affect the 
arguments, except maybe if making your script longer had an effect, but I 
have no problems running a long script with arguments.

What does the command "ftype Python.File" print on your system? If it is 
wrong that could easily stop arguments being passed to scripts run by 
entering the script name, but it ought to break them all whether or not you 
type the extension explicitly.

The only other thing I can think is that you might already have a 
findmyfiles.bat (or cmd/com/exe etc.) which is the one being picked up in 
place of the Python script when you don't specify an extension. That could 
certainly explain the behaviour.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Locate" command in Python

2006-04-10 Thread Adonis
BartlebyScrivener wrote:
> How about one of these that works on Windows XP? I know there's no
> files.cache, but I wonder if your script could be combined with another
> function that would generate a list of paths on a Windows XP machine.
> 
> Anyway, thanks for the script.
> 

I wrote it on a Windows XP machine. The files.cache is generated when 
you use the -u option. For example if you saved the script as locate.py 
first at a command prompt: python locate.py -u this will create the 
files.cache, it simply walks through your entire hard drive writing all 
the directories and files it finds along the way. Then doing: python 
locate.py SomeFileOrDirName  will go through the files.cache matching 
whatever term your looking for if present. Although the rootPath 
variable is set to the POSIX style path of "/" Python converts it to a 
proper path. At least thats my assumption as it works fine on my system.

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


Re: can't pass command-line arguments

2006-04-10 Thread BartlebyScrivener
Tim,

I had not seen the thread you linked to. I learned something, but it
still doesn't explain whatever is happening on my machine. When I run
assoc and ftype I get exactly the results you say I need to run the
scripts properly. However, this simple script (printargs.py) seems to
work whether I type the .py extention or not.

import os
import sys

print sys.argv
print sys.argv[0]
print sys.argv[1]
print sys.argv[2]

Whereas this more complex script (cbfindfiles.py) will NOT work unless
I type the .py extension. Otherwise the arguments don't seem to pass.

import os
import fnmatch
import sys

def all_files(root, patterns='*', single_level=False,
yield_folders=False):
"""walks the directory tree starting at root and finds all files
matching patterns"""
# Expand patterns from semicolon-separated string to list
patterns = patterns.split(';')
for path, subdirs, files in os.walk(root):
if yield_folders:
files.extend(subdirs)
files.sort()
for name in files:
for pattern in patterns:
if fnmatch.fnmatch(name, pattern):
yield os.path.join(path, name)
break
if single_level:
break
if __name__ == "__main__":
for path in all_files(sys.argv[1], sys.argv[2]):
print path

It's not big deal. I don't mind typing the .py extension. It's just a
curious quirk. Thanks for your help.

Rick

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


Re: how relevant is C today?

2006-04-10 Thread gregarican
bruno wrote:

> Err... Even if Lisp is the father of functional programming, it is
> definitively not a 'pure' FPL.

True. I couldn't referred to something like Haskell as being pure FP.
My bad :-)

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


RE: can't pass command-line arguments

2006-04-10 Thread Tim Golden
[BartlebyScrivener]

| I had not seen the thread you linked to. I learned something, but it
| still doesn't explain whatever is happening on my machine. When I run
| assoc and ftype I get exactly the results you say I need to run the
| scripts properly. However, this simple script (printargs.py) seems to
| work whether I type the .py extention or not.

| Whereas this more complex script (cbfindfiles.py) will NOT work unless
| I type the .py extension. Otherwise the arguments don't seem to pass.

Well, just to confirm, it works fine for me with:

python.file="C:\Python24\python.exe" "%1" %*

but if it always succeeds with the .py extension, it's not the file
association which is getting in the way. I think someone else has
suggested checking for non-python files of the same name. (Did you
have a batch file which wrapped the python script? Some people do
that to get more control over parameters).

I've just checked the thread, and you don't seem to say what
*does* happen when you run the script, so I'm not sure how
certain you are that the params *aren't* getting through.
Have you stuck a "print sys.argv" at the top of the 
"if __name__ == '__main__'" section? etc. etc. 

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Characters contain themselves?

2006-04-10 Thread WENDUM Denis 47.76.11 (agent)


gry@ll.mit.edu wrote:
> In fact, not just characters, but strings contain themselves:
> 
> 
'abc' in 'abc'
> 
> True
> 
> This is a very nice(i.e. clear and concise) shortcut for:
> 
> 
'the rain in spain stays mainly'.find('rain') != -1
> 
> True
> 
> Which I always found contorted and awkward.
> 
> Could you be a bit more concrete about your complaint?
> 
> -- George
> [Thanks, I did enjoy looking up the Axiom of Foundation!]
Here is the minimal context triggering an infinite descent in recursion.
 From the answers I've got it seems I'll have to check if I'm iterating
on a string or on another kind of "list".
> python
Python 2.3.5 (#2, Feb  9 2005, 00:38:15)
[GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.setrecursionlimit(10)
>>> def f(List):
...   try: # assuming List supports iteration
...   new=[f(item) for item in List]
...   except:# if no iteration is possible
...   new=1
...   return new
...
>>> f([1, [2,3]]) # f substitutes each non iterable item by 1 (silly butshows 
>>> the problem)
[1, [1, 1]]
>>> f([1, [2.3, (5,6,7)]])
[1, [1, [1, 1, 1]]]
>>> f('bac')
1]]], [[[1]]], [[[1
>>> sys.setrecursionlimit(5)
>>> f('bac')
[[[1]], [[1]], [[1]]]
>>> # each item in 'bac' is a character, 
ie. a string of length one on wich one can iterate
and so triggers an infinite descent of recursion.
  ...

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


Re: can't pass command-line arguments

2006-04-10 Thread BartlebyScrivener
Thanks, Duncan

Results of my ftype command

d:\python>ftype python.file
python.file="C:\Python24\python.exe" "%1" %*

See below, the response with examples to Tim. I'm not worried about it.

Thank you all for the education.

rick

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


Re: any() and all() on empty list?

2006-04-10 Thread Piet van Oostrum
> "Steve R. Hastings" <[EMAIL PROTECTED]> (SRH) wrote:
[snip]
>SRH> vowels = frozenset("aeiouAEIOU")
>SRH> f = open("a_file.txt")  # note that f is an iterator

>SRH> counts = tally(line[0] in vowels for line in f)

tally([line[0] in vowels for line in f])

>SRH> # counts is a dict; counts.keys() == [False, True]

No guarantee about the order. It could be [True, False]. 

>SRH> count_nonvowels, count_vowels = counts.values()

So you must use counts[False] and counts[True].

-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating an event loop

2006-04-10 Thread Larry Bates
Fabian Steiner wrote:
> Hello!
> 
> I am currently wondering how to write something like an "event loop".
> For example, if I want to write a function that checks whether a file
> was added or removed in a directory I would think of a "while 1: ..."
> construct that checks the mtime of the directory. Is this the right way
> to achieve the exepected result or are there any better ways?
> 
> Cheers,
> Fabian

You didn't mention what platform you were working on.  Google turns up
the following items.

These links might be beneficial if it is Windows:

http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html


If it is Linux:

http://pyinotify.sourceforge.net/

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


Re: how relevant is C today?

2006-04-10 Thread Rune Strand

gregarican wrote:
> 1) Smalltalk - The original object oriented programming language.
> Influenced anything from Mac/Windows GUI to Java language.

No. Simula is the "original object oriented programming language".

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


Problem embedding Python...

2006-04-10 Thread Andrew McCall
Hi Folks,

I have now managed to work out how to embed Python to allow me to
script my application, the only problem is I am getting a compiler
error when I try to compile:

The error is:

Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and
Settings\andy.mccall\Desktop\PythonEmbed\main.cpp" -o "C:\Documents and
Settings\andy.mccall\Desktop\PythonEmbed\main.exe"
-I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"
-I"C:\Dev-Cpp\include\c++\3.4.2\backward"
-I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"
-I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"
-I"C:\Python24\include"   -L"C:\Dev-Cpp\lib" -L"C:\Python24\Lib"
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x2b):main.cpp:
undefined reference to `_imp__Py_Initialize'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x3e):main.cpp:
undefined reference to `_imp__PyString_FromString'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x4e):main.cpp:
undefined reference to `_imp__PyImport_Import'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x68):main.cpp:
undefined reference to `_imp__PyModule_GetDict'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x80):main.cpp:
undefined reference to `_imp__PyDict_GetItemString'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x96):main.cpp:
undefined reference to `_imp__PyCallable_Check'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0xb7):main.cpp:
undefined reference to `_imp__PyObject_CallFunction'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0xcd):main.cpp:
undefined reference to `_imp__PyInt_AsLong'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x146):main.cpp:
undefined reference to `_imp__Py_Finalize'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x17c):main.cpp:
undefined reference to `_imp__PyArg_ParseTuple'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x1a6):main.cpp:
undefined reference to `_imp__Py_BuildValue'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x1c2):main.cpp:
undefined reference to `_imp__PyImport_AddModule'
C:\DOCUME~1\ANDY~1.MCC\LOCALS~1\Temp/cckhbaaa.o(.text+0x1f0):main.cpp:
undefined reference to `_imp__Py_InitModule4'
collect2: ld returned 1 exit status

Execution terminated

Can anyone help me please?

Thanks,

Andrew.

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


Re: StringIO.readline() returns ''

2006-04-10 Thread [EMAIL PROTECTED]
You can also just type buf.getvalue() which returns the current
StringIO buffer as a python string, without the rewinding

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


Re: can't pass command-line arguments

2006-04-10 Thread BartlebyScrivener
Tim,

No conflicting bat file.

Script name cbfindfiles.py

import os
import fnmatch
import sys

def all_files(root, patterns='*', single_level=False,
yield_folders=False):
"""walks the directory tree starting at root and finds all files
matching patterns"""
# Expand patterns from semicolon-separated string to list
patterns = patterns.split(';')
for path, subdirs, files in os.walk(root):
if yield_folders:
files.extend(subdirs)
files.sort()
for name in files:
for pattern in patterns:
if fnmatch.fnmatch(name, pattern):
yield os.path.join(path, name)
break
if single_level:
break
if __name__ == "__main__":
print sys.argv
for path in all_files(sys.argv[1], sys.argv[2]):
print path

If I run

cbfindfiles.py d:/ *emacs*

from the command prompt I get:

['d:\\python\\cbfindfiles.py', 'd:/', '*emacs*']
followed by a list of matching files

If I run

cbfindfiles d:/ *emacs*

If get an empty command prompt back.

Oh, well.

Not worth troubling over.

Thank you again.

Rick

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


Re: how relevant is C today?

2006-04-10 Thread John Salerno
Ray wrote:
> John Salerno wrote:
>>> At which level in the 'python challenge' did
>>> you get stuck - and why?
>> Ugh, don't remind me! :)
>>
>> I'm stuck on level 12, which is yet another image processing puzzle. I'm
>> getting tired of those, and I think it's really a shame that there is a
> 
> This is EXACTLY why I am still stuck on level 12 for many months. The
> first few ones are fun. That sequence thing is also particularly fun.
> 
> But after a while, it seems that it's an image after image after image
> after image. I just got sick of PIL :) 
> 
> 
> 

And it is surprisingly difficult to find solutions anywhere! People 
really want to keep them a secret! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how relevant is C today?

2006-04-10 Thread Philippe Martin
Hi,

It is very hard to avoid C in embedded/low-level/industrial programming.

Philippe



John Salerno wrote:

> Because of my 'novice-ness' in programming, I had always thought that C
> was replaced by C++ and wasn't really used anymore today. I know that's
> not the case at all now, but I'm still curious how much C is used
> anymore in programming today, and what purpose it serves. Is it used for
> actual application programming, or is its use more for something like
> extending Python? Would it help for a newbie to learn C for any reason?

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


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-10 Thread ChaosKCW

>
> When python tries to concatenate a byte string and a unicode string, it
> assumes that the byte string is encoded ascii and tries to convert from
> encoded ascii to unicode. It calls ascii decoder to do the decoding. If
> decoding fails you see message from ascii decoder about the error.
>
>Serge

Ok I get it now. Sorry for the slowness. I have to say as a lover of
python for its simplicity and clarity, the charatcer set thing has been
harder than I would have liked to figure out. 

Thanks for all the help.

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


Re: "Locate" command in Python

2006-04-10 Thread BartlebyScrivener
Adonis,

Cool! I'm on it. 

Thanks again.

rpd

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


About classes and OOP in Python

2006-04-10 Thread fyhuang
Hello all,

I've been wondering a lot about why Python handles classes and OOP the
way it does. From what I understand, there is no concept of class
encapsulation in Python, i.e. no such thing as a private variable. Any
part of the code is allowed access to any variable in any class, and
even non-existant variables can be accessed: they are simply created.
I'm wondering what the philosophy behind this is, and if this
behaviour is going to change in any future release of Python.

It seems to me that it is difficult to use OOP to a wide extent in
Python code because these features of the language introduce many
inadvertant bugs. For example, if the programmer typos a variable name
in an assignment, the assignment will probably not do what the
programmer intended.

Ruby does something with this that I think would be excellent as an
inclusion in Python (with some syntax changes, of course). If private
variables require a setter/getter pair, we can shortcut that in some
way, i.e. (pseudocode):

class PythonClass:
   private foo = "bar"
   private var = 42
   allow_readwrite( [ foo, var ] )

Or allow_read to only allow read-only access. Also there might be a
way to implement custom getters and setters for those times you want
to modify input or something:

class PythonClass:
   def get foo():
   return "bar"

   def set var( value ):
   var = value

Anyways, these are just some speculatory suggestions. My main question
is that of why Python chooses to use this type of OOP model and if it
is planned to change.

Thanks!

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


Re: can't pass command-line arguments

2006-04-10 Thread Peter Hansen
BartlebyScrivener wrote:
> No conflicting bat file.

What about a conflicting non-BAT file?  Anything in PATHEXT ahead of the 
.PY extension is a candidate...


> if __name__ == "__main__":
> print sys.argv
> for path in all_files(sys.argv[1], sys.argv[2]):
> print path
> 
> If I run
> 
> cbfindfiles.py d:/ *emacs*
> 
> from the command prompt I get:
> 
> ['d:\\python\\cbfindfiles.py', 'd:/', '*emacs*']
> followed by a list of matching files
> 
> If I run
> 
> cbfindfiles d:/ *emacs*
> 
> If get an empty command prompt back.

Then it's very likely not running this file...  what if you put a print 
at the very top of that file, saying just this:

 print "running",__file__

If you don't see that, I think you have pretty good confirmation that it 
is *not* in fact running that file.

> Oh, well.
> 
> Not worth troubling over.

But it is.  To help others.  Perhaps what you are encountering is a real 
bug, and solving it could avoid us having to deal with the same issue in 
the future (though it seems more likely it's something special to your 
case, but at least then we'll have a clear answer).  Please reconsider 
and investigate further.

If you run the following script and pass it the name "cbfindfiles", it 
will print out a list of all files in the PATH that might be executed 
when you type that name, in the order of the possible extensions in 
PATHEXT.  While you may be sure there's no .BAT file with that name, 
maybe there is another with some other extension.

import sys
import os

name = sys.argv[1]
for dir in ['.'] + os.environ['PATH'].split(';'):
 path = os.path.join(dir, name)
 for ext in os.environ.get('PATHEXT', '').split(';'):
 fullpath = path + ext
 if os.path.isfile(fullpath):
 print fullpath


-Peter

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


Re: Python 2.5 licensing: stop this change

2006-04-10 Thread Aahz
In article <[EMAIL PROTECTED]>,
Steve Holden  <[EMAIL PROTECTED]> wrote:
>
>To try and ensure this thread dies for ever, I have added a note to the 
>blog entry at
>
>   http://pyfound.blogspot.com/2006/04/python-25-licensing-change.html
>
>noting the fact that this was indeed an April Fool's joke.

That's what you *say*, but in fact the PS
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"Look, it's your affair if you want to play with five people, but don't
go calling it doubles."  --John Cleese anticipates Usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this code snippet pythonic

2006-04-10 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> My Tead  Lead  my object counter  code seen below is not  pythonic

I'm guessing this was supposed to say "My team lead says my " (?)

>  class E(object):
> _count = 0
> def __init__(self):
> E._count += 1
> count = property(lambda self: E._count )

Is this supposed to work in a threaded environment?  If so, you'll at 
least need to add an acquire/release pair using a threading.Lock()...

> if  not  waht woutld be the  pythonic way

Other comments:

1. Why the property?  Can't you just access ._count directly?

2. You don't need the "self" in the lambda, since you're not using it 
anyway.

3. There aren't any comments.  At the least there ought to be one above 
"_count = 0" telling the reader what the variable is for.

4. Why are you asking us?  The term "pythonic" doesn't have a fixed 
definition, so asking your "Tead Lead" makes more sense.  From us you 
might learn something, but the result might still not satisfy the one 
person you need to satisfy with this.  Maybe all he wants is to see a 
getter method instead of the lambda...

-Peter

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


Query : sys.excepthook exception in Python

2006-04-10 Thread Pramod, TK
Title:  Query : sys.excepthook exception in Python






Hi,


Sometimes during execution of python scripts below mentioned error string is displayed on the console. 


"Unhandled exception in thread started by  Error in sys.excepthook:  

Original exception was:"


The scripts are not terminated, they continue to execute normally.


Is this is a problem with python? Is there any known solution.


I am using Python 2.4.


Thanks in Advance


With Best Regards,

Pramod TK






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

Re: About classes and OOP in Python

2006-04-10 Thread [EMAIL PROTECTED]
You can do this in Python as well. Check out the property built-in
function. One can declare a property with a get, set, and delete
method. Here's a small example of a read-only property.

class Test(object):
def getProperty(self):
return 0;

prop = property(fget = getProperty)

t = Test()

print t.prop

t.prop = 100 # this will fail

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


Re: can't pass command-line arguments

2006-04-10 Thread BartlebyScrivener
>>  print "running",__file__

Well, I tried to let this die because I just KNEW I was going to look
like an idiot before it was over. It's the .pyc versus the .py file.
Obviously I don't understand how that works yet. The .pyc file lags
behind the .py file?  So when I run cbfindfiles.py I'm running the .py
version and when I run cbfindfiles it's running the .pyc version which
is not the same between edits.

No need to explain. I'll go read up on how that .pyc file is generated.

Sorry for the trouble. 

Rick

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


Re: Query : sys.excepthook exception in Python

2006-04-10 Thread Peter Hansen
Pramod, TK wrote:
> Sometimes during execution of python scripts below mentioned error 
> string is displayed on the console.
> 
> *"Unhandled exception in thread started by  Error in sys.excepthook:  *
> *Original exception was:"*
> 
> The scripts are not terminated, they continue to execute normally.

Are you certain they are not terminated?  I've only ever seen this when 
the entire application was shutting down, and "daemon" threads which 
were still running (as they do right up until almost the moment the 
process exits) are going nuts because of the shutdown/cleanup processing 
of the interpreter.  (The key item is that at one stage the interpreter 
walks through all loaded modules, rebinding all global names in each one 
to None, and this causes havoc in most code.  The exceptions that are 
raised cannot be displayed successfully either, for the same reason, 
resulting in what you see above.)

I've also seen this in CherryPy in "development" mode, because it is 
shutting down and restarting, so although it doesn't look like it 
terminated, in effect the problem is the same.

-Peter

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


Re: Is this code snippet pythonic

2006-04-10 Thread Kent Johnson
Peter Hansen wrote:
> [EMAIL PROTECTED] wrote:
>>>  class E(object):
>> _count = 0
>> def __init__(self):
>> E._count += 1
>> count = property(lambda self: E._count )

> 2. You don't need the "self" in the lambda, since you're not using it 
> anyway.

Yes he does, it's a property getter, it will be called with self as an 
argument.

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


Re: "Locate" command in Python

2006-04-10 Thread BartlebyScrivener
This script is COOL. It should be in the next cookbook. Maybe with some
tweaks and switches.

Thanks again.

Rick

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


Re: can't pass command-line arguments

2006-04-10 Thread Peter Hansen
BartlebyScrivener wrote:
> Well, I tried to let this die because I just KNEW I was going to look
> like an idiot before it was over. It's the .pyc versus the .py file.
> Obviously I don't understand how that works yet. The .pyc file lags
> behind the .py file?  So when I run cbfindfiles.py I'm running the .py
> version and when I run cbfindfiles it's running the .pyc version which
> is not the same between edits.

I thought of that one, of course, but it can't cause exactly the trouble 
you describe above.  If there's a .py in the same folder as the .pyc, it 
will not use the .pyc unless the timestamp encoded in it matches the one 
on the .py file (which, unless you go to extraordinary lengths, will 
never screw you up that way).

On the other hand, if there was a .pyc in the current directory when you 
run it with "python cbfindfiles.py", but no cbfindfiles.py in the same 
folder, it will run the local one and not the .py which might be 
elsewhere, in your PATH.  Any chance there are cbfindfiles.py* files in 
other folders or have you been doing this all from the same folder?

> No need to explain. I'll go read up on how that .pyc file is generated.

Don't think you look like an idiot (yet :-) ).  Not only has everyone 
been caught out by this, sometimes repeatedly (ah... it happened to a 
"friend" of mine a number of times), but when you combine the weirdness 
of Windows PATHEXT and FTYPE and such, you can really get into awkward 
situations.

I do hope you'll identify precisely what the issue was, so we can keep 
it in mind (if it's a new variant), or refresh our knowledge (if it's 
just the same old same old but we didn't realize it yet).

Thanks. :-)
-Peter

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


newbie: Need Help Moving Data from Kirbybase to Gadfly

2006-04-10 Thread dc
I am fairly new to python and SQL. I have been trying to move data from
Kirbybase table to a Gadfly table and cannot get it to work. Win XP
with python 2.4, Kirbase 1.9, Gadfly B5.

Complete script shown here, with python traceback.

#   get global modules for python
import os
import sys

#get database manager module
from kirbybase import KirbyBase, KBError

# open a database, embedded
db = KirbyBase()
result=db.select('test2.tbl', ['recno'],['*'], returnType='object')

# open Gadfly database for storing data
import gadfly
connection = gadfly.gadfly()
connection.startup("subscription", "pvfd_sql")
cursor = connection.cursor()

# Insert all records into SQL Database
for record in result:
   sql="INSERT INTO addresslist (lastname, firstname, address, city,
state, zip_code, phone) VALUES(?, ?, ?, ?, ?, ?, ?)"
   cursor.execute(sql,result)
   connection.commit()
connection.close

#--
#  End of Script
#--



Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32
Type "copyright", "credits" or "license()" for more information.

   
   Personal firewall software may warn about the connection IDLE
   makes to its subprocess using this computer's internal loopback
   interface.  This connection is not visible on any external
   interface and no data is sent to or received from the Internet.
   
   IDLE 1.1.2   No Subprocess 
>>>
Traceback (most recent call last):
 File "C:\Documents and Settings\timothy volner\Desktop\puryear\move
records to sql.py", line 30, in ?
   cursor.execute(sql,result)
 File "C:\Python24\lib\site-packages\gadfly\database.py", line 367, in
execute
   cs[i] = cs[i].relbind(database)
 File "C:\Python24\lib\site-packages\gadfly\operations.py", line 601,
in relbind
   target = self.target = db.get_for_update(name)
 File "C:\Python24\lib\site-packages\gadfly\store.py", line 201, in
get_for_update
   test = rels[name]
 File "C:\Python24\lib\site-packages\gadfly\store.py", line 1043, in
__getitem__
   return self.shadow[key]
KeyError: 'ADDRESSLIST'
>>>

No matter what I do to data, I always end up with this error.

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


Re: About classes and OOP in Python

2006-04-10 Thread Roy Smith
"fyhuang" <[EMAIL PROTECTED]> wrote:
> I've been wondering a lot about why Python handles classes and OOP the
> way it does. From what I understand, there is no concept of class
> encapsulation in Python, i.e. no such thing as a private variable. Any
> part of the code is allowed access to any variable in any class, and
> even non-existant variables can be accessed: they are simply created.
> I'm wondering what the philosophy behind this is, and if this
> behaviour is going to change in any future release of Python.

There are advantages and disadvantages to C++/Java style encapsulation 
using private data.  The advantages you (apparently) already know.  The 
disadvantage is added complexity.  There's a saying, "You can't have a bug 
in a line of code you never write".  By having to write all those getter 
and setter methods, you just add bulk and complexity.

That being said, you can indeed have private data in Python.  Just prefix 
your variable names with two underscores (i.e. __foo), and they effectively 
become private.  Yes, you can bypass this if you really want to, but then 
again, you can bypass private in C++ too.   You can also intercept any 
attempt to access Python attributes by writing __getattr__() and 
__setattr__() methods for your class.

> It seems to me that it is difficult to use OOP to a wide extent in
> Python code because these features of the language introduce many
> inadvertant bugs. For example, if the programmer typos a variable name
> in an assignment, the assignment will probably not do what the
> programmer intended.

Yes, that is is a risk.  Most people deal with that risk by doing a lot of 
testing (which you should be doing anyway).  If you really want to, you can 
use the __slots__ technique to prevent this particular bug from happening 
(although the purists will tell you that this is not what __slots__ was 
designed for).

> My main question is that of why Python chooses to use this type of OOP 
> model and if it is planned to change.

It sounds like you are used to things like C++ and Java, which are very 
static languages.  Everything is declared at compile time, and there are 
many safeguards in the language to keep you from shooting yourself in the 
foot.  They problem is, they often prevent you from getting any useful work 
done either; you spend most of your time programming the language, not the 
problem you are trying to solve.

In the past week, I've had two conversations with people about the nuances 
of C++ assignment operators.  None of our customers give two figs about 
assignment operators.  Getting them right is just a detour we need to take 
to keep our software from crashing.  With Python, I write a = b and trust 
that it does the right thing.  That lets me concentrate on adding value 
that our customer will see.
-- 
http://mail.python.org/mailman/listinfo/python-list


python + access + odbc + linux

2006-04-10 Thread Philippe Martin
Hi,

I understand that access can be accessed through an ODBC driver under
windows (instead of Jet).

I am wondering if the same can be done under Linux.

Regards,

Philippe

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


python interpreter widget for Tkinter?

2006-04-10 Thread Alexandre Guimond
Hi i was wondering if there already existed a simple python interpreter
widget for tkinter? Basically, i would like to be able to lauch a
python interpreter in a seperate window from my tkinter app for
debugging purposes. I would assume that this would be possible using
idlelib, but i can't figure out how. Does anyone know how to do this?

thx for any help
alex

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


Re: can't pass command-line arguments

2006-04-10 Thread Duncan Booth
Peter Hansen wrote:

> I thought of that one, of course, but it can't cause exactly the trouble 
> you describe above.  If there's a .py in the same folder as the .pyc, it 
> will not use the .pyc unless the timestamp encoded in it matches the one 
> on the .py file (which, unless you go to extraordinary lengths, will 
> never screw you up that way).
> 
> On the other hand, if there was a .pyc in the current directory when you 
> run it with "python cbfindfiles.py", but no cbfindfiles.py in the same 
> folder, it will run the local one and not the .py which might be 
> elsewhere, in your PATH.  Any chance there are cbfindfiles.py* files in 
> other folders or have you been doing this all from the same folder?

You missed the other option: if PATHEXT has .pyc in front of .py then you 
get exactly the described behaviour.

Of course that leaves open the question why anyone would want to put .pyc 
into PATHEXT.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python + access + odbc + linux

2006-04-10 Thread Felipe Almeida Lessa
Em Seg, 2006-04-10 às 10:38 -0500, Philippe Martin escreveu:
> I understand that access can be accessed through an ODBC driver under
> windows (instead of Jet).
> 
> I am wondering if the same can be done under Linux.

As far as I know, no. But there is that http://mdbtools.sourceforge.net/
that may help you, but when I tried I had limited success.

Cheers,

-- 
Felipe.

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

Re: can't pass command-line arguments

2006-04-10 Thread BartlebyScrivener
Running the script you recommended, I get

d:\python>hansen.py cbfindfiles
.\cbfindfiles.pyc
.\cbfindfiles.py
d:\python\cbfindfiles.pyc
d:\python\cbfindfiles.py

If I use XP search, searching all drives for any file with cbfindfiles
in the name, I get just the two in d:\python.

It has something to do with importing the cbfindfiles.py file as a
module, right? Because I just did that, and now the .py and .pyc files
are synchronized, and I'm getting the same result when I run
cbfindfiles or cbfindfiles.py, whereas before I was not.

Thank you so much for your generous help.

Rick

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


Re: can't pass command-line arguments

2006-04-10 Thread BartlebyScrivener
>> You missed the other option: if PATHEXT has .pyc in front of .py then you
>> get exactly the described behaviour.

That's it!!

Trust me, I didn't do it. It was either ActiveState, Wing, or Komodo
Dragon, or some combination thereof.

So remove .pyc from pathext?

Rick

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


RE: python + access + odbc + linux

2006-04-10 Thread Tim Golden
[Philippe Martin]

| I understand that access can be accessed through an ODBC driver under
| windows (instead of Jet).
| 
| I am wondering if the same can be done under Linux.

You need to look at the mdbtools packages

http://mdbtools.sourceforge.net/

which includes a Jet-ODBC driver which can be used under
Linux via iODBC or UnixODBC and mxODBC on the Python side. 
At least in theory: I had only qualified success, and 
eventually gave up. But it was clear from the mailing 
lists that other people had succeeded.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


RE: can't pass command-line arguments

2006-04-10 Thread Tim Golden
[BartlebyScrivener]

| >> You missed the other option: if PATHEXT has .pyc in front 
| of .py then you
| >> get exactly the described behaviour.
| 
| That's it!!
| 
| Trust me, I didn't do it. It was either ActiveState, Wing, or Komodo
| Dragon, or some combination thereof.

Amazing. I had a look, and my PATHEXT has .pyc too... but *after* .py.
I was a little confused because you seemed to be running this as
a script, not importing it as a module, but it's clear from your
other post that you had imported it as a module at least once.

Just goes to show...

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: About classes and OOP in Python

2006-04-10 Thread Felipe Almeida Lessa
Em Seg, 2006-04-10 às 07:19 -0700, fyhuang escreveu:
> class PythonClass:
>private foo = "bar"
>private var = 42
>allow_readwrite( [ foo, var ] )

You are aware that foo and var would become class-variables, not
instance-variables, right?

But you can always do:

class PythonClass(object):
def __init__(self):
self.__foo = "bar"

foo = property(lambda self: self.__foo)


And then:

>>> a = PythonClass()
>>> a.foo
'bar'
>>> a.foo = 'baz'
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: can't set attribute


But you can also bypass this "security":

>>> a._PythonClass__foo = 'baz'
>>> a.foo
'baz'


But this was not a mistake, nobody mistakenly writes "_PythonClass__".

> Or allow_read to only allow read-only access. Also there might be a
> way to implement custom getters and setters for those times you want
> to modify input or something:
> 
> class PythonClass:
>def get foo():
>return "bar"
> 
>def set var( value ):
>var = value

There's a PEP somewhere that proposes things like (same example I gave
earlier):

class PythonClass(object):
def __init__(self):
self.__foo = "bar"

create property foo:
def get(self):
return self.__foo

-- 
Felipe.

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

Re: can't pass command-line arguments

2006-04-10 Thread Peter Hansen
BartlebyScrivener wrote:
>>>You missed the other option: if PATHEXT has .pyc in front of .py then you
>>>get exactly the described behaviour.
> 
> That's it!!
> 
> Trust me, I didn't do it. It was either ActiveState, Wing, or Komodo
> Dragon, or some combination thereof.
> 
> So remove .pyc from pathext?

Doing that will prevent a leftover .pyc file in a directory earlier in 
the PATH from overriding a .py file later on in the PATH.  If that was 
the specific problem, definitely remove it.

Duncan, the answer to "why anyone would want to put .pyc into PATHEXT" 
is at least "because that's how it's almost always recommended".  At 
least, I have been using that myself, probably for the same reason Rick 
did, and I can see lots of search results that list it that way.  I'm 
just glad it was he who got caught by this and found the problem, and 
not me. ;-)

I think the only reason one would want .pyc in the PATHEXT is if one 
ever wanted to run .pyc files that didn't have matching .py files, 
without having to specify the extension.  That's certainly not a common 
enough usecase to justify making ".pyc;.py" the recommended or standard 
thing to add to PATHEXT.

-Peter

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


Re: About classes and OOP in Python

2006-04-10 Thread Sion Arrowsmith
fyhuang <[EMAIL PROTECTED]> wrote:
> [ ... ] no such thing as a private variable. Any
>part of the code is allowed access to any variable in any class, and
>even non-existant variables can be accessed: they are simply created.

You're confusing two issues: encapsulation and dynamic name binding.
You might also want to check out the difference between read and
write access to non-existant variables.

>I'm wondering what the philosophy behind this is,

"We are all consenting adults." And probably experience of data
encapsulation being more of a hinderence than a benefit.

> and if this
>behaviour is going to change in any future release of Python.

I damn well hope not.

And if you want to control those writes, try this for a base class:

class restrict_set:
def __init__(self, allowed_names):
self._allowed_names = set(allowed_names)
def __setattr__(self, name, value):
if not name.startswith('_') and name not in self._allowed_names:
getattr(self, name)
self.__dict__[name] = value

(Someone else can do the new style class and the metaclass versions.)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is this code snippet pythonic

2006-04-10 Thread Felipe Almeida Lessa
Em Seg, 2006-04-10 às 03:52 -0700, [EMAIL PROTECTED] escreveu:
> My Tead  Lead  my object counter  code seen below is not  pythonic

As Peter said, you should really ask your Tead Lead, but what about:

class E(object):
"""Holds a class-wide counter incremented when it's instantiated."""
count = 0

def __init__(self):
# One instance, increment the counter
E.count += 1


def  test():
"""Test the counter class E."""
e1 = E()
assert e1.count == 1
print e1.count

e2 = E()
assert e2.count == 2
print e2.count

e3 = E()
assert e3.count == 3
print e3.count

if __name__ == '__main__':
test()

-- 
Felipe.

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

Re: can't pass command-line arguments

2006-04-10 Thread Peter Hansen
BartlebyScrivener wrote:
> It has something to do with importing the cbfindfiles.py file as a
> module, right? Because I just did that, and now the .py and .pyc files
> are synchronized, and I'm getting the same result when I run
> cbfindfiles or cbfindfiles.py, whereas before I was not.

Yes!  That's the only reason you have a .pyc file at all.  Normally, for 
little command line scripts, Python doesn't even bother saving the 
compiled code in the .pyc file.  It does, however, always do this when 
you use "import" so, having once imported it, you'll have that 
out-of-date .pyc file kicking around forever as a latent problem.

> Thank you so much for your generous help.

You're welcome, and thanks for following this through.  I still have 
machines around that have PATHEXT=.pyc;.py;... and will now remove .pyc 
from all of them.  It would probably be nice to trace this back to the 
origin, find whether there was a good rationale for it being that way in 
the first place, and either update a FAQ somewhere or get the problem 
fixed once and for all.

I don't think the standard install messes with PATHEXT, so my bet is on 
ActiveState right now.  Can anyone confirm?  Trent, if you're reading 
this and it is from ActiveState's distribution, do you know where that 
PATHEXT=.pyc;.py choice came from and whether it might have been an 
ill-advised decision that should be undone?

-Peter

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


Re: python + access + odbc + linux

2006-04-10 Thread Philippe Martin
Thanks a lot Felipe.

Regards,


Philippe


Felipe Almeida Lessa wrote:

> Em Seg, 2006-04-10 às 10:38 -0500, Philippe Martin escreveu:
>> I understand that access can be accessed through an ODBC driver under
>> windows (instead of Jet).
>> 
>> I am wondering if the same can be done under Linux.
> 
> As far as I know, no. But there is that http://mdbtools.sourceforge.net/
> that may help you, but when I tried I had limited success.
> 
> Cheers,
> 

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


twisted.web and a

2006-04-10 Thread Fabian Steiner
Hello!

I am currently working on a quite complicated application (at least for
me) and unfortunately I don't know how to go on.

I wrapped a Windows-dll by using the ctypes module so that I can access
different functions that are used to control a network device (open,
close, write/read values). Now I was asked to write something like a GUI
for it which should be based on a CGI script that calls the different
functions (read/write) with parameters entered in a text-input of a
HTML-Template.
Therefore I wrote a small HTTP-Server class based on twisted.web. In its
constructor the network device is opened (--> the wrapper class is
initiated) and is closed by the server's destructor. Now I need the same
wrapper class instance in my CGI script so that read() and write() can
be called on exactly the same instance - otherwise these methods would
fail since the network device hasn't been opened so far.

Do you have any idea how to solve this problem? I am looking forward to
any responses.

Cheers,
Fabian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't pass command-line arguments

2006-04-10 Thread BartlebyScrivener
It's ActiveState. I just did a fresh install on an old machine.

It appends pyo;pyc;pyw;py in that order to PATHEXT

Thanks again to everyone for the generous help.

Rick

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


Is there a Python MVC that works just as well with just CGI, or FCGI?

2006-04-10 Thread walterbyrd
As I understand it, django works with fcgi, but it's a pain to setup.

Are there any python MVCs that are optimized to work without
mod_python. Or any other module that isn't likely to be loaded by
standard python hosters?

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


Re: Characters contain themselves?

2006-04-10 Thread Scott David Daniels
WENDUM Denis 47.76.11 (agent) wrote:
>...  From the answers I've got it seems I'll have to check if I'm
> iterating on a string or on another kind of "list"
 import sys
 sys.setrecursionlimit(10)
 def f(List):
> ...   try: # assuming List supports iteration
> ...   new=[f(item) for item in List]
> ...   except:# if no iteration is possible
> ...   new=1
> ...   return new
 f([1, [2,3]]) # f substitutes each non iterable item by 1 (silly 
 butshows the problem)
> [1, [1, 1]]
 f([1, [2.3, (5,6,7)]])
> [1, [1, [1, 1, 1]]]
 f('bac')
> 1]]], [[[1]]], [[[1
 sys.setrecursionlimit(5)
 f('bac')
> [[[1]], [[1]], [[1]]]
 # each item in 'bac' is a character, 
> ie. a string of length one on wich one can iterate
> and so triggers an infinite descent of recursion.

I'd rewrite your 'f' as follows:
 def copier(List):
 try: # assuming List supports iteration
new = [f(item) for item in List]
 except TypeError: # Non-iterables get replaced
 return '?'
 except RuntimeError: # Recursion failures get shown
 return 'Recursion'
 return new

Note, even if you got your wish and somehow you couldn't have an issue
with characters in strings, you would have to deal with this:

simple_list = [3.1415]
container = [simple_list]
simple_list.append(container)

Your function (and mine) assumes the argument is a DAG (Directed Acyclic
Graph), but there is no such guarantee about data structures in python.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how relevant is C today?

2006-04-10 Thread Scott David Daniels
gregarican wrote:
> Here are a few languages I recommend most programmers should at least
> have a peek at:
> 
> 1) Smalltalk - The original object oriented programming language.
> Influenced anything from Mac/Windows GUI to Java language. Terse, clean
> syntax. IDE rolled into an operating system rolled into a set of core
> libraries.
Simula actually is the "original o-o language (as Smalltalk's authors
freely admit).

> 2) Lisp - Along with FORTRAN, one of the oldest programming languages
> still in use. Pure functional programming model that is extensible and
> has many derivatives. Great for mathematical purposes. Easy to learn if
> you can get past all of the nested parenthesis :-)
The functional style is not what was unique to LISP.  LISP was the first
language whose behavior was fully specified before it was implemented
(and that definition was completely machine-independent).

> 3) C - The "Latin" of modern programming languages. Used in low level
> tasks (e.g. - hardware drivers) as well as larger projects (e.g. -
> operating systems and other programming languages). Logcal, explicit
> flow albeit a bit wordy.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to call functions in Advapi32.dll using ctypes

2006-04-10 Thread Podi
> Have you tried calling InitiateSystemShutdownA mentioned in the
> documentation?

Thanks! This function exists. However,
advapi32.InitiateSystemShutdownA("", 'This is a test', 30, 1, 1)
returns 0 though. I will need to play with it a bit more...

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


Re: how to make a generator use the last yielded value when it regains control

2006-04-10 Thread Lonnie Princehouse
> What's wrong with the following ?
>
> def morris(seed,n) :
> """..."""
> for k in xrange(n-1) :
> seed=length_encode(seed)
> return seed

Nothing's wrong with it.

I happen to think the recursive version is more elegant, but that's
just me ;-)

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


Re: [fcntl]how to lock a file

2006-04-10 Thread marcello
thank you a lot for your answering
Bye
Marcello
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >