intigrate the PyGame module with my Python

2005-03-05 Thread devendra_k
I want to intigrate the PyGame module with my Python exe,
means i DONT want to generate .PYD files separtely rather than that
want to put PyGame c src with Python workspace of VC project
workspace.
I am unable to import the sub modules( display, rect etc) of pygame,
its raising errors,
am giving the steps i followed, plz help me in this case

I am stuck at the pygame embedding using microsoft visual c++ under
win2000 os.
Formarly I have done following activities :

1. Downloaded the windows binary for python 1.5.2 from python.org.
2. Downloaded the sdl windows binary package from pysdl.org.
3. successfully integrated the sdl library into the python15 project.
   A sample py script was tested successfully.

4. Downloaded pygame 1.6 source from pygame.org.
5. Integrated the code into vc project.
6. On similar lines to sdl, the necessary changes were done
   ( as pygame happens to be successor to sdl).
   Initially, the pygame module was not being recognized by the
environment.
 
 
Regards,
 
Devendra

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


Re: locale support and 4.10

2005-03-05 Thread Martin v. Löwis
Timothy Smith wrote:
  locale.setlocale(locale.LC_NUMERIC, 'us')
the exact same thing works under windows xp.
do i have to compile it with locale support?
No. You have to choose a locale name that is supported by your
operating system (which appears to be FreeBSD). Read your OS
documentation for what valid locale names are; most likely,
en_US or en_US.ISO-8859-1 are supported.
also my second question. once i have this working how do i set the 
thousands_sep character to be a , ?
You don't directly set it. It is a property of the locale.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-05 Thread Iwan van der Kleyn
Gary Nutbeam wrote:
needing to learn Ruby.
But why wouldn't you just use Rails and learn Ruby in the process? The 
effort required to learn Ruby pales in comparisson to the advantages 
using Ruby on Rails might give you, imho.

Ruby is an excellent language, not much different from Python with its 
own set of advantages and problems (I really mis python's white-space 
indentation for example, but that is fully compensated by Ruby's nice 
OOP features). With a book like Programming Ruby you would be up to 
speed in a few days.

Rails gives you much more than a comparable set of Python libraries 
which are gobled together with sticky tape. It provides you not just 
with an superbly integrated and consistent set of components. Rails 
gives you:
 - (real) automation (take a look at scaffolding for quick prototyping)
 - terrific documentation (the videos are *not* a gimmick, for example)
 - an enthousiastic, supportive user community (that alone is an 
incredible help and time saver)

have fun,
Iwan

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


Re: How to write python plug-ins for your own python program?

2005-03-05 Thread Reinhold Birkenfeld
David M. Cooke wrote:
 Simon Wittber [EMAIL PROTECTED] writes:
 
 You mean like 'import'? :)

 That's how I would do it. It's the simplest thing, that works.

 exec(import %s as plugin % pluginName)
 plugin.someMethod()

 where pluginName is the name of the python file, minus the .py extension.
 
 You'd better hope someone doesn't name their plugin
 'os; os.system(rm -rf /); import sys'
 ^
Well, that would be difficult, but rm -rf ~ would work rather nicely...

Of course, one could test pluginName that it contains only
alphanumerics, but

 Use __import__ instead.

is surely the better solution.

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


Re: Indexing strings

2005-03-05 Thread Patrick Useldinger
Fred wrote:
That was exactely what I was searching for. I needed a program, that
chopped up a string into its words and then saves them into a list. I
think I got this done...
There's a function for that: text.split().
You should really have a look at the Python docs. Also, 
http://diveintopython.org/ and http://www.gnosis.cx/TPiP/ are great 
tutorials.

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


Re: Question of speed - Flat file DBMS

2005-03-05 Thread I.V. Aprameya Rao
OK, i forgot to mention this.

The speed is a critical issue because there will be a competition and 
whosever solution is faster wins the prize.

Hence will a python solution be as fast as a C++ solution??

aprameya

On 4 Mar 2005, John Machin wrote:

 
 I.V. Aprameya Rao wrote:
  Hi
 
  I have to implement a flat file dbms. The basic condition is that
  relations will be given in files and i will have to run certain
 select
  project join queries on those relations.
 
  Can someone tell me as to which language will be faster, python or
 C++??
 
 Faster to get a working app released: Python
 
 Faster to drive you nuts: C++
 
 Faster processing the files: My hunch is C++, but not by much. After
 you've shipped your working app (in Python), you'll still have lots of
 spare time to tweak up the speed -- IF it's slow, if anybody notices,
 and if anybody cares -- and this newsgroup usually provides a lively
 response to how do I make this faster questions.
 
 
 

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


Relative imports

2005-03-05 Thread Chris
Why do relative imports cause warnings in PyLint?
A warning like this:
ID:W0403  Relative import 'myPythonFileInTheSameFolder'
When the import is like:
from myPythonFileInTheSameFolder import MyClass

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


Re: Question of speed - Flat file DBMS

2005-03-05 Thread Michael Hoffman
I.V. Aprameya Rao wrote:
The speed is a critical issue because there will be a competition and 
whosever solution is faster wins the prize.

Hence will a python solution be as fast as a C++ solution??
It depends how good you are at programming in each language. If you
are an expert C++ programmer you can surely make it go faster. But if
you were an expert C++ programmer you wouldn't be asking here.
Whenever I have done performance-critical stuff, using Pyrex has been
more than sufficient.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: io.h include file in pyconfig.h

2005-03-05 Thread Michael Hoffman
pythonnewbie wrote:
where I should find the correct io.h in this linux environment?
Should be in /usr/include/sys/io.h
You are probably missing some RPM that has various system header files.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Relative imports

2005-03-05 Thread Michael Hoffman
Chris wrote:
Why do relative imports cause warnings in PyLint?
http://www.python.org/peps/pep-0328.html#rationale-for-absolute-imports
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integer From A Float List?!?

2005-03-05 Thread Michael Hoffman
Peter Otten wrote:
From the Evil Coder's Guide to Fast Code:

 [...]

$ py24 -m timeit -s floats = map(float, range(1000)) -sfrom itertools
import starmap, izip ints = list(starmap(int, izip(floats)))
1000 loops, best of 3: 343 usec per loop
Truly evil. Why is that faster than ints = list(imap(int, floats))?
It is on my system.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: enum question

2005-03-05 Thread Stephen Toledo-Brown
M.N.A.Smadi wrote:
does python support a C-like enum statement where one can define a 
variable with prespesified range of values?
Not built in, but there are various solutions available, some simpler 
than others. See the Infrequently Asked Questions: 
http://www.norvig.com/python-iaq.html

--
Steve Toledo-Brown
Speaking for myself only.
Humans please use domain uk.ibm.com
--
http://mail.python.org/mailman/listinfo/python-list


Integer From A Float List?!?

2005-03-05 Thread andrea_gavana
Hello NG,

probably because I still have Python 2.3.4, these are the results I'm
getting:


C:\Python23\Libpython timeit.py -s floats = map(float, range(1000)) ints
= m
ap(int, floats)
1000 loops, best of 3: 398 usec per loop

C:\Python23\Libpython timeit.py -s floats = map(float, range(1000)) ints
= [
int(x) for x in floats]
1000 loops, best of 3: 820 usec per loop

C:\Python23\Libpython timeit.py -s floats = map(float, range(1000)) ints
= [
] for x in floats: ints.append(int(x))
1000 loops, best of 3: 932 usec per loop

C:\Python23\Libpython timeit.py -s floats = map(float, range(1000)) -s
from
itertools import starmap, izip ints = list(starmap(int, izip(floats)))
1000 loops, best of 3: 513 usec per loop


So, the last (very smart) solution, works slightly slower on my PC wrt the
first solution. I don't know really what has changed in Python 2.4... At
the moment I cannot switch to 2.4 because some site-packages I use are still
not updated to Python 2.4.

Anyway, thanks to you all for your smart suggestion. It is really a nice
newsgroup.

Andrea.

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


Integer From A Float List?!?

2005-03-05 Thread andrea_gavana
Hello NG,

sorry to bother you again with this question... I never used the timeit
function, and I would like to ask you if the call I am doing is correct:

C:\Python23\Libpython timeit.py -n 1000 -s from Numeric import ones -s
 floa
ts=ones((1000,1),'f') -s ints = floats.astype(int)
1000 loops, best of 3: 0.0536 usec per loop

I used Numeric module to create a 1000 floats matrix of ones, and it seems
to me that is a lot faster than other solutions... but probably I am doing
something wrong in my call to the timeit function...

Thank you a lot.

Andrea.

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


Re: Integer From A Float List?!?

2005-03-05 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
Hello NG,
sorry to bother you again with this question... I never used the timeit
function, and I would like to ask you if the call I am doing is correct:
C:\Python23\Libpython timeit.py -n 1000 -s from Numeric import ones -s
 floa
ts=ones((1000,1),'f') -s ints = floats.astype(int)
1000 loops, best of 3: 0.0536 usec per loop
The -s option indicates Setup steps that are done outside the timing loop. So you have timed 1000 
empty loops, which is indeed impressively fast :-)

The correct command is
C:\Python23\Libpython23 timeit.py -n 1000 -s from Numeric import ones -s 
floats=ones((1000,1),'f')  ints = floats.astype(int)
1000 loops, best of 3: 30.7 usec per loop

which is still impressively fast compared to map:
C:\Python23\Libpython timeit.py -s floats = map(float, range(1000)) ints= 
map(int, floats)
1000 loops, best of 3: 572 usec per loop
Kent
I used Numeric module to create a 1000 floats matrix of ones, and it seems
to me that is a lot faster than other solutions... but probably I am doing
something wrong in my call to the timeit function...
Thank you a lot.
Andrea.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing Python parse trees

2005-03-05 Thread Manlio Perillo
On 3 Mar 2005 11:15:28 -0800, Lonnie Princehouse
[EMAIL PROTECTED] wrote:

No.  I don't think it's possible to read the parse tree used by the
interpreter, especially as it is being created. Here are a couple of
kludgy ideas that might come close, though:

Is this a 'limitation' of the current version or it is impossible for
the architecture of CPython?
What about pypy?


On a side note, check out the compiler module.  You might find it to be
friendlier and more useful than parser.

Thanks for the hint. It is what I want.
Unfortunately is seem to be not well documented.


Anyway, here is an example of what I would like to do:

#begin
def foo(**kwargs): print kwargs

foo(a = 1, b = 2, c = 3)
#end


In the current implementation kwargs is a dict, but I need to have the
keyword argument sorted.
Unfortunately subclassing fron dict and installing the class in the
__builtin__ module (with the name 'dict') does not work, CPython uses
only builtin types.

With the compiler module I can obtain the keyword arguments in the
order the were specified.
The problem is how to do this for every call to foo!




Thanks and regards   Manlio Perillo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static python program

2005-03-05 Thread Stephen Thorne
On Fri, 04 Mar 2005 12:10:00 +0100, Daniel Frickemeier
[EMAIL PROTECTED] wrote:
 I´m developing a small python-program wiht the mysql-python-module.
 The program should run on a server without any mysql-installation.
 Is there any posibility to kompile a python with static libaries?

Sure, have a look at cx_Freeze or py2exe. both are tools that allow
you to create an executable without dependancies.

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


Re: intigrate the PyGame module with my Python

