Re: [Tutor] Process list elements as consecutive pairs
On Fri, Mar 5, 2010 at 12:56 PM, Rüdiger Wolf < rudiger.w...@throughputfocus.com> wrote: > I am trying to Process list elements as consecutive pairs into > consecutive pairs. > Any pythonic suggestions? > > listin = [1,2,3,4,5,6,7,8,9,10] > I want to process as consecutive pairs > 1,2 > 3,4 > 5,6 > 7,8 > 9,10 > Not sure it's pythonic but zip(listin[0::2],listin[1::2]) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] merging dictionary values based on key
On Thu, Mar 12, 2009 at 4:24 PM, ski wrote: > Hello, > I have this issue, which I am unsure on how to solve. > mylist1 = {'a': 'x123', 'b':'12'} mylist2 = {'a': 'x234', 'c': 'a23'} for k in mylist2: > ... if k in mylist1: > ... mylist1[k] = [mylist1[k], mylist2[k]] > ... else: > ... mylist1[k] = mylist2[k] > ... mylist1 > {'a': ['x123', 'x234'], 'c': 'a23', 'b': '12'} > > this merges the two dictionaries, but what should be the method if: > mylist = [{'a': 'x123', 'b':'12'}, {'a': 'x234', 'b': 'd33', 'c': 'a23'}, {'a': 'x234', 'c': 'XX123'} ] > > where mylist has nth number of dictionaries and i want to merge the values > of the keys that are the same? > > Thanks > > Norman If I understand what you mean by merging, I think you want mylist = [{'a': 'x123', 'b':'12'}, {'a': 'x234', 'b': 'd33', 'c': 'a23'}, {'a': 'x234', 'c': 'XX123'} ] merged_dict = {} for dictionary in mylist: for key, value in dictionary.items(): merged_dict.setdefault(key,[]).append(value) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] update list of dictionaries based on key
On Fri, Mar 13, 2009 at 11:09 AM, ski wrote: > Hello, > Here is what I have so far: > mylist = [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': u'G3903'}, {'index': 1, 'title': 'Appointed Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': 'Association of Airline Cons.', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}, {'index': 1, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', 'affiliation_no': u'zser'}] > key = 'affiliation_no' > my_dup_keys = [] merged_list = [] > mykeys = [item['affiliation'] for item in mylist] > for x in mykeys: > if mykeys.count(x) >= 2: > my_dup_keys.append(x) > for item in mylist: > if item['affiliation'] in set(my_dup_keys): > merged_list.append(item) > > values = [d[key] for d in merged_list if d.has_key(key)] for dict in merged_list: > dict[key] = values > mylist.append(dict) > print mylist > [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': > False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Appointed > Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', > 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': > 'Association of Airline Cons.', 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}, > {'index': 1, 'title': 'Association of British Travel Agents', 'selected': > False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', u'zser']}, {'index': 0, 'title': 'Association > of British Travel Agents', 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', > u'zser']}, {'index': 1, 'title': 'Association of British Travel Agents', > 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', u'zser']}] > > > This sort of works but I want to return a list that updates 'mylist' not > append to it, so I will get: > > [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': > False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Appointed > Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', > 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': > 'Association of Airline Cons.', 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}] > It's a little hard to figure what you're getting at. This looks like a table represented by a list of dictionaries that you'd like to group by "affiliation." affiliation_nos = {} for row in mylist: affiliation_nos.set_default(row['affiliation'],[]).append(row['affliation_no']) will give you a list of affiliation_no's for each affiliation and if you want a list of dicts, you could do mynewlist = [dict(affiliation=affiliation, affiliation_nos = affiliation_nos[affiliation]) for affiliation in affiliation_nos.keys()] I don't know what to do about all the other fields though. In your example input list you have two dictionaries with affiliation = 'ABTA'. In your output you kept the one with index=0 and threw away index=1. (same for 'edit_row') How do you determine which to keep? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
On Wed, Mar 18, 2009 at 4:06 PM, Wayne Watson wrote: > Thanks to both above posts before this reply. > I'll forgo the VM route. It would really complicate things for the users of > the application having to deal with VM. Most are near neophytes. > Nevertheless, it looks like there may be some hope here for just doing it > from w/i Win OS. > > My other choice is recoding 38K lines of C code into Python. I'll pass on > that. :-) Unless there's a very good translator between languages. > I'm confused about what you want to do. If you have the code and want to call it from python, then maybe you can use something like http://www.swig.org/ is what you're looking for. What is the Red Hat dependency? I.e., what libraries are needed? Many libraries are available for windows. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] statistics with python
On Fri, Mar 20, 2009 at 6:45 AM, Bala subramanian wrote: > Dear python friends, > > someone kindly suggest me packages, modules and documentation resources > (especially) to > > i) plot graphs using python. > matplotlib is excellent and probably the most popular > > ii) statistical analysis using python. > > Your best bet is probably using the python binding for R ( http://rpy.sourceforge.net/). This also lets you use R's powerful graphing capability. Scipy.org also has some statistics packages, but nothing as complete as you can get with R. > > Thanks in advance, > Bala ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] adding dictionary values
2009/3/20 Emad Nawfal (عماد نوفل) > Hi Tutors, > I have two pickled dictionaries containing word counts from two different > corpora. I need to add the values, so that a word count is the sum of both. > If the word "man" has a count of 2 in corpus A and a count of 3 in corpus B, > then I need a new dictionary that has "man": 5. Please let me know whether > the following is correct/incorrect, good/bad, etc. > Your help appreciated: > > def addDicts(a, b): > c = {} > for k in a: > if k not in b: > c[k] = a[k] > else: > c[k] = a[k] + b[k] > > for k in b: > if k not in a: > c[k] = b[k] > return c > > # test this > dict1 = {"dad": 3, "man": 2} > dict2 = {"dad": 5, "woman": 10} > newDict = addDicts(dict1, dict2) > print(newDict) > # This gives > > {'dad': 8, 'woman': 10, 'man': 2} > > This looks like it will work, but you can accomplish this more compactly by just looping over the items in both dictionaries and making use of the default argument of the dictionaries get method. newDict = {} for k, v in dict1.items() + dict2.items(): newDict[k] = newDict.get(k,0) + v ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
On Fri, Mar 20, 2009 at 1:01 PM, Wayne Watson wrote: > To be clear. The program I'm trying to execute under Win XP was compiled > on a RH Linux machine. It was not compile on a Win OS machine. It may sound > far fetched some facility might be available to do this, but somewhere in my > very, very distant past before the small computers, these sorts of things > were possible, usually through a simulator of some sort. > Wayne, do you have the source code? From your previous responses, I think you do. If so, what is preventing you from compiling it on windows? Maybe we can help you with that. - Greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
On Fri, Mar 20, 2009 at 1:41 PM, Wayne Watson wrote: > Yes, I'm sure I'll need help. I just posted a message minutes before yours > mentioning I'm willing to try Cygwin. The C program, wolf, is the public > domain If trying to compile the program under Win is what you had in mind, > then I can send you all the necessary files in a zip file. If not, then I'll > be back to ask questions about what might be going wrong either here or in > some Cygwin newsgroup. I distantly recall there is one. > I actually found the code http://nightskylive.net/software/ from googling. A quick "make" under msys/mingw didn't complete as I'd hoped, so you'll have to put in some work, but it doesn't look insurmountable. I think this is pretty far afield from the python-tutor group though. Maybe you could try the community that uses WOLF or the cygwin group? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting with python
matplotlib and pylab are two APIs to the same library. Using matplotlib is a more object-oriented, pythonic API. pylab is modeled after the Matlab plotting functions to make it easier for those coming from that environment. There's a matplotlib mailing list and you can often figure out what you need from perusing the examples and the thumbnail gallery. In your case, I think http://matplotlib.sourceforge.net/examples/api/two_scales.html is what you want. On Fri, Mar 27, 2009 at 7:46 AM, Bala subramanian wrote: > Friends, > I am not sure if this forum is appropriate to ask question about a > particular package. After getting suggestions from some of you for python > based plotting, I have just started with matplotlib. I am bit confused with > the relation between matplotlib and pylab. > > In the matplotlib homepage, example plots are shown with both > matplotlib.pyplot and pylab. Inaddition within matplotlib, there is a module > called matplotlib.pylab > > i) matplotlib and pylab -> both are same or different modules ?. Is there > any advantage of using one over the other ? > > ii) Is it like i can plot the graphs with both matplotlib and pylab ? > > iii) can some kindly show me an example of ploting multy Y axes plot, ie > NXY. > > Thanks in advance, > Bala > > > ___ > Tutor maillist - tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Adding key, value to Dictionary
On Fri, Mar 27, 2009 at 1:31 PM, David wrote: > But I can not get this to update after the first time it is ran. > > def get_todo(): > todo = {} This set todo to an empty dictionary each time you execute get_todo. > key = raw_input('Enter Todo Title: ') > todo[key] = key > print '\n', key, 'has been added.' > print 'Next, enter date for Todo: ' > curr_date = time.strftime('%Y %m %d', time.gmtime()) > print 'Format as ', curr_date > yr = int(raw_input('\nEnter Year: ')) > mt = int(raw_input('Enter Month: ')) > dy = int(raw_input('Enter Day: ')) > hr = int(raw_input('Enter Hour (24h): ')) > mn = int(raw_input('Enter Minute (01-59): ')) > value = [yr, mt, dy, hr, mn] > todo = {key:value} > todo[key] = value todo = {key:value} again resets the value of todo. You only need todo[key]=value. > print todo > response = raw_input('Do you want to add another Todo? (y/n) ') > if response == 'y': > get_todo() > else: > print 'Goodbye' > > get_todo() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unknown reason for error.
On Thu, Sep 24, 2009 at 2:15 PM, Corey Richardson wrote: > Hello, python tutors, its Corey. > Anyway, I'm getting a syntax error for an unknown reason. Here is my > code... > name = raw_input("What is your name?") > print "Hello, ", name > wellness = raw_input("How are you?") > if wellness != "Good": > if wellness != "Well": > if wellness != "Fine": > print "Oh, I'm sorry you are not feeling well. I guessed > correct, right?" > else: print "Great!" > candyNumber = raw_input("How many candies do you want? :" > It looks like you're missing a closing parenthesis. > fat = raw_input("How many candies do you want to eat? :") > if fat > candyNumber: > print "HA! Nice try, but no. You don't have that many candies" > else print "HA! You ate the candy! Sucker. You are now", fat, "lbs > overweight" > The syntax arror is at the first fat. Thanks ahead of time, > ~Corey > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help or Advice on MySQL, Python and test data storage
On Thu, Oct 8, 2009 at 4:29 AM, David Jamieson wrote: > Hi All, > looking for some advice on using Python with MySQL for test data > storage. > While not a relational database, you might also look at http://www.pytables.org. It provides a python interface for writing to and reading from hdf5 files (http://www.hdfgroup.org/HDF5/). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with Gauge Bar.
On Sun, Aug 10, 2008 at 6:49 AM, Olrik Lenstra <[EMAIL PROTECTED]> wrote: > The program runs fine and works perfectly as the code is right now, But > while I'm asking for the bar, can I ask for some advice on the following bit > of code too? > > <<< > ##-- > ## Define all the private IP ranges that we're not going to filter in > ## the ipconfig part of the program. > ## From private4 to private19 is actually 1 range. (Needs to be looked at.) > ##-- > private1 = r"192\.168\.\d+\.\d+" > private2 = r"169\.254\.\d+\.\d+" > private3 = r"10\.\d+\.\d+\.\d+" > private4 = r"172\.16\.\d+\.\d+" > private5 = r"172\.17\.\d+\.\d+" > private6 = r"172\.18\.\d+\.\d+" > private7 = r"172\.19\.\d+\.\d+" > private8 = r"172\.20\.\d+\.\d+" > private9 = r"172\.21\.\d+\.\d+" > private10 = r"172\.22\.\d+\.\d+" > private11 = r"172\.23\.\d+\.\d+" > private12 = r"172\.24\.\d+\.\d+" > private13 = r"172\.25\.\d+\.\d+" > private14 = r"172\.26\.\d+\.\d+" > private15 = r"172\.27\.\d+\.\d+" > private16 = r"172\.28\.\d+\.\d+" > private17 = r"172\.29\.\d+\.\d+" > private18 = r"172\.30\.\d+\.\d+" > private19 = r"172\.31\.\d+\.\d+" > How about r = re.compile(r"(\d+)\.(\d+)\.\d+\.\d+") m = re.search(line[i]) if m: n1, n2 = map(int,m.groups()) # n1, n2 now have the first two numbers of the IP address Once you have n1, n2, you can check what range the ip is in and act accordingly. Greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with Gauge Bar.
On Sun, Aug 10, 2008 at 10:38 AM, Olrik Lenstra <[EMAIL PROTECTED]> wrote: > That bit of code doesn't make a lot of sense to me so far. > I don't see how that could "X" out a public address. > > (I do appreciate the help!) > > Regards, > Olrik > r = re.compile(r"(\d+)\.(\d+)\.\d+\.\d+") m = re.search(lines[i]) # search returns a match object if m: # the match object will be "None" if there is no match n1, n2 = m.groups() # n1, and n2 contain the strings corresponding to the parts # of the regexp in parentheses above # e.g., n1 == '192' and n2 == '168' n1 = int(n1) n2 = int(n2) # convert them to integers (I used the "map" trick before to do this in one line) # n1, n2 now have the first two numbers of the IP address # Once you have n1, n2, you can check what range the ip is in and act accordingly. # I left this out before, but here's how you might do the check if ( n1 == 10 or (n1 == 192 and n2 == 168) or (n1 == 169 and n2 == 254) or (n1 == 172 and n2 >= 16 and n2 <= 31)): lines[i] = r.sub("xxx.xxx.xxx.xxx",lines[i]) # using sub is a little more compact Check out the python regular expression howto - http://www.amk.ca/python/howto/regex/ Greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How Compute # of Days between Two Dates?
On Mon, Sep 1, 2008 at 10:17 AM, Wayne Watson <[EMAIL PROTECTED]> wrote: > That's the question in Subject. For example, the difference between > 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and > 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in > years between, say, 1990 and 2050. In other words not some really strange > period of time well outside our current era of history. You want the datetime module. >>> from datetime import datetime >>> datetime(2008,03,03) - datetime(2008,2,28) datetime.timedelta(4) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Message 'list' object has no attribute 'strptime ?
On Thu, Sep 4, 2008 at 2:00 PM, Wayne Watson <[EMAIL PROTECTED]>wrote: > The line > x = time.strptime(fmt_time, "%H %M %S") > with fmt_time = "11 12 40" > in function produces the msg: > Traceback (most recent call last): > File > "C:\Sandia_Meteors\Improved_Sentinel\Sentinel_Playground\Utility_Dev\SU_DateTimeAdjust.py", > line 209, in ? > if not verify_time(bump_time): > File > "C:\Sandia_Meteors\Improved_Sentinel\Sentinel_Playground\Utility_Dev\SU_DateTimeAdjust.py", > line 69, in verify_time > x = time.strptime(fmt_time, "%H %M %S") > AttributeError: 'list' object has no attribute 'strptime' > It looks like time is getting set to a list somewhere. Look at the code to figure out just what's in "time" at that point. You also might try a "print time" before that line or check it's value with a debugger. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Message 'list' object has no attribute 'strptime ?
On Thu, Sep 4, 2008 at 4:05 PM, Wayne Watson <[EMAIL PROTECTED]>wrote: > Further info. If I put > y = time.strptime("11 01 05", "%H %M %S") > both in the function and in the main body. Only the line above in the > function produces an error message. > > Here's a simple program that creates the problem. > > import datetime > > def verify_time(in_time): > time = in_time.split(":") > in_time.split(":") produces a list > if len(time) <> 3: > print > print "Invalid format. Try again. hh:mm:ss, hh is 24 hour time." > return False > y = time.strptime("11 01 05", "%H %M %S") > a list object does not have a strptime method ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Formating from hhmms to hh:mm:ss
I'm not clear on exactly what you're looking to do, but I think you want the strftime and strptime methods. See http://docs.python.org/lib/datetime-datetime.html On Sun, Sep 7, 2008 at 11:24 AM, Wayne Watson <[EMAIL PROTECTED]>wrote: > I've been writing various functions with datetime to change date-time > formats from one to another. For example, my file names have a time stamp of > mmdd_hhmmss in their names. When I need to convert, say, time by adding > seconds to the hhmmss part of the file name, I have a function that converts > hhmmss to hh:mm:ss, and another to go the other way. In between, I add > seconds. Maybe datetime can do this more easily without the use of my > functions? > -- > >Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet >"If voting made any difference they wouldn't let us do it." > -- Mark Twain > > Web Page: > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Formating from hhmms to hh:mm:ss
Is this an actual cut and paste of your code? The problem seems to be that you're getting a time.struct_time object instead of a datetime object. See below On Sun, Sep 7, 2008 at 12:52 PM, Wayne Watson <[EMAIL PROTECTED]>wrote: > Yes, that's correct., but that reference isn't doing it for me presently. > Here's a piece of code that might help explain what I'm trying to do: > > # program to test str... functions > import datetime > > Are you sure you didn't do "from datetime import datetime"? > > ... > # format conversion of date+time > dt1 = datetime.strptime("20080421_101145", "%Y%m%d_%H%M%S") > > I don't see how this works as written because the datetime module doesn't have a strptime function. > > print "dt1: ",dt1 > other = dt1.strftime("%Y%m%d_%H%M%S") <-- fails, line 11 > print other.replace(" ", "") > > Results: > dt1: (2008, 4, 21, 10, 11, 45, 0, 112, -1) > > > Traceback (most recent call last): > File > "C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/BumpSeconds", > line 11, in ? > other = dt1.strftime("%Y%m%d_%H%M%S") > AttributeError: 'time.struct_time' object has no attribute 'strftime' > > This is telling you that dt1 is a time.struct_time but I don't see how from the code you've shown here. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Formating from hhmms to hh:mm:ss
On Sun, Sep 7, 2008 at 1:36 PM, Wayne Watson <[EMAIL PROTECTED]>wrote: > Yes, cut and paste directly from the code. Positively a import as seen. > Here's the full set of code: > > # The effect of adding seconds to date-time to see if day gets changed > import datetime > dt1 = datetime.datetime(2008, 03, 10, 23, 59, 0) > print dt1 > delta = datetime.timedelta(seconds = 200) > print dt1+delta > > # format conversion of date+time > dt1 = time.strptime("20080421_101145", "%Y%m%d_%H%M%S") > > The first code you posted was different. You had datetime.strptime and not time.strptime. Your problem is dt1 is a time.struct_time which has no strftime method, producing the error. You must have imported time somewhere. This line makes dt1 a time.struct_time which causes your problem. > > print "dt1: ",dt1 > other = dt1.strftime("%Y%m%d_%H%M%S") > > Now dt1 is a time.struct_time and not a datetime.datetime object so it has no strftime method. > > ... >> # format conversion of date+time >> dt1 = datetime.strptime("20080421_101145", "%Y%m%d_%H%M%S") >> >> I don't see how this works as written because the datetime module > doesn't have a strptime function. > >> This is what you had before. Note datetime.strptime instead of time.strptime, which confused me because the datetime module doesn't have a strptime function. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sort Output
On Wed, Sep 17, 2008 at 3:30 PM, Wayne Watson <[EMAIL PROTECTED]>wrote: > I'm using Python 2.4 in Win XP. I was surprised to find the result below. > > >>> a =[4,2,5,8] > >>> b = a > >>> a.sort() > >>> a > [2, 4, 5, 8] > >>> b > [2, 4, 5, 8] > > b no longer has the same value as it began. Apparently to prevent sort from > making it the same I have to resort to copying b into a first? What is the > proper way to retain a variable with the original values of a? > You could use b = a[:]. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] deltatime difficulty
On Thu, Sep 18, 2008 at 8:38 PM, Wayne Watson <[EMAIL PROTECTED]>wrote: > What's the problem here. It seems right to me. line 9 is diff =... > > import time > from datetime import datetime > > You've imported the datetime class from the datetime module. > > def adjust_ftime(afilename, sec): > # Vmmdd_hhmmss+tag, seconds in, new mmdd_hhmmss out > ts = afilename[1:-7] # use time stamp portion > format = '%Y%m%d_%H%M%S' > d = datetime(*(time.strptime(ts, format)[0:6])) > print "sec: ", sec, type(d) > diff = datetime.timedelta(seconds = sec) > > As the output below tells you, the datetime class doesn't have a "timedelta" method. This is a variation on the same confusion between the datetime module and the datetime.datetime class you've posted before. You could fix this above by doing "from datetime import datetime, timedelta" and then doing diff = timedelta(seconds = sec) or be more explicit as use "import datetime" and then reference datetime.datetime and datetime.timedelta. (Another alternative is "import datetime as dt" and then dt.datetime and dt.timedelta.) ... > > Results: > sec: 33 > Traceback (most recent call last): > File > "C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/junk.py", > line 14, in ? > adjust_ftime('v20080120_20.xx.dat', 33) > File > "C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/junk.py", > line 9, in adjust_ftime > diff = datetime.timedelta(seconds = sec) > AttributeError: type object 'datetime.datetime' has no attribute > 'timedelta' > Hope this helps, Greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] school physics/math courses
On Thu, Oct 16, 2008 at 7:15 AM, roberto <[EMAIL PROTECTED]> wrote: > hello > (i am rather new in python ...) > > i am about to start a course of physics and math for students aged > 14-17 (high school) > and i am deeply interested in the possibilty of teaching fundamental > concepts of these subjects via teaching programming; > i chose python (i won't change my mind ...) > > so i am looking for resources on how to deal with these topics via > this great programming language; > You might take a look at VPython. I've used it before, but not for educational purposes. There are some interesting looking videos at http://showmedo.com/videos/series?name=pythonThompsonVPythonSeries ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running a script from another folder
> it looks like you're on linux - so at the beginning of your script put > #!/usr/bin/env python (I believe) and then chmod +x myscript.py > > then you can call it from the command line. > You'll also need to make sure ~myID/bin is in your PATH. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] experience/opinions with deploying python GUI app to Linux, Win32, and Mac OS X
Hi gang, I know this is probably like asking whether vi or emacs is better, but I'm looking for the best cross-platform (linux, windows, mac os x) user interface toolkit. Since the users won't be programmers, I'd like it to feel as much like a native app as possible in terms of installation. It should feel like installing any other mac/windows/linux application. I'm writing a very simple app to retrieve data from a device or import it from a file and then upload that data to a website (and possibly keep a local backup of the data using sqlite or similar).The main widget will be what in gtk would is called listview with a checkbox column for selecting which data to upload possibly as a panel within a wizard that would also have panels for selecting the device and logging into the web site. Deploying to the Mac seems to be the most difficult from what I've read. pygtk/glade seems natural for linux and even window, but 've read about difficulties with gtk on the mac, which at one point required installing X11, I believe. There's a "native" (no X11) port, but I'm not sure how mature that is. Here's what I've thought about with some pros/cons: - tkinter -- this is the obvious answer I suppose, but the widget set is limited and not pretty (out of the box at least) - pygtk -- not easy to deploy on mac? Non-native looking widgets - wxpython - complete widget set and native looking, but not sure if it's easy to deploy - jython/SWT -- I have no experience with this, but everybody has a JVM, so deploying should be easy - web app running locally -- no experience with this, but everybody has a web browser and there are frameworks like django I could use - curses -- probably not as pretty as mac/windows users would expect Any success stories out there? Thanks, Greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] experience/opinions with deploying python GUI app to Linux, Win32, and Mac OS X
Thanks for all the great replies! You've reaffirmed my #1 and #2 seeds -- wxpython and a web app. I haven't really found any show stoppers for wxpython, but I guess I was unnecessarily suspicious. dabodev.com looks like it targets my problem so that's something I'll definitely look at. I had one question about this response. On Thu, Nov 13, 2008 at 3:10 AM, Alan Gauld <[EMAIL PROTECTED]> wrote: >> - jython/SWT -- I have no experience with this, but everybody has a JVM, >> so deploying should be easy > > Of the client GUI options this is probably the easiest, but > also probably the hardest to use. Does "probably the easiest" mean "probably the easiest to develop?" Thanks again, Greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "Pointer" to a function? Storing a function as an object property? Passing arguments by value/by reference?
On Fri, Jan 16, 2009 at 7:51 AM, Vicent wrote: > > That "problem" has to contain, somehow, a property or element called > "function" which, in fact, I would like it to be a function, or a "pointer" > to a function. In python, the name of a function is just a pointer to it. Try this >>> def foo(): print "Hi!" >>> class Problem: def __init__(self,fun): self.fun = fun >>> p1 = Problem(foo) >>> p2 = Problem(foo) >>> foo >>> p1.fun >>> p2.fun >>> p1.fun == p2.fun True >>> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Translating FORTRAN (77?) to Python?
There's an absolutely incredible project call f2py http://cens.ioc.ee/projects/f2py2e/ that I've used before. It doesn't translate the code, but wraps it (which is actually better) and lets you import your library as a module. It even generates docstrings so you can see how to call the functions. On Fri, Jan 16, 2009 at 11:40 AM, Wayne Watson wrote: > I may have a need down the line to convert a large number of lines of > FORTRAN code to Python. Is there a good translator available to do this? In > the past, I've found some for translating Pascal to C, and possibly others. > -- > >Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) > > "The creation of the world did not occur at the > beginning of time; it occurs every day." -- M. Proust > > Web Page: > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] __builtins__
I'm trying to use sparkplot from sparkplot.org as a module. It's normally run from the command line and acts on an input file. I'd like to use it as a module though to render png's for a web application. Anyway, if I try "import sparkplot" from the interpreter, I get >>> import sparkplot Traceback (most recent call last): File "", line 1, in File "sparkplot.py", line 14, in min = __builtins__.min AttributeError: 'dict' object has no attribute 'min' The offending portion of sparkplot.py appears to be from pylab import * # Avoid name collisions with min and max functions from numarray module min = __builtins__.min max = __builtins__.max If I run python sparkplot.py (executing from __main__ namespace?) from the command line it works as __builtins__ appears to a name for the __builtin__ module and the __builtins__.min reference works, but when I "import sparkplot," the __builtins__ in the sparksplot module is a dict and __builtins__.min fails. In fact changing the above to min = __buitlins__['min'] eliminates the error on "import sparkplot." I think the practical answer is to clean up the namespace in sparkplot.py (get rid of the from pylab import *) as I was planning to do anyway, but I'm wondering what's behind this __builtins__ behavior. Thanks, Greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor