2,190 Posted Topics
Re: Assuming the name of your program is helloWorld.py, you would add the first line in the following example which tells the OS to use Python to run this program. Also add the "__main__" section at the bottom and make the file executable by your user name. You can then enter … | |
Re: [QUOTE=A no-name-moose;705114]Literally, what i want is >"if the all the letters in the Word match the letters in the successful letters do whatever"< any suggestions? Thank you very much for reading this ;)[/QUOTE] So I think you are asking how to do this[CODE]found = True for letter in MainInput: if … | |
Re: [QUOTE]Sorry for the dumb question, I saw the problem, thanks for looking though.[/QUOTE]They are pretty much all dumb.....after you find the answer. Also, please mark the post solved. | |
Re: Is anyone else getting a little tired of the "I Googled it and couldn't find anything" lie. "python sum list" brings up "total = sum(list_name)" as the second hit. Searching for "python adding list" gives both the sum() and a for() loop as examples on the fourth hit. But is … | |
Re: "How to Think Like a Computer Scientist" is one of many online books that can help with classes. [url]http://www.greenteapress.com/thinkpython/thinkCSpy/html/[/url] [url]http://www.python-eggs.org/[/url] | |
Re: [QUOTE]I want to refer back to the previous values without having to list all of them out again [/QUOTE]To answer your original question, you can copy a list with [CODE]orig_numbers_list=[10,13,32] for j in range(48, 123): orig_numbers_list.append(j) numbers = orig_numbers_list[:] print "orig =", orig_numbers_list del numbers[0] del numbers[5] print "\n\ncopy =", … | |
Re: [QUOTE]Note: I just managed to try the new one on a Windows machine, and it worked. WTF.[/QUOTE]It might have something to do with line endings. MS Windows uses decimal 13 & 10 and Linux (Mac) uses decimal 13 only. Since MS Windows pickle works on Windows and Mac's works on … | |
Re: You do want threading (note the "ing"), not subprocessing which is used to run a single instance. This link is to Doug Hellman's examples which are excellent. [url]http://blog.doughellmann.com/2008/01/pymotw-threading_13.html[/url] The other choice would be to use pyprocessing [url]http://pyprocessing.berlios.de/doc/intro.html[/url] There is also fork and spawn but threading or pyprocessing are preferrable as … | |
Re: Possibly, one hundred loops of a for() statement happens so fast that it is done before any other data is received. Try this example which sleeps for half of a second and see if the data changes.[CODE]for x in range (0,100): s = ser.readline() print x, repr(s) time.sleep(0.5)[/CODE] | |
Re: Post the code that you have so far. It's a straightforward program which asks for input, calculates the result, and prints the output. | |
Re: [QUOTE]I wanted to know if i could get some help to start the menu.I'll do the maths part working with the iterations etc as i learnt about loops today[/QUOTE]Post the code for the math and we will help with the menu. Of course it's not going to happen. The strategy … | |
Re: x = len(matches) so when you delete a character, the length of matches is reduced but x remains the same. There are several ways to do this. The easiest would be to test for if word.lower() in matches.lower(), but if you want to use this example then remove the del … | |
Re: [QUOTE]I am trying to create tuple but not able to do it.[/QUOTE]You can not change a tuple, you have to use a list. If I read your code correctly, you want something like the following [CODE]subject = "test subject" message = "message test" sender = "sender@test.com" data_list = [] for … | |
Re: [QUOTE=jlm699;697316]Read the [url=http://docs.python.org/lib/module-time.html]docs[/url] please.[/QUOTE][url]http://www.google.com/search?hl=en&client=opera&rls=en&hs=xhs&q=python+day+of+week&btnG=Search[/url] The very first hit. It's questions like this that cause me to run out of flame retardant. It's interesting that the third hit is Zelller's congruence (for anyone who want's to calculate it themselves). That hit also references calendar.weekday. | |
Re: Except that neither one thought to test for a < 0 (if someone doesn't know any of the words) or a => len(words). Also, you have 19 words and 20 answers. When doing this type of programming it is better to (a) use a dictionary with the word as the … | |
Re: A Google for "Tkinter menu" will yield numerous examples. New Mexico Tech [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/[/url] and Fredrik Lundh [url]http://hem1.passagen.se/eff/[/url] have good Tkinter sites. The following code came from "Charming Python", also a good site. [url]http://www.ibm.com/developerworks/linux/library/l-tkprg/#h5[/url][CODE]def help_menu(): help_btn = Tkinter.Menubutton(menu_frame, text='Help', underline=0) help_btn.pack(side=Tkinter.LEFT, padx="2m") help_btn.menu = Tkinter.Menu(help_btn) help_btn.menu.add_command(label="How To", underline=0, command=HowTo) help_btn.menu.add_command(label="About", underline=0, … | |
Re: You want a separate string to hold the time[CODE]now=time.asctime() now=now.replace(":", " ") print now TimeStr = [ "The time is currently " + now, "Right now its " + now, "It's " + now, now ] if phrase == "whats the time": speech.say(random.choice(TimeStr)) # ## you can also use datetime … | |
Re: Adding these print statements should shed some light on this if I understand what you want to do. Run it this way and if it does not give you an idea of what is happening then post back.[CODE]quotelist = [] for line in linelist: thesplit = line.split() print "\nline" print … | |
Re: For future reference, you do not want to assume that the characters you search for are found. This is better IMHO, although I too would prefer to use .split(".")[CODE]if start == -1: break najdi = DB.find ('.', start) if najdi > -1: end = DB.find ('.', najdi) if end > … | |
Re: My personal preference would be using a dictionary since it would be indexed on the number, but there are several ways to do this along the lines of the following. Add the recs to a dictionary. When a 7 is found, send the dictionary to a function to process. If … | |
Re: Your question is too vague to answer. What does "cannot specify a new filename and can only overwrite an existing one" mean? Are there errors? If so what are they? The saveFile function would be the first place to look. What does "print saveFile" display? Also, it is bad form … | |
Re: Note that you are reading an "exe" file. The first character is probably not alphanumeric or a space so it stops. You haven't gotten many responses because of laziness. Add a print statement to see what is being read [probably want to print ord(a) since it is not a text … | |
Re: You can only have one number inside a bracket. You want something like the following to get the fourth element, but only if it is a list of lists[CODE]print type(line[0]), line[0] if (i==2): width = line[0][3] ## ## or if you want the first three letters if (i==2): width = … | |
Re: For future reference, it seems that matplotlib at sourceforge.net (matplotlib.sourceforge.net) would be one solution to statistical calcs like percentile and root mean square, in addition to checking the scipy programs. | |
Re: The latest one is, 'My wife was killed in a car accident a year ago and I have terminal cancer and will die in X months. Since we have no children, i would like to donate my estate of some-tremendous-amount to an orphanage but don't know of any. If you … | |
Re: I would also suggest that you print s1 and s2 at the appropriate points so you can see what is going on. For example in the following snippet, what is the value of s1 if x%d does not equal zero and how does that effect s2?[CODE] if x%d==0: s1=s1+x/d[/CODE] | |
Re: Try writing and testing your programs on piece at a time. I've commented everything after the __init__ function for Player1 below. Run it that way first and see if that helps. Then add the functions one by one and test them. The problem is not that Player1 doesn't have an … | |
Re: I wondered why this has been asked many many times in the last few days both here and on python-forum. At least you are honest enough to admit that it is homework. You should be able to find this asked and answered many times already. If you do want help, … | |
Re: With Python you would use a list of lists for each group of records. Hopefully there is a similiar method in scipy. (If you were very, very lucky, each group would have the same number of records, you can use a counter to split them)[CODE]data_list=[ "#BEGIN 1", "1 .1 .2", … | |
Re: A Google codesearch came up with only the do it yourself, the gist of which used textChanged. This snippet was in one of the hits[CODE] searchLabel = QtGui.QLabel(" Search", self) hLayout.addWidget(searchLabel) self.searchText = QtGui.QLineEdit() searchLabel.setBuddy(self.searchText) hLayout.addWidget(self.searchText) self.treeWidget = self.createTreeWidget() vLayout.addWidget(self.treeWidget) self.connect(self.searchText, QtCore.SIGNAL('textChanged(QString)'), self.treeWidget.searchItemName)[/CODE] | |
Re: readline reads until it hits a line termination, (\n=decimal 10 in ascii, or \r\n=decimal 13 & 10, depending on the OS). Decimal 26 is generally used in ascii for end of file, which would terminate a file read also. So a byte is read and if it is not a … | |
Re: Take a look at the textwrap docs here [url]http://docs.python.org/lib/module-textwrap.html[/url] You should be able to use initial_indent and subsequent_indent for the left side spaces. For spaces on the right side, reducing width by 2 should get that, but I have never used textwrap. Also, it is not meant to be a … | |
Re: Just came across this thread. The only surprising thing is that no one has tried to tie the subject to an oxymoron. We Americans are not liked in some parts of the world even though the U.S. does more than any other nation to feed the poor, heal the sick, … | |
Re: It looks like your problem is here '+idpracownika+','+a+'kawaler'+a+',0,false)' You have +idpracownika +',' +a +'kawaler' +a +',0,false) ## you have to have at least one more (or one less) single quote here If you create a string and use that, you can then print the string to see if it is … | |
Re: python.org also has a tutorial. Try them all. Some parts of one will make more sense, and in another part, one of the other tutorials will be better. [url]http://docs.python.org/tut/tut.html[/url] | |
Re: And os.path.isfile(name) will work for a file. Note that name is the full name, so include the full path. | |
Re: The numbers come from the file as strings, not integers. Strings sort left to right so 100 --> 1 & (00) is less than 95 --> 9 & (5) Hopefully this bit of code will help [CODE]test_int_list = [ 80, 0, 60, 25, 50, 70, 75, 100, 90, 95 ] … | |
Re: There is not enough code here or enough of the error message to help you. If you are not using a class,[CODE][/CODE] the "self." will yield errors. This is an example using QVBoxLayout that hopefully will help.[CODE]#**************************************************************************** #** $Id: lineedits.py,v 1.1 2002/06/19 07:56:07 phil Exp $ #** #** Copyright (C) … | |
Re: To read the stdout, use communicate(). Take a look at Doug Hellmann's examples here. [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url] Also, you can pipe the output to a file (on Linux anyway). | |
Re: There are various tutorials on the web as well as on python.org . Try one of the tutorials so you can present some code that we can help you with. [url]http://www.faqts.com/knowledge_base/view.phtml/aid/23158/fid/552[/url] | |
Re: There are times when pyprocessing is a better choice. Using the queue and jointhread may be another solution, but the specifics are only known by yourself. [url]http://pyprocessing.berlios.de/[/url] | |
Re: Include a small code snippet that demonstrates what you want (it doesn't have to work, just use descriptive variable names). I think you are talking about passing variables from/to functions, classes, and separate program files, which is done in practically every program written, but a descriptive piece of code would … | |
Re: I think the gadfly maintainer stopped supporting gadfly several years ago. A big criteria for choosing is forums and/or documentation support, which gadfly did not have AFAIK. There are very, very few experts so you will be using them. In any case you want to use SQLite or metakit which … | |
Re: Use rec.split("*") and then convert the strings to an int and divide by float(100). Remember to round if converting back to a string as floats are not exact. Or you can use slice[:-2] to get everything except the last 2 digits and [-2:] to get only the last 2, and … | |
Re: Pypy is the faster Python. I have never tried it though. [url]http://codespeak.net/pypy/dist/pypy/doc/home.html[/url] | |
Re: Use a for loop to read the first 20 recs into a list, we'll call it move_list, and then remove the first item each time you read a new rec. With only 20 values you don't have to be too concerned about memory use or processing time, something like this … | |
Re: [QUOTE]I get no returned rows. I use the following SQL code to query: SELECT * FROM fdi.fdiresults;[/QUOTE]fdi.fdiresults seems odd for a table name. Try "SELECT tablename FROM pg_tables where tablename not like 'pg_%'" and see what it gives you for a table name. (Note that semicolons are not used in … | |
Re: Something like the following is a simple example and usually works. If not, then you will have to Google for your specific sendmail app.[CODE]fromaddr = "<me@localhost>" toaddrs = "<you@localhost>" msg = "Test of Python's sendmail\n" # The actual mail send part server = smtplib.SMTP('localhost') server.set_debuglevel(1) server.sendmail(fromaddr, toaddrs, msg) print server.verify( … | |
Re: This might be easier to understand (not tested). This is not as efficient as storing the value as you perform one additional split() per record instead of storing it, but it may be more straight forward.[CODE]import math data = open(filename, "r").readlines() ## reads entire file into list stop=len(data) daily_list=[] for … | |
Re: It is a good idea to insure that there is no white space in any of the records, so you should include rec = rec.strip() then you can use [code]substrs=rec.split() substrs[0] = substrs[0].upper() if (substrs[0].startswith("MM")) or (substrs[0].startswith("HS"):[/code] |
The End.