Re: Python discussed in Nature

2015-02-15 Thread giacomo boffi
Chris Angelico ros...@gmail.com writes:

 On Sat, Feb 14, 2015 at 6:40 AM, John Ladasky
 john_lada...@sbcglobal.net wrote:
 The default font that the Geany program editor uses on my Ubuntu
 system renders everything I've tried.  When I look up that font in
 Geany's Preferences menu, it is called, simply, monospace.


 That's a font alias. Unfortunately, I've never yet figured out a
 straight-forward way to snap the pointer;

when you know it, it's easy...

% fc-match mono
DejaVuSansMono.ttf: DejaVu Sans Mono Book
% 

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


Re: What does zip mean?

2014-11-13 Thread giacomo boffi
Grant Edwards invalid@invalid.invalid writes:

 No, you don't. That's not how a zipper works.  Each tooth from side A,
 isn't bound with one from side B.  It's bound with _two_ of them from
 side B. And each of those is in turn bound with an additional tooth
 from side A, and so on...

 In your program you have two lists, whose elements `zip` returns
 bound together in pairs

 What the zipper on a coat does is convert two separate sequences into
 a single sequence where the members alternate between the two input
 sequences.  IOW if we want to do something analogous to a zipper
 fastener it should do this:

   zip([a,b,c,d,e,f],[1,2,3,4,5,6])  = [a,1,b,2,c,3,d,4,e,5,f,6]
   
 Item '1' is bound equally to item 'a' and 'b'.  Item 'b' is bound
 equally to item '1' and '2'.

I love you folks of CLP

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


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-13 Thread giacomo boffi
Clayton Kirkwood c...@godblessthe.us writes:

 Although I suspect for a price you could bring all of your
 professional programming jobs to somebody here, but I think you
 would pay out more than you would make.

s/ here/ else/ and your assumption can be falsified
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What does zip mean?

2014-11-10 Thread giacomo boffi

On 11/09/2014 11:44 AM, satishmlm...@gmail.com wrote:

What does zip return in the following piece of code?


To help you understanding what is the `zip` builtin,
please forget about PKZip etc and think about the
_zip fastener_ or _zipper_ in your bag or in your trousers

In the bag you have two sequences of teeth that the zipper
binds together in interlocking pairs

In your program you have two lists, whose elements `zip` returns
bound together in pairs
--
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-27 Thread giacomo boffi
Rustom Mody rustompm...@gmail.com writes:

 What would you say to a person who
 - Buys a Lambhorgini

I'd say: Don't buy a Lambhorgini from that nice guy you met at a party,
  but buy a Lamborghini by an authorized dealer  ;-)

-- 
I was a kid when Lamborghini launched the Miura!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread giacomo boffi
ERRATA CORRIGE:

 many different circumstances, by the very, very helpful folks of clp.
  many different circumstances, by the very, very helpful folks of clpy

-- 
sapete contare fino a venticinque?
Olimpia Milano Jugoplastika Split Partizan Beograd
Roberto Premier Duska Ivanovic Zarko Paspalj
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread giacomo boffi
Rustom Mody rustompm...@gmail.com writes:

 [As best as I can make out the OP is not using the standalone
 interpreter
 nor idle
 nor (the many options like) python-interpreter-inside-emacs
 nor ipython
 nor ...

but CodeSkulptor http://www.codeskulptor.org/]

CodeSkulptor has been mentioned recently by S4H, and he had explained
why he uses CodeSkulptor, but I cannot remember anything of the explanation...

-- 
 Sarebbe ora gli scienziati italiani mostrassero un po' i coglioni
si`, vabbe`, ma a chi?   -- PLS, in IFQ
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread giacomo boffi
Seymore4Head Seymore4Head@Hotmail.invalid writes:

 Because most of the practice I am getting is not using Python.  I
 use Codeskulptor.

Seymore,

it's been months that you're struggling with python, if you happen to
own a computer could you please take the time to install python on it
and familiarise with the interactive interpreter?  I'll see that as a
personal favor. If you have to hand in assignments using codeskulptor
or are in any other way bound by your institution to use that service
you could anyway use the interactive interpreter on your pc, applying
the debugging and self-learning techniques that were shown to you, in
many different circumstances, by the very, very helpful folks of clp.

thank you for your attention
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about PANDAS

2014-10-20 Thread giacomo boffi
Ryan Shuell ryanshu...@gmail.com writes:

 Thanks guys.  I just feel frustrated that I can't do something useful.

I had read many of your messages in the recent past, and I'm under the
impression that your frustration has more to do with Python the
Infrastructure rather than Python the Language

my suggestions will somehow reiterate what was told you in previous
threads,

 1. scrap everything python from your hard disk and your registry,
using unistall as far as possible

 2. choose ONE flavour of python, either 2.7.x or 3.4.x
- future is with 3.4,
- most exaples you'll find were written (are still written...)
  for 2.7.x

 3. the Pyton distribution from official sources contains piles of
stuff (batteries included is the motto) but you seem interested in
what is called the python scientific stack and this is not
there.

If you want at once the stdlib AND the great majority of the extra
modules you're looking for AND an easy way to install other
packages, there are quite a number of third party distributions
that fit your ticket very well: entought, anaconda, active state,
pyxy, all of them should be good enough but I'n not a Windows guy
and I'm not be able to judge. Anyway, read or ask for advice on
python windows distributions, chose one, _install using the_
_defaults_, STICK WITH THAT DISTRIBUTION, familiarizing with its
infrastructure in terms of installing extra packages, setting
virtual environments, using the development tools it offers etc

in my very humble opinion, you are discomforted by the multiplicity of
the solutions and your quest for the best one... choose one, maybe not
the best one for you but trust me, it will be good enough! as soon as
you'll be in good terms with Python the language and python the
infrastructure, as presented to you by a single language version and a
single 3rd party distribution, you will gather momentum in a very
short time

my best wishes,
g
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] spelling colour / color was Re: Toggle

2014-10-18 Thread giacomo boffi
duncan smith buzzard@invalid.invalid writes:

 [...] It was the top / bottom of the [TV] programme that I didn't
 immediately get, because I was thinking of a timeline running left
 to right (perhaps rather than the script used by the presenters).

is it just me that thinks of a timeline running from the wall behind
the tv set into my dinette?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-14 Thread giacomo boffi
Tim Chase python.l...@tim.thechases.com writes:

 On 2014-10-12 22:16, Marko Rauhamaa wrote:
 is equivalent with
 
 while ans.lower()[0] != 'y':
  ans = input('Do you like python?')

 And still better improved with

   while ans[:1].lower() != 'y':
 ans = input('Do you like python?')

 yok is Turkish for an EMPHATIC NO
(or, at least, that's what I was led to think many years ago)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread giacomo boffi
Wiktor look@signature.invalid writes:

   I'm not starting from scratch. I'm using packages 'termcolor', 'colorama'
 and 'colorconsole'

the 'urwid' package could be useful for similar projects but cite
requires Linux, OSX, Cygwin or other unix-like OS/cite so I guess
it's of no use for you...

ciao
  g
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hello and sorry for disturbing !

2014-05-27 Thread giacomo boffi
Rustom Mody rustompm...@gmail.com writes:

 For ubuntu you should need nothing for python.
 In other words python should run on a basic ubuntu installation.
 From the shell just type python and the interpreter should start.

 For more specialized work there are dozens (maybe hundreds?) of
 packages in the apt repos.

% apt-cache show pythonTABTAB
Display all 2776 possibilities? (y or n)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python solve problem with string operation

2014-01-16 Thread giacomo boffi
Nac Temha nacctte...@gmail.com writes:

 Hi everyone,

 I want to do operation with chars in the given string. Actually I want to
 grouping the same chars.

 For example;

 input : 3443331123377
 operation- (3)(44)()(333)(11)(2)(33)(77)
 output: 34131237



 How can I do without list, regular expression. just using string operations. 
 Using an effective methods of python for this problem.


% cat a.py
def f(s,n):
if s[n+1] == s[n]:
return s[:n]+s[n+1:], n
return s, n+1

i = 3443331123377
n = 0

while n+1 != len(i):
i, n = f(i, n)

print i
% python a.py
34131237
% 

-- 
your instructor is a mean person
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python solve problem with string operation

2014-01-16 Thread giacomo boffi
giacomo boffi pec...@pascolo.net writes:

 % python a.py
 34131237

% cat a.py 
i=3443331123377;n=0
while n+1!=len(i):i,n=(i[:n]+i[n+1:],n) if i[n+1]==i[n] else (i,n+1)
print i
% python a.py 
34131237
%
-- 
for Nikos
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ASCII and Unicode

2013-12-08 Thread giacomo boffi
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:

 On Sat, 07 Dec 2013 17:05:34 +0100, giacomo boffi wrote:

 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
 
 Ironically, your post was not Unicode.  [...] Your post was sent using
 a legacy encoding, Windows-1252, also known as CP-1252
 
 i access rusi's post using a NNTP server, and in his post i see
 
 Content-Type: text/plain; charset=UTF-8

 But *which post* are you looking at?

blush the wrong one.../ i.e, the one JUST BEFORE your change of
subject --- if i look at the ellipsis post, i see the same encoding
that you have mentioned

sorry for the confusion
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ASCII and Unicode

2013-12-07 Thread giacomo boffi
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:

 Ironically, your post was not Unicode.  [...] Your post was sent
 using a legacy encoding, Windows-1252, also known as CP-1252

i access rusi's post using a NNTP server,
and in his post i see

Content-Type: text/plain; charset=UTF-8

is it possible that what you see is an artifact
of the gateway?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling 3 operands in an expression without raising an exception

2013-09-29 Thread giacomo boffi
Νίκος nikos.gr...@gmail.com writes:

 IF it can also be written in one-line

def f(x,n,w):return(lambda 
y=f(x[::2],n/2,w[::2]),z=f(x[1::2],n/2,w[::2]):reduce(lambda 
x,y:x+y,zip(*[(y[k]+w[k]*z[k],y[k]-w[k]*z[k]) for k in range(n/2)])))()if n1 
else x

-- 
anch'io la penso come me, ma -- SteO153, in IHC
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling 3 operands in an expression without raising an exception

2013-09-29 Thread giacomo boffi
Joel Goldstick joel.goldst...@gmail.com writes:

 On Sun, Sep 29, 2013 at 11:28 AM, giacomo boffi pec...@pascolo.net wrote:

 Νίκος nikos.gr...@gmail.com writes:

  IF it can also be written in one-line

 def f(x,n,w):return(lambda y=f(x[::2],n/2,w[::2]),z=f(x[1::2],n/2,w
 [::2]):reduce(lambda x,y:x+y,zip(*[(y[k]+w[k]*z[k],y[k]-w[k]*z[k]) for k 
 in
 range(n/2)])))()if n1 else x

 I've been reading along and learning some really obscure coding
 patterns.

well, the obscure patterns aren't mine, they were contributed by some
it.comp.python regulars, to which credit is due if credit is due
(please ask google groups for the individual contributions)

 why?

to show a recreational one liner from which Νίκος could learn
something, one way or another
-- 
X  = f(x,n,[exp(-2*pi*1j*k/n) for k in range(n/2)])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling 3 operands in an expression without raising an exception

2013-09-29 Thread giacomo boffi
giacomo boffi pec...@pascolo.net writes:

 it.comp.python

oops, it.comp.LANG.python

-- 
I do desire we may be better strangers.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with python functions?

2013-09-24 Thread giacomo boffi
kjaku...@gmail.com writes:

 def temp(T, from_unit, to_unit):
 conversion_table = {('c', 'k'):lambda x: x + 273.15,
 ('c', 'f'):lambda x: (x * (9.0/5)) + 32,
 ('k', 'c'):lambda x: x - 273.15,
 ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67,
 ('f', 'c'):lambda x: (x - 32) * (5.0/9),
 ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)}
 f = conversion_table[(from_unit.lower(), to_unit.lower())]
 return f(T)

 Would this be correct?

not always:

 temp(-300.0, 'c', 'k')
