Re: [Tutor] reading binary files

2009-02-03 Thread eShopping
Bob I am trying to read UNFORMATTED files. The files also occur as formatted files and the format string I provided is the string used to write the formatted version. I can read the formatted version OK. I (naively) assumed that the same format string was used for both files, the only diff

Re: [Tutor] Can you help me with subprocess module ?.

2009-02-03 Thread Larry Riedel
> I have a problem with the subprocess module. In fact I wish > that when I run the command with subprocess I can retrieve the > data immediately without waiting for the end of the command. > > import subprocess, os, sys > # Commande FFmpeg > com_1 = 'ffmpeg -i /home/user/path/in.avi -s 160x120 -ac

Re: [Tutor] Sort of database & "family tree" question

2009-02-03 Thread ALAN GAULD
> > And I assume you are reading these into a Person class and > > storing these classes in a persons dictionary? > Can you explain this a little more for me please? Sure. (I didn't notice this on gmane so apologies if others already answered) > The current way of reading the data is this: >

Re: [Tutor] struct question

2009-02-03 Thread Alan Gauld
"bob gailer" wrote >>> struct.calcsize('s') 1 >>> struct.calcsize('d') 8 >>> struct.calcsize('sd') 16 Why? Should not that be 9? Numbers always start on word boundaries. struct.calcsize('ds') 9 Alan G. ___ Tutor maillist - Tutor@python.or

Re: [Tutor] re weird bool

2009-02-03 Thread Alan Gauld
"prasad rao" wrote 2==True False It is an unexpected result to me. I thought any value other than 0 is True. Any value of non zero is treated as True in a boolean context. But aq test of equality with a boolean value is not a boolean context. For equiality you have to compare like with lik

[Tutor] Can you help me with subprocess module ?.

2009-02-03 Thread PyProg PyProg
Hello everyone, I have a problem with the subprocess module. In fact I wish that when I run the command with subprocess I can retrieve the data immediately without waiting for the end of the command. I tried this way but ordering must end so that I can recover the data: import subprocess, os, sys

Re: [Tutor] Parsing suggestion? (CUE file)

2009-02-03 Thread Kent Johnson
On Tue, Feb 3, 2009 at 5:17 PM, Terry Carroll wrote: > On Tue, 3 Feb 2009, Kent Johnson wrote: > >> I would look at pyparsing for that, and make sure cuetools won't do >> what you want. > > csv seems to be working well for me, and it's a standard piece of Python, > which I prefer to use. I don't

Re: [Tutor] Parsing suggestion? (CUE file)

2009-02-03 Thread Terry Carroll
On Tue, 3 Feb 2009, Kent Johnson wrote: > Ah, I see. I imagined something more ambitious, that treated the lines > as fields. I find that the more ambitious my projects become, the less likely I am to complete them! With two toddlers, on a good day, I get 30 to 60 minutes of discretionary tim

Re: [Tutor] Parsing suggestion? (CUE file)

2009-02-03 Thread Kent Johnson
On Tue, Feb 3, 2009 at 3:26 PM, Terry Carroll wrote: > On Tue, 3 Feb 2009, Kent Johnson wrote: > >> On Tue, Feb 3, 2009 at 2:55 PM, Terry Carroll wrote: >> >> > The silver cloud to my temporary Internet outage was that I was able to >> > solve my problem, in the process discovering that the csv m

Re: [Tutor] reading binary files

2009-02-03 Thread bob gailer
First question: are you trying to work with the file written UNFORMATTED? If so read on. If you are working with a file formatted (1X, 1X, A8, 1X, 1X, I6, 1X, 1X, A1) then we have a completely different issue to deal with. Do not read on, instead let us know. eShopping wrote: Data format:

Re: [Tutor] reading binary files

2009-02-03 Thread eShopping
Bob At 19:52 03/02/2009, you wrote: etrade.griffi...@dsl.pipex.com wrote: Data format: TIME 1 F 0.0 DISTANCE 10 F 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 F=float, D=double, L=logical, S=string etc The first part of the file should contain a string (eg "TIME"), an integer (1) and ano

Re: [Tutor] Parsing suggestion? (CUE file)

2009-02-03 Thread Terry Carroll
On Tue, 3 Feb 2009, Kent Johnson wrote: > On Tue, Feb 3, 2009 at 2:55 PM, Terry Carroll wrote: > > > The silver cloud to my temporary Internet outage was that I was able to > > solve my problem, in the process discovering that the csv module can parse > > a CUE file[1] quite nicely if you set up

Re: [Tutor] Parsing suggestion? (CUE file)

2009-02-03 Thread Kent Johnson
On Tue, Feb 3, 2009 at 2:55 PM, Terry Carroll wrote: > The silver cloud to my temporary Internet outage was that I was able to > solve my problem, in the process discovering that the csv module can parse > a CUE file[1] quite nicely if you set up an appropriate csv.Dialect class. > > "Comma Separ

Re: [Tutor] struct question

2009-02-03 Thread Kent Johnson
On Tue, Feb 3, 2009 at 2:03 PM, Marc Tompkins wrote: > More results to chew on: > struct.calcsize('s') > 1 struct.calcsize('d') > 8 struct.calcsize('sd') > 16 struct.calcsize('ds') > 9 struct.calcsize('dss') > 10 struct.calcsize('dss') > 14 struct.calcsize('

Re: [Tutor] Parsing suggestion? (CUE file)

2009-02-03 Thread Terry Carroll
On Tue, 3 Feb 2009, Terry Carroll wrote: > I am parsing certai Sorry about that. I was composing this message last night when my Internet connection went down. When I logged on this morning, I had a partial message. I meant to cancel but unfortunately, in pine, the SEND key (CTRL-X) is adja

Re: [Tutor] reading binary files

2009-02-03 Thread bob gailer
etrade.griffi...@dsl.pipex.com wrote: Data format: TIME 1 F 0.0 DISTANCE 10 F 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 F=float, D=double, L=logical, S=string etc The first part of the file should contain a string (eg "TIME"), an integer (1) and another string (eg "F") so I tried us

Re: [Tutor] struct question

2009-02-03 Thread Marc Tompkins
On Tue, Feb 3, 2009 at 11:05 AM, bob gailer wrote: > I have submitted this as a bug. Same behavior with c instead of s. > I don't think it's a bug. Each double requires 8 bytes; that 8 bytes needs to start at an 8-byte boundary. If your struct starts with a 1-byte object, then some empty paddi

Re: [Tutor] struct question

2009-02-03 Thread bob gailer
W W wrote: On Tue, Feb 3, 2009 at 6:25 PM, bob gailer > wrote: >>> struct.calcsize('s') 1 >>> struct.calcsize('d') 8 >>> struct.calcsize('sd') 16 Why? Should not that be 9? >>> struct.calcsize('ds') 9 at least on the current box I'm ru

Re: [Tutor] struct question

2009-02-03 Thread Marc Tompkins
On Tue, Feb 3, 2009 at 10:29 AM, W W wrote: > > > On Tue, Feb 3, 2009 at 6:25 PM, bob gailer wrote: > >> >>> struct.calcsize('s') >> 1 >> >>> struct.calcsize('d') >> 8 >> >>> struct.calcsize('sd') >> 16 >> >> Why? Should not that be 9? >> > > >>> struct.calcsize('ds') > 9 > > at least on the cur

[Tutor] Parsing suggestion? (CUE file)

2009-02-03 Thread Terry Carroll
I am parsing certai ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] struct question

2009-02-03 Thread W W
On Tue, Feb 3, 2009 at 6:25 PM, bob gailer wrote: > >>> struct.calcsize('s') > 1 > >>> struct.calcsize('d') > 8 > >>> struct.calcsize('sd') > 16 > > Why? Should not that be 9? > >>> struct.calcsize('ds') 9 at least on the current box I'm running. It also gave me this: >>> struct.calcsize('sd')

[Tutor] struct question

2009-02-03 Thread bob gailer
>>> struct.calcsize('s') 1 >>> struct.calcsize('d') 8 >>> struct.calcsize('sd') 16 Why? Should not that be 9? -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Sort of database & "family tree" question

2009-02-03 Thread Timo
Alan Gauld schreef: Timo wrote So my entry's look like this (more or less ;)): [person1] firstName = foo lastName = bar father = person2 mother = person3 And I assume you are reading these into a Person class and storing these classes in a persons dictionary? Then to access a father becomes:

Re: [Tutor] regex: not start with FOO

2009-02-03 Thread Kent Johnson
On Tue, Feb 3, 2009 at 11:12 AM, Bernard Rankin wrote: > In [3]: re.findall('^(?!FOO)in', 'in in in') > Out[3]: ['in'] > > In [4]: re.findall('(?!^FOO)in', 'in in in') > Out[4]: ['in', 'in', 'in'] > > In [5]: re.findall('(?!FOO)in', 'in in in') > Out[5]: ['in', 'in', 'in'] > > In [6]: re.findall(

Re: [Tutor] regex: not start with FOO

2009-02-03 Thread Bernard Rankin
> > I'd like to match any line that does not start with FOO. (Using just a > > reg-ex > rule) > > > > 1) What is the effective difference between: > > > > (?!^FOO).* > > > > ^(?!FOO).* > > One difference is that the first will match starting anywhere in a > string, while the second will matc

Re: [Tutor] regex: not start with FOO

2009-02-03 Thread Bernard Rankin
> > I'd like to match any line that does not start with FOO. (Using just a > > reg-ex > rule) > > > > 1) What is the effective difference between: > > > > (?!^FOO).* > > > > ^(?!FOO).* > > One difference is that the first will match starting anywhere in a > string, while the second will matc

Re: [Tutor] transforming an integer to a list of integers

2009-02-03 Thread Kent Johnson
On Tue, Feb 3, 2009 at 10:17 AM, H.G. le Roy wrote: > One step for my solution should be transforming this big integer to a list > of integers. I did: > > import math > > bignr = 12345 > bignrs =[] > The suggestions with strings are fine, but you can simplify your approach as well: > for i in x

Re: [Tutor] transforming an integer to a list of integers

2009-02-03 Thread Andre Engels
On Tue, Feb 3, 2009 at 4:24 PM, Andre Engels wrote: > On Tue, Feb 3, 2009 at 4:17 PM, H.G. le Roy wrote: >> Hi, >> >> recently I learned about Project Euler (http://projecteuler.net/) and now >> I'm trying to work me through. At the moment I'm thinking about >> http://projecteuler.net/index.php?s

Re: [Tutor] transforming an integer to a list of integers

2009-02-03 Thread Andre Engels
On Tue, Feb 3, 2009 at 4:17 PM, H.G. le Roy wrote: > Hi, > > recently I learned about Project Euler (http://projecteuler.net/) and now > I'm trying to work me through. At the moment I'm thinking about > http://projecteuler.net/index.php?section=problems&id=8 > > One step for my solution should be

Re: [Tutor] transforming an integer to a list of integers

2009-02-03 Thread Ken Oliver
Not an expert here, but I think I would first change it to a big string of 1000 chars and then pick off the chars one at a time and do int().-Original Message- From: "H.G. le Roy" Sent: Feb 3, 2009 10:17 AM To: tutor@python.org Subject: [Tutor] transforming an integer to a list of integers

[Tutor] transforming an integer to a list of integers

2009-02-03 Thread H.G. le Roy
Hi, recently I learned about Project Euler (http://projecteuler.net/) and now I'm trying to work me through. At the moment I'm thinking about http://projecteuler.net/index.php?section=problems&id=8 One step for my solution should be transforming this big integer to a list of integers. I did: imp

Re: [Tutor] re division problem

2009-02-03 Thread Andre Engels
On Tue, Feb 3, 2009 at 2:46 PM, prasad rao wrote: > hi >>Right now you skip by x+((len(v))/columns) >>which will be different for each row. > How is it possible. len(v)=98.A constant. > Is it not. > Does len(v) changes with each iteration? No, but x does. -- André Engels, andreeng...@gmail.com

[Tutor] re division problem

2009-02-03 Thread prasad rao
hi>Right now you skip by x+((len(v))/columns) >which will be different for each row. How is it possible. len(v)=98.A constant. Is it not. Does len(v) changes with each iteration? Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailm

Re: [Tutor] re division problem

2009-02-03 Thread Kent Johnson
On Tue, Feb 3, 2009 at 8:24 AM, prasad rao wrote: >> I wrote a function named vertical to print string .printable characters >> and > .>> ASCII values in a table. >>> 1)It is swallowing some characters. >>> 2)It output some characters 2 or 3 times. >>> 3)It prints one column more than what I aske

[Tutor] re weird bool

2009-02-03 Thread prasad rao
helloyes.you are right. >>> 2==True False It is an unexpected result to me. I thought any value other than 0 is True. And the solution provided by you(bool(a/1)) is useful to me. Thank you Prasad ___ Tutor maillist - Tutor@python.org http://mail.pytho

[Tutor] re division problem

2009-02-03 Thread prasad rao
> I wrote a function named vertical to print string .printable characters and .>> ASCII values in a table. >> 1)It is swallowing some characters. >> 2)It output some characters 2 or 3 times. >> 3)It prints one column more than what I asked for. >> def vertical(columns): >> import string >

