Re: [Tutor] Problem with print

2010-12-20 Thread Steven D'Aprano
David Hutto wrote: On Sun, Dec 19, 2010 at 4:33 PM, Hugo Arts wrote: On Sun, Dec 19, 2010 at 10:11 PM, Sander Sweers wrote: On 19 December 2010 21:54, jtl999 wrote: File "GettingStarted.py", line 91 print ("Lesson Two") ^ SyntaxError: invalid syntax [...] Apparently so, but I

Re: [Tutor] calling setters of superclasses

2010-12-20 Thread Steven D'Aprano
Alan Gauld wrote: "Gregory, Matthew" wrote class PositiveX(object): def __init__(self): @property def x(self): @x.setter def x(self, val): I don't use properties in Python very often (hardly ever in fact) and I've never used @setter so there may be naming requirements I'm not

[Tutor] doing maths on lists

2010-12-20 Thread Chris Begert
Bonjour I have three lists with 65 float items and would like to do the following sum: L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))]) So it just should do a sum across all the items in the list: L0A[0]*cos(L0B[0]+L0C[0]*JME)+ L0A[1]*cos(L0B[1]+L0C[1]*JME)+... + L0A[64]*cos(L

Re: [Tutor] doing maths on lists

2010-12-20 Thread Nitin Pawar
you may want to do type casting whenever you have a float answer cause integer to float causes data loss On Mon, Dec 20, 2010 at 4:28 PM, Chris Begert wrote: > Bonjour > > I have three lists with 65 float items and would like to do the following > sum: > > L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME

Re: [Tutor] doing maths on lists

2010-12-20 Thread Chris Begert
Thanks I tried to put a float around my lists as well as around the sum but it didn't work. Do I have to do some type casting around all items of the list? Cheers Original-Nachricht > Datum: Mon, 20 Dec 2010 16:33:39 +0530 > Von: Nitin Pawar > An: Chris Begert > CC: tutor@p

Re: [Tutor] doing maths on lists

2010-12-20 Thread Christian Witts
On 20/12/2010 12:58, Chris Begert wrote: Bonjour I have three lists with 65 float items and would like to do the following sum: L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))]) So it just should do a sum across all the items in the list: L0A[0]*cos(L0B[0]+L0C[0]*JME)+ L0A[1]

Re: [Tutor] doing maths on lists

2010-12-20 Thread Steven D'Aprano
Chris Begert wrote: Bonjour I have three lists with 65 float items and would like to do the following sum: L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))]) [...] However, I always get this error: TypeError: can't multiply sequence by non-int of type 'float'

Re: [Tutor] doing maths on lists

2010-12-20 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Chris Begert wrote: Bonjour I have three lists with 65 float items and would like to do the following sum: L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))]) So it just should do a sum across all the items in the list: L0A[0]*cos(L0B[0]+L0C[0]*JME)+

Re: [Tutor] doing maths on lists

2010-12-20 Thread Chris Begert
Dave and Christian Thanks a lot for the help, it looks like it works! Chris Original-Nachricht > Datum: Mon, 20 Dec 2010 07:32:45 -0500 > Von: Dave Angel > An: Chris Begert > CC: tutor@python.org > Betreff: Re: [Tutor] doing maths on lists > On 01/-10/-28163 02:59 PM, Chris

Re: [Tutor] why "ifconfig" is alway running?

2010-12-20 Thread lei yang
On Sun, Dec 19, 2010 at 9:05 PM, Sander Sweers wrote: > On 19 December 2010 13:43, lei yang wrote: >> Right, it gets stuck at the readline(), is there a function not get >> stuck to instead of readline(). > > readline() will keep reading stdout until it received a newline > character. So if there

Re: [Tutor] calling setters of superclasses

2010-12-20 Thread Alan Gauld
"Steven D'Aprano" wrote I don't use properties in Python very often (hardly ever in fact) and I've never used @setter so there may be naming requirements I'm not aware of. But in general I'd avoid having two methods with the same name. That's generally good advice, since one will over-write

Re: [Tutor] doing maths on lists

2010-12-20 Thread Peter Otten
Dave Angel wrote: > from math import cos > > JME = 0.4 > L0A = [2.3, 4.65] > L0B = [1.8, 2.2] > L0C = [12.1, 4] > limit = len(L0A) > > L0 = sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(limit)) OP, if you are planning to do this "maths on lists" a lot you should have a look at numpy. With n

[Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread ashish makani
Hi Python Tutor folks This is a rather long post, but i wanted to include all the details & everything i have tried so far myself, so please bear with me & read the entire boringly long post. Goal : I am trying to parse a ginormous ( ~ 1gb) xml file. I am looking for a specific element..there ar

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Luke Paireepinart
If you can assume a well formatted file I would just parse it linearly, should be much faster. Read the file in as lines if the XML is already in human readable form, or just read in blocks and append to a list and do a join() when you have a whole match. - Sent from

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Steven D'Aprano
ashish makani wrote: Goal : I am trying to parse a ginormous ( ~ 1gb) xml file. I sympathize with you. I wonder who thought that building a 1GB XML file was a good thing. Forget about using any XML parser that reads the entire file into memory. By the time that 1GB of text is read and pars

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Brett Ritter
On Mon, Dec 20, 2010 at 4:19 PM, Steven D'Aprano wrote: >> Goal : I am trying to parse a ginormous ( ~ 1gb) xml file. > > I sympathize with you. I wonder who thought that building a 1GB XML file was > a good thing. XML is like violence: if it isn't working, try more. -- Brett Ritter / SwiftOne

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Sithembewena Lloyd Dube
[?] Brett, that was very mischievous. I wish I could help - am watching this thread with great curiosity, I could learn something from it myself. On Mon, Dec 20, 2010 at 11:40 PM, Brett Ritter wrote: > On Mon, Dec 20, 2010 at 4:19 PM, Steven D'Aprano > wrote: > >> Goal : I am trying to parse a

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Steven D'Aprano
Brett Ritter wrote: On Mon, Dec 20, 2010 at 4:19 PM, Steven D'Aprano wrote: Goal : I am trying to parse a ginormous ( ~ 1gb) xml file. I sympathize with you. I wonder who thought that building a 1GB XML file was a good thing. XML is like violence: if it isn't working, try more. I love it

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Brett Ritter
On Mon, Dec 20, 2010 at 5:32 PM, Steven D'Aprano wrote: >> XML is like violence: if it isn't working, try more. > > I love it -- may I quote you? I can't claim credit for it, I saw originally saw it on some sigs on Slashdot a few years ago. It certainly matches the majority of XML usage I've enc

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Alan Gauld
"ashish makani" wrote I am looking for a specific element..there are several 10s/100s occurrences of that element in the 1gb file. I need to detect them & then for each 1, i need to copy all the content b/w the element's start & end tags & create a smaller xml This is exactly what sax and

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread ashish makani
Thanks Luke, Steve, Brett, Lloyd & Alan for your prompt responses & sharing your wisdom. I <3 the python community... You(We ?) folks are AWESOME I cross-posted this query on comp.lang.python I bet most of you hang @ c.l.p too, but just in case, here is the link to the discussion at c.l.p https:/

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Chris Fuller
This isn't XML, it's an abomination of XML. Best to not treat it as XML. Good thing you're only after one class of tags. Here's what I'd do. I'll give a general solution, but there are two parameters / four cases that could make the code simpler, I'll just point them out at the end. Iterat

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread ashish makani
Chris This block of code made my day - especially yummydataaddrs & "here's your stupid data" > for start,end in yummydataaddrs: >fd.seek(start) >print "here's your stupid data:", fd.read(end-start+1) Nothing is more impressive than solid code, with a good sense of humor. Thanks for the

[Tutor] decimal input problem

2010-12-20 Thread jtl999
when I try to multiply with a decimal number in python with the input this is what i get MathCheats Times-Ed by jtl999 Not for decimal numbers due to a bug in the code. Enter first number: 1.2 Traceback (most recent call last): File "Timesed.py", line 18, in numberx1 = (int)(raw_input('En

Re: [Tutor] Problem with print

2010-12-20 Thread David Hutto
On Mon, Dec 20, 2010 at 5:15 AM, Steven D'Aprano wrote: > David Hutto wrote: >> >> On Sun, Dec 19, 2010 at 4:33 PM, Hugo Arts wrote: >>> >>> On Sun, Dec 19, 2010 at 10:11 PM, Sander Sweers >>> wrote: On 19 December 2010 21:54, jtl999 wrote: > >  File "GettingStarted.py", line

Re: [Tutor] Problem with print

2010-12-20 Thread Hugo Arts
On Tue, Dec 21, 2010 at 5:35 AM, David Hutto wrote: > > I was used to the tutorials from 3 showing the correct print(), and > seeing the errors for print 'whatever', when i accidentally used them > in 3, that I used them exclusively after seeing the 3 tutorials, and > that it could be used as both

Re: [Tutor] Problem with print

2010-12-20 Thread David Hutto
> > Note that print can actually only be used as a statement in python 2. > It just so happens that you can include parentheses in the statement. > Though that makes it look similar to a function call, it certainly is > not. You'll see that when you try to supply multiple arguments to the > "functi

[Tutor] Was: Trying to parse a HUGE(1gb) xml file in python Now: OT, Hackerspaces

2010-12-20 Thread Tino Dai
Hi Ashish, Check out Noisebridge ( https://www.*noisebridge*.net/) in SF. I think you will find there are like minded tech people there. It also has Mitch Altman ( http://en.wikipedia.org/wiki/*Mitch*_*Altman* ) is one of

Re: [Tutor] Problem with print

2010-12-20 Thread Hugo Arts
On Tue, Dec 21, 2010 at 6:08 AM, David Hutto wrote: >> >> Note that print can actually only be used as a statement in python 2. >> It just so happens that you can include parentheses in the statement. >> Though that makes it look similar to a function call, it certainly is >> not. You'll see that