ANN: Assembly Line 0.8.2

2009-02-16 Thread Greg Ewing

I have released an updated version of Assembly Line,
my entry in PyWeek 6 and later the Pyggy Awards.

http://media.pyweek.org/dl/1007/greg_pgF09/AssemblyLine-0.8.2.zip

About Assembly Line
---

Become a FADE!

That's Factory Automation Design Engineer for Pixall Manufacturing, the world 
leader in pixellated products.


We give you product designs from our RD department, and you design and build 
factories to manufacture them as efficiently possible. Make a good profit and 
you'll earn big bonuses and a huge salary!


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

   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


Re: hist without plotting

2009-02-16 Thread Peter Otten
Nick Matzke wrote:

 Is there a way to run the numpy hist function or something similar and
 get the outputs (bins, bar heights) without actually producing the plot
 on the screen?
 
 (R has a plot = false option, something like this is what I'm looking
 for...)

First hit googling for numpy hist led me to

http://www.scipy.org/Tentative_NumPy_Tutorial#head-aa75ec76530ff51a2e98071adb7224a4b793519e

So pylab.hist() plots and numpy.histogram() just calculates.

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


Re: Display a list using PyQt

2009-02-16 Thread Gerhard Häring
member Basu wrote:
 I'm writing an application with PyQt as the GUI toolkit. I have a
 function that returns a simple list and I would like to update a List
 View widget with it. However I can't get it to work. I'm not sure if I
 need to subclass one of the Model classes, because it is just a list.
 Can someone point me to a simple tutorial or give me instructions on how
 to go about doing this?

The attached example should help. Also see the examples included with PyQt.

-- Gerhard
from PyQt4 import QtCore, QtGui
import sys

class MyDialog(QtGui.QDialog):
def __init__(self,  parent):
super(QtGui.QDialog,  self).__init__(parent)

self.layout = QtGui.QVBoxLayout(self)

self.resize(400, 300)
self.listWidget = QtGui.QListWidget(self)
self.layout.addWidget(self.listWidget)

buttonBox = QtGui.QDialogButtonBox(self)
buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
self.layout.addWidget(buttonBox)

QtCore.QObject.connect(buttonBox, QtCore.SIGNAL(accepted()), self.accept)


def set_list(self, lst):
for item in lst:
listItem = QtGui.QListWidgetItem(str(item), self.listWidget)

def accept(self):
selected_items = , .join([str(item.text()) for item in self.listWidget.selectedItems()])
print selected:, selected_items
self.close()

if __name__ == __main__:
app = QtGui.QApplication(sys.argv)
dlg = MyDialog(None)
lst = [3,4,5]
dlg.set_list(lst)
dlg.exec_()
--
http://mail.python.org/mailman/listinfo/python-list


Windows vista

2009-02-16 Thread loveshadowdog
Hi. My name is toru.
I start learning python couple weeks ago.

I install the compiler from python.org.
but I cannot use the IDLE program.
(command line works fine so far)
the error screen says that the my personal fire wall is blocking the
program to run.
I am not sure how to fix this.
By the way, I heard many people said that this is because I am using
windows vista.
Does anyone know how to use IDLE program on Windows Vista machine?

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


Will multithreading make python less popular?

2009-02-16 Thread rushenaly
Hi everybody,
I am an engineer. I am trying to improve my software development
abilities. I have started programming with ruby. I like it very much
but i want to add something more. According to my previous research i
have designed a learning path for myself. It's like something below.
  1. Ruby (Mastering as much as possible)
  2. Python (Mastering as much as possible)
  3. Basic C++ or Basic Java
And the story begins here. As i search on the net,  I have found that
because of the natural characteristics of python such as GIL, we are
not able to write multi threaded programs. Oooops, in a kind of time
with lots of cpu cores and we are not able to write multi threaded
programs. That is out of fashion. How a such powerful language doesn't
support multi threading. That is a big minus for python. But there is
something interesting, something like multi processing. But is it a
real alternative for multi threading. As i searched it is not, it
requires heavy hardware requirements (lots of memory, lots of cpu
power). Also it is not easy to implement, too much extra code...

After all of that, i start to think about omiting python from my
carrier path and directly choosing c++ or java. But i know google or
youtube uses python very much. How can they choose a language which
will be killed by multi threading a time in near future. I like python
and its syntax, its flexibility.

What do you think about multi threading and its effect on python. Why
does python have such a break and what is the fix. Is it worth to make
investment of time and money to a language it can not take advantage
of multi cores?

Thank you...
Rushen
--
http://mail.python.org/mailman/listinfo/python-list


How to enum all the users from a windows domain via python win32net module?

2009-02-16 Thread vimuser
I tried the command net user /DOMAIN in windows console(cmd.exe),
and it showed me all the usernames in my domain without any problems.
But when I tried it in python with these commands :
info=win32net.NetUserEnum(DOMAIN_NAME,1),
info=win32net.NetUserEnum(r\\DOMAIN_NAME,1),and
info=win32net.NetUserEnum(DOMAIN_NAME,1), I all got the System
Error 53 (The network path was not found) .

What should I do, if I intend to enum all the users from a windows
domain via python win32net module?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to enum all the users from a windows domain via python win32net module?

2009-02-16 Thread Tim Golden

vimuser wrote:

I tried the command net user /DOMAIN in windows console(cmd.exe),
and it showed me all the usernames in my domain without any problems.
But when I tried it in python with these commands :
info=win32net.NetUserEnum(DOMAIN_NAME,1),
info=win32net.NetUserEnum(r\\DOMAIN_NAME,1),and
info=win32net.NetUserEnum(DOMAIN_NAME,1), I all got the System
Error 53 (The network path was not found) .

What should I do, if I intend to enum all the users from a windows
domain via python win32net module?
--
http://mail.python.org/mailman/listinfo/python-list


code

import win32net
import win32netcon

dc = win32net.NetGetAnyDCName (None, None)

resume = 0
while 1:
 (_users, total, resume) = \
   win32net.NetUserEnum (
 dc,
 3,
 win32netcon.FILTER_NORMAL_ACCOUNT,
 resume,
 win32netcon.MAX_PREFERRED_LENGTH
   )
 for _user in _users:
   print _user['name'], _user['home_dir'], _user['profile']
 break
 if not resume:
   break


/code

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


[Fwd: Re: Pythonic way to determine if a string is a number]

2009-02-16 Thread Tim Golden

[Resending after a bounce from mailing list]

pyt...@bdurham.com wrote:

try:
   float (input)
except ValueError:
   return False
else:
   return True


I follow the semantics, but I don't know why I would prefer the try/else
technique over the simpler:

try:
float( input )
return True
except ValueError:
return False



In this case, I don't think you would. At least I would
say it's no more than 50/50 depending on taste and probably
more like 60/40 in favour of your solution. However
there are situations where try-except-else more 
naturally expresses the code intent. Of course I

can't think of a single one now, and it's not an easy
thing to search my codebase for so I'll just press send
and then think of an example two seconds later!

Really wanted to make sure you were aware of it as an
option; the else clause on try-except (and its cousin
the for-else clause) are easily overlooked / forgotten.

TJG

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


Re: Will multithreading make python less popular?

2009-02-16 Thread Andreas Kaiser
On 16 Feb., 10:34, rushen...@gmail.com wrote:
 Hi everybody,
 I am an engineer. I am trying to improve my software development
 abilities. I have started programming with ruby. I like it very much
 but i want to add something more. According to my previous research i
 have designed a learning path for myself. It's like something below.
       1. Ruby (Mastering as much as possible)
       2. Python (Mastering as much as possible)
       3. Basic C++ or Basic Java
 And the story begins here. As i search on the net,  I have found that
 because of the natural characteristics of python such as GIL, we are
 not able to write multi threaded programs. Oooops, in a kind of time
 with lots of cpu cores and we are not able to write multi threaded
 programs. That is out of fashion. How a such powerful language doesn't
 support multi threading. That is a big minus for python.

On comp.lang.ruby David Masover wrote this at 29 Jul. 2008, 07:55:
-
Right now, Ruby shares a problem with Python called the GIL -- the
Global (or
Giant) Interpreter Lock. What this means is that only one Ruby
instruction
may execute at a time. So even though they're using separate OS
threads, and
even though different Ruby threads might run on different cores, the
speed of
your program (at least the Ruby part) is limited to the speed of a
single
core.
-

Please don't mix threads and parallel processing on more then one CPU
core.

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


Re: Will multithreading make python less popular?

2009-02-16 Thread Aleksa Todorovic
Hi, Rushen!

I'm also new to using Python but from what I've found, GIL is very
intentional decision. It is one of the features of Python which make
it so powerful. I believe that if it didn't have GIL, Python wouldn't
be half near where it is now (regarding it as a language, community,
platform support, popularity, ...).

The most important question is do you really need multi-threading for
what you do? There is lot of software which doesn't require mt at all,
or could be written without mt. Also, if you haven't learnt C++ or
Java yet, mt is not something you should be worried about in the near
future - there are lot of other, more important things, you need to
learn before opening door mt hell :-)

Best,
Aleksa


On Mon, Feb 16, 2009 at 10:34,  rushen...@gmail.com wrote:
 Hi everybody,
 I am an engineer. I am trying to improve my software development
 abilities. I have started programming with ruby. I like it very much
 but i want to add something more. According to my previous research i
 have designed a learning path for myself. It's like something below.
  1. Ruby (Mastering as much as possible)
  2. Python (Mastering as much as possible)
  3. Basic C++ or Basic Java
 And the story begins here. As i search on the net,  I have found that
 because of the natural characteristics of python such as GIL, we are
 not able to write multi threaded programs. Oooops, in a kind of time
 with lots of cpu cores and we are not able to write multi threaded
 programs. That is out of fashion. How a such powerful language doesn't
 support multi threading. That is a big minus for python. But there is
 something interesting, something like multi processing. But is it a
 real alternative for multi threading. As i searched it is not, it
 requires heavy hardware requirements (lots of memory, lots of cpu
 power). Also it is not easy to implement, too much extra code...

 After all of that, i start to think about omiting python from my
 carrier path and directly choosing c++ or java. But i know google or
 youtube uses python very much. How can they choose a language which
 will be killed by multi threading a time in near future. I like python
 and its syntax, its flexibility.

 What do you think about multi threading and its effect on python. Why
 does python have such a break and what is the fix. Is it worth to make
 investment of time and money to a language it can not take advantage
 of multi cores?

 Thank you...
 Rushen
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Aleksa Todorovic - Lead Programmer
Eipix Entertainment
http://www.eipix.com/
--
http://mail.python.org/mailman/listinfo/python-list


explain

2009-02-16 Thread Saeed Iravani
I download python 2.5.4 and install but I dont know that how perform python?
I dont know from which directory perform python?
Please explain for me.
Thank you


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


explain

2009-02-16 Thread Saeed Iravani
I download python 2.5.4 and install but I dont know that how run python?
I dont know from which directory run python?
Please explain for me.
Thank you


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


Re: explain

2009-02-16 Thread Jeroen Ruigrok van der Werven
-On [20090216 11:17], Saeed Iravani (si.4...@yahoo.com) wrote:
I download python 2.5.4 and install but I dont know that how perform python?
I dont know from which directory perform python?

It would help if you would clarify which operating system you are using.

On Unix/Linux systems you make sure to 'rehash' your $PATH or add the
appropriate directory to the $PATH variable.

On Windows, you set your environment variable PATH to include the path to
Python programs (typically something like C:\Python25), which you can find
under the system control panel.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Earth to earth, ashes to ashes, dust to dust...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows vista

2009-02-16 Thread Jeroen Ruigrok van der Werven
-On [20090216 09:50], loveshadow...@yahoo.com (loveshadow...@yahoo.com) wrote:
the error screen says that the my personal fire wall is blocking the
program to run.

