Re: Natural Language Processing in Python

2009-08-15 Thread Alejandro E. Ciniglio
nltk is a good start, we used it in my Computational Linguistics course 
in school.

www.nltk.org

--Alejandro

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


Re: Natural Language Processing in Python

2009-08-15 Thread Ned Deily
In article 
,
 Prateek  wrote:
> Can somebody please provide me link to a good online resource or e-
> book for doing natural language processing programming in Python.

Check out the Natural Language Toolkit:
http://www.nltk.org/

-- 
 Ned Deily,
 [email protected]

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


Re: Natural Language Processing in Python

2009-08-15 Thread Vlastimil Brom
2009/8/14 Prateek :
> Hi,
>
> Can somebody please provide me link to a good online resource or e-
> book for doing natural language processing programming in Python.
>
> Thanks,
> Prateek
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Maybe you could start with NLTK
http://www.nltk.org/
Check the toolkit as well as the documentation.

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


bug?: python-config --ldflags gives incorrect output

2009-08-15 Thread Joseph Garvin
On the latest stable ubuntu:

$ python-config --ldflags
-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6

In case the user is statically linking, I believe the -lpython2.6
should go before the other -l's. Also, -lz is missing so whenever you
try to link against python you get tons of errors about missing PyZlib
references. Am I right in thinking these are bugs?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

2009-08-15 Thread fortunatus
On Aug 14, 1:01 pm, vippstar  wrote:
> Why would you fill your website with junk?

The OP made it clear:

>Just wanted to express some frustration with whitespace-mode.
-- 
http://mail.python.org/mailman/listinfo/python-list


get the pause status from amarok 2.1

2009-08-15 Thread Sleepy Cabbage
As the title says, I'm trying to find a way to get the pause status from 
amarok 2.1.

I'm running kubuntu 9.04 with kde 4.2.2, python 2.6.2.

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


Re: Natural Language Processing in Python

2009-08-15 Thread wwwayne
On Fri, 14 Aug 2009 09:31:43 -0700 (PDT), Prateek
 wrote:

>Hi,
>
>Can somebody please provide me link to a good online resource or e-
>book for doing natural language processing programming in Python.
>
>Thanks,
>Prateek

http://www.nltk.org/book

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


Re: anyone with genomewide microarray analysis experience ?

2009-08-15 Thread Istvan Albert
On Aug 14, 8:52 am, trias  wrote:

> Does anyone have some scripts I could use for this purpose. I work with
> S.cerevisiae

Since the largest chromosome on the yeast genome is around 4 million
bp, the easiest way to accomplish your goal is to create a list of the
same size as the chromosome, then populate this list by mapping the
genomic index to the list index.

After doing this your problem simplifies to slicing the list around
the coordinates of interest.

You'll be done in minutes.

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


Re: Python 'for' loop is memory inefficient

2009-08-15 Thread Rascal
look at xrange -- http://docs.python.org/library/functions.html#xrange
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

2009-08-15 Thread Martin P. Hellwig

Sounds like a bad case of STRIS
http://blog.dcuktec.com/2009/08/stris.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does my ftp script quit after couple of hours?

2009-08-15 Thread kk
Awesome stuff, thank you so much for all the help. The
Pcomp.lang.python is the most helpful list I have encountered so
far :)

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


Re: Natural Language Processing in Python

2009-08-15 Thread mobiledreamers
Try this out

Fotoroll does term extraction http://bit.ly/HCPDi

So to get json output of list of terms post to
http://fotoroll.com/findterms?json=true&text=Content+to+extract terms from

Hope this helps

Fotoroll Term extraction No limit on number of queries per day Yahoo 5000
queries a day Zemanta 1000 queries a day with regn

On Fri, Aug 14, 2009 at 11:26 AM, Vlastimil Brom
wrote:

> 2009/8/14 Prateek :
> > Hi,
> >
> > Can somebody please provide me link to a good online resource or e-
> > book for doing natural language processing programming in Python.
> >
> > Thanks,
> > Prateek
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
> Maybe you could start with NLTK
> http://www.nltk.org/
> Check the toolkit as well as the documentation.
>
> hth
>  vbr
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Bidegg worlds best auction site
http://bidegg.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: implementing descriptors

2009-08-15 Thread Raymond Hettinger
> Raymond,
>    This functionality is exactly what I was looking for. Thanks!  I'll
> be using this to solve my problem.
>
>    Now that I'm on the right track, I'm still a bit confused about how
> __get__ and __set__ are useful.  Admittedly, I don't need to
> understand them to solve this problem, but perhaps they may be useful
> in the future.  If I wanted to solve this problem using __get__ and
> __set__ could it be done?

The __get__ and __set__ methods are used to implement property()
itself.
So, if you didn't have property, you could roll your own version:

class MyProperty(object):

def __init__(self, fget, fset):
self.fget = fget
self.fset = fset

def __get__(self, obj, objtype=None):
return self.fget(obj)

def __set__(self, obj, value):
self.fset(obj, value)


class foo(object):
def __init__(self,a = None,b = None):
self._start = a
self._end = b
def get_start(self):
return self._start
def set_start(self, value):
if self._end is None or value < self._end:
self._start = value
else:
self._end = value
start = MyProperty(get_start, set_start)
def get_end(self):
return self._end
def set_end(self, value):
if self._start is None or value > self._start:
self._end = value
else:
self._start = value
end = MyProperty(get_end, set_end)


Raymond

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


"for" cycle with assigning index

2009-08-15 Thread dmitrey
Hi all,
could you inform me how to do it properly?

I have the cycle

for i in xrange(len(Funcs2)): # Funcs2 is Python dict
 Funcs.append(lambda *args, **kwargs: (Funcs2[i](*args, **kwargs)
[IndDict[left_arr_indexes[i]]]))

So, all the Funcs are initialized with i = last index = len(Funcs2)

When I involve

for i in xrange(len(Funcs2)):
 Funcs.append(lambda i=i,*args, **kwargs: (Funcs2[i](*args,
**kwargs)[IndDict[left_arr_indexes[i]]]))

I get "list indices must be integers, not dict" (and i is equal to
Python dictionary, that is Funcs2)

So, how to do it correctly?
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Hendrik van Rooyen
On Friday 14 August 2009 15:58:37 [email protected] wrote:

> One strategy you might employ to get rid of the busy looping is to use
> Twisted and its serial port support.  This also addresses the full-
> duplex issue you've raised.

I know - vaguely - about twisted and I have been dancing around the fire, not 
really ready to put the time in to understand it properly.   Looks like the 
time has come though - my weekend is really going to hell.

I am now going to make a loopback connector and start playing.

Thanks to everybody for the feedback.

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


Re: "for" cycle with assigning index

2009-08-15 Thread Carl Banks
On Aug 15, 12:17 am, dmitrey  wrote:
> Hi all,
> could you inform me how to do it properly?
>
> I have the cycle
>
> for i in xrange(len(Funcs2)): # Funcs2 is Python dict
>      Funcs.append(lambda *args, **kwargs: (Funcs2[i](*args, **kwargs)
> [IndDict[left_arr_indexes[i]]]))
>
> So, all the Funcs are initialized with i = last index = len(Funcs2)
>
> When I involve
>
> for i in xrange(len(Funcs2)):
>      Funcs.append(lambda i=i,*args, **kwargs: (Funcs2[i](*args,
> **kwargs)[IndDict[left_arr_indexes[i]]]))
>
> I get "list indices must be integers, not dict" (and i is equal to
> Python dictionary, that is Funcs2)
>
> So, how to do it correctly?
> Thank you in advance, D.


Define a helper function to do it:

def create_funcs_caller(i):
def func(*args,**kwargs):
return(Funcs2[i](*args,**kwargs)[IndDict[left_arr_indexes
[i]]]))
retirm func

for i in xrange(len(Funcs2)):
Funcs.append(create_funcs_caller(i))


(I prefer to do it this way in any case; never liked the keyword
argument hack way of doing it.)


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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Hendrik van Rooyen
On Friday 14 August 2009 16:19:04 Grant Edwards wrote:
> On 2009-08-14, Hendrik van Rooyen  wrote:
> > In the meantime I have had another idea which I have also not tried yet,
> > namely to do independent opens for reading and writing, to give me two
> > file instances instead of one, and to try with that.  I have no idea if
> > it would make any difference, or even work at all.
>
> That should work (and shouldn't make any difference)
>
> > My normal stuff works, but I do not like it as it is
> > essentially busy looping with short sleeps in between. In the
> > eBox, it uses most of the processor just to move a few bytes
> > of I/O in and out between the serial port and the TCP/IP, and
> > struggles to do that better than five times a second, while
> > the message time on the 115200 baud port is only about 2
> > milliseconds.
>
> What platform are you using?  I suppose it's possible that
> there's something broken in the serial driver for that
> particular hardware.

Your experience seems to be exactly the opposite to mine - you are saying it 
should "just work" and I am seeing half duplex functionality.

I have seen this on my development machine which is a dual processor of some 
gigs running SuSe Linux 10.3, as well as on the other end of a the scale - 
the eBox (a 400MHz 486 without floating point with 128 Mb of memory) running 
Slackware.

Maybe it is in the way I set the port up, because that is the common thing. 
What I do is this:

reterror = os.system('stty -F /dev/ttyS0 sane 115200 cread clocal raw -echo')

It does not seem to make a difference if I do this before or after opening the 
port.

Any comments from a Linux Guru?

- Hendrik



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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Hendrik van Rooyen
On Friday 14 August 2009 16:03:22 Diez B. Roggisch wrote:

> You should *really* just use pyserial. No hassle, instant satisfaction.

:-)  I have downloaded and had a quick look, and I see it is based on the 
standard library's serial.Serial class - another battery that I have not used 
before.  And I see that serial.Serial looks like it uses os. calls, which is 
one of the things Greg mentioned.  Curioser and Curioser.

There was one thing I saw in a quick read of pyserial  that I did not like as 
I cannot understand why it is done - if a timeout  is set to less than a 
tenth of a second, then it is changed to be a tenth.  - In a polling protocol 
that will limit you to poll only ten terminals a second, or less, and is a 
very long time if a message takes only a couple of millis to send.

I am getting there - this time around I want to kill this problem dead because 
I seem to keep doing something wrong somewhere and I want to understand what 
it is and stop doing it.

- Hendrik

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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Hendrik van Rooyen
On Friday 14 August 2009 16:19:36 Grant Edwards wrote:
> On 2009-08-14, [email protected]  wrote:
> > One strategy you might employ to get rid of the busy looping
> > is to use Twisted and its serial port support.  This also
> > addresses the full- duplex issue you've raised.
>
> There are no such full-dulex issues.

I will put an example together as soon as I have finished reading and 
answering the mail - maybe I am crazy and chasing angels.

- Hendrik

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


Re: "for" cycle with assigning index

2009-08-15 Thread Paul Rubin
Carl Banks  writes:
> def create_funcs_caller(i):
> def func(*args,**kwargs):
> return(Funcs2[i](*args,**kwargs)[IndDict[left_arr_indexes[i]]])
> retirm func
> 
> for i in xrange(len(Funcs2)):
> Funcs.append(create_funcs_caller(i))