2005-03-05 Thread Lucas Raab
[EMAIL PROTECTED] wrote:
I want to intigrate the PyGame module with my Python exe,
means i DONT want to generate .PYD files separtely rather than that
want to put PyGame c src with Python workspace of VC project
workspace.
I am unable to import the sub modules( display, rect etc) of pygame,
its raising errors,
am giving the steps i followed, plz help me in this case
I am stuck at the pygame embedding using microsoft visual c++ under
win2000 os.
Formarly I have done following activities :
1. Downloaded the windows binary for python 1.5.2 from python.org.
2. Downloaded the sdl windows binary package from pysdl.org.
3. successfully integrated the sdl library into the python15 project.
   A sample py script was tested successfully.
4. Downloaded pygame 1.6 source from pygame.org.
5. Integrated the code into vc project.
6. On similar lines to sdl, the necessary changes were done
   ( as pygame happens to be successor to sdl).
   Initially, the pygame module was not being recognized by the
environment.
 
 
Regards,
 
Devendra

You don't want to put the Pygame files in the pythonxy.exe (where xy is 
your version number) file, but rather the pythonxy.dll file.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing Python parse trees

2005-03-05 Thread Kent Johnson
Manlio Perillo wrote:
Anyway, here is an example of what I would like to do:
#begin
def foo(**kwargs): print kwargs
foo(a = 1, b = 2, c = 3)
#end
In the current implementation kwargs is a dict, but I need to have the
keyword argument sorted.
Unfortunately subclassing fron dict and installing the class in the
__builtin__ module (with the name 'dict') does not work, CPython uses
only builtin types.
With the compiler module I can obtain the keyword arguments in the
order the were specified.
The problem is how to do this for every call to foo!
Why not just pass the kind of argument you want? What is it you really need 
to do?
def foo(kwds): print kwds
foo(MyDict(a = 1, b = 2, c = 3))
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: programmatically calling a function

2005-03-05 Thread Simon Percivall
You might also want to take a peek at the getattr() function:

   http://docs.python.org/lib/built-in-funcs.html#l2h-31

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


Re: survey

2005-03-05 Thread Cameron Laird
In article [EMAIL PROTECTED],
Peter Hansen  [EMAIL PROTECTED] wrote:
Dave Zhu wrote:
 Hello All,
 
 Is there any survey on scripting languages? I would
 like to get information on several scripting languages
 including Python, Perl, Ruby, Tcl, etc.

What kind of information? ...

Precisely.  There are whole books URL:
http://www.amazon.com/exec/obidos/ASIN/1578700108/002-9216984-6160028 
on this subject; there are breezy sketches URL: 
http://www.itworld.com/AppDev/4061/swol-0202-regex/ 
you can read in a single setting; and 'most everything
between.  Who wants to know?  Is your real interest to
know what the job market for each language is, or the
syntax of arithmetic in each language, or which one has
the best Conferences, or ...?  

URL: http://www.catb.org/~esr/faqs/smart-questions.html 
-- 
http://mail.python.org/mailman/listinfo/python-list


Appeal for python developers

2005-03-05 Thread BOOGIEMAN
Please include goto command in future python realeses
I know that proffesional programers doesn't like to use it, 
but for me as newbie it's too hard to get used replacing it 
with while, def or other commands
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: programmatically calling a function

2005-03-05 Thread Doug Schwarz
In article [EMAIL PROTECTED],
 Dave Ekhaus [EMAIL PROTECTED] wrote:

 hi
 
   i'd like to call a python function programmatically - when all i have 
 is the functions name as a string.  i.e.
 
   
 fnames = ['foo', 'bar']
 
 for func in fnames:
 
   #
   # how do i call function 'func' when all i have is the name of the 
 function ???
   #
   
 
 
 def foo():
   
   print 'foo'
 
 def bar():
 
   print 'bar'
 
 
   i'd really appreciate any help the 'group' has to offer.
 
 
 thanks
 dave


Dave,

I think eval might be what you're looking for:

f = eval('len')
length = f([1,2,3])


By the way, are you the Dave Ekhaus I used to work with at Kodak?

-- 
Doug Schwarz
dmschwarzurgrad,rochester,edu
Make obvious changes to get real email address.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Appeal for python developers

2005-03-05 Thread Michael Hoffman
BOOGIEMAN wrote:
Please include goto command in future python realeses
As has been said before, you can only use goto in Python if
you are using Python with line numbers:
http://groups-beta.google.com/group/comp.lang.python/msg/98264a0daa007c46
 I know that proffesional programers doesn't like to use it,
 but for me as newbie it's too hard to get used replacing it
 with while, def or other commands
I suggest you learn. It shouldn't take you very long to get
used to it, and it will be much easier after you do so.
Trust us. ;)
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: programmatically calling a function

2005-03-05 Thread Reinhold Birkenfeld
Doug Schwarz wrote:

 Dave,
 
 I think eval might be what you're looking for:
 
 f = eval('len')
 length = f([1,2,3])

But only if the string given to eval is checked thorougly for allowed
contents. Better use getattr.

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


Re: Appeal for python developers

2005-03-05 Thread Torsten Bronger
Hallchen!

BOOGIEMAN [EMAIL PROTECTED] writes:

 Please include goto command in future python realeses I know
 that proffesional programers doesn't like to use it, but for me as
 newbie it's too hard to get used replacing it with while, def
 or other commands

Accordings to Stroustrup's C++ book, the only good reason for goto
statements in a language is to have it in computer-generated code.
I don't know whether programs generate Python, but I *think* that
even there goto can be avoided very easily.

Anyway, at our institute we control devices with HT Basic, and my
collegues have used lots of gotos, so I can understand that avoiding
them is somewhat inconvenient at the beginning.  However, it's still
very easy to learn.  Most gotos are disguised function calls, so
just copy the code in a def.  And loops can be translated to
whiles almost trivially.

After a couple of days, it'll be even simpler than before.

Tsch,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Appeal for python developers (THIS IS A TROLL)

2005-03-05 Thread Dave Reed
On Saturday 05 March 2005 09:34, Thomas Rösner aka TRauMa wrote:
 BOOGIEMAN wrote:
  Please include goto command in future python realeses
  I know that proffesional programers doesn't like to use it, 
  but for me as newbie it's too hard to get used replacing it 
  with while, def or other commands
 
 Technically, as a newbie you shouldn't know about GOTO at all. So 
you're 
 more a Tainted by previous spaghetti code practices-guy than newbie.


Or more likely a troll. Google for:

 Boogieman yahoo troll

and you'll see this isn't the only place he/she does this sort of thing.

Please don't feed the trolls.

Dave

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


Re: Calling python scripts from php

2005-03-05 Thread Cameron Laird
In article [EMAIL PROTECTED],
Michael Livingston [EMAIL PROTECTED] wrote:
Hi all,

I'm currently working on a project to develop an online simulation model of
the juvenile justice system in Queensland.  We've developed the simulation
model using the python module simPy and currently we're trying to link the
simulation model to a web interface.  Unfortunately, the web interface and
its interactions with the database have been separately developed in PHP and
ASP.  Rather than rebuilding the web interface using python, we're looking
for an easy way to call a python script from within PHP.  In particular,
we'd like to have the script called but, as running the model can take some
time, we'd prefer if the browser didn't have to sit and wait while the
script was running (instead, we intend to notify the user via email when
their model has completed).  So all we really want to do is start the script
off and running (it's a simple call to a python method).

If you're particularly interested in helping me out and if I've not been
entirely clear, you can go to:

 http://210.49.85.147:8000/justicemodel/login.php

and log in using the user name: temp and the password: pass, select a model
and go to the workspace - the button 'run model' is what we want to trigger
the python script, while all the rest of the website (setting up the model
scenarios, viewing output etc etc) has been developed in php and asp.  Any
assistance anyone can offer me would be greatly appreciated.
.
.
.
I'm sure there's a satisfactory solution.  I'd be happy to work
with you, even on a professional basis.  It might be quite simple
...  To make any progress, I or anyone helping you through
comp.lang.python will need to understand clearly your description.
When you write,  So all we really want to do is start the script
off and running (it's a simple call to a python method), do you
realize that's more of a PHP then Python question?  The answer
is messy (from a Python perspective), but certainly feasible.  I
assume your server is a Win* host; Unix would be easier.  Briefly,
you need to exec(start ...) (or even system(exec ...), if you
prefer), and to do so successfully you'll probably need to adjust
the configuration of your PHP installation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Relative imports

2005-03-05 Thread Chris
After reading that link I tried to change my imports like this:
 from .myPythonFileInTheSameFolder import MyClass

Well, this caused an error in PyLint:
Encountered . at line 1, column 6. Was expecting one of: or ...
and ... not ... is ... in ... lambda ...
   if ... else ... elif ... while ... for ...
try ... except ... def ... class ...
finally ... print ... pass ... break ...
continue ... return ... yield ... import ...
from ... del ... raise ... global ... exec
... assert ... as ... NAME ...
ID:E0001  invalid syntax

I'm getting more and more confused...
How can I correctly do a relative import ?

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


Re: enum question

2005-03-05 Thread Patrick Useldinger
M.N.A.Smadi wrote:
does python support a C-like enum statement where one can define a 
variable with prespesified range of values?

thanks
m.smadi
 BLUE, RED, GREEN = 1,5,8
 BLUE
1
 RED
5
 GREEN
8
--
http://mail.python.org/mailman/listinfo/python-list


site-packages versus site-python

2005-03-05 Thread enrio
I recently installed python 2.4, and many installed software packages
stopped working. Some things got working after I copied some files and
directories from /usr/lib/python2.3/site-packages to
/usr/lib/python2.4/site-packages, but I also had to install a newer
PyXml package, as some of the files that came with python2.4 required a
newer version of pyxml than I had in python2.3/site-packages.

I wonder if there is any particular reason I have no
/usr/lib/site-python directory, and everything is installed in
version-specific site-packages.

I have Fedora Core 3. Is it the Fedora packagers who prefer installing
everything in the version-specific directory? Is there no way to have
older packages continue working in the presence of python2.4? (I still
want the newest to be the default!)

I have tried (cd /usr/bin; grep '#!.*python' * 2/dev/null), and very
few of the programs have a specific version in the interpreter line. Is
there any good reason this is so?

Thinking about it, a particular python program may require a particular
module, but not any particular version of python or the module. The
module perhaps requires at least python2.3, but could run just as well
with python2.4 or later. It does not make sense to have the program
demand a particular version of python in its interpreter string (e.g.,
#!/usr/bin/python2.3), but what about the module. Would it be better
to put the module in site-python and include code to check the
interpreter version?

Perhaps there is no perfect solution that covers all permutations, but
on the other hand, what is currently the correct philosophy of
version handling?

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


Re: Relative imports

2005-03-05 Thread Kent Johnson
Chris wrote:
After reading that link I tried to change my imports like this:
 from .myPythonFileInTheSameFolder import MyClass
This style of import is not yet implemented.
I'm getting more and more confused...
How can I correctly do a relative import ?
I think your choices are
- keep doing what you have been doing and ignore the warnings from PyLint
- keep doing what you have been doing and turn off the warnings from PyLint
- rewrite your imports to be absolute imports
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: Appeal for python developers (THIS IS A TROLL)

2005-03-05 Thread Torsten Bronger
Hallchen!

Dave Reed [EMAIL PROTECTED] writes:

 On Saturday 05 March 2005 09:34, Thomas Rsner aka TRauMa wrote:

 [...]
 
 Technically, as a newbie you shouldn't know about GOTO at all. So
 you're more a Tainted by previous spaghetti code practices-guy
 than newbie.

 Or more likely a troll. Google for:

  Boogieman yahoo troll

 and you'll see this isn't the only place he/she does this sort of
 thing.

And this makes a troll?

Tsch,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Appeal for python developers

2005-03-05 Thread Andrew Dalke
Torsten Bronger wrote:
 Accordings to Stroustrup's C++ book, the only good reason for goto
 statements in a language is to have it in computer-generated code.

I've needed goto statements when translating old code written
with gotos.

  Most gotos are disguised function calls, so
 just copy the code in a def.  And loops can be translated to
 whiles almost trivially.

True, but there are some that aren't easily translated.  I
remember implementing code from Knuth.  I think it was a
prime generation algorithm.  It was MIX code that interwove
two loops and couldn't be easily untangled.

Since I just wanted to text it out I used C++ which had
both gotos and priority queues built in.

Andrew
[EMAIL PROTECTED]

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


GOTO (was Re: Appeal for python developers)

2005-03-05 Thread beliavsky
Torsten Bronger wrote:
 Hallöchen!

 BOOGIEMAN [EMAIL PROTECTED] writes:

  Please include goto command in future python realeses I know
  that proffesional programers doesn't like to use it, but for me as
  newbie it's too hard to get used replacing it with while, def
  or other commands

 Accordings to Stroustrup's C++ book, the only good reason for goto
 statements in a language is to have it in computer-generated code.
 I don't know whether programs generate Python, but I *think* that
 even there goto can be avoided very easily.

Goto is useful in breaking out of a nested loop and when there is a
clean-up section of a function that should be executed for various
error conditions.

In another newsgroup I once asked who needs GOTO and got some good
answers -- the thread can be found by Googling '[EMAIL PROTECTED]
explicit GOTO'. Goto's are less dangerous when they are in the
forward direction, to code appearing later.

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


os.join Windows action

2005-03-05 Thread Colin J. Williams
I am puzzled by the Windows XP usage below:
   C:\Python23\Lib\site-packages\PyMatrixc:python23\python
   The system cannot find the path specified.
   C:\Python23\Lib\site-packages\PyMatrixc:python23\python.exe
   The system cannot find the path specified.
   C:\Python23\Lib\site-packages\PyMatrixc:\python23\python.exe
   Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit
   (Intel)] on win32
   Type help, copyright, credits or license for more information.
 ^Z
   C:\Python23\Lib\site-packages\PyMatrixc:\python23\python
   Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit
   (Intel)] on win32
   Type help, copyright, credits or license for more information.

C:\XXX is required, C:XXX is not acceptable.
The os.path.join doc has:
   *join*(  path1[, path2[, ...]])
   Joins one or more path components intelligently. If any
   component is an absolute path, all previous components are
   thrown away, and joining continues. The return value is the
   concatenation of path1, and optionally path2, etc., with exactly
   one directory separator (|os.sep|) inserted between components,
   unless path2 is empty. Note that on Windows, since there is a
   current directory for each drive, os.path.join(c:, foo)
   represents a path relative to the current directory on drive C:
   (c:foo), not c:\\foo.
How should os.path.join('C:', 'ugh')  be treated?
Colin W.

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


Re: Newbie getting confused again

2005-03-05 Thread M.E.Farmer
It's me wrote:
 If I have:

 a = (1,2,3)

 how do I ended up with:

 res=[(1), (2), (3), (4), (5)]

 without doing:

 res=[(a[0]), (a[1]), (a[2]), (4), (5)]

 ???

 ps: This is just a nobrainer example of what my real code is trying
to do.
 a might have many many elements.   That's why the explicit indexing
method
 won't work.

 Thanks,
Hello,
List objects have a method called extend().
It is made for this.
Py a = [1,2,3]
Py b = [4,5,6]
Py a.extend(b)
Py a
[1, 2, 3, 4, 5, 6]
Since you are a newbie I also suggest you look at
your objects a little and see what they have available.

Pydir(a)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
'__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__',
'__imul__', '__init__', '__le__', '__len__', '__lt__', '__mul__',
'__ne__', '__new__', '__reduce__', '__repr__', '__rmul__',
'__setattr__', '__setitem__', '__setslice__', '__str__', 'append',
'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
'sort']

