75 Posted Topics
Re: I would need more information to answer that. What is the structure of the dictionary? Normally, I would key an address book on "name" so something like AddBook={"john doe":("8134789 Zubruzlechester", "Alpha Centauri", "999-555-1234")}. In that case I would get the telephone number, for instance, for John Doe, as: AddBook["john doe"][2] | |
Re: check out the pickle module (I think it still is used with v3.x) | |
Re: colorcode="#00ffaa" strBase1="blah blah blah kjklajaskladfjlkjasdf maxMass=" strBase2="blah blah aiopweruioweruio minMass=" strBase3="blah blah iqweuiqweru890 colorCode=" strBase4="2389023489asdfjkl qwruijasdfjklha fasdfasdf" chrDelim="," f1=open(<input file name>) f2=open(<output file name>,"w") for strLine in f1: lstLine=strLine.strip('\n').split(chrDelim) colorcode=colorcodefunction(lstLine) strOut=strBase1+lstLine[0]+strBase2+lstLine[1]+strBase3+colorcode+strBase4 f2.write(strOut+'\n') f1.close() f2.close() | |
Re: When you identify a duplicate, let's say there are 2, do both get written to the file or just the one that wasn't first? | |
Re: I think this is the culprit: Resistance.append(tuple((float(x) if x.strip() else '0.0'). On the one hand it's number, on the other, a string. | |
Re: I'm not sure I follow. If it's a random number, then it won't point reliably in either direction, no? Is this maybe what you want? There is a list of hints, lstHints. For each element of lstHints, there is a tuple, (n1,n2), where lstHints[n1] is that element and lstHints[n2] is … | |
Re: Let's forget the altitude component for now since I don't think you're really mapping in 3-d here. So you have a series of lat/long. Let's say you know how to convert that to a more convenient x/y system. Now, if your track is a straight line, then you can easily … | |
Re: You've got the right idea but I think you're doing something you don't want to do and I know you're doing something wrong. First the wrong thing. When you read each line, `for line in f.readlines():`, "line" is a string. Strings are iterable but each character is an element. So, … | |
Re: I don't use the csv module much (at all); I find it just as easy to manipulate csv files manually. That said, if len(timelist) is 1, that sounds a lot like the csv.reader doesn't know your delimiter is ";". Also, according to the documentation, the open() statement needs to specify … | |
Re: You could initialize a dictionary, then use the first column as the key and accumulate a growing value separated by some character you don't expect to find in the data, like, say, "_": >>> d={} >>> d["test"]="_".join((d.get("test",""),"abc")) >>> d["test"] '_abc' >>> d["test"]="_".join((d.get("test",""),"xyz")) >>> d["test"] '_abc_xyz' >>> where instead of "test" … | |
Re: Look. It's a bit presumptuous, if not rude, to ask people to do your homework without even making a token attempt, yourself. Do you have any code written? Do you understand classes/objects at all in some other context maybe? Think of it this way: There is a class, "patient". Objects … | |
Re: You need to 1 - remove the linefeeds from the input line (line=line.strip('\n')) 2 - split the line into a list (lstLine=line.split(',')) | |
Re: What graphics module are you using? In Tkinter, there is nothing called an input box. Rather there is a widget called an "entry". It has no title, but you can fit it with a "label". Likewise, pyGTK, has a "text" and "label". In non-GUI python, "input" is a command indicating … | |
Re: Code tags are better when just the code is tagged. Still, better than no tags at all. I don't see how the code you posted does anything at all. The lists are instantiated outside of the functions and in the case of newList(), not even used. Let's see what might … | |
Re: Since you title your post with "...csv file", I'll assume you're reading this table one row at a time from a comma delimited file. So, let's say you've opened the file as fid (i.e., fid=open(<file name>)). Then you read through the file, strip off the line feed, split the line … | |
Re: your question was answered in devshed | |
Re: I'm not entirely sure I follow but let's say you have (as in your example) 11 fields separated by commas. You're going to check if the value of the first element (index 0) has one of several values and if so, and if the value of field-x is equal to … | |
Re: for the first type, 21 - 27 Nov 2012: ` >>> import re >>> s="abcd efgh 44 - 88 Dec 2012 xyz" >>> pat=r'\d{1,2} - \d{1,2} \w{3} \d{4}' >>> m=re.search(pat,s) >>> m.group(0) '44 - 88 Dec 2012' ' for 1 Dec 2012 and 26 Nov 2012: `pat=r'\d{1,2} \w{3} \d{4}` for … | |
Re: change `z = setup.readline()` to `z = setup.readline().strip('\n')` | |
Re: I'm not sure what you're asking. If you mean how many sidereal days in 7 24-hour days: >>> 7.0*24/(23+56.0/60) 7.0194986072423395 | |
Re: A dictionary isn't really a natural implementation of a database. I suppose you could have each row be it's own dictionary such that row1={key1:value1, key2:value2,...} and likewise for all rows. Then you'd get the value in column3, row3 from row3[key3] or something like that. I think a better implementation is … | |
Re: I think the csv module is overkill for most applications. I'm not sure I follow what the format of your data file is but let's say each line in the CSV file has n fields separated by ";". Depth is in field i (starting from 0), time is field j, … | |
Re: There is obviously something missing: the creation of the list, obs. Given that, the method, add(), updates the values in prior and total for each element of obs. The method, discr(), looks like it's updating something like a grade point average for each element in obs. The method, classify(), looks … | |
Re: You should, of course post the error but frequently the problem is that the backslash, "\", is used by Python as the escape character. You should either use the forward slash, "/" or escape the backslash, "\\" in your paths. | |
Re: Probably, the way you're executing the script is making the default directory other than where you have the file. Try fully qualifying the file name. |
The End.