I prefer to get rid of the index variable:

def create_funcs_caller(f,ix):
   return lambda *args, **kw: f(*args,**kw)[ix]

Funcs = list(create_funcs_caller(f,ix)
   for f,ix in zip(Funcs2, left_arr_indexes))

Or in point-free style:

from itertools import starmap

Funcs = starmap(create_funcs_caller, zip(Funcs2,left_arr_indexes))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

2009-08-15 Thread Xah Lee
Fresh out of the oven:

• How to use and setup Emacs's whitespace-mode
  http://xahlee.org/emacs/whitespace-mode.html

  Xah
∑ http://xahlee.org/

☄

On Aug 13, 6:36 pm, Xah Lee  wrote:
> • A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode
>  http://xahlee.org/UnixResource_dir/writ/emacs_whitespace-mode_problems.html
>
> plane text version follows:
> --
>
> A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode
>
> Xah Lee, 2009-08-13
>
> Just wanted to express some frustration with whitespace-mode.
>
> Emacs 23, just released, has this whitespace-mode feature. It renders
> spaces, tabs, newlines characters with a visible glyph. This feature,
> is in Microsoft Word since about 1992.
>
> This feature is important in practical ways. For example, when you
> work with “tab separated line” files (CSV) that's a common format for
> importing/exporting address books or spreadsheets. It's also important
> in whitespace-significant langs such as Python. Or, in text processing
> when placement of space and tabs matters in the output.
>
> All i wanted, is to make Space and Tab and Newline chars visible.
>
> However, the emacs whitespace-mode does much more than that. It is
> designed for tech geeking control freaks to tune every aspect of white
> space in his source code. The mode is filled with bells and whistles.
> It distinguishes tabs mixed with spaces, EOLs mixed with spaces, EOLs
> at beginning of file, EOLs at end of file, run on spaces at end of
> line, lines that has nothing to do with white spaces but is simply
> longer than 80 chars, etc. Each of these is rendered with different
> foreground, background, colors, so that they cannot possibly escape
> the notices of control freaks.
>
> By default, most of these are on, so that, when you turn on the mode,
> most reasonable clean source code become this colorful rainbow
> unreadable fuck.
>
> I tried to tune it, with my 10 years of emacs of fucking 16 hours of
> using per day, and 3 years of elisp coding experience. But, after a
> hour, it's confusion hell sans avail.
>
> O, that Alex idiot with his emacswiki, refused to lead emacswiki into
> any readable state. All he can think about is my social skills. (See:
> Problems of Emacswiki.)
>
> What the fuck motherfuck. Hi tech geekers, coding freaks, social
> science ignoramus fucks, basic economics illiterate FSF fucks, freedom
> abusing selfish ideologists fucks, Richard Stallman propagandist fuck,
> we-try-to-be-easy-to-use linuxer idioting fucks, FUCK U.
>
>   Xah
> ∑ http://xahlee.org/
>
> ☄
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Hendrik van Rooyen
On Friday 14 August 2009 16:28:26 Grant Edwards wrote:
> On 2009-08-14, greg  wrote:
> > Hendrik van Rooyen wrote:
8<---

> Doh!  It didn't even occur to me that somebody would use python
> "file" objects for serial ports, and I completely overlooked
> the fact that the OP was doing that.
>
> In short: don't do that -- it just messes things up

*grin*

All right that makes me feel better - you were so adamant that there is no 
problem that I was starting to doubt my sanity. - So I hereby cancel the 
promise I have just made to put an example together. - It is no longer 
needed.

>
> Do not use Python file objects.  Use the underlying file
> descriptors: os.open(), os.read(), os.write().  That will
> almost certainly solve your problems.
>
> If you want examples of os.x() usage, below is the
> PosixSerial.py module that I use for Linux-only applications.
> For cross-platform work, use pyserial (whose Posix support is
> based on the code below).
>

8<  -PosixSerial.py

Thanks that looks, on first inspection, similar to the serialposix.py module 
in the stdlib, but less cluttered.

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


Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]

2009-08-15 Thread Hendrik van Rooyen
On Friday 14 August 2009 18:11:52 Steven D'Aprano wrote:
> On Fri, 14 Aug 2009 07:07:31 -0700, Aahz wrote:
> > "I saw `cout' being shifted "Hello world" times to the left and stopped
> > right there."  --Steve Gonedes
>
> Assuming that's something real, and not invented for humour, I presume
> that's describing something possible in C++. Am I correct? What the hell
> would it actually do???

It would shift "cout" left "Hello World" times.
It is unclear if the shift wraps around or not.

It is similar to a banana *holding his hands apart about a foot* this colour.

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


Re: Python docs disappointing - group effort to hire writers?

2009-08-15 Thread Carl Banks
On Aug 14, 10:15 pm, Bill Jones  wrote:
> On Aug 8, 3:27 pm, Mark Lawrence  wrote:
> > My gut feeling (which could of course be wrong) is that many hard core
> > Pythonistas are cheesed off with newbies who refuse to help themselves.
>
> The funny thing is that their response is to shutdown changes that are
> intended
> to *help* newbies help themselves. It seems self-defeating to me.

Intended to help newbies doesn't necessarily mean it actually will
help newbies.

(Just sayin'.)


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


Re: Why does my ftp script quit after couple of hours?

2009-08-15 Thread Hendrik van Rooyen
On Friday 14 August 2009 18:25:50 kk wrote:

> As far as robustness, I agree with your assestment. I guess my main
> confusion with my result is that the console window just disappears. I
> wonder if I can make the window stay even if it crashesor if there are
> connection issues? I will createa  seperate log file to see if I can
> catch any issues in a log file.

try opening python with the -i flag - then the console window hangs around 
after the script exits and you can examine variables and stuff.

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


Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]

2009-08-15 Thread Chris Rebert
On Sat, Aug 15, 2009 at 4:47 AM, Hendrik van
Rooyen wrote:
> On Friday 14 August 2009 18:11:52 Steven D'Aprano wrote:
>> On Fri, 14 Aug 2009 07:07:31 -0700, Aahz wrote:
>> > "I saw `cout' being shifted "Hello world" times to the left and stopped
>> > right there."  --Steve Gonedes
>>
>> Assuming that's something real, and not invented for humour, I presume
>> that's describing something possible in C++. Am I correct? What the hell
>> would it actually do???
>
> It would shift "cout" left "Hello World" times.
> It is unclear if the shift wraps around or not.
>
> It is similar to a banana *holding his hands apart about a foot* this colour.
>
> - Hendrik

I think you managed to successfully dereference the null pointer there...

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


Re: Python 'for' loop is memory inefficient

2009-08-15 Thread Hendrik van Rooyen
On Saturday 15 August 2009 03:25:45 Dr. Phillip M. Feldman wrote:

> It seems as though Python is actually expanding range(2,n) into a list of
> numbers, even though this is incredibly wasteful of memory. There should be
> a looping mechanism that generates the index variable values incrementally
> as they are needed.

There is.

Use xrange instead of range, and try again.

And while you are about it, you may as well teach them that it is much better 
to do a multiplication than a division.

-Hendrik

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


Re: Python 'for' loop is memory inefficient

2009-08-15 Thread John Machin
On Aug 15, 11:38 am, Mark Lawrence  wrote:
> Dr. Phillip M. Feldman wrote:> I wrote the following correct but inefficient 
> test of primality for purposes
> > of demonstrating that the simplest algorithm is often not the most
> > efficient.  But, when I try to run the following code with a value of n that
> > is large enough to produce a significant amount of running time, I get an
> > out-of-memory error!
>
> > def is_prime(n):
> >    for j in range(2,n):
> >       if (n % j) == 0: return False
> >    return True
>
> > It seems as though Python is actually expanding range(2,n) into a list of
> > numbers, even though this is incredibly wasteful of memory. There should be
> > a looping mechanism that generates the index variable values incrementally
> > as they are needed.
>
> I have a strong suspicion that you will find hints in the Python
> documentation that this has already been addressed.  Perhaps you could
> try reading before posting?

Alternative hypothesis: the good doctor read the Python 3.x
documentation but absent-mindedly ran Python 2.x
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get the pause status from amarok 2.1

2009-08-15 Thread Sleepy Cabbage
On Fri, 14 Aug 2009 12:55:07 +0200, Diez B. Roggisch wrote:

> Sleepy Cabbage schrieb:
>> As the title says, I'm trying to find a way to get the pause status
>> from amarok 2.1.
>> 
>> I'm running kubuntu 9.04 with kde 4.2.2, python 2.6.2.
>> 
>> Thanks in advance.
> 
> Not at my linux-system right now, but dcop and the respective
> python-module should help.
> 
> Diez

Thanks for you reply Diez. i'm sure that kde4.2 now uses qdbus instead of 
dcop and not sure whether amarok has the qdbus org.kde.amarok /Player 
GetStatus as it returns the following: 
qdbus: I don't know how to display an argument of type '()'

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


Re: A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

2009-08-15 Thread Byung-Hee HWANG
Xah Lee  writes:

> • A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode
>   http://xahlee.org/UnixResource_dir/writ/emacs_whitespace-mode_problems.html
> [... snip 38 lines ...]

OK, Xah, thanks for good writing, i'll read it 27 hours later. And i
respect for your passion on Elisp, Python and text processing. BTW, i
don't agree with your thought that you dislike FSF. FSF is not bad
guy. Xah plz... 

Sincerely,

-- 
"Don Michael."
-- Peter Clemenza, "Chapter 31", page 435
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Hendrik van Rooyen
On Saturday 15 August 2009 04:03:42 Terry Reedy wrote:
> greg wrote:
> > You can't read and write with the same stdio file object
> > at the same time. Odd things tend to happen if you try.
>
> I believe the C standard specifies that the behavior of mixed reads and
> writes is undefined without intervening seek and/or flush, even if the
> seek is ignored (as it is on some Unix systems). With two threads, the
> timing is undetermined.

For a serial port, flush on write makes some sense, but seek is complete 
nonsense because it is undefined, and besides-  the point you try to seek to 
may never come around.  So the message I am getting loud and clear is that 
the basic thing I am doing wrong is to use the ordinary python open() instead 
of os.open().

As for the timing in two threads - Yes you are right, but there is not a lot 
one can do about it - The right solution depends to a large extent on what 
you are doing - for instance, if you are writing a polling protocol (such as 
Burroughs poll-select, or Uniscope), then you want a loop that transmits 
something, and waits for an answer or time out.  This is essentially half 
duplex, and in a high level language the natural structure to write this is 
in one thread.   On the other hand, if you are writing a sliding window type 
protocol that is capable of pouring stuff into a link asynchronously from 
both ends, then the natural way to do it is to use two threads - one to 
handle incoming stuff, and the other to squirt out the data that must go out.  
If, as is true in my case, the source of outgoing data and the sink for 
incoming data is a TCP/IP socket, then one can accomplish this with blocking 
I/O quite efficiently, provided you have a third thread looking after overall 
timing Issues.  For such a case, the timing is essentially determined by the 
flow of the data (provided of course that you can keep up with the link 
speed).   When one introduces another variable into the equation, namely the 
requirement to do a transmission at least every n milliseconds, (a feel-good 
keepalive) then you need a time out on the sources, so that you can either do 
a transmission or raise an alarm because a reporting period was missed.  So 
then you are back at a loop waiting for input or timeout, and doing a 
transmission afterwards.  Only now there are two of them, facing in opposite 
directions. 

I think this sort of thing is better written at a lower level where one has 
access to the interrupts from the ports, as well as a timer interrupt to 
handle timing and timeout issues.  But that is a lot of work, so I make do 
with python.

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


Re: unittest

2009-08-15 Thread Mag Gam
So, in this example:

"import random"

In my case I would do "import foo" ? is there anything I need to do for that?




On Sat, Aug 15, 2009 at 2:24 AM, Richard Thomas wrote:
> On Aug 15, 4:28 am, Mag Gam  wrote:
>> I am writing an application which has many command line arguments.
>> For example: foo.py -args "bar bee"
>>
>> I would like to create a test suit using unittest so when I add
>> features to "foo.py" I don't want to break other things. I just heard
>> about unittest and would love to use it for this type of thing.
>>
>> so my question is, when I do these tests do I have to code them into
>> foo.py? I prefer having a footest.py which will run the regression
>> tests. Any thoughts about this?
>>
>> TIA
>
> You should certainly keep your test suite separate. There's a quick
> example of how to write unit tests in the unittest documentation:
> http://docs.python.org/library/unittest.html#basic-example
>
> Richard.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread greg

Terry Reedy wrote:

I believe the C standard specifies that the behavior of mixed reads and 
writes is undefined without intervening seek and/or flush, even if the 
seek is ignored (as it is on some Unix systems). With two threads, the 
timing is undetermined.


It's also possible that the stdio object is being locked
while one of the threads is using it, which would also
account for the observed half-duplex behaviour.

Another good reason to steer clear of file objects!

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


Python 2.6 still not giving memory back to the OS...

2009-08-15 Thread Chris Withers

Hi All,

I thought this was fixed back in Python 2.5, but I guess not?

So, I'm playing in an interactive session:

>>> from xlrd import open_workbook
>>> b = open_workbook('some.xls',pickleable=0,formatting_info=1)

At this point, top shows the process usage for python to be about 500Mb.
That's okay, I'd expect that, b is big ;-)

>>> del b

However, it still does now, maybe the garbage collector needs a kick?

>>> import gc
>>> gc.collect()
702614

Nope, still 500Mb. What gives? How can I make Python give the memory its 
no longer using back to the OS?


Okay, so maybe this is something to do with it being an interactive 
session? So I wrote this script:


from xlrd import open_workbook
import gc
b = open_workbook('some.xls',pickleable=0,formatting_info=1)
print 'opened'
raw_input()
del b
print 'deleted'
raw_input()
gc.collect()
print 'gc'
raw_input()

The raw inputs are there so I can check the memory usage in top.
Even after the gc, Python still hasn't given the memory back to the OS :-(

What am I doing wrong?

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


What happened to __cmp__() in Python 3.x?

2009-08-15 Thread Xavier Ho
Hey all,

I've recently made my way to Python 3.1 and I'm not seeing __cmp__() in the
documentation.

Is there a substitution for this special method in 3.1, or do I really have
to define all six rich comparison methods to work it out?

If this question has already been asked somewhere, I apologise in advance.
Already googled around but I didn't find information on this.

Any replies appreciated.

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: [email protected]
Website: http://xavierho.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


What's a good solution to implement rich comparison for user-defined classes? (was: What happened to __cmp__() in Python 3.x?)

2009-08-15 Thread Xavier Ho
Never mind my last email. Google actually found me something at last.

I also found this page:
http://mail.python.org/pipermail/python-list/2008-November/688591.html

That still uses a sloppy way of defining the special methods, and a little
chunky.

Is there a better way for the lazy me?

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: [email protected]
Website: http://xavierho.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-15 Thread Steven D'Aprano
On Fri, 14 Aug 2009 18:25:45 -0700, Dr. Phillip M. Feldman wrote:

> It seems as though Python is actually expanding range(2,n) into a list
> of numbers, even though this is incredibly wasteful of memory. There
> should be a looping mechanism that generates the index variable values
> incrementally as they are needed.


Others have already pointed out to you that xrange() (for Python 2.x) 
does what you want. In Python 3.x, the old range() is gone for good, and 
xrange() renamed to just range().

However, I'd like to point out that your subject line is fundamentally 
incorrect. What you've discovered has *nothing* to do with for-loops: the 
for-loop will happily iterate over whatever object you pass to it (or at 
least try to, because not all objects are iterable). You might be 
thinking that Python requires you to write for-loops as 

for i in range(...):

but that's not correct. The for-loop doesn't care what object comes after 
the "in" and before the ":", so long as it can iterate over it one item 
at a time:

for i in [1, 3, 4, 5, 2, 0, -1, 8, 7, 6]:
print i

for c in "abcd":
print c

and many other variations will work perfectly fine.


The memory-consumption you have discovered is a property of the range() 
function, not the for-loop:

>>> L = range(2, 20)
>>> L
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

Compare to xrange:

>>> L = xrange(2, 20)
>>> L
xrange(2, 20)
>>> list(L)  # expand out into a list
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]


By the way, both range() and xrange() take an optional 'stepsize' 
argument, defaulting to 1:

>>> range(3, 20, 2)
[3, 5, 7, 9, 11, 13, 15, 17, 19]


help(range) and help(xrange) in the interactive interpreter are your 
friends.



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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread candide
Thanks to all for your response.  I particularly appreciate Rascal's solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittest

2009-08-15 Thread Steven D'Aprano
On Sat, 15 Aug 2009 07:32:15 -0400, Mag Gam wrote:

> So, in this example:
> 
> "import random"
> 
> In my case I would do "import foo" ? is there anything I need to do for
> that?


Suppose you have a file mymodule.py containing your code, and you want 
some unit tests. 

If you only have a few, you can probably put them inside mymodule.py, but 
let's say you have lots and want to keep them in a separate file. So 
create a new module mymoduletests.py, and start it like this:

# mymoduletests.py

import unittest
import mymodule

class MyTests(unittest.TestCase):  # Inherit from the TestCase class.
# Put your tests inside this class
def test_module_has_docstring(self):
"""Fail if the module has no docstring, or if it is empty."""
docstring = mymodule.__doc__
self.assert_(docstring is not None)
self.assert_(docstring.strip() != '')

if __name__ == '__main__':
# only execute this part when you run the module
# not when you import it
unittest.main()




Now to actually run the tests, from command-line, type:

python mymoduletests.py

and hit enter. (You do this from the operating system shell, not the 
Python interactive interpreter.) You should see something like this:

.
--
Ran 1 tests in 0.001s

OK




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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Michael Ströder
Hendrik van Rooyen wrote:
> In the past, on this  group, I have made statements that said that on Linux, 
> the serial port handling somehow does not allow transmitting and receiving at 
> the same time, and nobody contradicted me.

Despite all the good comments here by other skilled people I'd recommend to
determine whether the transmission line to the devices accessed support full
duplex.

My knowledge is a bit rusty on this topic. But I vaguely remember having to
deal with symmetric two-wire connections (RS-485) which were definitely
limited to half-duplex by the wire. So the PC hardware was a normal serial
port with the usual UART hardware device but the transmission protocols were
limited to half-duplex.

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Jan Kaliszewski

Dnia 15-08-2009 o 08:08:14 Rascal  wrote:


I'm bored for posting this, but here it is:

def add_commas(str):
str_list = list(str)
str_len = len(str)
for i in range(3, str_len, 3):
str_list.insert(str_len - i, ',')
return ''.join(str_list)


For short strings (for sure most common case) it's ok: simple and clear.
But for huge ones, it's better not to materialize additional list for the
string -- then pure-iterator-sollutions would be better (like Gabriel's or
mine).

Cheers,
*j

--
Jan Kaliszewski (zuo) 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 still not giving memory back to the OS...

2009-08-15 Thread Dave Angel

Chris Withers wrote:

Hi All,

I thought this was fixed back in Python 2.5, but I guess not?

So, I'm playing in an interactive session:

>>> from xlrd import open_workbook
>>> b = open_workbook('some.xls',pickleable=0,formatting_info=1)

At this point, top shows the process usage for python to be about 500Mb.
That's okay, I'd expect that, b is big ;-)

>>> del b

However, it still does now, maybe the garbage collector needs a kick?

>>> import gc
>>> gc.collect()
702614

Nope, still 500Mb. What gives? How can I make Python give the memory 
its no longer using back to the OS?


Okay, so maybe this is something to do with it being an interactive 
session? So I wrote this script:


from xlrd import open_workbook
import gc
b = open_workbook('some.xls',pickleable=0,formatting_info=1)
print 'opened'
raw_input()
del b
print 'deleted'
raw_input()
gc.collect()
print 'gc'
raw_input()

