Re: [Tutor] Classes in multiple files - code included
On 04/04/13 16:58, Peter Otten wrote: Phil wrote: I think I must be very close now so I'll post just the code that I think is relevant. This the main window class: import satListDialog Here you are importing the module "satListDialog" class MainWindow(QMainWindow, Ui_MainWindow): This is the function to show the dialog; def on_actionList_triggered(self): self.dialog = Ui_satListDialog.SatelliteListDialog() self.dialog.show() and here you are referring to the module "Ui_satListDialog". I'd guess that should be self.dialog = satListDialog.SatelliteListDialog() instead. Thanks Peter, This one of those times when I wish I could cancel a question. I discovered the answer, mostly through trial and error, a couple of hours ago. I had also accidentally commented out a line in the dialog class. Anyway, I've made some headway with PyQt today. By the way, I notice that it can take several hours for my postings to appear on the list. Possibly due to moderation? -- Regards, Phil ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Classes in multiple files - code included
On 04/04/13 13:12, Phil wrote: On 04/04/13 11:58, Steven D'Aprano wrote: On 04/04/13 12:47, Phil wrote: And this is the error message; "global name 'Ui_satListDialog' is not defined" On its own, that is almost useless. Python gives you more debugging information than that: it gives you a complete traceback, which includes the actual line of code causing the problem. We don't even know which file gives the error, let alone which line of code! When you try to run the program, you will get an error. Please copy and paste the *complete* traceback, starting with the line "Traceback (most recent call last)" all the way to the bottom. It will show you which file contains the error, what type of error it is, and which line fails. Thank you for your reply Steven, As useless as the error message may be it's the only one given. You have misunderstood me. In your email, quoted above, you pasted ONLY the error message "global name 'Ui_satListDialog' is not defined". But now, following my prompting, you pasted the ENTIRE traceback: phil@Asus:~/Eric/Pest$ python pest.py Traceback (most recent call last): File "/home/phil/Eric/Pest/ui/mainwindow.py", line 57, in on_actionList_triggered dialog = Ui_satListDialog.SatelliteListDialog(self) NameError: global name 'Ui_satListDialog' is not defined ^CTraceback (most recent call last): File "pest.py", line 9, in sys.exit(app.exec_()) Notice how much more information there is? We learn: * the error is occurring in your mainwindow.py file * on line 57 * in the function or method "on_actionList_triggered" * with the exact line "dialog = Ui_satListDialog.SatelliteListDialog(self)" * which gives a NameError (as apposed to any of dozens of different sorts of error) * with the specific error message "global name 'Ui_satListDialog' is not defined" (and then there is a further error when you try to quit the app with Ctrl-C, but one thing at a time). One of the most critical skills for a programmer is to learn how to diagnose errors. Trying to diagnose the error from just the error message is a bit like telling the doctor you have a pain, but refusing to tell where the pain is, what sort of pain, how long you've had it, or under what circumstances it comes and goes. Debugging, at times, is hard enough even with the assistance of full tracebacks. You'll soon learn to appreciate them. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Classes in multiple files - code included
On 04/04/13 08:51, Phil wrote: By the way, I notice that it can take several hours for my postings to appear on the list. Possibly due to moderation? Nope, the only posts that get moderated are the ones where the poster has not subscribed to the list (or is using a different email address than the one they signed up with!) Remember email is not a high priority message type on the internet. The suggested SLA for delivery used to be 48 hours but I believe current recommendations say 24 hours. So even though mail usually gets there much faster than that you shouldn't count on it. (Note that if you are using corporate "email" like Microsoft Exchange that's not really email at all, just corporate messaging which is nearly instant!). And of course email is not guaranteed delivery either so it might never get there - if a server gets busy it's quite within its rights to just throw all the email messages away...! And the nature of the internet is that your mail may be routing through somebody's old 50MHz 486 PC server somewhere in Uzbekistan or Mongolia... Having said all that, I rarely see a post to tutor take more than 20 minutes to get onto the gmane newsfeed that I use from the list server. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help required
I am new to python. My intention is to read the file digi.txt and store in separate arrays all the values of each columns. However, the following program prints only the last value, i.e. 1350696500.0. Please help to rectify this. f = open ("digi.txt", "r+") datafile = f.readlines() list_of_lists = datafile for data in list_of_lists: lstval = data.split (',') timest = float(lstval[0]) energy = float(lstval[1]) f.close() print timest Regards, Arijit Ukil Tata Consultancy Services Mailto: arijit.u...@tcs.com Website: http://www.tcs.com Experience certainty. IT Services Business Solutions Outsourcing =-=-= Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] File Import
Hi, I am importing data produced from an external code. The data is organized into columns. I would like to be able to assign each column to a variable or array. How would you recommend doing this? I have been looking into the pickle function, as well as "f.readline" and "for line in f:" and I got all of those ideas from the Python Tutorial. I am a little new to python. Thank you, Tristan Clark ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] os.system() with imbeded quotes
I get the example os.system('ls -al') no problem. i'm trying to create a variable with my command built but needs to include quotes. Portion of code is as follows: someip = '192.168.01.01' var1 = 'lynx -dump http://' + someip + '/cgi-bin/.log&.submit=+++Go%21+++ > junk' print var1 os.system(var1) If I print var1 it looks right . If I use the os.system(var1) as above it seems to have a problem near the end of the string with msg sh: .submit=+++Go%21+++: command not found clearly there is some escape sequence that I don't understand . I tried combinations of single and double quotes and mixed around var1, but that generates command not found. I need it to look like how I enter it manually and works lynx -dump 'http://192.168.01.01/cgi-bin/.log&.submit=+++Go%21+++ > junk' Probably obvious to many but i'm spinning my wheels. many thanks for help . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Phyton script for fasta file (seek help)
Hi everyone, Can someone please help me with the following phyton script? I received the error message DeprecationWarning: the sets module is deprecated from sets import Set. After googling, I have tried the methods others suggest: change sets to set or delete the from sets import Set but none of them works. Can someone suggest me how to modify the following codes so that the input file is read from standard input? I'd like to execute them with unix command script.py < sequence.fna Thanks a bunch. #!/usr/local/bin/python import math from sets import Set line = file("sequence.fna", "r") for x in line: if x [0] == ">" : #determine the length of sequences s=line.next() s=s.rstrip() length = len(s) # determine the GC content G = s.count('G') C = s.count('C') GC= 100 * (float(G + C) / length) stList = list(s) alphabet = list(Set(stList)) freqList = [] for symbol in alphabet: ctr = 0 for sym in stList: if sym == symbol: ctr += 1 freqList.append(float(ctr)/len(stList)) # Shannon entropy ent = 0.0 for freq in freqList: ent = ent + freq * math.log(freq, 2) ent = -ent print x print "Length:" , length print "G+C:" ,round(GC),"%" print 'Shannon entropy:' print ent print 'Minimum number of bits required to encode each symbol:' print int(math.ceil(ent)) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] The game of nim in python
Hello, I am trying to modify a game of nim code. The game in the code works as: "You need to remove from 1 to 3 straws from the pile. The player that removes the final straw is the loser." But I would like it to be like the classic game, where you have 4 piles containing 1,3,5 and 7 sticks where the drawer of the last stick is the winner. It would be awsome if I could print how many sticks there are left in each pile, e.g. : I III I III. Thanks in advance! The code I have: player1=str(input("Enter your name. ")) player2="Computer" howMany=0 gameover=False strawsNumber=random.randint(10,20) if (strawsNumber%4)==1: strawsNumber+=1 def removingStrawsComputer(): removedNumber=random.randint(1,3) global strawsNumber while removedNumber>strawsNumber: removedNumber=random.randint(1,3) strawsNumber-=removedNumber return strawsNumber def removingStrawsHuman(): global strawsNumber strawsNumber-=howMany return strawsNumber def humanLegalMove(): global howMany legalMove=False while not legalMove: print("It's your turn, ",player1) howMany=int(input("How many straws do you want to remove?(from 1 to 3) ")) if howMany>3 or howMany<1: print("Enter a number between 1 and 3.") else: legalMove=True while howMany>strawsNumber: print("The entered number is greater than a number of straws remained.") howMany=int(input("How many straws do you want to remove?")) return howMany def checkWinner(player): if strawsNumber==0: print(player," wins.") global gameover gameover=True return gameover def resetGameover(): global gameover gameover=False return gameover def game(): while gameover==False: print("It's ",player2,"turn. The number of straws left: ",removingStrawsComputer()) checkWinner(player1) if gameover==True: break humanLegalMove() print("The number of straws left: ",removingStrawsHuman()) checkWinner(player2) game() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] chat-server python
Hello there, am beginner in python. i want start my first project with chat-server. i want create a messenger which encodes msg, hides it in a image(steganography) and send it to second user. i want this messenger be available also by internet and non static ips,so i want use chat server. also i want filter incoming packets,which only trusted MAC addresses can communicate with mesenger may i get some help from u? any chat-server messenger source code for python? after i finish encoding and steganography part,i will upload my job in your site thank u ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] moderation queue flushed - may be old/duplicates coming through
I've just flushed the queue so there will be some old or duplicate messages coming through. Apologies, but I hadn't looked in there for a couple of weeks! Oops. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help required
On 03/20/2013 02:12 AM, Arijit Ukil wrote: I am new to python. My intention is to read the file digi.txt and store in separate arrays all the values of each columns. However, the following program prints only the last value, i.e. 1350696500.0. Please help to rectify this. f = open (/"digi.txt"/, /"r+"/) datafile = f.readlines() list_of_lists = datafile fordata inlist_of_lists: lstval = data.split (/','/) timest = float(lstval[0]) energy = float(lstval[1]) f.close() printtimest Regards, Arijit Ukil You would want to create an empty list and then append values to it inside the loop. E.g. lst=[]; lst.append(val) -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] File Import
On 03/18/2013 11:14 PM, Clark, Tristan wrote: Hi, I am importing data produced from an external code. The data is organized into columns. I would like to be able to assign each column to a variable or array. How would you recommend doing this? I have been looking into the pickle function, as well as "f.readline" and "for line in f:" and I got all of those ideas from the Python Tutorial. I am a little new to python. Thank you, Tristan Clark Take a look at csv module (for Py2, see drop down version choice for Py3): http://docs.python.org/2/library/csv.html Is the data going to be ASCII? There are some issues in regard to csv / unicode handling. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 109, Issue 71
On 03/20/2013 09:14 PM, Matthew Johnson wrote: I recently asked a question on SO: http://stackoverflow.com/questions/15180767/subset-list-based-on-value-of-dictionary-element and got very confused when trying to generalise the answer. The problem is as follows: say i have this list, and would like to get the value at each date that has the largest value for realtime_start (date) value. obs = [{'date': '2012-10-01', 'realtime_end': '2013-02-18', 'realtime_start': '2012-11-15', 'value': '231.751'}, {'date': '2012-10-01', 'realtime_end': '-12-31', 'realtime_start': '2012-12-19', 'value': '231.623'}, {'date': '2012-11-01', 'realtime_end': '2013-02-18', 'realtime_start': '2012-12-14', 'value': '231.025'}, {'date': '2012-11-01', 'realtime_end': '-12-31', 'realtime_start': '2013-01-19', 'value': '231.071'}, {'date': '2012-12-01', 'realtime_end': '2013-02-18', 'realtime_start': '2013-01-16', 'value': '230.979'}, {'date': '2012-12-01', 'realtime_end': '-12-31', 'realtime_start': '2013-02-19', 'value': '231.137'}, {'date': '2012-12-01', 'realtime_end': '-12-31', 'realtime_start': '2013-03-19', 'value': '231.197'}, {'date': '2013-01-01', 'realtime_end': '-12-31', 'realtime_start': '2013-02-21', 'value': '231.198'}, {'date': '2013-01-01', 'realtime_end': '-12-31', 'realtime_start': '2013-03-21', 'value': '231.222'}] maxDate = "2013-02-21" The answer suggested itertools, and it worked for the exact maxDate that's above. However, when i move the date (say to "2013-01-21") it throws the error: ValueError: max() arg is an empty sequence. I can see from the list that there are elements that have realtime_start values that are lower than 2013-01-21 so this is a bug. I have read the documents for itertools, but cannot quite work out this groupby stuff. there's a snip of the SO solution below -- help understanding as well as the bug fix would be much appreciated. thanks in advance, Matt Johnson You should refer to my earlier answer using groupby -- where I sorted the list before using groupby on it; you can read some notes on this in python groupby documentation. I'm not sure why you insist on using groupby for this problem. I would also try to stay away from packing so much in a single list comp as the SO answer does, and instead split things into separate steps where each step is simple and clear, then you'd be able to print out intermediate results and see what exactly is happening. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] TypeError: can't multiply sequence by non-int of type 'float'
Dear All, I know this error occurs when one tries to multiply a string with a fraction i.e float. In my case , I can't figure out how can a numpy floating point array be a string. Interestingly, the concerned expression gets printed in the loop for the first time but on the second go it fails. The concerned snippet of code is given below : for t in t_range(0,1,0.1): print t p_za=[] pv_za=[] # Opening file in file_t format fname = 'file_' + str(t) + '.dat' fo = open(fname,'w') # p_za.append(p_initial - t*K*np.sin(K*p_initial)) print 'K=',K print 'pv_za_temp =',pv_za_temp print '- t*K*np.sin(K*p_initial) = ',- t*K*np.sin(K*p_initial) print '-K*np.sin(K*pv_za_temp) = ',-K*np.sin(K*pv_za_temp) pv_za.append(-K*np.sin(K*pv_za_temp)) pv_za_temp = [] pv_za_temp.append(np.array(pv_za)) Here is paste the output,which clearly shows that the concerned expression i.e -K*np.sin(K*pv_za_temp) prints perfectly for the first looping. Also see the error that comes on the second looping. I'm clueless. 0 K= 3.14159265359 pv_za_temp = [ 0. 0.5 1. 1.5 2. ] - t*K*np.sin(K*p_initial) = [ 0. 0. -0. -0. 0.] *-K*np.sin(K*pv_za_temp) = [ -0.e+00 -3.14159265e+00 6.49753967e-13 3.14159265e+00* * -1.29950793e-12] PRINTS PERFECTLY* * * 0.1 K= 3.14159265359 pv_za_temp = [array([[ -0.e+00, -3.14159265e+00, 6.49753967e-13, 3.14159265e+00, -1.29950793e-12]])] - t*K*np.sin(K*p_initial) = [ -0.e+00 -3.14159265e-01 6.49753967e-14 3.14159265e-01 -1.29950793e-13] -K*np.sin(K*pv_za_temp) = *ERROR* Traceback (most recent call last): File "ZA.py", line 45, in print '-K*np.sin(K*pv_za_temp) = ',-K*np.sin(K*pv_za_temp) *TypeError: can't multiply sequence by non-int of type 'float'* Please Help Cheers, Sayan -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TypeError: can't multiply sequence by non-int of type 'float'
I attach the script herewith. On 4 April 2013 19:10, Sayan Chatterjee wrote: > Dear All, > > I know this error occurs when one tries to multiply a string with a > fraction i.e float. In my case , I can't figure out how can a numpy > floating point array be a string. Interestingly, the concerned expression > gets printed in the loop for the first time but on the second go it fails. > > The concerned snippet of code is given below : > > for t in t_range(0,1,0.1): > print t > p_za=[] > pv_za=[] > > # Opening file in file_t format > fname = 'file_' + str(t) + '.dat' > fo = open(fname,'w') > > # p_za.append(p_initial - t*K*np.sin(K*p_initial)) > print 'K=',K > print 'pv_za_temp =',pv_za_temp > print '- t*K*np.sin(K*p_initial) = ',- t*K*np.sin(K*p_initial) > print '-K*np.sin(K*pv_za_temp) = ',-K*np.sin(K*pv_za_temp) > pv_za.append(-K*np.sin(K*pv_za_temp)) > pv_za_temp = [] > pv_za_temp.append(np.array(pv_za)) > > > Here is paste the output,which clearly shows that the concerned > expression i.e -K*np.sin(K*pv_za_temp) prints perfectly for the first > looping. Also see the error that comes on the second looping. I'm clueless. > > 0 > K= 3.14159265359 > pv_za_temp = [ 0. 0.5 1. 1.5 2. ] > - t*K*np.sin(K*p_initial) = [ 0. 0. -0. -0. 0.] > *-K*np.sin(K*pv_za_temp) = [ -0.e+00 -3.14159265e+00 > 6.49753967e-13 3.14159265e+00* > * -1.29950793e-12] PRINTS PERFECTLY* > * > * > 0.1 > K= 3.14159265359 > pv_za_temp = [array([[ -0.e+00, -3.14159265e+00, 6.49753967e-13, > 3.14159265e+00, -1.29950793e-12]])] > - t*K*np.sin(K*p_initial) = [ -0.e+00 -3.14159265e-01 > 6.49753967e-14 3.14159265e-01 > -1.29950793e-13] > -K*np.sin(K*pv_za_temp) = *ERROR* > Traceback (most recent call last): > File "ZA.py", line 45, in > print '-K*np.sin(K*pv_za_temp) = ',-K*np.sin(K*pv_za_temp) > *TypeError: can't multiply sequence by non-int of type 'float'* > > Please Help > > > Cheers, > Sayan > > > -- > > > -- > *Sayan Chatterjee* > Dept. of Physics and Meteorology > IIT Kharagpur > Lal Bahadur Shastry Hall of Residence > Room AB 205 > Mob: +91 9874513565 > blog: www.blissprofound.blogspot.com > > Volunteer , Padakshep > www.padakshep.org > -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ZA.py Description: Binary data ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Invitation to use Google Talk
--- You've been invited by Sayan Chatterjee to use Google Talk. If you already have a Google account, log in to Gmail and accept this chat invitation: http://mail.google.com/mail/b-8dcd51705-090ef095ef-tIz_r28PffY3z4wTZmz--hUlRBY To sign up for a Google account and get started with Google Talk, you can visit: http://mail.google.com/mail/a-8dcd51705-090ef095ef-tIz_r28PffY3z4wTZmz--hUlRBY?pc=en_gb-rf---a Learn more at: http://www.google.com/intl/en/landing/accounts/ Thanks, The Google Team ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help required
On 20 March 2013 06:12, Arijit Ukil wrote: > I am new to python. My intention is to read the file digi.txt and store in > separate arrays all the values of each columns. However, the following > program prints only the last value, i.e. 1350696500.0. > Please help to rectify this. > > f = open ("digi.txt", "r+") > > datafile = f.readlines() > > list_of_lists = datafile > for data in list_of_lists: > lstval = data.split (',') > timest = float(lstval[0]) > energy = float(lstval[1]) > > f.close() > print timest > A few questions to ask yourself. Is 'f' a descriptive name, equivalent to your other variable names? What does your third line do, and do you think it's actually required? What implications would it cause if you removed it? How do you overcome those issues? What value is stored in 'timest' the first iteration of the loop, the second, the third? (Put a print statement in the loop to find out) Are you actually doing anything with 'energy'? Do you need to wait until after the loop to close your file? HTH, Bodsda ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TypeError: can't multiply sequence by non-int of type 'float'
On 4 April 2013 14:40, Sayan Chatterjee wrote: > Dear All, > > I know this error occurs when one tries to multiply a string with a fraction > i.e float. In my case , I can't figure out how can a numpy floating point > array be a string. Interestingly, the concerned expression gets printed in > the loop for the first time but on the second go it fails. > > The concerned snippet of code is given below : > > for t in t_range(0,1,0.1): > print t > p_za=[] > pv_za=[] > > # Opening file in file_t format > fname = 'file_' + str(t) + '.dat' > fo = open(fname,'w') > > # p_za.append(p_initial - t*K*np.sin(K*p_initial)) > print 'K=',K K is somewhere above set to a float with the value 3.14... > print 'pv_za_temp =',pv_za_temp pv_za_temp is somewhere above set to a list containing an array as it's only element. > print '- t*K*np.sin(K*p_initial) = ',- t*K*np.sin(K*p_initial) > print '-K*np.sin(K*pv_za_temp) = ',-K*np.sin(K*pv_za_temp) Here you try to multiply the two. The error can be achieved like so: >>> import numpy >>> a = numpy.array([[1, 2], [3, 4]]) >>> a array([[1, 2], [3, 4]]) >>> 3.14 * a array([[ 3.14, 6.28], [ 9.42, 12.56]]) >>> 3.14 * [a] Perhaps what you want is to multiply K with pv_za_temp[0]? [SNIP] > K= 3.14159265359 > pv_za_temp = [array([[ -0.e+00, -3.14159265e+00, 6.49753967e-13, > 3.14159265e+00, -1.29950793e-12]])] Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TypeError: can't multiply sequence by non-int of type 'float'
Sayan Chatterjee wrote: >I know this error occurs when one tries to multiply a string with a >fraction i.e float. In my case , I can't figure out how can a numpy >floating point array be a string. The problem is not that the numpy array is a string but that you append the array to a python list: > pv_za=[] > pv_za.append(-K*np.sin(K*pv_za_temp)) > pv_za_temp = [] > pv_za_temp.append(np.array(pv_za)) Both "pv_za" and "pv_za_temp" are python lists to which you append a numpy array. But since you delete both lists in each iteration I assume you want to just assign a new numpy array to both names: pv_za = -K * np.sin(K * pv_za_temp) pv_za_temp = pv_za # "pv_za" is already a numpy array Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] The game of nim in python
On 03/27/2013 08:30 AM, Yasin El Guennouni wrote: Hello, I am trying to modify a game of nim code. The game in the code works as: "You need to remove from 1 to 3 straws from the pile. The player that removes the final straw is the loser." But I would like it to be like the classic game, where you have 4 piles containing 1,3,5 and 7 sticks where the drawer of the last stick is the winner. It would be awsome if I could print how many sticks there are left in each pile, e.g. : I III I III. In my opinion, you'd have to modify so much that you'd probably be better off starting from scratch. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help required
First up please give a sensible subject, say "problem parsing csv file". I'm assuming the crud shown below is due to you posting in html, please use plain text instead. On 20/03/2013 06:12, Arijit Ukil wrote: I am new to python. My intention is to read the file digi.txt and store in separate arrays all the values of each columns. However, the following program prints only the last value, i.e. 1350696500.0. Please help to rectify this. f = open (/"digi.txt"/, /"r+"/) You might like to use the with statement as it saves the explicit close later. Do you really need update mode? I'll assume not. with open('digi.txt', 'r') as f: datafile = f.readlines() datafile is a poor name, it's the contents of the file here not the file itself. list_of_lists = datafile This gives another name for datafile which you only use in the for loop, you can use datafile directly. fordata inlist_of_lists: lstval = data.split (/','/) The csv module from the standard library can look after this for you. timest = float(lstval[0]) energy = float(lstval[1]) You do nothing with timest and energy within the for loop. f.close() printtimest You're printing the last value for timest here. So you need something like the following, I'll leave you to look up the csv module if you're interested. with open('digi.txt', 'r') as f: lines = f.readlines() timestamps = [] energies = [] for line in lines: splits = line.split(',') # I'll admit not the best name timestamps.append(float(splits[0])) energies.append(float(splits[1])) # process timestamps and energies to your heart's content Regards, Arijit Ukil -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Proper uses of classes
Sorry about the indentation guys my mail service atomatically removed it when I pasted the text (I tried to fix it by hand but it was hard to tell if I was sucessful.) I was tring to create a list object (self) and change it using the list methods and some additional ones I will define in my class. I wanted to create some varibles which I pass to most if not all of my methods. Two of my variables are to be passed to the class apon creation of the object and then they in turn are to be passed to all or most of the methods I create (a, b in this case.) If I make a, b nonlocal I get the message that they are already nonlocal. I will need for debuging purposes to print my object in random places in my class. If I did this: > self.a = aWhat would that create (I'm thinking local variable?)? class alist(): def __init__(self, b, a): self.mylist = list() self.mylist.append(b) self.a = a + b def appendit(self): #I need to get a in hear without passing #it in; it must come from the init method. self.mylist.append(self.a) #(I hope I've updated the code well, I can't test it from this computer.)PS: This is not the real code that I'm Emailing: I thought I'd be better off with some simpler code that produces the same errors. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.system() with imbeded quotes
cevyn e writes: > I get the example os.system('ls -al') no problem. > > i'm trying to create a variable with my command built but needs to include > quotes. > Portion of code is as follows: > someip = '192.168.01.01' > > var1 = 'lynx -dump http://' + someip + > '/cgi-bin/.log&.submit=+++Go%21+++ > junk' > > print var1 > > os.system(var1) > > > If I print var1 it looks right . If I use the os.system(var1) as above it > seems to have a problem near the end of the string with msg > sh: .submit=+++Go%21+++: command not found > > clearly there is some escape sequence that I don't understand . > > I tried combinations of single and double quotes and mixed around var1, but > that generates command not found. > > I need it to look like how I enter it manually and works > lynx -dump 'http://192.168.01.01/cgi-bin/.log&.submit=+++Go%21+++ > > junk' > > Probably obvious to many but i'm spinning my wheels. many thanks for help . There's a pipes.quote function (in python2, available as shlex.quote in python3.3) that you can use in these circumstances. Your problem is because os.system passes the command to a shell, and the '&' character in your argument terminates the command line. Here's a transcript that shows the use of pipes.quote: In [1]: import os In [2]: os.system('echo a&b') sh: 1: b: not found a Out[2]: 32512 In [5]: os.system('echo %s' % (pipes.quote('a&b'),)) a&b Out[5]: 0 You should be able to get the effect you want by doing this: cmd = 'lynx -dump %s > junk' % (pipes.quote(url),) That said, you should take a look at the subprocess module. The functions in that module can invoke commands without invoking a shell, which avoids such problems. Untested example: with open('junk', 'wb') as output_stream: p = subprocess.Popen(['lynx', '-dump', url], stdout=output_stream) p.communicate() In this case, no quoting of the "url" argument is required. Finally, you can also look at higher level ways of doing whatever it is you're trying. See the urllib2 standard module (assuming python2 because of your print statement), or the requests module (http://docs.python-requests.org/en/v1.1.0/) which provide facilities to access different kinds of urls with varying degrees of automation. -- regards, kushal ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Doubt in for loop
On 04/04/2013 08:23 AM, Dave Angel wrote: On 04/03/2013 09:53 PM, Steven D'Aprano wrote: On 04/04/13 12:29, bessenkphilip wrote: Hi all, I'm having a doubt in the below program's 2n'd "for" loop. for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number' ... 2 is a prime number 3 is a prime number 4 equals 2 * 2 5 is a prime number 6 equals 2 * 3 7 is a prime number 8 equals 2 * 4 9 equals 3 * 3 My doubt is that "will 'x' be always of value 2, if so why that for loop "for x in range(2, n):" i don't know how the first output , as If 2%2==0:(this satisfies the if loop as x =2) , so how the else part came to output i.e 2 is a prime number. I'm sorry, I don't understand your question. x is *not* always of value 2. You can see with the last line, 9 equals 3 * 3 x has value 3. The outer loop just checks 2, 3, 4, ... 9 to see whether they are prime. The inner loop actually does the checking: for x in range(2, n): if n % x == 0: print n, 'equals', x, '*', n/x break This tests whether n is divisible by 2, 3, 4, 5, 6, ... up to n-1. If n is divisible by any of those numbers, then n cannot be prime. For example, with n = 9, the inner loop does this: x = 2 Test if 2 is a factor: does 9/2 have remainder zero? No. x = 3 Test if 3 is a factor: does 9/3 have remainder zero? Yes. So 9 is not prime, and 9 = 3 * (9/3) = 3 * 3 If we test it with n = 35, the inner loop would do this: x = 2 Test if 2 is a factor: does 35/2 have remainder zero? No. x = 3 Test if 3 is a factor: does 35/3 have remainder zero? No. x = 4 Test if 4 is a factor: does 35/4 have remainder zero? No. x = 5 Test if 5 is a factor: does 35/5 have remainder zero? Yes. So 35 is not prime, and 35 = 5 * (35/5) = 5 * 7 Notice that this does more work than necessary! Can you see what work it does that is unnecessary? (Hint: what even numbers are prime?) I don't understand the questions either, but I can point out one thing that might be puzzling the OP: When n is 2, the inner loop does nothing, it just skips to the else clause. The reason is that range(2,2) is a null iterator. range(i,j) produces values from i to j-1, or to put it another way values for which i <= n < j If i and j are identical, there's nothing to match it. Thank you very much Steven for explaining this. Yes,Dave, i was having doubt how n=2 came to else part, cleared that too, thank you . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor