2,190 Posted Topics
Re: You don't actually split a widget, you use 2 widgets and pass whatever data back and forth. The following code is not exactly what you want but does show how to pass data from one widget to another. When you click on the 'Edit' button the item you selected is … | |
Re: First, don't use "file" as a variable name as it is a reserved word. I would guess that the problem may be with counter equal or not equal to one, or not stripping spaces from the name or term. There were some punctuation errors in the code you posted as … | |
Re: A "How To" is generally sample code on how you do something, so anyone who doesn't want to know how to do this will not even look at the thread. Try a new thread with a more specific title and some sample code. For example, "How would I link two … | |
Re: letters_used and wrong are never incremented. You should be able to tell that from the print letters_used statement. Also, you define letters_used=() (a tuple) and not zero. | |
Re: You have to declare the encoding somewhere. The following works for me on python 3.x. Note that printing to screen is a different matter as some characters will not print depending on the encoding and font for the system. [CODE]#!/usr/bin/python3 # -*- coding: latin-1 -*- y = 'abcdef' + chr(128) … | |
Re: Take a look at any of these [url]http://code.activestate.com/recipes/52250/[/url] [url]http://www.daniweb.com/forums/thread255278.html[/url] [url]http://www.daniweb.com/code/snippet216636.html[/url] [url]http://www.daniweb.com/forums/thread70426.html[/url] [url]http://www.daniweb.com/forums/thread143165.html[/url] | |
Re: Take a look here [url]http://tinyurl.com/yefdoug[/url] | |
Re: I've only done this once and used html2ps and then ps2png. I am pretty sure that convert within Imagemagick (located here in most distros [URL]file://localhost/usr/share/doc/ImageMagick-6.5.6/www/convert.html[/URL] ) will do it in one step from the command line but you may have to supply additional paramenters like layers, etc. | |
Re: We can't help without knowing what encoding your program uses (obviously not the right one). It appears to work fine with the universal utf-8 encoding, see here [url]http://effbot.org/pyfaq/what-does-unicodeerror-ascii-decoding-encoding-error-ordinal-not-in-range-128-mean.htm[/url] [CODE]a = unicode('\u05d0', "utf-8") print a [/CODE] | |
Re: I have this example from somewhere on the web that changes based on the slider value. You are interested in the moveSlider and valueChanged functions. Sorry, I didn't note where i came from. Edit: Just noticed that you are using Qt3, so try this program instead. I don't have Qt3 … | |
Re: Works fine for me (using the following stripped down version). You should include the actual error when posting; it is not always what you think it means. [CODE]class Card(): SUIT = { 'C':'Clubs', 'D':'Diamonds', 'H':'Hearts', 'S':'Spades' } VALUES = { '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, \ '10':10, … | |
Re: I think you want to use new_sentence (and is one of the positive results of posting code). [CODE]def wordFrequences(new_sentence): wordFreq = {} ## new_sentence was not defined split_sentence = new_sentence.split() for word in split_sentence: wordFreq[word] = wordFreq.get(word,0) + 1 wordFreq.items() print wordFreq sentence = "The first test of the function" … | |
Re: Use startswith() on each record to test for <HEADLINE and the string find function to locate the double quotation marks. | |
Re: [QUOTE]if I could do something like sort all values[/QUOTE]Try a normal list sort and then print it to see if it is in the order you want. You can then go through the list item by item, and if the first letter of this word is different from the first … | |
Re: You can also strip() the record (remove '\n') and test for endswith zero. | |
Re: [QUOTE]print "\n\t", board[0], "|", board[1], "|", board[2] IndexError: list index out of range[/QUOTE]Add a print len(board) as the first statement in the function to see if your list contains 9 items (and of course it doesn't, but this will tell you how many items it does contain). | |
Re: print score(0,-9) will trigger the last return in this block of code, because x=0. Note that the "y" portion of the code will never be reached, because any value of x will result in a return from the function. [CODE] if x>15 or x<-15: print "Out of Bounds, No Points" … | |
Re: A second for the use of SQLite, then you can select where sex=='Male', etc. If you want to keep your original structure, a dictionary of lists might work better, with each position in the list holding a specitic data value. exp_dict[Exp#] = [sex, age_band, type_of treatment] Otherwise, you would want … | |
Re: [QUOTE]TypeError: __add__ nor __radd__ defined for these operands [/QUOTE]The error could be here because of backticks print "Adding strTest to Array " + `unDepSuccess` Also, you can not concatenate a string and a list (I'm assuming it is a list because you append to it). print "Printing unDepSuccess " + … | |
Re: t.play(toy) doesn't have a return, which means it returns None, so print 'Yip! ' + str(t.play(toy)) prints "Yip!None" Try [CODE]print 'Yip!', t.play(toy) # # or class Toy(object): def play(self, toy, lit): '''Print squeak''' print lit+'Squeak!' t.play(toy, 'YIP!') ## note that 'toy' is not used anywhere # # or class Toy(object): … | |
Re: spell = [] defines an empty list on every pass through the loop. You want it before the while(). Also, your code is an infinite loop, i.e. there is no exit. | |
Re: I am not a user (of regex's) so would do something like the following. You might prefer to find the first "&" and slice from there instead of using split and join. [CODE]test_data = ["sometext herekeywords=walter&keywords=scott", "keywords=john&sometexthere", "keywords=james&keywords=john& keywords=brian&"] delim = 'keywords=' found_list = [] for rec in test_data: ## … | |
Re: Not using a regex, it would be [CODE]mystring = "00:00:11 192.168.21.44 GET /images/help.gif - 200 Mozilla/4.0+(compatible;+MSIE+5.0;+Windows+98;+DigExt) ASPSESSIONIDGGGGGQEG=CLDIHIJBJAPFAGBFIOMCFGGA;+PRO%5FOnline=SEARCHQUERY=%09%3Cinput+type%3Dhidden+name%3D%27HrowColumns%27+ID%3D%27HrowColumns%27++value%3D%271%3B6%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27txtScopeData10%27+ID%3D%27txtScopeData10%27++value%3D%27catherine%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27txtScopeData30%27+ID%3D%27txtScopeData30%27++value%3D%27porter%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27txtScopeData50%27+ID%3D%27txtScopeData50%27++value%3D%27%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27txtScopeData11%27+ID%3D%27txtScopeData11%27++value%3D%27%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27txtScopeData31%27+ID%3D%27txtScopeData31%27++value%3D%27%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27txtScopeData51%27+ID%3D%27txtScopeData51%27++value%3D%27%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27HCollection%5Fid%27+ID%3D%27HCollection%5Fid%27++value%3D%271%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27Submit1%2Ex%27+ID%3D%27Submit1%2Ex%27++value%3D%2736%27%3E%0D%0A%09%3Cinput+type%3Dhidden+name%3D%27Submit1%2Ey%27+ID%3D%27Submit1%2Ey%27++value%3D%2718%27%3E%0D%0A http://www.foo-bar.com/SearchResult.asp" substrs = mystring.split('++value%3D%27') for s in substrs: if s[0].isalpha(): print s.split("%27") [/CODE] | |
Re: Bookmark the Python wiki as it is a good place to start for anything Python [url]http://wiki.python.org/moin/[/url] | |
Re: There are many ways to flatten a list. Here are two. I'm sure a Google would come up with many more. [CODE]a = [[1,2,3], [4,5,6], [7,8,9]] b = [num for sublist in a for num in sublist] print b import itertools c = itertools.chain(*a) print list(c) [/CODE] | |
Re: Generally, you would use mutiprocessing or threading, with a separate class instance/window running in a separate process or thread. | |
Re: And you can use a dictionary as a container for all of this, so if you want to change anything, you just add, change, or delete from the dictionary. Your code assumes that just one hit will be found. If there is more than one, "person" will be whatever was … | |
Re: See if adding this print statement clears things up. You have to compare the same type of variables, i.e. an integer to an integer, etc. [CODE]def Marks(*score): print score, type(score) marks0 = 0 marks1 = 0 marks2 = 0 marks3 = 0 marks4 = 0 marks5 = 0 if score … | |
Re: [QUOTE]i mean that if there isnt enough elements to delete in data_list that process should wait until there is enough elements[/QUOTE]Can you just compare the length of data_list to the number of random elements you wish to delete? | |
Re: This function returns on the first pass through the loop. [CODE]def simulateFlips(times): import random heads = 0 tails = 0 for i in range(times): if random.randint(1,2) == 1: heads += 1 else: tails += 1 return (heads, tails) ## it should be return heads, tails [/CODE]Also you have to convert … | |
Re: [QUOTE]the problem is that import queue and import Queue dont work[/QUOTE]In your original example, Queue imported fine. It was the statement calling Queue that was the problem. Try the first two lines of redyugi's example and see what you get.[CODE]from Queue import Queue ##<----- imports fine def main(): ##========================================================= ## … | |
Re: You have to define glob. Try a google for one of the online books like: "dive into python" glob | |
Re: [QUOTE] I dont want to remove the old data in the file just add new data to it?[/QUOTE]Opening a file in write mode creates new file. You want to open in append mode. A Google for 'Python file append' will give all the info you want to know. [CODE]import random … | |
Re: Do you have to find up and down as well? If North is (5,5), and you are using a dictionary, you can easily look up (5,7) etc. instead of the list comprehension. print coord_dict[(5,7)] instead of East = [e.color for e in objectList if (e.coord[0] == object.coord[0] + 2 and … | |
Re: Works fine for me as well. I get 7 entries at the end. [CODE]studRoll = [] def GetInteger(i): try: return int(i) except: return 0 class stud: def __init__(self, a, n, m): self.age = a self.name = n self.mark = m def ShowRoll(): for stud in studRoll: print "\n\n\n>>>> Student Roll … | |
Re: [QUOTE]I forgot, the reset button has to reset all, exept for one label that cuntes victories.[/QUOTE]You can delete all items from the listbox and then re-insert the victory counter. listbox.delete(0, END) ## deletes all items listbox.insert(END, newitem) | |
Re: [QUOTE]Here is what I WANT to echo to a file: [ $(date +\%d) -eq $(echo $(cal) | awk '{print $NF}') ] &&[/QUOTE]The brace, "}", is some kind of an escape character but I don't remember the particulars. Perhaps something like mes = "$(date +\%d) -eq $(echo $(cal) | awk '{print … | |
Re: As Namibnat has already stated, it depends on what you are using to print it. Obviously, if you are printing in the terminal you are limited to ASCII characters and can not do it, as you stated yourself, so you will have to be more specific than just stating that … | |
Re: The same kind of thing was said when Proctor and Gamble introduced Oxydol in the late 1920s. It competed with Tide, which was then the market leader. Sure enough, Oxydol reduced Tide's market share but the combined market share was greater than Tide's alone. | |
Re: [QUOTE=jbennet;410507]i like eating and coking favourite things: scones homemade tablet haggis with parsnips and potatoes (mashed) shortbread[/QUOTE]Coking? I though a spell checker would kick that out, but it turns out that coking is the process of making coke while distilling coal. Look at the length of this topic. Perhaps we … | |
Re: In Linux you have to use an "@" sign in front of the filename, but root.wm_iconbitmap('@'+fname) yields an "error reading bitmap file". I opened it in GIMP and it is fine, and tried ico, gif, and bmp with the same results. This is something that is not critical but we … | |
Re: For something simple like "ls", use subprocess.call('ls -l /home', shell=True) Doug Hellmann's examples are a good place to start [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url] | |
Re: [QUOTE] Inside this Class, there is another Class[/QUOTE]Why is this necessary. Everything should be in functions inside a single class, or two classes with one calling an instance of the other. [QUOTE]TclError: image "pyimage8" doesn't exist[/QUOTE]You are probably looking in the wrong directory. Use the absolute directory + file name … | |
Re: If I understand correctly, you should read a record, look for one of the strings, and print the line. Something like the following should be close to what you want. [CODE]## pass "fin" to the function and avoid the use of globals def CifT(self, fin): pos1 = ["_chemical_formula_moiety", "_chemical_formula_weight", "_symmetry_cell_setting", … | |
Re: string.replace(" nf ","1.0")? Your question is not clear because you show the after but not the before. | |
Re: [QUOTE]. how can ı make ı read from command shel (like ı wıll poınt my txt file from the shell and ıt wıll command and read thıs fıle) [/QUOTE] Have you tried something like program.bash > program.py where the output of the shell is the input to the Python program. … | |
Re: You want to group the moveUp under one if statement, and the same for moveDown, otherwise moveUp also prints for (moveUp and moveLeft) or (moveUp and moveRight).[COde]if self.moveUp: if self.moveRight: ## moveUp and moveRight print "MOVE UPRIGHT" elif self.moveLeft: ## moveUp and moveLeft print "MOVE UPLEFT" else: ## moveRight and … | |
Re: What type of objects does the query return? You may have to convert to a list to access it in this way. [CODE]query = db.GqlQuery("SELECT *" .....etc. print type(query) ctr = 0 for q in query: if ctr < 2: print type(q) ctr += 1 [/CODE] | |
Re: Use getpass [QUOTE]Can you help meee???? pleaseeeee=(((( [/QUOTE] Don't know about anyone else, but I ignore any posts with this type of plea, especially when nothing has been tried. | |
Re: Add some print statements so you know what is going on. [CODE]def colourpicker(): print "pick four different colours from; red, green, blue, yellow, orange, pink, brown" colourList = ["red", "green", "blue", "yellow", "orange", "pink", "brown"] coloursPicked = [] while True: colour1 = raw_input("pick first colour: ") print "colour1 picked =", … |
The End.