The raw inputs are there so I can check the memory usage in top.
Even after the gc, Python still hasn't given the memory back to the OS 
:-(


What am I doing wrong?

Chris

You're not doing anything wrong.  I don't know of any other environment 
that "gives the memory back" to the OS.


I don't know Unix/Linux memory management, but I do know Windows, and I 
suspect the others are quite similar.  There are a few memory allocators 
within Windows itself, and some more within the MSC runtime library.  
They work similarly enough that I can safely just choose one to 
explain.  I'll pick on malloc().


When malloc() is called for the first time (long before your module is 
loaded), it asks the operating system's  low-level mapping allocator for 
a multiple of 64k.  The 64k will always be aligned on a 64k boundary, 
and is in turn divided into 4k pages.  The 64k could come from one of 
three places -  the swapfile, an executable (or DLL), or a data file, 
but there's not much real difference between those.  malloc() itself 
will always use the swapfile.  Anyway, at this point my memory is a 
little bit fuzzy.  I think only 4k of the swapfile is actually mapped 
in, the rest being reserved.  But malloc() will then build some data 
structures for that 64k block, and as memory is requested, get more and 
more pieces of that 64k, till the whole thing is mapped in.  Then, 
additional multiples of 64k are allocated in the same way, and of course 
the data structures are chained together.  If an application "frees" a 
block, the data structure is updated, but the memory is not unmapped.  
Theoretically, if all the blocks within one 64k were freed, malloc() 
could release the 64k block to the OS, but to the best of my knowledge, 
malloc() never does.   Incidentally, there's a different scheme for 
large blocks, but that's changed several times, and I have no idea how 
it's done now.


Now, C programmers sometimes write a custom allocator, and in C++, it's 
not hard to have a custom allocator manage all instances of a particular 
class.  This can be convenient for applications that know how their 
memory usage patterns are likely to work.  Photoshop for example can be 
configured to use "user swap space" (I forget what they call it) from 
files that Photoshop explicitly allocates.  And space from that 
allocator is not from the swapfile, so it's not constrained by other 
running applications, and wouldn't be counted by the Windows equivalent 
of  'top'  (eg. the Windows Task Manager).


A custom allocator can also be designed to know when a particular set of 
allocations are all freed, and release the memory entirely back to the 
system.  For instance, if all temp data for a particular transaction is 
put into an appropriate custom allocator, then at the end of the 
transaction, it can safely be released.


I would guess that Python doesn't do any custom allocators, and 
therefore never releases the memory back to the system.  It will however 
reuse it when you allocate more stuff.



DaveA  (author of the memory tracking subsystem of NuMega's BoundsChecker)

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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Grant Edwards
On 2009-08-15, Hendrik van Rooyen  wrote:
> On Friday 14 August 2009 16:19:04 Grant Edwards wrote:
>
>> What platform are you using?  I suppose it's possible that
>> there's something broken in the serial driver for that
>> particular hardware.
>
> Your experience seems to be exactly the opposite to mine - you
> are saying it should "just work" and I am seeing half duplex
> functionality.

If you're using Python's normal open()/read()/write() calls,
then that introduces all sorts of issues.  I always use direct
OS calls os.open(), os.read(), os.write().

> Any comments from a Linux Guru?

Are you using python file operations open/read/write or OS
file-descriptor operations os.open/os.read/os.write?

-- 
Grant

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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Grant Edwards
On 2009-08-15, Hendrik van Rooyen  wrote:
> On Friday 14 August 2009 16:03:22 Diez B. Roggisch wrote:
>
>> You should *really* just use pyserial. No hassle, instant satisfaction.
>
>:-) I have downloaded and had a quick look, and I see it is
> based on the standard library's serial.Serial class - another
> battery that I have not used before.

There is no "serial" module in the standard library.  The
serial module is provided by pyserial.

> And I see that serial.Serial looks like it uses os. calls,
> which is one of the things Greg mentioned.

Indeed.  You shouldn't try to use normal open/read/write calls
with serial ports.

-- 
Grant

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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Grant Edwards
On 2009-08-15, Hendrik van Rooyen  wrote:

> 8<  
> -PosixSerial.py
>
> Thanks that looks, on first inspection, similar to the
> serialposix.py module in the stdlib, but less cluttered.

pyserial is a bit more complex because it is cross-platform and
supports Windows, as well as RFC2272 telnet backends (and OS
X?).  The Posix support in pyserial is based on an earlier
version of PosixSerial.

-- 
Grant

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


Re: callable virtual method

2009-08-15 Thread Scott David Daniels

Jean-Michel Pichavant wrote:

Steven D'Aprano wrote:

On Fri, 14 Aug 2009 18:49:26 +0200, Jean-Michel Pichavant wrote:

 

Sorry guys (means guys *and* gals :op ), I realized I've not been able
to describe precisely what I want to do. I'd like the base class to be
virtual (aka abstract). However it may be abstract but it does not mean
it cannot do some usefull stuff.


Here is the schema of my abstract methods :

class Interface(object):
def method(self):
# -
# some common stuff executed here
# -
print 'hello world'
# -
# here shall stand child specific stuff (empty in the interface
method)
# -
if self.__class__.method == Interface.method:
raise NotImplementedError('You should have read the f**
manual ! You must override this method.')




Okay, so I want to sub-class your Interface class. As you said, the 
methods in the abstract class are still useful, so in my class, I 
don't need any extra functionality for some methods -- I'm happy with 
just the "common stuff". So I use normal OO techniques and over-ride 
just the methods I need to over-ride:


  
Sometimes the base is doing cool stuff but incomplete stuff which 
requires knowledge only hold by the sub class. In my case the interface 
is a high level interface for a software that can run on multiple 
hardware platforms. Only the sub class has knowledge on how to operate 
the hardware, but no matter the hardware it still produces the same effect.


Let's say I have 50 different hardwares, I'll have 50 sub classes of 
Interface with the 'start' method to define. It wouldn't be appropriate 
(OO programming)to write 50 times '_log.debug('Starting %s' % self)' in 
each child start method when the simple task of logging the call can be 
nicely handled by the base class.


In the meantime, I must make sure  the user, who is not a python guru in 
this case, has implemented the start method for his hardware, because 
only him knows how to effectively start this hardware. I don't want him 
to come to me saying, "I got no error, still my hardware does not 
start". You can then blame him for not reading the docs, but it will 
still be less expensive to throw a nice exception with an accurate 
feedback.


[snip]

class VerboseGoodChild(Interface):
# forced to over-ride methods for no good reason
  


Definitely no !! This is the purpose of an interface class: to force 
people to write these methods. They *are* required, if they were not, 
they would not belong to the Interface.


JM


But there _is_ one moment when you can check those things, then avoid
checking thereafter: object creation.  So you can complicate your
__init__ (or __new__) with those checks that make sure you instantiate
only fully defined subclasses:

# obviously not tested except in concept:

class Base(object_or_whatever):
 def __init__(self, ...):
 class_ = self.__class__
 if class_ is Base:
 raise TypeError('Attempt to instantiate Base class')
 for name in 'one two three four':
 if getattr(Base, name) is not getattr(Base, name):
 raise NotImplementedError(
 '%s implementation missing' % name)
 ...

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


Re: Python 2.6 still not giving memory back to the OS...

2009-08-15 Thread Mark Dickinson
On Aug 15, 12:55 pm, Chris Withers  wrote:
> Hi All,
>
> I thought this was fixed back in Python 2.5, but I guess not?
>
> So, I'm playing in an interactive session:
>
>  >>> from xlrd import open_workbook
>  >>> b = open_workbook('some.xls',pickleable=0,formatting_info=1)
>
> At this point, top shows the process usage for python to be about 500Mb.
> That's okay, I'd expect that, b is big ;-)
>
>  >>> del b
>
> However, it still does now, maybe the garbage collector needs a kick?
>
>  >>> import gc
>  >>> gc.collect()
> 702614
>
> Nope, still 500Mb. What gives? How can I make Python give the memory its
> no longer using back to the OS?
> [...]

Can you get the same effects without using the xlrd module? I don't
have xlrd installed on my system (OS X 10.5/Intel), but I just tried
the following:

Python 2.6.2 (r262:71600, Jun 17 2009, 09:08:27)
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> b = 'x'*(10**9)
>>> f = open('testfile.txt', 'w')
>>> f.write(b)
>>> del b
>>> f = open('testfile.txt')
>>> b = f.read()
>>> del b

and got the expected memory usage for my Python process, as
displayed by top:  memory usage went up to nearly 1Gb after
each assignment to b, then dropped down to 19 Mb or so after
each 'del b'.  I get similar results under Python 2.5.

So maybe there's something in xlrd that's hanging on to all
that memory?

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


Re: Python docs disappointing - group effort to hire writers?

2009-08-15 Thread Mark Lawrence

Bill Jones wrote:

On Aug 8, 3:27 pm, Mark Lawrence  wrote:

Kee Nethery wrote:

As someone trying to learn the language I want to say that the tone on
this list towards people who are trying to learn Python  feels like it
has become anti-newbies.

[snip]


Kee Nethery

My gut feeling (which could of course be wrong) is that many hard core
Pythonistas are cheesed off with newbies who refuse to help themselves.


The funny thing is that their response is to shutdown changes that are
intended
to *help* newbies help themselves. It seems self-defeating to me.

And I still do not believe this to be true.  Documents are being changed 
all the time.  See the python-dev mailing list "Summary of python 
tracker issues" dated 17/24/31 July and 07/14 August 2009.  The only 
request I recall being rejected is someone objecting to the use of 
"weapons" in a piece of sample code.


Also see Issue6660 on the bug tracker, it is of particular interest to 
anyone who's interested in plans for python.org documentation links.


--
Kindest regards.

Mark Lawrence.

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


Error: No SSL support included in this Python ?

2009-08-15 Thread kramed
Hi there, I am running Windows on my dev machine and am running into
the following error while running Django and my email routines.

Exception Type: RuntimeError
Exception Value:No SSL support included in this Python
Exception Location: C:\Python26\lib\smtplib.py in starttls, line 615

This may sounds stupid but I thought SSL support was baked into
Python? I am running Active State Python 2.6.2 and Django 1.1. The
code works on my server but emails are not being sent properly so I
need to debug the app.

Can someone please point out what I am missing. Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittest

2009-08-15 Thread Scott David Daniels

Mag Gam wrote:

I am writing an application which has many command line arguments.
For example: foo.py -args "bar bee"

I would like to create a test suit using unittest so when I add
features to "foo.py" I don't want to break other things. I just heard
about unittest and would love to use it for this type of thing.

so my question is, when I do these tests do I have to code them into
foo.py? I prefer having a footest.py which will run the regression
tests. Any thoughts about this?

TIA

I avoid putting the tests in foo.py, simply because the bulk of my
tests would make the code harder to read.  So, no, unittest does not
require that you code things into foo.py.  You will find that you
may bend your coding style within foo.py in order to make it more
testable, but (if you do it right) that should also make the code
clearer.

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


Re: What happened to __cmp__() in Python 3.x?

2009-08-15 Thread Mark Lawrence

Xavier Ho wrote:

Hey all,

I've recently made my way to Python 3.1 and I'm not seeing __cmp__() in the
documentation.

Is there a substitution for this special method in 3.1, or do I really have
to define all six rich comparison methods to work it out?

If this question has already been asked somewhere, I apologise in advance.
Already googled around but I didn't find information on this.

Any replies appreciated.

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: [email protected]
Website: http://xavierho.com/



http://bytes.com/topic/python/answers/844614-python-3-sorting-comparison-function

--
Kindest regards.

Mark Lawrence.

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


Re: What's a good solution to implement rich comparison for user-defined classes? (was: What happened to __cmp__() in Python 3.x?)

2009-08-15 Thread Mark Lawrence

Xavier Ho wrote:

Never mind my last email. Google actually found me something at last.

I also found this page:
http://mail.python.org/pipermail/python-list/2008-November/688591.html

That still uses a sloppy way of defining the special methods, and a little
chunky.

Is there a better way for the lazy me?

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: [email protected]
Website: http://xavierho.com/



Did you follow on to this?
http://mail.python.org/pipermail/python-list/2008-November/688661.html

I think it's your call as to what to do next.

--
Kindest regards.

Mark Lawrence.

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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Hendrik van Rooyen
On Saturday 15 August 2009 14:40:35 Michael Ströder wrote:
> Hendrik van Rooyen wrote:
> > In the past, on this  group, I have made statements that said that on
> > Linux, the serial port handling somehow does not allow transmitting and
> > receiving at the same time, and nobody contradicted me.
>
> Despite all the good comments here by other skilled people I'd recommend to
> determine whether the transmission line to the devices accessed support
> full duplex.
>
> My knowledge is a bit rusty on this topic. But I vaguely remember having to
> deal with symmetric two-wire connections (RS-485) which were definitely
> limited to half-duplex by the wire. So the PC hardware was a normal serial
> port with the usual UART hardware device but the transmission protocols
> were limited to half-duplex.

You raise a good point, that is probably not well known amongst the youngsters 
here, as simple serial multidropping has gone out of fashion.

