2,190 Posted Topics

Member Avatar for lewashby

[QUOTE]what do these two strings have to do with the A & c in RANKS & SUITS?[/QUOTE]One is a class instance and one is a class attribute. See here [url]http://diveintopython.org/object_oriented_framework/class_attributes.html[/url]

Member Avatar for woooee
0
100
Member Avatar for fatalblade

You have to enter "d:\" to make it equal to "d:\\" since backslash is the escape character. Why not make it simple and test for "D:" only. I've added some print statements to clarify. [CODE]#!/usr/bin/python3 import os import sys whileloop = True while(whileloop): initial_drive = "C:\\" inputline = input(initial_drive) print("inputline …

Member Avatar for fatalblade
0
170
Member Avatar for explorepython

[QUOTE] i want to receive messages from the threads running in other python modules and display or process in my pyqt application.[/QUOTE]You would have to communicate between the threads. I use multiprocessing instead of threading and so would communicate through a manager list or dictionary. This is an example of …

Member Avatar for explorepython
0
616
Member Avatar for WOPR

One thing, you can not open a directory, so you should test that it is a file. [CODE]import os a = [] a = os.listdir('.') for t in a: if os.path.isfile(t): f = open(t,'r') print t, "opened" f.close() else: print " ", t, "not a file" [/CODE] Also, if you …

Member Avatar for WOPR
0
90
Member Avatar for Destray

The same code with a call back to show which button was pressed. Hopefully you will use a class structure for this as that eliminates shared variable problems. [CODE]from Tkinter import* def cb_handler(event, cb_number ): print "cb_handler - button number pressed =", cb_number root = Tk() frame = Frame(root) frames …

Member Avatar for Destray
0
207
Member Avatar for monstercameron

[CODE] if option==3: active<>"on"[/CODE]This will print "True" if active != 'on' and print "False" otherwise. <> has been deprecated so use "!=" instead. I think you want [CODE] if option==3: active = "off"[/CODE]Also you can simplify the following code. [CODE] if option<>1 or option<>2 or option<>3: ondamenu() ## ## can …

Member Avatar for woooee
0
153
Member Avatar for harpalss

I don't use regex as a rule and it is not necessary in this case. [CODE]found = False fp = open(fname, 'r') for num, line in enumerate(fp): line = line.strip() if line.startswith(search_term): found = True if found: print num, line fp.close() [/CODE] [QUOTE]and a number of lines before and after …

Member Avatar for d5e5
0
133
Member Avatar for leegeorg07

First you want to check that the word ends up as an even number, otherwise you can't divide it in two. Tiger = 59 so is not a good choice. [CODE]import string def number_equiv(word): ## I prefer a list over string.find (so sue me) letters_list = [ ltr for ltr …

Member Avatar for leegeorg07
0
195
Member Avatar for manathisbest

It's personal preference, but I would use a dictionary in the players() function. [CODE] def player(self, choice, Com): win_d = { 'rock':'Scissors', 'paper':'Rock', 'scissors':'paper'} if choice.lower() == Com.lower(): return 'Tie!' elif win_d[choice] == Com: return 'You won!' else: return 'You lost!' [/CODE] Also, you can create all four buttons with …

Member Avatar for manathisbest
0
2K
Member Avatar for mruane

This program should use a class. For the foo_sell() function as it is, pass 'cash' and 'dealers' to it and return them as well, avoiding globals. [QUOTE]I have never had a problem with declaring globals like this[/QUOTE]You have now and hopefully have learned that lesson.

Member Avatar for mruane
0
147
Member Avatar for Adam2k

This is why we have SQL. I have a work in progress that generates simple SQLite code for throw away applications. This is the code it generated for your application. The test_data() function adds some records with the data you provided. You should be able to figure how to add …

Member Avatar for Adam2k
0
112
Member Avatar for chris99

You want to add buttons for the functions to add, multiply, etc and tie that to the proper event. Right now, every button you push calls buttonNPush which prints the button. You also have to issue a get() to retrieve data. See this link for an example. [url]http://www.uselesspython.com/calculator.py[/url]

Member Avatar for vegaseat
0
209
Member Avatar for checker

'student' has not been declared so who knows what this does. [CODE] data = student.sport k = len(student.fname)[/CODE] What happens when the key is not found? [code] for i in data: freq[i] = freq.get(i, 0) + 1 [/CODE] Your code is poor at best. Add some print statements, print the …

Member Avatar for checker
0
207
Member Avatar for SoulMazer

It should be something with ButtonReleaseMask. Try this code and Google for ButtonReleaseMask if it doesn't work. [CODE]import Xlib import Xlib.display display = Xlib.display.Display(':0') root = display.screen().root root.change_attributes(event_mask= Xlib.X.ButtonPressMask | Xlib.X.ButtonReleaseMask) while True: event = root.display.next_event() print "Hello button press" [/CODE]

Member Avatar for SoulMazer
0
584
Member Avatar for ahspats

FWIW, a more generic solution using a list to keep track of the maximum's value and the number of times it occurs. [CODE]def find_the_max(blist): ## a list containing the value and the number of times it appears max_group = [blist[0], 0] this_group = [blist[0], 0] for el in blist: if …

Member Avatar for woooee
0
145
Member Avatar for i are smart

effbot's tutorial turns up as the first hit for a Google of "tkinter scrollbars". Since we don't know what you want to attach it to, effbot would be the place to start. This is effbot's code for a canvas widget as an example. [CODE]from Tkinter import * root = Tk() …

Member Avatar for woooee
0
102
Member Avatar for ffs82defxp
Member Avatar for ffs82defxp
0
113
Member Avatar for JuvenileMango

I had a simple solution using a list of lists to associate the letter with the original position. [CODE]def find_letter(letter, list_in, stars_list): for ch_list in list_in: ##print(" comparing %s and %s" % (letter, ch_list[0])) if letter == ch_list[0]: print(" found %s" % (ch)) ## replace '*' with letter el = …

Member Avatar for JuvenileMango
0
178
Member Avatar for basti!

It would generally be something in this ballpark [CODE]file_pointer = open("Handylist.csv", "r") name_in = raw_input("Enter the name") for rec in file_pointer: substrs = rec.split() name = substrs[x] ## don't know where this is if name == name_in: print("%s Found" % (name)) [/CODE]

Member Avatar for vegaseat
0
119
Member Avatar for jmark13

It's pretty straight forward, and since I'm sick and not doing much today... [CODE]test_data = [ "c The random seed used to shuffle this instance was seed=1755086696", "p cnf 1200 4919", "-35 491 -1180 0", "479 1074 -949 0", "609 1177 -67 0" ] formula = [] for rec in …

Member Avatar for jmark13
0
4K
Member Avatar for sanitizer

[QUOTE]main.cpp:1:20: error: Python.h: No such file or directory[/QUOTE]Python.h is under /usr/include/pythonx.y on my Slackware box. If you don't have it then you will have to install the source.

Member Avatar for Gribouillis
0
731
Member Avatar for lisedaton
Member Avatar for Namibnat
0
92
Member Avatar for Dan08

For timed events you generally use the "after" function. [CODE]from Tkinter import * import datetime import time class ChangeTime(Frame): def __init__(self, master=None): master.geometry("100x50+5+5") Frame.__init__(self, master) self.pack() self.timestr = StringVar() lbl = Label(master, textvariable=self.timestr) lbl.pack() # register callback self.listenID = self.after(1000, self.newtime) def newtime(self): timenow = datetime.datetime.now() self.timestr.set("%d:%02d:%02d" % \ (timenow.hour, …

Member Avatar for Dan08
0
22K
Member Avatar for hackabusa

[QUOTE]I have absolutely no clue how to do it with a list of lists[/QUOTE] [CODE]test_matrix = [ ["A", "b", "c"], \ ["R", "S", "s"], \ ["X", "Y", "Z"] ] for sublist in test_matrix: print sublist for ch in sublist: if ch == "S": print "\nS found in", sublist, "\n" [/CODE]

Member Avatar for hackabusa
0
144
Member Avatar for Dokino

You can put the redundant code into a function [CODE]def get_two_numbers(): while True: try: x = float(raw_input("number one\n")) break except ValueError: print "Wrong input" while True: try: y = float(raw_input("number two\n")) break except ValueError: print "wrong input" return x, y def add(): x, y = get_two_numbers() print 'your answer is:', …

Member Avatar for woooee
0
98
Member Avatar for ffs82defxp

getRandEntry() calls startLink(theRandoms) which calls getRandEntry() which will create and infinite loop.

Member Avatar for Gribouillis
0
173
Member Avatar for sentinel123

This will change every 2nd letter to "x" and every 3rd letter to "y", but note that the 6th letter could become either "x" or "y" depending on the logic. [CODE]def change_chr(chr, x): if not x % 3: return "y" if not x % 2: return "x" return chr mystring …

Member Avatar for sentinel123
-2
4K
Member Avatar for funfullson

[QUOTE]fetching data from qt[/QUOTE]The short answer is to look at QLineEdit here [url]http://www.devshed.com/c/a/Python/PyQT-Input-Widgets/[/url] More tutorials are on the wiki [url]http://www.diotavelli.net/PyQtWiki/Tutorials[/url]

Member Avatar for funfullson
0
147
Member Avatar for klackey19

There are many possible problems with this code, one of which is the following. Add some print statements to see what the program is doing. [CODE] def __radd__(self, other): print "__radd__ return =", self, other, type(self), type(other) return self + other def __rtruediv__(self, other): ## add a similar print statement …

Member Avatar for woooee
0
107
Member Avatar for MRWIGGLES

You draw an object like a circle and fill it with the color selected inside a try/except. It will fail if it is not a valid color. I think Tkinter uses an r,g,b tuple so your program should accept that as well as a name.

Member Avatar for woooee
0
142
Member Avatar for Yeen

input is raw_input in 2.6 That's the only big difference along with Tkinter becoming tkinter. For print you can use either print str print(str) and string.split(a) has been deprecated for while for all versions of Python, so use a.split() in all versions as well. There should be very few problems …

Member Avatar for Yeen
0
155
Member Avatar for hondros

Numpy will probably already do everything you want [url]http://www.scipy.org/Tentative_NumPy_Tutorial#head-926a6c9b68b752eed8a330636c41829e6358b1d3[/url]

Member Avatar for hondros
0
120
Member Avatar for uv2009

You can use a dictionary as a counter, but you first have to convert the key to a tuple. [CODE]arr=[[10, 2, 10], [10, 9, 10], [10, 9, 10], [10, 9, 10], [10, 9, 10], [22, 9, 10], [10, 9, 10], [10, 9, 10], [22, 9, 10], [10, 9, 10]] unique_dict …

Member Avatar for uv2009
0
149
Member Avatar for Dokino

[QUOTE]but import statement imports it only once and i have no clues how to fix it.[/QUOTE] Why do want to import the same thing a second time? You already have it in memory. Putting the same thing in another block of memory is a waste. To test for a number, …

Member Avatar for Dokino
0
130
Member Avatar for kaydub123

First, try running this code in Idle. It will tell you that there are problems with this statement with a variable name that contains special characters. Starting_weight_of_food_in_lbs{:}ozs=input("Enter Starting_weight_of_food_in_lbs{:}ozs") Take a look here for getting started with Idle [url]http://www.ai.uga.edu/mc/idle/index.html[/url]

Member Avatar for masterofpuppets
0
136
Member Avatar for smohrchi

+1 for "Dive Into Python" and "Think Like A Computer Scientist" For the non-programmer, something like this might be better as it explains the logic behind things like while() loops, etc. [url]http://www.pasteur.fr/formation/infobio/python/[/url]

Member Avatar for jaux
0
92
Member Avatar for johnroach1985

Doug Hellmann always has good explanations. [url]http://www.doughellmann.com/PyMOTW/threading/index.html[/url] [url]http://www.doughellmann.com/PyMOTW/multiprocessing/index.html[/url]

Member Avatar for woooee
0
291
Member Avatar for sjgriffiths

[QUOTE]File "./ste.py", line 64, in disconnect self._conn.close() _mysql_exceptions.ProgrammingError: closing a closed connection[/QUOTE]Why are you closing a connection (twice) for a db that you are adding records to. How about some code. Also, you do not have to commit after every add, so wait until after you have added x records, …

Member Avatar for woooee
0
178
Member Avatar for truekid

> the first phase will read in the file and find all of the tags and save them into a queue Wouldn't that just be a list or a dictionary. > the second phase will take in the queue of tags from the first phase and check to see if …

Member Avatar for sneekula
0
106
Member Avatar for Musafir
Re: Flip

The first two posts found in a search of this forum, after your post which is the first/latest, have working solutions that you should be able to adapt.

Member Avatar for vegaseat
0
141
Member Avatar for saikeraku

[QUOTE]The problem I have is after I did the rstrip(), nothing really happened to the text file? I don't really know what I'm missing.[/QUOTE]You have to write the data to a file. You read the disk file into memory, change it in memory and then exit the program. If you …

Member Avatar for woooee
0
130
Member Avatar for ShadyTyrant

I would suggest two classes, one that handles the physical details of the SQL database and one for everything else. So, if you want to modify a record, the second class would generate a GUI to ask for info on the record. The info would be passed to the SQL …

Member Avatar for ShadyTyrant
2
262
Member Avatar for peepeep

[QUOTE]matrix[x][y] = corr(file[x], file[y]) TypeError: 'list' object is not callable corr = ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6'] ## list matrix[x][y] = corr(file[x], file[y]) ## function [/QUOTE] You are using corr as both a list and a function. You'll have to rename one of them.

Member Avatar for woooee
0
103
Member Avatar for Musafir

Start by asking the player(s) for a name and store it in a dictionary that will also keep track of their score. Then, open one graphic window that will simply display the name and score of the player(s). Worry about the multiple windows and clicking on each at a latter …

Member Avatar for vegaseat
-3
282
Member Avatar for reduxmachine

[CODE]if clickx>=iris1x and clickx <=iris2x and clicky>=iris1y and clicky<=iris2y:[/CODE] If you are dealing with eyes, etc. that are circles then your test doesn't work. I think you would have to 1. take the distance of the mouse-click x-coordinate from the center of the circle 2. make sure the difference is …

Member Avatar for woooee
0
115
Member Avatar for laccko

If you can call/execute external programs, then you can put each routine in a function in a separate file with the appropriate return value. Otherwise, you could do something like the following to eliminate the else statements, and hopefully the program is not large. [CODE]a = 1 if a > …

Member Avatar for woooee
0
144
Member Avatar for Musafir

A quick example of a spiral using deque. It still has a few problems (works best with a square and prints too many) but shows the general concept. [CODE]from collections import deque ##======================================================================== def print_spiral( total_cols, total_rows ) : d_list = [] ## hold pointers to separate deque objects for …

Member Avatar for woooee
0
116
Member Avatar for Stefano Mtangoo

The python.org website has a beginners guide that includes links to tutorials and introductory books. [url]http://wiki.python.org/moin/BeginnersGuide[/url]

Member Avatar for elasolova
0
184
Member Avatar for mn_kthompson

I don't have much experience with this, so only have used ps to a file and parse the file when this is necessary. This may require some tweaking.[CODE]def ps_test(): fname = "./example_ps.txt" os.system("ps -AFL > " + fname) ## or subprocess data_recs = open(fname, "r").readlines() for rec in data_recs: if …

Member Avatar for donaldw
0
133
Member Avatar for python.noob

[QUOTE]So i searched the sys.path for 2.6 and included usr/lib/python2.6/dist-packages in python3 sys.path[/QUOTE]So you are obviously using PyQT4 built for Python 2.6. The error message confirms it. [QUOTE]undefined symbol: PyString_FromString[/QUOTE]Ask how to install PyQT for both 2.6 and 3.x on the Ubuntu or PyQt forum. Some one has done this …

Member Avatar for woooee
0
378

The End.