Posts
 
Reputation
Joined
Last Seen
Ranked #571
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
~91.9K 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
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
306
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
231
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
397
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
357
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
818
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
202
Member Avatar for christopherbe11
Member Avatar for christopherbe11
0
155
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
272
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
427
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
214
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
240
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
372
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
252
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
153
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
244
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
243
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
170
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
541
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
266
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
226
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
176
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
781