2,646 Posted Topics
Re: [icode]mylist.sort()[/icode] works, but it sorts the list in place and returns None [code] >>> L = "the file I'm working with has all text in the same case, case doesn't matter here".split() >>> print(L) ['the', 'file', "I'm", 'working', 'with', 'has', 'all', 'text', 'in', 'the', 'same', 'case,', 'case', "doesn't", 'matter', 'here'] … | |
Re: try [icode]class A(object, ElementTree)[/icode] | |
![]() | Re: I don't know about google-diff-match-patch, but I once used an algorithm called compression distance. It returns a number in [0.0, 1.0], a "small" value meaning that the strings are close (or equal). [code=python] # python 2.6 from zlib import compress def distance (sx, sy): ab =len (compress (sx + sy)) … |
Re: In idle, sys.exit doesn't exit the process. Instead, the exception is caught and displayed [code=python] >>> import sys >>> sys.exit(False) Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> sys.exit(False) SystemExit: False [/code] | |
Re: It's a bad idea to try to upgrade your python installation on a linux system. Don't do it, because the system uses a specific python version to run. What you can do is install several versions of python. Currently, linux systems have 2 python packages: the package which comes with … | |
Re: [QUOTE=Mr Tk;1370215]Hi I have a question about a problem I'm having with raw_input function in python. I'm writing a CL program that requires a comment to be entered by the user, however problems arise when someone makes a mistake entering said comment. [CODE=python]comment = raw_input(Enter comment: )[/CODE] User Input: Archie^?ve … | |
Re: [QUOTE=knan;1370912]t-el!!!!! @everyone: yup. that "(" was making the problem.. i was working continuously for 20+ hours and my mind was all f***ed up!!! I had some nice sleep.. and then i could figure this out easily... Thanks everyone for the help![/QUOTE] Mismatched parentheses have a high probability when a SyntaxError … | |
Re: [QUOTE=griswolf;1370835]"[I]i still can't get it to restart the program fully without it showing previous results[/I]" Do you mean that you want the screen to erase the prior input and calculated results? That is tricky if you do it by clearing the screen, but you can do something very simple: At … | |
| |
Re: READ THE DOC! os.walk returns a sequence of triples (dirpath, dirnames, filenames) suggestion: install pydoc. You only need to type [icode]pydoc os.walk[/icode] in a terminal (cmd shell for windows) to see the doc. | |
Re: [QUOTE=griswolf;1369759]It ain't personal, its didactic. [B]Did[/B] you think about it? Perhaps I should have had Mr. Number visit a science expo one time and a primary school the next. Is the representation of the value 1111.111111 better as "1.11111*10^3", as "approximately 1100" as "1111 plus 1/9" or something else? Does … | |
Re: Why don't you use python's functions to access the file system ? A good pythoneer would write [code=python] import os os.chdir("/home/user/folder") if os.path.exists(filename): do_something() # we know the file exists else: do_something_else() # we know the file doesn't exist [/code] | |
Re: [QUOTE=delocalizer;1365155]Using [icode][charD]*len()[/icode] as an argument to [icode]map()[/icode] is clever, but in this context is a very poor "example of the map function" because it is so unPythonic. In 2.4 is better (and simpler) to do: [code=python]charD = dict([ (n, chr(n)) for n in range(32, 256) ])[/code] replacing five lines (including … | |
Re: [QUOTE=utpalendu;1369445]temp=1 main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']] for each_list in main_list: for ctr in range(len(each_list) - 1): temp=ctr +1 while temp < len(each_list) : print each_list[ctr],"-", each_list[temp ] temp = temp + 1;[/QUOTE] Please learn about code tags [url]http://www.daniweb.com/forums/announcement.php?f=8&announcementid=3[/url] See how better it looks: [code=python] main_list … | |
Re: [QUOTE=novice20;1369332]yes...i got a simple solution.. here s it, hoping it might help some newbie like me:) [B]if value[:4]== '4501': print "xxx..whatever..."[/B][/QUOTE] What you can do with an object depends entirely on its class. I suspect that your object's class is pyasn1.type.univ.OctetString. You should probably be able to convert the value … | |
Re: [QUOTE=suntom;1368795]Because if I remove the second login part, before server.sendmail, I get the following error. And only when I use server.login once more, I get passed the error - any advice regarding that? Thanks for your reply![/QUOTE] I think you should remove lines 47 to 51 included. | |
Re: [QUOTE=knan;1368469]Thank you very much. That was very helpful. How am I going to achieve the 1st and 2nd conditions. I am still trying, but i couldnt figure out a regular expression...[/QUOTE] You can write pseudo code to build the regular expression. You want to match this [code=text] pattern: either: symbol1 … | |
Re: The variables in a function's body are local to this function and can't be used outside the function. The solution is to return the variable and to catch the return value when the function is called [code=python] def example(a): alist=[] alist.append(a) print alist return alist # <---- return alist to … | |
Re: Try [url=http://lmgtfy.com/?q=python+xml]THIS LINK[/url]. Click on the first link. | |
Re: You could also use the strings substitution operator % [code=python] keywords = set("TOWN COUNTY".split()) # new keywords can be added here # helper code import re word_re = re.compile(r"\b[a-zA-Z]+\b") def sub_word(match): "helper for create_template" word = match.group(0) return "%%(%s)s" % word if word in keywords else word def create_template(format): "Transform … | |
Re: Each module has its own 'namespace', that is to say its own dictionary of known variable names. In your example, the (global) names defined in the module 'usermodule' are 'Image' and 'usermodule. The names defined in the main program are 'image', 'usermodule' and 'imload'. It means that the function usermodule() … | |
Re: If there is only 1 pair, you should get the value with [code=python] value = varBinds[0][1] [/code] This value's type is probably this Integer class [url]http://twistedsnmp.sourceforge.net/pydoc/pysnmp.asn1.univ.html#Integer[/url] or a similar class. Since the class has an __int__ method, you should be able to convert it directly to a python int: [code=python] … | |
Re: You should use optparse. There is an excellent tutorial here [url]http://www.alexonlinux.com/pythons-optparse-for-human-beings[/url] . Also note that in recent versions of python, optparse has been replaced by a module named argparse, but I never used it yet :). Optparse is very simple. | |
Re: You could write it this way [code=python] MONTH = ['January','Febuary','March','April','May','June','July','August', 'September','October','November','December'] def highestMonth (rainfall): bestMonth, bestValue = 0, rainfall[0] for month, value in enumerate(rainfall): if value > bestValue: bestMonth, bestValue = month, value return MONTH[bestMonth], bestValue def lowestMonth (rainfall): bestMonth, bestValue = 0, rainfall[0] for month, value in enumerate(rainfall): if … | |
Re: See the answer in this thread [url]http://www.daniweb.com/forums/thread320097.html[/url] | |
Re: A universal trick is to avoid numbered variables like num_1, num_2, but rather have a list 'num' and access the data as num[0], num[1]. This allows you to write loops. So you would have [code=python] num = list() for i in range(2): num.append(str(raw_input("Enter set %d: " % (i+1)))) errors = … | |
Re: Why don't you try the algorithm explained above ? I would write [code=python] def mulPoly(lst1, lst2): if isZeroPoly(lst1): return [] else: return addPoly( mulPoly(shiftRight(lst1), shiftLeft(lst2), scalePoly(constCoef(lst1), lst2) ) [/code] | |
Re: Write a loop [code=python] for i in range(3): print test(5) [/code] Or if you want to create a list of numbers [code=python] the_list = [ test(5) for i in range(3) ] [/code] | |
Re: Yes you can store several lines of input in a list before starting to work on them [code=python] numlist = list() for i in range(1,3): numlist.append(str(raw_input("Enter row " + str(i-1) + ": "))) # then check the content of numlist [/code] Note that in the case of 3 numbers, it … | |
Re: [QUOTE=nawaf_ali;1364131]It was really great piece of code, I really liked it, does any body knows how to get more statistics? like word length, sentence length, paragraph length, and if possible how to plug the results into a prgram like excel or matlab to get graphs of our results? your help … | |
Re: This session of the python interpreter should enlight you [code=python] >>> grades = raw_input("Enter grades:") Enter grades:10, 4, 4, 2 >>> print grades 10, 4, 4, 2 >>> # grades is a string (str). To examine it we print its repr ... >>> print repr(grades) '10, 4, 4, 2' >>> … | |
Re: A google search led me to this blog page [url]http://gwynconnor.blogspot.com/2010/04/copying-files-between-two-remote-hosts.html[/url]. Download scp_r2r.py at the bottom of the page, it should allow you to scp between the 2 hosts. Otherwise, you can use ssh and sftp with paramiko to transfer your files. | |
Re: I don't know anything at all about virtual machines, but if I wanted a script to execute another script on a remote host (with arbitrary argv), I would install a ssh server on the remote host and send the command to that server with the module paramiko. Can you access … | |
Re: You can print the characters one by one. Post your code, I'll post mine :) | |
Re: Start simple: write the code which indefinitely asks the user the French word for 'one' and always answers that is correct. | |
Re: [QUOTE=ch1zra;1363259]for some reason, it's working now again : [CODE]import os, time, re, Image, zipfile t0 = time.clock() path = "C:\\kontrolneliste\\docx\\" for (path, dirs, files) in os.walk(path): for file in files: fname = file[:7] docx = path + '\' + fname + '.docx' print docx destinationPath = 'c:\\aa\' + fname + … | |
Re: [QUOTE=danholding;1361524]the external program then sets conditions for the folder and puts databases in to it and creates log files? i just need the command for typing a string or text in to a external program as i can get it to open the program but not to type anything?[/QUOTE] You … | |
Re: The only potential error that I see in line 21 in gameobjects.py is division by zero if x and y are both 0 in a Vectory2 instance. Why don't you post the exception traceback ? A bug in your code is that after the sequence with the keys in lines … | |
Re: [QUOTE=Schoil-R-LEA;1361952]Can you tell us about the format of the text file your reading - that is to say, in what order do you expect things in? For example, does it have the name of the employee followed by the hourly wage followed by the hours worked? Or is it in … | |
Re: Here is an more complete example [code=python] >>> L = [ (1, (2, 3)), (4, (5, 6)), (7, (8, 9))] >>> for item in L: ... print item (1, (2, 3)) (4, (5, 6)) (7, (8, 9)) >>> for x, y in L: ... print x, y 1 (2, 3) … | |
Re: This thread is duplicate from this one [url]http://www.daniweb.com/forums/thread317912.html[/url] see my answer there. | |
Re: In linux, I do it this way [code=python] from pymouse import PyMouse m = PyMouse() m.click(1020, 390, 1) # it works ! [/code] The module pymouse can be found here [url]http://github.com/pepijndevos/PyMouse[/url] . It claims to be cross platform, so you should try it in windows. | |
Re: At line 8, it should be [icode]print test[/icode]. | |
Re: The traceback says it all: you are sending an SQL statement with a syntax error (perhaps the \n that it contains). Check the SQL syntax. This has nothing to do with using functions or not. | |
Re: You can replace line 3 with [icode]line = lines.rstrip().split(',')[/icode]. | |
Re: [QUOTE=uve;1361467]Hi! I tried it, but it doesn't work. PyImport_Import always return a NULL value. I supose that it is a path problem. If I try to import a core python module (sys, os, ..) the import works fine, but if I try to import other module (wx for example) it … | |
Re: DOn't you need to pass a flag to ./configure, like --enable-shared ? Check your configure options. | |
Re: Idle uses the tkinter GUI, which uses Tcl/Tk. Are Tcl and Tk installed on your mac ? Also: try to run idle from a command line to get the error message. | |
Re: Try this [code=python] import pickle tilemap = pickle.load(open('data/tilemap2.txt', 'rb')) print (tilemap) [/code] | |
Re: Here is a possibility [code=python] print "You have decided to attack the giant rat." ratHP = 100 while ratHP > 0: dmg = min(ratHP, random.randrange(1, 10, 1)) print "you did %d damge to the rat, giving it %d left" % (dmg, ratHP-dmg) ratHP -= dmg print "The rat is dead … |
The End.