-26.8500023
 


-- 
le mie sacrosante questioni di principio
  VS gli sciocchi puntigli di quel cretino del mio vicino
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-13 Thread giacomo boffi
Ana Dionísio anadionisio...@gmail.com writes:

 Hello!

 I have a CSV file with 20 rows and 12 columns and I need to store it
 as a matrix.

array=numpy.array([row for row in csv.reader(open('Cenarios.csv'))])

NB: i used array= as in your sample code, BUT
-- 
http://mail.python.org/mailman/listinfo/python-list


PMW+BLT on windows, any chance?

2012-01-30 Thread Giacomo Boffi
on my linux box i have a small python program that draws some 2-d line
graphs in a window aside a graphical interface to change the problem
data

as you may have guessed from the subject line, the gui widgets are
done with help from PMW [1], and the graps are done by the PMW -
BLT[2] interface

now i'd like to port the whole mess to windows to give it away to
unix-impaired people, but i cannot find a precompiled BLT for my
window (virtual)box

otoh, even if i find such a rare pearl, every reference i found on
google implies that BLT 2.4z works with tk8.5 while python 2.7 comes
with tk 8.5

1. is it possible to do what i wish to do?
2. is it worth?
3. if it is impossible or unworty, i'd better rewrite my program to
   use which graphics library?

tia,
gb

[1] Python Mega Widgets is a pure python implementation of complex,
expandable widgets built on tkinter, i use its input widgets
because they do data validation
[2] Blt is a library that enhances tcl/tk adding some useful stuff, in
my case i use the 2-d graph widget
-- 
We have met the enemy and he is us.
--- Pogo.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validating Entry in tkinter

2011-07-27 Thread Giacomo Boffi
Saul Spatz saul.sp...@gmail.com writes:

 In tcl/tk an Entry widget can be set to validate its contents with
 the validate option. [...]  Can one do something like this in
 tkinter?

i read the thread and nobody mentioned the python mega widget (Pmw)
toolkit, from whose docs i quote the following

Pmw.EntryField() - entry widget with validation

[...]

Validation is performed early, at each keystroke or other event
which modifies the text. However, if partially valid text is
permitted, the validity of the entered text can be checked just
before it is to be used, which is a form of late validation.

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


Re: Convert AWK regex to Python

