Re: How to convert bytearray into integer?

2010-08-16 Thread Mark Dickinson
On Aug 16, 8:08 pm, Jacky wrote: > Hi Thomas, > > Thanks for your comments!  Please check mine inline. > > On Aug 17, 1:50 am, Thomas Jollans wrote: > > > On Monday 16 August 2010, it occurred to Jacky to exclaim: > > > > Hi there, > > > > Recently I'm facing a problem to convert 4 bytes on an by

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

2010-08-16 Thread Mel
Baba wrote: [ ... ] > Now, i believe that the number of consecutive passes required to make > this work is equal to the smallest number of pack sizes. So if we have > packs of (9,12,21) the number of passes needed would be 9 and the > theorem would read > > "If it is possible to buy n,n+1,n+2,...n

Re: How to convert bytearray into integer?

2010-08-16 Thread Mark Dickinson
On Aug 16, 8:36 pm, Mark Dickinson wrote: > On Aug 16, 8:08 pm, Jacky wrote: > > My concern is that struct may need to parse the format string, > > construct the list, and de-reference index=0 for this generated list > > to get the int out. > > > There should be some way more efficient? > > Well,

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

2010-08-16 Thread Giacomo Boffi
Baba 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_nugge

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

2010-08-16 Thread Baba
well i still believe that the key is the smallest sized pack and there's no need to go into higher mathematics to solve this problem. I think below code works within the limits of the exercise which states to look at a maximum range of 200 in order not to search forever. packages=[2,103,105] min_s

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

2010-08-16 Thread John Posner
On 8/16/2010 4:18 PM, Baba wrote: packages=[2,103,105] min_size=min(packages[0],packages[1],packages[2]) or: min_size = min(packages) -John -- http://mail.python.org/mailman/listinfo/python-list

Re: question about pdb assignment statements

2010-08-16 Thread Kev Dwyer
On Mon, 16 Aug 2010 08:17:20 -0700, Steve Ferg wrote: > In this little script: > > > import pdb > pdb.set_trace() > def main(): > xm = 123 > print("Hello,world!") > main() > > > When I run this, I use pdb to step through it until I reach the point in > main() where the xm varia

Re: Python -Vs- Ruby: A regexp match to the death!

2010-08-16 Thread rantingrick
On Aug 9, 8:19 am, Mike Kent wrote: > On Aug 8, 8:43 pm, rantingrick wrote: > Xah, this is really you, isn't it.  Come on, confess. *MOI*, How could *I* be xah. I really don't like Ruby however he gushes over it all the time. And he does not like Python that much either. We are total opposites,

Re: question about pdb assignment statements

2010-08-16 Thread Kev Dwyer
On Mon, 16 Aug 2010 08:17:20 -0700, Steve Ferg wrote: > In this little script: > > > import pdb > pdb.set_trace() > def main(): > xm = 123 > print("Hello,world!") > main() > > > When I run this, I use pdb to step through it until I reach the point in > main() where the xm varia

Re: Python -Vs- Ruby: A regexp match to the death!

2010-08-16 Thread rantingrick
On Aug 8, 8:15 pm, Steven D'Aprano wrote: > On Sun, 08 Aug 2010 17:43:03 -0700, rantingrick wrote: > > Ruby has what they > > call a "Here Doc". Besides picking the most boneheaded name for such an > > object > > It's standard terminology that has been around for a long time in many > different l

Re: Python 2.7 re.IGNORECASE broken in re.sub?

