2,190 Posted Topics
Re: You call executemany but only supply one value. What is the point of creating the tuple "tests" or "vuln" instead of supplying the fields directly to the insert statement. You should also open or create the SQLite db once at the top of the function before the for loop. As … | |
Re: I would just add both directories to the PYTHONPATH variable in .bashrc. You can also add something like export PYTHONSTARTUP=$HOME/.pythonstartup to .bashrc to execute a given file when python starts. Edit: Sorry, I see now from the "7" and "xp" that you are probably using a windows OS, but am … | |
Re: An infinite loop as play_click is not changed within the while loop while(self.play_click==0): self.while_time() When testing it is a good idea to limit while loops ctr = 0 while self.play_click==0: self.while_time() ctr += 1 if ctr > 99: print "Counter limit exit from while loop" self.play_click=99 | |
Re: That comes out to June 10th, 14 days off. There would be something like 28 leap years which is too far off to be a possibility. "41401,250002" comes back as May 9th at 6:00 AM (providing January 1, 1900 is correct). import datetime x=datetime.datetime(1900, 1, 1, 0, 0, 0) + … | |
Re: It appears that user name or password are None as the program prints the message and then exits, but it should be sys.exit(0) instead of exit(0). | |
Re: Always use complete names. The program is not looking in the directory that the file is located in. Also, you should be able to use a slash, /directory_name on any OS. ##------------------------------------------------------------- ## Assumes this code is now indented to run under the for() loop ##------------------------------------------------------------- folder_to_import = '/Location/DATA' l_files_to_import … | |
Re: 2nd hit on Google [pyusb backend not accessible](http://stackoverflow.com/questions/5152133/pyusb-backend-not-accessible). You have to install an additional lib that pyusb depends on, and it's also on the [pyusb site](http://sourceforge.net/apps/trac/pyusb/) but the web site isn't real clear saying that you have to install one of the library dependencies. Please mark this as solved. | |
Re: A class is a prototype, i.e. it is only a potential object. class HelloWorld : def __init__(self): print("Hi") def talk(self ,name): self.nameA = name print("Hello", self.nameA) HW1=HelloWorld() ## calls the class or creates an actual instance HW2=HelloWorld() ## a second, separate instance HW1.talk("Name 1") HW2.talk("Name Two") print HW1.nameA print HW2.nameA | |
Re: > i wanted to use the subprocess module also but i couldn't know how to use it , and got this Error : WindowsError: [Error 2] Le fichier spécifié est introuvable We don't know what the statment was that produced the error so can not offer any help on how … | |
Re: It is replacing every 'a" with "ein". A [tutorial on using a dictionary to map from English to Spanish](http://www.greenteapress.com/thinkpython/html/thinkpython012.html) ## CamelCase is reserved for classes in Python dic_word= { 'a':'ein', 'an':'eine', 'able':'KOmmen', 'about':'gegen', 'above':'Uber', 'absence':'Abwesenheit', 'absent':'abwesend', 'accent':'Betonung', 'accept':'akzeptieren', 'according':'nach', 'acquainted':'kennen', 'across':'uber' } for word in ["a", "able", "acquainted"]: print word, … | |
Re: If the car is still in transit, we don't know what the speed is. If there is no traffice, it is faster. If there is a traffic jam it is slow. If the traffice is the same then the speed is the same. If the car has already arrived, it's … | |
Re: If someone enters a wrong user name, or password, or bc, nothing happens. It should be something along the lines of if Choice==2: username = "" while username != uname: username=raw_input("Login User name: ") This is definitely a list exercise IMHO and whould be much easier with dictionaries. The point … | |
Re: We don't have the inherited class, EventHandler, and don't know what graphics tool kit you are using, so can not offer any assistance other than to say that you don't call the function "handle" anywhere in the code posted that I can see. | |
Re: For starters you will have to [load/open and read the file](http://www.freenetpages.co.uk/hp/alan.gauld/tutfiles.htm) Post back when you have this coded (whether it works or not) with a sample of input and the output you would like. | |
Re: No "/n". The data is there it's just on one r e a l l y long line. fp=open("data.txt", "a") fp.write(dependent_variables) fp.close() And it should be fp=open("data.txt", "a") ## do the input or calcs or whatever fp.write(dependent_variables) ## do more input and/or calcs fp.write(dependent_variables) ## at the end of the … | |
Re: You have not declared log_size or log1_size anywhere and it appears the indentation is off under the while True, which is an infinite loop since you don't ever exit it. There is no reason from the code you posted to append to "packed" and then write each value from packed … | |
Re: When you call/instantiante the class you should be including a monitor value. Someone on Chapter 15 of the book "Object-Oriented Programming in Python" should know how to call a class. Time to go back and review the basics. | |
Re: Not without code as the error is possibly in the HtmlEasyPrinting function call. HtmlEasyPrinting(name_of_print_object, parentWindow) http://wxpython.org/docs/api/wx.html.HtmlEasyPrinting-class.html which it appears you overwrote/replaced with a class of the same name but we can not tell without code. > HtmlEasyPrinting.PreviewText(self, self.GetHtmlText(text)) | |
Re: If you are using a Linux system, then it should be /dev/ttyS0, etc. If it is a USB connection, try [PyUSB](http://sourceforge.net/apps/trac/pyusb/) | |
Re: use [canvas.create_image](http://effbot.org/tkinterbook/canvas.htm#canvas.Canvas.create_image-method) instead of configure, and then place whatever objects on top of it. | |
Re: Take a look at "Function Arguments" and "The Return Statement" [Click Here](http://www.tutorialspoint.com/python/python_functions.htm) You can also Google for instance objects (also called instance variables) if you want to learn more about classes. | |
Re: GUI's have their own "sleep" type methods that should be used. However each GUI uses a different function name so it depends on the GUI toolkit you are using. | |
Re: Python does have a goto add on [Click Here](http://entrian.com/goto/) but it was an April Fool's joke so I don't know if it works or not (and don't care as I will not be using it). | |
Re: To set the background from a list for example would be like the following, and you would use other input parameters in a similar manner, although I don't think I understood your question correctly. import wx class mainFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title,style=wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION) mainBox = wx.BoxSizer(wx.VERTICAL) … | |
Re: I agree that you are doing it the hard way. Note that dollars is multiplied by two after the print and the addition to total #get the ending limit days = int(raw_input('How manys days were worked? ')) total = 0 dollars = 0.02 #print table headings print('\nDays\tDollars') print('------------------------------') #print the … | |
Re: Does the file have more than one taxon? In the example you posted there is only one so all of the solutions are for one only. Try this as a hint, although there are other ways to do it. handle = open(fname, "r") all_data = handle.read() print all_data.split("taxon") | |
Re: Python does have os.linesep which is perhaps what the OP was referring to. In Python, "\n" will be converted to the proper end of record termination for the OS used. | |
Re: I would suggest that you use a button instead of a label, which can execute a funtion when it is clicked. Also, the name "list" is already used by Python so you should not override it, although you never use the variable "list" in the code posted so the "list" … | |
Re: event.x and event.y have to be within the boundaries of the label. An example using a canvas but similar to what you want try: import Tkinter as tk ## Python 2.x except ImportError: import tkinter as tk ## Python 3.x def point(event): x = event.x y = event.y print "x, … | |
Re: Once you get the value it is a normal variable and you can do anything with it that you can do to a normal variable. I would suggest that you consider putting everything under one class instead of here's a function, there's a class, here's another function, etc. try: import … | |
Re: Please mark the the thread "Solved" so as to not waste other's time looking at an already solved thread. | |
Re: There is a typo in get_average that you should be able to run down from the error messages, or at least begin to learn how. Using descriptive variable names would help you with this, as well as help us understand the program. Print the return from get_average and see if … | |
Re: For future reference, the error was eliminated because you added the plus signs. Also, include the entire error message in the future. print('Ok,'chara, print('Ok, '+ chara + | |
Re: It would be something like cipher = short_str.find(letter, cipher) if cipher > -1: print cipher + 1, else: print "_", | |
Re: First, remove punctuation (? , . etc). Next all words should be lower() case as an upper case word is different to the computer than a lower case word. To print use the dictionary's key as below, although this code does not do any of the other above suggestions data="""I … | |
Re: And it's not tough to do. [CODE]import Tkinter root = Tkinter.Tk() root.title('Canvas') canvas = Tkinter.Canvas(root, width=450, height=450) canvas.create_oval(100,50,150,100, fill='gray90') x = 125 y = 175 stick = canvas.create_line(x, y-75, x, y) diff_x = 25 stick_leg1 = canvas.create_line(x, y, x-diff_x, y+50) stick_leg2 = canvas.create_line(x, y, x+diff_x, y+50) y=145 stick_arm1 = canvas.create_line(x, … | |
Re: Has anyone used the PIL fork [Pillow](https://pypi.python.org/pypi/Pillow) and is there any reason to change? | |
Re: The best you can do AFAIK is to bind the canvas to a button click and get the coordinates. You then check to see if the click was within the boundaries of the image. If you bind the Canvas object to a button click that calls the function clicked, the … | |
Re: You append everything to converted as one list, i.e. you have to use a sub-list and append it each time the list breaks. eq= ['MPNRRRCKLSTAISTVATLAIASPCAYFLVYEPTASAKPAAKHYEFKQAASIADLPGEVLDAISQGLSQFGINL', 'MQLVDRVRGAVTGMSRRLVVGAVGAALVSGLVGAVGGTATAGAFSRPGLPVEYLQVPSPSMGRSELPGWLQA', 'GLVGLAGGAATAGAFSRPGLPVEYLQVPSPSMGRDIKVQFQSGGNNSPAVYLLDGLRAQDDYNGWDINTPAFEWACGKAGCQTYKWETFLTSELPQWLSANRAVKPTGSAAIGLSMAGSSAMILAAYHPQQFIYAGSLSALL'] polarity = { 'A': 0.000, 'R': 52.000, 'N': 3.380, 'D': 49.700, 'C': 1.480, 'Q': 3.530, 'E': 49.900, 'G': 0.000, 'H': 51.600, 'I': 0.130, … | |
Re: names = nmls means let both point to the same block of memory, so both get updated. names = nmls[:] note the colon means names is now a copy (complete slice) of nmls. You can also use copy() and deepcopy() to get a copy of the list [Click Here](http://docs.python.org/2/library/copy.html) . | |
Re: 1. ask for each value separately. Otherwise "Enter if done" returns a "need 2 values to unpack" error. 2. you can do something like what is in your program but it returns a string odom2, gallons = input("\nPlease enter odometer reading and gallons used (odometer gallons) [Enter if done]: ").split() … | |
Re: > I can't seem to get pickle.dumps (or f.write..tried that earlier) to save without saving over itself. f =open('pettycash.txt', 'wb') Instead of write mode, which creates a new file each time, open the file in append mode: see the example at [Click Here](http://www.freenetpages.co.uk/hp/alan.gauld/tutfiles.htm) where these lines are explained def logError(msg): … | |
Re: You do not test for the password for the user so if any user's password is found it will return True. This works for me but again will accept any user's password (and note the added print statements to see what is happening). import crypt line="victim: HX9LLTdc/jiDE: 503:100:Iama Victim:/home/victim:/bin/sh" cryptPass … | |
Re: As Tony said getters and setters are not used in Python as it is inefficient to create a function just to change or return some variable when that can be done directly as the following example illustrates class Priority(): def __init__(self, priority): self.priority = priority Pr = Priority(1) print Pr.priority … | |
Re: You have to set writeback=True for changes to be made to the db. Doug Hellmann has a nice write up [Click Here](http://doughellmann.com/2007/08/pymotw-shelve.html) | |
Re: Your code can return one, two, or three values. The error occurs when less (or more) than three vaules are returned (i.e. dice1, dice2, dice3 and only two are returned from the function). Usually you would catch the return with a [tuple Click Here](http://www.tutorialspoint.com/python/python_tuples.htm) since you want to catch any … | |
Re: For starters, your recursive call has no exit point so could easily go beyond the length of the list isloopy(nextcownum,data,did) This doesn't happen because the 1: '0', 2: '4', 3: '1' is a repetitive loop if I read this correctly (3 goes back to 1), so if cownum in did: … | |
Re: What and where do you and to print. I don't see anything in the program that prints name, etc. See [Click Here](http://www.freenetpages.co.uk/hp/alan.gauld/tutfiles.htm) for more info on reading files. Instead, we generally use something like fp_in = open(file_name, "r") for record in fp_in: # do some stuff print record | |
The following code does the same lookups using a list and a dictionary. Lists are sequential in memory, meaning that the program has to get the offset for the beginning of the item it wants to use, go to that offset, compare to what it wants to find, and go … | |
Re: A hint from string import ascii_lowercase as letters print letters[-1:] print letters[-2:] print location=25 print letters[location:] location -= 1 print letters[location:] |
The End.