Took too long time to start before executing my first line of code

2015-04-23 Thread Steven Woody
Hi,

I got a problem and hope your gurus can show me some clues.

I run python on an embedded ARM system.  Everything is fine except that it 
seems every program need 3s+ time to load -- I mean it took 3s before executing 
the first line of every program.

I run strace but cannot identify the true problem,  can you have a look at the 
below strace output and check is there anything unusual?  Thanks in advance.

---cut start---
10:59:51.615872 execve("./a.py", ["./a.py"], [/* 30 vars */]) = 0
10:59:51.629981 brk(0)  = 0x16000
10:59:51.636587 uname({sys="Linux", node="FFC3", ...}) = 0
10:59:51.644010 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or 
directory)
10:59:51.651538 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
10:59:51.652945 fstat64(3, {st_mode=S_IFREG|0644, st_size=25193, ...}) = 0
10:59:51.660953 mmap2(NULL, 25193, PROT_READ, MAP_PRIVATE, 3, 0) = 0x400ce000
10:59:51.662309 close(3)= 0
10:59:51.663520 open("/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
10:59:51.664978 read(3, 
"\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0(\320\0\0004\0\0\0"..., 512) = 
512
10:59:51.671837 fstat64(3, {st_mode=S_IFREG|0755, st_size=133660, ...}) = 0
10:59:51.674480 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40166000
10:59:51.676166 mmap2(NULL, 165176, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401a5000
10:59:51.677422 mprotect(0x401c6000, 28672, PROT_NONE) = 0
10:59:51.678618 mmap2(0x401cd000, 4096, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2) = 0x401cd000
10:59:51.679974 close(3)= 0
10:59:51.686401 open("/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
10:59:51.687826 read(3, 
"\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\274\201\1\0004\0\0\0"..., 512) 
= 512
10:59:51.689408 fstat64(3, {st_mode=S_IFREG|0755, st_size=1254532, ...}) = 0
10:59:51.697454 mmap2(NULL, 1295760, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401ce000
10:59:51.698643 mprotect(0x402fd000, 32768, PROT_NONE) = 0
10:59:51.699771 mmap2(0x40305000, 12288, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12f000) = 0x40305000
10:59:51.706489 mmap2(0x40308000, 9616, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40308000
10:59:51.707888 close(3)= 0
10:59:51.709232 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4007f000
10:59:51.715685 set_tls(0x4007f4c0, 0x4007fb98, 0x40112058, 0x4007f4c0, 
0x40112058) = 0
10:59:51.718582 mprotect(0x40305000, 8192, PROT_READ) = 0
10:59:51.725269 mprotect(0x40111000, 4096, PROT_READ) = 0
10:59:51.726390 munmap(0x400ce000, 25193) = 0
10:59:51.729425 brk(0)  = 0x16000
10:59:51.735659 brk(0x37000)= 0x37000
10:59:51.737164 execve("/bin/python", ["python", "./a.py"], [/* 30 vars */]) = 
-1 ENOENT (No such file or directory)
10:59:51.746368 execve("/sbin/python", ["python", "./a.py"], [/* 30 vars */]) = 
-1 ENOENT (No such file or directory)
10:59:51.755206 execve("/usr/bin/python", ["python", "./a.py"], [/* 30 vars 
*/]) = 0
10:59:51.762688 brk(0)  = 0x11000
10:59:51.763926 uname({sys="Linux", node="FFC3", ...}) = 0
10:59:51.780735 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or 
directory)
10:59:51.782585 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
10:59:51.784086 fstat64(3, {st_mode=S_IFREG|0644, st_size=25193, ...}) = 0
10:59:51.791800 mmap2(NULL, 25193, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40094000
10:59:51.792826 close(3)= 0
10:59:51.794020 open("/usr/lib/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = 3
10:59:51.801063 read(3, 
"\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\344\371\1\0004\0\0\0"..., 512) 
= 512
10:59:51.802651 fstat64(3, {st_mode=S_IFREG|0555, st_size=5496357, ...}) = 0
10:59:51.805532 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40198000
10:59:51.806731 mmap2(NULL, 1492672, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40251000
10:59:51.807986 mprotect(0x4039a000, 28672, PROT_NONE) = 0
10:59:51.809177 mmap2(0x403a1000, 77824, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x148000) = 0x403a1000
10:59:51.815967 mmap2(0x403b4000, 38592, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x403b4000
10:59:51.817451 close(3)= 0
10:59:51.818641 open("/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
10:59:51.819991 read(3, 
"\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0lZ\0\0004\0\0\0"..., 512) = 512
10:59:51.826883 fstat64(3, {st_mode=S_IFREG|0755, st_size=127839, ...}) = 0
10:59:51.829478 mmap2(NULL, 131624, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x4005e000
10:59:51.830829 mprotect(0x40073000, 32768, PROT_NONE) = 0
10:59:51.832022 mmap2(0x4007b000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x4007b000
10:59:51.833549 mmap2(0x4007d000, 4648, PRO

How to find an COM object in using of pywin32

2010-03-01 Thread Steven Woody
Hi,

I want to interactive with an OLE application with pywin32.  The
problem is I get totally no idea how to find the object in OLEView and
how to figure out it's interface.

With pywin32's example, I even don't understand that in the below statement,

  win32com.client.Dispatch('Excel.Application')

that where the name 'Excel.Application' comes from?  In OLEView
(Microsoft's COM brower), I cannot find this name.


Could you give me any help?  Thanks


-- 
Life is the only flaw in an otherwise perfect nonexistence
-- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyserial: Unexpected Local Echo

2010-01-17 Thread Steven Woody
2010/1/16 John Nagle :
> Grant Edwards wrote:
>>
>> On 2010-01-11, Steven Woody  wrote:
>>
>>> I am using pyserial.  But I always get the local echo after I
>>> write some characters onto serial port
>>
>> I really doubt you're getting a local echo.  Is the data coming
>> out the serial port?  Do you get the echo if you disconnect the
>> serial cable?
>>
>>> and I find no way to disable this behavior. When I say 'local
>>> echo', I mean the next read operation will get characters that
>>> was just write to the same port.
>>
>> The device to which you're connected is echoing them.  There's
>> also a chance that your rxd line is floating and there's enough
>> crosstalk in the cable to "echo" the data, but I'll bet money
>> it's not being done locally (in the serial driver or port).
>>
>>> I run my program on cygwin (pyserial was also built on the
>>> system from source code) and the serial port i am using is a
>>> USB adapter that simulates a port (COM4 on my XP) because my
>>> laptop don't have a real serial port.  But I checked my COM4
>>> settings, there is no any think like 'local echo'.
>
>    You're using what?  Some version of Python built on Cygwin
> running on a Windows XP system?   What if you just run a stock
> Python built for Windows on Windows XP?  Or run Linux?  That
> half-and-half environment may not work right.  pyserial has
> special cases in it for Windows and Linux, and it's not
> clear what it will do on Cygwin.
>
>    That said, if you're getting echo from output back to input,
> I'd look at the USB to serial device.  I've used devices with
> the Silicon Laboratories CP2102 part, and they work fine.
> ("http://www.aetherltd.com/connectingusb.html";)
>
>    Do you have something plugged into the serial port?  If
> so, what?
>
>                                John Nagle
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Now I tried run the same test code using pure Windows python +
pyserial, the result is same.

Actually, the USB device is a optic head, that read data from an
electric energy meter:

PC USB Port -> Optic Head -> Meter

I get the echo even when the meter itself is disconnected, that mean
the echo is not generated by firmware inside the meter. So, if the
echo is also not generated from my PC, that much be from the optic
head itself.  Is it possible?

Regards,
woody

-- 
Life is the only flaw in an otherwise perfect nonexistence
-- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


pyserial: Unexpected Local Echo

2010-01-11 Thread Steven Woody
Hi,

I am using pyserial.  But I always get the local echo after I write
some characters onto serial port and I find no way to disable this
behavior. When I say 'local echo', I mean the next read operation will
get characters that was just write to the same port.

I run my program on cygwin (pyserial was also built on the system from
source code) and the serial port i am using is a USB adapter that
simulates a port (COM4 on my XP) because my laptop don't have a real
serial port.  But I checked my COM4 settings, there is no any think
like 'local echo'.


Thanks in advance.

-- 
Life is the only flaw in an otherwise perfect nonexistence
-- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Rapid GUI Programming with Python and Qt" source code

2009-09-11 Thread Steven Woody
On Thu, Sep 10, 2009 at 10:18 PM, David Boddie wrote:

> On Thursday 10 September 2009, Steven Woody wrote:
> > On Wed, Sep 9, 2009 at 9:33 PM, David Boddie 
> wrote:
>
> > > See this page for the links:
> > >
> > >  http://www.qtrac.eu/pyqtbook.html
> >
> > but the URL is not reachable from here.  is there another URL? thanks.
>
> Can't you access anything from qtrac.eu from where you are? Here are two
> links to archives for the Python 2.6 versions of the examples:
>
> http://www.qtrac.eu/pyqtbook26.tar.gz
> http://www.qtrac.eu/pyqtbook26.zip
>
> If you can't reach those, maybe Mark will send you the examples directly.
>
> David
>

Hi, Mark & David
I don't know the reason, but from here the site www.qtrac.eu is totally
unreachable.  So, would you please send me a file directly?

Thanks you very much!


-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Rapid GUI Programming with Python and Qt" source code

2009-09-10 Thread Steven Woody
On Wed, Sep 9, 2009 at 9:33 PM, David Boddie  wrote:

> On Wed Sep 9 07:11:26 CEST 2009, Steven Woody wrote:
>
> > *I've searched google and cannot find a valid link for the source code of
> > the book "Rapid GUI Programming with Python and Qt". Could anyone please
> > give me a non-broken URL?*
>
> See this page for the links:
>
>  http://www.qtrac.eu/pyqtbook.html
>
>
but the URL is not reachable from here.  is there another URL? thanks.



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



-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


"Rapid GUI Programming with Python and Qt" source code

2009-09-08 Thread Steven Woody
*Hi, *
*I've searched google and cannot find a valid link for the source code of
the book "Rapid GUI Programming with Python and Qt". Could anyone please
give me a non-broken URL?*

Thanks.

*
*--
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


How to distribute an application

2009-08-23 Thread Steven Woody
Hi,
My application contains a main python source file as well as a set of
modules (also .py files).  Now, I am considering distribute my application
to others. But the distutils seems made for distributing packages not for
main applications.  Am I right?  Thanks.


-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Blank Line at Program Exit

2009-08-23 Thread Steven Woody
On Sat, Aug 22, 2009 at 11:25 PM, Nitebirdz wrote:

> On Thu, Aug 20, 2009 at 01:31:14PM +0800, Steven Woody wrote:
> > Hi,
> > Any python program, even that does absolutely nothing in the code, will
> > cause a blank line printed out when the program exit.  What's the reason?
> >  Thanks.
> >
>
> Chances are it is related to whichever operating system and/or shell you
> are using.  For instance, this is taken from a system running Ubuntu
> Linux 8.04:
>
> -
> laptop:$ cat hello.py
> #!/usr/bin/env python
>
> print "Hello, there!"
> laptop:$ ./hello.py
> Hello, there!
> laptop:$ cat nothing.py
> #!/usr/bin/env python
>
> laptop:$ ./nothing.py
> laptop:$
> -
>
>
> As you can see, no blank line was printed out.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Hi,
I am using cywin on XP.

-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


line completion

2009-08-22 Thread Steven Woody
Hi,
I wrote a program that takes some user input.  Many inputs are quit often
used by user, so when a user launch the program, and type in "The Sha",  he
wants to get "wshank Redemption" displayed automatically in reversed color
(black text on white background) along his cursor.  When he decided to use
"The Shawshank Redemption", he just press the enter key, otherwise, he type
in other words anyway.

My question is, is there any module that can easy the implementation of this
feature?  Thanks.



-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Blank Line at Program Exit

2009-08-22 Thread Steven Woody
Hi,
Any python program, even that does absolutely nothing in the code, will
cause a blank line printed out when the program exit.  What's the reason?
 Thanks.


-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OptionParser How to: prog [options] [arguments]

2009-08-15 Thread Steven Woody
Thanks for all you suggestions!
-- 
http://mail.python.org/mailman/listinfo/python-list


OptionParser How to: prog [options] [arguments]

2009-08-13 Thread Steven Woody
Hi,
I am using OptionParser, but I've not managed figure out a way to support
what I wanted command line format "prog  [options] [arguments]".
E.g., "svn ls -r123 http://hello.world";.   Can I do this using OptionParser?

Thanks.

-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Event Handling and Signal-Slot Mechanism

2009-01-19 Thread Steven Woody
On Tue, Jan 20, 2009 at 1:03 AM, BlueBird  wrote:
> On Jan 19, 4:10 am, Steven Woody  wrote:
>> Hi,
>>
>> Python has Signal-Slot mechanism,
>
> Python does not have signal/slot mechanism. You are talking about the
> Qt toolkit, which is initially a (nice) C++ toolkit, available also in
> python via the PyQt wrapper.
>
> Signal/slots were introduced by Qt to make C++ gui programming easier.
> Signal/slots basically provides a very easy way to implement the
> observer/consumer design pattern, with only 2 or 3 lines of code (as
> opposed to one or two classes in java for example).
>
> Python itself does not have signal/slots but the it's very easy to
> emulate them using the Python language. In C++ however, it's tricky to
> do signal/slots in pure C++ and this addition is one of the reason
> that programming GUI in Qt is nice (personal opinion obviously).
>
> To comne back to your question:
>
>> why he still need another mechanism
>> Event Handling?
>
> This is actually a Qt question: why have event handling for some
> things, and signal/slot for some others ?
>
> My opinion on the debate:
> - signal/slot add an overhead of one class to every QObject class, and
> 3 method calls when emitting a signal (if I remember Qt documentation
> correctly). For some real-time tasks, like repainting the screen,
> every microseconds must be saved and sparing 3 method calls is a good
> idea.
> - since a GUI application is fundamentally an event driven system, the
> event stuff has to be there anyway.
> - signal/slot is very convenient for data exchange between widgets but
> I think it would be overkill to use it everywhere. Event propagation
> is a nice design as well.
>
> Now, if you want to discuss this further, I suggest to go to Qt
> interest ( http://lists.trolltech.com/qt-interest/ ) which is
> dedicated to discussion around Qt.
>
> cheers,
>
> Philippe
> --
> http://mail.python.org/mailman/listinfo/python-list
>

So much thanks, Philippe!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Event Handling and Signal-Slot Mechanism

2009-01-18 Thread Steven Woody
On Mon, Jan 19, 2009 at 11:29 AM, James Mills
 wrote:
> On Mon, Jan 19, 2009 at 1:10 PM, Steven Woody  wrote:
>> Python has Signal-Slot mechanism, why he still need another mechanism
>> Event Handling?  And, in some cases, it seems only Event Handling
>> mechanism is available, for example closeEvent().  For what case and
>> for what reason, the python think Signal Slot is not enough and will
>> not work?
>
> In what context ? What application ?
>

I am reading mark summerfield's book Rapid GUI Programming with Python
and Qt, chapter 6. In the example code, it inserted customized
behavior when user selects file->exit by overriding closeEvent() event
handler, but in other context, when a behavior is needed to handle
user interaction, the single-slot mechanism is always used.
--
http://mail.python.org/mailman/listinfo/python-list


Event Handling and Signal-Slot Mechanism

2009-01-18 Thread Steven Woody
Hi,

Python has Signal-Slot mechanism, why he still need another mechanism
Event Handling?  And, in some cases, it seems only Event Handling
mechanism is available, for example closeEvent().  For what case and
for what reason, the python think Signal Slot is not enough and will
not work?

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


File layout in development stage

2009-01-11 Thread Steven Woody
Hi,

Adapted your kindly suggestions in a previous post,  I now decide to
organize my source tree in a pattern like below:


prj:
src:
lib:
foomodule.py
barmodule.py
scripts:
prj_main.py
 test:
 footest.py
 bartest.py
 ...


That is, I want to put the top-level scripts in  prj/src/scripts  and
share libraries in prj/src/lib.  In the prj/test directory I want to
put my unit-tests using unittest module.  My question is that when in
development stage there is  no file is actually distributed, so how
should a python source in one directory refer to (import) another
module in another directory?

Thanks in advance.

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


Re: Best practice in organize classes into modules

2009-01-09 Thread Steven Woody
On Fri, Jan 9, 2009 at 4:54 PM, Bruno Desthuilliers
 wrote:
> Steven Woody a écrit :
>>
>> On Fri, Jan 9, 2009 at 1:02 PM, James Mills
>>  wrote:
>>>
>>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody 
>>> wrote:
>>>>
>>>> In C++/Java, people usually put one class into one file.  What's the
>>>> suggestion on this topic in Python?  I so much interesting this
>>>> especially when exception classes also involved.
>>>
>>> Normally i group related functionality into the one module.
>>
>> Will that lead to too large source file size?
>
> When the case happens, then you can safely refactor the module into a
> package with submodules, and use the package's __init__.py to make it a
> facade for the submodules so the refactoring is transparent for client code.

really a smart idea.  Did you mean putting some 'import statement in
__init__.py and use the old module name as the new package name?
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: threading in PyQt vs threading in standard library

2009-01-08 Thread Steven Woody
On Fri, Jan 9, 2009 at 3:32 PM, Phil Thompson
 wrote:
> On Fri, 9 Jan 2009 15:15:28 +0800, "Steven Woody" 
> wrote:
>> Hi,
>>
>> I am considering using PyQt for GUI programs, and I notices that both
>> of them include threading supports, so which one should I pick up?
>> Similar also applies 'socket'.
>
> I'd recommend using the PyQt versions of both.
>
> A significant advantage of PyQt's sockets is that they are integrated with
> the event loop. This means you don't need threads to handle networking.
>

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


threading in PyQt vs threading in standard library

2009-01-08 Thread Steven Woody
Hi,

I am considering using PyQt for GUI programs, and I notices that both
of them include threading supports, so which one should I pick up?
Similar also applies 'socket'.

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


Re: Best practice in organize classes into modules

2009-01-08 Thread Steven Woody
On Fri, Jan 9, 2009 at 2:52 PM, Steve Holden  wrote:
> Chris Rebert wrote:
>> On Thu, Jan 8, 2009 at 9:09 PM, Steven Woody  wrote:
>>> On Fri, Jan 9, 2009 at 1:02 PM, James Mills
>>>  wrote:
>>>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody  wrote:
>>>>> In C++/Java, people usually put one class into one file.  What's the
>>>>> suggestion on this topic in Python?  I so much interesting this
>>>>> especially when exception classes also involved.
>>>> Normally i group related functionality into the one module.
>>> Will that lead to too large source file size?  Is there a
>>> recommendation on max lines of a python source?  Thanks.
>>
>> I don't think there's really a hard-and-fast rule (just like in Java &
>> C++!). When the program starts to feel unwieldly, then start splitting
>> it into multiple modules. Python files can generally contain several
>> classes and functions and still be quite manageable.
>>
> The OP can take a look at the standard library to get some impression of
> what's been considered acceptable over the years. Just remember that
> some of the code is a little antiquated, as working code is not
> rewritten just for the fun of fixing the bugs this would inject.
>
> 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
>

Thanks for all your inputs!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best practice in organize classes into modules

2009-01-08 Thread Steven Woody
On Fri, Jan 9, 2009 at 1:02 PM, James Mills
 wrote:
> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody  wrote:
>> In C++/Java, people usually put one class into one file.  What's the
>> suggestion on this topic in Python?  I so much interesting this
>> especially when exception classes also involved.
>
> Normally i group related functionality into the one module.

Will that lead to too large source file size?  Is there a
recommendation on max lines of a python source?  Thanks.

> I do try to keep my std dev. as low as I can though
> if that makes any sense.
>
> cheers
> James
>
--
http://mail.python.org/mailman/listinfo/python-list


Best practice in organize classes into modules

2009-01-08 Thread Steven Woody
Hi,

In C++/Java, people usually put one class into one file.  What's the
suggestion on this topic in Python?  I so much interesting this
especially when exception classes also involved.

Thanks.

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


frontend + backend style application design

2009-01-07 Thread Steven Woody
Hi,

I am considering write an application, its core functionalities should
be implemented in a command-line application with which a user can
interact via its command line interface. This kind of command line
interface can help batch usage of the application.  On the other hand,
I still want a GUI front-end which does not implement any core
functionality but only provides a rich GUI interface and communicates
with the command-line back-end.

I am asking you experts, in the terms of python, what
idea/tools/module support this kind of architecture?

Thanks in advance.

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


Re: message of Exception

2009-01-06 Thread Steven Woody
On Wed, Jan 7, 2009 at 12:02 PM, Terry Reedy  wrote:
> Steven Woody wrote:
>>
>> Hi,
>>
>> I am trying define an Exception as below:
>>
>> class MyError(Exception):
>>def __init__(self, message):
>>self.message = message
>>
>> And, I expect that when I raise a MyError as
>>raise MyError, "my message"
>
> In 2.x you may and in 3.0 you must write that as
> raise MyError("my message")
> Best to start looking forward ;-).

Ok, I will adapt the advice.
--
http://mail.python.org/mailman/listinfo/python-list


Re: message of Exception

2009-01-06 Thread Steven Woody
On Wed, Jan 7, 2009 at 11:09 AM, Chris Rebert  wrote:
> On Tue, Jan 6, 2009 at 6:56 PM, Steven Woody  wrote:
>> Hi,
>>
>> I am trying define an Exception as below:
>>
>> class MyError(Exception):
>>def __init__(self, message):
>>self.message = message
>>
>> And, I expect that when I raise a MyError as
>>raise MyError, "my message"
>> the python should print a line such as
>>   MyError: my message
>>
>> But I did not get that, I just got:
>>   ...
>>   MyError
>>
>> I guess I had made something wrong with the __init__() definition, but
>> I can not find an answer in doc.  Please help, thanks!
>
> You need to call the superclass constructor:
>
> #note: this code will be different in Py 3.0
> class MyError(Exception):
>def __init__(self, message):
>super(MyError, self).__init__(message)

Thank you, I forgot to call base class's __init__()

>
> Or if you're not going to add anything else to MyError, you might as
> well just leave the class body empty and it'll use Exception's
> __init__, which takes care of the message.

Yes,  I know that, I just want to try and learn something.
--
http://mail.python.org/mailman/listinfo/python-list


message of Exception

2009-01-06 Thread Steven Woody
Hi,

I am trying define an Exception as below:

class MyError(Exception):
def __init__(self, message):
self.message = message

And, I expect that when I raise a MyError as
raise MyError, "my message"
the python should print a line such as
   MyError: my message

But I did not get that, I just got:
   ...
   MyError

I guess I had made something wrong with the __init__() definition, but
I can not find an answer in doc.  Please help, thanks!

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


Re: __builtin__ quote

2009-01-06 Thread Steven Woody
On Tue, Jan 6, 2009 at 4:42 PM, James Stroud  wrote:
> Steven Woody wrote:
>>
>> Hi,
>>
>> I am a new leaner and I get a question:  abs() is a member of
>> __builtin__ module, but why should I use abs() rather than
>> __builtin__.abs() ? Thanks.
>
> It saves typing.
>
> This might help your understanding:
>
> py> import __builtin__
> py> __builtin__.abs is abs
>True
>

Does that mean someone did 'import * from __builtin__'  when python startup?
--
http://mail.python.org/mailman/listinfo/python-list


__builtin__ quote

2009-01-06 Thread Steven Woody
Hi,

I am a new leaner and I get a question:  abs() is a member of
__builtin__ module, but why should I use abs() rather than
__builtin__.abs() ? Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multi-dimension list

2008-12-23 Thread Steven Woody
Hi,

In the book Python Essential Reference, Chapter 3, when talking about
extended slicing, it gives an example:  a = m[0:10, 3:20].  But I
don't understand how the 'm' was defined.  What should it looks like?

Thanks.

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


Multi-dimension list

2008-12-23 Thread Steven Woody
Hi,

In the book Python Essential Reference, Chapter 3, I see an example:
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to represent a sequence of raw bytes

2008-12-22 Thread Steven Woody
On Tue, Dec 23, 2008 at 5:05 AM, John Machin  wrote:
> On Dec 23, 1:52 am, "Steven Woody"  wrote:
>> On Mon, Dec 22, 2008 at 6:44 PM, Steven D'Aprano
>>
>>  wrote:
>> > On Mon, 22 Dec 2008 14:56:45 +0800, Steven Woody wrote:
>>
>> >> The intension is to allocate 200 undefined bytes in memory.
>>
>> > You *want* undefined bytes? Out of curiosity, what do you intend to do
>> > with them?
>>
>> to receive/send network packets, read raw files, etc.  After read
>> replies of the thread, I think 'array' or 'struct' maybe what I
>> wanted, may a plain list can do, but I am not sure.
>
> [Rhetorical questions] How do you use "undefined bytes" to receive
> network packets?? Do you really want to use "undefined bytes" to
> *send* network packets
>
> Suggestion: Stop trying to replicate C in Python; think about what you
> are trying to accomplish at a higher level, then how to implement that
> in Python.
>
> Cheers,
> John

Good suggestion, thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to represent a sequence of raw bytes

2008-12-22 Thread Steven Woody
On Mon, Dec 22, 2008 at 6:44 PM, Steven D'Aprano
 wrote:
> On Mon, 22 Dec 2008 14:56:45 +0800, Steven Woody wrote:
>
>> The intension is to allocate 200 undefined bytes in memory.
>
> You *want* undefined bytes? Out of curiosity, what do you intend to do
> with them?
>

to receive/send network packets, read raw files, etc.  After read
replies of the thread, I think 'array' or 'struct' maybe what I
wanted, may a plain list can do, but I am not sure.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to represent a sequence of raw bytes

2008-12-22 Thread Steven Woody
On Mon, Dec 22, 2008 at 4:35 PM, James Mills
 wrote:
> On Mon, Dec 22, 2008 at 4:56 PM, Steven Woody  wrote:
>> I thing "\x11\x22\x33" in python is not the {0x11, 0x22, 0x33} in C.
>> Since, a string in python is immutable, I can _not_ do something like:
>>  b[1] = "\x55".
>>
>> And, how about char buf[200] in my original question?  The intension
>> is to allocate 200 undefined bytes in memory. Thanks.
>
> Steven, one piece of advice.
>
> Python is not C.
>
> Thank.
>
> cheers
> James
>

Ok, I will study all your advices. I think I may find my way when
doing real tasks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to represent a sequence of raw bytes

2008-12-21 Thread Steven Woody
On Mon, Dec 22, 2008 at 10:27 AM, Michiel Overtoom  wrote:
> On Monday 22 December 2008 03:23:03 Steven Woody wrote:
>
>> 2.  char buf[] = {0x11, 0x22, 0x33, ... }
>>
>> What's the equivalent representation for above in Python?
>
>>>> buf="\x11\x22\33"
>>>> for b in buf: print ord(b)
> ...
> 17
> 34
> 27
>>>>
>

Hi, Michiel

I thing "\x11\x22\x33" in python is not the {0x11, 0x22, 0x33} in C.
Since, a string in python is immutable, I can _not_ do something like:
 b[1] = "\x55".

And, how about char buf[200] in my original question?  The intension
is to allocate 200 undefined bytes in memory. Thanks.

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


How to represent a sequence of raw bytes

2008-12-21 Thread Steven Woody
Hi,

What's the right type to represent a sequence of raw bytes.  In C, we usually do

1.  char buf[200]  or
2.  char buf[] = {0x11, 0x22, 0x33, ... }

What's the equivalent representation for above in Python?

Thanks.

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


Re: How to parsing a sequence of integers

2008-12-19 Thread Steven Woody
On Fri, Dec 19, 2008 at 9:33 PM, Bruno Desthuilliers
 wrote:
> Steven Woody a écrit :
>>
>> Hi,
>>
>> I am a newbie and is reading the python book.  Could anyone tell me,
>> how to parsing the following string
>>   "123 100 12 37 ..."
>
>> into a list of integers on which I can then apply max()/min()?
>
> source = "123 100 12 37"
> list_of_ints = [int(part) for part in source.strip().split()]
>
>>
>> In additional to max/min, is there something like average()?
>
> Not AFAIK, but it's really trivial
>
> def average(lst):
>   """ assume lst is a list of numerics """
>   return sum(lst) / len(lst)
>

Cool! Thank all of you.
--
http://mail.python.org/mailman/listinfo/python-list


How to parsing a sequence of integers

2008-12-19 Thread Steven Woody
Hi,

I am a newbie and is reading the python book.  Could anyone tell me,
how to parsing the following string
   "123 100 12 37 ..."
into a list of integers on which I can then apply max()/min()?

In additional to max/min, is there something like average()?

Thanks in advance.

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