Re: [Tutor] Division problems

2009-02-03 Thread Kent Johnson
On Tue, Feb 3, 2009 at 3:42 AM, prasad rao wrote: > Hello > I wrote a function named vertical to print string .printable characters and > ASCII values in a table. > 1)It is swallowing some characters. > 2)It output some characters 2 or 3 times. > 3)It prints one column more than what I asked for.

Re: [Tutor] regex: not start with FOO

2009-02-03 Thread Kent Johnson
On Mon, Feb 2, 2009 at 5:46 PM, Bernard Rankin wrote: > Hello, > > > I'd like to match any line that does not start with FOO. (Using just a > reg-ex rule) > > 1) What is the effective difference between: > > (?!^FOO).* > > ^(?!FOO).* One difference is that the first will match starting anywhere

Re: [Tutor] weird bool

2009-02-03 Thread Andre Engels
On Tue, Feb 3, 2009 at 11:40 AM, prasad rao wrote: > hi a=2.1 a%1==True > False a%1==False > False b=3.8 b%1==True > False b%1==False > False > If it gives correct bool, it could be put to good use. == gives a high degree of equality. In your idea, it would not be a

[Tutor] weird bool

2009-02-03 Thread prasad rao
hi >>> a=2.1 >>> a%1==True False >>> a%1==False False >>> b=3.8 >>> b%1==True False >>> b%1==False False If it gives correct bool, it could be put to good use. Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] reading binary files

