Posts
 
Reputation
Joined
Last Seen
Ranked #3K
Strength to Increase Rep
+0
Strength to Decrease Rep
-0
100% Quality Score
Upvotes Received
15
Posts with Upvotes
12
Upvoting Members
7
Downvotes Received
0
Posts with Downvotes
0
Downvoting Members
0
3 Commented Posts
0 Endorsements
Ranked #411
~71.5K People Reached
Favorite Forums
Favorite Tags

85 Posted Topics

Member Avatar for jrp370

For a start, use 'elif'. This will fix the problem with input of '2'. [CODE] from math import * def main(): n=input("please enter the number you wish to check:") n=abs(n) if n < 2: print("this is not a prime number") elif n == 2: print("this is a prime number") elif …

Member Avatar for vegaseat
0
265
Member Avatar for KrazyKitsune

Here is some code to help you, but you need to do some work. [CODE] # define your own function that check for prime def isPrime(x): pass def primeFactorization(num): pfactors = [] while True: j = 2 while j < num+1: if num%j==0 and isPrime(j): num = num/j pfactors.append(j) break …

Member Avatar for TrustyTony
0
178
Member Avatar for Tsepang

You can refer to Chapter 18 of this book on how to create a deck class. Think Python: How to Think Like a Computer Scientist by Allen B. Downey [URL="http://www.greenteapress.com/thinkpython/thinkpython.html"]http://www.greenteapress.com/thinkpython/thinkpython.html[/URL]

Member Avatar for Lee28
0
966
Member Avatar for [V]

You can try this as suggested above: [CODE] keys = {} for pair in results: keys.setdefault(pair[0], []).append(pair[1]) [/CODE]

Member Avatar for vegaseat
0
155
Member Avatar for qingmui

To help you get started, for recursive function, think of (1) termination condition (2) each successive step solves a smaller subset of original problem. In your case, you can solve the problem by checking the first and last characters, and passing the shorter substring with first and last characters removed …

Member Avatar for vegaseat
0
780
Member Avatar for patrickgormally

When you want to perform mathematical operations, remember to cast your string tokens into integer/float using int()/float(). There is no need to use 'eval' in such cases.

Member Avatar for patrickgormally
0
3K
Member Avatar for danholding

I think there is something wrong in your logic in the first place. Do you intend the sort the files by size? Your code is currently trying to sort a list of 2 elements containing just the file size and filename.

Member Avatar for VulcanDesign
0
528
Member Avatar for knan
Member Avatar for kur3k

another way is to use the method Enable() [CODE] # declare text ctrl txt = wx.TextCtrl(...,...) # write to text box txt.SetValue(...) # disable text box txt.Enable(False) # enable back text box txt.Enable(True) [/CODE]

Member Avatar for cghtkh
0
84
Member Avatar for Archenemie

Try to replace line 18 with following line, remember to add 'import re'. [code] fname2 = re.sub(r'%s(.*)' % toBeStripped, r'\1', c[0]) + c[1] [/code]

Member Avatar for Archenemie
0
2K
Member Avatar for gunbuster363

Go to [url]http://www.wxpython.org/onlinedocs.php[/url] and select "Alphabetical class reference", click on the widget that you are interested. This is normally what I do. However, as a beginner, I think "wxPython in Action" is a good book to begin with.

Member Avatar for cghtkh
0
107
Member Avatar for convoluted

Another way to to add the controls to a list. [CODE] # initialize controls text_ctrls = [] for x in xrange(1,4): text_ctrls.append(wx.StaticText(self, -1, "Text%d" %x, size=( (x-1)*20+10 ,-1))) # set attributes for x in xrange(3): text_ctrls[x].SetBackgroundColour(color[x]) # color can be initialized in a list somewhere [/CODE]

Member Avatar for convoluted
0
179
Member Avatar for Mollier
Member Avatar for c2q

[code] wordsingle = [] worddouble = [] for word in l: if word in wordsingle: worddouble.append(word) else: wordsingle.append(word) return [ word for word in wordsingle if word not in worddouble] [/code]

