134 Posted Topics

Member Avatar for TrustyTony
Member Avatar for hughesadam_87

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 …

Member Avatar for TrustyTony
0
124
Member Avatar for pythonbegginer

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 …

Member Avatar for snippsat
0
6K
Member Avatar for hughesadam_87

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 …

Member Avatar for snippsat
0
189
Member Avatar for happyhd

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 …

Member Avatar for s.v.pavani
0
10K
Member Avatar for sinnebril

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. …

Member Avatar for pk87
0
3K
Member Avatar for ckugblenu

You can really do anything with Python; however, I'd be interested to know what is "the skill"

Member Avatar for m1raEbrah1m
0
122
Member Avatar for minimee120

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 …

Member Avatar for Lardmeister
0
262
Member Avatar for learned1
Member Avatar for jone kim
Member Avatar for pakiali007
Member Avatar for hughesadam_87
0
110
Member Avatar for JenniferT1980

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 …

Member Avatar for JenniferT1980
0
182
Member Avatar for joey_r

Google's RE tutorial may be useful. http://code.google.com/edu/languages/google-python-class/regular-expressions.html

Member Avatar for TrustyTony
0
164
Member Avatar for jon92

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.

Member Avatar for woooee
1
116
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
487
Member Avatar for scott_liddle

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.

Member Avatar for hughesadam_87
0
116
Member Avatar for welshly_2010

Woooee's method is probably the most common way to do this, so I would keep it in mind for many applications.

Member Avatar for TrustyTony
0
214
Member Avatar for hughesadam_87

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] …

Member Avatar for Gribouillis
0
166
Member Avatar for moroccanplaya

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.

Member Avatar for hughesadam_87
0
121
Member Avatar for hughesadam_87

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) …

Member Avatar for hughesadam_87
0
121
Member Avatar for floatingshed

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]

Member Avatar for hughesadam_87
0
157
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
147
Member Avatar for R.S.Chourasia

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 …

Member Avatar for TrustyTony
0
6K
Member Avatar for Yoink

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 …

Member Avatar for Yoink
0
193
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
245
Member Avatar for straylight

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 …

Member Avatar for straylight
0
136
Member Avatar for Bauke

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.

Member Avatar for Bauke
0
116
Member Avatar for hughesadam_87

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), …

Member Avatar for hughesadam_87
0
1K
Member Avatar for funfullson

I'd look into the Enthought Tool Suite and read up on Mayavi. There's no simple solution to your problem.

Member Avatar for hughesadam_87
0
117
Member Avatar for sofia85

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.

Member Avatar for Gribouillis
0
151
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
222
Member Avatar for vlady

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.

Member Avatar for vlady
0
126
Member Avatar for felix001

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.

Member Avatar for hughesadam_87
0
91
Member Avatar for jefroxnergal

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. …

Member Avatar for woooee
0
481
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
178
Member Avatar for hughesadam_87

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 …

Member Avatar for TrustyTony
0
2K
Member Avatar for imGhostofYou
Member Avatar for aint

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?

Member Avatar for hughesadam_87
0
4K
Member Avatar for hughesadam_87

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 …

Member Avatar for JoshuaBurleson
0
142
Member Avatar for hughesadam_87

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 …

Member Avatar for TrustyTony
0
85
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
389
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
179
Member Avatar for JoshuaBurleson

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: …

Member Avatar for Enalicho
0
242
Member Avatar for hughesadam_87

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 …

0
56
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
405
Member Avatar for Nachodsk

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 …

Member Avatar for Nachodsk
0
236
Member Avatar for hughesadam_87

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...); …

-1
77
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
138
Member Avatar for magnetic rifle

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?

Member Avatar for Gribouillis
0
160
Member Avatar for hughesadam_87

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 …

Member Avatar for hughesadam_87
0
217

The End.