Then you can try and get some help from Python.
Pyhelp(a.extend)
Help on built-in function extend:

extend(...)
L.extend(iterable) -- extend list by appending elements from the
iterable

And finally use pydoc it is very helpful.
Cl python pydoc -g
hth,
M.E.Farmer

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


Re: Appeal for python developers

2005-03-05 Thread Grant Edwards
On 2005-03-05, BOOGIEMAN [EMAIL PROTECTED] wrote:
 Please include goto command in future python realeses
 I know that proffesional programers doesn't like to use it, 
 but for me as newbie it's too hard to get used replacing it 
 with while, def or other commands

Troll.

-- 
Grant Edwards   grante Yow!  RELAX!!... This
  at   is gonna be a HEALING
   visi.comEXPERIENCE!! Besides,
   I work for DING DONGS!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: survey

2005-03-05 Thread beliavsky
Dave Zhu wrote:
 Hello All,

 Is there any survey on scripting languages? I would
 like to get information on several scripting languages
 including Python, Perl, Ruby, Tcl, etc.

The Language Shootout at http://shootout.alioth.debian.org/ has code
samples in many languages, both interpreted and compiled, including the
ones you mentioned. Don't trust the lines-of-code statistics, though --
the LOC measure is wrongly shown as zero for several codes, and comment
lines are counted, so that languages with programmers who use more
comments are penalized.

You can obtain the paper Are Scripting Languages Any Good? A
Validation of Perl, Python, Rexx, and Tcl against C, C++, and Java. by
Prechelt at http://page.mi.fu-berlin.de/~prechelt/Biblio/ -- his answer
is yes.

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


Re: os.join Windows action

2005-03-05 Thread Michael Hoffman
Colin J. Williams wrote:
C:\XXX is required, C:XXX is not acceptable.
C:XXX is acceptable, it just means something entirely different from
C:\XXX. There is a current working directory on each drive. C:XXX is
file XXX in the current directory on drive C:.
How should os.path.join('C:', 'ugh')  be treated?
Exactly as it is? If you want other behavior, you want
os.path.join('C:\\', 'ugh').
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Appeal for python developers (THIS IS A TROLL)

2005-03-05 Thread Michael Hoffman
Dave Reed wrote:
Or more likely a troll. Google for:
 Boogieman yahoo troll
and you'll see this isn't the only place he/she does this sort of thing.
I'm not convinced.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


python/mod_python conflicts...

2005-03-05 Thread bruce
hi...

i have a linux redhat8 server. i'm trying to get python andmod_python to
play nicely, meaning that i have the right mod_python for the python that
i've installed.

it appears that the box has multiple versions of python.

when i'm 'root' the python version is 2.2.1
when i'm a user 'test', the version is 2.3.5

when i do a 'rpm -q python, i get python-2.2.1-17 as being what was/is
installed via 'rpm'

when i do a 'rpm -q mod_python, i get mod_python-3.1.3-5 as being what
was/is installed via 'rpm'

---
i tried to do an upgrade of the python/mod_python using the rpms from redhat
for RH8 and RH9 and got the following err msg from the command line
python/interpreter:

 import mod_python
   .
   .
   .
ImportError: No module named psp

This happened for both the RH8 and RH9 rppms that I used...

so... any ideas as to how to get this situation to work/resolved...

thanks

-bruce

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


Re: Win32 drive mapping... aka net use

2005-03-05 Thread Lucas Machado

Alex Martelli wrote:

 import win32net
 win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:'})

 is an example (not all that easy to fathom from the docs, but I
 found it out with a little help from the docs, a little from MSDN,
 and a little experimentation).

I looked through the MSDN and was not able to find much information on
how to properly use the NetUseAdd function.  I searched for the
function and looked through the results but all it showed was some data
structure, but i was actually looking for a list of all possible
arguments and which arguments were/were not required.

my problem with the above NetUseAdd example is that I would rather not
have to specify a device.  In the script I am writing the user may
choose to map multiple shares so I need to be able to map to the next
available device:

net use * \\some_server\share_name

instead of:

net use k: \\server\share

Thanks for the help in advance.  Also, if anyone could provide a link
to good windows api docs for python that would be great.

Cheers,
--Lucas Machado

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


Re: programmatically calling a function

2005-03-05 Thread Reinhold Birkenfeld
Doug Schwarz wrote:

  Dave,
  
  I think eval might be what you're looking for:
  
  f = eval('len')
  length = f([1,2,3])
 
 But only if the string given to eval is checked thorougly for allowed
 contents. Better use getattr.
 
 Actually, upon reading Peter Hansen's reply more carefully, I wil defer 
 to his approach, namely,
 
 def foo():
 print foo
 
 f = globals()[foo]
 
 as I suspect that it will be more efficient.  You still need to make
 sure that the string in question is one of the keys in the globals() 
 dictionary or else handle the error -- just as with eval.

Well, with eval, you need to really check the string before calling
eval, with globals() you just need to catch an KeyError, which is cheaper.

 I don't see how getattr solves the original problem.  What, exactly, is 
 the first argument to getattr?

If run at the toplevel, __main__. If the functions are in a module, this
module. But you are right, globals() is more understandable.

However, if the use case is as in the OP's example, Peter Hansen's first
approach is surely the fastest and most concise.


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


Re: Accessing Python parse trees

2005-03-05 Thread Steve Holden
Manlio Perillo wrote:
On 3 Mar 2005 11:15:28 -0800, Lonnie Princehouse
[EMAIL PROTECTED] wrote:

No.  I don't think it's possible to read the parse tree used by the
interpreter, especially as it is being created. Here are a couple of
kludgy ideas that might come close, though:

Is this a 'limitation' of the current version or it is impossible for
the architecture of CPython?
What about pypy?

On a side note, check out the compiler module.  You might find it to be
friendlier and more useful than parser.

Thanks for the hint. It is what I want.
Unfortunately is seem to be not well documented.
Anyway, here is an example of what I would like to do:
#begin
def foo(**kwargs): print kwargs
foo(a = 1, b = 2, c = 3)
#end
In the current implementation kwargs is a dict, but I need to have the
keyword argument sorted.
Unfortunately subclassing fron dict and installing the class in the
__builtin__ module (with the name 'dict') does not work, CPython uses
only builtin types.
With the compiler module I can obtain the keyword arguments in the
order the were specified.
The problem is how to do this for every call to foo!
The nature of the interpreter is that the C code implementing function 
calls specifically uses a dict created in C rather than using the 
mechanisms that would be used to create a dict from within a python 
program, so you have no way to hook your own implementation in to the 
interpreter without modifying the C code.

Introspection does have its limits, and unfortunately that's one of 
them. Sine the code that interprets the byte codes is pretty much all 
written in C, there's no way to affect something that does not already 
have Python run-time hooks provided (such as the __add__ method that 
allows you to implement a specific response to the binary + operator).

What you probably need is a specific magic hook for the ** operator, 
but I'm not sure that's going to happen any time soon ...

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie getting confused again

2005-03-05 Thread It's me
Thanks, got it.


