Commands for a breakpoint in .pdbrc

2010-01-05 Thread Pablo Torres N.
Hi all,

I'd like to save the commands for a breakpoint in a .pdbrc, something
like:

b 81
commands 1
pp foo.attr1
pp foo.attr2
end
b 108
commands 2
pp bar.attr1
pp bar.attr2
end

This would automate setting the environment for the debugging session.
However, this does not work with 'python -m pdb script.py', because at
the line 'commands 1', the pdb prompt starts and asks me for the
commands for the first breakpoint, ignoring what I wrote in .pdbrc;
further, it raises a NameError after I type 'end' at the pdb prompt,
because of 'foo.attr1', 'foo.attr2' and even 'end'. The same happens
for the rest of the breakpoints, so I end up with them set but not
their commands.

What would be the correct way to do this? Is it even possible?


Thanks a lot,
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-24 Thread Pablo Torres N.
On Sep 24, 5:51 am, Iain King iaink...@gmail.com wrote:
 On Sep 23, 7:36 pm, David C Ullrich dullr...@sprynet.com wrote:



  On Tue, 22 Sep 2009 02:34:53 +, Steven D'Aprano wrote:
   On Mon, 21 Sep 2009 13:50:23 -0500, David C Ullrich wrote:

   But you actually want to return twice the value. I don't see how to do
   that.

   What?

   Seriously?

  You're saying it _can_ be done in Python? They must have added
  something to the standard library again. I mean how can you return
  twice a value without a twice function to start with? I've tried.
  You'd think

  def twice(n):
    return twice(n)

  would work, but I get this really long error message.

   You're not just yanking the OP's chain???

  That would be cruel. I mean the guy has enough problems already...

 Sorry, there is no 'twice' builtin.  I think what you are looking for
 is:

 def twice(n):
     return return n

 Iain

Actually, what he wants is:

(def twice (x)
  (+ (once x) (once x)))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does extend() fail in this case, and what am I doing wrong?

2009-07-14 Thread Pablo Torres N.
This has been asked extensively before, here and elsewhere.

On Tue, Jul 14, 2009 at 09:52, Xavier Hocont...@xavierho.com wrote:
 Why doesn't the second output print [1, 2, 3,  , 7, 8, 9] ?
 The code is run at: http://codepad.org/wgLU4JZh

 class A():
     def __init__(self):
     self.n = [1, 2, 3, 4, 5]

 a = A()
 print a.n
 print a.n.extend([6, 7, 8, 9])

 #Output:
 #[1, 2, 3, 4, 5]
 #None

 I really don't know, but I'm probably missing something. Any pointers would
 be great.

 Best regards,

 Ching-Yun Xavier Ho, Technical Artist

 Contact Information
 Mobile: (+61) 04 3335 4748
 Skype ID: SpaXe85
 Email: cont...@xavierho.com
 Website: http://xavierho.com/

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





-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can i write a assemly language programs in python

2009-07-09 Thread Pablo Torres N.
Or maybe he meant if you can have both Python and assembler code in
the same source file, but I haven't heard of it.  If what you are
trying to do is write a faster version of some part of your code, try
SWIG: http://www.swig.org/

Playing the guessing game is a time sink, and since nobody has done it
so far, I will: OP, please read
http://www.mikeash.com/getting_answers.html and
http://catb.org/esr/faqs/smart-questions.html

On Thu, Jul 9, 2009 at 12:40, Terry Reedytjre...@udel.edu wrote:
 Dave Angel wrote:

 m.reddy prasad reddy wrote:

 can any one tell me how to write assembly language programs in
 python...if
 no is there any other way to write the programs in python

 Reddi prasad reddy
 ph.no:09958083797



 Assembly language is a different programming language than Python.  You
 can use both in the same process, much in the same way you can use C or C++
 with Python.  In fact, some of the system DLL's are written (partly) in
 assembler, though mostly in C or C++.

 It is possible that he meant how to write assembly *with* python.
 Or how to translate python to assembly.

 As it turns out, CPython translates Python to byte code and has a dis
 (assembly) module that produces very nice assembly code ;-)
 So that is one answer to his question.

 You'll need to tell us what your real goal is.

 Definitely.

 tjr

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




-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie needs help

2009-07-07 Thread Pablo Torres N.
On Tue, Jul 7, 2009 at 10:02, nacim_br...@agilent.com wrote:
 Hello Gurus,

 Thank you for trying to help to my initial and not well written questions.  I 
 will compile more detailed information and ask again.  Btw, I am giving a 
 glimpse to: How To Ask Questions The Smart Way.

 nacim

Give this one a try too: http://www.mikeash.com/getting_answers.html
It doesn't talk down to you...as much :P


-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Bug By Any Other Name ...