Member Avatar for cghtkh
0
132
Member Avatar for HoneyBadger
Member Avatar for planetPlosion

To check if an item exists in a list, just do: [CODE] if item in List1: # item found, add code here else: # item not found, add code here [/CODE]

Member Avatar for Gribouillis
0
113
Member Avatar for JasonQiao

Add "import re" at the top of script and line 6 should be [code] x = re.compile(...) [/code] Line 9 has 1 additional '('. Line 12 can just be [code] line = '\n'.join(s) [/code]

Member Avatar for cghtkh
-1
263
Member Avatar for sravi.pearl

From your descriptions, it seems like you just want to strip "POST" and "is vulnerable.". Can't you just do [CODE] s= s.replace("POST","").replace("is vulnerable.","") [/CODE]?

Member Avatar for cghtkh
0
128
Member Avatar for marboleon

You can try the following, assuming frame is the parent of the panel. In def __init__ of class RefreshPanel, add self.parent = parent Then, instead of frame.SetStatusText(), use self.parent.SetStatusText()

Member Avatar for marboleon
0
182
Member Avatar for zeesix

Since you already know what you want to do, just read up on how to read and write to file, and how to execute a loop.

Member Avatar for cghtkh
0
121
Member Avatar for testie

when you do [code] l.remove(l[i])[/code], your list 'l' reduces in size, so at some point, l[i] will give error because the index doesn't exist.

Member Avatar for Gribouillis
0
144
Member Avatar for JasonQiao

This problem may be solved using 're' more easily. But just to correct your mistake, do the following: 1. Change line 11 to [CODE] return int(price[:c])+float(int(price[c+1:b]))/int(price[b+1:]) [/CODE] 2. Change line 15 to [CODE] return float(int(price[:b]))/int(price[b+1:]) [/CODE] 3. Change line 22 to [CODE] return price [/CODE] You should also change return …

Member Avatar for cghtkh
0
230
Member Avatar for evertron

Line 79 should be [CODE]myCar.getVIN()[/CODE] instead of [CODE]myCar.getVIN('V81FDX')[/CODE]

Member Avatar for evertron
0
92
Member Avatar for Bluerain

[CODE] line = '''<a href="http://www.gumtree.sg/?ChangeLocation=Y" rel="nofollow">Singapore</a>''' startpos = line.find('http') endpos = line.find('>') print line[startpos:endpos] [/CODE]

Member Avatar for aml25
0
169
Member Avatar for James0l9l
Member Avatar for ChaosKnight11
Member Avatar for HoneyBadger

Some mistakes: (1) userhex.lower should be userhex.lower() (2) "addhex" function is not returning any value (3) The values of your hextable should be string i.e. [CODE] 'a':"1010" # not 'a':1010 [/CODE]

Member Avatar for HoneyBadger
0
456
Member Avatar for henryford
Member Avatar for jackocurly0074

Can you try this? Try to bind wx.EVT_IDLE in the main frame or picture frame. [CODE] # create the binding to wx.EVT_IDLE self.Bind(wx.EVT_IDLE, self.OnIdle) def OnIdle(self, event): self.Refresh() [/CODE]

Member Avatar for cghtkh
0
134
Member Avatar for patto78

For recursion, (1) there should be a terminating condition. (2) each successive call to the recursive function is solving a smaller subset of the problem. [CODE] def reduce(n): print n if n==3: # condition 1 return reduce((n-1)) # condition 2 reduce(12) [/CODE]

Member Avatar for patto78
0
204
Member Avatar for Mr Tk

This could be due to your terminal property. Try to set 'stty erase ^H' in your terminal.

Member Avatar for Mr Tk
0
3K
Member Avatar for R2605
Member Avatar for sravi.pearl

[code] a = ['1','2','3'] # use map b = map(lambda x:int(x), a) # or b = [ int(x) for x in a ] [/code]

Member Avatar for TrustyTony
0
94
Member Avatar for novice20

To help you get started, [code] filelocation = raw_input("Please enter file location:") [/code]

Member Avatar for novice20
0
84
Member Avatar for sss33