M.E.Farmer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 It's me wrote:
  If I have:
 
  a = (1,2,3)
 
  how do I ended up with:
 
  res=[(1), (2), (3), (4), (5)]
 
  without doing:
 
  res=[(a[0]), (a[1]), (a[2]), (4), (5)]
 
  ???
 
  ps: This is just a nobrainer example of what my real code is trying
 to do.
  a might have many many elements.   That's why the explicit indexing
 method
  won't work.
 
  Thanks,
 Hello,
 List objects have a method called extend().
 It is made for this.
 Py a = [1,2,3]
 Py b = [4,5,6]
 Py a.extend(b)
 Py a
 [1, 2, 3, 4, 5, 6]
 Since you are a newbie I also suggest you look at
 your objects a little and see what they have available.

 Pydir(a)
 ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
 '__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
 '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__',
 '__imul__', '__init__', '__le__', '__len__', '__lt__', '__mul__',
 '__ne__', '__new__', '__reduce__', '__repr__', '__rmul__',
 '__setattr__', '__setitem__', '__setslice__', '__str__', 'append',
 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
 'sort']

 Then you can try and get some help from Python.
 Pyhelp(a.extend)
 Help on built-in function extend:

 extend(...)
 L.extend(iterable) -- extend list by appending elements from the
 iterable

 And finally use pydoc it is very helpful.
 Cl python pydoc -g
 hth,
 M.E.Farmer



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


Re: enum question

2005-03-05 Thread Carl Banks

M.N.A.Smadi wrote:
 does python support a C-like enum statement where one can define a
 variable with prespesified range of values?

The thing is, variables don't have types; objects do.  A variable can
be bound to an object of any type, so there's no way to prespecify a
range of values for a variable.

Your question has the air of someone who's evaluating Python features,
considering whether to try it.  If so, you might need to widen your
worldview a little to understand Python; its variables are
fundamentally different from C, and things like enums don't make much
sense in Python because of it.  However, Python is versatile enough
that you can get something to that effect if you really need it.


-- 
CARL BANKS

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


handling pywintypes.error exceptions