2011-05-16 Thread Giacomo Boffi
J jnr.gonza...@googlemail.com writes:

 cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print 
 $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service command 
 status; do echo Service: $service, Command: $command, Status: $status, 
 Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep 
 $status | wc -l | awk '{ print $1 }'`  logs/pdu_log_fe_clean.log; done

 This AWK command gets lines which look like this:-

 2011-05-16 09:46:22,361 [Thread-4847133] PDU D G_CC_SMS_SERVICE_51408_656.O_ 
 CC_SMS_SERVICE_51408_656-ServerThread-VASPSessionThread-7ee35fb0-7e87-11e0-a2da-00238bce423b-TRX
  - 2011-05-16 09:46:22 - OUT - (submit_resp: (pdu: L: 53 ID: 8004 Status: 
 0 SN: 25866) 98053090-7f90-11e0-a2da-00238bce423b (opt: ) ) 

 And outputs lines like this:-

 CC_SMS_SERVICE_51408 submit_resp: 0


i see some discrepancies in the description of your problem

1. if i echo a properly quoted line like this above in the pipeline
   formed by the first three awk commands i get

$ echo $likethis | awk -F\- '{print $1,$NF}' \
 | awk -F\. '{print$1,$NF}'  \
 | awk '{print $1,$4,$5}'
2011 ) )
$ 
   not a triple 'service command status'

2. with regard to the final product, you script outputs lines like in

echo Service: $service, [...]

   and you say that it produces lines like

CC_SMS_SERVICE_51408 submit_resp: 


WHATEVER, the abnormous run time is due to the fact that for every
output line you rescan again and again the whole log file

IF i had understood what you want, imho you should run your data
through sort and uniq -c

$ awk -F\- '{print $1,$NF}'  $file \
| awk -F\. '{print$1,$NF}'  \
| awk '{print $1,$4,$5}'| sort | uniq -c | format_program

uniq -c drops repeated lines from a sorted input AND prepends to each
line the count of equal lines in the original stream

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


Re: [pyplot] using f1=figure(1)

2011-04-04 Thread Giacomo Boffi
eryksun () eryk...@gmail.com writes:

 figure(fig1.number)
 plot(...)

that's already much better than figure(1);...;figure(2);...

 Alternatively, you can use the plot methods of a particular axes:

 fig1 = figure()
 ax1 = axes()
 fig2 = figure()
 ax2 = axes()

 ax1.plot(...)
 ax2.plot(...)

that's nicer

 It works the same for subplots: [...]

thanks a lot
-- 
le mie sacrosante questioni di principio
  VS gli sciocchi puntigli di quel cretino del mio vicino
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fun python 3.2 one-liner

2011-04-04 Thread Giacomo Boffi
Chris Angelico ros...@gmail.com writes:

 def f(x,n,w): return x if n==1 else\
    (lambda x0=f(x[::2],n/2,w[::2]),\
            x1=f(x[1::2],n/2,w[::2]): reduce(lambda a,b: a+b ,\
                                      zip(*[(x0[k]+w[k]*x1[k],\
                                             x0[k]-w[k]*x1[k])\
                                             for k in range(n/2)])))()

 What sort of parameters does this take? So far all I can figure out
 is that n is an integer and x and w are sliceables, but I'm not sure
 whether x and w should be strings or arrays.

def direct_fft(x,n):
  return f(x,n,[exp(-2*pi*1j*k/n) for k in range(n/2)]) 
def inverse_fft(x,n):
  return [x/n for x in f(x,n,[exp(+2*pi*1j*k/n) for k in range(n/2)])] 
-- 
le mie sacrosante questioni di principio
  VS gli sciocchi puntigli di quel cretino del mio vicino
-- 
http://mail.python.org/mailman/listinfo/python-list


[pyplot] using f1=figure(1)

2011-03-28 Thread Giacomo Boffi
i executed the following interactions and i remained disappointed

$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type help, copyright, credits or license for more information.
 from pylab import *
 f1=figure(1)
 f2=figure(2)
 f1
matplotlib.figure.Figure object at 0xb745668c
 f2
matplotlib.figure.Figure object at 0x8df834c
 plot(sin(linspace(0,10)),figure=f1)
[matplotlib.lines.Line2D object at 0x8df8fac]
 plot(cos(linspace(0,10)),figure=f2)
[matplotlib.lines.Line2D object at 0x8df8f0c]
 show()
 

i'm surely off by one in my understanding of the plot command, as i
expected a sine in figure 1 and a cosine in 2, while what i got was a
blank figure 1 and both the sine and the cosine in figure 2

can anyone help me? tia
gb

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


Re: [pyplot] using f1=figure(1)

2011-03-28 Thread Giacomo Boffi
Blockheads Oi Oi breamore...@yahoo.co.uk writes:

 I don't know why but this works fine.
 f1=figure(1)
 plot(sin(linspace(0,10)),figure=f1)
 f2=figure(2)
 plot(cos(linspace(0,10)),figure=f2)
 show()

it works as well (with a proper t...)

plot(sin(t);figure(2);plot(cos(t));show()

because that's the way it is advised to do

in help(plot) one can read that in the named  arguments that are
accepted from plot, you can say also figure=figurehandle, but it is
evident that i misundertood the issue

 You're also likely to get more answers if you ask on the mailing list
 here https://lists.sourceforge.net/lists/listinfo/matplotlib-users.

another mailing list?  really i have to? smilies, lots of

-- 
Fan culo a quelli che quando si svegliano la mattina, non importa se
sono leoni o gazzelle, sono comunque delle bestie. -- Zonker, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems of Symbol Congestion in Computer Languages

2011-02-18 Thread Giacomo Boffi
Chris Jones cjns1...@gmail.com writes:

 [...] most any software of note appears to have come out of cultures
 where English is either the native language, or where the native
 language is either relatively close to English...

i do acknowledge your most, but how do you spell Moon in Portuguese?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems of Symbol Congestion in Computer Languages

2011-02-18 Thread Giacomo Boffi
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:

 A dedicated concatenation operator would have avoided that mess.

 I don't quite agree that the mess is as large as you make out, but yes, 
 more operators would be useful.

am i wrong, or | is still available?
-- 
l'amore e' un sentimento a senso unico. a volte una via comincia dove
finisce un'altra e viceversa   -- Caldana, in IFQ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should there be a 'core' python install?

2011-01-20 Thread Giacomo Boffi
Martin P. Hellwig martin.hell...@dcuktec.org writes:

 Yep when I started looking much more at other toolkits, I started to
 like Tkinter more and more. Maybe its simplicity,

maybe the good design of Tk, 
-- 
BOMBED BY AIRCRAFT. SINKING. U-824.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using property() to extend Tkinter classes but Tkinter classes are old-style classes?

2010-11-30 Thread Giacomo Boffi
Terry Reedy tjre...@udel.edu writes:

 On 11/28/2010 3:47 PM, pyt...@bdurham.com wrote:
 I had planned on subclassing Tkinter.Toplevel() using property() to wrap
 access to properties like a window's title.
 After much head scratching and a peek at the Tkinter.py source, I
 realized that all Tkinter classes are old-style classes (even under
 Python 2.7).
 1. Is there a technical reason why Tkinter classes are still old-style
 classes?

 To not break old code. Being able to break code by upgrading all
 classes in the stdlib was one of the reasons for 3.x.

In 3.x, are Tkinter classes still derived by old-style classes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: elementwise multiplication of 2 lists of numbers

2010-09-20 Thread Giacomo Boffi
harryos oswald.ha...@gmail.com writes:

 hi
 I have 2 lists of numbers,say
 x=[2,4,3,1]
 y=[5,9,10,6]
 I need to create another list containing
 z=[2*5, 4*9, 3*10, 1*6]  ie =[10,36,30,6]

 I did not want to use numpy or any Array types.I tried to implement
 this in python .I tried the following

 z=[]
 for a,b in zip(x,y):
 z.append(a*b)
 This gives me the correct result.Still,Is this the correct way?
 Or can this be done in a better way?

what you've done is correct, rather than in better ways this can be
done in different ways

first, there is list comprehension
 [x*y for x,y in zip([2,4,3,1],[5,9,10,6])]
[10, 36, 30, 6]
 

if you feel that zip looks like an artifact, python has some
functional bit
 map(lambda x,y: x*y, [2,4,3,1],[5,9,10,6])
[10, 36, 30, 6]
 

if you feel that lambda looks like an artifact,
 from operator import mul
 map(mul, [2,4,3,1],[5,9,10,6])
[10, 36, 30, 6]
 

hth,
-- 
 In tutti noi c'è un lato interista 
Lato perlopiù nascosto dalle mutande. 
--- Basil Fawlty, a reti unificate (IFQ+ISC)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Arguments from the command line

2010-09-13 Thread Giacomo Boffi
Dennis Lee Bieber wlfr...@ix.netcom.com writes:

 On Fri, 10 Sep 2010 12:25:17 +0200, Giacomo Boffi
 giacomo.bo...@polimi.it declaimed the following in
 gmane.comp.python.general:

 Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes:
 
  In message 8662yfklzu@aiuole.stru.polimi.it, Giacomo Boffi wrote:
 
  Dennis Lee Bieber wlfr...@ix.netcom.com writes:
  
  FORTRAN just differentiates by having the main file start with
  PROGRAM random_name
  whereas subfiles are all either (or both)
  SUBROUTINE another_name(args)
  FUNCTION that_other_name(args)
  
  no BLOCKDATA?
 
  I think you mean COMMON.
 
 i meant BLOCKDATA

   It exists but I've only seen it used once... And I don't recall it
 being executable in the same way as program/function/subroutine.

i simply meant that the BLOCKDATA statement can begin a subfile as
well as SUBROUTINE or FUNCTION
-- 
Sarò un'ingenua ma continuo a pensarla come prima, anche se
probabilmente i fatti mi smentiscono.  -- Francy, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Python works: What do you know about support for negative indices?

2010-09-10 Thread Giacomo Boffi
Ben Finney ben+pyt...@benfinney.id.au writes:

 Raymond Hettinger pyt...@rcn.com writes:

 It doesn't seem to be common knowledge when and how a[x] gets
 translated to a[x+len(x)].  So, here's a short info post on how Python
 supports negative indices for sequences.

 Thanks for this. Could you post your messages using a channel that
 doesn't arbitrarily split your paragraphs into long-short-long-short
 lines?

hi Ben, i see that you uses gnus... well, it's gnus that does the
unwanted formatting

try C-u g, as dettailed below, ciao

g runs `gnus-summary-show-article'

`gnus-summary-show-article' is an interactive compiled Lisp function
  -- loaded from gnus-sum
(gnus-summary-show-article optional ARG)

Documentation:
Force redisplaying of the current article.
If ARG (the prefix) is a number, show the article with the charset
defined in `gnus-summary-show-article-charset-alist', or the charset
input.
If ARG (the prefix) is non-nil and not a number, show the raw article
without any article massaging functions being run.  Normally, the key
strokes are `C-u g'.
-- 
la lenza penzola
   -- PMF, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Arguments from the command line

2010-09-10 Thread Giacomo Boffi
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes:

 In message 8662yfklzu@aiuole.stru.polimi.it, Giacomo Boffi wrote:

 Dennis Lee Bieber wlfr...@ix.netcom.com writes:
 
 FORTRAN just differentiates by having the main file start with
 PROGRAM random_name
 whereas subfiles are all either (or both)
 SUBROUTINE another_name(args)
 FUNCTION that_other_name(args)
 
 no BLOCKDATA?

 I think you mean COMMON.

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


Re: [Tutor] Arguments from the command line

2010-09-09 Thread Giacomo Boffi
Dennis Lee Bieber wlfr...@ix.netcom.com writes:

   FORTRAN just differentiates by having the main file start with
   PROGRAM random_name
 whereas subfiles are all either (or both)
   SUBROUTINE another_name(args)
   FUNCTION that_other_name(args)

no BLOCKDATA?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGeo

2010-08-31 Thread Giacomo Boffi
L lamlb...@optusnet.com.au writes:

 also the PyGeo readme text mentions Numerical python (I think it
 means Numeric, but I also have NumPy installed)

afaict, Numerical python is numpy --- if you look at pygeo home page,
the reference to Numerical python is a link to numpy home page

on the contrary, there is no import numpy in all the sources of
pygeo, and a couples or so of import Numeric, so that the situation
is unclear

aiuole/../PyGeo-1.0a1 $ find build| grep py$ | xargs grep -n import'.*'numpy
aiuole/../PyGeo-1.0a1 $ find build| grep py$ | xargs grep -n import'.*'Numeric
build/lib.linux-i686-2.6/pygeo/base/pygeomath.py:1:import Numeric as N
build/lib.linux-i686-2.6/pygeo/base/wiresphere.py:2:import Numeric
aiuole/../PyGeo-1.0a1 $ 

to complicate matters, it is not possible to install python-numeric
using the apt system on debian unstable

i don't know if it is possible to build numeric against the default
python (2.6) on my system, further i don't know if it is worthwhile
because, at a first sight, it looks like pygeo does not use advanced
features of numeric, and replacing numeric with numpy should be very
easy

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


Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-17 Thread Giacomo Boffi
Paul Rubin no.em...@nospam.invalid writes:

 Baba raoul...@gmail.com writes:
 exercise: given that packs of McNuggets can only be bought in 6, 9 or
 20 packs, write an exhaustive search to find the largest number of
 McNuggets that cannot be bought in exact quantity.

 Is that a homework problem?

yes, and no

it was a homework problem, assigned in 2008, as clearly stated by the OP

most of what was discussed on the ng was clearly stated in the
introduction to the actual problem, so that we can thank Baba for NOT
having read the text of the assignment, leavin' us a couple of days of
amusing and interesting posts
-- 
Mangiate pure le vostre carote, noi mangeremo le nostre salsicce!
   -- Claud,   in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-16 Thread Giacomo Boffi
Baba raoul...@gmail.com writes:

 Hi Mel,

 indeed i thought of generalising the theorem as follows:
 If it is possible to buy n, n+1,~, n+(x-1) sets of McNuggets, for some
 x, then it is possible to buy any number of McNuggets = x, given that
 McNuggets come in x, y and z packs.

 so with diophantine_nuggets(7,10,21) i would need 7 passes
 result:53

 but with (10,20,30) and 10 passes i get no result

you need at least an odd number in your set, because summing even
numbers only you'll never get an odd result
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Win7. Why Don't Matplotlib, ... Show up in Control Panel Add-Remove?

2010-08-11 Thread Giacomo Boffi
Martin v. Loewis mar...@v.loewis.de writes:

 If you use the bdist_wininst, bdist_msi, or bdist_rpm distutils
 commands, you get packages which support uninstallations very well.

bdist_deb?
-- 
Vorrei andare a lavorare in Sicilia, a max 15 km dal mare. Con chi 
devo parlare? Col capomafia distrettuale? Oppure bisogna sporcarsi le 
mani e fare la tessera di FI?  -- Marvin,  in IFQ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python -- floating point arithmetic

2010-07-08 Thread Giacomo Boffi
Zooko O'Whielacronx zo...@zooko.com writes:

 I'm starting to think that one should use Decimals by default and
 reserve floats for special cases.

would you kindly lend me your Decimals ruler? i need to measure the
sides of the triangle whose area i have to compute
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting in batch with no display

2010-06-08 Thread Giacomo Boffi
Hans Georg Schaathun h.schaat...@surrey.ac.uk writes:

 :  import matplotlib
 :  matplotlib.use('agg')
 :  import pylab
 :  pylab.plot([1, 3, 5])
 :  fig = file('foo.png', 'wb')
 :  pylab.savefig(fig, format='png')
 :  fig.close()

 Raster graphics is not good enough

#ig = file('foo.png', 'wb'
pylab.savefig('foo.png', format='pdf')

that's all
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting in batch with no display

2010-06-08 Thread Giacomo Boffi
Giacomo Boffi giacomo.bo...@polimi.it writes:

 Hans Georg Schaathun h.schaat...@surrey.ac.uk writes:

 :  import matplotlib
 :  matplotlib.use('agg')
 :  import pylab
 :  pylab.plot([1, 3, 5])
 :  fig = file('foo.png', 'wb')
 :  pylab.savefig(fig, format='png')
 :  fig.close()

 Raster graphics is not good enough

 #ig = file('foo.png', 'wb'
 pylab.savefig('foo.png', format='pdf')

 that's all

either

matplotlib.use('cairo.pdf')
...
pylab.savefig('foo.pdf')

-- 
le mie sacrosante questioni di principio
  VS gli sciocchi puntigli di quel cretino del mio vicino
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: if, continuation and indentation

2010-06-04 Thread Giacomo Boffi
HH henri...@gmail.com writes:

   if (width == 0 and
   height == 0 and
   color == 'red' and
   emphasis == 'strong' or
   highlight  100):
   raise ValueError(sorry, you lose)

 
if (width == 0 and
height == 0 and
color == 'red' and
emphasis == 'strong' or
highlight  100):

raise ValueError(sorry, you lose)

-- 
compro mobili vecchi - vendo mobili antichi
-- 
http://mail.python.org/mailman/listinfo/python-list


[pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Giacomo Boffi
i have this code

def example(a):
return lambda b: a+b+1

fun = example(10)
k_1 = fun(7)
...

and pylint tells me

[...]
C:  4: Invalid name fun (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C:  5: Invalid name k_1 (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
[...]

afaict, [A-Z_][A-Z0-9_]* identifiers should be used for constants, and
i don't think of fun or k_1 as constants... what's going on?

tia,
g
-- 
la lenza penzola
   -- PMF, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Giacomo Boffi
Jean-Michel Pichavant jeanmic...@sequans.com writes:

 Giacomo Boffi wrote:
 i have this code

 def example(a):
 return lambda b: a+b+1

 fun = example(10)
 k_1 = fun(7)
 ...

 and pylint tells me

 [...]
 C:  4: Invalid name fun (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
 C:  5: Invalid name k_1 (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
 [...]
 g

 Pylint default rules need some tuning

ok, but maybe it's not my specific problem (see below)

 However, given you example, you should not insert code execution at
 you module level, unless it's required only at the module import. I
 dont know what is your module

module? this was not well specified in my OP, but i'd rather speak of
a script instead of a module...

maybe should i use the

if __name__ == __main__:
main()

idiom to keep happy my pylint? oh, let's do it... it should be easy
isn't it?

thanks,
g
-- 
 I wish we'd come to our senses and see there is no truth
 In those who promote the confusion for this ever changing mood.
(people get ready people get ready people get ready people get ready)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Giacomo Boffi
Giacomo Boffi giacomo.bo...@polimi.it writes:

 However, given you example, you should not insert code execution at
 you module level, unless it's required only at the module import. I
 dont know what is your module

 module? this was not well specified in my OP, but i'd rather speak of
 a script instead of a module...

 maybe should i use the

 if __name__ == __main__:
 main()

 idiom to keep happy my pylint? oh, let's do it... it should be easy
 isn't it?

well, it's not so easy... pylint complains (correctly) about too many
local variables in main(), and about other things for different
adjustments i tried

i think i will put some variable at top level, CAPITALIZED, with the
intention of making evident that those values are the data of the
problem, as well as other quantities that are computed once from base
data, and then use these capitalized global variables inside my main
function --- tonight, at home

thank you again,
g
-- 
l'amore e' un sentimento a senso unico. a volte una via comincia dove
finisce un'altra e viceversa   -- Caldana, in IFQ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating a rainbow?

2010-04-13 Thread Giacomo Boffi
Tobiah t...@rcsreg.com writes:

 I'm having a difficult time with this.  I want
 to display a continuous range of hues using HTML
 hex representation (#RRGGBB).  How would I go 
 about scanning through the hues in order to
 make a rainbow?

if you mean real rainbows when you say rainbow, as rainbows go from
low to high wavelengths and you have to specify colors to your display
in RGB, i think that you have to read, e.g.,

http://www.physics.sfasu.edu/astro/color.html

otoh if you mean simply a continuos palette with varying hues,
excellent answers were already posted

hth
g
-- 
compro mobili vecchi - vendo mobili antichi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python as pen and paper substitute

2010-04-09 Thread Giacomo Boffi
Manuel Graune manuel.gra...@koeln.de writes:

 Giacomo Boffi giacomo.bo...@polimi.it writes:

 Manuel Graune manuel.gra...@koeln.de writes:

 Hello everyone,

 I am looking for ways to use a python file as a substitute for simple
 pen and paper calculations.

 search(embedded calc mode) if manuel in emacs_fellows_set or sys.exit(1)

 Well, the subject does say python

and so i answered in python...

seriously, embedded calc mode is not mathematica's notebooks but is
usable for doing live maths in a text buffer

 I'm a vim-user anyways.

sorry... otoh, vim is scriptable in python.  i know less than nothing
on this subject but i'd be surprised if something akin to your request
were not available

 *duckandrun*

tanto ti ripiglio
g
-- 
non ho capito un apascio   -- pp, tra se e se 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recommend Commercial graphing library

2010-04-08 Thread Giacomo Boffi
Grant Edwards inva...@invalid.invalid writes:

 If it's 2D data, you don't need to use a 3D graph.

if it's tabular data, you don't need an uber-histogram
-- 
giampippetto, coso, come si chiama? ah si` MMAX ha scritto:
 Tra il trascendente e l'interpretazione prevalente del dato come
 assioma ne passa...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python as pen and paper substitute

