67 Discussion / Question Topics

Remove Filter
Member Avatar for hughesadam_87

Hi guys, This feels like something that should be possible in Python, and something that I feel like I should know how to do. Image I have a list of numbers: items=[10,20,30] Let's say I wanted iterate over them and define two new variables, a and b. a=[] b=[] for …

Member Avatar for hughesadam_87
0
179
Member Avatar for hughesadam_87

Hi guys, I am running a costly simulation and trying to optimize the output. I'd have a fixed range over which the parameter of interest can vary, and about 100 values it can take in between. We know the result we are looking for and want to find the parameter …

Member Avatar for hughesadam_87
0
165
Member Avatar for hughesadam_87

Hi guys, I've downloaded 2 cached_property implementations from the internet and both did not work correctly for my programs. Does anyone here used a cached_property function that works really well and could share with me?

Member Avatar for hughesadam_87
0
244
Member Avatar for hughesadam_87

Hi, I'm having some difficulty reading in boolean values from a file, particularly false values. Python can understand false values as empty strings, as well as a few other ways. For example: In [43]: bool(0) Out[43]: False In [44]: bool(False) Out[44]: False In [45]: bool('') Out[45]: False The problem is, …

Member Avatar for woooee
0
929
Member Avatar for hughesadam_87

Hi, I am trying to create the most general function possible to test if an object passed into it has mutability or not. With some prior help from pytony, it seemed that the best way to do this is to try to set and attribute. If the attribute can be …

Member Avatar for hughesadam_87
0
4K
Member Avatar for hughesadam_87

Hi, I'm curious about a few conventions. If you have a function that can return a or b based on some conditionals, which do you think is the best/accepted notation? def test(val): if val > 10: return a else: return b Or def test(val): if val>10: return a return b …

Member Avatar for sneekula
0
99
Member Avatar for hughesadam_87

Hi, I have several functions that I'd like to operate on both mutable and immutable containers (mostly tuples vs. objects) and I'm looking for the optimal way to test for mutability in these objects. I can think of many ways to do this. For example: try setattr: do mutable stuff …

Member Avatar for hughesadam_87
0
116
Member Avatar for hughesadam_87

Hi, I have an object subclass that I am using with a cusom __repr__() method. class NewClass(object): def __repr__(self): return ', '.join('%s=%s'%(k, v) for (k,v) in self.__dict__.items()) This works fine (leaving out some more details about my program): test=NewClass(a=1,b=2) print test a=1, b=2 But what I really want for reasons …

Member Avatar for hughesadam_87
0
184
Member Avatar for hughesadam_87

I have a simple class that stores attributes: In [1]: class Test(object): ...: a=10 ...: b=20 I have a function that returns attributes using attrgetter, and it accepts these through the args parameter to allow a user to pass various attribute fieldnames in. For example: In [4]: def getstuff(*args): ...: …

Member Avatar for hughesadam_87
0
496
Member Avatar for hughesadam_87

Hi, I've been having trouble posting a code snipet tonight, I keep getting this error: The code snippet in your post is formatted incorrectly. Please use the Code button in the editor toolbar when posting whitespace-sensitive text or curly braces. My code is running fine in wingware IDE with 4 …

Member Avatar for hughesadam_87
0
169
Member Avatar for hughesadam_87

I'd like to make a dictionary subclass that takes in positional keywords in addition to the standard *args, **kwargs. I found this example on stackoverflow: class attrdict(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) self.__dict__ = self a = attrdict(x=1, y=2) print a.x, a.y print a['x'] b.x, b.y = 1, …

Member Avatar for hughesadam_87
0
726
Member Avatar for hughesadam_87

Hi, I think I have a pretty simple question but my google searches are giving me more information than I need. I think my terminology is not clear. Let's say I'm making a dictionary to hold a datatype very specific to some filetype or data of interest. Let's say I …

Member Avatar for hughesadam_87
0
441
Member Avatar for hughesadam_87