2010-08-16 Thread Steven D'Aprano
On Mon, 16 Aug 2010 05:46:17 -0700, Alex Willmer wrote: > On Aug 16, 12:23 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 15 Aug 2010 17:36:07 -0700, Alex Willmer wrote: >> > On Aug 16, 1:07 am, Steven D'Aprano > > cybersource.com.au> wrote: >> >> You're passing re.IGNORECASE (which ha

Re: execfile() and locals()

2010-08-16 Thread fons
On Sun, Aug 15, 2010 at 11:24:25PM +, Steven D'Aprano wrote: > On Sun, 15 Aug 2010 23:21:51 +0200, fons wrote: > > > The documentation on execfile() and locals() makes it clear that code > > executed from execfile() can not modify local variables in the function > > from wich execfile() was c

Re: Simple Problem but tough for me if i want it in linear time

2010-08-16 Thread Steven D'Aprano
On Mon, 16 Aug 2010 20:40:52 +0200, Frederic Rentsch wrote: > How about > [obj for obj in dataList if obj.number == 100] > > That should create a list of all objects whose .number is 100. No need > to cycle through a loop. What do you think the list comprehension does, if not cycle throug

Re: [Q] How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

2010-08-16 Thread Lawrence D'Oliveiro
In message <5fa7b287-0199-4349-ae0d-c34c8461c...@5g2000yqz.googlegroups.com>, Standish P wrote: > We envisage an exogenous stack which has malloc() associated > with a push and free() associated with a pop. Since when are malloc(3) and free(3) exogenous? -- http://mail.python.org/mailman/listin

Running pygtk app under windows.

2010-08-16 Thread Sebastian Alonso
Hey everyone, I'm trying to be able to run my app, which uses pygtk, under windows, but unfortunately I'm having big problems with it. The main purpose of this is to later on make an .exe file but i havent even been able to run the app at least. I've followed every single step from this faq

Re: Textvariable display in label (GUI design)

2010-08-16 Thread Jah_Alarm
On Aug 17, 3:32 am, Eric Brunel wrote: > In article > <993d9560-564d-47f0-b2db-6f0c6404a...@g6g2000pro.googlegroups.com>, > >  Jah_Alarm wrote: > > hi, > > > pls help me out with the following issue: I wrote a function that uses > > a for loop that changes a value of a certain variable each itera

Re: EOFError with fileinput

2010-08-16 Thread Steven D'Aprano
On Mon, 16 Aug 2010 19:27:32 +0200, Alex van der Spek wrote: > Here is an excerpt. It works because the end condition is a fixed number > (ln==10255), the approximate number of data lines in a file. If I > replace that condition by EOFError, the program does not do the intended > work. It appears

random number generation

2010-08-16 Thread Jah_Alarm
hi, I need to generate a binary array with a specified average proportion of 1s (e.g. [1 0 0 0 0 1 0 0] has this proportion = 25%). In Matlab I run something like random(m,n)http://mail.python.org/mailman/listinfo/python-list

Re: random number generation

2010-08-16 Thread Brian Blais
On Aug 16, 2010, at 20:37 , Jah_Alarm wrote: hi, I need to generate a binary array with a specified average proportion of 1s (e.g. [1 0 0 0 0 1 0 0] has this proportion = 25%). In Matlab I run something like random(m,n) if you're coming from matlab, then you should use the numpy package (an

Re: How to convert bytearray into integer?

2010-08-16 Thread Jacky
Hi Mark, Thanks for your reply. Agree and I'll use your suggestions. Thanks! -Jacky On Aug 17, 3:36 am, Mark Dickinson wrote: > On Aug 16, 8:08 pm, Jacky wrote: > > > Hi Thomas, > > > Thanks for your comments!  Please check mine inline. > > > On Aug 17, 1:50 am, Thomas Jollans wrote: > > >

Re: How to convert bytearray into integer?

2010-08-16 Thread Jacky
On Aug 17, 3:38 am, Thomas Jollans wrote: > On Monday 16 August 2010, it occurred to Jacky to exclaim: > > > > > > > Hi Thomas, > > > Thanks for your comments!  Please check mine inline. > > > On Aug 17, 1:50 am, Thomas Jollans wrote: > > > On Monday 16 August 2010, it occurred to Jacky to exclai

Re: Python "why" questions

2010-08-16 Thread Roy Smith
In article , Martin Gregorie wrote: > Say you have intensity data captured from an X-ray goniometer from 160 > degrees to 30 degrees at 0.01 degree resolution. Which is most evil of > the following? > > 1) real intensity[16000:3000] >for i from lwb intensity to upb intensity > plot(

Re: How to convert bytearray into integer?

2010-08-16 Thread Jacky
On Aug 17, 3:53 am, Mark Dickinson wrote: > On Aug 16, 8:36 pm, Mark Dickinson wrote: > > > > > > > On Aug 16, 8:08 pm, Jacky wrote: > > > My concern is that struct may need to parse the format string, > > > construct the list, and de-reference index=0 for this generated list > > > to get the in

Re: random number generation

2010-08-16 Thread Raymond Hettinger
On Aug 16, 5:37 pm, Jah_Alarm wrote: > hi, > > I need to generate a binary array with a specified average proportion > of 1s (e.g. [1 0 0 0 > > 0 1 0 0] has this proportion = 25%). In Matlab I run something like > random(m,n) > between 0 and 1. I'm trying to use random.randint(0,2,size=[m,n]), but

2 Regex Questions

2010-08-16 Thread AlphaBravo
Hello Comp.Lang,Python, 1) How do I parse Basic Posix RE's in Python (i need it because of some old scripts and a specific OS developed in Seattle) 2) How can I split a string into sections that MATCH a regex (rather then splitting by seperator). Tokenizer-style but ignoring every place from wh

Re: EXOR or symmetric difference for the Counter class