2009-02-03 Thread etrade . griffiths
Sorry, still having problems > > I am trying to read data from a file that has format > > item_name num_items item_type items > > > > eg > > > > TIME 1 0.0 > > DISTANCE 10 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 > > Where is the item_type? Ooops, the data format should loo

Re: [Tutor] Alarm Clock (suggestions please)

2009-02-03 Thread ukapache
John Fouhy wrote: > > 2009/2/3 David : >> while(doit): >>mytime = list(time.localtime()) >>hour = mytime[3] >>minute = mytime[4] >>if hour == alarmhour and minute == alarmmin: >>subprocess.call('mplayer -loop 9 ring.wav', shell=True) >>

[Tutor] Division problems

2009-02-03 Thread prasad rao
HelloI wrote a function named vertical to print string .printable characters and ASCII values in a table. 1)It is swallowing some characters. 2)It output some characters 2 or 3 times. 3)It prints one column more than what I asked for. It may be a division problem(floating point). Its sibling call

Re: [Tutor] newton's square root formula

2009-02-03 Thread Alan Gauld
"WM." wrote # program to find square root square = float(raw_input ("Please enter a number to be rooted, ")) guess = input("Please guess at the root, ") Actually, I meant you should use raw_input here too... input() is considered insecure and not recommended. (In Python v3 it has been remo

Re: [Tutor] newton's square root formula

2009-02-03 Thread Andre Engels
On Tue, Feb 3, 2009 at 3:59 AM, WM. wrote: > # program to find square root > square = float(raw_input ("Please enter a number to be rooted, ")) > guess = input("Please guess at the root, ") > i = 0 > while guess**2 != square: >i+=1 ># Newton's formula >guess = guess - (gues