Hi, I have been subclassing namedtuple to handle my custom data type: fields=['Query', 'u1', 'Accession] Old = namedtuple('Old', fields, verbose=False) class New(Old): def __repr__(self): return 'Overwriting works nicely' p=New('Hi',2,3) print p >>> 'Overwriting works nicely' What I want to do is to add the behavior that some of my fields …

Member Avatar for hughesadam_87
-1
152
Member Avatar for hughesadam_87

Hi guys, This is more a general discussion of methodology than a specific question. I have been working on a, the primary purpose of which is to store an oddly formatted data file (aka not you classic CSV). At the end of the day, the data is stored in a …

Member Avatar for hughesadam_87
0
159
Member Avatar for hughesadam_87

Hi guys, I was working with the pandas package and was so impressed with how simple something was that I had to share. Have you ever worked with csv data (in excel for example) and wanted to import the data to python, take either a column average or row average, …

1
84
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 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 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 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 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 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 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 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 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 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 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 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 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 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
Member Avatar for hughesadam_87

Hello all, Following the guide on sourceforge, I've created several pyplot programs which have nice event handling. I'm able to press keys on my keyboard and the plots advance and change. The backend for this program is GTKagg. There are several instances where I can change parameters in the plot …

Member Avatar for hughesadam_87
0
118
Member Avatar for hughesadam_87

Hey guys, Couldn't find the answer to this question in any old threads, probably because I don't know the terminology involved well enough. I have a program which takes in data and writes it into a numpy array at the beginning of a pipeline. I use a class called Masterarray …

Member Avatar for hughesadam_87
0
98
Member Avatar for hughesadam_87

Hey fellows, I've created a fairly large math suite for my spectrometer research, which is basically a set of programs that does several math operations, generates plots etc... It's beginning to get pretty bulky, and seems like it would benefit from a nice class; wherein, I could store all the …

Member Avatar for TrustyTony
0
121
Member Avatar for hughesadam_87

Hello all, I've tried to find this problem in past threads, so sorry if this is a repost. I have a large file with regular data. The file is too large for me to open it all at once, so I need to split it into evenly (preferred) spaced output …

Member Avatar for Gribouillis
0
296
Member Avatar for hughesadam_87

I have a series of data files with large headers. Here is an example: [COLOR="red"]SpectraSuite Data File ++++++++++++++++++++++++++++++++++++ Date: Fri Feb 25 13:43:55 EST 2011 User: group Dark Spectrum Present: No Reference Spectrum Present: No Number of Sampled Component Spectra: 1 Spectrometers: USB2E7196 Integration Time (usec): 11000 (USB2E7196) Spectra Averaged: …

Member Avatar for hughesadam_87
0
151
Member Avatar for hughesadam_87

I wrote a program that interactively allows you to import files directly from your HDD into another python program. When building a new program, you simply call my program, navigator, and it lets you choose a directory and it prints out a numbered list of file: file a 1 file …

Member Avatar for Gribouillis
0
162
Member Avatar for hughesadam_87

Hey guys, Tried doing a search on this, and couldn't figure out if anyone had posted it before. Basically, my question is this. I have a large python pipeline that outputs data to be compared in an ordered fashion where comparable entries are to overlay one another. For example: Entry …

Member Avatar for lolafuertes
0
84
Member Avatar for hughesadam_87

Hey guys, I've been trying to solve this problem many ways now, and am really just not familiar enough with the language to see an elegant solution. I have a dictionary, where each value is itself a list of lists. For example: [CODE]keyA:([x1,y1,z1], [x2,y2,z2] etc...) [/CODE] Within a key, I …

Member Avatar for djidjadji
0
377
Member Avatar for hughesadam_87

Hey all, I'm trying to read through a code written by a colleague last year in which he used the BioPython package. The package is no longer on my computer, and I have to wait for the systems admin to update it; thus, I'm forced to merely read the code. …

Member Avatar for keithsavin
0
114
Member Avatar for hughesadam_87

Hey all, I'm new to C and trying to pick up good habits before I get too routed in my ways. Essentially, I have a code which runs a mathematical test on an array, and depending on the percent error, it decides to continue iterating or stop. Essentially, I have …

Member Avatar for Hiroshe
0
88
Member Avatar for hughesadam_87

Hey guys, Say I had the following list: [1, 2, 2, 2, 3, 4,4] Let's assume that the list will always be integers. Does python have a built in feature which would take a sorted list, and then return the frequency that each element occurred. For example: 1 -> 1 …

Member Avatar for jlm699
0
157
Member Avatar for hughesadam_87

Hey guys, This questions is more about organization of python modules than the actual construction therein. In my project, we have several scientists performing similar analysis on several different data sets. For each project, the science changes, but the analysis often requires almost identical data handling. For example, one project …

Member Avatar for hughesadam_87
0
128
Member Avatar for hughesadam_87

Hey all, I have been reading some older posts on line/list manipulation, but don't quite understand exactly how to implement all of the tools that you guys are using (line.strip() for example) to get what I need. Essentially, I have a working program that iterates through data and outputs it …

Member Avatar for tdeck
0
21K
Member Avatar for hughesadam_87

Hey guys, I want to write a program which scans the first line in a data file and sees whether it is delimited by "\t", "," or " ". If it is any of these, I want to keep the line, else, I want to raise some sort of error …

Member Avatar for woooee
0
102
Member Avatar for hughesadam_87

Hey guys, Lets say I had two different files, each with a column of data. So: [CODE](File 1) 1 2 3[/CODE] And [CODE](File 2) Friend Foe Fighter[/CODE] In the end, I want to unify these into one large file: [CODE] 1 Friend 2 Foe 3 Fighter[/CODE] Each file has an …

Member Avatar for hughesadam_87
0
89

The End.