Posts
 
Reputation
Joined
Last Seen
Ranked #573
Strength to Increase Rep
+6
Strength to Decrease Rep
-1
97% Quality Score
Upvotes Received
34
Posts with Upvotes
27
Upvoting Members
20
Downvotes Received
1
Posts with Downvotes
1
Downvoting Members
1
5 Commented Posts
3 Endorsements
Ranked #486
Ranked #425
~92.4K People Reached
About Me

de-frocked physicist

Interests
woodworking, dogs, politics
PC Specs
bodhilinux on EVEREX desktop and eeePC 701 netbook
Favorite Forums
Favorite Tags

75 Posted Topics

Member Avatar for Shaji_1

Maybe: with open('c:\FLOUpper.txt', 'r') as infile,open('c:\FLOLower.txt', 'w') as outfile: data = infile.readlines() data = [i.capitalize() for i in data] outfile.write(data)

Member Avatar for TrustyTony
0
307
Member Avatar for abaddon2031

I think there are 2 ways depending on just how big the file really is. If it can all be read into memory, then I suggest: data=[] with open(<csv file name>) as fid: lines=fid.read().split('\n') for i in lines: data.append(i.split(',')) data.sort(key=lambda x: x[3]) for d in data: field=d[3] with open('pc_Numbers_'+field+'.csv') as …

Member Avatar for rrashkin
0
233
Member Avatar for varshaholla

It seems this, `blue = IntVar()`, defines "blue". I've had poor results trying to use any widget's textvariable in Tkinter (as opposed to Tk). I think you would need to explicitly set the variable, blue, in the entry widget, blue_text, `app.blue_text.insert(0,blue)` (I think that's the right syntax).

Member Avatar for woooee
0
3K
Member Avatar for ZJRG.1997

From the [Library Reference](http://docs.python.org/2/library/stdtypes.html#set-types-set-frozenset): > The set type is mutable — the contents can be changed using methods like add() and remove().

Member Avatar for Gribouillis
0
401
Member Avatar for Yozuru

Here's my 2 cents: Let's say I have a function that turns Year,month,day into day of year: def ymd2doy(y,m,d): if y<100: y+=2000 ly=0 if (y-2000)%4==0: ly=1 md=(31,28+ly,31,30,31,30,31,31,30,31,30,31) for i in xrange(m-1): d+=md[i] return d Instead of `if (y-2000)%4==0: ly=1` I want to use a function: def leapyr (y): return (y-2000)%4==0 …

Member Avatar for slate
0
5K
Member Avatar for kangarooblood

It can be done with the eval() builtin function. **However!!!** it is very dangerous to allow users to input any old thing and then evaluate that input. It would be better to give them a limited set of choices.

Member Avatar for rrashkin
0
366
Member Avatar for fatimaashena

Unless I missed it, it seems you haven't posted your code. It would be easier (read: maybe possible) to help if we could see what you are trying to do. If the code is long, maybe just the pertinent piece will suffice.

Member Avatar for rrashkin
0
828
Member Avatar for Mithun_1

I'm not sure what your particular needs might be but the standard way of accessing another script is "import <filename>". For that to work, the accessed file either needs to be in the same directory as the running script or in the sys.path. Another, less enthusiastically recommended, way is "execfile(<fully …

Member Avatar for rrashkin
0
204
Member Avatar for christopherbe11
Member Avatar for christopherbe11
0
159
Member Avatar for lfc3798
Member Avatar for victorkvarghese

100000 isn't that big. Why not just: f=open(<your text file>) for line in f: if <your search string> in line: <do your thing> f.close() or even: f=open(<your text file>) strA=f.read() f.close() if <your search string> in strA: <do your thing>

Member Avatar for slate
0
3K
Member Avatar for CodingCabbage

There are a couple of choices. You can initalize the object with some attiributes and include methods for changing them: #class test class cA(object): a = 42 def chA(self,b): self.a = b return (self.a,b) f=cA() print f.a x=f.chA(8) print x print f.a raw_input('done') In this case "a" is an attribute …

Member Avatar for rrashkin
0
274
Member Avatar for flebber

>>> d={"key1":3,"key2":18,"key3":8} >>> d["key2"]=0 >>> d {'key3': 8, 'key2': 0, 'key1': 3} >>> s=d.items() >>> s [('key3', 8), ('key2', 0), ('key1', 3)] >>> for i in s: ... if i[1]==0: ... del d[i[0]] ... >>> d {'key3': 8, 'key1': 3}

Member Avatar for flebber
0
430
Member Avatar for peto29

So you want to embed the second loop **inside** the first loop? That's not the way it is now.

Member Avatar for Schol-R-LEA
0
218
Member Avatar for Vish0203

Are you allowed to use list comprehension which is an implicit for loop? [i*6 for i in xrange(3,0,-1)] [18, 12, 6]

Member Avatar for rrashkin
0
243
Member Avatar for WILLIAM_5
Member Avatar for srinu_1

I'm not sure how you're supposedto use re.finditer but not this way. The elements of the returned list are match objects, not strings. I suggest you use findall instead. If I do this: lst1=re.findall(r'rhs="(.*)"',d1) I get this: ['domain.com', 'domainn.com', '1010data.com']

Member Avatar for snippsat
0
373
Member Avatar for upadhyay_1

What you've shown is an array (list), that is, it's already split. What are you starting with?

Member Avatar for rrashkin
-1
254
Member Avatar for shwetha R Adiga

Not to endorse or refute the underlying concept, if you provided the rules (eg: number of vowels is greater than twice the square root of the number of "s"s) I'm sure you'd get some help.

Member Avatar for rrashkin
0
156
Member Avatar for dean.ong.14
Member Avatar for jallen111

If the file is small enough (and that depends on your memory, usually pretty big) to be read all at one go: f=open(<text file name>) strdata=f.read() f.close() c=strdata.count("abc")

Member Avatar for rrashkin
0
246
Member Avatar for speen

Everything is a function except `cSetInsert(5,4)` so that gets executed. cSetInsert tries to use "5" as the argument, "cSet". However the function treats it as a list: `cSet[hashChar(e)]` I think you intended to call cSetCreate() first and pass in the corresponding returned cSet. I don't know what you think "5" …

Member Avatar for speen
0
246
Member Avatar for RAJESH.M

If I understand correctly you're having a problem parsing the return of "version.sh" which looks like the 15-line report. Try this: Insert after "output=commands.....": outlist=output.split('\n') for i in outlist: if i.startswith("Version"): vers=i.split()[1] if i.startswith("Type"): type=i.split()[1] Then make your "result=..." however you want to format vers and type.

Member Avatar for rrashkin
0
172
Member Avatar for flebber

random.choice() will return a single element. Why are you making it a tuple? If you are trying to get the key **and** value out, you will need to do it explicitly: `k=random.choice(d_mod); v=d_mod[k]; arr[y].append([k,v])` if that's what you really want.

Member Avatar for flebber
0
542
Member Avatar for glao

You print the index after the value is incremented: index += 1 print "index: " +str(index) So the loop is iterated with the value of "index" equal to 11, then the value of index is increased but the loop is not evaluated so the processing doesn't cease.

Member Avatar for glao
0
268
Member Avatar for glez_b

Let's say d is a date string in the format you posted. Then `m=datetime.date(*map(int,d.split("/"))).month ` returns the month as an integer. You could construct a dictionary that collects the data for each month: `dctTemp[m].append(newTemp)` Then you can average the values when you collect all the days.

Member Avatar for glez_b
0
3K
Member Avatar for farmwife

I've used both and I make my decision as follows: I use Tkinter on Windows since Python installs with it and I use GTK on Linux (Ubuntu) since that's what comes with that.

Member Avatar for farmwife
0
4K
Member Avatar for Rebecca_2

First of all, you probably don't need to close and open "writer" at every step. It's just creating a lot of overhead. Open it once as you do before the loop and close it once afterward. As for the reading files, instead of `writer=open('psub', 'a')`, which I recommend you remove, …

Member Avatar for vegaseat
0
228
Member Avatar for farmwife

Within the function, you do, indeed, need to initialize y before you can start defining elements. Even then, if you try to assign elements out of order, that is, an element, [i], when [i-1] is empty, you will get the out of range error: >>> y=[] >>> y[8]=5 Traceback (most …

Member Avatar for james.lu.75491856
-1
177
Member Avatar for Taruna_1

Can you assume that each word is separated by a space (one and only one), and that there are no leading and trailing spaces? If so, let's say your list of strings is "list-1". Then you could make a list of word counts as: `list-2=[i.count(" ")+1 for i in list-1]` …

Member Avatar for Taruna_1
0
785
Member Avatar for martin.schmidt.9465

I'm guessing you're using Python 3.x where print() takes exactly one argument. Instead of `print (x)('x')(y)` you need something like ("something like" because I don't have Python 3 to test on): `print(x + 'x' + y)`

Member Avatar for martin.schmidt.9465
0
20K
Member Avatar for Swetha_1

I would start by reading the file into a list: fid=open('file1.txt') lstData=fid.readlines() fid.close() Now the last record is: lstData[-1] To loop through the records from the 2nd to last until the first, `for i in lstData[-2::-1]:`

Member Avatar for rrashkin
0
164
Member Avatar for james.lu.75491856

I'm not really clear what you're trying to do but os.system has fallen from favor and the subprocess module is recommended. Maybe that will suit your needs better.

Member Avatar for Gribouillis
0
203
Member Avatar for حسن_3
Member Avatar for حسن_3
0
315
Member Avatar for m_ishwar

look at [this](https://skydrive.live.com/redir?resid=F5DA0DF892D264EE!675&authkey=!ABykCFZUlTggjxI) for an example. Basically, the key is in the **open()**: > Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' truncates the file). Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text …

Member Avatar for m_ishwar
0
316
Member Avatar for Matigo

assuming this is tkinter, you could use **pack** instead of grid and **-side left** or **-side right**.

Member Avatar for bumsfeld
0
220
Member Avatar for AppleR

Well, when you set enemy equal to goblin, that's really just an association, not a new object. You can see an explanation of the issue and the use of "copy" to deal with it [here](http://docs.python.org/2/library/copy.html?highlight=deep%20copy). Perhaps it is simpler just to instantiate a new obect.

Member Avatar for AppleR
0
344
Member Avatar for wolf29

If you don't insist on using RE, fid=open(<csv file>) chklst=["Red Hat","Debian" , "Fedora" , "Linux"] for row in fid: for o in chklst: if o in row: print row break fid.close()

Member Avatar for wolf29
0
275
Member Avatar for goatroxley

For what you describe, I would eschew the csv module. Generally, split and append: fid=open(<filename>) lstOfLines=[] for record in fid: lstOfLines.append(record.strip("\n").split(",")) fid.close()

Member Avatar for rrashkin
0
362
Member Avatar for lewisrs89

Either make the appropriate variables class variables (by declaring them at the class level) or pass values (arguments other than "self") into the function(s) and return the computed result as a variable.

Member Avatar for woooee
0
220
Member Avatar for user45949219

First of all, unzip step doesn't really help you. You can get the ith element of each list with list comprehension: `list=[a[i] for a in column]` for a given i. To get some other set of elements as you describe will require looping through the **number** of elements and taking …

Member Avatar for TrustyTony
0
194
Member Avatar for otengkwaku

This is sort of buried in the language reference. If you look here: [Click Here](http://docs.python.org/2/glossary.html#term-argument), it gets explained, but you have to dig. In particular: > or passed as a value in a dictionary preceded by ** That means that the identifier after the "**" is a dictionary with "variable …

Member Avatar for dashing.adamhughes
0
691
Member Avatar for Rick345

I can't really follow what you're doing but if you want to print a string with all the "0"s replaced with "_" you can "replace": `>>> "11110abc0".replace("0","_") '1111_abc_'`

Member Avatar for Rick345
0
227
Member Avatar for Subomi

It's very ineffient but here goes: a= [10, 5, 2, 7, 20] b=[] for i in xrange(len(a)): b.append(min(a)) a.pop(a.index(b[-1]))

Member Avatar for vegaseat
0
293
Member Avatar for gskssit
Member Avatar for zaphoenix

The maximum height is where yvel = 0. In your initialization method you have: `self.yvel=velocity*sin(theta)` You know that yvel goes to zero when 0.98*time equals the initial velocity, or at `velocity*sin(theta)/9.8 seconds` So you can figure out when you get to that time at your interval. Now since xvel is …

Member Avatar for zaphoenix
0
2K
Member Avatar for usongo123

First a list of all the gemstones: f=open("your file name") gemstones=[] for i in f: gemstones.append(i.split(',')[1]) f.close() now a dictionary where key is gemstone and value is count gcount={} for g in gemstones: gcount[g]=gcount.get(g,0)+1

Member Avatar for vegaseat
0
184
Member Avatar for rev_ollie

I dont use WX but I don't think that matters. There's a lot of code there and I admit I didn't read it all. So I don't know really what you're doing already, but you have asked a specific question. I think I would make each sensor a different obect …

Member Avatar for rrashkin
0
220
Member Avatar for rexmorgan

Your data is in a 2-d list, data_list. The first step is finding the indices of the 2 months you want. That will accomplished on data_list[0]. index1=data_list[0].index(month1), where month1 is the starting month. Likewise, index2=data_list[0].index(month2). Now you'll loop through the elements from 1 to the end, convert the string rainfall …

Member Avatar for rexmorgan
0
3K
Member Avatar for clouds_n_things

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]

Member Avatar for clouds_n_things
0
191

The End.