4,305 Posted Topics

Member Avatar for Ancient Dragon
Member Avatar for Dixtosa

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]

Member Avatar for ov3rcl0ck
-2
265
Member Avatar for mbaliko
Member Avatar for grudgemuch

Most people call it HTML Scraping. The programs are called HTML Scrapers. Easy to do with Python, don't know about C.

Member Avatar for Dave Sinkula
0
285
Member Avatar for vegaseat

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 ...

Member Avatar for The-IT
0
1K
Member Avatar for pelupelu

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]

Member Avatar for vegaseat
0
277
Member Avatar for lukerobi

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 …

Member Avatar for vegaseat
0
99
Member Avatar for Frenzic

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 …

Member Avatar for pysup
-1
98
Member Avatar for jaymeaux77

[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 …

Member Avatar for jaymeaux77
0
223
Member Avatar for CurtisEClark

[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 …

Member Avatar for masterofpuppets
0
85
Member Avatar for adcodingmaster

Take a good look at: [url]http://www.daniweb.com/tutorials/tutorial45806.html[/url]

Member Avatar for Ancient Dragon
-1
147
Member Avatar for DEATHMASTER

[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 …

Member Avatar for vegaseat
-1
219
Member Avatar for SuperMetroid

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 …

Member Avatar for vegaseat
-1
4K
Member Avatar for flebber
Member Avatar for lewashby

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, …

Member Avatar for vegaseat
-1
119
Member Avatar for lewashby

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]

Member Avatar for snippsat
-1
169
Member Avatar for Dan08

Use pythonw.exe to run your GUI programs, it avoids the console screen.

Member Avatar for vegaseat
-1
76
Member Avatar for GradStudent

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, ...

Member Avatar for lllllIllIlllI
-1
81
Member Avatar for neverlander

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 …

Member Avatar for vegaseat
-1
5K
Member Avatar for MichelleCrews

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]

Member Avatar for MichelleCrews
-1
105
Member Avatar for ihatehippies
Member Avatar for oasuspender

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 …

Member Avatar for vegaseat
-1
98
Member Avatar for mohankumar554

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 …

Member Avatar for vegaseat
-1
854
Member Avatar for DMcQuinn

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 …

Member Avatar for vegaseat
-1
15K
Member Avatar for vegaseat

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.

3
734
Member Avatar for x3277789

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 …

Member Avatar for ov3rcl0ck
-1
257
Member Avatar for jasonehoss

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, …

Member Avatar for jasonehoss
-1
97
Member Avatar for lukerobi
Member Avatar for kingofkya

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]

Member Avatar for kingofkya
0
2K
Member Avatar for redpython

This thread was originally posted as a code snippet by mistake. Code snippets are for completed working code only.

Member Avatar for redpython
0
191
Member Avatar for Todd88

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.

Member Avatar for vegaseat
0
127
Member Avatar for khaos64

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 …

Member Avatar for khaos64
0
273
Member Avatar for CurtisEClark

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 …

Member Avatar for vegaseat
0
242
Member Avatar for AutoPython
Member Avatar for ov3rcl0ck
0
574
Member Avatar for flebber

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 …

Member Avatar for flebber
0
28K
Member Avatar for smerny

[QUOTE=smerny;996343]wow, very descriptive, thanks a lot[/QUOTE] I agree! Very nice of our friend JasonHippy to enlighten us so thoroughly!

Member Avatar for JasonHippy
0
159
Member Avatar for scrace89

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 += …

Member Avatar for willygstyle
0
278
Member Avatar for leegeorg07

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]

Member Avatar for ov3rcl0ck
0
207
Member Avatar for catcit

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]

Member Avatar for vegaseat
0
24K
Member Avatar for htndrum

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]

Member Avatar for foosion
0
106
Member Avatar for soulrider

[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 …

Member Avatar for vegaseat
0
291
Member Avatar for akie2741

[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.

Member Avatar for vegaseat
0
160
Member Avatar for smerny

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].

Member Avatar for vegaseat
0
165
Member Avatar for LindaHeron

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]

Member Avatar for cygnetservice
0
151
Member Avatar for sysenm

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.

Member Avatar for sysenm
0
104
Member Avatar for vegaseat

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 …

Member Avatar for Ezzaral
0
73
Member Avatar for vextorspace
Member Avatar for A_Dubbs

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 …

Member Avatar for vegaseat
0
74
Member Avatar for chico2009

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.

Member Avatar for chico2009
0
186
Member Avatar for The-IT

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 …

Member Avatar for The-IT
0
6K

The End.