There is nothing wrong with your memory as far as RS-485 goes - you have 
to "turn the line around", same as for *shudder* Burroughs TDI (Two Wire 
Direct Interface).  Otherwise, if two or more parties talk at once you have 
cacophony.  An RS-422 link is to some extent worse, as it is capable of full 
duplex, but the slaves cannot hear each other, so they have to listen and 
play very nicely with the master.

This instance Is not one of those, thank heaven - I am on both sides of the 
link - once in the eBox in python, and on the other side there is just one  
Dallas chip - a fast (30 Mhz single cycle) 8051 lookalike that I programmed 
in assembler.  It is a thing that does discrete I/O that we have made for a 
customer. The link in between is just RS-232 receive and transmit without 
hardware flow control or anything fancy.  This is why I was so certain that 
there was something wrong in my python part, because I could use the second 
port on the Dallas to do monitoring, by spewing stuff out into Hyper 
Terminal.

- Hendrik

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Emile van Sebille

On 8/14/2009 5:22 PM candide said...

Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal string with thousands
separator.


What is the pythonic way to do this ?


I like list comps...

>>> jj = '1234567890123456789'
>>> ",".join([jj[ii:ii+3] for ii in range(0,len(jj),3)])
'123,456,789,012,345,678,9'
>>>

Emile

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


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-15 Thread Hendrik van Rooyen
On Saturday 15 August 2009 16:25:03 Grant Edwards wrote:

>
> Are you using python file operations open/read/write or OS
> file-descriptor operations os.open/os.read/os.write?

The former - that seems to be the source of my trouble.

I have now written a little test that uses serial.Serial and it works a treat.

I am still confused about pyserial and serial - I found serial in my 
distribution library, (on the SuSe machine, not on the 2.5 in Slackware) but 
I had to download pyserial.  I see that you were the the original author.  
Thank you for letting this stuff loose in the wild.

- Hendrik

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


Re: Python 2.6 still not giving memory back to the OS...

2009-08-15 Thread Christian Heimes

Mark Dickinson wrote:

and got the expected memory usage for my Python process, as
displayed by top:  memory usage went up to nearly 1Gb after
each assignment to b, then dropped down to 19 Mb or so after
each 'del b'.  I get similar results under Python 2.5.


I get the same results on Linux:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import os, psutil
pi = psutil.Process(os.getpid())
[mem/1024.**2 for mem in pi.get_memory_info()]

[4.71875, 28.2578125]

s = 'x' * (10**9)
[mem/1024.**2 for mem in pi.get_memory_info()]

[958.40234375, 981.93359375]

del s
[mem/1024.**2 for mem in pi.get_memory_info()]

[11.62890625, 55.1875]

Christian

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


Python-URL! - weekly Python news and links (Aug 15)

2009-08-15 Thread Gabriel Genellina
QOTW:  "They questioned my competence and that made her very sad." - Roger
Wallis,expert witness for Pirate Bay, on his wife

http://torrentfreak.com/pirate-bay-witness-wife-overwhelmed-with-flowers-090227/


unicode(s) is, surprisingly, MUCH faster (for certain encodings) than
s.decode():

http://groups.google.com/group/comp.lang.python/browse_thread/thread/314a3043ea63319f/

It is not possible to overload a compound "< <" operator (as in:
a < x < b):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/5b931a6417b7829d/

Automatic join of "consecutive" " string " "literals": bug or feature?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/174d4e2b7c0203d/

Also, unrecognized escape sequences in string literals stay in the
string: bug or feature?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4e1ea6f550a8a1d1/

Restricting dictionary keys to those objects explicitely defining
__eq__ / __hash__ may be useful in certain cases:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d35856349110c18c/

How to find out in which module an instance was created?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6acd71c326591325/

Monkey-patching an instance to make it callable (without altering other
instances of the same class):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6fdfc6458d82b581/

reload() and the 'from ... import ...' form of the import statement:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/994a6af36febabb5/

Several recipes to extract unique elements from a list:
http://groups.google.com/group/comp.lang.python/t/e5015c12a57b46b8/

All those __double_underscored__ names are confusing - why do they exist?
http://groups.google.com/group/comp.lang.python/t/e75ce772af98aaac/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiasts":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available, see:
http://www.python.org/channews.rdf
For more, see:
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python

getting the fractional part of a real?

2009-08-15 Thread Roy Smith
What's the best way to get the fractional part of a real?  The two ways I 
can see are r % 1 and r = int(r), but both seem a bit hokey.  Is there 
something more straight-forward that I'm missing, like fraction(r)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting the fractional part of a real?

2009-08-15 Thread Christian Heimes

Roy Smith schrieb:
What's the best way to get the fractional part of a real?  The two ways I 
can see are r % 1 and r = int(r), but both seem a bit hokey.  Is there 
something more straight-forward that I'm missing, like fraction(r)?



import math
math.modf(1.5)

(0.5, 1.0)

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


Re: getting the fractional part of a real?

2009-08-15 Thread Mark Dickinson
On Aug 15, 7:40 pm, Christian Heimes  wrote:
> Roy Smith schrieb:
>
> > What's the best way to get the fractional part of a real?  The two ways I
> > can see are r % 1 and r = int(r), but both seem a bit hokey.  Is there
> > something more straight-forward that I'm missing, like fraction(r)?
> >>> import math
> >>> math.modf(1.5)
>
> (0.5, 1.0)

What Christian said.  math.fmod(r, 1.0) also works.

Note that r % 1 and r - int(r) aren't the same thing for negative
reals.
What sign do you want the result to have when r is negative?

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Gregor Lingl



What is the pythonic way to do this ?


For my part, i reach to this rather complicated code:


# --

def comaSep(z,k=3, sep=','):
z=z[::-1]
x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
return sep.join(x)

# Test
for z in ["75096042068045", "509", "12024", "7", "2009"]:
print z+" --> ", comaSep(z)



Just if you are interested, a recursive solution:

>>> def comaSep(z,k=3,sep=","):
return comaSep(z[:-3],k,sep)+sep+z[-3:] if len(z)>3 else z

>>> comaSep("7")
'7'
>>> comaSep("2007")
'2,007'
>>> comaSep("12024")
'12,024'
>>> comaSep("509")
'509'
>>> comaSep("75096042068045")
'75,096,042,068,045'
>>>

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Gregor Lingl



What is the pythonic way to do this ?


For my part, i reach to this rather complicated code:


# --

def comaSep(z,k=3, sep=','):
z=z[::-1]
x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
return sep.join(x)

# Test
for z in ["75096042068045", "509", "12024", "7", "2009"]:
print z+" --> ", comaSep(z)



Just if you are interested, a recursive solution:

>>> def comaSep(z,k=3,sep=","):
return comaSep(z[:-3],k,sep)+sep+z[-3:] if len(z)>3 else z

>>> comaSep("7")
'7'
>>> comaSep("2007")
'2,007'
>>> comaSep("12024")
'12,024'
>>> comaSep("509")
'509'
>>> comaSep("75096042068045")
'75,096,042,068,045'
>>>

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Gregor Lingl

Emile van Sebille schrieb:

On 8/14/2009 5:22 PM candide said...

...

What is the pythonic way to do this ?


I like list comps...

 >>> jj = '1234567890123456789'
 >>> ",".join([jj[ii:ii+3] for ii in range(0,len(jj),3)])
'123,456,789,012,345,678,9'
 >>>

Emile



Less beautiful but more correct:

>>> ",".join([jj[max(ii-3,0):ii] for ii in
 range(len(jj)%3,len(jj)+3,3)])
'1,234,567,890,123,456,789'

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


Re: getting the fractional part of a real?

2009-08-15 Thread Gregor Lingl

Christian Heimes schrieb:

Roy Smith schrieb:
What's the best way to get the fractional part of a real?  The two 
ways I can see are r % 1 and r = int(r), but both seem a bit hokey.  
Is there something more straight-forward that I'm missing, like 
fraction(r)?



import math
math.modf(1.5)

(0.5, 1.0)

Christian


Or without the need to import something:

>>> divmod(1.5, 1)
(1.0, 0.5)
>>>

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


Re: A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

2009-08-15 Thread John Nagle

fortunatus wrote:

On Aug 14, 1:01 pm, vippstar  wrote:

Why would you fill your website with junk?


The OP made it clear:


Just wanted to express some frustration with whitespace-mode.


   Well, it took until Python 3.0 until Python enforced rules that
ensured that the indentation the user sees is the same indentation the
compiler sees.  We finally have a solution that allows both tabs and
spaces but disallows the situations which are ambiguous.  Until
Python 3.0 is fully deployed, there are situations when you need an insane
level of tab/space visibility.  Blame Python, not EMACS.

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


Re: Python 'for' loop is memory inefficient

2009-08-15 Thread John Nagle

Hendrik van Rooyen wrote:

On Saturday 15 August 2009 03:25:45 Dr. Phillip M. Feldman wrote:


And while you are about it, you may as well teach them that it is much better 
to do a multiplication than a division.


   Actually, division speed hasn't been much of an issue in years.  Arithmetic
has been faster than memory access since CPUs went superscalar.  In CPython,
with all the interpreter overhead, you'll probably never notice the difference.

   I'd thought "xrange" had already been obsoleted, and hadn't realized the
2.3 - 2.6 versions of CPython were still doing "range" the hard way, not
as a generator.

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


random.gauss vs. random.normalvariate

2009-08-15 Thread Alan G Isaac
Quoting http://docs.python.org/3.1/library/random.html#random.gauss:
Gaussian distribution. mu is the mean, and sigma is the
standard deviation. This is slightly faster than the
normalvariate() function defined below.

So since both are offered and gauss is faster, I assume it
must have some offsetting disadvantage.  What is it?

Thank you,
Alan Isaac

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


Re: getting the fractional part of a real?

2009-08-15 Thread Roy Smith
In article <[email protected]>,
 Gregor Lingl  wrote:

> Christian Heimes schrieb:
> > Roy Smith schrieb:
> >> What's the best way to get the fractional part of a real?  The two 
> >> ways I can see are r % 1 and r = int(r), but both seem a bit hokey.  
> >> Is there something more straight-forward that I'm missing, like 
> >> fraction(r)?
> > 
>  import math
>  math.modf(1.5)
> > (0.5, 1.0)
> > 
> > Christian
> 
> Or without the need to import something:
> 
>  >>> divmod(1.5, 1)
> (1.0, 0.5)
>  >>>
> 
> Gregor

Thanks.  I knew I had to be missing something obvious.

Regarding Mark Dickinson's question about what I want for negative reals, 
for the application I have in mind, r is guaranteed to be positive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]

2009-08-15 Thread Douglas Alan
On Aug 14, 10:25 pm, Dave Angel  wrote:

> Benjamin Kaplan wrote:

> > On Fri, Aug 14, 2009 at 12:42 PM, Douglas Alan wrote:

> >> P.S. Overloading "left shift" to mean "output" does indeed seem a bit
> >> sketchy, but in 15 years of C++ programming, I've never seen it cause
> >> any confusion or bugs.

