4,305 Posted Topics
Re: I don't get it? | |
Re: This works with Python 2.5 ... [code=python]# from http://pypi.python.org/pypi/processing installed: # processing-0.52.win32-py2.5.exe from processing import Process def func(name): print 'hello %s' % name if __name__ == '__main__': # initialize thread p = Process(target=func, args=('bob', )) # starts thread p.start() # waits until thread is done p.join() [/code] | |
Re: What storage does your matrix use, CDS or JDS? | |
Re: Most people call it HTML Scraping. The programs are called HTML Scrapers. Easy to do with Python, don't know about C. | |
Tired of the Tk icon in the corner of the form. It's easy to replace with any fancy icon you have. Here is the code ... | |
Re: You can also look into the the code snippet called "Story Statistics" that creates dictionaries (Python containers) of words and characters in a story text. Just amazing what you can do with those dictionaries. See: [url]http://www.daniweb.com/code/snippet228125.html[/url] | |
Re: You are getting tangled up in a forest of parenthesis. There is one missing in the mess. It is best to break things into smaller parts ... [code=python]list_a = [1,2,3,5,6,7] list_b = [4,5,6,7,8,9,10] # for convenience list_ab = list_a + list_b average = float(sum(list_ab))/len(list_ab) offset = float(len(list_b) - len(list_a)) a … | |
Re: As a hint, here is a slow but simple prime number algorithm ... [code=python]# slow and simple algorithm to find prime numbers # prime numbers are only divisible by unity and themselves # (1 is not considered a prime number) limit = 20 # 2 is the first prime number … | |
Re: [QUOTE=jaymeaux77;1001071]Hi, I am fairly new at the whole programming racket and I am having trouble with an assignment for my computer science class. I know homework help is discouraged ...[/QUOTE]We will give you homework help, as long as you show an effort! However, we will not do the homework for … | |
Re: [QUOTE=masterofpuppets;1005119]Probably you get the error because you are using the input() function when for textual input you should use raw_input() By the way you could use input() but you need to put whatever you type in quotes "" otherwise they can be omitted :) hope that helps[/QUOTE]Looks like the OP … ![]() | |
Re: Take a good look at: [url]http://www.daniweb.com/tutorials/tutorial45806.html[/url] | |
![]() | Re: [code=python]app = 'abc' app1 = 'def' my_input= 'xabcdefgh' # find() returns the index at which app+app1 ('abcdef') # appears in string my_input, this should print output if my_input.find(app + app1) == 1: print "output" [/code]Do not under any circumstances use 'input' as a variable name for your string! If you … |
Re: Dictionary key searches are highly optimized, since Python itself uses dictionaries internally. There are entire articles published that recommend converting a long list into a dictionary for fast searches. Still faster than a list search even with the time it takes to convert. I remember seeing one of these articles … | |
| |
Re: Running a little test program will help you a lot ... [code=python]word = "index" # print first character of word at index=0 # index is zero based print word[0] # i # print third character of word at index=2 # since the index is zero based you count 0, 1, … | |
Re: If you want to know what is going on, put in a temporary test print ... [code=python]... ... while word: position = random.randrange(len(word)) jumble += word[position] word = word[:position] + word[(position + 1):] # for test only ... print position, jumble, word ... ... [/code] | |
Re: Use pythonw.exe to run your GUI programs, it avoids the console screen. | |
Re: Pick a project. something you are interested in. Maybe an image viewer, a slide show, computer generated random or fractal art, a database for your baseball cards, a story writer, ... | |
Re: Better late than never ... [code=python]# use PyQt to play an animated gif # added buttons to start and stop animation # tested with PyQt4.4 and Python 2.5 # also tested with PyQt4.5 and Python 3.0 # vegaseat import sys # too lazy to keep track of QtCore or QtGui … | |
Re: Hint ... [code=python]n = 123452267 # convert number to a string s = str(n) # count the number of '2' in the string print s.count('2') [/code] | |
Re: I suggest you write yourself a small test model program. | |
Re: jice is right. Judging from raw_input() and the print statement you are using a Python2 version. There the '/' will do an integer division if you have integers, so 2/5 would give you zero. This has changed with the advent of Python3 where '/' will give you a floating point … | |
Re: Check your Python code file, should have extension .py, and make sure the first active code line (other then comments) is something like ... [code]from __future__ import with_statement [/code]The above import line for example is used by Python25 if you want to use the [B][COLOR="Red"]with[/COLOR][/B] statement, which has become standard … | |
Re: You actually picked a strange example where the floating point representation error makes a difference ... [code=python]r = 6.0 while r < 6.4: print r r += 0.1 """my result --> 6.0 6.1 6.2 6.3 6.4 <--- oops! (float rep of 6.4 --> 6.3999999999999986) """ [/code]This works correctly ... [code=python]r … | |
An example of a range generator that handles floating point numbers, appropriately called frange(). The function range() or the generator xrange() can only be used for integers. Note that xrange() now is range() in Python3. | |
Re: In an ideal world your html code could look like this ... [code=html]<html> <head> <title>My Title</title> </head> <body> <b>Hello there</b> </body> </html> [/code]However you may as well expect this ... [code=html]<html> <Head> <title>My Title</title> </head> <body bgcolor="Yellow" text="#6600FF"> <b>Hello there</b> </BODY> </Html> [/code]Putting this in a list of lists would … | |
Re: Try this ... [code=python]# This script will determine the size if the gwarchive directories # in everyone's home folder import os folder_size = 0 for username in open("L:\\dirl.txt"): folder = "L:\\" + username + "\\gwarchiv" print folder for (path, dirs, files) in os.walk(folder): for name in files: filename = os.path.join(path, … | |
Re: If you have time, post the solution you came up with. | |
Re: Tkinter is somewhat finicky about persistent images. Take a look at this example where I had to create a photo list to make the label list work. Not quite sure how those two lists connect: [url]http://www.daniweb.com/forums/showthread.php?p=1001448#post1001448[/url] | |
Re: This thread was originally posted as a code snippet by mistake. Code snippets are for completed working code only. | |
Re: You could simply use a list to store the class instances. Now the index of the list would be your fragment number. Python3 also offers named tuples. | |
![]() | Re: As your users and their passwords get more numerous, it will be difficult to keep them matched in separate containers like tuples. So I would go with user/password pairs like was suggested above. Either a tuple of (user, password) tuples or a user:password dictionary. The dictionary would be easier to … ![]() |
Re: It is much simpler and more readable if you set up your while loop this way ... [code=python]# This is a game character health simulator # give the user instructions print("Character health can be from 0 to 600+ (-1 exits the loop)") while True: health = int(input("What is your characters … | |
Re: How are you yourself going to decrypt this top secret message? | |
Re: To find the error class simply create the error ... [code=python]import datetime as dt # the date has to be entered in dd/mm/yy format # entering dd/mm/yyyy by mistake will create an error # the error class will be --> ValueError test_date = "15/07/2003" d1 = dt.datetime.strptime(test_date, "%d/%m/%y") [/code]Also be … | |
Re: [QUOTE=smerny;996343]wow, very descriptive, thanks a lot[/QUOTE] I agree! Very nice of our friend JasonHippy to enlighten us so thoroughly! | |
Re: You may want to store your result in a string, so you can work with it ... [code=python]import string def main(): user = raw_input("Enter the message you want coded: ") user = string.upper(user) encoded = "" for i in user: if i != ' ': i = ord(i) i += … | |
![]() | Re: Since you don't know the specific error class, simply use ... [code=python]for i in range(1, 638): try: temp=start+str(i) permlist.append(str(url.urlopen(temp).readlines()[88])) textlist.append(str(url.urlopen(temp).readlines()[77])) except: # catch any exception and continue the for loop print "Error at index %d."%i pass [/code] |
Re: Even simpler, for your console programs you can just use ... [code=python]import tkFileDialog dirname = tkFileDialog.askdirectory(initialdir="/", title='Please select a directory') # test print dirname [/code] | |
Re: Generally you can simplify your code to ... [code=python]def find(): for bd_line in open("birthday.txt"): for pi_line in open("pidigits.txt"): ix = pi_line.find(bd_line[:6]) if ix >= 0: print "birthday %s is at index %s in pi line\n%s" % \ (bd_line[:6], ix, pi_line) find() [/code] | |
Re: [QUOTE=ov3rcl0ck;996426]first off try using the raw_input function rather than the input function, second off pythion 3.x may never become standard, they may just skip it or drag 2.x out for a long long time, thing is no one like 3.x because they made very little changes and those changes aren't … | |
Re: [B]htmlDoc=connect.read()[/B] gives you the whole code as a string, and your for loop would iterate this one character at a time. You need to use: [B]htmlDoc=connect.readlines()[/B] to get a list of code lines. | |
Re: Also, Python has a function rstrip() that will do that: [B]line = line.rstrip('\n')[/B] no need for the if statement. Thanks for giving us a descriptive title. BTW, the operation you are talking about is actually called [B]slicing[/B]. | |
Re: Simply Google for: outlook alternatives There are many of them, obviously for a good reason. My best bet: [url]http://www.mozillamessaging.com/en-US/thunderbird/[/url] A recent review of many: [url]http://www.zdnet.com.au/insight/software/soa/Top-alternatives-to-Microsoft-Outlook/0,139023769,339295046,00.htm[/url] | |
Re: Your problem is called 'permutations'. If you have 9 unique letters, then you can get the 'factorial of 9' = 362880 number of permutations of 9 letter words. To get words that are meaningful in a particuar language, you have to check against a dictionary of that langauge. | |
Ever since I upgraded to IE8 I have noticed the beast freezing up more frequently than the usual Windows software. I have switched to Firefox and found that web browser a lot more stable than even IE7. Is there any software for converting "IE favorites" to something useful like an … | |
Re: How are you importing OpenGL in your program? | |
Re: Some files contain values that can not be printed, such as image files and most likely the .doc format of MS Word. Such values can be read with the binary file mode, but can not be displayed directly as they have to be interpreted by the image viewer or word … | |
Re: I always test for -40, it should be the same for both. Snee's approach seems to work correctly. Or even simpler, 0 C gives 32 F, and 32 F should give 0 C. Something you can do by just looking at the two formulas. | |
Re: Here is an example for a listbox, the textbox should be similar ... [code=python]# Tk_ListBoxScroll1.py # simple example of Tkinter listbox with scrollbar try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk root = tk.Tk() # use width x height + x_offset + y_offset … |
The End.