[CODE] for line in open("file"): nums = [int(x) for x in line.split()] # nums now contains a list of integer # you can add/subtract/multiply by traversing the list [/CODE]

Member Avatar for pixelss
0
75
Member Avatar for sahil1991

I agree with group256. If you already know c++, you will appreciate the beauty and simplicity of Python.

Member Avatar for sahil1991
0
110
Member Avatar for MTN

Here is something for you to start with [CODE] questions = [ ["What is the French word for one?", "un" ], ["What is the French word for two?", "deux"], ... ] right = 0 wrong = 0 for question in questions: ans = raw_input(question[0]) if ans.strip() == question[1]: ... else: …

Member Avatar for cghtkh
0
100
Member Avatar for kevintse
Member Avatar for kevintse
0
151
Member Avatar for DocBreen

Your "b2" is initialized within an "if" block which may not be executed during runtime. So one way is to initialize "b2" outside the "if" block depending on what you want. [CODE] if dungeon2 == "Volcanic Valley": ... b2 = raw_input("Select your action:") # this line may not be executed. …

Member Avatar for cghtkh
0
162
Member Avatar for Bombshock

You can try the 're' module. [code] line = "64 bytes from 74.125.45.106: icmp_seq=0 ttl=46 time=736.635 ms" mobj = re.search(r'^(\d+) bytes from ([0-9.]+): icmp_seq=(\d+) ttl=(\d+) time= ([0-9.]+) ms', line): print mobj.groups() # returns ('64', '74.125.45.106', '0', '46', '736.635') [/code]

Member Avatar for TrustyTony
0
148
Member Avatar for dustbunny000

You can create an atom class and methods. [CODE] class atom: def __init__(self, name, x, y, z): self.name = name self.x = x self.y = y self.z = z def distance(self, other): '''Implement method to calculate distance between 2 atom''' [/CODE]

Member Avatar for TrustyTony
0
847
Member Avatar for Ashena

[CODE] for line in open('testconn.txt'): if line.startswith('Domain') or line.startswith('Referer'): print line [/CODE]

Member Avatar for TrustyTony
0
14K
Member Avatar for Ultralisk

Your constructor (__init__) is defined as such [CODE] def __init__(self, tracker, timestamp): [/CODE] So when you create an instance of the class, it should be [CODE] newOrder = Order(orderNumber, timestamp) [/CODE] Alternately, change your __init__() as [CODE] def __init__(self, tracker): [/CODE]

Member Avatar for Ultralisk
0
160
Member Avatar for Megabyte89

Your description was not very clear, not sure how you want to layout your control. You can try this below, it adds some padding. [CODE] sizer.Add(fnameLabel, 0, wx.ALIGN_RIGHT|wx.TOP|wx.LEFT, 5) sizer.Add(self.fname, 0, wx.RIGHT|wx.TOP|wx.LEFT, 5) [/CODE]

Member Avatar for Megabyte89
0
981
Member Avatar for Abhishek2805
Member Avatar for pacers10

This may be what you want, to return a list of items below the mean. [CODE] def mean(alist): belowMean = [] mean = sum(alist) / len(alist) for item in alist: if item<mean: belowMean.append(item) return belowMean [/CODE]

Member Avatar for Schol-R-LEA
0
94
Member Avatar for corrwee

I suppose when he type [CODE] words = line.split(p) [/CODE] he meant [CODE] words = p.split() [/CODE]

Member Avatar for griswolf
0
239
Member Avatar for danholding
Member Avatar for cghtkh
0
378
Member Avatar for patrickm129

You can first try to follow the tutorial at [url]http://www.python.org/doc/[/url]. Alternatively, you can search online and you will find some wonderful free resources. Then come back to here when you have queries regarding the syntax.

Member Avatar for cghtkh
0
248
Member Avatar for gishi

[CODE] import re target = '<name value>my name is</name value>' mobj = re.search('<.*>(.*)</.*>', target) print mobj.groups()[0] [/CODE]

Member Avatar for Gribouillis
0
288

The End.