> > The only reason it hasn't is because people use it in "Hello World". I bet
> > some newbie C++ programmers get confused the first time they see << used to
> > shift.

People typically get confused by a *lot* of things when they learn a
new language. I think the better metric is how people fare with a
language feature once they've grown accustomed to the language, and
how long it takes them to acquire this familiarity.

> Actually, I've seen it cause confusion, because of operator precedence.  
> The logical shift operators have a fairly high level priority, so
> sometimes you need parentheses that aren't obvious.  Fortunately, most
> of those cases make compile errors.

I've been programming in C++ so long that for me, if there's any
confusion, it's the other way around. I see "<<" or ">>" and I think I/
O. I don't immediately think shifting. Fortunately, shifting is a
pretty rare operation to actually use, which is perhaps why C++
reclaimed it for I/O.

On the other hand, you are right that the precedence of "<<" is messed
up for I/O. I've never seen a real-world case where this causes a bug
in C++ code, because the static type-checker always seems to catch the
error. In a dynamically typed language, this would be a much more
serious problem.

|>ouglas

P.S. I find it strange, however, that anyone who is not okay with
"abusing" operator overloading in this manner, wouldn't also take
umbrage at Python's overloading of "+" to work with strings and lists,
etc. Numerical addition and sequence concatenation have entirely
different semantics.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]

2009-08-15 Thread John Haggerty
I guess the problem is---does it actually matter?

On Fri, Aug 14, 2009 at 10:11 AM, Steven D'Aprano <
[email protected]> wrote:

> On Fri, 14 Aug 2009 07:07:31 -0700, Aahz wrote:
>
> > "I saw `cout' being shifted "Hello world" times to the left and stopped
> > right there."  --Steve Gonedes
>
> Assuming that's something real, and not invented for humour, I presume
> that's describing something possible in C++. Am I correct? What the hell
> would it actually do???
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQt4.__file__ gives PyQt4/__init__.py as value

2009-08-15 Thread wgw
I don't understand why the __file__ value in my installation of PyQt
would not give a proper, full path.

I'm guessing that I did not install pyqt properly (I'm on Ubuntu
Hardy, trying to install QT4.5), but before redoing the install, I
want to see if there is a quicker fix.

Also, though PyQt4/ is in the site-packages directory, and loads
properly into the interactive environment. Yolk does not list it. ???

Something strange here!

Any suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: Splitting a string into substrings of equal size

2009-08-15 Thread Mark Tolonen


"Gregor Lingl"  wrote in message 
news:[email protected]...

Emile van Sebille schrieb:

On 8/14/2009 5:22 PM candide said...

...

What is the pythonic way to do this ?


I like list comps...

 >>> jj = '1234567890123456789'
 >>> ",".join([jj[ii:ii+3] for ii in range(0,len(jj),3)])
'123,456,789,012,345,678,9'
 >>>

Emile



Less beautiful but more correct:

>>> ",".join([jj[max(ii-3,0):ii] for ii in
 range(len(jj)%3,len(jj)+3,3)])
'1,234,567,890,123,456,789'

Gregor


Is it?


jj = '234567890123456789'
",".join([jj[max(ii-3,0):ii] for ii in range(len(jj)%3,len(jj)+3,3)])

',234,567,890,123,456,789'

At least one other solution in this thread had the same problem.

-Mark


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


Re: random.gauss vs. random.normalvariate

2009-08-15 Thread Carl Banks
On Aug 15, 12:49 pm, Alan G Isaac  wrote:
> Quotinghttp://docs.python.org/3.1/library/random.html#random.gauss:
>     Gaussian distribution. mu is the mean, and sigma is the
>     standard deviation. This is slightly faster than the
>     normalvariate() function defined below.
>
> So since both are offered and gauss is faster, I assume it
> must have some offsetting disadvantage.  What is it?

random.gauss is not thread safe.

I'm kind of surprised the html docs don't mention this; the docstring
does.


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


redoing libgmail interface to "smtplib" blah?

2009-08-15 Thread John Haggerty
The following program is theoretically supposed to use a supported library.
Issues have come up where the library is not working and now another
interface is being requierd to be used.

At this point I'm looking at just changing the send commands but don't feel
confident in doing so. Wondering specifically what would have to be changed
to what.

Thanks for your time :)

#!/usr/bin/env python
#
# ogss -- SMS Shell through Gmail and libgmail
#
# Version 0.2
#
# Author: [email protected]
#
# License: GPL 2.0
#
# NOTE:
#   You should ensure you are permitted to use this script before using it
#   to access Google's Gmail servers.
#
def main(argv):
print "Starting ogss"

logfile = os.path.join(os.environ["HOME"],"ogss.log")
print "Logfile at:"+logfile
execd = []
#Checking to see if the logfile already exists
#if it doesn't we create it.
if not os.path.exists(logfile):
print "Creating log file"
try:
open(logfile,"w").close()
except:
print "Failed to open create log file. Check permissions"
exit()
#Opening log file for reading and parseing its contents into a list
#Must do this to ensure that we dont execute old commands
print "Opening log file for reading"
try:
r = open(logfile,"r")
for line in r:
eid = line.split("~")
if len(eid)>=2:
execd.append(int(eid[0]))
r.close()
except:
print "Failed to open or read log file. Check permissions"
exit()

clist = [["3 River Wireless","@sms.3rivers.net"],["7-11 Speakout","@
cingularme.com"],["Airtel (Karnataka","India)Alaska Communications
Systems"],["Alltel Wireless","@message.alltel.com"],["AT&T Wireless","@
txt.att.net"],["Bell Mobility (Canada)","@txt.bell.ca"],["Boost Mobile","@
myboostmobile.com"],["Cellular One
(Dobson)","@mobile.celloneusa.com"],["Cingular
(Postpaid)","@cingularme.com"],["Centennial
Wireless","@cwemail.com"],["Cingular
(GoPhone prepaid)","@cingularme.com"],["Claro (Nicaragua)","@
ideasclaro-ca.com"],["Comcel","@comcel.com.co"],["Cricket","@
sms.mycricket.com"],["CTI","@sms.ctimovil.com.ar"],["Emtel (Mauritius)","@
emtelworld.net"],["Fido (Canada)","@fido.ca"],["General Communications
Inc.","@msg.gci.net"],["Globalstar","@msg.globalstarusa.com"],["Helio","@
myhelio.com"],["Illinois Valley Cellular","@ivctext.com"],["i wireless",".
[email protected]"],["Meteor (Ireland)","@sms.mymeteor.ie"],["Mero Mobile
(Nepal)","@sms.spicenepal.com"],["MetroPCS","@mymetropcs.com"],["Movicom","@
movimensaje.com.ar"],["Mobitel (Sri Lanka)","@sms.mobitel.lk"],["Movistar
(Colombia)","@movistar.com.co"],["MTN (South Africa)","@sms.co.za"],["MTS
(Canada)","@text.mtsmobility.com"],["Nextel
(Argentina)","@nextel.net.ar"],["Orange
(Poland)","@orange.pl"],["Personal (Argentina)","@personal-net.com.ar"],["Plus
GSM (Poland)","@text.plusgsm.pl"],["President\s Choice (Canada)","@
txt.bell.ca"],["Qwest","@qwestmp.com"],["Rogers
(Canada)","@pcs.rogers.com"],["Sasktel
(Canada)","@sms.sasktel.com"],["Setar Mobile email (Aruba)","@mas.aw"],["Solo
Mobile","@txt.bell.ca"],["Sprint (PCS)","@messaging.sprintpcs.com"],["Sprint
(Nextel)","@page.nextel.com"],["Suncom","@tms.suncom.com"],["T-Mobile","@
tmomail.net"],["T-Mobile (Austria)","@sms.t-mobile.at"],["Telus Mobility
(Canada)","@msg.telus.com"],["Thumb Cellular","@sms.thumbcellular.com"],["Tigo
(Formerly Ola)","@sms.tigo.com.co"],["Unicel","@utext.com"],["US
Cellular","@email.uscc.net"],["Verizon","@vtext.com"],["Virgin Mobile
(Canada)","@vmobile.ca"],["Virgin Mobile (USA)","@vmobl.com"],["YCC","@
sms.ycc.ru"],["Orange (UK)","@orange.net"],["Cincinnati Bell Wireless","@
gocbw.com"],["T-Mobile Germany","@t-mobile-sms.de"],["Vodafone Germany","@
vodafone-sms.de"],["E-Plus","@smsmail.eplus.de"]]

print "Parsing user input"
if len(argv)<4:
if len(argv) == 2:
if argv[1] == "-c":
counter = 0
for car in clist:
print str(counter) + "--" + car[0]
counter += 1
exit()
else:
print
"--Useage---\n\r--Start
Service --- ogss.py USERNAME PASSWORD CELL-NUMBER
CARRIER-NUMBER\n\r--List carriers --- ogss.py -c"
print "--Useage from
phone\n\r--Ogss
COMMAND"
exit()
username   = argv[1]
password   = argv[2]
number = argv[3]
carrier = clist[int(argv[4])]
cell_email = number+carrier[1]

print "Connecting to Gmail"
account = libgmail.GmailAccount(username,password)
print "Logging into Gmail"
account.login()

print "Opening log file for writing"
try:
w = open(logfile,"a")
except:
print "Failed to open log file. Check permissions."
exit()

#If the logfile is empty (if this is the first use) we want to

Re: random.gauss vs. random.normalvariate

2009-08-15 Thread John Haggerty
What does the term "thread safe" mean exactly. I never had to program with
"threads" before

On Sat, Aug 15, 2009 at 2:26 PM, Carl Banks wrote:

> On Aug 15, 12:49 pm, Alan G Isaac  wrote:
> > Quotinghttp://docs.python.org/3.1/library/random.html#random.gauss:
> > Gaussian distribution. mu is the mean, and sigma is the
> > standard deviation. This is slightly faster than the
> > normalvariate() function defined below.
> >
> > So since both are offered and gauss is faster, I assume it
> > must have some offsetting disadvantage.  What is it?
>
> random.gauss is not thread safe.
>
> I'm kind of surprised the html docs don't mention this; the docstring
> does.
>
>
> Carl Banks
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Why is "unpacking" of tuples only allowed when there's 1 tupple ?

2009-08-15 Thread Stef Mientki

hello,

I'm not sure if  "unpacking" is the right term
but if I have a tuple of 2 arrays,
I can either call a function with:

 Space_State = tf2ss ( filt[0], filt[1] )

or with
 Space_State = tf2ss ( *filt )

Now if I've to call a function with more parameters,
why can't I use (Polynome is again a tuple of 2 arrays) :
(which already gives an error in the IDE)

 Respons = signal.lfilter ( *Polynome, Signal )

and thus I've to use:

 Respons = signal.lfilter ( Polynome[0], Polynome[1], Signal )


I use Python 2.5.2

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


Re: random.gauss vs. random.normalvariate

2009-08-15 Thread Alan G Isaac
> On Aug 15, 12:49 pm, Alan G Isaac  wrote:
>> Quotinghttp://docs.python.org/3.1/library/random.html#random.gauss:
>> Gaussian distribution. mu is the mean, and sigma is the
>> standard deviation. This is slightly faster than the
>> normalvariate() function defined below.
>>
>> So since both are offered and gauss is faster, I assume it
>> must have some offsetting disadvantage.  What is it?



On 8/15/2009 4:26 PM Carl Banks apparently wrote:
> random.gauss is not thread safe.
> 
> I'm kind of surprised the html docs don't mention this; the docstring
> does.



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


Re: Why is "unpacking" of tuples only allowed when there's 1 tupple ?

2009-08-15 Thread Jan Kaliszewski
Dnia 15-08-2009 o 22:50:39 Stef Mientki   
napisał(a):



hello,

I'm not sure if  "unpacking" is the right term
but if I have a tuple of 2 arrays,
I can either call a function with:

  Space_State = tf2ss ( filt[0], filt[1] )

or with
  Space_State = tf2ss ( *filt )

Now if I've to call a function with more parameters,
why can't I use (Polynome is again a tuple of 2 arrays) :
(which already gives an error in the IDE)

  Respons = signal.lfilter ( *Polynome, Signal )

and thus I've to use:

  Respons = signal.lfilter ( Polynome[0], Polynome[1], Signal )


The content of that tuple or list (filt/Polynome here) doesn't matter.
Simply, when calling function, you can't put positional (non-keyword)
argument after *something.

 >>> def nic(*args, **kwargs): pass
 ...
 >>> nic(*[1,2,3], 4)
   File "", line 1
 SyntaxError: only named arguments may follow *expression


That'd be ok:

 Respons = signal.lfilter(*Polynome, sig=Signal)  # if this method can
  # receive argument
  # 'sig' after more
  # than len(Polynome)
  # of arguments

--
Jan Kaliszewski (zuo) 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-15 Thread MRAB

John Nagle wrote:

Hendrik van Rooyen wrote:

On Saturday 15 August 2009 03:25:45 Dr. Phillip M. Feldman wrote:


And while you are about it, you may as well teach them that it is much 
better to do a multiplication than a division.


   Actually, division speed hasn't been much of an issue in years.  
Arithmetic
has been faster than memory access since CPUs went superscalar.  In 
CPython,
with all the interpreter overhead, you'll probably never notice the 
difference.


   I'd thought "xrange" had already been obsoleted, and hadn't realized the
2.3 - 2.6 versions of CPython were still doing "range" the hard way, not
as a generator.


It would've broken some existing code, hence it was left until Python 3.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is "unpacking" of tuples only allowed when there's 1 tupple ?

2009-08-15 Thread Stef Mientki

thanks Jan,
for the clear explanation.
cheers,
Stef

Jan Kaliszewski wrote:
Dnia 15-08-2009 o 22:50:39 Stef Mientki  
napisał(a):



hello,

I'm not sure if  "unpacking" is the right term
but if I have a tuple of 2 arrays,
I can either call a function with:

  Space_State = tf2ss ( filt[0], filt[1] )

or with
  Space_State = tf2ss ( *filt )

Now if I've to call a function with more parameters,
why can't I use (Polynome is again a tuple of 2 arrays) :
(which already gives an error in the IDE)

  Respons = signal.lfilter ( *Polynome, Signal )

and thus I've to use:

  Respons = signal.lfilter ( Polynome[0], Polynome[1], Signal )


The content of that tuple or list (filt/Polynome here) doesn't matter.
Simply, when calling function, you can't put positional (non-keyword)
argument after *something.

 >>> def nic(*args, **kwargs): pass
 ...
 >>> nic(*[1,2,3], 4)
   File "", line 1
 SyntaxError: only named arguments may follow *expression


That'd be ok:

 Respons = signal.lfilter(*Polynome, sig=Signal)  # if this method can
  # receive argument
  # 'sig' after more
  # than len(Polynome)
  # of arguments



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


Re: PyQt4.__file__ gives PyQt4/__init__.py as value

2009-08-15 Thread Christian Heimes

wgw wrote:

I don't understand why the __file__ value in my installation of PyQt
would not give a proper, full path.

I'm guessing that I did not install pyqt properly (I'm on Ubuntu
Hardy, trying to install QT4.5), but before redoing the install, I
want to see if there is a quicker fix.


Some versions of Debian and Ubuntu used to compile Python files with a 
relative path. Try this:


python2.5 /usr/lib/python2.5/compileall.py -f /usr/lib/python2.5
python2.5 -o /usr/lib/python2.5/compileall.py -f /usr/lib/python2.5

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


Python or ActionScript 3.0

2009-08-15 Thread Jaseem
Hi,

Is python similar to actionscript 3.0
Which is better to create a rich gui internet application?
Is it AS 3.0 with flex or python with its GUI libs?

Is python in demand?
Heard that python is similar to lisp. But both python and AS 3.0 is
almost identical. Which is more similar to lisp are powerful?

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread ryles
On Aug 14, 8:22 pm, candide  wrote:
> Suppose you need to split a string into substrings of a given size (except
> possibly the last substring). I make the hypothesis the first slice is at the
> end of the string.
> A typical example is provided by formatting a decimal string with thousands
> separator.
>
> What is the pythonic way to do this ?
>
> For my part, i reach to this rather complicated code:
>
> # --
>
> def comaSep(z,k=3, sep=','):
>     z=z[::-1]
>     x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
>     return sep.join(x)
>
> # Test
> for z in ["75096042068045", "509", "12024", "7", "2009"]:
>     print z+" --> ", comaSep(z)
>
> # --
>
> outputting :
>
> 75096042068045 -->  75,096,042,068,045
> 509 -->  509
> 12024 -->  12,024
> 7 -->  7
> 2009 -->  2,009
>
> Thanks

py> s='1234567'
py> ','.join(_[::-1] for _ in re.findall('.{1,3}',s[::-1])[::-1])
'1,234,567'
py> # j/k ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt4.__file__ gives PyQt4/__init__.py as value

2009-08-15 Thread wgw
On Aug 15, 2:19 pm, Christian Heimes  wrote:
> wgw wrote:
> > I don't understand why the __file__ value in my installation of PyQt
> > would not give a proper, full path.
>
> > I'm guessing that I did not install pyqt properly (I'm on Ubuntu
> > Hardy, trying to install QT4.5), but before redoing the install, I
> > want to see if there is a quicker fix.
>
> Some versions of Debian and Ubuntu used to compile Python files with a
> relative path. Try this:
>
> python2.5 /usr/lib/python2.5/compileall.py -f /usr/lib/python2.5
> python2.5 -o /usr/lib/python2.5/compileall.py -f /usr/lib/python2.5
>
> Christian

python2.5 /usr/lib/python2.5/compileall.py -f /usr/lib/python2.5

didn't change anything, and there is no -o option (-O exists, but
would that be useful?)

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread MRAB

ryles wrote:

On Aug 14, 8:22 pm, candide  wrote:

Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal string with thousands
separator.

What is the pythonic way to do this ?

For my part, i reach to this rather complicated code:

# --

def comaSep(z,k=3, sep=','):
z=z[::-1]
x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
return sep.join(x)

# Test
for z in ["75096042068045", "509", "12024", "7", "2009"]:
print z+" --> ", comaSep(z)

# --

outputting :

75096042068045 -->  75,096,042,068,045
509 -->  509
12024 -->  12,024
7 -->  7
2009 -->  2,009

Thanks


py> s='1234567'
py> ','.join(_[::-1] for _ in re.findall('.{1,3}',s[::-1])[::-1])
'1,234,567'
py> # j/k ;)


If you're going to use re, then:

>>> for z in ["75096042068045", "509", "12024", "7", "2009"]:
print re.sub(r"(?<=.)(?=(?:...)+$)", ",", z)


75,096,042,068,045
509
12,024
7
2,009
--
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Brian
On Sat, Aug 15, 2009 at 4:06 PM, MRAB  wrote:

> ryles wrote:
>
>> On Aug 14, 8:22 pm, candide  wrote:
>>
>>> Suppose you need to split a string into substrings of a given size
>>> (except
>>> possibly the last substring). I make the hypothesis the first slice is at
>>> the
>>> end of the string.
>>> A typical example is provided by formatting a decimal string with
>>> thousands
>>> separator.
>>>
>>> What is the pythonic way to do this ?
>>>
>>> For my part, i reach to this rather complicated code:
>>>
>>> # --
>>>
>>> def comaSep(z,k=3, sep=','):
>>>z=z[::-1]
>>>x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
>>>return sep.join(x)
>>>
>>> # Test
>>> for z in ["75096042068045", "509", "12024", "7", "2009"]:
>>>print z+" --> ", comaSep(z)
>>>
>>> # --
>>>
>>> outputting :
>>>
>>> 75096042068045 -->  75,096,042,068,045
>>> 509 -->  509
>>> 12024 -->  12,024
>>> 7 -->  7
>>> 2009 -->  2,009
>>>
>>> Thanks
>>>
>>
>> py> s='1234567'
>> py> ','.join(_[::-1] for _ in re.findall('.{1,3}',s[::-1])[::-1])
>> '1,234,567'
>> py> # j/k ;)
>>
>
> If you're going to use re, then:
>
> >>> for z in ["75096042068045", "509", "12024", "7", "2009"]:
>print re.sub(r"(?<=.)(?=(?:...)+$)", ",", z)
>
>
> 75,096,042,068,045
> 509
> 12,024
> 7
> 2,009
>

Can you please break down this regex?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting a string into substrings of equal size

2009-08-15 Thread MRAB

Brian wrote:



On Sat, Aug 15, 2009 at 4:06 PM, MRAB > wrote:


ryles wrote:

On Aug 14, 8:22 pm, candide  wrote:

Suppose you need to split a string into substrings of a
given size (except
possibly the last substring). I make the hypothesis the
first slice is at the
end of the string.
A typical example is provided by formatting a decimal string
with thousands
separator.

What is the pythonic way to do this ?

For my part, i reach to this rather complicated code:

# --

def comaSep(z,k=3, sep=','):
   z=z[::-1]
   x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
   return sep.join(x)

# Test
for z in ["75096042068045", "509", "12024", "7", "2009"]:
   print z+" --> ", comaSep(z)

# --

outputting :

75096042068045 -->  75,096,042,068,045
509 -->  509
12024 -->  12,024
7 -->  7
2009 -->  2,009

Thanks


py> s='1234567'
py> ','.join(_[::-1] for _ in re.findall('.{1,3}',s[::-1])[::-1])
'1,234,567'
py> # j/k ;)


If you're going to use re, then:


 >>> for z in ["75096042068045", "509", "12024", "7", "2009"]:
   print re.sub(r"(?<=.)(?=(?:...)+$)", ",", z)


   
75,096,042,068,045

509
12,024
7
2,009


Can you please break down this regex?


The call replaces a zero-width match with a comma, ie inserts a comma,
if certain conditions are met:

"(?<=.)"
Look behind for 1 character. There must be at least one previous
character. This ensures that a comma is never inserted at the start of
the string. I could also have used "(?http://mail.python.org/mailman/listinfo/python-list


