3,386 Posted Topics

Member Avatar for Vkitor

You better not mix up sleep with gui, tkinter has after events use them [url]http://www.daniweb.com/software-development/python/code/384025[/url]

Member Avatar for TrustyTony
0
173
Member Avatar for arson09

You are not reversing integer, you are processing a string, for integer use function divmod (or // and % operators). You do not call the palindrome_generator function, so nothing will happen.

Member Avatar for woooee
0
238
Member Avatar for DanWebb3148

Experiment with side and expand parameters to pack and use help frames! You must assign frame first and pack it separately to use it for other widgets. [CODE]def showAbout(): t1 = Toplevel(root) t1.geometry("430x300") t1.title('About Lemniscate') f = Frame(t1) f.pack(side=LEFT, expand=False) Label(f, text='Draw Lemniscate Curve', font=("Arial", 14)).pack(pady=30, side=TOP) # Can you …

Member Avatar for DanWebb3148
0
20K
Member Avatar for pwolf

You are not taking dictionary as input, this is the other direction? The dictionary has not order, so that does not matter. [CODE]>>> def print_dictionary(d): print '[%s]' % (', '.join('%s' % (0 if v not in d else d[v]) for v in range(min(d), max(d)+1))) >>> print_dictionary({0: 1, 2: 1, 4: …

Member Avatar for pwolf
0
2K
Member Avatar for usdblades

You did not post error message or something like it. Looks like you are repeating almost same code, use functions. Also why you ask hours if salary is not per hour?

Member Avatar for usdblades
0
164
Member Avatar for pwolf
Member Avatar for M.S.

If you insist on doing it yourself, the method is start[B]s[/B]with, not startwith: [CODE]data = open('contacts.vcf', 'r') name = '' number = '' if data: for line in data: if line.startswith('N;'): name = line.split(':')[1].strip(' ;:\n') if name and line.startswith('TEL'): number = line.split(':')[1].rstrip() print "%s: %s"%(name, number) name = number = …

Member Avatar for snippsat
0
2K
Member Avatar for apeiron27

Here alternative without iterator, which leaves extra digits: [CODE]def add_dash(control, to_add): as_list = list(to_add) p = 0 while '-' in control[p:]: p = control.find('-', p) + 1 as_list.insert(p - 1, '-') return ''.join(as_list) s1 = "75465-54224-4" s2 = "245366556346" print add_dash(s1, s2) """my output --> 24536-65563-46 """ [/CODE]

Member Avatar for Gribouillis
0
107
Member Avatar for huskeraider
Member Avatar for sainitin

You should consider that pattern could be split on consecutive lines. [CODE]with open('seq.txt') as seqfile: tag = 'GAAT' seqs = [(s.split('\n', 1)[0], ''.join(s.split('\n', 1)[1].split()).count(tag)) for s in seqfile.read().split('>') if s] for s, count in seqs: print s, ':', count [/CODE]

Member Avatar for TrustyTony
0
292
Member Avatar for edwords12
Member Avatar for patyypol

Post your code and explain your problem and what you have done to solve it. Do not forget code-tags.

Member Avatar for TrustyTony
0
124
Member Avatar for apeiron27

Explain what you are trying to do, and post whole relevant function. Probably you have wrong algorithm for the job. Also maybe you should be using xrange if the length of the range is big and you use Python 2. In my computer struct.pack() looks like taking around 0.88 microseconds.

Member Avatar for woooee
0
347
Member Avatar for Karlwakim

If you have computer with Python you can have it show the binary and decimal versions easily: [CODE=python] Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> for a in 0x000, 0x010, 0x011, 0x040, 0x0C1, 0x200, …

Member Avatar for jacklogan
0
153
Member Avatar for sbutler0311

Then generate primes, produce squares of them and then check through squared_primes in loop if number - squared_prime is in squared_primes.

Member Avatar for TrustyTony
0
260
Member Avatar for pwolf

[CODE]def splitWord(word, length): r = [] for count in range(0, len(word), length): r.append(word[count:count+length]) return r [/CODE] Your capitalization is idiosyncratic (probably due the site not following the [URL="http://www.python.org/dev/peps/pep-0008/"]PEP8[/URL]

Member Avatar for pwolf
0
894
Member Avatar for chebude

else part of try is for the case of no exception happened, there is exit function and same you can do also by raising SystemExit, using function like above is also good idea to organize code. You can raise exception in function and handle it in calling function if you …

Member Avatar for chebude
0
360
Member Avatar for apeiron27

Of course then [CODE]>>> a[::-1] < b[::-1] True >>> [/CODE] But it is questionable if this is faster than simply unpacking them before compare: [CODE]>>> def less_packed(a,b): return unpack('<I', a) < unpack('<I', b) >>> less_packed(a,b) True [/CODE]

Member Avatar for TrustyTony
0
125
Member Avatar for drlockdown

You have completely misindented the code and you are using input for inputting string, also all those str functions look ugly, take a look of [B]% [/B]string formatting or [B]format [/B]method for neat printing.

Member Avatar for snippsat
0
194
Member Avatar for Malraux
Member Avatar for arunpawar

This does not sound to have any use but here my puny efforts: [CODE]import re st="big brown fox jumps over the lazy dog. fox chases mice, dog chases fox" print re.findall('fox', st), re.split('fox', st) #more usefull print re.findall(r'[^.,!?]+[.,!?]', st) #in Python print 'fox' in st, st.count('fox'), st.split('fox') [/CODE] Output [CODE]['fox', …

Member Avatar for TrustyTony
0
216
Member Avatar for Malraux

[CODE]>>> def split_hex(n): print '%02x %02x' % divmod(n, 256) print '%c%c' % divmod(n,256) return '%c%c' % divmod(n,256) >>> split_hex(2012) 07 dc Ü '\x07\xdc' >>> [/CODE]

Member Avatar for TrustyTony
0
230
Member Avatar for pwolf

Efficient way is to use min and sum on list input, at least it is generalizable. On the other hand the input is so simple, that it is possible to easily spell it out, so your solution is a valid one also. Using general function is much more complicated to …

Member Avatar for TrustyTony
0
247
Member Avatar for pwolf

There is built in find method, which I think you should implement yourself as exercise. Use loop to check for every possible starting place. Initialize the result variable to -1.

Member Avatar for TrustyTony
0
186
Member Avatar for pwolf
Member Avatar for pwolf
Member Avatar for apeiron27

sort(mylist) if you want raising order, otherwise you should user reverse parameter.

Member Avatar for TrustyTony
0
60
Member Avatar for pwolf
Member Avatar for Joelx

Just reset flag after writing the line out, alternatively: [CODE]save = '' with open('test.txt') as f, open('outfile.txt', 'w') as f_out: for line in f: if 'line 2' in save: f_out.write(line) save = line '''Output--> line 3 ''' [/CODE]

Member Avatar for Joelx
0
181
Member Avatar for pwolf
Member Avatar for sofia85
Re: R

Maybe you should use interactive prompt to get feed back of your syntax. Even you had two different ways in your arrays, both the prompt did not accept. This seemed to work: [CODE]> x <- c(10.4, 5.6, 3.1, 6.4, 21.7) > y <- c(12,5.6, 7.2, 1.0, 9.3) > plot(x,y) >[/CODE]

Member Avatar for TrustyTony
0
92
Member Avatar for TrustyTony

Inspired by discussion in [url]http://www.daniweb.com/tutorials/tutorial238544.html[/url] (test cases are from there) I used my magic pattern matching function transformed from numbers and adding the parts length checking loop. I like my own solution better, I do not know about you.

Member Avatar for TrustyTony
0
2K
Member Avatar for adrain91

I did not get same error, but you did not decode bytes. [CODE]import urllib.request import sys import webbrowser #'http://www.imdb.com/list/SuSZdwCyHzU/' def savePage(urll,filename): page=urllib.request.urlopen(urll).read() print(page) sys.argv[0]=filename with open(sys.argv[0],'w') as outfile: outfile.write(page.decode('utf8')) savePage('http://www.daniweb.com/software-development/python/threads/406620/1735920#post1735920','outIMDB.html') webbrowser.open('outIMDB.html') [/CODE]

Member Avatar for richieking
0
438
Member Avatar for Gribouillis

It is quite unclear which is the 'five lines'. You could reduce this terrible code bloat ;) by using the short function exception from PEP8 and put __init__ and __get__ definitions in single line also the example could use tertiary if handling the one word difference in printed strings. Cheers, …

Member Avatar for TrustyTony
1
435
Member Avatar for Valex

OK, take a look at [url]http://www.daniweb.com/software-development/python/threads/32007/1122938#post1122938[/url] (it has some space for improvement as code is quite old, but should do as example).

Member Avatar for Valex
0
2K
Member Avatar for debasishgang7
Member Avatar for snippsat
0
286
Member Avatar for Azmah

Basic math is of course simple, but got myself mystified sometimes with exponentiation (shame on me, and I got stipend of best mathematical science student in my graduation year 1984 in my town): -1**0.5 is valid formula (-1^0.5 some languages).

Member Avatar for BDove
0
2K
Member Avatar for vikaram

You have brittle code by using the input for numbers, so your program crashes if input letters or empty line. You are calling menu instead of returning from submenu, so when you quit after from main menu, you will end up in submenu. Good design of submenus is to have …

Member Avatar for vikaram
0
325
Member Avatar for AdampskiB

Seconds resolution is too coarse for binary search, move to milliseconds: [CODE]def main(): lst = [] result, length = 0, 500000 while result <= 0.50: for i in range(length): lst.append(randint(1, length)) value = randint(1, length) t0 = time.clock() linearSearch(value, lst) result = (time.clock() - t0) * 1000 print("This LINEAR SEARCH …

Member Avatar for AdampskiB
0
161
Member Avatar for TrustyTony

While looking into [URL="http://www.had2know.com/academics/gaussian-prime-factorization-calculator.html?blankone=2&result="]Gaussian primes [/URL]I came to think additional ways to check for is number integer or not, what you think is best way? [CODE]epsilon = 1e-11 def is_integer(n): """ traditional abs, epsilon check for near integer """ return abs(n-round(n)) < epsilon def is_integer2(n): return (float(n)- int(n)).as_integer_ratio()[1] == 1 …

Member Avatar for TrustyTony
0
292
Member Avatar for arunpawar

You are typing your function to new window in IDLE, by Ctrl-N or File - New Window aren't you? Then you can just choose to run the file with F5 or choose Run - Run Module from menu.

Member Avatar for arunpawar
0
362
Member Avatar for natehome

You could compare [URL="http://www.daniweb.com/software-development/python/code/371844"]with mine[/URL], use numpy or shedskin like me and/or do profiling

Member Avatar for TrustyTony
0
151
Member Avatar for KrazyKitsune

You do not need to test all numbers neither test for prime as factorin wjile loop ensures prime. You can test for only valid prime candidates n * 6 +- 1 after testing with 2 and 3. BTW this is old solved thread and I do not know how much …

Member Avatar for TrustyTony
0
179
Member Avatar for Cenchrus
Member Avatar for ni5958

The result should include sublists of length k which do not contain first element and lists of first element followed by all sublists from other elements of length k - 1, when length of argument is more than k.

Member Avatar for Gribouillis
0
3K
Member Avatar for betty2
Member Avatar for khajvah
Member Avatar for telmo96
-1
111
Member Avatar for chris99

Do you have possibility to upgrade? Admin rights and not any incompatible modules you use? For example if you use psyco, you need to keep to Python 2.6, but I think most things should at least work with that. Latest Python 2 is Python 2.7.2.

Member Avatar for chris99
0
2K
Member Avatar for pwolf

If you want to prepare package called MyModules, and the parent directory is in your PATH or PYTHONPATH, then you should create an empty file called __init___.py in the directory and import the module as MyModules.polymod. If you want to import all your modules from this directory and they are …

Member Avatar for pwolf
0
578
Member Avatar for hovestar

Your style is bit esoteric, especially using multiline single quotes everywhere, here is maybe little more conventional way: [CODE]def grid(x, y): first = (3* ' ' + ''.join('%c'.center(7) % (ord('A') + n) for n in range(x)) + '\n ' + (6 * '_') * x + '\n') rest = (3 …

Member Avatar for TrustyTony
0
494

The End.