2010-08-16 Thread Raymond Hettinger
[Paddy] > Lets say you have two *sets* of integers representing two near-copies > of some system, then a measure of their difference could be calculated > as: > > len(X.symmetric_difference(Y)) / (len(X) + len(Y)) * 100 % > > If the two collections of integers are allowed duplicates then you > need

Re: how to switch image in tkinter? making it mutable? how?

2010-08-16 Thread ChrisChia
On Aug 17, 2:57 am, Jeff Hobbs wrote: > On Aug 16, 7:30 am, ChrisChia wrote: > > > I have this: > > image1 = ImageTk.PhotoImage(file = "c:\\f1.jpg") > > image2 = ImageTk.PhotoImage(file = "c:\\f2.jpg") > > > imagelist.append(image1) > > imagelist.append(image2) > > > self.label  = tk.Label(image

Re: Python "why" questions

2010-08-16 Thread Lawrence D'Oliveiro
In message , Roy Smith wrote: > 5) real intensity[160.0 : 30.0 : 0.01] How many elements in that array? a) 2999 b) 3000 c) neither of the above -- http://mail.python.org/mailman/listinfo/python-list

Re: Python "why" questions

2010-08-16 Thread Roy Smith
In article , Lawrence D'Oliveiro wrote: > In message , Roy Smith wrote: > > > 5) real intensity[160.0 : 30.0 : 0.01] > > How many elements in that array? > > a) 2999 > b) 3000 > c) neither of the above c) neither of the above. More specifically, 13,001 (if I counted correctly). -- http://

79 chars or more?

2010-08-16 Thread AK
As monitors are getting bigger, is there a general change in opinion on the 79 chars limit in source files? I've experimented with 98 characters per line and I find it quite a bit more comfortable to work with that length, even though sometimes I have to edit files in 80 width terminals, it's stil

Re: 79 chars or more?

2010-08-16 Thread James Mills
On Tue, Aug 17, 2010 at 12:35 PM, AK wrote: > As monitors are getting bigger, is there a general change in opinion on > the 79 chars limit in source files? I've experimented with 98 characters > per line and I find it quite a bit more comfortable to work with that > length, even though sometimes I

Re: 79 chars or more?

2010-08-16 Thread Roy Smith
In article , James Mills wrote: > On Tue, Aug 17, 2010 at 12:35 PM, AK wrote: > > As monitors are getting bigger, is there a general change in opinion on > > the 79 chars limit in source files? I've experimented with 98 characters > > per line and I find it quite a bit more comfortable to work

Re: 79 chars or more?

2010-08-16 Thread AK
On 08/16/2010 10:42 PM, James Mills wrote: On Tue, Aug 17, 2010 at 12:35 PM, AK wrote: As monitors are getting bigger, is there a general change in opinion on the 79 chars limit in source files? I've experimented with 98 characters per line and I find it quite a bit more comfortable to work wit

Re: 79 chars or more?

2010-08-16 Thread James Mills
On Tue, Aug 17, 2010 at 12:50 PM, Roy Smith wrote: > I disagree with James.  I have no problem with going wider than 80, if > it improves readability by not forcing you to fold lines in unnatural > places. > > There's more important things to worry about. Roy, under normal circumstances I would a

array manipulation-

2010-08-16 Thread Aram Ter-Sarkissov
hi, this is probably a very silly question, but I can't get my hear around it unfortunately( I have an array (say, mat=rand(3,5)) from which I 'pull out' a row (say, s1=mat[1,]). The problem is, the shape of this row s1 is not [1,5], as I would expect, but rather [5,], which means that I can't, fo

bash: syntax error near unexpected token

2010-08-16 Thread kreglet
Hello, I started learning python last year. All of this time i have used the terminal and gedit to create, modify, and test my applications and modules. For some reason I can not do this any more. I'll try to do my best to explain whats happening. I have a script modtest.py which has a function t

Re: bash: syntax error near unexpected token

2010-08-16 Thread Benjamin Kaplan
On Mon, Aug 16, 2010 at 11:33 PM, kreglet wrote: > Hello, > > I started learning python last year. All of this time i have used the > terminal and gedit to create, modify, and test my applications and modules. > For some reason I can not do this any more. > I'll try to do my best to explain whats

Re: 79 chars or more?

2010-08-16 Thread Steven D'Aprano
On Mon, 16 Aug 2010 22:35:49 -0400, AK wrote: > As monitors are getting bigger, is there a general change in opinion on > the 79 chars limit in source files? I've experimented with 98 characters > per line and I find it quite a bit more comfortable to work with that > length, even though sometimes

Re: Python "why" questions