2010-04-08 Thread Giacomo Boffi
Manuel Graune manuel.gra...@koeln.de writes:

 Hello everyone,

 I am looking for ways to use a python file as a substitute for simple
 pen and paper calculations.

search(embedded calc mode) if manuel in emacs_fellows_set or sys.exit(1)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a pure Python chart drawing module

2009-09-18 Thread Giacomo Boffi
Piet van Oostrum p...@cs.uu.nl writes:

 Chris Withers ch...@simplistix.co.uk (CW) wrote:

CW John Nagle wrote:
 That's a wrapper for Antigrain (http://www.antigrain.com/;),
 which is a C++ library.  I'm trying hard to avoid dependencies on
 binary libraries with limited support.  Builds exist only for
 Python 2.4 and 2.5.

CW Huh?

CW Matplotlib is a pretty phenomenal charting library, I use it
CW routinely on both windows and linux, I've never had any
CW compilation problems on Linux and never even needed to compile
CW it on Windows.

CW Writing if off as just a wrapper for antigrain is pretty
CW insulting...

 *You* made up the just in that quote. The point was that the OP
 wants something that only needs Python.

matplotlib can be used to generate .ps, .pdf and .svg files (all
vectorial formats) without resorting to Antigrain

Antigrain is used only in rasterizing, due to its better capabilities
in the field of antialiasing, when you use matplotlib with an
interactive backend; of course, if you're truly dispising Antigrain
and are happy with a coarser display you can select interactive
backends that DO NOT use Antigrain