2005-03-05 Thread Lucas Machado
I'm using the win32 api to map samba shares, and I'm having trouble
handling some exceptions.  In my script there are 2 possible exceptions
when the script attempts to map a share:

 win32net.NetUseAdd(None, 1, {'remote':r'\\foo\bar','local':'X
Traceback (most recent call last):
  File stdin, line 1, in ?
pywintypes.error: (53, 'NetUseAdd', 'The network path was not found.')

This exception occurs when '\\foo\bar' is not an existing share. Also,
when a drive letter is already in use the following occurs:

 win32net.NetUseAdd(None, 1,
{'remote':r'\\some_server\share','local':'Y:'})
Traceback (most recent call last):
  File stdin, line 1, in ?
pywintypes.error: (85, 'NetUseAdd', 'The local device name is already
in use.')

I know the exception raised in these cases is pywintypes.error, but
how can i differentiate between the two exceptions? Being able to do
this is critical for my script

Thanks in advance,
--Lucas Machado

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


Re: programmatically calling a function

2005-03-05 Thread Carl Banks

Doug Schwarz wrote:
 I don't see how getattr solves the original problem.  What, exactly,
is
 the first argument to getattr?


mod = __import__(__this__)
f = getattr(mod,foo)

I tend to prefer this over globals() because it seems a little less
magical to me, especially when setting a global.  Either this or
gloabls() will work fine.  Please don't use eval for stuff like this:
that's not what it's for and it has the potential to be dangerous.


-- 
CARL BANKS

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


Re: Win32 drive mapping... aka net use

2005-03-05 Thread Roger Upole
You could use win32api.GetLogicalDriveStrings to list
the drive letters currently in use, and find the next free
letter.  net use * probably does something like that under
the covers.

 hth
  Roger

Lucas Machado [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 Alex Martelli wrote:

 import win32net
 win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:'})

 is an example (not all that easy to fathom from the docs, but I
 found it out with a little help from the docs, a little from MSDN,
 and a little experimentation).

 I looked through the MSDN and was not able to find much information on
 how to properly use the NetUseAdd function.  I searched for the
 function and looked through the results but all it showed was some data
 structure, but i was actually looking for a list of all possible
 arguments and which arguments were/were not required.

 my problem with the above NetUseAdd example is that I would rather not
 have to specify a device.  In the script I am writing the user may
 choose to map multiple shares so I need to be able to map to the next
 available device:

 net use * \\some_server\share_name

 instead of:

 net use k: \\server\share

 Thanks for the help in advance.  Also, if anyone could provide a link
 to good windows api docs for python that would be great.

 Cheers,
 --Lucas Machado
 



== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GOTO (was Re: Appeal for python developers)

2005-03-05 Thread Paul McGuire
At the risk of beating this into the Pythonic ground, here is a
generator version which collapses the original nested loop into a
single loop, so that break works just fine:

.def getCombinations(*args):
.if len(args)  1:
.for a0 in args[0]:
.for remainder in getCombinations(*args[1:]):
.yield [a0]+remainder
.else:
.for a0 in args[0]:
.yield [a0]
.
.for i,j,k in getCombinations(xrange,yrange,zrange):
.if lookup(i,j,k) == target:
.print Eureka!
.break
.else:
.print Rats! No match found.

Now that we have getCombinations in our toolkit, we can also do things
like:
.numbers = range(2)
.colors = ['red','green','blue','orange','white']
.sizes = ['S','M','L','XL','XXL']
.letters = ABCDE
.print [ c for c in getCombinations(numbers, colors) ]
.print [ c for c in getCombinations(numbers, colors, sizes) ]
.print [ c for c in getCombinations(letters,colors) ]
.print [ c for c in getCombinations(letters,letters) ] # take letters
two at a time
.print [ .join(c) for c in getCombinations(letters,letters) ]

giving:

[[0, 'red'], [0, 'green'], [0, 'blue'], [0, 'orange'], [0, 'white'],
[1, 'red'], [1, 'green'], [1, 'blue'], [1, 'orange'], [1, 'white']]
[[0, 'red', 'S'], [0, 'red', 'M'], [0, 'red', 'L'], [0, 'red', 'XL'],
[0, 'red', 'XXL'], [0, 'green', 'S'], [0, 'green', 'M'], [0, 'green',
'L'], [0, 'green', 'XL'], [0, 'green', 'XXL'], [0, 'blue', 'S'], [0,
'blue', 'M'], [0, 'blue', 'L'], [0, 'blue', 'XL'], [0, 'blue', 'XXL'],
[0, 'orange', 'S'], [0, 'orange', 'M'], [0, 'orange', 'L'], [0,
'orange', 'XL'], [0, 'orange', 'XXL'], [0, 'white', 'S'], [0, 'white',
'M'], [0, 'white', 'L'], [0, 'white', 'XL'], [0, 'white', 'XXL'], [1,
'red', 'S'], [1, 'red', 'M'], [1, 'red', 'L'], [1, 'red', 'XL'], [1,
'red', 'XXL'], [1, 'green', 'S'], [1, 'green', 'M'], [1, 'green', 'L'],
[1, 'green', 'XL'], [1, 'green', 'XXL'], [1, 'blue', 'S'], [1, 'blue',
'M'], [1, 'blue', 'L'], [1, 'blue', 'XL'], [1, 'blue', 'XXL'], [1,
'orange', 'S'], [1, 'orange', 'M'], [1, 'orange', 'L'], [1, 'orange',
'XL'], [1, 'orange', 'XXL'], [1, 'white', 'S'], [1, 'white', 'M'], [1,
'white', 'L'], [1, 'white', 'XL'], [1, 'white', 'XXL']]
[['A', 'red'], ['A', 'green'], ['A', 'blue'], ['A', 'orange'], ['A',
'white'], ['B', 'red'], ['B', 'green'], ['B', 'blue'], ['B', 'orange'],
['B', 'white'], ['C', 'red'], ['C', 'green'], ['C', 'blue'], ['C',
'orange'], ['C', 'white']]
[['A', 'A'], ['A', 'B'], ['A', 'C'], ['B', 'A'], ['B', 'B'], ['B',
'C'], ['C', 'A'], ['C', 'B'], ['C', 'C']]
['AA', 'AB', 'AC', 'BA', 'BB', 'BC', 'CA', 'CB', 'CC']

Finally, these last two examples make me think of permutations as well
(in which order is significant - can't count both AB and BA).  So here
is a brute force version of getPermutations, built on getCombinations,
but filtering previously reported duplicates:

.from sets import Set as set
.def getPermutations(*args):
.prevs = []
.for comb in getCombinations(*args):
.thisComb = set(comb)
.if not thisComb in prevs:
.prevs.append(thisComb)
.yield comb
.
.print [ c for c in getPermutations(letters,letters) ]
.print [ .join(c) for c in getPermutations(letters,letters) ]

gives:
[['A', 'A'], ['A', 'B'], ['A', 'C'], ['B', 'B'], ['B', 'C'], ['C',
'C']]
['AA', 'AB', 'AC', 'BB', 'BC', 'CC']


-- Paul

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


Re: Win32 drive mapping... aka net use

2005-03-05 Thread Lucas Machado
Roger Upole wrote:
 You could use win32api.GetLogicalDriveStrings to list
 the drive letters currently in use, and find the next free
 letter.  net use * probably does something like that under
 the covers.

I went and took your advice and this is where I am now:

 import win32api
 a = win32api.GetLogicalDriveStrings()
 a
'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'
 print a
A:\ C:\ D:\ E:\ Z:\

So I think this function will work great since it gives me a string
that i can simply strip away what i don't need and then split it into a
list and traverse the list.  However, when I try to split it, the
following occurs:

 b = a.strip(r'\\\x00')
 b
'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'
 b = a.split(r'\\\x00')
 b
['A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00']

I'm a bit of a novice at python (even more so of the win32 api), but
I've used the split and strip functions before (for example to get rid
of '\n' from strings) so it is unclear to me why this does not work.

Thanks
--LM

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


Re: GOTO (was Re: Appeal for python developers)

2005-03-05 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote:
Goto is useful [...] when there is a clean-up section of a function
that should be executed for various error conditions.
Like this?
def foo():
f = open('foo.txt')
try:
# do stuff with f
finally:
f.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Win32 drive mapping... aka net use

2005-03-05 Thread Roger Upole
The split should work fine if you remove the r
(raw string) prefix.
 win32api.GetLogicalDriveStrings().split('\\\x00')
['A:', 'C:', 'D:', 'E:', 'F:', 'G:', 'H:', 'J:', 'K:', 'Y:', 'Z:', '']

 Roger

Lucas Machado [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Roger Upole wrote:
 You could use win32api.GetLogicalDriveStrings to list
 the drive letters currently in use, and find the next free
 letter.  net use * probably does something like that under
 the covers.

 I went and took your advice and this is where I am now:

 import win32api
 a = win32api.GetLogicalDriveStrings()
 a
 'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'
 print a
 A:\ C:\ D:\ E:\ Z:\

 So I think this function will work great since it gives me a string
 that i can simply strip away what i don't need and then split it into a
 list and traverse the list.  However, when I try to split it, the
 following occurs:

 b = a.strip(r'\\\x00')
 b
 'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'
 b = a.split(r'\\\x00')
 b
 ['A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00']

 I'm a bit of a novice at python (even more so of the win32 api), but
 I've used the split and strip functions before (for example to get rid
 of '\n' from strings) so it is unclear to me why this does not work.

 Thanks
 --LM
 



== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Win32 drive mapping... aka net use

2005-03-05 Thread Diez B. Roggisch
 b = a.strip(r'\\\x00')
 b
 'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'
 b = a.split(r'\\\x00')
 b
 ['A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00']
 
 I'm a bit of a novice at python (even more so of the win32 api), but
 I've used the split and strip functions before (for example to get rid
 of '\n' from strings) so it is unclear to me why this does not work.

The string you get ist actually a list of null-terminated strings. And the
byte 0 that you want to have as delimiter for splitting is written

'\x00'

So do this:

b = a.split('\x00')

Read the python docs about strings and raw strings and escaping of
characters to understand the subtle details here.

-- 
Regards,

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


Re: Wrong with this script?

2005-03-05 Thread Daniel Fackrell
R.Meijer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi, I've been busy with an experimental script, and I can't seem to
 see what is wrong with it, can somebody tell me?

 Here it is:

 a = 0
 b = 1
 mainloop = 1

 print Welcome to pyFibo
 print For more information type \'help\'
 while mainloop==1:
   limit = input(Until what number do you want to see the
 Fibonacci series?)
   if limit==help:
   print The Fibonacci series is a worldfamous series of
 numbers.\
 Each consecutive number is calculated by adding the previous two
 numbers to\
 each other.
   else:
   while b  limit:
 print b
 a, b = b, a+b
   print Want to do another series?
   again = input((Type yes for another series, or anything
 else to quit.)

You need to close the () for input here.  After doing that, if you run it
you will notice that you get an exception for most inputs, including yes.
IIRC, input() is scheduled for removal in some future version of Python
because it doesn't do what you would expect and it is generally a bad idea
to use it.  The functionality is along the lines of:

eval(raw_input('your string here'))

You undoubtedly want raw_input() instead here.

   if again!=yes:
   mainloop = 0

This last line needs indented.

And a couple of minor points:

1. Choose an amount of indentation per level and stick to it.  4 is rather
common in Python code.

2. When posting to the list, make sure that the lines in your code are short
enough that they will not wrap and be posted as broken code.  70 chars is
usually safe.

Daniel Fackrell



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


Re: Equality operator

2005-03-05 Thread Kent Johnson
italy wrote:
Why doesn't this statement execute in Python:
1 == not 0
I get a syntax error, but I don't know why. 
Because == has higher precedence than 'not', so you are asking for
(1 == not) 0
Try
 1 == (not 0)
True
Kent
Thanks,
Adam Roan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Equality operator

2005-03-05 Thread Chris Grebeldinger
not has a lower priority than non-Boolean operators, so not a == b is
interpreted as not (a == b), and a == not b is a syntax error.

http://docs.python.org/lib/boolean.html

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


Python and VT100

2005-03-05 Thread Dominique Bouré
Using Python (Command line version, not IDLE, nor pythonwin)

With Linux, print \033[33mHello prints a brown hello. Fine!
With Windows, the VT100 sequence seems to be unknown?


Why? and how can I correct that?

Thanks


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


Re: Wrong with this script?

2005-03-05 Thread Steven Bethard
R.Meijer wrote:
Hi, I've been busy with an experimental script, and I can't seem to
see what is wrong with it, can somebody tell me?
For future notice, it's useful to
(1) explain what it is you want your script to do, and
(2) explain what it currently does (including an exception traceback if 
one is printed)

Using my mind-reading powers, I'd suggest that maybe you want something 
like:

py for limit in iter(lambda: raw_input('What number? '), ''):
... if limit == help:
... print The Fibonacci series...
... else:
... a, b = 0, 1
... limit = int(limit)
... while b  limit:
... print b
... a, b = b, a+b
...
[... I type '6' ...]
1
1
2
3
5
[... I type '13' ...]
1
1
2
3
5
8
[... I type '' (nothing) ...]
py
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


how to execute Python in VIM

2005-03-05 Thread DENG
hi,

im a newbie to VIM(gVIM under WINXP), i want to execute python in vim
like press F5 in SciTE.

i try to search in google and config as follows in my _vimrc:
---
map f5:D:\python24\python.exe %

if has(autocmd)


  autocmd FileType python setlocal et | setlocal sta | setlocal sw=4
  autocmd FileType python compiler pyunit
  autocmd FileType python setlocal makeprg=python\ ./alltests.py
  autocmd BufNewFile,BufRead test*.py setlocal makeprg=python\ %


endif

--

but neither F5 nor MAKE works.

who can help me ?

thanks in advance

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


calling a same class using threading python

2005-03-05 Thread Raghul
Hi friends,
 I am creating a jabber client and a separate class  for
dialog is created,So when the roster name is clicked this dialog open
and can continue chat.What I need is I am calling the same class when
reciving the message so that the application goes not responding.People
told me to use threading for this.


Can any one help me in calling the same dialog class using threading...

Thanks in advance

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


Re: site-packages versus site-python

2005-03-05 Thread Steve Holden
[EMAIL PROTECTED] wrote:
I recently installed python 2.4, and many installed software packages
stopped working. Some things got working after I copied some files and
directories from /usr/lib/python2.3/site-packages to
/usr/lib/python2.4/site-packages, but I also had to install a newer
PyXml package, as some of the files that came with python2.4 required a
newer version of pyxml than I had in python2.3/site-packages.
I wonder if there is any particular reason I have no
/usr/lib/site-python directory, and everything is installed in
version-specific site-packages.
Well, broadly, the reason is that it allows version-specific code to be 
included in libraries.

Of course, Python is so good at maintaining backward compatibility that 
it's unlikely a pure Python module will fail to run on the next version 
of Python. But you have to do this for extension modules, where the code 
is compiled against a specific version of the Python interpreter API, 
which doesn't stay the same from one version to the next.

I have Fedora Core 3. Is it the Fedora packagers who prefer installing
everything in the version-specific directory? Is there no way to have
older packages continue working in the presence of python2.4? (I still
want the newest to be the default!)
I have tried (cd /usr/bin; grep '#!.*python' * 2/dev/null), and very
few of the programs have a specific version in the interpreter line. Is
there any good reason this is so?
Thinking about it, a particular python program may require a particular
module, but not any particular version of python or the module. The
module perhaps requires at least python2.3, but could run just as well
with python2.4 or later. It does not make sense to have the program
demand a particular version of python in its interpreter string (e.g.,
#!/usr/bin/python2.3), but what about the module. Would it be better
to put the module in site-python and include code to check the
interpreter version?
Perhaps there is no perfect solution that covers all permutations, but
on the other hand, what is currently the correct philosophy of
version handling?
The current correct philosophy is to have version-specific libraries. 
Of course, there is nothing to stop you building your own 
*no*-version-specific library directory and configuring it on to the 
PYTHONPATH for each version you run.

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to execute Python in VIM

2005-03-05 Thread DENG
i change the path

 autocmd FileType python setlocal makeprg=\d:\\Python24\\python.exe\\

  autocmd BufNewFile,BufRead test*.py setlocal
makeprg=\d:\\Python24\\python.exe\\ %

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


Re: Accessing Python parse trees

2005-03-05 Thread Manlio Perillo
On Sat, 05 Mar 2005 08:52:38 -0500, Kent Johnson [EMAIL PROTECTED]
wrote:

Manlio Perillo wrote:
 Anyway, here is an example of what I would like to do:
 
 #begin
 def foo(**kwargs): print kwargs
 
 foo(a = 1, b = 2, c = 3)
 #end
 
 
 In the current implementation kwargs is a dict, but I need to have the
 keyword argument sorted.
 Unfortunately subclassing fron dict and installing the class in the
 __builtin__ module (with the name 'dict') does not work, CPython uses
 only builtin types.
 
 With the compiler module I can obtain the keyword arguments in the
 order the were specified.
 The problem is how to do this for every call to foo!

Why not just pass the kind of argument you want? What is it you really need to 
do?

def foo(kwds): print kwds

foo(MyDict(a = 1, b = 2, c = 3))

Kent

I don't understand your code.
Here an example using OrderedDict from twisted:

 import twisted.python.util as util

 foo(util.OrderedDict(a = 1, b = 2, c = 3))
{'a': 1, 'c': 3, 'b': 2}


Simply I can't use a dict.

I have to do, as an example example:
foo('a', 1, 'b', 2, 'c', 3)

or

foo(['a', 'b', 'c'], [1, 2, 3])


Thanks and regards   Manlio Perillo


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


GUI Guy auto-reply

2005-03-05 Thread GUI Guy
Thanks for e-mailing GUI Guy.  Please note the following:

If your e-mail was a request for technical support, it will be ignored.  Please 
use the support forums available online here:

http://guiguy.wminds.com/forums/

Due to large amounts of spam and recent increased virus activity, I am no 
longer accepting mail sent to this e-mail address unless it contains a specific 
string of text in the subject.

If your e-mail is not a request for technical support and you would like me to 
read it, please re-send it with the following text anywhere in the subject 
(without the quotes):

--nospam here--

Thanks and sorry for the hassle.

Best regards,

GUI Guy

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


python/linux guru needed.. now!!!!

2005-03-05 Thread bruce
hi...

i have a situation with a linux rh8 server. i can't seem to get
python/mod_python/apache working as one...

i can't seem to import mod_python from the python interpreter to work, and
i'm not sure as to why. i'm fairly convinced that it's a conflict issue of
some type, but i'm not sure as to how to resolve it...

if you are a guru with python/mod_python/linux then i'd like to talk with
you...

searching through google/mailing lists/etc... is getting me nowhere!!

thanks

bruce

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


Re: GOTO (was Re: Appeal for python developers)

2005-03-05 Thread Steven Bethard
Dennis Lee Bieber wrote:
On 5 Mar 2005 08:00:23 -0800, [EMAIL PROTECTED] declaimed the following
in comp.lang.python:
explicit GOTO'. Goto's are less dangerous when they are in the
forward direction, to code appearing later.
	UGH... That is the one direction I always avoid (in FORTRAN 77).
Typical example of forward GOTOs in Python source:
static PyObject *
min_max(PyObject *args, PyObject *kwds, int op)
{
...
while (( item = PyIter_Next(it) )) {
/* get the value from the key function */
if (keyfunc != NULL) {
val = PyObject_CallFunctionObjArgs(
keyfunc, item, NULL);
if (val == NULL)
goto Fail_it_item;
}
...
else {
int cmp = PyObject_RichCompareBool(
val, maxval, op);
if (cmp  0)
goto Fail_it_item_and_val;
else if (cmp  0) {
...
}
}
}
if (PyErr_Occurred())
goto Fail_it;
...
return maxitem;
Fail_it_item_and_val:
Py_DECREF(val);
Fail_it_item:
Py_DECREF(item);
Fail_it:
Py_XDECREF(maxval);
Py_XDECREF(maxitem);
Py_DECREF(it);
return NULL;
}
Note that the GOTOs are basically there to take care of the appropriate 
decref-ing if exceptions occur.

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


Re: python/linux guru needed.. now!!!!

2005-03-05 Thread grahamd

bruce wrote:
 hi...

 i have a situation with a linux rh8 server. i can't seem to get
 python/mod_python/apache working as one...

 i can't seem to import mod_python from the python interpreter to
work, and
 i'm not sure as to why. i'm fairly convinced that it's a conflict
issue of
 some type, but i'm not sure as to how to resolve it...

 if you are a guru with python/mod_python/linux then i'd like to talk
with
 you...

 searching through google/mailing lists/etc... is getting me nowhere!!

You will do better if you present your problem in the mod_python
mailing
list. Go to http://www.modpython.org to get the mailing list details,
get
yourself on the list and then post the following information as a
start.

Which version of mod_python you are using.

Whether you are using the global configuration file or a .htaccess
file.

The snippet of the Apache configuration you are using to configure
mod_python and enable its use in the directory you are working in.

Details of any error responses which are being displayed by your web
browser.

Details of messages, be they notices or error messages, which occur in
the Apache error log file corresponding to any request you are making
which is not working.

The full contents of the Python code file for the content handler you
are
trying to use.

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


Re: Equality operator

2005-03-05 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], italy wrote:

 Why doesn't this statement execute in Python:
 
 1 == not 0
 
 I get a syntax error, but I don't know why. 

`==` has a higher precedence than `not` so Python interprets it as::

  (1 == not) 0

This works::

   1 == (not 0)
  True

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


[ICCIMA'05] Final Call for Papers; Due Date March 10, 2005

2005-03-05 Thread avinash
We apologize if this is a duplicate email.


International Conference on Computational Intelligence and
Multimedia Applications, (ICCIMA) August 16-18, 2005
University of Nevada, Las Vegas, USA
 (www.iccima.org)
F I N A LC A L L  F O R P A P E R S


The International Conference on Computational Intelligence and
Multimedia Applications will be held at the University of Nevada, Las
Vegas, USA on August 16-18, 2005. The conference will provide an
international forum for discussion on issues in the areas of
Computational Intelligence and Multimedia for scientists, engineers,
researchers and practitioners. ICCIMA'05 is organized jointly with
International Conference on Systems Engineering (ICSEng'05:
www.icseng.info) and the registered participants of ICCIMA'05 will be
able to attend ICSEng'05.

The conference will include sessions on theory, implementation and
applications, as well as the non-technical areas of challenges in
education and technology transfer to industry. There will be both oral
and poster sessions.  Accepted full papers will be included in the
proceedings  to be published by IEEE CS Press. Selected papers will be
published in International Journal on Computational Intelligence and
Applications published by World Scientific Publishing Company Press.
Several well-known keynote speakers will address the conference.

Conference Topics Include (but not limited to):
Artificial Intelligence, Artificial Neural Networks, Pattern
Recognition, Fuzzy Systems, Genetic Algorithms, Hybrid Systems,
Intelligent Control, Intelligent Databases, Knowledge-based
Engineering, Learning Algorithms, Memory: Storage and Retrieval,
Multimedia Systems, Formal Models for Multimedia, Interactive
Multimedia, Multimedia and Virtual Reality, Multimedia and
Telecommunications, Multimedia Information Retrieval, Multimedia and
Security, Multimedia Hardware, Multimedia and Algorithms.

Special Poster Session:

 ICCIMA'05 will include a special poster session devoted to recent work
and work-in-progress. Abstracts are solicited for this session (2 page
limit) in camera ready form, and may be submitted up to 30 days before
the conference date. They will not be refereed and will not be included
in the proceedings, but will be distributed to attendees upon arrival.
Students are especially encouraged to submit abstracts for this
session.

Invited Sessions: Keynote speakers (key industrialists, chief research
scientists and leading academics) will be addressing the main issues of
the conference.

Important Dates: Submission of papers received latest on:  March 10,
2005

Submission of Papers: Papers in English reporting original and
unpublished research results and experience are solicited. Electronic
submission of papers via www.iccima.org. Visit the web page for more
information.

Page Limits: Papers for refereeing should be double-spaced and must
include an abstract of 100-150 words with up to six keywords. Selected
papers will have a limit of 6 pages in the proceedings to be published
by IEEE.

Evaluation Process: All submissions will be refereed based on the
following criteria by two reviewers with appropriate background:
  originality
 significance
 contribution to the area of research
 technical quality
 relevance to ICCIMA 2005 topics
 clarity of presentation

Contact Information:
ICCIMA' 05 Secretariat
Department of Electrical and Computer Engineering
University of Nevada, Las Vegas
4505 Maryland Parkway, Box 454026
Las Vegas, NV 89154-4026
USA

Phone:  +1 702 895 4184
Fax:  +1 702 895 1115
email:[EMAIL PROTECTED]
URL:  http://www.iccima.org/
___
Conf mailing list
[EMAIL PROTECTED]
http://Mail.Egr.UNLV.EDU/mailman/listinfo/conf

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


[ICSEng'05] Final CFP - due date March 10, 2005

2005-03-05 Thread avinash
We apologize if this is a duplicate email.


EIGHTEENTH INTERNATIONAL CONFERENCE ON SYSTEMS ENGINEERING (ICSEng05)
LAS VEGAS, USA,
AUGUST 16-18, 2005
(http://www.icseng.info)

This series of International Conferences is jointly organized on a
rotational basis among three institutions, University of Nevada, Las
Vegas, USA, Technical University of Wroclaw, Poland, and Coventry
University, UK. In August 2005, the 18th International Conference will
be held in Las Vegas, NV, at the University of Nevada, Las Vegas, USA.
The Proceedings of the conference will be published by IEEE  CS.
ICSEng05 is organized jointly with the International Conference on
Computational Intelligence and Multimedia Applications (ICCIMA'05:
www.iccima.org) and the registered participants of ICSEng05 will be
able to attend ICCIMA05.

Scope of Conference:
The Conference will cover the general area of Systems Engineering, with
particular emphasis being placed on applications. It is expected to
include sessions on the following themes:
Avionics
Computer Algorithms, Databases, Parallel and Distributed Systems,
Networks
Digital systems, Architecture
Control Theory, System Identification and Adaptive Control, Nonlinear
Controls
Engineered Systems for Nuclear Waste Management
Environmental Systems and Energy Systems
Expert Systems and Artificial Intelligence
Finance Engineering
Geographic Information Systems
Global Position Systems
Information Theory and Communication Systems
Neural Network and Applications
Requirements Processes
Risk Management
Robotics and Industrial Automation
Systems Engineering Metrics
Systems Engineering Paradigms, Standards and Challenges
System Architecture
Standards and Testing
Signal Processing
Systems Engineering Education
Transportation Systems

Special Tracks:

1. Data Fusion:
Data fusion is the concept of comparing, combining, and interpreting
data over time and from disparate information sources (sensors, data
bases, and knowledge bases) in order to gain a better understanding of
ones environment, scenario, and/or situation.  The four primary level
of data fusion include object refinement, situational assessment,
impact assessment, and refinement.  The applications of and
technologies associated with data fusion are quite varied.
Applications include (but are not limited to) target tracking, fault
detection and diagnosis, environmental monitoring, control systems,
medical systems, robotics, and traffic control.  Technologies in the
field of data fusion include estimation theory, neural networks, fuzzy
logic, control, probability theory, image processing, decision theory,
and data mining. Papers are being sought for this special session on
data fusion which address advances in fusion technologies and
applications of data fusion systems. One page abstracts for the purpose
of reviewing are due by March 10, 2004.
For more information: http://www.icseng.info/data.htm

2. Risk Management:
This track is ideal for program/project managers, project personnel,
risk managers, and support personnel wanting to develop and expand
knowledge, and share experiences, on best practices in aerospace risk
management processes. Presentations by invited speakers, followed by a
panel discussion, are provided for track participants. Risk management
is a project-wide effort involving management, engineering, production,
test, and support personnel.  Several customers, including NASA and the
DoD, continue to observe that risk management is important to project
success and yet lacks rigor in a majority of space activities.  This
track on Current Trends and Best Practices in aerospace risk management
is designed to explore risk management contributions to current and
future space programs, including projects from many customer
communities (including commercial, NASA, DoD, and ESA among others).
Key themes include how practices are applied successfully to programs
and organizations, how the risk process influences decision-making and
project cost management, and selection of successful tools for
quantitative cost and schedule risk analysis.  Lessons learned from
executing risk management on a wide variety of programs will be
presented to illustrate implementation of success-oriented risk
processes. One page abstracts for the purpose of reviewing are due by
March 10, 2004.
For more information: http://www.icseng.info/strm.htm

3. Computer Infrastructure for Systems Biology:

The special session's goal is to bring forth ideas and collaborations
among industrial and academic bioinformaticians, biocomputing
professionals, data analysts, and system biologists to facilitate
systems biology research and findings. Both research papers (6 pages,
IEEE Proceedings format) and poster papers (2 pages) are solicited to
explore case histories of building and maintaining IT infrastructures
that support advanced biological research. Both industrial and academic
contributions are welcome.

Systems Biology is an emerging field that seeks to analyze disparate

Impersonating other broswers...

2005-03-05 Thread sboyle55
So I wrote a quick python program (my first ever) that needs to
download pages off the web.

I'm using urlopen, and it works fine.  But I'd like to be able to
change my browser string from Python-urllib/1.15 to instead
impersonate Internet Explorer.

I know this can be done very easily with Perl, so I'm assuming it's
also easy in Python.  How do I do it?

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


Re: how to execute Python in VIM

2005-03-05 Thread DENG
ok

i find it

map F12 Esc:!d:\python24\python.exe %CR


but it comes with a new pop-up windowsdame~

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


Re: Impersonating other broswers...

2005-03-05 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 So I wrote a quick python program (my first ever) that needs to
 download pages off the web.
 
 I'm using urlopen, and it works fine.  But I'd like to be able to
 change my browser string from Python-urllib/1.15 to instead
 impersonate Internet Explorer.
 
 I know this can be done very easily with Perl, so I'm assuming it's
 also easy in Python.  How do I do it?

from the urllib docs:

'''
class URLopener(
[proxies[, **x509]])

 Base class for opening and reading URLs. Unless you need to support opening
objects using schemes other than http:, ftp:, gopher: or file:, you
probably want to use FancyURLopener. 

By default, the URLopener class sends a User-Agent: header of urllib/VVV,
where VVV is the urllib version number. Applications can define their own
User-Agent: header by subclassing URLopener or FancyURLopener and setting
the instance attribute version to an appropriate string value before the
open() method is called. 


The optional proxies parameter should be a dictionary mapping scheme names
to proxy URLs, where an empty dictionary turns proxies off completely. Its
default value is None, in which case environmental proxy settings will be
used if present, as discussed in the definition of urlopen(), above. 


Additional keyword parameters, collected in x509, are used for
authentication with the https: scheme. The keywords key_file and cert_file
are supported; both are needed to actually retrieve a resource at an https:
URL. 

'''
-- 
Regards,

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


Re: how to execute Python in VIM

2005-03-05 Thread Diez B. Roggisch
DENG wrote:

 ok
 
 i find it
 
 map F12 Esc:!d:\python24\python.exe %CR
 
 
 but it comes with a new pop-up windowsdame~

I'm no windows expert - but maybe pythonw.exe helps here?
-- 
Regards,

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


Re: Impersonating other broswers...

2005-03-05 Thread Skip Montanaro

sboyle I'm using urlopen, and it works fine.  But I'd like to be able
sboyle to change my browser string from Python-urllib/1.15 to instead
sboyle impersonate Internet Explorer.

sboyle I know this can be done very easily with Perl, so I'm assuming
sboyle it's also easy in Python.  How do I do it?

Easy is in the eye of the beholder I suppose.  It doesn't look as
straightforward as I would have thought.  You can subclass the
FancyURLopener class like so:

class MSIEURLopener(urllib.FancyURLopener):
version = Internet Exploder

then set urllib._urlopener to it:

urllib._urlopener = MSIEURLopener

After that, urllib.urlopen() should spit out your user-agent string.

Seems like FancyURLopener should support setting the user agent string
directly.  You can accomplish that with something like this:

class FlexibleUAopener(urllib.FancyURLopener):
def set_user_agent(self, user_agent):
ua = [(hdr, val) for (hdr, val) in self.addheaders
 if hdr == User-agent]
while ua:
self.addheaders.remove(ua[0])
ua.pop()
self.addheader((User-agent, user_agent))

You'd then be able to set the user agent, but have to use your new opener
class directly:

opener = FlexibleUAopener(...)
opener.set_user_agent(Internet Exploder)
f = opener.open(url)
print f.read()

It doesn't look any easier to do this using urllib2.  Seems like a
semi-obvious oversight for both modules.  That suggests few people have ever
desired this capability.

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


Re: programmatically calling a function

2005-03-05 Thread Carl Banks

Carl Banks wrote:
 Doug Schwarz wrote:
  I don't see how getattr solves the original problem.  What,
exactly,
 is
  the first argument to getattr?


 mod = __import__(__this__)

That should be __import__(__name__) 
Silly me.


-- 
CARL BANKS

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


Re: Wrong with this script?

2005-03-05 Thread Daniel Fackrell
R.Meijer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Thank you very much for the help and the tips :-) This is my very first
python
 script, and I knew it would have some stupid mistakes; but it's doing
something
 weird right now...I did all the stuff you told, me, and now it'll at least
run.
 But whenI enter a number as a limit, the loop keeps going on forever, nad
the
 numbers won't stop rolling. I'm guessing this is because it sees limit as
a
 string, how can I let it see it as an integer?

My mistake.  I was only looking at the last input() call you were using.
For the other one, when you change it to raw_input(), you will get a string
that you must convert to an integer in order to use it for numerical
calculations or comparisons.

int(raw_input('your message here'))

will do this.

After you make this change, try entering a string that cannot be parsed as
an integer, and you will see another exception (ValueError) is raised.  In
order to properly handle this, I would wrap the int(raw_input()) in a try:
except: block inside a loop.  When you get a valid integer, you can then
break out of the loop and continue executing.

You may also want to look at the rest of your script for another place you
can use break in order to eliminate a flag.

Happy scripting, and welcome to the bliss that is Python.

Daniel Fackrell



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


Re: Python and VT100

2005-03-05 Thread TZOTZIOY
On Sat, 5 Mar 2005 22:10:38 +0100, rumours say that Dominique Bouré
[EMAIL PROTECTED] might have written:

Using Python (Command line version, not IDLE, nor pythonwin)

With Linux, print \033[33mHello prints a brown hello. Fine!
With Windows, the VT100 sequence seems to be unknown?


Why? and how can I correct that?

Thanks


On Sat, 5 Mar 2005 22:10:38 +0100, rumours say that Dominique Bouré
[EMAIL PROTECTED] might have written:

Using Python (Command line version, not IDLE, nor pythonwin)

With Linux, print \033[33mHello prints a brown hello. Fine!
With Windows, the VT100 sequence seems to be unknown?


Why? and how can I correct that?

(Sigh)

Why?

I don't think there ever was a colour VT100, BICBW.  I don't know about colour
VT220 either.  I once worked with a colour VT320.

Linux consoles simulate some ANSI terminal similar to the VT's mentioned above
for historical reasons.  It's a quirk maybe; it's not a mandatory feature for
every computer system out there (hint: what was the escape sequence to print a
brown hello on a Macintosh with MacOS 9 and earlier?)


and how can I correct that?

Your car does not run on charcoal either, but you don't *correct* that (ie it's
not part of the design of the car).

There was once an ANSI.SYS (on MS DOorS days, that is :) that you could load in
your CONFIG.SYS file and then MS-DOS command line recognized ANSI escape
sequences.  I don't know if it still exists.

And I just checked on this laptop with Windows XP and it exists! (exclamation
most sincere).  Try googling for directions how to load it.

Otherwise, if willing to drop compatibility with escape sequences, you can use
WConio:

http://newcenturycomputers.net/projects/wconio.html


Other related stuff:

http://en.wikipedia.org/wiki/Vt100

http://en.wikipedia.org/wiki/Ansi.sys
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: locale support and 4.10

2005-03-05 Thread Timothy Smith
Martin v. Löwis wrote:
Timothy Smith wrote:
  locale.setlocale(locale.LC_NUMERIC, 'us')
the exact same thing works under windows xp.
do i have to compile it with locale support?

No. You have to choose a locale name that is supported by your
operating system (which appears to be FreeBSD). Read your OS
documentation for what valid locale names are; most likely,
en_US or en_US.ISO-8859-1 are supported.
also my second question. once i have this working how do i set the 
thousands_sep character to be a , ?

You don't directly set it. It is a property of the locale.
Regards,
Martin
something strange is happening, no matter what i try nothing is a 
supported locale
and yes it's freebsd 4.10
--
http://mail.python.org/mailman/listinfo/python-list


Re: yield_all needed in Python

2005-03-05 Thread Isaac To
 Paul == Paul Moore [EMAIL PROTECTED] writes:

Paul You can work around the need for something like yield_all,
Paul or explicit loops, by defining an iflatten generator,
Paul which yields every element of its (iterable) argument,
Paul unless the element is a generator, in which case we recurse
Paul into it:
Paul ...

Only if you'd never want to yield a generator.

Regards,
Isaac.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: locale support and 4.10

2005-03-05 Thread Martin v. Löwis
Timothy Smith wrote:
something strange is happening, no matter what i try nothing is a 
supported locale and yes it's freebsd 4.10
Sounds like a problem with your operating system. AFAICT, you ought
to have a directory /usr/share/locale on your disk. What is its
contents?
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Impersonating other broswers...

2005-03-05 Thread Eric Pederson
Skip Montanaro [EMAIL PROTECTED] wrote

 It doesn't look any easier to do this using urllib2.  Seems like a
 semi-obvious oversight for both modules.  That suggests few people have 
 ever
 desired this capability.


my $.02:

I have trouble believing few people have not desired this for two reasons:

(1)  some web sites will shut out user agents they do not recognize to preserve 
bandwidth or for other reasons; the right User Agent ID can be required to get 
the data one wants;

(2)  It seems like it is a worthwhile courtesy to identify oneself when 
spidering or data scraping, and the User Agent ID seems like the obvious way to 
do that. I'd guess (and like to think) that Python users are generally a little 
more concerned with such courtesies than the user population of some other 
languages.

e.g.  Your website might get a hit from:  Mozilla/5.0 (Songzilla MP3 Blog, 
http://songzilla.blogspot.com) Gecko/20041107 Firefox/1.0

And you'll get to decide whether to shut them out or not, but at least it won't 
seem like the black hats are attacking.




Eric Pederson
http://www.songzilla.blogspot.com
:::
domainNot=@something.com
domainIs=domainNot.replace(s,z)
ePrefix=.join([chr(ord(x)+1) for x in do])
mailMeAt=ePrefix+domainIs
:::

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


[ANN] WConio 1.5 Binary Installer for Python 2.4

2005-03-05 Thread Chris Gonnerman
At long last I've upgraded to Python 2.4 on my Windows 
development host, and as a direct result I have released
a WConio 1.5 binary installer for Python 2.4.

WConio is my Windows CONsole I/O for Python module.  It
emulates the conio.h functionality of Turbo C 2.0.  This
module is based heavily on the TCCONIO package by Daniel 
Guerrero Miralles, and (like TCCONIO) is in the public
domain.

WConio may be downloaded from:
http://newcenturycomputers.net/projects/wconio.html
-- Chris.
--
http://mail.python.org/mailman/listinfo/python-list


multiple inheritance with builtins

2005-03-05 Thread Giovanni Bajo
Hello,

I noticed that bultin types like list, set, dict, tuple don't seem to adhere to
the convention of using super() in constructor to correctly allow
diamond-shaped inheritance (through MRO). For instance:


 class A(object):
... def __init__(self):
... print A.__init__
... super(A, self).__init__()
...
 class B(A, list):
... def __init__(self):
... print B.__init__
... super(B, self).__init__()
...
 B.__mro__
(class '__main__.B', class '__main__.A', type 'list', type 'object')
 B()
B.__init__
A.__init__
[]
 class C(list, A):
... def __init__(self):
... print C.__init__
... super(C, self).__init__()
...
 C.__mro__
(class '__main__.C', type 'list', class '__main__.A', type 'object')
 C()
C.__init__
[]



It seems weird to me that I have to swap the order of bases to get the expected
behaviour. Is there a reason for this, or is it simply a bug that should be
fixed?
-- 
Giovanni Bajo


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


[ANN] Alternative Readline for Windows -- Binary Installer for Python 2.4 released

2005-03-05 Thread Chris Gonnerman
This is to announce the release of a binary installer
for my Alternative Readline for Windows.  This module
provides interactive command-line editing for Python
on Windows.  I realize the console functions of Windows
2000, XP, and 2003 work in the newest Python versions, 
but it appears that many programmers still work at
least part time on Windows 95/98/Me.  This module is
for them.

The source archives and binary installers for Alternative
Readline are available for download here:
http://newcenturycomputers.net/projects/readline.html
-- Chris.
--
http://mail.python.org/mailman/listinfo/python-list


Re: using python to parse md5sum list

2005-03-05 Thread James Stroud
Among many other things:

First, you might want to look at os.path.walk()
Second, look at the string data type.

Third, get the Python essential reference.

Also, Programming Python (O'Riely) actually has a lot in it about stuff like 
this. Its a tedious read, but in the end will help a lot for administrative 
stuff like you are doing here.

So, with the understanding that you will look at these references, I will 
foolishly save you a little time...

If you are using md5sum, tou can grab the md5 and the filename like such:

myfile = open(filename)
md5sums = []
for aline in myfile.readlines():
  md5sums.append(aline[:-1].split(  ,1))
myfile.close()

The md5 sum will be in the 0 element of each tuple in the md5sums list, and 
the path to the file will be in the 1 element.


James

On Saturday 05 March 2005 07:54 pm, Ben Rf wrote:
 Hi

 I'm new to programming and i'd like to write a program that will parse
 a list produced by md5summer and give me a report in a text file on
 which md5 sums appear more than once and where they are located.

 the end end goal is to have a way of finding duplicate files that are
 scattered across a lan of 4 windows computers.

 I've dabbled with different languages over the years and i think
 python is a good language for this but i have had a lot of trouble
 sifting through manual and tutorials finding out with commands i need
 and their syntax.

 Can someone please help me?

 Thanks.

 Ben

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
-- 
http://mail.python.org/mailman/listinfo/python-list


using python to parse md5sum list

2005-03-05 Thread Ben Rf
Hi

I'm new to programming and i'd like to write a program that will parse
a list produced by md5summer and give me a report in a text file on
which md5 sums appear more than once and where they are located.

the end end goal is to have a way of finding duplicate files that are
scattered across a lan of 4 windows computers.

I've dabbled with different languages over the years and i think
python is a good language for this but i have had a lot of trouble
sifting through manual and tutorials finding out with commands i need
and their syntax.

Can someone please help me?

Thanks.

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


How do I import everything in a subdir?

2005-03-05 Thread Dfenestr8
Hi.

I have a program which I want a plugin directory for. I figured the way to
go about that would be to just add a plugin/ dir to sys.path, and import
everything in it. Then my program can just execute the main() method of
each imported plugin.

Is that a good way to go about it?

If so, how do I import everything in the plugins dir? The method raises an
error as you can see.

 import sys
 import os
 sys.path.append(plugins)
 ls = os.popen(ls plugins).readlines()
 for x in ls:
... plugs.append(x[0:x.rfind(.py)])
 for x in plugs:
... import x
...
Traceback (most recent call last):
  File stdin, line 2, in ?
ImportError: No module named x

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


Re: os.join Windows action

2005-03-05 Thread John Machin

Michael Hoffman wrote:
 Colin J. Williams wrote:

  C:\XXX is required, C:XXX is not acceptable.

 C:XXX is acceptable, it just means something entirely different from
 C:\XXX. There is a current working directory on each drive. C:XXX is
 file XXX in the current directory on drive C:.

Further notes for Colin:

On *x, /xxx is the xxx file in the root directory and xxx is the xxx
file in the current directory. Same perceived problem.

This is not a new feature in Windows XP; it has been as Michael
described ever since directories were introduced in MS-DOS 2.0.  And of
course it applies to all file paths, irrespective of whether you want
to execute / read /write / etc.

As a matter of interest, do you normally run python with
site-packages as the current directory? Most folk would not do that,
with any software package, preferring the installed software to be just
that, and not polluted with their own data etc which should be kept
elsewhere in appropriately named and structured directories. 

HTH,
John

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


Modifying Call Tips and Intellisense Behavior

2005-03-05 Thread pytopo

I like the way call tips displays argument variables for functions when
you type the ( after the function name.  However, if one of the
arguments to the function is something like SomeMod.attribute, the
intellisense will display all the exposed methods and attributes when
SomeMod. is typed.  This is fine but once I have selected the desired
attribute and continue with entering the next argument, the original
call tip for the function I'm working on is lost.  I think it would be
nice if one could hit a key sequence or something to recall the last
call tip.

Are there some other python editors that have this type of behavior?

If not, where should I start looking to tweak.

Thanks

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


yum install python2.4

2005-03-05 Thread richardun
My goal is to install python2.4 using yum (wouldn't you know it, it's a
dependency for something else).

From this page (), I followed the following instructions:
1. ...creat /etc/yum.repos.d/python24.repo with the following lines:

[python24]
name=Fedora Core $releasever - $basearch - Python 2.4
baseurl=http://www.python.org/ftp/python/2.4/rpms/fedora-$releasever/
enabled=1
gpgcheck=1

2. Add the KRUD GPG key by running: rpm --import
http://www.python.org/ftp/python/2.4/rpms/KRUD-GPG-KEY;

3. Install Python 2.4 by running: yum install python2.4.

This is the output I get after running the yum install line:

...
Cannot find a package matching python2.4
No actions to take

Now, I've checked two things well, the python24.repo file I created is
just as it is above, except instead of $releasever, I have 3.  This is
because my version would otherwise attempt 3AS here.  And next, I
followed the repository to make sure such a path would have something
there.  It does:  http://www.python.org/ftp/python/2.4/rpms/fedora-3/

So, why the heck doesn't this find python2.4???  These are all the
instructions posted on Python's site to install using yum.  So, what's
wrong?

TIA,
Richard

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


Can a method in one class change an object in another class?

2005-03-05 Thread Stewart Midwinter
I've got an app that creates an object in its main class (it also
creates a GUI).  My problem is that I need to pass this object, a
list, to a dialog that is implemented as a second class. I want to
edit the contents of that list and then pass back the results to the
first class.   So my question is, can a method in one class change an
object in another class?

If the answer is no, I suppose I could pass in the list as an argument
when I create the second class, then return the contents of the list
when I end the methods in that second class.

alternatively, I could make the list a global variable, then it would
be available to all classes.  I have a nagging feeling though that
global variables are to be avoided on general principle. Is this
correct?

Here's a simple example app that tries to have one class change the
object in another class.  It doesn't give the behaviour I want,
though.

---
#objtest.py

class first:
def __init__(self):
a = 'a'
self.a = a
print self.a

def update(self):
print 'initially, a is', self.a
self.a = second(self.a)
print 'afterwards, a is', self.a

class second:
def __init__(self, a):
pass

def __call__(self, a):
a = 'aa'
return a

if __name__ == '__main__':
app = first()
app.update()

thanks,
--
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Tough Spawn Problem

2005-03-05 Thread googlemike
I'm trying to use Python and PyGTK + Glade, along with Bash. I want to
make a GUI for the Linux vpnclient command-line tool. (Look for
linux-vpnclient.tar.gz on the Internet if you are curious.) Anyway,
this vpnclient tool connects to VPN and then stays locked like that
while the VPN connection is running. What I was trying to do was either
spawn it and then use another command-line tool to check on its status,
or shell the process and redirect all its output text to the GTK
textbox in the GUI. Here's the problems I found with that:

* Spawn - This seems to spawn the process okay, but when the vpnclient
connection is finally loaded, it holds the process and the GUI cannot
return to being responsive -- it locks the GUI up, essentially. I tried
os.NO_WAIT and os.DETACH but os.NO_WAIT was no solution and os.DETACH
only works in the documentation, not in my version of Python.

* Shell - This seems to do the same thing as spawn but instead of
sending output to a console, it sends the output into a console-less
space. Then, because the VPN connection is locked-in, it also holds the
GUI up and hangs it.

I tried using the   operator but that seemed to have no effect in
fixing this problem.

What's the trick?

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


Re: Setting default option values for Tkinter widgets

2005-03-05 Thread [EMAIL PROTECTED]
yep, that works better under Windows.   Pretty obscure use of Python,
though! :-)

S

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


Re: win32 COM and data types / direction

2005-03-05 Thread Tim Roberts
Alexander Eisenhuth [EMAIL PROTECTED] wrote:

Hello everybody,

i wonder how the win32 COM extension handles different C-int types 
(short, int, long).

All of those types are passed on the stack as 32-bit dwords.  No problem.

Another question for me is weather the 
out-direction of parameter is supported out of the box ?

Yes, but you have to make them outputs from your function.  Remember that
assigning to a parameter in Python does not change the parameter from the
caller's point of view:

def FunWithTwoInts( self, inShort, inInt ):
print got as short:% as int%d % (inShort, inInt)
return inShort + inInt

If you have multiple OUT parameters, you return a tuple of values.

To clarify look at the methode FunWithTwoInts
--
#SimpleCOMServer.py - A sample COM server - almost as small as they come!
#
# We expose a single method in a Python COM object
class PythonUtilities:
 _public_methods_ = [ 'FunWithTwoInts' ]
 _reg_progid_ = PythonDemo.Utilities

 # NEVER copy the following ID!
 # Use print pythoncom.CreateGuid( ) to make a new one
 _reg_clsid_  = {40CEA5F8-4D4C-4655-BD8B-0E7B6A26B556}

 def FunWithTwoInts(self, inShort, inInt, outSum):
   print got as short:%d as int:%d sum:%d % (inShort, inInt, outSum)
   outSum = inShort + inInt

# Add code so that when this script is run by
# Python.exe, it self-registers
if __name__=='__main_  _':
 print Registering COM server...
 import win32com.server.register
 win32com.server.register.UseCommandLine(PythonUtilities)
--
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ python-Bugs-1157169 ] csv Sniffer returns bad dialect?

2005-03-05 Thread SourceForge.net
Bugs item #1157169, was opened at 2005-03-05 08:14
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1157169group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Neil Schemenauer (nascheme)
Assigned to: Nobody/Anonymous (nobody)
Summary: csv Sniffer returns bad dialect?

Initial Comment:

 d = csv.Sniffer().sniff('abc', ['\t', ','])
 csv.reader(['abc'], d)   
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: bad argument type for built-in operation

If the 'delimiters' argument to sniff() is left out
then the TypeError is not raised.  Not sure what's
going on here.

A few other nits:

sniff() seems to be misdocumented.  It cannot return None.

What's the point of the Sniff class?  Why isn't sniff()
a module level function?

The library manual does not state what the iterator
returned by reader() returns.  It should state that
generates lists of strings.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1157169group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1157255 ] PEP 328 and Python 2.4 error

2005-03-05 Thread SourceForge.net
Bugs item #1157255, was opened at 2005-03-05 13:23
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1157255group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Kent Johnson (kjohnson)
Assigned to: Nobody/Anonymous (nobody)
Summary: PEP 328 and Python 2.4 error

Initial Comment:
PEP 328 says that 
from __future__ import absolute_import

will be part of Python 2.4, but it is not:

D:\Projects\CBpython
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32
bit (Intel)] on win32
Type help, copyright, credits or license for
more information.
  from __future__ import absolute_import
  File stdin, line 1
SyntaxError: future feature absolute_import is not defined

The PEP should be updated to reflect this.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1157255group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1156412 ] add documentation for __new__

2005-03-05 Thread SourceForge.net
Bugs item #1156412, was opened at 2005-03-03 22:00
Message generated for change (Comment added) made by gward
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1156412group_id=5470

Category: Documentation
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Steven Bethard (bediviere)
Assigned to: Nobody/Anonymous (nobody)
Summary: add documentation for __new__

Initial Comment:
3.3.1 Basic customization does not document __new__. 
Proposed addition:

__new__(cls[, ...])

Called to create a new instance of the class.  __new__
is a staticmethod (special-cased so you need not
declare it as such) that takes the class to be created
as the first argument.  The remaining arguments are
those passed to the class constructor expression. The
return value of __new__ should be the new object instance.

Typical usage is to create a new instance of the class
by invoking the superclass's __new__ method using
super(BaseClass, cls).__new__([...]) with appropriate
arguments, modifying the returned instance if
necessary, and then returning it.  If the returned
value is an instance of cls (the first argument to
__new__), its __init__ will be invoked.

Note that you need not return an instance of cls, but
if you don't, the new instance's __init__ method will
not be invoked.

The __new__ staticmethod is intended mainly to allow
modification of immutable types like int, long, float,
str and tuple.

--

Comment By: Greg Ward (gward)
Date: 2005-03-05 11:11

Message:
Logged In: YES 
user_id=14422

I think that last paragraph can be written even more concisely:

The __new__ staticmethod is intended mainly to allow
subclasses of immutable types (like int, str, or tuple) to
customize instance creation.

Also, the usual convention when talking about methods and
functions is to write __new__(), not __new__.  At least
that's how the 2.3.3 language ref which I have on my PC looks.

Finally, this bug is in the Python 2.5 group -- surely
there's no harm in checking this in to the 2.4 docs and
merging forward?

--

Comment By: Nick Coghlan (ncoghlan)
Date: 2005-03-04 23:02

Message:
Logged In: YES 
user_id=1038590

Close, but the phrasing's a bit awkward. Getting rid of the
commas seems to fix that:

The __new__ staticmethod is intended mainly to allow you to
customize instance creation in a subclass of an immutable
type (like int, long, float, complex, str, unicode, or tuple).

--

Comment By: Steven Bethard (bediviere)
Date: 2005-03-04 15:19

Message:
Logged In: YES 
user_id=945502

Good point.  How about:

The __new__ staticmethod is intended mainly to allow you,
in a subclass of an immutable type (like int, long, float,
complex, str, unicode, or tuple), to customize instance
creation.

--

Comment By: Oren Tirosh (orenti)
Date: 2005-03-04 13:05

Message:
Logged In: YES 
user_id=562624

The __new__ staticmethod is intended mainly to allow
modification of immutable types like int, long, float,
str and tuple.

You might like to rephrase that. It gives the impression
that __new__ somehow makes it possible to modify the value
of an immutable object. In fact, it only allows customized
creation of new instances.


--

Comment By: Steven Bethard (bediviere)
Date: 2005-03-04 11:11

Message:
Logged In: YES 
user_id=945502

Yup, type_call in typeobject.c special-cases this behavior.
 See also
http://sourceforge.net/tracker/?func=detailaid=1123716group_id=5470atid=105470

--

Comment By: Nick Coghlan (ncoghlan)
Date: 2005-03-04 10:53

Message:
Logged In: YES 
user_id=1038590

Looks reasonable to me - but does CPython actually currently
follow those rules regarding when __init__ is and isn't invoked?

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1156412group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >