Re: concatenate the elements in each list of a list of lists

2008-07-23 Thread Michael Schneider
Am Wed, 23 Jul 2008 08:33:57 -0700 wrote antar2:

 I already asked a similar question, but encounter problems with
 python...
 How can I concatenate the elements in each list of a list of lists
 
 list_of_listsA =
 
 [['klas*', '*', '*'],
 ['mooi*', '*', '*', '*'],
 ['arm*', '*', '*(haar)']]
 
 wanted result:
 
 list_of_listsA =
 
 [['klas* * *']
 ['mooi* * * *']
 ['arm* * *(haar)']]
 
 Thanks a lot !

Hello,

maybe this will help:

In [5]: list_of_listsA = [['klas*', '*', '*'], ['mooi*', '*', '*', '*'], 
['arm*', '*', '*(haar)']]
In [6]: s = 
In [7]: print [[s.join(item)] for item in list_of_listsA]
[['klas***'], ['mooi'], ['arm***(haar)']]

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


Re: Writing pins to the RS232

2005-12-31 Thread Michael Schneider
Jay,

Couple of points that may help you.

1) A serial port does not have data ports 0-n.  A serial port takes a 
byte (8 bits), then shifts them down a single pipe using a chip called a
UART (feel free to google for unfamiliar terms).

example

Bit pattern 1010 1010

would be shifted one bit at a time

1
0
1
0

1
0
1
0

a one is +5 volts on single send line of the UART and 0 is 0 volts.

RS232 uses a different mapping for 1's and 0's (but is still serial)

1 - ~-3V - -12 V
0 0-12 V

So you slap a chip on between the UART and the RS232 pin  (usually a 
MAX232)  that translates the voltages for you.

On the other end of the wire

232 socket
MAC232
UART (usually built into the microcontroller)
Register in Microcontroller


I like playing at this level.   I would recommend using AVR 
microcontroller (easiest to program and there is an open source
gcc compiler).

for $20.00 US you can buy the butterfly eval board with:
- microcontroller
- max232 all wired up for rs232 connection from your computer
- lcd display
- temperature sensor
- light sensor
- the avr mega169 has many goodies
 - analog - digital converter
 - digital - analog converter
 - LCD controller

This is a great bargin.

If you are starting out in microcontrollers.  I would suggest that you 
go to:

http://smileymicros.com/

They sell a nice package for $90.00

- butterfly eval board
- great, easy to follow book on how to develop on microcontrollers for 
the beginer.
- project kit - includes everything you need to build all of the 
projects (even includes the wire ;-)


There are python libs that support Ateml Avr connections:


It is easy to use your rs232 serial with a microcontroller at the other 
end of the wire.  Microcontrollers are cheap.  If you fry why is 
connected to your devices, you are only out the microcontroller.


Have fun,
Mike



[EMAIL PROTECTED] wrote:
 I want to write to the pins of an RS232 without using the serial
 protocol.  The use would be every pin could act to complete a circuit
 in customized hardware.  I could use python to communicate serially to
 a BASIC stamp or a Javelin stamp and then use the stamp to set however
 many pins as 0's or 1's but should it be that hard to do with python.
 I've looked through how python does serial with the serial module but
 it just uses Java's javax.comm libraries.  Is there anyway to do very
 low level device writing to COM ports?
 
 In summary I'm looking for something like:
 ser = serial.Serial(0)
 ser.pin0 = 1
 ser.pin1 = 1
 ser.pin2 = 1
 
 
 
 or
 ser.write('0xFF')
 which would set 8 pins on the RS232 cable to 1's
 


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: - E04 - Leadership! Google, Guido van Rossum, PSF

2005-12-29 Thread Michael Schneider
Congratulations to Guide,

Mike

Harald Armin Massa wrote:
 Guido at Google: a message in THE public forum c.l.p.
 
 A confirmation by Martellibot, that Guido is IN FACT sitting 15m
 distant from him; and everybody in Python knows where Martellibot has
 his desk.
 
 Can it get more official than this?
 
 yeah:
 a confirmation by Greg Stein @ Google within slashdot, that Guido is
 working at Google.
 
 I am sure that more people in the Python community are reading c.l.p.
 and /. than the washington post, the people affected have been
 informed.
 
 I guess that's as formal and official as it can get.
 
 And concerning Guido, Python, community and leadership:
 
 Guido is the designer, the creator of Python. He has nearly unlimeted
 trust in his design decisions: we all know, that he is THE gifted
 language designer. His proclamations are accepted because he has proven
 over time that he knows what's best for the language.
 
 Allow me to quote Greg Stein:
 Ha! Guido would quit in a heartbeat if you tried to make him manage
 people. That just isn't where he's at. He's absolutely brilliant and
 loves to write excellent code. Great. We're gonna let him do just that
 :-)
 
 So, Google with their geek-version of the Playboy-Mansion, free massage
 parleurs, free lunch and dinner and best recruitment tactics on the
 planet and the known universe will not be able to make Guido manage
 people.
 
 Somehow the Python community managed itself through the years... Python
 grew healthy and steadily; forked less then usual, inspired other
 languages and got faster and faster and faster.
 
 Maybe only mediocre and less ideas need a great leader. Maybe a great
 idea can lead for itself?
 
 Harald
 
 --
 GHUM Harald Massa
 persuadere et programmare
 Harald Armin Massa
 Reinsburgstraße 202b
 70197 Stuttgart
 0173/9409607
 


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-07 Thread Michael Schneider
[EMAIL PROTECTED] wrote:
  ,, info cut

  However there is one thing I don't like in python,
 that is, scoping by indentation. But it would not annoy me so much that
 make me decide to implement a new language^_^.
 
 
 Regards,
 
 Limin
 


I find these comments interesting.  It is very common for people to 
complain about indentation.

I have helped several very large companies create C++ coding
standards.

One common requirement is very fixed indentation rules.  These
rules are often encoded into lint-like tools.  These tools
treat indentation errors like compile time errors.


These are often the same people that don't want to use python because
it uses indentation ..

It is humorous if stand back and look from a distance greater then 10 
feet :-)

Mike


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to ping in Python?

2005-12-07 Thread Michael Schneider
I telnet to port 13 (returns time)

Hope this is helpful,
Mike

Nico Grubert wrote:
 Hi there,
 
 I could not find any ping Class or Handler in python (2.3.5) to ping a 
 machine.
 I just need to ping a machine to see if its answering. What's the best 
 way to do it?
 
 Kind regards,
 Nico


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to ping in Python?

2005-12-07 Thread Michael Schneider
Les,

I only ping internal machines.  You are right about shutting down ports.

When we disable telent, we also disable ping.  Many people may not though,

good luck,
Mike

Laszlo Zsolt Nagy wrote:

 Michael Schneider wrote:

 I telnet to port 13 (returns time)

 The problem is that most modern up-to-date servers use firewalls. They 
 only open the ports that are absolutely necessary. Usually the time 
 service is part of inetd, which is disabled by default, on most of the 
 servers. PING ICMP may work, but sometimes it does not either. In the 
 worst case, all port are closed and you have no way to tell if there 
 is a computer or not.

 Can you tell more about what kind of server do you need to ping?

 Example: if you need to know if a web server is alive, you should 
 connect to port 80 (http). If the connection was successful, you can 
 close the connection immeditelly. You can expect a HTTP server to open 
 the HTTP port, but all other ports may be closed.

   Les






-- 
The greatest performance improvement occurs on the transition of from the 
non-working state to the working state.

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


Re: Ant (with Python extensions) good replacement for distutils?

2005-12-07 Thread Michael Schneider
I would vote against ant because java must be installed to run it.


The bootstrap install should be very simple.  If you make python usage
dependent on:

1) download java
2) install java
3) add java to path
4) download ant
5) install ant
6) add ant to path
7) download ptyhon
8) install python
9) add python to path
10) download package
11) run ant to install package

just food for thought,
Mike

[EMAIL PROTECTED] wrote:
 I know distutils well but don't know anything about Ant except that it
 is a build
 tool from Apache project.
 
 Could it possible be better or as good as distutils?
 (There are extensions for Python.)
 
 Chris
 


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for small, impressive 3D-related Python script

2005-11-29 Thread Michael Schneider
Ken,

I would suggest that you embed python in your app (very easy to do).

-And convert several of your existing scripts to python.

-Show them a stack of python books for customer training purposes

- Drive excel with python (allows integration of your product with other 
products.

- Pick an area of functionality that your product offers today that your
customer would like to customize.

- convert this alg to python
- hack you product to execute the python script
- code a variant of the alg in python
- execute your variant to demonstrate that python can lower custom 
development cost, and provide points of extensibility


Have fun,
good luck,
Mike

Kenneth McDonald wrote:
 I'm not trying to persuade my company to offer Python as a scripting  
 language for their product, but I am trying to give them examples of  
 things that Python can do easily that cannot be done easily with  their 
 current proprietary scripting language. After that it would be  their 
 decision. As the product is a 3D package, I'm looking for  something in 
 this field.
 
 This does _not_ have to use PyOpenGL, or for that matter, any Python  3D 
 package. In fact, my ideal would be a Python script that simply  uses 
 L-Systems (Lindenmayer systems) as in The Algorithmic Beauty of  
 Plants, to generate plantlike OBJ files that can then be displayed  in 
 our program. In general, something that generates an OBJ file  would 
 probably be preferable to something that actually uses  PyOpenGL, 
 Blender, etc, as then I can just display the OBJ file in  our program to 
 say, This is the sort of thing that can be easily  done by Python 
 without recourse to any other programs.
 
 So please, any suggestions are welcome.
 
 As always, many thanks to this group,
 Ken


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AJAX = APAX? Or: is there support for python in browsers?

2005-11-16 Thread Michael Schneider
Alex,

Good point.   Can python be used to write firefox extensions that could 
be called from javascript?

1) javascript would come in on the HTML page
2) javascript would communication with the Extension API
3) the extension would be written in python

That way, you would only need to make your extension's API safe to the wild.

It would require the user to download an extension, but flash, et all 
seem to do ok.

Is this possible today?

Thanks
Mike


PS.  Sorry for my ignorance on this, I am a client-side developer, 
trying to explore serious client development.

Alex Martelli wrote:
 Tim Roberts [EMAIL PROTECTED] wrote:
...
 
Internet Explorer will allow any registered ActiveScript language to be
used in a web page.  Python qualifies.  In the latest Win32 extensions,
there is a script in win32comext/axscript/client/pyscript.py that will
register Python as an ActiveScript language.

The you can say

  script language=python
  print h1Hello, there./h1
  /script
 
 
 Out of curiosity, how sandboxed is this Python?  I remember a similar
 solution being withdrawn once because it wasn't really safely sandboxed,
 so the ``script'' could easily do any arbitrary damage to the machine...
 
 
 Alex


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Which Version of Linux

2005-11-05 Thread Michael Schneider
I have been away from unix/linux for a couple of years.

I went with SUSE.   Just do an install all, and 10 gig later you
are done.

Very simple install, very easy admin with YAST.

If you are a power admin, there may be better release.  But if you want
simple, but powerful, SUSE has worked well for me.

Good Luck,
Mike


[EMAIL PROTECTED] wrote:
 ok, i m going to use Linux for my Python Programs, mainly because i 
 need to see what will these fork() and exec() do. So, can anyone tell 
 me which flavour of linux i should use, some say that Debian is more 
 programmer friendly, or shold i use fedora, or Solaris. Because these 
 three are the only ones i know of that are popular and free.


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: weakrefs to functions for observer pattern

2005-11-03 Thread Michael Schneider
Alex Martelli wrote:
 Michael Schneider [EMAIL PROTECTED] wrote:
 
 
I would like to use weak refs in an observer pattern implementation.
The problme that I have seems to be that weakrefs can't manage functions.
 
 
 They can manage just fine functions written in *Python*, just not
 builtin functions*, i.e., ones written in *C*.  Just wrap any builtin
 function you need to register as observer into a tiny Python-coded
 wrapper and live happily ever after.
...
 
Not all objects can be weakly referenced; those objects which can 
include class instances, functions written in Python (but not in C), 
 
 
 
 Alex
Alex,

Thank you, I mis-read the docs.

The mistake I  made was having was using a weak reference as a key in 
the dictionary.

Weak references will be very useful for me.

I really enjoy python.  So many good things have been added to the 
language without taking the fun away :-)

Mike

-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read/Write from/to a process

2005-10-25 Thread Michael Schneider
Jas,

I use a python called twisted to run processes as you describe.

Twisted is an event-driven framework that brings a change in the
way that you look at things.

take a look at:

http://twistedmatrix.com/projects/core/documentation/howto/process.html

Good luck, hope this is useful,
Mike


jas wrote:
 Hi,
   I would like to start a new process and be able to read/write from/to
 it.  I have tried things like...
 
 import subprocess as sp
 p = sp.Popen(cmd.exe, stdout=sp.PIPE)
 p.stdin.write(hostname\n)
 
 however, it doesn't seem to work.  I think the cmd.exe is catching it.
 
 I also tried
 f = open(out.txt, w)
 sys.stdout = f
 os.system(cmd.exe)
 
 ..but out.txt didn't contain any output from cmd.exe
 
 So, how can I create a process (in this case, cmd.exe) on Windows and
 be able to read/write from/to it?
 
 Thanks
 


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Problems with properties

2005-10-14 Thread Michael Schneider
Hello All,

I have been working on learning how to use python properties.

The get property access is working, but the the set
property is not working.

Rather then dispatching the property assignment to setNothing, the
property object is being replaced with a string.

I must be doing something very stupid here.

Could someone please point out my error, I have dents in my forehead
for this one.

Thanks,
Mike



--

from unittest import TestCase
import unittest


class Task:
   def __init__(self,command):
 self._command = command

   def setNothing(self, value):
 raise AttributeError

   def getCommand(self):
 return self._command

   command=property(getCommand, setNothing)


class taskTest(TestCase):

 def testTask(self):
 t = Task(dir c:)
 c = t.command
 self.assertEquals(dir c:, c)

 # should fail, but doesn't
 t.command = foo Bar

 self.assertEquals(dir c:, t.command)



if __name__ == __main__:
 unittest.main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with properties

2005-10-14 Thread Michael Schneider
Thanks to all,  I added the object as a subclass (should this be 
required for 2.4.1 ???)

I also switched to the decorator with the @property syntax

Thank you very much for the help for adding @property to the language.

what a great language :-)

Mike


Michael Schneider wrote:
 Hello All,
 
 I have been working on learning how to use python properties.
 
 The get property access is working, but the the set
 property is not working.
 
 Rather then dispatching the property assignment to setNothing, the
 property object is being replaced with a string.
 
 I must be doing something very stupid here.
 
 Could someone please point out my error, I have dents in my forehead
 for this one.
 
 Thanks,
 Mike
 
 
 
 --
 
 from unittest import TestCase
 import unittest
 
 
 class Task:
   def __init__(self,command):
 self._command = command
 
   def setNothing(self, value):
 raise AttributeError
 
   def getCommand(self):
 return self._command
 
   command=property(getCommand, setNothing)
 
 
 class taskTest(TestCase):
 
 def testTask(self):
 t = Task(dir c:)
 c = t.command
 self.assertEquals(dir c:, c)
 
 # should fail, but doesn't
 t.command = foo Bar
 
 self.assertEquals(dir c:, t.command)
 
 
 
 if __name__ == __main__:
 unittest.main()


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with properties

2005-10-14 Thread Michael Schneider
Thanks to all,  I added the object as a subclass (should this be 
required for 2.4.1 ???)

I also switched to the decorator with the @property syntax

Thank you very much for the help for adding @property to the language.

what a great language :-)

Mike


Michael Schneider wrote:
 Hello All,
 
 I have been working on learning how to use python properties.
 
 The get property access is working, but the the set
 property is not working.
 
 Rather then dispatching the property assignment to setNothing, the
 property object is being replaced with a string.
 
 I must be doing something very stupid here.
 
 Could someone please point out my error, I have dents in my forehead
 for this one.
 
 Thanks,
 Mike
 
 
 
 --
 
 from unittest import TestCase
 import unittest
 
 
 class Task:
   def __init__(self,command):
 self._command = command
 
   def setNothing(self, value):
 raise AttributeError
 
   def getCommand(self):
 return self._command
 
   command=property(getCommand, setNothing)
 
 
 class taskTest(TestCase):
 
 def testTask(self):
 t = Task(dir c:)
 c = t.command
 self.assertEquals(dir c:, c)
 
 # should fail, but doesn't
 t.command = foo Bar
 
 self.assertEquals(dir c:, t.command)
 
 
 
 if __name__ == __main__:
 unittest.main()


-- 
The greatest performance improvement occurs on the transition of from 
the non-working state to the working state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far

2005-10-06 Thread Michael Schneider
Take a look at:

http://wingware.com/

It is only $35.00 for an IDE. (30 day free eval version)

I use eclipse for java, and have become quite fond of tab completion.

Mike

CppNewB wrote:
 I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
 feels very clean with an emphasis on simplification.
 
 My only complaint is that there doesn't appear to be a great commercial IDE 
 for the language.  I've tried Komodo, etc and they are nice applications, 
 but they don't feel like they give me the power like a Visual Studio or 
 Delphi (I wish I could articulate better the differences).Finding a 
 descent GUI builder has been a challenge as well.  Most of them have support 
 for Dialogs, but what about more complex UI's?  I may need a resizable frame 
 within a resizable frame? I haven''t found a GUI builder with a great feel 
 yet.
 
 Other than that, my experience has been wonderful.  Even after my 
 complaints, I plan on sticking with Python for a while. 
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


What python idioms for private, protected and public?

2005-09-29 Thread Michael Schneider
I have been following this thread with great interest.

I have been coding in C++ since the late 80's and Java since the late 90's.


I do use private in these languages, with accessors to get at internal 
data.

This has become an ingrained idiom for me.  When I create a python 
object, it is natural for me to want  to use familiar idioms.


Hare are the places where private is useful to me:


Design Intent:

1) mark an object as dirty in a setter (anytime the object is changed, 
the dirty flag is set without requiring a user to set the dirty flag

2) enforce value constraints (even if just during debugging)

3) lazy init, don't bring the data in until needed

4) adding debug info

5)  more here


I do write code that violates private
- memory ptr access in C++
- reflection in java
- aspects in java

I usually violate private when adding an aspect to a class, and
I don't want this code in every class.  Example,  persistence.


I really like the C# properties, you can access data with a data
accessor, but add functionality is triggered when accessing the data.

I like the data access syntax, better then the set/get functions.  I 
need the functionality to achieve the design goals above, so i use 
function, but the are ugly, especially in math code.


It would be easy for me to say Add public and private to python so I
can code the way that I am used to.  What are some python alternatives 
to achieve the design intents specified above above?

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


Re: What python idioms for private, protected and public?

2005-09-29 Thread Michael Schneider
Frederik,

Thank you very much for the info on properties, that is very useful.

Sorry about the public typo, that should have been protected. I should
not post before coffee hits :-)

Happy coding,
Mike

Fredrik Lundh wrote:
 Michael Schneider wrote:
 
 
1) mark an object as dirty in a setter (anytime the object is changed,
the dirty flag is set without requiring a user to set the dirty flag
 
 
 properties.
 
 
2) enforce value constraints (even if just during debugging)
 
 
 properties.  (when you no longer need to enforce things, switch back
 to a plain attribute).
 
 
3) lazy init, don't bring the data in until needed
 
 
 properties.
 
 
4) adding debug info
 
 
 properties.
 
 
5)  more here
 
 
 properties.
 
 
It would be easy for me to say Add public and private to python so I
can code the way that I am used to.
 
 
 huh?  what do private and public have to do with what you're describing?
 
 
What are some python alternatives to achieve the design intents specified
above above?
 
 
 properties.
 
 http://users.rcn.com/python/download/Descriptor.htm#properties
 
 /F 
 
 
 

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


Re: 1 Million users.. I can't Scale!!

2005-09-28 Thread Michael Schneider
I would need to get a better picture of your app.

I use a package called twisted to handle large scale computing
on multicore, and multi-computer problems


http://twistedmatrix.com/

Hope this is useful,
Mike

yoda wrote:
 Hi guys,
 My situation is as follows:
 
 1)I've developed a service that generates content for a mobile service.
 2)The content is sent through an SMS gateway (currently we only send
 text messages).
 3)I've got a million users (and climbing).
 4)The users need to get the data a minimum of 5 seconds after it's
 generated. (not considering any bottlenecks external to my code).
 5)Generating the content takes 1 second.
 
 I'm considering moving to stackless python so that I can make use of
 continuations so that I can open a massive number of connections to the
 gateway and pump the messages out to each user simultaneously.(I'm
 thinking of 1 connection per user).
 
 My questions therefore are:
 1)Should I switch to stackless python or should I carry out experiments
 with mutlithreading the application?
 2)What architectural suggestions can you give me?
 3)Has anyone encountered such a situation before? How did you deal with
 it?
 4)Lastly, and probably most controversial: Is python the right language
 for this? I really don't want to switch to Lisp, Icon or Erlang as yet.
 
 I really need help because my application currently can't scale. Some
 user's end up getting their data 30 seconds after generation(best case)
 and up to 5 minutes after content generation.  This is simply
 unacceptable.  The subscribers deserve much better service if my
 startup is to survive in the market.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Python OGL Shader Programming

2005-09-19 Thread Michael Schneider
Just curious,  is anyone using python for OGL 2.0 shader language 
development?

Which lib are you using?

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