My default Windows Vista x64 installation is not blocking my IDLE at all, so
it might be you're not using the standard Windows firewall but perhaps some
third-party one.

Most of the time in the firewall configuration windows you can add specific
executables to be allowed access. As such you probably have to point it to
the C:\Python25\Python.exe file, but that's just a guess.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Earth to earth, ashes to ashes, dust to dust...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread Michele Simionato
On Feb 16, 10:34 am, rushen...@gmail.com wrote:
 Hi everybody,
 I am an engineer. I am trying to improve my software development
 abilities. I have started programming with ruby. I like it very much
 but i want to add something more. According to my previous research i
 have designed a learning path for myself. It's like something below.
       1. Ruby (Mastering as much as possible)
       2. Python (Mastering as much as possible)
       3. Basic C++ or Basic Java
 And the story begins here. As i search on the net,  I have found that
 because of the natural characteristics of python such as GIL, we are
 not able to write multi threaded programs. Oooops, in a kind of time
 with lots of cpu cores and we are not able to write multi threaded
 programs. That is out of fashion. How a such powerful language doesn't
 support multi threading. That is a big minus for python. But there is
 something interesting, something like multi processing. But is it a
 real alternative for multi threading. As i searched it is not, it
 requires heavy hardware requirements (lots of memory, lots of cpu
 power). Also it is not easy to implement, too much extra code...

multiprocessing is already implemented for you in the standard
library.
Of course it does not require heavy hardware requirements.

 After all of that, i start to think about omiting python from my
 carrier path and directly choosing c++ or java. But i know google or
 youtube uses python very much. How can they choose a language which
 will be killed by multi threading a time in near future. I like python
 and its syntax, its flexibility.

 What do you think about multi threading and its effect on python. Why
 does python have such a break and what is the fix. Is it worth to make
 investment of time and money to a language it can not take advantage
 of multi cores?

You can take advantage of multi cores, just not with threads but with
processes,
which BTW is the right way to go in most situations. So (assuming you
are not
a troll) you are just mistaken in thinking that the only way to
use multicores is via multithreading.

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


Re: Will multithreading make python less popular?

2009-02-16 Thread Tim Rowe
2009/2/16  rushen...@gmail.com:
 Hi everybody,
 I am an engineer. I am trying to improve my software development
 abilities. I have started programming with ruby. I like it very much
 but i want to add something more. According to my previous research i
 have designed a learning path for myself. It's like something below.
  1. Ruby (Mastering as much as possible)
  2. Python (Mastering as much as possible)
  3. Basic C++ or Basic Java
 And the story begins here. As i search on the net,  I have found that
 because of the natural characteristics of python such as GIL, we are
 not able to write multi threaded programs. Oooops, in a kind of time
 with lots of cpu cores and we are not able to write multi threaded
 programs. That is out of fashion. How a such powerful language doesn't
 support multi threading. That is a big minus for python.

In a way, you've answered your own question. Why are you learning
three languages? Perhaps you've already realised that being
Turing-complete isn't the last word in language choice; that different
languages make different compromises, so the best language for one
task may not be the best language for a different task. Ok, Python
doesn't cope well with threading. It doesn't cope well with hard
real-time, either. So what? A deep saucepan isn't much use for making
an omlette (it can be done, but it's inefficient), but it's ideal for
making soup. Just because multiple cores are available doesn't mean
they will help your program significantly. Most real-world programs
work just fine in a single core, and it usually just isn't worth all
of the extra design effort, coding effort and debugging effort of
threading to cut the user response time down from a tenth of a second
to a twentieth. For *most* applications the single-thread Python
programmer will have something written, shipped and doing the job
whilst the multi-thread programmer is still trying to debug an
intermittent livelock that goes away whenever instrumentation is
added.  For those few cases where threading is a genuine advantage,
Python is not ideal. But in the real world I doubt they're enough to
make a significant dent in Python's popularity.

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


Creating custom formatter function

2009-02-16 Thread Garrett Cooper
Hello Python folks,
I have a function where I'd like to prefix a format string via a
`prefix' string. The definition of the base method is as follows:

#START CODE
def print_message(prefix, out_stream, fmt, *args, **kwargs):
 Print out [prefix]: [message] 

message = fmt

if 0  len(kwargs.keys()):
message = message % kwargs

if 0  len(args):
message = message % args

out_stream.write(message + \n)
#END CODE

My python 2.4.5 interpreter fails at `message % args' claiming the
following:

  File logging.py, line 10, in print_message
message = message % (args)
TypeError: not all arguments converted during string formatting

Thus I was wondering what the proper means was for formatting
strings. I'm new to this portion of Python, so I obviously didn't
apply the right syntax.
TIA!
-Garrett
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread rushenaly
Hi again,

Dear Andreas

I know about GIL in ruby interpreter, they are trying to solve
problems because of GIL but it is not so important for me because i
like ruby because of its esthetic and it helps me to grasp some
programming concepts. As i know it is not so powerful language like
java. (Powerful language : rich libraries, wide community, very
variety of usage). why i want to learn python because it has syntax
like ruby but it is also powerful language, not of course as much as
java or c++

And also, i am trying to find an answer to the question mark in my
head. Is there a way to use multi cores in python as much effective
and easier as multi threading.

Dear Aleksa

Of course i have a long way to ago even if i am too old for these
things. However, i think that being able to use both cores or more is
a very big plus for execution time, speed like these. I believe many
programs will be rewritten to be able to use multiple cores.

Dear Michele

As i know every process has own hardware sources like memory and cpu
so i think it requires more source than multi threading.

Dear Tim

I want to learn python + c++ or java because of the desire of having
python's felxibility and easiness and c++ or java's stability and
speed and power together.

Thank you
Rushen



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


Re: Will multithreading make python less popular?

2009-02-16 Thread Tim Rowe
2009/2/16  rushen...@gmail.com:

 I want to learn python + c++ or java because of the desire of having
 python's felxibility and easiness and c++ or java's stability and
 speed and power together.

Yes, that's what I mean by different tradeoffs. Python is much easier
to program in than C++ or Java (in my experience, at least), but C++
and Java scale better and at least have the potential to be faster.
I'm not convinced that library support is significantly better for C++
or Java -- Python's libraries seem pretty rich to me. And that extra
speed might not be needed as often as you think. My postgrad
dissertation involved heavy number-crunching on large data sets, and
in my proposal I said I'd switch from Python to C++ when Python got
too slow. In fact, Python never did get too slow (I didn't even have
to switch to numpy), and plugging together ad-hoc modules, defined in
an XML script, was a dream in Python when I'd probably still be coding
it today in C++. Horses for courses. It's almost always wrong to say
that language A is better than language B; the most you can say is
that language A is better than language B for some specific task.


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


Re: Module to read/write MIDI ?

2009-02-16 Thread Tim Wintle
 I had my first look around pypi.python.org/pypi yesterday and didn't
 see anything.  Is there a MIDI-module for Python ?  If not, I'll
 email Sean to ask if he'd mind me translating his module into Python3...

http://www.mxm.dk/products/public/pythonmidi

This is the only project I have seen that aims to do that - I haven't
actually used it, and there might be others out there (I believe pygame
www.pygame.org supports midi-output).



 
 Regards,  Peter
 

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


replace ftp by local copy

2009-02-16 Thread loial
I have been given an old python application that calls ftplib in many
places to copy files to a remote server.

I have been given the task of cloneing this code so that ftp is not
used, but files are just copied locally in a scenerio where ftp is not
available. The code is not well structured which makes this more
difficult.

Before starting this just wondered if anyone has previously done
anything like overriding the ftplib module so that I can leave the
existing code largely unchanged but have the ftp commands just copy
files locally?

Just thought I'd ask before getting started.




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


logging and daemons

2009-02-16 Thread Fernando M. Maresca

Hello.

I'm in the process of replacing a custom logger class in one of my apps
that has several daemons. In the last step of daemonizing a program,
after closing fds, stderr and stdout are redirected to the logfile of
the program.

Now, I'm trying to use TimedRotatingFileHandler as the only channel when
the programs run in daemon mode. My problem is: I can't see a goog way
to redirect stderr/stdout both to the logger.

Note that I don't have any print statements in any of my code, but I
can't be sure about all the modules I'm importing, and I like to get any
uncached exception info that may go to stderr/stdout to show up in the
logfiles.

Any ideas?
Thanks a lot,

-- 
Fernando 


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: logging and daemons

2009-02-16 Thread Garrett Cooper
On Mon, Feb 16, 2009 at 5:02 AM, Fernando M. Maresca fmare...@gmail.com wrote:

 Hello.

 I'm in the process of replacing a custom logger class in one of my apps
 that has several daemons. In the last step of daemonizing a program,
 after closing fds, stderr and stdout are redirected to the logfile of
 the program.

 Now, I'm trying to use TimedRotatingFileHandler as the only channel when
 the programs run in daemon mode. My problem is: I can't see a goog way
 to redirect stderr/stdout both to the logger.

 Note that I don't have any print statements in any of my code, but I
 can't be sure about all the modules I'm importing, and I like to get any
 uncached exception info that may go to stderr/stdout to show up in the
 logfiles.

 Any ideas?
 Thanks a lot,

Hopefully this'll answer your question:

You can actually set sys.std[err|out] to your ?file? descriptor of
choice in python (it has to have read, write, and flush methods, IIRC
to function). The only thing is (like all things dealing with multiple
file descriptors like std[err|out]) the output may come in out of
order due to flushing and insertion into the buffers, but it shouldn't
be as much of an issue considering that the file descriptor for both
items is the same descriptor, but this is just a note of forewarning.

nose does something similar with the way that it scrapes stderr /
stdout for exception data and messages.

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


Re: logging and daemons

2009-02-16 Thread Fernando M. Maresca
Hello, thanks for the answer.

On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote:
 You can actually set sys.std[err|out] to your ?file? descriptor of
 choice in python (it has to have read, write, and flush methods, IIRC
 to function). The only thing is (like all things dealing with multiple
 file descriptors like std[err|out]) the output may come in out of
 order due to flushing and insertion into the buffers, but it shouldn't
 be as much of an issue considering that the file descriptor for both
 items is the same descriptor, but this is just a note of forewarning.
Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
fd of the logfile change in every rotation of the logfile. So the direct
approach of std[out|err] redirection to the logfile fd obtained from
the logger instance is unusable (it works fine with a simple file
handler). 
I'm looking into this because I really need rotating, because when
debugging is on, large amounts of data are logged, and because I like
the logging module approach in every aspect.

Also, may it be possible to derive the class and add a file-like write
method? Anyone using logging in this manner?


Cheers,
-- 
Fernando


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread andrew cooke
rushen...@gmail.com wrote:
 Hi everybody,
 I am an engineer. I am trying to improve my software development
 abilities. I have started programming with ruby. I like it very much
 but i want to add something more. According to my previous research i
 have designed a learning path for myself. It's like something below.
   1. Ruby (Mastering as much as possible)
   2. Python (Mastering as much as possible)
   3. Basic C++ or Basic Java
 And the story begins here. As i search on the net,  I have found that
 because of the natural characteristics of python such as GIL, we are
 not able to write multi threaded programs. Oooops, in a kind of time
 with lots of cpu cores and we are not able to write multi threaded
 programs. That is out of fashion. How a such powerful language doesn't
 support multi threading. That is a big minus for python. But there is
 something interesting, something like multi processing. But is it a
 real alternative for multi threading. As i searched it is not, it
 requires heavy hardware requirements (lots of memory, lots of cpu
 power). Also it is not easy to implement, too much extra code...

I understand why you are asking this question - you want to learn, and
that is good - but as you say, you are a beginner, and you are focussing
on one thing that has caught your eye when there are many other issues
that are more important.

The GIL is an implementation detail.  I suspect that it could be largely
removed if there was sufficient need.  But that still wouldn't make Python
a good language for programming on multiple cores.  That's not as big a
deal as you think, because we currently DON'T KNOW what would make a good
language for programming on multiple cores - it's an open topic in the
wider community.

It may be, for example, that the best approaches for concurrent
programming require a lot of automatic pre-processing that needs static
type information.  Or that mutable state is simply too much of a problem
and pure functional programming is the only way forwards.  Both of these
would be much more serious problems for Python than the GIL.  On the other
hand, Python has inbuilt support for co-routines.  Experience gained with
that might lead towards a more actors-like solution that fits naturally
within Python.

So my first point is that you are worrying about a problem that no-one yet
know how to solve, and worrying about a small and largely irrelevant part
of that.


Second, you are committing the common mistake of over-estimating the
importance of efficiency.  Python is not a fast language; it never has
been.  That does not stop it being extremely useful.  This is largely
because when it needs to do hard work it delegates to C libraries.  Why
can this not apply to concurrent programming too?  Maybe the top level
logic will stay in a single thread, because that is easier to program, but
libraries will use multiple cores.

So my second point is that you are being too restrictive in considering
what a future solution might look like.


In conclusion, then, I strongly suggest you stop worrying so much about
things that you don't yet have the experience to see completely, and
instead get more experience under your belt.  That sounds more harsh than
I really mean - obviously worrying about this kind of thing is part of
learning.

Incidentally, if you already know Ruby and want to improve your abilities
I am not sure learning Python is the best use of your time.  The two
languages are very similar.  You might be better taking a huge leap to
something like Haskell or OCaml.  Or, if you want to get hands-on
experience of concurrency now, Erlang.

Andrew



 After all of that, i start to think about omiting python from my
 carrier path and directly choosing c++ or java. But i know google or
 youtube uses python very much. How can they choose a language which
 will be killed by multi threading a time in near future. I like python
 and its syntax, its flexibility.

 What do you think about multi threading and its effect on python. Why
 does python have such a break and what is the fix. Is it worth to make
 investment of time and money to a language it can not take advantage
 of multi cores?

 Thank you...
 Rushen
 --
 http://mail.python.org/mailman/listinfo/python-list




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


Re: Will multithreading make python less popular?

2009-02-16 Thread andrew cooke
andrew cooke wrote:
 something like Haskell or OCaml.  Or, if you want to get hands-on
 experience of concurrency now, Erlang.

I think for once I said something useful there.  I think you would
probably enjoy Erlang, and it would be very useful for understanding
concurrency.  Also, Erlang is not as strange a language as Haskell or
OCaml.  You will probably find it quite familiar.  And there's an
excellent book (Joe Armstrong's Programming Erlang).

At the risk of hastening Python's demise :o) I strongly encourage you to
learn Erlang instead of Python.

Andrew


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


Re: logging and daemons

2009-02-16 Thread Garrett Cooper
On Mon, Feb 16, 2009 at 5:15 AM, Fernando M. Maresca fmare...@gmail.com wrote:
 Hello, thanks for the answer.

 On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote:
 You can actually set sys.std[err|out] to your ?file? descriptor of
 choice in python (it has to have read, write, and flush methods, IIRC
 to function). The only thing is (like all things dealing with multiple
 file descriptors like std[err|out]) the output may come in out of
 order due to flushing and insertion into the buffers, but it shouldn't
 be as much of an issue considering that the file descriptor for both
 items is the same descriptor, but this is just a note of forewarning.
 Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
 fd of the logfile change in every rotation of the logfile. So the direct
 approach of std[out|err] redirection to the logfile fd obtained from
 the logger instance is unusable (it works fine with a simple file
 handler).
 I'm looking into this because I really need rotating, because when
 debugging is on, large amounts of data are logged, and because I like
 the logging module approach in every aspect.

I cannot comment about this because I haven't used this module before.

 Also, may it be possible to derive the class and add a file-like write
 method? Anyone using logging in this manner?

Indeed, yes. That's sort of what I was hinting at with my statement
that you must have a read, write and flush method for your class. Now
that I think back, other modules like pexpect implement simple logic
to deal with writing to psuedo file descriptors as well.

Locking the data streams may or may not be required -- I'm not sure
what the underlaying portions of python expose or do not expose in
terms of scheduling in output streams.

HTH,
-Garrett
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread rushenaly
Dear Andrew,

I think reading beating the averages by paul graham before some
experience is not a very good decision.
:)

Thank you
Andrew
--
http://mail.python.org/mailman/listinfo/python-list


Re: logging and daemons

2009-02-16 Thread Neal Becker
Garrett Cooper wrote:

 On Mon, Feb 16, 2009 at 5:15 AM, Fernando M. Maresca fmare...@gmail.com
 wrote:
 Hello, thanks for the answer.

 On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote:
 You can actually set sys.std[err|out] to your ?file? descriptor of
 choice in python (it has to have read, write, and flush methods, IIRC
 to function). The only thing is (like all things dealing with multiple
 file descriptors like std[err|out]) the output may come in out of
 order due to flushing and insertion into the buffers, but it shouldn't
 be as much of an issue considering that the file descriptor for both
 items is the same descriptor, but this is just a note of forewarning.
 Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
 fd of the logfile change in every rotation of the logfile. So the direct
 approach of std[out|err] redirection to the logfile fd obtained from
 the logger instance is unusable (it works fine with a simple file
 handler).
 I'm looking into this because I really need rotating, because when
 debugging is on, large amounts of data are logged, and because I like
 the logging module approach in every aspect.
 
 I cannot comment about this because I haven't used this module before.
 
 Also, may it be possible to derive the class and add a file-like write
 method? Anyone using logging in this manner?
 
 Indeed, yes. That's sort of what I was hinting at with my statement
 that you must have a read, write and flush method for your class. Now
 that I think back, other modules like pexpect implement simple logic
 to deal with writing to psuedo file descriptors as well.
 
 Locking the data streams may or may not be required -- I'm not sure
 what the underlaying portions of python expose or do not expose in
 terms of scheduling in output streams.
 
 HTH,
 -Garrett
 --
 http://mail.python.org/mailman/listinfo/python-list

I use this, but for my own specialized purpose:

import atexit
class logger (object):
def __init__ (self, name):
self.name = name   # final file name
self.f = open (self.name, 'w')
atexit.register (self.__del__)
def write (self, stuff):
self.f.write (stuff)
def close (self):
self.f.close()
def flush (self):
self.f.flush()
def reopen (self):
self.f.flush()
self.f.close()
os.rename (self.name, self.name + '.old')
self.f = open (self.name, 'w')
def __del__ (self):
try:
os.remove (self.name + '.old')
except:
pass



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


to access the gretest

2009-02-16 Thread VEERENDRA
Vjrocks.comhttp://www.vjrocks.com/
BCA
BCA Ist YEARhttp://www.vjrocks.com/BCA_Ist_year.html
BCA IInd YEARhttp://www.vjrocks.com/BCA_IInd_year.html
BCA IIIrd YEARhttp://www.vjrocks.com/BCA_IIIrd_year.html

LANGUAGE

Introduction to Computershttp://www.vjrocks.com/Introduction to
Computers.html
Programming IN Chttp://www.vjrocks.com/Introduction to Computers.html
C++http://www.vjrocks.com/CPlusPlus.html
Javahttp://www.vjrocks.com/Java.htmlVisual Basic.html
Visual Basichttp://www.vjrocks.com/Visual Basic.html
--
http://mail.python.org/mailman/listinfo/python-list


What is a phyton?

2009-02-16 Thread www.livtotravel.blogspot.com
is phyton a programming language? what can a python do? how is it
different from others?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating custom formatter function

2009-02-16 Thread Alan G Isaac

On 2/16/2009 6:50 AM Garrett Cooper apparently wrote:

I was wondering what the proper means was for formatting
strings.


http://docs.python.org/library/string.html#string-formatting

http://docs.python.org/library/string.html#template-strings

http://docs.python.org/library/stdtypes.html#string-formatting

As for the last: values must be a tuple with exactly the number
of items specified by the format string, or a single mapping
object (for example, a dictionary) unless you need only a
single argument in your format string.

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


Threads in PyGTK: keep typing while ping-ing

2009-02-16 Thread Mamahita Sela
Dear All,

I have read several howtos for threading in PyGTK. I have tried some but with 
no luck.

What i want is: i can keep typing in gtk.TextView while periodically doing ping 
some hosts.
 
I think, the thread part is working since i can ping so fast (even for not 
reply host, around 3 s for 27 no-reply-host). But, when the ping action is 
running, i can not typing in textview. What i type while pinging will show up 
after ping action is done. 

(I am using 2.5.1, pygtk 2.10.6 on Linux x86)

This is my code:
import threading
import commands 
import gtk
import gobject

gtk.gdk.threads_init()


class PingHost(threading.Thread):
def __init__(self, host):
threading.Thread.__init__(self)
self.host = host
self.result = ()
def run(self):
self.result = self.host, commands.getstatusoutput('ping %s -c1' 
%(self.host))[0]

class Main:
def __init__(self):
self.win = gtk.Window()
self.win.connect('destroy', gtk.main_quit)
#
self.textb = gtk.TextBuffer()
self.textv = gtk.TextView(self.textb)
self.textv.set_size_request(500, 500)
#
self.win.add(self.textv)
self.win.show_all()
#
gobject.timeout_add(5000, self.do_ping)

def do_ping(self):
all_threads = []
#
for h in range(100, 105):
host = '192.168.0.%d' %(h)
#
worker = PingHost(host)
worker.start()
all_threads.append(worker)
#
for t in all_threads:
t.join()
print t.result
#
return True


if __name__ == '__main__':
app = Main()
gtk.main()


Any help would be appreciated :)
Best regards,
M


  

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


Re: Will multithreading make python less popular?

2009-02-16 Thread Aleksa Todorovic
Or the other way around :-)

Little off-topic, but...

After several months of fighting with Java threads, dead locks, live
locks, race conditions, I've rewritten my game server synchronization
so that threads are executed in concurrent way (with only exceptions
being socket sending and recieving threads), and all synchronization
is implemented on top of Java blocking structures (little blasphemy:
the way Stackless does it). After that change, the game suddenly
started working like a charm!


On Mon, Feb 16, 2009 at 13:24,  rushen...@gmail.com wrote:
 Of course i have a long way to ago even if i am too old for these
 things. However, i think that being able to use both cores or more is
 a very big plus for execution time, speed like these. I believe many
 programs will be rewritten to be able to use multiple cores.



-- 
Aleksa Todorovic - Lead Programmer
Eipix Entertainment
http://www.eipix.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread rushenaly
Dear Aleksa,

As you mentioned, using multi cores makes programs more fast and more
popular. But what about stackless python? Does it interpret same set
of python libraries with Cpython or Does it have a special sub set?

Thank you
Rusen
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is a phyton?

2009-02-16 Thread Thorsten Kampe
* www.livtotravel.blogspot.com (Mon, 16 Feb 2009 05:45:09 -0800 (PST))
 is phyton a programming language?

http://en.wikipedia.org/wiki/Phyton
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threads in PyGTK: keep typing while ping-ing

2009-02-16 Thread Jean-Paul Calderone

On Mon, 16 Feb 2009 05:47:22 -0800 (PST), Mamahita Sela 
mamahitas...@yahoo.com wrote:

Dear All,

I have read several howtos for threading in PyGTK. I have tried some but with 
no luck.

What i want is: i can keep typing in gtk.TextView while periodically doing ping 
some hosts.


You don't need threads for this.  The GTK mainloop supports socket event
sources.  This lets you deal with the GUI and with the network in a single
thread without blocking anything.



I think, the thread part is working since i can ping so fast (even for not 
reply host, around 3 s for 27 no-reply-host). But, when the ping action is 
running, i can not typing in textview. What i type while pinging will show up 
after ping action is done.