that's for the Antigrain wrapper

otoh, if the OP intended a plotting library that does not use binary
modules at all (then his reference to Antigrain was mostly fogging),
then matplotlib is not for him

% find matplotlib-0.99.0/| grep -v agg24 | grep '\.cpp$' | wc -l
23
% find matplotlib-0.99.0/| grep -v agg24 | grep '\.c$' | wc -l
5
% 

-- 
 I wish we'd come to our senses and see there is no truth
 In those who promote the confusion for this ever changing mood.
(people get ready people get ready people get ready people get ready)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a pure Python chart drawing module

2009-09-17 Thread Giacomo Boffi
Vlastimil Brom vlastimil.b...@gmail.com writes:

 As for BLT, there is Pmw.Blt, the original is written in Tcl.

doesn't work (dumps core) on debian linux
bug #525860: python-pmw triggers segmentation fault in blt

not that blt itself is really OK
bug #524149: blt: zooming in a graph produces segmentation fault
-- 
Io ti saluto diventa equivalente ad io saluto te   -- gobbacci, in ISC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a pure Python chart drawing module

2009-09-17 Thread Giacomo Boffi
John Nagle na...@animats.com writes:

 gerlos wrote:
 John Nagle ha scritto:

 I'm looking for something that can draw simple bar and pie charts
 in Python.  I'm trying to find a Python package, not a wrapper for
 some C library, as this has to run on both Windows and Linux
 and version clashes are a problem.

 Did you look at matplotlib? In their examples page there are some
 charts like the ones you asked for. I guess it could work for you,
 and it seems to work flawlessy in MS Windows as in gnu/linux.

That's a wrapper for Antigrain (http://www.antigrain.com/;), which is
 a C++ library.

come on, you can configure matplotlib to use one of too many different
backends

from http://matplotlib.sourceforge.net/users/customizing.html

 CONFIGURATION BEGINS HERE

# the default backend; one of GTK GTKAgg GTKCairo CocoaAgg FltkAgg
# MacOSX QtAgg Qt4Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG Template
# You can also deploy your own backend outside of matplotlib by
# referring to the module name (which must be in the PYTHONPATH) as
# 'module://my_backend'
backend  : GTKAgg

-- 
Yes you who must leave everything that you cannot control.
It begins with your family, but soon it comes around to your soul.
Well I've been where you're hanging, I think I can see how you're pinned:
When you're not feeling holy, your loneliness says that you've sinned.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with cumulative sum

2009-09-11 Thread Giacomo Boffi
Maggie la.f...@gmail.com writes:

 [...]
 else:
print 'The loop is finito'

do you know of it.comp.lang.python?

-- 
Sarebbe essere un atto di pieta'. 
Contro i miei principi.-- whip,  in IFMdI
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tkinter] messed callbacks

2009-09-10 Thread Giacomo Boffi
Scott David Daniels scott.dani...@acm.org writes:

 Giacomo Boffi wrote:
 Giacomo Boffi giacomo.bo...@polimi.it writes:
 ...
 | def create_cb(a,b):
 | return lambda: output(a+'-'+b)
 | | def doit(fr,lst):
 |   for c1,c2 in zip(lst[::2], lst[1::2]):
 | subframe=Frame(fr)
 | Label(subframe,text=c1+' - 
 '+c2).pack(side='left',expand=1,fill='both')
 | Button(subframe,text='',command=create_cb(c1,c2)).pack()
 | Button(subframe,text='',command=create_cb(c2,c1)).pack()
 | subframe.pack(fill='x',expand=1)
 ...
 works ok, now i have to fully understand my previous error

 This is really why functools.partial exists.

i take due note, tx

 Also note from Pep 8, spaces are cheap and make the code easier to
 read.

space-crunch was just for posting on usenet, 80 cols terminals etc.

grazie,
   g
-- 
Sarò un'ingenua ma continuo a pensarla come prima, anche se
probabilmente i fatti mi smentiscono.  -- Francy, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tkinter] messed callbacks

2009-09-10 Thread Giacomo Boffi
John Posner jjpos...@optimum.net writes:

 def output(x,y,op):
  if op == :
print x, ---, y
  elif op == :
print x, ---, y
  else:
print Operation argument error!

uh, nice!, i'll adapt this to my real problem

thank you John,
g
-- 
anch'io la penso come me, ma -- SteO153, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tkinter] messed callbacks

2009-09-10 Thread Giacomo Boffi
Terry Reedy tjre...@udel.edu writes:

 Reedy's Lambda Rule: [detailed explanation omitted]

i'm beginning to _understand_ what's going on with my code

 Terry Jan Reedy

thanks, grazie 1000 Terry,
 g
-- 
Lord, what fools these mortals be!
-- 
http://mail.python.org/mailman/listinfo/python-list


[Tkinter] messed callbacks

2009-09-09 Thread Giacomo Boffi
i have this test program (that i already posted on it.comp.lang.python)

[ test.py ]
from Tkinter import *

def output(s):
  print s

def doit(fr,lst):
  for c1,c2 in zip(lst[::2], lst[1::2]):
subframe=Frame(fr)
Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both')
Button(subframe,text='',command=lambda: output(c1+'-'+c2)).pack()
Button(subframe,text='',command=lambda: output(c2+'-'+c1)).pack()
subframe.pack(fill='x',expand=1)

root=Tk()
fr=Frame(root,relief='raised',borderwidth=5).pack(fill='both',expand=1)
doit(fr,['pippo','pluto','paperino','zio_paperone'])
Button(root,text='Q',command=root.destroy).pack(expand=1,fill='x')
root.mainloop()


when i execute it from the command line, click on the 4 buttons from
top to bottom and quit (you can do the same), this is what i get

aiuole: python test.py 
gray-black
black-gray
gray-black
black-gray
aiuole: 

as you see, the button 0 and 1 have callbacks different from my
expectations, as my script was intended to give

cyan-blue
blue-cyan
gray-black
black-gray

why the messed callbacks? what's the right thing to do?

tia, 
g
-- 
l'amore e' un sentimento a senso unico. a volte una via comincia dove
finisce un'altra e viceversa   -- Caldana, in IFQ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tkinter] messed callbacks

2009-09-09 Thread Giacomo Boffi
Diez B. Roggisch de...@nospam.web.de writes:

 Giacomo Boffi wrote:

 def doit(fr,lst):
   for c1,c2 in zip(lst[::2], lst[1::2]):
 subframe=Frame(fr)
 Label(subframe,text=c1+' -
 '+c2).pack(side='left',expand=1,fill='both')
 Button(subframe,text='',command=lambda: output(c1+'-'+c2)).pack()
 Button(subframe,text='',command=lambda: output(c2+'-'+c1)).pack()
 subframe.pack(fill='x',expand=1)
 
 why the messed callbacks? what's the right thing to do?

 Closures in python contain names, not the objects they refer to. So
 when you rebind that name (as you do above in your loop),

sorry, i'm not conscient of rebinding a name... what do you mean by
rebind that name exactly?

 the created callbacks will only refer to the last bound value of a
 name.
 
 Create new closures, or bind arguments as defaults:

 funcs = []

 def create_func(i):
 return lambda: i

 for i in xrange(10):
 funcs.append(lambda i=i: i)
 funcs.append(create_func(i))

 for f in funcs:
 print f()

i tried to understand, and maybe i have understood a thing or two...

funcs = []

def create_func(i):
return lambda: i

for i in xrange(10):
funcs.append(lambda i=i: i)
funcs.append(create_func(i))
funcs.append(lambda: i)# this is my addition

for f in funcs:
print f()

ok, i'll try again following your advice

thank you very much
g
-- 
It will be rain tonight.
Let it come down.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tkinter] messed callbacks

2009-09-09 Thread Giacomo Boffi
Giacomo Boffi giacomo.bo...@polimi.it writes:

 ok, i'll try again following your advice

,[ test.py ]
| from Tkinter import *
| 
| def output(s):
|   print s
| 
| def create_cb(a,b):
| return lambda: output(a+'-'+b)
| 
| def doit(fr,lst):
|   for c1,c2 in zip(lst[::2], lst[1::2]):
| subframe=Frame(fr)
| Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both')
| Button(subframe,text='',command=create_cb(c1,c2)).pack()
| Button(subframe,text='',command=create_cb(c2,c1)).pack()
| subframe.pack(fill='x',expand=1)
| 
| root=Tk()
| doit(root,['cyan','blue','gray','black'])
| Button(root,text='Q',command=root.destroy).pack(expand=1,fill='x')
| root.mainloop()
`

works ok, now i have to fully understand my previous error

again, thanks you very much
g
-- 
Yes you who must leave everything that you cannot control.
It begins with your family, but soon it comes around to your soul.
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter+matplotlib

2006-03-27 Thread Giacomo Boffi
i have coded some progs that use the Pmw.Blt.Graph widgets, embedded
in a simple Tkinter GUI

,
| from Tkinter import *
| import Pmw
| ...
| frame=Frame(root)
| ...
| graph=Pmw.Blt.Graph(frame,...)
| graph.line_create(...)
| graph.pack(...)
`

now i'd like to port those progs to an environment where i have no BLT

assuming that i can use matplotlib to draw the line graphs i need, how
do i place the graph widget inside my tkinter GUI?

tia,
gb
-- 
  If you grow tired of the friends you make
   Never ever turn the back on them
Say they were the best of time you ever had
The best of times with the thougthless kind-- John Cale
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Pmw] reusing a graph after deleting a curve

2005-03-16 Thread giacomo boffi
giacomo boffi [EMAIL PROTECTED] writes:

 my question: is it possible to erase a graph, and reuse it?

 like in

 # x - compute - y
 g=Pmw.Blt.Graph(); g.pack()
 g.line_create(name,x,y)
 # other computing - a better y
 # do something to g, erasing the previous plot
 #[the above is the part that i cannot understand...]
 g.line_create(name,x,y)


ok, i've got it:

  g.element_configure(name,ydata=a_better_y)

if a Pmw.Blt hacker is listening, i cannot understand why on earth
it's named element_configure, and not line_configure (yes, lines and
bars are both elements, but...)

-- 
vabbuò parliamo d'altro-- Agnosco, in IFQ
-- 
http://mail.python.org/mailman/listinfo/python-list


[Pmw] reusing a graph after deleting a curve

2005-03-10 Thread giacomo boffi

my question: is it possible to erase a graph, and reuse it?

like in

# x - compute - y
g=Pmw.Blt.Graph(); g.pack()
g.line_create(name,x,y)
# other computing - a better y
# do something to g, erasing the previous plot
#[the above is the part that i cannot understand...]
g.line_create(name,x,y)

-- 
Lovercraft, bestia.-- Whip,in IFQ
-- 
http://mail.python.org/mailman/listinfo/python-list