134 Posted Topics
Re: Any idea when this is going to happen roughly? | |
Hi, If I have a list of strings, it's easy to output them using .join(). For example: mylist=['hi', 'there', 'girls'] myout='\t'.join(mylist) What I want to know is if there is a builtin python method that acts like join, except it automatically converts ints and floats to strings without giving a … | |
Re: There are several ways. The easiest way is to use a python list. The more complicated way is to use a dictionary. The advantage of the dictionary is that if later down the road, you need to retrieve some of the original information (for example, the entire line that corresponded … | |
Real quick question. If I have a string 'hi my name is bill' and I want to reduce this to a list of letters, with no whitespaces (eg ['h', 'i', 'm', 'y'] as opposed to ['hi', 'i', ' ' , 'm', 'y', ' ', 'n'...]), is there a really quick … | |
Re: This is cool bud. I think if you have enough understanding of OOP to make this chess game, you ought to start learning the Enthough Tool Suite. The Enthought Tool Suite will let you rebuild this program with a total GUI and other things without adding much. I know this … | |
Re: You can use f.readlines() to bring in your entire file into a list. By default, then use some manipulation to split this list at the '\n' characters and write each row into a dictionary. Then you can access rows by a row number keys and columns by a value key. … | |
Re: You can really do anything with Python; however, I'd be interested to know what is "the skill" | |
Re: For 6 and 7, you should look into the module itemgetter() (Do a ctrl+f for getter on this page: http://docs.python.org/library/operator.html) If you have simple items in a list, for example a list of ints: mylist=[1,2,5,3,7,8] Then you can use simply mylist.sort() to sort them. If you have strings, it will … | |
Re: Post your best try so far and then we can give you help with it. | |
Re: Yeah you have to put in an effort, we can't do homework for you. | |
Re: Look. I honestly can't make it through all that code but I can say that I used TK to roll my own GUI's and always found eventually the GUI code would end up longer than the source to begin with. I just posted this tutorial on a package that will … | |
Re: Google's RE tutorial may be useful. http://code.google.com/edu/languages/google-python-class/regular-expressions.html | |
Re: You'll want to read up on the "raw input" function in python. You can use it to enter anything (integers, strings, floats) directly from the command line to the program. | |
Hey everyone, Last semester my buddy and I made a tutorial on application programming in Python. This video uses the Enthought Tool Suite (ETS), a free powerful Python development toolkit, to build quick, easy and powerful GUI's. I see many posts on this site about Tk, wx, qt but haven't … | |
Re: You can shorten this: [CODE] for line in responsesfile: line = line.strip() parts = [p.strip() for p in line.split(' ')] responses[parts[1]] = (parts[0], parts[2]) return responses[/CODE] By doing this: [CODE]responses={line.strip()[1] : (line.strip()[0], line.strip()[2]) for line in responses file} [/CODE] Note this syntax is only valid for python 2.7 or better. | |
Re: Woooee's method is probably the most common way to do this, so I would keep it in mind for many applications. | |
Hey guys, I've looked over several Google results for basic explanations on [CODE]is / '=='[/CODE] However, I don't think I quite understand enough to know what is the ideal operator for this. [CODE]mylist=[1,2,3] if type(mylist) == list: print 'yes'[/CODE] or do I use [CODE] if type(mylise) is list: print 'yes'[/CODE] … | |
Re: Maybe I am misunderstanding, but you'd simply take the self.textWidget (which seems to be the only class/instance variable in this problem) and make it either a global variable, or pass it to your method as an argument. | |
Hey guys, In prepping for a job interview, I'm trying to eliminate some bad habits and this trivial problem has me realizing how hard that is :'(. The problem: Print a 12 x 12 multiplication table. This is easy.... [CODE]outstring='' for i in range(1,13): for j in range(1,13): outstring +='\t'+str(i*j) … | |
Re: One simple way to sample a list while skipping elements with with the following syntax. [CODE] a=[1,2,3,4,5] b=a[::2] #means sample all elements with spacing = 2 print b >>>[1,3,5] c=a[2::2] #means sample all elements with spacing =2 starting from the 3rd element[/CODE] | |
I've followed a tutorial where a Person class was used to illustrate the difference between class and instance variables. Something like: [CODE] class Person(object): population=0 def __init__(self, name): self.name=name Person.population += 1 print 'current population', Person.population Sally=Person('sally') Joe=Person('joe') [/CODE] This example really illustrated the difference between class and instance variables … | |
Re: I think the builtin filter method in python will also do this, but it might not be so straightforward. Vegas's answer will extend to dictionaries if you use: [CODE] for item in A.iteritems(): for item in B.iteritems():[/CODE] etc... However if you can't use loops (which is dumb IMO) then you … | |
Re: There are numerous solutions to this problem, but perhaps one that is most straightforward is to just put all your items in a list of lists. Or a tuple of lists, or a dictionary of lists...etc there's many advanced storage options in python. Here's a list of lists: [CODE] def … | |
Hey guys, I have a simple numpy datatype: [CODE]spec_dtype = np.dtype([ ('wavelength', float), ('intensity', float) ])[/CODE] I chose to use this in my program because it's very easy to read in 2-column spectral data files using the genfromtxt() method. Therefore, I made a fairly sizable program around this datatype. Now … | |
Re: Does this functionality have to be incorporated in the function itself? It doesn't seem like something you'd want to use a function for at all. The functions are meant to not be aware of the global operations of the program, so it's not straightforward to have the function be aware … | |
Re: At the bottom of the thread there should be a link that says "blah blah is this solved then Mark as Solved" where the "Mark as Solved" is a hyperlink. Just click that. Use ctrl+F to find it quicker in your browser if you don't see it. | |
I have data which has a very particular format that I'm trying to store in a numpy array. avi_05MSalt00001.txt 2012 Feb 07 20:12:41 50000 (usec) 300 10 I've defined the following numpy datatype: [CODE]timefile_dtype=numpy.dtype([ ('filename', file), ('year', int), ('month', str), #Why don't these work? ('day', int), ('time', str), ('int_time', int), … | |
Re: I'd look into the Enthought Tool Suite and read up on Mayavi. There's no simple solution to your problem. | |
Re: Same with me. Post a sample of the data file so we know how your data is structured then try to explain exactly what you do more clearly and we can suggest a better code. | |
Hey everyone, I have a set of classes which, when instantiated, take up a lot of memory. I'm trying to write a program which can inspect class attributes and methods given a list of classes, without actually instantiating them. Let's say I wanted to see if the following class had … | |
Re: I feel like this is too complicated for what you want to do. Can you clarify what you want to do and we could suggest a more simple class structure for it. | |
Re: Sys is standard for most python distributions, so at the top of your code, just put the line: import sys and you'll have all the features therein. | |
Re: You define the variable b inside of these private methods, so it doesn't exit outside of the methods. You define it in add, but it is not passed to the other methods. The way you are setting this up, it's suitable for object oriented programming, meaning you should use classes. … | |
Hey everyone, I've been using python quite a bit to develop scientific applications. As of late, the Enthought Tool Suite is proving to be one of the handiest set of development tools out there. One question I have is, with commercial software, I often see the ability to plugin output … | |
Hey everyone, this should be simple, but I keep running into errors so help is greatly appreciated. I have a large class, call it class A, which has several methods. Most of these methods modify data. [CODE]ClassA() def __init(X,Y,Z) ... .. def data_mod1(): ... def data_mod2(): ... [/CODE] I'm dealing … | |
Re: Which solution did you end up using to make the exe | |
Re: Can you be more specific about exactly what you want to plot. You have a list of numbers. You wanted to do some operations, like normalization and stuff... after you did all of these, what would you be left with? Strictly an array of numbers still? | |
Hey everyone, I'm checking some bessel functions in python using mathematica, and I can't find anything online about how to import values into python with exponentials. I know how to values with exponents. For example: [CODE]x=2032.43 * 10 **23[/CODE] However, when I read in a data file, say with one … | |
Hey all, After beating my head against the wall with this, I decided to post. I'm using f2py, a wrapper to call Fortran routines from python. I can't use it because my current version of gcc does not support f2py. According to a posted solution, I have to edit my … | |
Hey everyone, I've tried extensively to find a thread like this already, so I hope it's not a repose. Basically, I have a program with a nice GUI (Tkinter) which has a frame which takes in matplotlib figures. I am able to connect the plots to the Tkinter frame this … | |
Hey everyone, I'm making a data analysis suite in python, and want to construct a custom event handler which will reset the axis based on the data in the current subplot. To do so, I need the event handler to know what data is currently in the subplot. The matplotlib … | |
Re: I'm not so great at explaining all the nuts and bolts of classes, and probably have some bad habits, but I've fixed your code so that it at least works: [CODE]class OffSwitch: def __init__(self): self.keycheck='off' def turnOff(self, key): print key, 'hi' if key==self.keycheck: SystemExit else: print('will continue') switchword=str(raw_input('Enter a word: … ![]() | |
Hi all, I have built a small event handler to zoom in on a graph on pyplot figure, and then I use the builtin pickline event handler to select a line. I plot multiple lines from a large dataset of ordered series, so when I choose one, I need my … | |
Hey everyone, I'm in the process of writing a data analysis program with a full GUI. The program is turning out to be quite useful for the spectral analysis we do in our lab, so I'd like to share it with my colleagues. Perhaps if it catches on, I would … | |
Re: Hi, That game sounds like a good motivator to get started. I wrote a text-based rock paper scissor game to learn early on. Your best bet is really not a book, but a good online tutorial. I don't remember the ones I followed; however, this one looks good. [url]http://docs.python.org/release/2.5.2/tut/tut.html[/url] Read … | |
Hey everyone. I have a matrix of matricies. Basically, I have a 3 dimensional matrix object which stores i 2-d arrays. For example: M=(i,j,k) A= M[1,:,:] = (j, k) B= M[2, :, :] = (j', k') etc.. Now, what is want to do is actually do the entire product (A*B*C...); … | |
Hey guys, I am writing a GUI program, and one of the routines requires that I choose a file to be my data file. If the data file is chosen correctly, then my program will send it to a subroutine which will perform a bunch of methods and ultimately construct … | |
Re: What do you mean random vector? Is this a vector in a mathematical sense, or do you mean an array/list? Also, what's random about it? The entries? | |
Hey everyone, I'm getting familiar with TkInter, and while it's a cool program, I'm having a hell of a time with keeping all the classes straight. As of now, I'm trying to build a program with a menubar and some other widgets. I can get the program working if I … |
The End.