2009-07-06 Thread Pablo Torres N.
On Mon, Jul 6, 2009 at 07:12, Hendrik van Rooyenm...@microcorp.co.za wrote:
 Terry Reedy t@..el.edu wrote:

 Gabriel Genellina wrote:
 
  In this case, a note in the documentation warning about the potential
  confusion would be fine.

 How would that help someone who does not read the doc?

 It obviously won't.

 All it will do, is that it will enable people on this group,
 who may read the manual, to tell people who complain,
 to RTFM.

Yes, it's their problem if they don't read the docs.


  I agree that it would be a good idea to make it an
 error, or a warning - this might not do what you
 think it does, or an are you sure? exception.

  :-)

 - Hendrik

That would be even harder than adding a line to the docs.  Besides,
the problem that Mr. alex23 pointed: where do you stop? would really
get out of hand.

-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semi-Newbie needs a little help

2009-07-06 Thread Pablo Torres N.
On Mon, Jul 6, 2009 at 17:02, Nilenile_mcad...@yahoo.com wrote:
 Code

    for x in range(len(file_list)):
    d = open(file_list[x] , r)
    data = d.readlines()
    k = above_or_below(data)                                # This
 function seems to work correctly
    print here is the value that was returned  , k
    dict[k] = dict.get(k,0) + 1

    dict_list = dict.values()
    print here is a list of the dictionary values , dict_list
    print the length of the dictionary is , len(dict)

Correcting your indentation errors and moving your comments above the
line they reference will attract more help from others in this list
;-)

Also, I'd recommend limiting your line length to 80 chars, since lines
are wrapped anyway.


-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Python Implements long integer?

2009-07-05 Thread Pablo Torres N.
On Sun, Jul 5, 2009 at 04:57, Mark Dickinsondicki...@gmail.com wrote:
 On Jul 5, 8:38 am, Pedram pm567...@gmail.com wrote:
 Hello,
 I'm reading about implementation of long ints in Python. I downloaded
 the source code of CPython and will read the longobject.c, but from
 where I should start reading this file? I mean which function is the
 first?

 I don't really understand the question:  what do you mean by 'first'?
 It might help if you tell us what your aims are.

I think he means the entry point, problem is that libraries have many.


-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling C or C++ Functions inside Python script

2009-07-04 Thread Pablo Torres N.
On Sat, Jul 4, 2009 at 05:06, Parikshat Dubeyparikshatdu...@gmail.com wrote:
 Hi,

 Is this possible to call C functions(inbuilt or user defined) inside python
 script.If yes, please illustrate how it can be done.
 Thanks,
 Parikshat Dubey

From http://www.swig.org  :

SWIG is a software development tool that connects programs written in C
and C++ with a variety of high-level programming languages. SWIG is used
with different types of languages including common scripting languages
such as Perl, PHP, Python, Tcl and Ruby. 


---
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clarity vs. code reuse/generality

2009-07-04 Thread Pablo Torres N.
On Sat, Jul 4, 2009 at 10:05, kjno.em...@please.post wrote:
http://docs.python.org/reference/simple_stmts.html#grammar-token-assert_stmt
The current code generator emits no code for an assert statement when 
optimization is requested at compile time.

 Sorry, this doesn't say anything like don't use assertions to test
 argument values.  I'm aware of the fact that assertions are silenced
 under certain circumstances.  But where does the principle 1. in
 your first reply come from?  I've never seen it before, and would
 like to understand the reasoning behind it.

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


But...if no code is generated for assertions on some occasions, then the
parameters would go unchecked, potentially breaking your code in said
occasions.

-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sequence splitting

2009-07-03 Thread Pablo Torres N.
On Fri, Jul 3, 2009 at 06:01, Paul Moorep.f.mo...@gmail.com wrote:
 2009/7/3 Brad schi...@gmail.com:
 Perhaps true, but it would be a nice convenience (for me) as a built-
 in written in either Python or C. Although the default case of a bool
 function would surely be faster.

 The chance of getting this accepted as a builtin is essentially zero.
 To be a builtin, as opposed to being in the standard library,
 something has to have a very strong justification.

That's right.  Mr. schickb, I think what you need is a few concrete
examples as to where this function would be beneficial, so it can be
judged objectively.

-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clarity vs. code reuse/generality

2009-07-03 Thread Pablo Torres N.
On Fri, Jul 3, 2009 at 09:05, kjno.em...@please.post wrote:
 The context is the concept of a binary search.  In one of their
 homeworks, my students will have two occasions to use a binary
 search.  This seemed like a perfect opportunity to illustrate the
 idea of abstracting commonalities of code into a re-usable function.
 So I thought that I'd code a helper function, called _binary_search,
 that took five parameters: a lower limit, an upper limit, a
 one-parameter function, a target value, and a tolerance (epsilon).
 It returns the value of the parameter for which the value of the
 passed function is within the tolerance of the target value.

Five params for a novice function is overkill.  I'd drop the epsilon
thing and, assuming you are searching in a list, tuple or something
similar, make the lower limit default to the first index and the upper
default to the last one.

In fact, I'd let them to realize that a function is convenient, and
base some of the grading in whether they wrote it or not.  Just a
thought.

-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sequence splitting

2009-07-02 Thread Pablo Torres N.
On Thu, Jul 2, 2009 at 21:56, schickbschi...@gmail.com wrote:
 I have fairly often found the need to split a sequence into two groups
 based on a function result. Much like the existing filter function,
 but returning a tuple of true, false sequences. In Python, something
 like:

 def split(seq, func=None):
    if func is None:
        func = bool
    t, f = [], []
    for item in seq:
        if func(item):
            t.append(item)
        else:
            f.append(item)
    return (t, f)

 The discussion linked to below has various approaches for doing this
 now, but most traverse the sequence twice and many don't apply a
 function to spit the sequence.
 http://stackoverflow.com/questions/949098/python-split-a-list-based-on-a-condition

 Is there any interest in a C implementation of this? Seems too trivial
 to write a PEP, so I'm just trying to measure interest before diving
 in. This wouldn't really belong in intertool. Would it be best
 implemented as a top level built-in?

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


This sounds like it belongs to the python-ideas list.  I suggest
posting there for better feedback, since the core developers check
that list more often than this one.


-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sequence splitting

2009-07-02 Thread Pablo Torres N.
On Jul 2, 9:56 pm, schickb schi...@gmail.com wrote:
 I have fairly often found the need to split a sequence into two groups
 based on a function result. Much like the existing filter function,
 but returning a tuple of true, false sequences. In Python, something
 like:

 def split(seq, func=None):
     if func is None:
         func = bool
     t, f = [], []
     for item in seq:
         if func(item):
             t.append(item)
         else:
             f.append(item)
     return (t, f)

 The discussion linked to below has various approaches for doing this
 now, but most traverse the sequence twice and many don't apply a
 function to spit the 
 sequence.http://stackoverflow.com/questions/949098/python-split-a-list-based-o...

 Is there any interest in a C implementation of this? Seems too trivial
 to write a PEP, so I'm just trying to measure interest before diving
 in. This wouldn't really belong in intertool. Would it be best
 implemented as a top level built-in?

 -Brad

This sounds like it belongs to the python-ideas list.  I suggest
posting there for better feedback, since the core developers check
that list more often than this one.

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


Re: Sequence splitting

2009-07-02 Thread Pablo Torres N.
On Thu, Jul 2, 2009 at 23:34, Bradschi...@gmail.com wrote:
 On Jul 2, 9:08 pm, Paul Rubin http://phr...@nospam.invalid wrote:
 Brad schi...@gmail.com writes:
  On Jul 2, 8:14 pm, Paul Rubin http://phr...@nospam.invalid wrote:
   schickb schi...@gmail.com writes:
def split(seq, func=None):
    if func is None:
        func = bool
    t, f = [], []
    for item in seq:
        if func(item):
            t.append(item)
        else:
            f.append(item)
    return (t, f)

   untested:

      def split(seq, func=bool):
         xs = zip(seq, itertools.imap(func, seq))
         t = list(x for (x,y) in xs if y)
         f = list(x for (x,y) in xs if not y)
         return (t, f)

  In my testing that is 3.5x slower than the original solution (and less
  clear imo). I fixed my version to take a bool default. Either way, I'm
  not really looking for additional ways to do this in Python unless
  I've totally missed something. What I am considering is writing it in
  C, much like filter.

 I'm a little skeptical that the C version will help much, if it's
 evaluating a python function at every list element.

 Perhaps true, but it would be a nice convenience (for me) as a built-
 in written in either Python or C. Although the default case of a bool
 function would surely be faster.

 Here's a variant of your version:

  def split(seq, func=bool):
      t, f = [], []
      ta, fa = t.append, f.append
      for item in seq:
          (ta if func(item) else fa)(item)
      return (t, f)

 This avoids some dict lookups and copying.  I wonder if that helps
 significantly.

 Faster, but in tests of a few short sequences only 1% so.

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


If it is speed that we are after, it's my understanding that map and
filter are faster than iterating with the for statement (and also
faster than list comprehensions).  So here is a rewrite:

def split(seq, func=bool):
t = filter(func, seq)
f = filter(lambda x: not func(x), seq)
return list(t), list(f)

The lambda thing is kinda ugly, but I can't think of anything else.
Also, is it ok to return lists?  Py3k saw a lot of APIs changed to
return iterables instead of lists, so maybe my function should have
'return t, f' as it's last statement.


-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list