This is because you're joining the threads in the GTK thread.  Joining
blocks until the thread being joined exits.  While you're blocking the
GTK thread like this, the GTK GUI is not updated.  If you want to keep
using threads, then you need a way to avoid joining the threads until
you know they're done.

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


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Gustavo Narea
On Feb 14, 3:27 pm, Michele Simionato michele.simion...@gmail.com
wrote:
 I lack the context to see how this could be fixed in your case, but
 this a not a show stopper, you can just keep the original decorator
 and forget about making itsignature preserving.

I'm sorry for the possibly dumb question, but how can I do that?

Thanks for all the time you've spent on this, Michele.

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


Re: What is a phyton?

2009-02-16 Thread Diez B. Roggisch

Thorsten Kampe schrieb:

* REMOVED(Mon, 16 Feb 2009 05:45:09 -0800 (PST))

is phyton a programming language?


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


Thanks for quoting the OPs spam name so that the visibility of his post 
 is increased.


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


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Michele Simionato
On Feb 16, 3:50 pm, Gustavo Narea m...@gustavonarea.net wrote:
 On Feb 14, 3:27 pm, Michele Simionato michele.simion...@gmail.com
 wrote:

  I lack the context to see how this could be fixed in your case, but
  this a not a show stopper, you can just keep the original decorator
  and forget about making itsignature preserving.

 I'm sorry for the possibly dumb question, but how can I do that?

 Thanks for all the time you've spent on this, Michele.

   - Gustavo.

Let the original code as it is. If ain't broken, don't fix it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Gustavo Narea
On Feb 16, 3:56 pm, Michele Simionato michele.simion...@gmail.com
wrote:
 On Feb 16, 3:50 pm, Gustavo Narea m...@gustavonarea.net wrote:

  On Feb 14, 3:27 pm, Michele Simionato michele.simion...@gmail.com
  wrote:

   I lack the context to see how this could be fixed in your case, but
   this a not a show stopper, you can just keep the original decorator
   and forget about making itsignature preserving.

  I'm sorry for the possibly dumb question, but how can I do that?

  Thanks for all the time you've spent on this, Michele.

- Gustavo.

 Let the original code as it is. If ain't broken, don't fix it.

But the problem is that it is broken.

That decorator is for controller actions in Pylons-powered web
applications (which are instance methods). Pylons inspects the
action's signature to find what parameters it's going to pass to its
instance method, which fails because my current decorator changes the
signature.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Michele Simionato
On Feb 16, 4:07 pm, Gustavo Narea m...@gustavonarea.net wrote:
 But the problem is that it is broken.

 That decorator is for controller actions in Pylons-powered web
 applications (which are instance methods). Pylons inspects the
 action's signature to find what parameters it's going to pass to its
 instance method, which fails because my current decorator changes the
 signature.

Yes, I am saying don't mess with the internal mechanism of Pylons and
leave it as
it was. Or was it broken from the beginning? The only reason I see for
you
to touch those things is if you are a Pylons core developer.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread Hendrik van Rooyen
andrew cooke and...@aorg wrote:


The GIL is an implementation detail.  I suspect that it could be largely
removed if there was sufficient need.  But that still wouldn't make Python
a good language for programming on multiple cores.  That's not as big a
deal as you think, because we currently DON'T KNOW what would make a good
language for programming on multiple cores - it's an open topic in the
wider community.

Those who do not study history are doomed to repeat it.

Occam was the language that should have won the marketing
prize, but didn't.

- Hendrik


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


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Gustavo Narea
On Feb 16, 4:18 pm, Michele Simionato michele.simion...@gmail.com
wrote:
 Yes, I am saying don't mess with the internal mechanism of Pylons and
 leave it as
 it was. Or was it broken from the beginning? The only reason I see for
 you
 to touch those things is if you are a Pylons core developer.

It was broken from the beginning on Pylons.

I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons
as of version 2. The decorator has always worked in TurboGears because
of the way TG finds the action arguments, but now I'm working to make
it work in Pylons too, but this is the only problem that has stopped
me from making it work under Pylons.

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


RedHat 4

2009-02-16 Thread Germán Gutiérrez
Hi,

I need to confirm and certificate python 2.5 works in a RedHat Enterprise 4 and 
I don't know where I find that information. Please, if anybody knows some URL 
in RedHat or Python with this information email me.

Thanks

 Germán Gutiérrez Gayoso
Temuco



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


Re: Python interface to ODF documents?

2009-02-16 Thread Lie Ryan
On Sun, 15 Feb 2009 22:03:25 +0200, Dotan Cohen wrote:

 Is there a Python interface to ODF documents? I'm thinking of something
 that will import, for example, an ADS spreadsheet into a
 multidimensional array (including formulas and formatting) and let me
 manipulate it, then save it back.
 

Since python is one of OpenOffice.org's Macro language, depending on your 
need, you might be able to use that as well.

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


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Michele Simionato
On Feb 16, 4:29 pm, Gustavo Narea m...@gustavonarea.net wrote:
 On Feb 16, 4:18 pm, Michele Simionato michele.simion...@gmail.com
 wrote:

  Yes, I am saying don't mess with the internal mechanism of Pylons and
  leave it as
  it was. Or was it broken from the beginning? The only reason I see for
  you
  to touch those things is if you are a Pylons core developer.

 It was broken from the beginning on Pylons.

 I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons
 as of version 2. The decorator has always worked in TurboGears because
 of the way TG finds the action arguments, but now I'm working to make
 it work in Pylons too, but this is the only problem that has stopped
 me from making it work under Pylons.

 Thanks.

I see. I would ask on the Pylons list. I suspect a bound method is
passed and that you will
need to extract the corresponding function with .im_func, then making
sure that you pass
the self argument correctly. But this is wild guess since I have no
idea of how Pylons decorators
work internally as compared to TurboGears decorators.
--
http://mail.python.org/mailman/listinfo/python-list


Re: RedHat 4

2009-02-16 Thread J. Cliff Dyer
It *works* in RHEL 4, but it doesn't come as a package.  RHEL4 ships
with Python 2.3, and RHEL 5 only ships with Python 2.4, even though 2.5
had been out for god knows how long when it came out.

Though I haven't tested it, I wouldn't recommend replacing the system's
python binary with 2.5 if you do install it yourself.  Instead, install
it to python2.5, and set the shebang line (#!) on your scripts to point
to /usr/local/bin/python2.5  (or wherever you install it).  

Cheers,
Cliff

On Mon, 2009-02-16 at 07:28 -0800, Germán Gutiérrez wrote:
 Hi,
 
 I need to confirm and certificate python 2.5 works in a RedHat
 Enterprise 4 and I don't know where I find that information. Please,
 if anybody knows some URL in RedHat or Python with this information
 email me.
 
 Thanks
  
 Germán Gutiérrez Gayoso
 Temuco
 
 
 
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Will multithreading make python less popular?

2009-02-16 Thread Christof Donat
Hi,

 But there is
 something interesting, something like multi processing. But is it a
 real alternative for multi threading. As i searched it is not, it
 requires heavy hardware requirements (lots of memory, lots of cpu
 power).

Not necessarily.

For the memory, modern operating Systems can ustilize a copy on write 
semantics in their Applications virtual memory space. That means that after 
starting a new process with fork(), the new Process shares all physical 
Memory Pages with the original one as long a none of them writes to wome 
Memory. The first write is cought by the OS. Then the Page will be copied 
and the writing process will in future use the new copy of that page while 
the other one (or eventually many) stay with the original. Multiprocessing 
needs more Memory than well optimized Multithreading, but it is not as bad 
as it is often said.

For the CPU: There are two things that make the difference here.

One ist Context Switching. When the OS switches between two threads of the 
same Process, it does not need to change the memory lookup table. When 
switching between Processes that is always necessary. Switching from a 
Thread of Process A to a Thread of Process B is just like switching from A 
to B.

Using Threads just increases the probability that the OS can do a faster 
Context Switch. So Threads are faster here, but it is not a too big issue as 
well.

The Second Thing is Communication. With Threds you can simply use variables 
to communicate between Threads. To Prevent conflicting access to those 
Variables you will use e.g. mutexes. That can be done with Shared Memory as 
well. Shared Memory is a bit more difficult to handle than simply using the 
heap, but again the impact is not really so big.

Google uses Processes for the Tabs in Chrome, because that way they get 
around many Memory Management Problems they would have with Threads or with 
a singlethreaded reactor. Using Processes is not per se a bad Idea. You pay 
a bit with Memory and CPU but in many situations you get a much simpler 
programming model.

Christof


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


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Gustavo Narea
On Feb 16, 4:40 pm, Michele Simionato michele.simion...@gmail.com
wrote:
  It was broken from the beginning on Pylons.

  I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons
  as of version 2. The decorator has always worked in TurboGears because
  of the way TG finds the action arguments, but now I'm working to make
  it work in Pylons too, but this is the only problem that has stopped
  me from making it work under Pylons.

  Thanks.

 I see. I would ask on the Pylons list. I suspect a bound method is
 passed and that you will
 need to extract the corresponding function with .im_func, then making
 sure that you pass
 the self argument correctly. But this is wild guess since I have no
 idea of how Pylons decorators
 work internally as compared to TurboGears decorators.

I've not seen anything special in Pylons or TurboGears 2 decorators,
except that they are all functions that use the decorator package --
while my decorator is a class that doesn't use the decorator package
yet.

My attempt to turn that decorator into a signature preserving one
using the decorator packages fails even on TurboGears 2. As of
decorator 3.0.1, I get this error:
TypeError: You are decorating a non function: unbound method
SecurePanel.__before__

Isn't this caused by the fact that my decorator is a class, or the way
such a class is defined (whose code is in the first post of the
thread)? I can turn it into a function because I'm sure I'll work --
although I wanted a class to make it easier to customize.

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


Re: What is a phyton?

2009-02-16 Thread Python


On 16 feb 2009, at 14:45, www.livtotravel.blogspot.com wrote:


is phyton a programming language? what can a python do? how is it
different from others?
--

If i were to replace 'python' with 'french'
would you be willing to write the answer in one email?
it's gonna be a loong email...

if you want to know, type the same questions in google...
or start by reading http://www.python.org

if you don;t want that, then maybe go to a zoo and follow the signs ;)

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


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Gustavo Narea
On Feb 16, 4:59 pm, Gustavo Narea m...@gustavonarea.net wrote:
 On Feb 16, 4:40 pm, Michele Simionato michele.simion...@gmail.com
 wrote:



   It was broken from the beginning on Pylons.

   I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons
   as of version 2. The decorator has always worked in TurboGears because
   of the way TG finds the action arguments, but now I'm working to make
   it work in Pylons too, but this is the only problem that has stopped
   me from making it work under Pylons.

   Thanks.

  I see. I would ask on the Pylons list. I suspect a bound method is
  passed and that you will
  need to extract the corresponding function with .im_func, then making
  sure that you pass
  the self argument correctly. But this is wild guess since I have no
  idea of how Pylons decorators
  work internally as compared to TurboGears decorators.

 I've not seen anything special in Pylons or TurboGears 2 decorators,
 except that they are all functions that use the decorator package --
 while my decorator is a class that doesn't use the decorator package
 yet.

 My attempt to turn that decorator into a signature preserving one
 using the decorator packages fails even on TurboGears 2. As of
 decorator 3.0.1, I get this error:
 TypeError: You are decorating a non function: unbound method
 SecurePanel.__before__

 Isn't this caused by the fact that my decorator is a class, or the way
 such a class is defined (whose code is in the first post of the
 thread)? I can turn it into a function because I'm sure I'll work --
 although I wanted a class to make it easier to customize.

 Thanks.


This is another attempt, where the decorator is a still a class but
uses an auxiliary function:
http://paste.chrisarndt.de/paste/38bf8a8443614464968d424e1f2d4182

However, that raises this exception:
http://paste.chrisarndt.de/paste/f90bc9a058254e2ca5660882011752a7?wrap=no
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python interface to ODF documents?

2009-02-16 Thread Dotan Cohen
 Since python is one of OpenOffice.org's Macro language, depending on your
 need, you might be able to use that as well.


That's not a bad idea. Thanks!

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Michele Simionato
On Feb 16, 4:59 pm, Gustavo Narea m...@gustavonarea.net wrote:
 I've not seen anything special in Pylons or TurboGears 2 decorators,
 except that they are all functions that use the decorator package --
 while my decorator is a class that doesn't use the decorator package
 yet.

 My attempt to turn that decorator into a signature preserving one
 using the decorator packages fails even on TurboGears 2. As of
 decorator 3.0.1, I get this error:
     TypeError: You are decorating a non function: unbound method
 SecurePanel.__before__

 Isn't this caused by the fact that my decorator is a class, or the way
 such a class is defined (whose code is in the first post of the
 thread)? I can turn it into a function because I'm sure I'll work --
 although I wanted a class to make it easier to customize.

 Thanks.

The decorator class is fine, the error in clearly in what you pass to
the decorator.
You are trying to decorate an unbound method SecurePanel.__before__:
are you
sure this is really what you want to decorate? Are you decorating
automatically all methods
of SecurePanel? I have already mentioned it, but you can extract the
underlying function
from the method by using  SecurePanel.__before__.im_func if you really
want.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread seb . binet
hi there,

[snip]
 Google uses Processes for the Tabs in Chrome, because that way they get
 around many Memory Management Problems they would have with Threads or with
 a singlethreaded reactor. Using Processes is not per se a bad Idea. You pay
 a bit with Memory and CPU but in many situations you get a much simpler
 programming model.

note also that one can bet on things like KSM [1] to further improve
the memory situation.

For example, we are investigating its use in the large (read heavy)
application frameworks at CERN where the typical vmem footprint is
~2Gb.
Running KSM together with a multiprocessing-based event loop manager,
we
managed to overcommit ~300% of the memory (ie: run 3 instances of our
application on a 2Gb-per-core machine)

cheers,
sebastien

[1] http://lwn.net/Articles/306642
--
http://mail.python.org/mailman/listinfo/python-list


RE: Changing the Image on a button

2009-02-16 Thread John Posner
  from Tkinter import *
  
  def do():
  btn.configure(image = None)
  
  root = Tk()
  img1 = PhotoImage(file=bacon.gif)
  
  btn = Button(image = img1, command = do, text = hello )
  btn.img = img1
  btn.pack()
  root.mainloop()
  

Try this change:

  from: btn.configure(image = None)
to: img1.blank()

-John







E-mail message checked by Spyware Doctor (6.0.0.386)
Database version: 5.11770
http://www.pctools.com/en/spyware-doctor-antivirus/
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] RELEASED Python 3.0.1

2009-02-16 Thread Benjamin Peterson
On Sun, Feb 15, 2009 at 9:15 PM, Ned Deily n...@acm.org wrote:

 It would be great if someone could add OS X links for the 3.0.1 and
 2.6.1 to the main download page, too:
   http://www.python.org/download/

I've now added them to the main download page.




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


Re: Windows vista

2009-02-16 Thread Dick
On Feb 16, 1:46 am, loveshadow...@yahoo.com wrote:
 Hi. My name is toru.
 I start learning python couple weeks ago.

 I install the compiler from python.org.
 but I cannot use the IDLE program.
 (command line works fine so far)
 the error screen says that the my personal fire wall is blocking the
 program to run.
 I am not sure how to fix this.
 By the way, I heard many people said that this is because I am using
 windows vista.
 Does anyone know how to use IDLE program on Windows Vista machine?

 thank you.

On my Vista machine I reply to a firewall popup the first time I run
IDLE and tell it to allow
IDLE to open a port. The next time I run IDLE, all is OK. I still have
the problem that
sometimes IDLE does not properly cleanup hung processes, which means
IDLE will not restart.

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


Re: Threads in PyGTK: keep typing while ping-ing

2009-02-16 Thread bieffe62
On 16 Feb, 14:47, Mamahita Sela mamahitas...@yahoo.com wrote:
 Dear All,

 I have read several howtos for threading in PyGTK. I have tried some but with 
 no luck.

 What i want is: i can keep typing in gtk.TextView while periodically doing 
 ping some hosts.

 I think, the thread part is working since i can ping so fast (even for not 
 reply host, around 3 s for 27 no-reply-host). But, when the ping action is 
 running, i can not typing in textview. What i type while pinging will show up 
 after ping action is done.

 (I am using 2.5.1, pygtk 2.10.6 on Linux x86)

 This is my code:
 import threading
 import commands
 import gtk
 import gobject

 gtk.gdk.threads_init()

 class PingHost(threading.Thread):
     def __init__(self, host):
         threading.Thread.__init__(self)
         self.host = host
         self.result = ()
     def run(self):
         self.result = self.host, commands.getstatusoutput('ping %s -c1' 
 %(self.host))[0]

 class Main:
     def __init__(self):
         self.win = gtk.Window()
         self.win.connect('destroy', gtk.main_quit)
         #
         self.textb = gtk.TextBuffer()
         self.textv = gtk.TextView(self.textb)
         self.textv.set_size_request(500, 500)
         #
         self.win.add(self.textv)
         self.win.show_all()
         #
         gobject.timeout_add(5000, self.do_ping)

         def do_ping(self):
         all_threads = []
         #
         for h in range(100, 105):
             host = '192.168.0.%d' %(h)
             #
             worker = PingHost(host)
             worker.start()
             all_threads.append(worker)
         #
         for t in all_threads:
             t.join()
             print t.result
         #
         return True

 if __name__ == '__main__':
     app = Main()
     gtk.main()

 Any help would be appreciated :)
 Best regards,
 M

As you have been already told, join() blocks until the thread is
terminated. and you should avoid that.
A simple fix could by add a timeout to t.join, doing something like :
t.join(JOIN_TIMEOUT);
if not t.isAlive():
print t.result

Anywway, starting a thread for each ping is not very efficient, so you
could do better by having a 'ping server thread'
that repeatedly performs the following steps:
- accepts ping command on a queue.Queue
- ping the target and waits for the result
- publish the result on another queue.Queue

At this point, the do_ping action should:
  - send a ping command to the oping server
  - check (in non blocking mode) if there is any result on the ping
results queue
  - display the result, if any

Another big speedup would be to avoid spawning a subprocess fro each
ping and instead
using directly sockets to send ICMP packets, using recipes like this :

http://code.activestate.com/recipes/409689/

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


Re: Turning a signature-changing decorator into a signature-preserving one

2009-02-16 Thread Gustavo Narea
On Feb 16, 5:18 pm, Michele Simionato michele.simion...@gmail.com
wrote:
 On Feb 16, 4:59 pm, Gustavo Narea m...@gustavonarea.net wrote:



  I've not seen anything special in Pylons or TurboGears 2 decorators,
  except that they are all functions that use the decorator package --
  while my decorator is a class that doesn't use the decorator package
  yet.

  My attempt to turn that decorator into a signature preserving one
  using the decorator packages fails even on TurboGears 2. As of
  decorator 3.0.1, I get this error:
  TypeError: You are decorating a non function: unbound method
  SecurePanel.__before__

  Isn't this caused by the fact that my decorator is a class, or the way
  such a class is defined (whose code is in the first post of the
  thread)? I can turn it into a function because I'm sure I'll work --
  although I wanted a class to make it easier to customize.

  Thanks.

 The decorator class is fine, the error in clearly in what you pass to
 the decorator.
 You are trying to decorate an unbound method SecurePanel.__before__:
 are you
 sure this is really what you want to decorate? Are you decorating
 automatically all methods
 of SecurePanel? I have already mentioned it, but you can extract the
 underlying function
 from the method by using  SecurePanel.__before__.im_func if you really
 want.

Thank you very much, it works with SecurePanel.__before__.im_func!
--
http://mail.python.org/mailman/listinfo/python-list


Re: logging and daemons

2009-02-16 Thread Diez B. Roggisch

Fernando M. Maresca schrieb:

Hello.

I'm in the process of replacing a custom logger class in one of my apps
that has several daemons. In the last step of daemonizing a program,
after closing fds, stderr and stdout are redirected to the logfile of
the program.

Now, I'm trying to use TimedRotatingFileHandler as the only channel when
the programs run in daemon mode. My problem is: I can't see a goog way
to redirect stderr/stdout both to the logger.

Note that I don't have any print statements in any of my code, but I
can't be sure about all the modules I'm importing, and I like to get any
uncached exception info that may go to stderr/stdout to show up in the
logfiles.


why don't you just replace the sys.stdout/sys.stdin objects with 
something that is file-like (supports a write-method, that should be 
enough in this case), and then simply write the data arriving to the 
logger instance of your trust.


If other modules don't get overly tricky to bypass sys.stdout, that 
should capture all you output, regardless of the file descriptor issues.


In the end, if a 3rd-party-module choses to open a filedescriptor itself 
 write to that, there is nothing you can do about that. But usually, 
they don't behave that way.


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


Re: logging and daemons

2009-02-16 Thread Vinay Sajip
On Feb 16, 1:15 pm, Fernando M. Maresca fmare...@gmail.com wrote:
 Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
 fd of the logfile change in every rotation of the logfile. So the direct
 approach of std[out|err] redirection to the logfile fd obtained from
 the logger instance is unusable (it works fine with a simple file
 handler).

That's fine with a FileHandler, as long as you don't use e.g.
logrotate - that would cause the fd to change, too.

 I'm looking into this because I really need rotating, because when
 debugging is on, large amounts of data are logged, and because I like
 the logging module approach in every aspect.


You can capture the stuff written to std[out|err] using any file-like
object, so there are other options beyond redirecting to the fd of the
handler's fd or adding a write method to the logger. For example, if
you create a simple class which duck-types the file-like object, you
could create two instances, for stdout and stderr, and wire them into
sys. At any point you choose, you can choose to forward the
information collected to the log. Is all your stuff pure Python, or do
you have C extensions or subprocesses which are C-based? Also, I
assume you have a separate rotating log file per daemon - is that
right?

Regards,

Vinay Sajip

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


Re: Will multithreading make python less popular?

2009-02-16 Thread Scott David Daniels

andrew cooke wrote:
The best short to the GIL issue that I have read in a long time

Thanks a lot for writing this, I'll be pointing to it from time to time.
Were I writing such a thing I'd focus too much on the how (issues I know
that non-GIL true concurrency faces), and not enough on the high level
view.

Bravo.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can this iterator be optimized?

2009-02-16 Thread Basilisk96
On Feb 14, 10:19 am, Paul McGuire pt...@austin.rr.com wrote:
 If func is expensive, you could try memoizing it.  Then subsequent
 calls just do arg lookups.  Michele Simianato has posted a good
 memoizing decorator on the Python wiki.

 -- Paul

That's the trick! I almost forgot about that one. Thanks!
-Basilisk96
--
http://mail.python.org/mailman/listinfo/python-list


chi squared (X2) in Python

2009-02-16 Thread ts8807385
I was wondering if anyone has done this in Python. I wrote two
functions that do it (I think... see below), but I do not understand
how to interpret the results. I'm doing an experiment to implement ent
in Python. ent tests the randomness of files and chi squared is
probably the best test for this purposes when compared to other tests.
Many of the statistical tests are easy (like Arithmetic Mean, etc) and
I have no problems interpreting the results from those, but chi
squared has stumped me. Here are my two simple functions, run them if
you like to better understand the output:

import os
import os.path

def observed(f):

# argument f is a filepath/filename
#
# Return a list of observed characters in decimal ord(char).
# Decimal value of characters may be 0 through 255.
# [43, 54, 0, 255, 4, etc.]

chars = []
#print f

fd = open(f, 'rb')
bytes = fd.read(13312)
fd.close()

for byte in bytes:
chars.append(ord(byte))

#print chars

if len(chars) != 13312:
print Wait... chars does not equal 13312 in observed!!!
return None
else:
return chars

def chi(char_list):

# Expected frequency of characters. I arrived at this like so:
# expected = number of observations/number of possibilities
# 52 = 13312/256

expected = 52.0

print observed\texpected\tx2

# 0 - 255
for x in range(0,256):
observed = 0
for char in char_list:
if x == char:
observed +=1

# The three chi squared calculations
# one = observed - expected
# two = one squared
# x2 = two/expected

# x2 = (observed - expected) squared
#   
#expected

one = observed - expected
two = one * one
x2 = two/expected

print observed, \t, expected, \t, x2


chi(observed(filepath))

The output looks similar to this:

observedexpectedx2
62  52.01.92307692308
46  52.00.692307692308
60  52.01.23076923077
68  52.04.92307692308

I know this is a bit off-topic here, just hoping someone could help me
interpret the x2 variable. After that, I'll be OK. I need to sum up
things to get an overall x2 for the bytes I've read, but before doing
that, I wanted to post this note. Please feel free to comment on any
aspect of this. If I've got something entirely wrong, let me know.
BTW, I selected 13KB (13,312) as it seems to be efficient and a decent
size to test, the data could be any amount (up to and including the
whole file) above this.

Thanks,

Tiff

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


Re: how to distribute python extensions independently of python

2009-02-16 Thread M.-A. Lemburg
On 2009-02-12 18:38, Travis wrote:
 So,
 
 Recently I made a fix to the zlib module that I need for use at work.
 
 I would like other employees to be able to use it without recompiling python.
 
 I assume I can just rename it and distribute it as a python extension.
 
 I was wondering how I can provide a way for other employees to build it.
 
 I saw a Universal Unix Makefile for Python extensions that looks promising.
 
 Is this the accepted way to compile python extensions still?

Not really. That approach was abandoned years ago in favor of a
distutils approach:

http://docs.python.org/distutils/index.html

in particular:

http://docs.python.org/distutils/setupscript.html#describing-extension-modules

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 16 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way to determine if one char of many in a string

2009-02-16 Thread Nicolas Dandrimont
* pyt...@bdurham.com pyt...@bdurham.com [2009-02-16 00:48:34 -0500]:

 Nicolas,
 
  I would go for something like:
  
  for char in word:
  if char in 'aeiouAEIUO':
  char_found = True
  break
  else:
  char_found = False
 
  It is clear (imo), and it is seems to be the intended idiom for a 
  search loop, that short-circuits as soon as a match is found.
 
 Thank you - that looks much better that my overly complicated attempts.
 
 Are there any reasons why I couldn't simplify your approach as follows?
 
 for char in word:
 if char in 'aeiouAEIUO':
 return True
 return False

If you want to put this in its own function, this seems to be the way to go.

Cheers,
-- 
Nicolas Dandrimont