2010-08-16 Thread Robert Kern
On 8/16/10 9:29 PM, Roy Smith wrote: In article, Lawrence D'Oliveiro wrote: In message, Roy Smith wrote: 5) real intensity[160.0 : 30.0 : 0.01] How many elements in that array? a) 2999 b) 3000 c) neither of the above c) neither of the above. More specifically, 13,001 (if I counted co

Re: array manipulation-

2010-08-16 Thread Robert Kern
On 8/16/10 10:07 PM, Aram Ter-Sarkissov wrote: hi, this is probably a very silly question, but I can't get my hear around it unfortunately( I have an array (say, mat=rand(3,5)) from which I 'pull out' a row (say, s1=mat[1,]). The problem is, the shape of this row s1 is not [1,5], as I would expe

update of elements in GUI

2010-08-16 Thread Jah_Alarm
hi, I've already asked this question but so far the progress has been small. I'm running Tkinter. I have some elements on the screen (Labels, most importantly) which content has to be updated every iteration of the algorithm run, e.g. "Iteration =" [i] for i in range(n), n=100. I'm using the updat

Re: 79 chars or more?

2010-08-16 Thread AK
On 08/16/2010 11:51 PM, Steven D'Aprano wrote: On Mon, 16 Aug 2010 22:35:49 -0400, AK wrote: As monitors are getting bigger, is there a general change in opinion on the 79 chars limit in source files? I've experimented with 98 characters per line and I find it quite a bit more comfortable to wo

Re: Python "why" questions

2010-08-16 Thread Steven D'Aprano
On Mon, 16 Aug 2010 22:56:20 -0500, Robert Kern wrote: > On 8/16/10 9:29 PM, Roy Smith wrote: >> In article, >> Lawrence D'Oliveiro wrote: >> >>> In message, Roy Smith wrote: >>> 5) real intensity[160.0 : 30.0 : 0.01] >>> >>> How many elements in that array? >>> >>> a) 2999 >>> b) 3000 >>>

Eval cannot see globals from another module

2010-08-16 Thread Tom Harris
Greetings, I want a debugging function with the effect of the function below (in a seperate module): def dump(expr): print expr, '=', eval(expr) foo = 33 dump('foo') Of course this fails when called from another module because eval does not know the globals or locals of the caller. Is the

Re: 79 chars or more?

2010-08-16 Thread James Mills
On Tue, Aug 17, 2010 at 2:12 PM, AK wrote: > There's no doubt that there are pro's and con's, but to be fair, it's > not like code becomes unreadable over 79 chars - the difference is that > when your terminal is 80 chars, it's less convenient for you to read > code that's wider and when your term

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

2010-08-16 Thread cbr...@cbrownsystems.com
On Aug 16, 11:04 am, Baba wrote: > Hi Chas, Roald, > > These are all complicated formula that i believe are not expected at > this level. If you look at the source (see my first submission) you > will see that this exercise is only the second in a series called > "Introduction to Programming". The

Re: update of elements in GUI

2010-08-16 Thread woooee
On Aug 16, 9:07 pm, Jah_Alarm wrote: I have some elements on the screen (Labels, most > importantly) which content has to be updated every iteration of the > algorithm The variable type is IntVar() You would use int_var_name.set(some_number) -- http://mail.python.org/mailman/listinfo/python-lis

Re: 79 chars or more?

2010-08-16 Thread AK
On 08/17/2010 12:26 AM, James Mills wrote: On Tue, Aug 17, 2010 at 2:12 PM, AK wrote: There's no doubt that there are pro's and con's, but to be fair, it's not like code becomes unreadable over 79 chars - the difference is that when your terminal is 80 chars, it's less convenient for you to rea

Re: 79 chars or more?

2010-08-16 Thread James Mills
On Tue, Aug 17, 2010 at 2:50 PM, AK wrote: > By the way, the reason I asked is that we're working on a python > tutorial and I realized that even though I'm used to 99, I wasn't sure > if it's ok to teach that to new users or not.. In my opinion it would be "okay" to teach. However: Bare in mind

Re: 79 chars or more?

2010-08-16 Thread Michael Torrie
On 08/16/2010 08:59 PM, AK wrote: > But.. why horizontal scrolling, isn't autowrap much better than that? Wouldn't it really make a visual mess of Python code if lines wrapped? Maybe if they wrapped smartly. In general, the only time I find my lines longer than 75 characters are strings or somet

Re: 79 chars or more?

2010-08-16 Thread Michael Torrie
On 08/16/2010 10:50 PM, AK wrote: > I stay away from ugly cramped one-liners; I mostly run over 79 when I > have a few `and` and `or` clauses or long strings. I've also noticed > something interesting: going from 79 to 99 affects a relatively large > number of lines, but going over 99 (i.e. 99 to 1

<    1   2