Re: Splitting a string into substrings of equal size

2009-08-15 Thread ryles
On Aug 15, 6:28 pm, MRAB  wrote:

> >      >>> for z in ["75096042068045", "509", "12024", "7", "2009"]:
> >            print re.sub(r"(?<=.)(?=(?:...)+$)", ",", z)
>
> >     75,096,042,068,045
> >     509
> >     12,024
> >     7
> >     2,009
>
> The call replaces a zero-width match with a comma, ie inserts a comma,
> if certain conditions are met:
>
> "(?<=.)"
>      Look behind for 1 character. There must be at least one previous
> character. This ensures that a comma is never inserted at the start of
> the string. I could also have used "(? whether the first character is a "-". That's left as an exercise for the
> reader. :-)
>
> "(?=(?:...)+$)"
>      Look ahead for a multiple of 3 characters, followed by the end of
> the string.

Wow, well done. An exceptional recipe from Python's unofficial regex
guru. And thanks for sharing the explanation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python- javascript

2009-08-15 Thread Mike Paul
I'm trying to scrap a dynamic page with lot of javascript in it.
Inorder to get all the data from the page i need to access the
javascript. But i've no idea how to do it.

Say I'm scraping some site htttp://www.xyz.com/xyz

request=urllib2.Request("htttp://www.xyz.com/xyz")
response=urllib2.urlopen(request)
data=response.read()


So i get all the data on the initial page. Now i need to access the
javascript on this page to get additional details. I've heard someone
telling me to use spidermonkey. But no idea  on how to send javscript
as request and get the response. How hsuld i be sending the javascript
request as ? how can it be sent?

This is the script I need to access.

Click this to view more items

Can anyone tell me how can i do it very clearly. I've been breaking my
head into this for the past few days with no progress.


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


Python - scraping - javascript

2009-08-15 Thread Mike Paul
I'm trying to scrap a dynamic page with lot of javascript in it. Inorder to
get all the data from the page i need to access the javascript. But i've no
idea how to do it.

Say I'm scraping some site htttp://www.xyz.com/xyz

request=urllib2.Request("htttp://www.xyz.com/xyz")
response=urllib2.urlopen(request)
data=response.read()


So i get all the data on the initial page. Now i need to access the
javascript on this page to get additional details. I've heard someone
telling me to use spidermonkey. But no idea on how to send javscript as
request and get the response. How hsuld i be sending the javascript request
as ? how can it be sent?

This is the script I need to access.

Click this to view more items

Can anyone tell me how can i do it very clearly. I've been breaking my head
into this for the past few days with no progress.


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


Re: Unrecognized escape sequences in string literals

2009-08-15 Thread Douglas Alan
On Aug 14, 1:55 pm, Steven D'Aprano  wrote:

> Douglas, you and I clearly have a difference of opinion on
> this. Neither of us have provided even the tiniest amount
> of objective, replicable, reliable data on the
> error-proneness of the C++ approach versus that of
> Python. The supposed superiority of the C++ approach is
> entirely subjective and based on personal opinion instead
> of quantitative facts.

Alas, this is true for nearly any engineering methodology or
philosophy, which is why, I suppose, Perl, for instance,
still has its proponents. It's virtually impossible to prove
any thesis, and these things only get decided by endless
debate that rages across decades.

> I prefer languages that permit anything that isn't
> explicitly forbidden, so I'm happy that Python treats
> non-special escape sequences as valid,

I don't really understand what you mean by this. If Python
were to declare that "unrecognized escape sequences" were
forbidden, then they would be "explicitly forbidden". Would
you then be happy?

If not, why are you not upset that Python won't let me do

   [3, 4, 5] + 2

Some other programming languages I've used certainly do.

> and your attempts to convince me that this goes against
> the Zen have entirely failed to convince me. As I've done
> before, I will admit that one consequence of this design
> is that it makes it hard to introduce new escape sequences
> to Python. Given that it's vanishingly rare to want to do
> so,

I'm not so convinced of that in the days of Unicode. If I
see, backslash, and then some Kanji character, what am I
supposed to make of that? For all I know, that Kanji
character might mean newline, and I'm seeing code for a
version of Python that was tweaked to be friendly to the
Japanese. And in the days where smart hand-held devices are
proliferating like crazy, there might be ever-more demand
for easy-to-use i/o that lets you control various aspects of
those devices.

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


Re: Python 2.6 still not giving memory back to the OS...

2009-08-15 Thread John Machin
On Aug 16, 2:41 am, Mark Dickinson  wrote:
> and got the expected memory usage for my Python process, as
> displayed by top:  memory usage went up to nearly 1Gb after
> each assignment to b, then dropped down to 19 Mb or so after
> each 'del b'.  I get similar results under Python 2.5.
>
> So maybe there's something in xlrd that's hanging on to all
> that memory?

News to me, and news to guppy/heapy v0.1.9 -- unless the new Windows
support has some deficiencies -- after `del b` heapy can't find any
trace of the Book object and its contents.

As far as releasing memory back to the OS is concerned, I have dim
memories of *x systems where free() would return space to the OS if
the block was "large" and it was next to the "break" point ... this
effect could be what you are seeing.
-- 
http://mail.python.org/mailman/listinfo/python-list


ignored test cases in unittest

2009-08-15 Thread Terry
Hi,

I have some 100s unittest cases with my python program. And sometimes,
I did quick-and-dirty work by ignoring some test cases by adding an
'x' (or something else) to the beginning of the case name.
As time pass by, it's very hard for me to find which test cases are
ignored.

It seemed the to me that python unittest module does not support the
counting of ignored test cases directly. Is there any ready solution
for this?

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


Re: ignored test cases in unittest

2009-08-15 Thread Roy Smith
In article 
,
 Terry  wrote:

> Hi,
> 
> I have some 100s unittest cases with my python program. And sometimes,
> I did quick-and-dirty work by ignoring some test cases by adding an
> 'x' (or something else) to the beginning of the case name.
> As time pass by, it's very hard for me to find which test cases are
> ignored.

If you are consistent in how you do this (i.e. always add an "x" to the 
beginning of the name), it should be trivial to find them all.  I'm sure I 
could whip up some introspection based method, but it's easier and faster 
to just do "grep 'def.*xtest' *.py".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or ActionScript 3.0

2009-08-15 Thread Douglas Alan
On Aug 15, 5:32 pm, Jaseem  wrote:

> Is python similar to actionscript 3.0

For some very rough sense of "similar" it might be, but not really.

> Which is better to create a rich gui internet application?
> Is it AS 3.0 with flex or python with its GUI libs?

Python doesn't run in your typical web browser, but it is common to
use Python for doing the server-side programming, along with a Python-
based web development framework, such as Django.

You could use Jython to make a JVM applet that would run in a browser,
but JVM applets aren't very popular for a variety of reasons, and I
doubt the performance would be very good.

> Is python in demand?

Yes, it's a popular language.

> Heard that python is similar to lisp.

Kind of. Not any more so that JavaScript is, though, for instance.

> But both python and AS 3.0 is almost identical.

No, Python and ActionScript are not "almost identical".

> Which is more similar to lisp are powerful?

They both have their similarities and differences from Lisp. I think
it would be impossible to say which one is more similar to Lisp. In
general, Python is in my opinion more pleasant to program in than
ActionScript, but Python is not generally used for client-side browser
code.

I think the future of client-side browser programming is actually
JavaScript, not ActionScript, though that future may morph into one
that mostly uses JavaScript as a virtual machine. This is the approach
that Google Web Toolkit takes. It lets you write your client-side code
in Java, and that is then compiled into JavaScript.

|>ouglas



-- 
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


Re: Python- javascript

2009-08-15 Thread Douglas Alan
On Aug 15, 8:02 pm, Mike Paul  wrote:

> I'm trying to scrap a dynamic page with lot of javascript in it.
> Inorder to get all the data from the page i need to access the
> javascript. But i've no idea how to do it.

I'm not sure exactly what you are trying to do, but scraping websites
that use a lot of JavaScript are often very problematic. The last time
I did so, I had to write some pretty funky regular expressions to pick
data out of the JavaScript. Fortunately, the data was directly in the
JavaScript, rather than me having to reproduce the Ajax calling
chain.  If you need to do that, then you almost certainly want to use
a package designed for doing such things. One such package is
HtmlUnit. It is a "GUI-less browser" with a built-in JavaScript engine
that is design for such scraping tasks.

Unfortunately, you have to program it in Java, rather than Python.
(You might be able to use Jython instead of Java, but I don't know for
sure.)

|>ouglas


P.S. For scraping tasks, you probably want to use BeautifulSoup rather
than urllib2.


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


Re: ignored test cases in unittest

2009-08-15 Thread Ben Finney
Terry  writes:

> It seemed the to me that python unittest module does not support the
> counting of ignored test cases directly. Is there any ready solution
> for this?

One solution I've seen involves:

* a custom exception class, ‘TestSkipped’

* raising that exception at the top of test cases you want to
  temporarily skip

* a custom ‘TestResult’ class that knows about a “skipped” result

* a custom reporter class that knows how you want to report that result

-- 
 \   “A lot of people are afraid of heights. Not me, I'm afraid of |
  `\   widths.” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]

2009-08-15 Thread Steven D'Aprano
On Sat, 15 Aug 2009 13:01:43 -0700, Douglas Alan wrote:

> P.S. I find it strange, however, that anyone who is not okay with
> "abusing" operator overloading in this manner, wouldn't also take
> umbrage at Python's overloading of "+" to work with strings and lists,
> etc. Numerical addition and sequence concatenation have entirely
> different semantics.

Not to English speakers, where we frequently use 'add' to mean 
concatenate, append, insert, etc.:

"add this to the end of the list"
"add the prefix 'un-' to the beginning of the word to negate it"
"add your voice to the list of those calling for change"
"add your name and address to the visitor's book"

and even in-place modifications:

"after test audiences' luke-warm response, the studio added a completely 
different ending to the movie".


Personally, I would have preferred & for string and list concatenation, 
but that's entirely for subjective reasons.


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


Re: A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

2009-08-15 Thread Steven D'Aprano
On Sat, 15 Aug 2009 12:24:26 -0700, John Nagle wrote:

> fortunatus wrote:
>> On Aug 14, 1:01 pm, vippstar  wrote:
>>> Why would you fill your website with junk?
>> 
>> The OP made it clear:
>> 
>>> Just wanted to express some frustration with whitespace-mode.
> 
> Well, it took until Python 3.0 until Python enforced rules that
> ensured that the indentation the user sees is the same indentation the
> compiler sees.  We finally have a solution that allows both tabs and
> spaces but disallows the situations which are ambiguous.  Until Python
> 3.0 is fully deployed, there are situations when you need an insane
> level of tab/space visibility.  Blame Python, not EMACS.

You know, there are situations outside of Python where it is useful to 
see otherwise invisible characters. I was using Microsoft Word's "Show 
Invisibles" functionality years before Python even existed. Being able to 
see a visual glyph in place of whitespace (including line ending 
characters) is not just useful for editing indentation.



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


  1   2   >