The nice thing about Windows is - It does not just crash, it displays a
dialog box and lets you press 'OK' first.
(Arno Schaefer's .sig)


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to distribute python extensions independently of python

2009-02-16 Thread Robert Kern

On 2009-02-12 11:38, Travis wrote:

So,

Recently I made a fix to the zlib module that I need for use at work.


Would you mind contributing this fix back to Python?

  http://bugs.python.org/

If you don't want to go to the effort of making a patch, at least a description 
of the problem you encountered and a description of your fix would be helpful.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: logging and daemons

2009-02-16 Thread Scott David Daniels

Fernando M. Maresca wrote:
 On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote:

You can actually set sys.std[err|out] to your ?file? descriptor of
choice in python 

Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
fd of the logfile change in every rotation of the logfile. So the direct
approach of std[out|err] redirection to the logfile fd obtained from
the logger instance is unusable (it works fine with a simple file
handler). 


Right, so you stick something in as stderr/stdout that talks to the
logfile.  That is, something like:

import sys

class MyFakeStdout(object):
def flush(self):
pass
def write(self, text):
code to actually do the logging
sys.stderr = sys.stdout = MyFakeStdout()


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


pythojn/xpath question...

2009-02-16 Thread bruce
hi...

using libxml2dom as the xpath lib

i've got a situation where i can have:
 foo=a.xpath( /html/body/table[2]/tr[45]/td)
and i can get
 11 as the number of returned td elements for the 45th row...

this is as it should be.

however, if i do:
 foo=a.xpath( /html/body/table[2]/tr)

and then try to iterate through to the 45th tr, and try to get the number
of td elements..
i can't seem to get the additional xpath that has to be used,

i've tried a number of the following with no luck...
  l1 = libxml2dom.toString(tmp_[0])
  print l1 = +l1+\n

  ldx = 0
  for l in tmp_:
print ld =+str(ldx)
if ldx==45:
  #needs to be a better way...
  #l1 = libxml2dom.toString(tmp_[0])
  l1 = libxml2dom.toString(l)
  #print  = ,l1

  q1 = libxml2dom
  b1 = q1.parseString(l1, html=1)
  #dd1 = b1.xpath(//td[not(@width)])
  #data = b1.xpath(//td/font)
  #data = b1.xpath(//t...@valign='top'][not(@width)])
  #data =
b1.xpath(//child::td[position()0...@valign='top'][not(@width)])
  #data = b1.xpath(//td/parent::*/t...@valign='top'][not(@width)])
  #data = b1.xpath(//td[position()])
  #data = b1.xpath(//parent::tr[position()=1]/td)
  data = b1.xpath(//t...@valign='top'][not(@width)])


it appears that i somehow need to get the direct child/node of the parent
tr that's the td...
it looks like using (//td... gets all the underlying child td... as
opposed to the direct
1st level child/siblings... any thoughts/pointers would be appreciated...

thanks...


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


Re: Pythonic way to determine if one char of many in a string

2009-02-16 Thread J. Cliff Dyer

On Mon, 2009-02-16 at 00:28 -0500, Nicolas Dandrimont wrote:
 * pyt...@bdurham.com pyt...@bdurham.com [2009-02-16 00:17:37 -0500]:
 
  I need to test strings to determine if one of a list of chars is
  in the string. A simple example would be to test strings to
  determine if they have a vowel (aeiouAEIOU) present.
  I was hopeful that there was a built-in method that operated
  similar to startswith where I could pass a tuple of chars to be
  tested, but I could not find such a method.
  Which of the following techniques is most Pythonic or are there
  better ways to perform this type of match?
  # long and hard coded but short circuits as soon as match found
  if 'a' in word or 'e' in word or 'i' in word or 'u' in word or
  ... :
  -OR-
  # flexible, but no short circuit on first match
  if [ char for char in word if char in 'aeiouAEIOU' ]:
  -OR-
  # flexible, but no short circuit on first match
  if set( word ).intersection( 'aeiouAEIOU' ):
 
 I would go for something like:
 
 for char in word:
 if char in 'aeiouAEIUO':
 char_found = True
 break
 else:
 char_found = False
 
 (No, I did not forget to indent the else statement, see
 http://docs.python.org/reference/compound_stmts.html#for)
 
 It is clear (imo), and it is seems to be the intended idiom for a search
 loop, that short-circuits as soon as a match is found.
 

If performance becomes an issue, you can tune this very easily, so it
doesn't have to scan through the string 'aeiouAEIOU' every time, by
making a set out of that:

vowels = set('aeiouAEIOU')
for char in word 
if char in vowels:
return True
return False

Searching in a set runs in constant time.  


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

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


Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread laplacian42
On Feb 16, 2:34 am, Python Nutter pythonnut...@gmail.com wrote:
 Had a look and it is still under my radar unfortunately because of
 TkInter. OceanGUI

Note: spelling is OcempGUI. Also, since google broke some of the
links,
here's that main link again:

http://ocemp.sourceforge.net/gui.html

 has a lot of large decencies (Pygame, SDL libraries,
 PyObjC, etc.) to install on my system

Well, to be fair, SDL is pretty commonly-used software and they offer
binary downloads for Mac OS X and MS Windows. Pygame seems to provide
the same. So, installation should be a breeze.

 to just to get a GUI thats no
 better loking than TkInter which comes pre-installed (no dependencies)
 on most every major platform.

Well, of course, there *is* a dependency: you need Tcl/Tk installed.

 If I was writing a game I might be interested, but I'd want to do some
 serious skinning of that GUI to make it look better.

I suppose so, but the point of my post was that by default it makes
quite a nice GUI toolkit.

 For applications installing the full wxWidgets or Qt toolkits would be
 less disk space and dependcies than OceanGUI

What? Qt and wX are *huge* compared to OcempGUI.

 and performance would
 probably be higher.

Probably, but wX and Qt are written in C++. OcempGUI is pure Python,
which would make it easier for the Python community to help extend,
optimize, and maintain.

 TkInter also has many skins/themes you can add
 that makes it rather, although not 100% native looking on target
 systems.

OcempGUI can also be themed as well. Though I'm not sure how much is
out there yet.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread Dotan Cohen
 For applications installing the full wxWidgets or Qt toolkits would be
 less disk space and dependcies than OceanGUI

 What? Qt and wX are *huge* compared to OcempGUI.


Don't forget that many people will already have Qt already installed,
such as KDE users, or those who use Skype, Google Earth, or Opera.
Though KDE's Qt will likely be accessibily installed in a convinient
place, though, I'm not so sure about those other examples.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list


wxPython and Croatian characters

2009-02-16 Thread vedrandekovic
Hello,

I have problem with configuring my wxPython script to work with
Croatian characters like:  đ,š,ž,č,ć.
Here is my simple script without wxPython (this script works):

  # -*- coding: utf-8 -*-
  s = hello normal string đšžćč
  print s

..here is my snippet with wxPython:

text = wx.StaticText(self, -1,Matični broj,(0,100)) # in this
example,we have character č

...when I run this text, it looks something like:  Mati,some weird
characters ,and ni

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


Re: pythojn/xpath question...

2009-02-16 Thread Diez B. Roggisch

bruce schrieb:

hi...

using libxml2dom as the xpath lib

i've got a situation where i can have:
 foo=a.xpath( /html/body/table[2]/tr[45]/td)
and i can get
 11 as the number of returned td elements for the 45th row...

this is as it should be.

however, if i do:
 foo=a.xpath( /html/body/table[2]/tr)

and then try to iterate through to the 45th tr, and try to get the number
of td elements..
i can't seem to get the additional xpath that has to be used,

i've tried a number of the following with no luck...
  l1 = libxml2dom.toString(tmp_[0])
  print l1 = +l1+\n

  ldx = 0
  for l in tmp_:
print ld =+str(ldx)
if ldx==45:
  #needs to be a better way...
  #l1 = libxml2dom.toString(tmp_[0])
  l1 = libxml2dom.toString(l)
  #print  = ,l1

  q1 = libxml2dom
  b1 = q1.parseString(l1, html=1)
  #dd1 = b1.xpath(//td[not(@width)])
  #data = b1.xpath(//td/font)
  #data = b1.xpath(//t...@valign='top'][not(@width)])
  #data =
b1.xpath(//child::td[position()0...@valign='top'][not(@width)])
  #data = b1.xpath(//td/parent::*/t...@valign='top'][not(@width)])
  #data = b1.xpath(//td[position()])
  #data = b1.xpath(//parent::tr[position()=1]/td)
  data = b1.xpath(//t...@valign='top'][not(@width)])


it appears that i somehow need to get the direct child/node of the parent
tr that's the td...
it looks like using (//td... gets all the underlying child td... as
opposed to the direct
1st level child/siblings... any thoughts/pointers would be appreciated...


 - you don't give enough information, as you don't provide the html
 - the above code is obviously not the one running, as I can't see 
anything that's increasing your running variable ldx
 - using l as variable names is extremely confusing, because it's hard 
to distinguish from 1 (the number). Using l1 is even worse.
 - xpath usually counts from 1, whereas python is 0-based. As is your 
code. So you most probably have a off-by-one-error.
 - you should read a xpath-tutorial, as //td's purpose is to fetch 
*all*  elements td from the document root, as it is clearly stated here: 
http://www.w3.org/TR/xpath#path-abbrev. So it's no wonder you get more 
than you expect. Direct child nodes are found by simply omitting the 
axis specifier.


Diez

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


To 3.0.2 or not to 3.0.2?

2009-02-16 Thread Lennart Regebro
I discovered some remaining cmp() in 3.0.1, 38 minutes after Benjamin
fixed them. :) Unfortunately, that means porting setuptools to 3.0.1
will be a bit difficult. So my question is: Will there be a 3.0.2 with
those fixes, or should I add workaround code for 3.0.1?

-- 
Lennart Regebro: Pythonista, Barista, Notsotrista.
http://regebro.wordpress.com/
+33 661 58 14 64
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython and Croatian characters

2009-02-16 Thread Diez B. Roggisch

vedrandeko...@gmail.com schrieb:

Hello,

I have problem with configuring my wxPython script to work with
Croatian characters like:  đ,š,ž,č,ć.
Here is my simple script without wxPython (this script works):

  # -*- coding: utf-8 -*-
  s = hello normal string đšžćč
  print s

..here is my snippet with wxPython:

text = wx.StaticText(self, -1,Matični broj,(0,100)) # in this
example,we have character č

...when I run this text, it looks something like:  Mati,some weird
characters ,and ni


Unless you are using python 3.0 (which I doubt, afaik no wx available), 
your above coding declaration is useless for the shown piece of code, as 
it only applies to unicode literals, which are written with a preceding u.


So

umönsch ist doch nicht so schwer


gives you an unicode literal, that wx might work with (don't know wx)

And of course you need to make sure your editor produces utf-8 as 
output, otherwise the exercise is futile as well.


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


Re: logging and daemons

2009-02-16 Thread Fernando M. Maresca
On Mon, Feb 16, 2009 at 10:11:51AM -0800, Scott David Daniels wrote:
 Fernando M. Maresca wrote:
  On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote:
 You can actually set sys.std[err|out] to your ?file? descriptor of
 choice in python 
 Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
 fd of the logfile change in every rotation of the logfile. So the direct
 approach of std[out|err] redirection to the logfile fd obtained from
 the logger instance is unusable (it works fine with a simple file
 handler). 

 Right, so you stick something in as stderr/stdout that talks to the
 logfile.  That is, something like:

 import sys

 class MyFakeStdout(object):
 def flush(self):
 pass
 def write(self, text):
 code to actually do the logging
 sys.stderr = sys.stdout = MyFakeStdout()

Thanks a lot for the input.
That's pretty much what I'm doing right now, just wondered if were a
cleanest way.

Cheers,

-- 
Fernando


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread laplacian42
On Feb 16, 1:52 pm, Dotan Cohen dotanco...@gmail.com wrote:

 Don't forget that many people will already have Qt already installed,
 such as KDE users, or those who use Skype, Google Earth, or Opera.
 Though KDE's Qt will likely be accessibily installed in a convinient
 place, though, I'm not so sure about those other examples.


Well, yes. KDE users will already have Qt installed (and maybe PyQt)
but may groan at the prospect of having to install GTK+ and PyGTK.
Gnome users will already have GTK+ installed (and maybe PyGTK), but
may groan at having to install Qt and PyQt. However, both will likely
have no qualms about installing SDL and Pygame (which are pretty small
and also allow them to play various games as well).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way to determine if one char of many in a string

2009-02-16 Thread Stefaan Himpe

An entirely different approach would be to use a regular expression:

import re
if re.search([abc], nothing expekted):
   print a, b or c occurs in the string 'nothing expekted'

if re.search([abc], something expected):
   print a, b or c occurs in the string 'something expected'

Best regards,
Stefaan.
--
http://mail.python.org/mailman/listinfo/python-list


Re: replace ftp by local copy

2009-02-16 Thread Steve Holden
loial wrote:
 I have been given an old python application that calls ftplib in many
 places to copy files to a remote server.
 
 I have been given the task of cloneing this code so that ftp is not
 used, but files are just copied locally in a scenerio where ftp is not
 available. The code is not well structured which makes this more
 difficult.
 
 Before starting this just wondered if anyone has previously done
 anything like overriding the ftplib module so that I can leave the
 existing code largely unchanged but have the ftp commands just copy
 files locally?
 
 Just thought I'd ask before getting started.
 
I don't remember anyone mentioning this, but it sounds like the soundest
engineering approach, and the one least likely to induce breakage ...

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Easier to wrap C or C++ libraries?

2009-02-16 Thread Hrvoje Niksic
Nick Craig-Wood n...@craig-wood.com writes:

 Christian Heimes li...@cheimes.de wrote:
  Hrvoje Niksic schrieb:
  Diez B. Roggisch de...@nospam.web.de writes:
  
  The answer is easy: if you use C, you can use ctypes to create a
  wrapper - with pure python, no compilation, no platform issues.
  
  The last part is not true.  ctypes doesn't work on 64-bit
  architectures, nor does it work when Python is built with non-gcc Unix
  compilers
 
  ctypes works on 64bit systems, too. However it's a pain in the ... back
  to write code with ctypes that works across all platforms. I used to use
  ctypes for wrapper but eventually I switched to Cython.

 What sort of problems have you had?

 I find as long as I use the same types as the C code actually uses it
 all works fine.  If on a 64 bit platform long is 64 bits then it will
 be under ctypes too.

I apologize for the misinformation that ctypes doesn't work on 64-bit
systems.  The project I'm working on doesn't include ctypes, but it
could be because we don't use GCC to build, or because we also need to
support Win64.
--
http://mail.python.org/mailman/listinfo/python-list


Speedup Bitmap Parser

2009-02-16 Thread Jayson Santos
Hello people, I'm writing a Bitmap parser for study purposes, however
when I parse a bitmap file and when I paint that file in a window, the
script take to much time.
How can I optimize my script loops to be faster ?

Here is the script

http://pastebin.com/m652b8d65

Best Regards
Jayson Reis
--
http://mail.python.org/mailman/listinfo/python-list


Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread Bruno Desthuilliers

laplacia...@gmail.com a écrit :

On Feb 16, 1:52 pm, Dotan Cohen dotanco...@gmail.com wrote:

Don't forget that many people will already have Qt already installed,
such as KDE users, or those who use Skype, Google Earth, or Opera.
Though KDE's Qt will likely be accessibily installed in a convinient
place, though, I'm not so sure about those other examples.



Well, yes. KDE users will already have Qt installed (and maybe PyQt)
but may groan at the prospect of having to install GTK+ and PyGTK.
Gnome users will already have GTK+ installed (and maybe PyGTK),  but
may groan at having to install Qt and PyQt.  However, both will likely
have no qualms about installing SDL and Pygame (which are pretty small
and also allow them to play various games as well).


FWIW (and servers set aside, of course), I can hardly remember of any of 
linux box I worked one not having both GTK and KDE installed.

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


Re: illegal list name

2009-02-16 Thread Bruno Desthuilliers

Sandra Quiles a écrit :

Hello. I have followed the instructions of a post on Installing mailman 
on OS X 10.4, and got to step 7 and hit this error.



(snip)

So. illegal name error. it list listname as 'mailman@mycomputername'

that's in response to the 'bin/newlist mailman' command


Sorry, this has nothing to do with Python. Please refer to mailman's 
documentation, mailing list or whatever.


also, I purchased the Postfix Enabler, but have no clue what to do with 
the software.


Nor do I.


Tips, advise, hand-holding welcomed.


Start here:
http://catb.org/~esr/faqs/smart-questions.html


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


flexible find and replace ?

2009-02-16 Thread OdarR
Hi guys,

how would you do a clever find and replace, where the value replacing
the tag
is changing on each occurence ?

...TAGTAGTAG..TAG.

is replaced by this :

...REPL01REPL02REPL03..REPL04...


A better and clever method than this snippet should exist I hope :

counter = 1
while 'TAG' in mystring:
mystring=mystring.replace('TAG', 'REPL'+str(counter), 1)
counter+=1
...

(the find is always re-starting at the string beginning, this is not
efficient.

any ideas ? thanks,

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


Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread Dotan Cohen
 FWIW (and servers set aside, of course), I can hardly remember of any of
 linux box I worked one not having both GTK and KDE installed.

I don't think that those netbooks come with Qt. And for a Windows
installer, where one may want to package the toolkit with the program,
a small toolkit may be nice. There is such an issue today on the Zim
list, where including GTK in the installer bloated it to four times
it's size.

So it may be more of a download size for Windows users, than an
installed size for Linux users (disk space is cheap, at least with
traditional rotating hard drives).

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list


Re: flexible find and replace ?

2009-02-16 Thread bearophileHUGS
OdarR:

 how would you do a clever find and replace, where the value replacing
 the tag is changing on each occurence ?
 ...TAGTAGTAG..TAG.
 is replaced by this :
 ...REPL01REPL02REPL03..REPL04...


You may use something like this (tested) replacing  with
the correct re function:

import re

def replacer(mobj):
replacer.counter += 1
return REPL%02d % replacer.counter
replacer.counter = 0

print re.(TAG, replacer, s1)

(If you have more than 99 replacements it will use more than two
digits.)

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: flexible find and replace ?

2009-02-16 Thread Jason Scheirer
On Feb 16, 12:10 pm, OdarR olivier.da...@gmail.com wrote:
 Hi guys,

 how would you do a clever find and replace, where the value replacing
 the tag
 is changing on each occurence ?

 ...TAGTAGTAG..TAG.

 is replaced by this :

 ...REPL01REPL02REPL03..REPL04...

 A better and clever method than this snippet should exist I hope :

 counter = 1
 while 'TAG' in mystring:
     mystring=mystring.replace('TAG', 'REPL'+str(counter), 1)
     counter+=1
     ...

 (the find is always re-starting at the string beginning, this is not
 efficient.

 any ideas ? thanks,

 Olivier

You could split on the string and interleave your new string in
between:

In [1]: def replmaker():
   ...: index = 0
   ...: while True:
   ...: index += 1
   ...: yield REPL%02i%index
   ...:

In [2]: def spliton(string, tag=TAG, sepgen=replmaker):
   ...: repl_iter = sepgen()
   ...: strlist = string.split(tag)
   ...: length = len(strlist)
   ...: for index, item in enumerate(strlist):
   ...: yield item
   ...: if index  length - 1:
   ...: yield repl_iter.next()
   ...:

In [3]: ''.join(spliton
(...TAGTAGTAG..TAG. ))
Out[3]:
'...REPL01REPL02REPL03..REPL04.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython and Croatian characters

2009-02-16 Thread Jason Scheirer
On Feb 16, 10:58 am, vedrandeko...@gmail.com wrote:
 Hello,

 I have problem with configuring my wxPython script to work with
 Croatian characters like:  ð,¹,¾,è,æ.
 Here is my simple script without wxPython (this script works):

       # -*- coding: utf-8 -*-
       s = hello normal string ð¹¾æè
       print s

 ..here is my snippet with wxPython:

     text = wx.StaticText(self, -1,Matièni broj,(0,100)) # in this
 example,we have character è

 ...when I run this text, it looks something like:  Mati,some weird
 characters ,and ni

 Regards,
 John

You may be using an ANSI build of wxWidgets instead of a unicode one.
Make sure to enable Unicode when you run ./configure, or if in
Windows, uninstall and download the win32-unicode version of the
wxPython you want.
--
http://mail.python.org/mailman/listinfo/python-list


Re: explain

2009-02-16 Thread Terry Reedy

Jeroen Ruigrok van der Werven wrote:

-On [20090216 11:17], Saeed Iravani (si.4...@yahoo.com) wrote:

I download python 2.5.4 and install but I dont know that how perform python?
I dont know from which directory perform python?


It would help if you would clarify which operating system you are using.

On Unix/Linux systems you make sure to 'rehash' your $PATH or add the
appropriate directory to the $PATH variable.

On Windows, you set your environment variable PATH to include the path to
Python programs (typically something like C:\Python25), which you can find
under the system control panel.


On windows, that is not necessary for many uses.  Just use the entries 
in the start menu.



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


Re: Creating custom formatter function

2009-02-16 Thread Terry Reedy

Garrett Cooper wrote:

Hello Python folks,
I have a function where I'd like to prefix a format string via a
`prefix' string. The definition of the base method is as follows:

#START CODE
def print_message(prefix, out_stream, fmt, *args, **kwargs):
 Print out [prefix]: [message] 

message = fmt

if 0  len(kwargs.keys()):
message = message % kwargs

if 0  len(args):


To clarify error message, print fmt, message, args here


message = message % args


This line



out_stream.write(message + \n)
#END CODE

My python 2.4.5 interpreter fails at `message % args' claiming the
following:

  File logging.py, line 10, in print_message
message = message % (args)


does not quite match this one, so one is not copy/pasted.


TypeError: not all arguments converted during string formatting

Thus I was wondering what the proper means was for formatting
strings. I'm new to this portion of Python, so I obviously didn't
apply the right syntax.
TIA!
-Garrett
--
http://mail.python.org/mailman/listinfo/python-list



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


Re: Speedup Bitmap Parser

2009-02-16 Thread Terry Reedy

Jayson Santos wrote:

Hello people, I'm writing a Bitmap parser for study purposes, however
when I parse a bitmap file and when I paint that file in a window, the
script take to much time.


1. You turned constants into static methods called for every line, 
adding attribute lookup and function call time.
2. You read the image a line at a time and break each line into separate 
pixel objects.

3. You paint each pixel by drawing and filling a 1-pixel rectangle.


How can I optimize my script loops to be faster ?


Don't do any of the above.  Look at how other programs such as PIL or 
pygame read, store, and paint images.



Here is the script
http://pastebin.com/m652b8d65


tjr

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


Re: Will multithreading make python less popular?

2009-02-16 Thread rushenaly
Hi again

OpenERP and ERP5 was written in python as i know. I really wonder how
they do this without threads. I want to see a real time graph at the
same time while i am working on the same screen. What is the secret?

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


Re: Regarding Joystick

2009-02-16 Thread shreyas shah
Hi ,

I have figured out a code with the help of archives in pygame 

can anyone help me with controlling the speed of joystick ... i am going to
integrate joystick with a PTZ camera ... i was wondering if there are any
functions which can help me control the speed of camera and by controlling
motion of joystick


#! /usr/bin/env python

import pygame
from pygame import locals




jlist = [] # global joystick list


class Joystick:


def __init__(self):
pygame.init()
self.nbJoy = pygame.joystick.get_count()

for n in range(self.nbJoy):
pygame.joystick.Joystick(n).init()

try:
for n in range(pygame.joystick.get_count()): #
stick = pygame.joystick.Joystick(n)
jlist.append(stick) # create a joystick instance
stick.init() # init instance
# report joystick charateristics #
print '-'*20
print 'Enabled joystick: ' + stick.get_name()
print 'it has the following devices :'
print '-- buttons : '+ str(stick.get_numbuttons())
print '-- balls : '+ str(stick.get_numballs())
print '-- axes : '+ str(stick.get_numaxes())
print '-- hats : '+ str(stick.get_numhats())
print '-'*20
except pygame.error:
print 'pygame.error, no joystick found.'





def main(self):


#init() # init pygame and joystick system


while 1: # endless loop

for e in pygame.event.get(): # iterate over event stack


if e.type == pygame.locals.JOYAXISMOTION: # 7
for j in jlist:
for n in range(j.get_numaxes()):
print 'moved axe num '+str(n)+' : ' +
str(j.get_axis(n))
print '-'*10 # separation


elif e.type == pygame.locals.JOYBALLMOTION: # 8
for j in jlist:
for n in range(j.get_numballs()):
print 'moved ball num '+str(n)+' : '+
str(j.get_ball(n))
print '-'*10 # separation


elif e.type == pygame.locals.JOYHATMOTION: # 9
for j in jlist:
for n in range(j.get_numhats()):
print 'moved hat num '+str(n)+' : '+
str(j.get_hat(n))
print '-'*10 # separation


elif e.type == pygame.locals.JOYBUTTONDOWN: # 10
for j in jlist:
for n in range(j.get_numbuttons()):
if j.get_button(n) : # if this is down
print 'down button num '+str(n)+' : '+
str(j.get_button(n))
print '-'*10 # separation

elif e.type == pygame.locals.JOYBUTTONUP: # 11
for j in jlist:
for n in range(j.get_numbuttons()):
print 'up button num '+str(n)+' : '+
str(j.get_button(n))
print '-'*10 # separation


if __name__ == '__main__':
j = Joystick()
j.main()


thanks
shreyas






On Thu, Feb 12, 2009 at 11:36 PM, Banibrata Dutta banibrata.du...@gmail.com
 wrote:

 AFAIK, the mechanism / API / protocol to actuate the Camera's tilt, pan,
 zoom functions are not standardized (happy to be corrected there!), so even
 if you find something, it'd most likely be something very specific to a
 particular device.
 As for Joystick usage, I remember seeing one thread on that couple of
 months back, so searching thru the archive should give you leads.

 On Fri, Feb 13, 2009 at 3:33 AM, shreyas shah shreya...@gmail.com wrote:

 Hi ,

 I am trying to control the motion of the camera with help of joystick , i
 need some basic functionality where if i move a joystick to left the camera
 moves to the left . Can anyone help me with that ?

 Thanks
 Shreyas


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




 --
 regards,
 Banibrata
 http://www.linkedin.com/in/bdutta

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


Re: Speedup Bitmap Parser

2009-02-16 Thread bearophileHUGS
Jayson Santos:
 Hello people, I'm writing a Bitmap parser for study purposes,

This code:

x = 0
y = 0
for line in bmp.bitmap_lines.lines:
for color in xrange(len(line.colors)):
canvas.create_line(x, y, x+1, y, fill=#%02x%02x%02x
% (line.colors[color].red, line.colors[color].green, line.colors
[color].blue))
x += 1
x = 0
y += 1


May be replaced with something like:

for x, color in enumerate(line.colors):
canvas.create_line(x, y, x+1, y, fill=#%02x%02x%02x %
(color.red, color.green, color.blue))

And maybe a RGBTriple may be replaced with an immutable namedtuple.
Using nested classes may be overkill for this program.

Use the Python profiler and profile your code with a real image, and
show us/me the profiler results, so I can give you some suggestions to
speed up your code.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread Nick Craig-Wood
laplacia...@gmail.com laplacia...@gmail.com wrote:
  I think I just found the GUI toolkit for Python I've been searching
  for. It seems to meet all of the following requirements:
 
* free software
* small (I don't need batteries -- Python already comes with those.)
* easy to use
* actively maintained
* cross-platform
* easy to install
* based on a stable and actively-maintained C library
* does not depend on an external scripting language (for example,
  Tcl)
* well-documented
* not too many dependencies
* can easily integrate with PyOpenGL
* support for accessibility
 
  and it's also written in Python.
 
  I have no idea how it's stayed under the radar in the Python community
  for this long, yet here it is: [OcempGUI](http://ocemp.sourceforge.net/
  gui.html). The C library it depends upon? [SDL](http://
  www.libsdl.org/) (via [PyGame](http://www.pygame.org/news.html)).

Interesting!  One of the commercial apps I'm involved (C++ not python)
in uses SDL as its GUI with windows etc built on top of it.  It means
that it looks exactly the same on all supported platforms and since it
usually runs full screen that is fine.  I imagine this GUI toolkit
fits the same niche.

Presumably since it uses SDL then all the GUI will appear in one
window?  So windows within windows in the MDI style?

-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way to determine if a string is a number

2009-02-16 Thread Nick Craig-Wood
pyt...@bdurham.com pyt...@bdurham.com wrote:
  Thanks for everyone's feedback. I believe my original post's code
  (updated following my signature) was in line with this list's feedback.
 
  Christian: Thanks for reminding me about exponential formats. My updated
  code accounts for these type of numbers. I don't need to handle inf or
  nan values. My original code's except catches an explicit ValueError
  exception per your concern about bare excepts.
 
  Malcolm
 
 code
  # str_to_num.py
 
  def isnumber( input ):
  try:
  num = float( input )
  return True
 
  except ValueError:
  return False

That is a fine solution.

Last time I had to solve this I had a specific format of number to
parse - I didn't want to include all the python formats.  This is what
I came up with...  This particular code returns the converted number
or 0.0 - adjust as you see fit!

import re

_float_pattern   = re.compile(r^\s*([-+]?(\d*\.)?\d+([eE][-+]?\d+)?))

def atof(value):

Convert a string to an float in the same way the c-library atof()
does.  Ie only converting as much as it can and returning 0.0 for
an error.

match = _float_pattern.search(value)
if match:
return float(match.group(1))
return 0.0

 atof(15.5 Sausages)
15.5
 atof(   17.2)
17.199
 atof(0x12)
0.0
 atof(8.3.2)
8.3007
 atof(potato)
0.0


-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: flexible find and replace ?

2009-02-16 Thread Tim Chase

how would you do a clever find and replace, where the value replacing
the tag
is changing on each occurence ?

...TAGTAGTAG..TAG.

is replaced by this :

...REPL01REPL02REPL03..REPL04...




This is a variant of the class I've used in the past for stateful 
replacements:


  import re

  class Counter(object):
def __init__(self, prefix=REPL, start=1):
self.prefix = prefix
self.counter = start - 1
def __call__(self, matchobj):
self.counter += 1
return %s%02i % (self.prefix, self.counter)

  r = re.compile(TAG) # the regexp to find what we want
  s = some TAG stuff with TAG whatever more TAG stuff

  print s
  # just use the counter
  print r.sub(Counter(), s)
  # demo a different starting number
  print r.sub(Counter(start=42), s)
  # maintain a single counter across calls
  c = Counter(prefix=Hello, start=42)
  print r.sub(c, s)
  print r.sub(c, s)


A better and clever method than this snippet should exist I hope :

counter = 1
while 'TAG' in mystring:
mystring=mystring.replace('TAG', 'REPL'+str(counter), 1)
counter+=1
...

(the find is always re-starting at the string beginning, this is not
efficient.


This also has problems if your search-string is a substring of 
your replacement string:


  search = foo
  replacement = foobar#

You'll get

  s = foo_foo
  s = foobar01_foo
  s = foobar02bar01_foo
  ...

which isn't quite what it looks like you want.

-tkc



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


Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread laplacian42
On Feb 16, 4:31 pm, Nick Craig-Wood n...@craig-wood.com wrote:

 Interesting!  One of the commercial apps I'm involved (C++ not python)
 in uses SDL as its GUI with windows etc built on top of it.  It means
 that it looks exactly the same on all supported platforms and since it
 usually runs full screen that is fine.  I imagine this GUI toolkit
 fits the same niche.

 Presumably since it uses SDL then all the GUI will appear in one
 window?  So windows within windows in the MDI style?

 --
 Nick Craig-Wood n...@craig-wood.com --http://www.craig-wood.com/nick

There is a `window.py` example that comes with the distribution. It
has modal and non-modal windows within the main window.

I haven't yet seen any examples where OcempGUI runs full-screen.

The relevant portion of the manual re. subwindows is:
http://ocemp.sourceforge.net/manual/windows_and_dialogs.html
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >