2,190 Posted Topics
Re: The easiest way is to use a class and define the dictionary as self.some_name so you can access it inside or outside the class. A simple example: [CODE]class TestClass: def __init__(self): self.test_name = "test name from class" def print_object_variable(self): print "variable within class -->", self.test_name x = TestClass() print "outside … | |
Re: Store the "short" line and blank it after writing. If there isn't a short line, the store variable will be empty. [CODE]in_file = open('myhugetextfile.txt') out_file = open('mycleaneduptextfile.txt','w') #go through the file line by line repaired_line = "" for line in in_file: #split on ;; and check if the length is … | |
Re: If you are looking for the same English word in both files, use one set for each file and then you can get the difference or intersection of the sets. [url]http://en.wikibooks.org/wiki/Python_Programming/Sets[/url] To read two files, you open the first file, process it (add to the set or whatever), and then … | |
Re: I looked through all 10 of your previous posts and you haven't produced one line of code. It's about time you did or find another site to get free programming. | |
Re: If I understand the question, you want to print file dates that have not already been printed so you have to use some sort of container, a list for example, which contains the dates already printed, and print only if the date has not already been used. | |
Re: It sounds like either the screensaver or the wxPython time out (for certain types of widgets). I don't use timeout so am not familiar with it other than seeing it in the docs. Your program should allow the user a certain amount of time to choose a file, and if … | |
Re: QImage has a save function. See "Reading and Writing Image Files" [URL=http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qimage.html]here[/URL] | |
Re: Python usually has ways of replacing a bunch of if/elif/else statements.[CODE] for field in infos: if field.startswith('AC'): f_out.write('%s\t' % field[3:]) elif field.startswith('ID'): f_out.write('%s\t' % field[3:]) elif field.startswith('FA'): f_out.write('%s\t' % field[3:]) elif field.startswith('OS'): f_out.write('%s\t' % field[3:]) elif field.startswith('SF'): f_out.write('%s\t' % field[3:]) elif field.startswith('BS'): f_out.write('%s\t' % field[3:]) elif field.startswith('GE'): f_out.write('%s\t\n' % field[3:]) … | |
Re: If I understand correctly, you would modify the RemovePunc() function to receive an individual record from the file, and then execute the rest of the code as is line = RemovePunc(file_record) line_stop_words = RemoveStopWords(line) line_stop_words = StemWords(line_stop_words) index = Indexing(line_stop_words) OutputIndex(index) See here [url]http://www.greenteapress.com/thinkpython/html/book010.html#wordlist[/url] | |
Re: It's in the repository [url]https://admin.fedoraproject.org/pkgdb/acls/name/qscintilla?_csrf_token=ad09f71cc75d6c163204002663217b089dd6945c[/url] so you can install it like any other software. [QUOTE]I get an error message.........(bash: qmake command not found)[/QUOTE]On my Slackware machine, qmake is in /usr/lib/qt which is not in the path, so you would have to call it with /usr/lib/qt/qmake ... | |
Re: Split on the period. Note that the following doesn't make sense/requires an example. [QUOTE]Also, if a sentence is long, does not end in the same paragraph, it should be printed as a whole too [/QUOTE] | |
Re: [QUOTE]The error is: TypeError: unsupported operand type(s) for +: 'int' and 'tuple' [/QUOTE]There isn't any "+" sign in the code you posted. How about posting the entire error message including the offending line of code, | |
Re: You can use the code you have with a range from total rows to zero and a step of -1, or a counter for the number of stars to print. [CODE]total_rows = 5 num_stars = total_rows for row in range (total_rows): print '*' * num_stars num_stars -= 1 [/CODE] | |
Re: Take a look at the first paragraph of the first hit [URL=http://www.google.com/search?client=opera&rls=en&q=pygtk+set+cursor&sourceid=opera&ie=utf-8&oe=utf-8]here[/URL]. You can just comment that line and keep the default cursor. | |
Re: [QUOTE]I need to read in the first 2 columns until line 12960. I then need to write the 12960 lines of 2 columns to a file.[/QUOTE]You can use enumerate to count the records as it appears that a file is shorter than you think or there are blank records. [CODE]import … | |
Re: Personal preference here is to use a dictionary, with the key being the word, pointing to the number. Convert the first list to a dictionary, loop through the second list and if the word is found in the dictionary, add to the number [url]http://www.greenteapress.com/thinkpython/html/book012.html#toc120[/url] Post back with any code you … | |
Re: Try greeting = Text(Point(300, 250), "Hello," + player + "and good night") Otherwise: print_str = "Hello," + player + "and good night" greeting = Text(Point(300, 250), print_str) | |
Re: printB is not part of the class unless you define as being a class member, like so[CODE] def printB(self): print "B"[/CODE]You then call it with self.printB() See this page from "How To Think Like A Computer Scientist" [url]http://www.greenteapress.com/thinkpython/html/book018.html[/url] | |
Re: [QUOTE]I essentially need to compare each Item in a list to every other item in the list.[/QUOTE]Generally speaking, to compare you start with the first item in the list and compare to item #2, #3, etc. Then the same for the second item through n-1, as there is nothing to … | |
Re: That comes from the OS and depends on what "graphic card details" means. If you just want to know what type of graphics card, use subprocess to run lspci and pipe the output to a file. You can then read the file and search for "graphic". | |
Re: You can use the id also since you only want a name that is unique. Perhaps a dictionary with name/id --> class + args as well. [CODE]class TestClass(object): def __init__(self): print "class instantiated" ins = TestClass() unique_name = str(id(ins)) print unique_name [/CODE] | |
Re: I don't see a problem on my machine using this simple example so it probably has nothing to do with time.sleep(). The queue perhaps? [CODE]import time from multiprocessing import Process class TestClass(): def test_f(self, name): ctr = 0 while True: ctr += 1 print name, ctr time.sleep(1.0) if __name__ == … | |
Re: [QUOTE]Write a PYTHON function that takes the time as three integer arguments (for hours, minutes, and seconds)[/QUOTE] You are supposed to create a function, not a class, that takes three arguments/parameters. Your class doesn't take any arguments. You can take a look at functions [URL="http://hetland.org/writing/instant-python.html"]here[/URL] for a simple example. | |
Re: [CODE]L = 10 - len(answer) list.append(answer + ' ' * L)[/CODE]You can do this if you want but remember that Python has most things built in so you can also use: (look up string formatting) [CODE]print "%10s %10s" % (car, answer) ## ## and your original code should read print_list … | |
Re: You should be able to read the 100 bytes, split and write. The following code uses 25 bytes and splits from 10 through 20 (11 bytes) for simplicity. [CODE]alpha = "abcdefghijklmnopqrstuvwxy" print alpha print alpha[9:20][/CODE] | |
Re: Here is a link to simple on-line tutorial. See the explanation under "Functions". You should book mark this link for future reference [url]http://hetland.org/writing/instant-python.html[/url] | |
Re: You would have to use Tkinter or one of the other toolkits. An example [url]http://tkinter.unpythonic.net/wiki/AutocompleteEntry[/url] | |
Re: Since you are running an app outside of the Python environment, via os.system, the mouse is controlled by the external app that you are running. | |
Re: Perhaps I am missing something, but the following code should work. But once you get past the precision of floating point numbers you will have to use the decimal module whichever way you do it. [CODE]import decimal x = decimal.Decimal("2.4999999999999999999999999") whole, remain = divmod(x, 1) if remain >= decimal.Decimal("0.5"): whole … | |
Re: You have to install pygtk, which is the python binding to GTK, for the 2.5 version. If you look in the /usr/lib/ directory for 2.6.4 you should see a directory for pygtk. I would first search the Fedora repositories as it should have both Python2.5 and PyGTK for 2.5. | |
Re: I prefer to bind the button to a function that returns the desired variable, but it is somewhat personal preference. [CODE]from Tkinter import * class ChooseVideoFiles: def __init__(self, root): canv = Toplevel(root) canv.geometry("+150+250") title = Label(canv, text = "Select 3 videos with specified or a bit longer length", font = … | |
Re: Use root.withdraw [CODE]from tkinter import * ##from tkinter import ttk from tkinter import messagebox root = Tk() root.withdraw() answer = messagebox.askyesno(message="Are you thinking of the " + "data " + "?" ,icon='question' ,title="My guess") print(answer) [/CODE] | |
Re: Can you just strip off the first and last parameter? [CODE]## path_file "".join(sys.argv[1:-1]) import os test1 = ["program_name.py", "one/path/", "two_paths/", "three", "second_arg"] path_file = "".join(test1[1:-1]) print path_file if os.path.isfile(path_file): ## etc [/CODE] | |
Re: See this comment is tbone2sk's reply above. [QUOTE]Line 33 Python Syntax (Toggle Plain Text) return windowSurface return event A method can not have more than one return statement, both of these variables can be returned as a tuple though. [/QUOTE]The first culprit to check on is to see if "event" … | |
Re: [QUOTE]These files are between 6 and 15 mb is size.[/QUOTE]That's not very large by today's standards so I doubt that "MemoryError message" means running out of memory. Try running the program with a try/except and maybe you will get error messages that show what and where the error is, as … | |
Re: The problem is more one of viewpoint, not coding. You want to get away from the word processing mentality. There is no such thing as lines in a document in a folder (unless the programmer first creates them). We have data (bytes) in two files that we can use or … | |
Re: You have to find some unique combination that you can split on. If SV= is always the final string then you can split on that. You could also split on finding X number of capital letters in a row. [CODE]## an easy way to create the string from the post … | |
Re: To get a matrix, you would have to split each record in the file. The file will be read in as a single dimension list if each record has a newline. You then have to split each record on the individual fields to get a matrix that you can access. … | |
Re: Using EasyGUI [url]http://easygui.sourceforge.net/download/current_version/tutorial/[/url] is a simple solution and should solve the problem | |
Re: Is self.storeli a list or a dictionary? I would suggest that you print self.counter and len(self.storeli) before the line in question. +1 on Beat_Slayer's suggestion. | |
Re: The following part of your code doesn't make sense. You should go back to where ever the code came from and double check that it was copied correctly, and that you copied all of the code supplied. Also, print the dictionary to see what it contains. [CODE]clist= {} for word … | |
Re: Python has a CSV reader/writer [url]http://docs.python.org/release/2.5.2/lib/csv-examples.html[/url]. I would suggest you start with reading the file and printing individual rows and columns so you discover how to access them individually. Google is your friend here. | |
Re: You would have to use threading or multiprocessing. One thread/process would run festival, while another process would capture some input and send a notice (change a variable) in the first process. Obviously you would have to communicate between the two processes. | |
Re: Mechanize is an easier way IMHO to do this. This link explains how to log in with a user name and password to a remote site [url]http://stockrt.github.com/p/emulating-a-browser-in-python-with-mechanize/[/url] | |
Re: The general way to create a dictionary is to split the text file records into a key and data, then [CODE]if key not in the_dictionary: the_dictionary[key] = [] ## this is a list but you can use whatever type you want the_dictionary[key].append(data) [/CODE] For additional help you should post some … | |
Re: This is trivial without regular expressions. Read one record, split into words, and test each word; read the next record, etc. Note that the following two lines probably don't do anything as Original_File_Content is one, long string. See Section 7.2.1 for clarification [URL]http://docs.python.org/release/2.5.2/tut/node9.html#SECTION009200000000000000000[/URL]. If it is a very large file, … | |
Re: Gedit is going to use whatever locale the OS is set up for. I'm sure you can probably change the UTF for gedit alone, although I don't use it so don't know. You can also change the locale which would make the change system wide, but how you do this … | |
Re: Somebody should Google disk cache. This is the doc for flushing write commands. [QUOTE]file.flush() Flush the internal buffer, like stdio‘s fflush(). This may be a no-op on some file-like objects. Note: flush() does not necessarily write the file’s data to disk. Use flush() followed by os.fsync() to ensure this behavior. … | |
Re: [QUOTE]there is no main[/QUOTE]Python does not require a "main" function. I would be better the say that no instance of the class has been called/created. This is a link to the instant python tutorial which includes classes [url]http://hetland.org/writing/instant-python.html[/url] If you copied this program and want to modify it, I would … | |
Re: Actually this is more a function of the desktop, each of which has wrappers to perform this function. KDocker for KDE is only one that comes to mind right now but there are sure to be more, perhaps one or two that are not desktop specific. |
The End.