2,646 Posted Topics

Member Avatar for king_koder

[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'] …

Member Avatar for king_koder
0
231
Member Avatar for mbartz
Member Avatar for neocortex

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)) …

Member Avatar for Neil Fraser
0
1K
Member Avatar for Teiji

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]

Member Avatar for TrustyTony
0
366
Member Avatar for novice20

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 …

Member Avatar for npmaier
0
178
Member Avatar for Mr Tk

[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 …

Member Avatar for Mr Tk
0
3K
Member Avatar for knan

[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 …

Member Avatar for Gribouillis
0
158
Member Avatar for Shlaa

[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 …

Member Avatar for Shlaa
0
138
Member Avatar for j855
Member Avatar for j855
0
70
Member Avatar for danholding

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.

Member Avatar for Gribouillis
0
202
Member Avatar for henryford

[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 …

Member Avatar for richieking
0
152
Member Avatar for R2605

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]

Member Avatar for R2605
0
118
Member Avatar for vegaseat

[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 …

Member Avatar for Gribouillis
0
439
Member Avatar for knan

[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 …

Member Avatar for Gribouillis
0
152
Member Avatar for novice20

[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 …

Member Avatar for Gribouillis
0
131
Member Avatar for suntom

[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.

Member Avatar for richieking
0
1K
Member Avatar for knan

[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 …

Member Avatar for TrustyTony
0
203
Member Avatar for aint

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 …

Member Avatar for Gribouillis
0
99
Member Avatar for G33KKitty

Try [url=http://lmgtfy.com/?q=python+xml]THIS LINK[/url]. Click on the first link.

Member Avatar for Gribouillis
0
97
Member Avatar for gis-brad

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 …

Member Avatar for gis-brad
0
298
Member Avatar for iwanttolearnc

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() …

Member Avatar for iwanttolearnc
0
133
Member Avatar for novice20

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] …

Member Avatar for novice20
0
994
Member Avatar for pythonlearning

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.

Member Avatar for pythonlearning
0
172
Member Avatar for VectorAKA

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 …

Member Avatar for woooee
0
270
Member Avatar for BreezieWG

See the answer in this thread [url]http://www.daniweb.com/forums/thread320097.html[/url]

Member Avatar for Gribouillis
-2
87
Member Avatar for Limiter

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 = …

Member Avatar for Limiter
0
157
Member Avatar for JJHT7439

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]

Member Avatar for Gribouillis
0
3K
Member Avatar for dustbunny000

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]

Member Avatar for TrustyTony
0
89
Member Avatar for Limiter

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 …

Member Avatar for TrustyTony
0
300
Member Avatar for nawaf_ali

[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 …

Member Avatar for nawaf_ali
0
217
Member Avatar for blast

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' >>> …

Member Avatar for woooee
0
652
Member Avatar for sravyen

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.

Member Avatar for TrustyTony
0
7K
Member Avatar for ljjfb

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 …

Member Avatar for ljjfb
0
139
Member Avatar for testie
Member Avatar for TrustyTony
0
573
Member Avatar for MTN

Start simple: write the code which indefinitely asks the user the French word for 'one' and always answers that is correct.

Member Avatar for cghtkh
0
100
Member Avatar for ch1zra

[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 + …

Member Avatar for Gribouillis
0
144
Member Avatar for danholding

[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 …

Member Avatar for Gribouillis
0
269
Member Avatar for lewashby

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 …

Member Avatar for Gribouillis
0
192
Member Avatar for mtmalleus

[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 …

Member Avatar for Schol-R-LEA
0
185
Member Avatar for lewashby

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) …

Member Avatar for woooee
0
6K
Member Avatar for haojam
Member Avatar for woooee
0
249
Member Avatar for me4ka86

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.

Member Avatar for Gribouillis
0
106
Member Avatar for ZigZagMan
Member Avatar for kimmi_baby

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.

Member Avatar for Gribouillis
0
600
Member Avatar for rahul8590
Member Avatar for TrustyTony
0
202
Member Avatar for OffbeatPatriot

[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 …

Member Avatar for uve
0
796
Member Avatar for _neo_

DOn't you need to pass a flag to ./configure, like --enable-shared ? Check your configure options.

Member Avatar for _neo_
0
759
Member Avatar for thekevinguy

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.

Member Avatar for Gribouillis
0
155
Member Avatar for matkod

Try this [code=python] import pickle tilemap = pickle.load(open('data/tilemap2.txt', 'rb')) print (tilemap) [/code]

Member Avatar for Gribouillis
0
185
Member Avatar for DocBreen

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 …

Member Avatar for Gribouillis
0
119

The End.