133 Posted Topics

Member Avatar for frank_albers123

Read the last post of masterofpuppets to your other thread ([url]http://www.daniweb.com/forums/thread235765.html[/url]) and you'll nearly have the answer... Put his code in a function (pascrow), change the for loop condition and the print statement and you've got it

Member Avatar for jice
0
112
Member Avatar for tototo

Oh yes, you've got another choice. Use your brain. This assignment is fairly doable and, if you search this forum or others, you'll find plenty of ways to do it. I'm afraid that your post shows someone that doesn't want to bother with this assignment. I'd be interested in knowing …

Member Avatar for jice
-4
143
Member Avatar for twoshots

doing x=Stuff make of x an alias to the Stuff class. Try this : [CODE] class Test: def __init__(self): self.a="a" x=Test print x y=x() print y.a [/CODE] This may be useful if you want to pass an object definition as an argument for a function. Never happened to me yet …

Member Avatar for twoshots
0
122
Member Avatar for bdesc100

Totally agree with Gribouillis. This is not a good way of doing things. Many problems may occur. You may use a dictionnary instead: [CODE] def myfunc(arg1, arg2): d={'x':2, 'y':3, 'z':4} return d[arg1], d[arg2] print myfunc('x', 'y') # returns: 2, 3 print myfunc('y', 'z') # returns: 3, 4 [/CODE] But in …

Member Avatar for paddy3118
0
113
Member Avatar for Kruptein

you can use list comprehensions [CODE] g = "ThisIsATestt" print [g[i:i+2] for i in range(0,len(g),2)] [/CODE]

Member Avatar for jice
0
104
Member Avatar for saikeraku

My 2 cents... 1 - I prefer for loop than while ones when I can (less code to write and no infinite loops). [CODE] start = int(raw_input("Start at: ")) end = int(raw_input("End at: ")) count = int(raw_input("Count by: ")) for i in range(start,end+1,count) : # end + 1 because range …

Member Avatar for cornflakes
0
347
Member Avatar for Judgment

I would add that [B]exactly[/B] the same question was posted 2 days ago. [url]http://www.daniweb.com/forums/thread230626.html[/url] It would be a good idea to search the forum before asking...

Member Avatar for vegaseat
-1
297
Member Avatar for mahela007

It points to the original variable. This is true for all variables containing objects. For a list, if you want to duplicate it, you have to do [CODE] mylist = [1,2,3,4] a = mylist[:] a[0] = 'hello' print mylist [/CODE]

Member Avatar for jice
0
332
Member Avatar for awa

first of all your function getdata should return the values you want : [code] def getdata(data): # the code you've already written return number, items [/code]

Member Avatar for awa
0
117
Member Avatar for rociel

[CODE]numQuiz = input("Enter the number of quizzes: ") total = 0 for i in range(numQuiz): print ('Enter quiz score %d: ' % i) # # OR print ('Enter quiz score ', str(i), ' : ') score= input() total = total + score print "------------------------------------" # Compute the average and print …

Member Avatar for rociel
0
129
Member Avatar for Joe Hart

Beware of the ''. You should write [CODE] textfile = file('C:\\HourlyATC\\ATC101509\\10-15-09 to 10-21-09 ATC.txt','w') # \\ and 'w' [/CODE]

Member Avatar for baki100
0
145
Member Avatar for zyrus001

Could you post some code or be more precise ? Is this list made of objects from the same class ? Maybe should you implement the __cmp__ OR __eq__, __ge__, __gt__, __le__, __lt__ and __ne__ special method in your object... That would allow comparisons between objects. and sort them

Member Avatar for jice
0
244
Member Avatar for AutoPython

Why do you want to have vars named POSn. I wouldn't do that... Very complicated. It's far easier to have one list variable where you assign pos[n] [code] pos=[' ' for i in range(10)] # defines a list inited with [' ', ' ',... ten times] pos[POS-1]='->' [/code]

Member Avatar for AutoPython
0
148
Member Avatar for darkbow
Member Avatar for kingofkya

I don't think so : zip.write waits for a file NAME and you pass a file OBJECT. I think this may be done by using the second argument of zip.write : [CODE] zip.write(filename, arcname=None, compress_type=None) # filename = the file you want to archive # arcname the name you give …

Member Avatar for kingofkya
0
204
Member Avatar for The-IT

I don't have time to test extensively your code but i'd begin by looking at loops. I've seen a couple of while True... How long do you stay in these loops ? You should test and locate precisely where your program lose time.

Member Avatar for jlm699
0
3K
Member Avatar for Joe Hart

I can't copy the text to test... Is this to be a html file ? Are the <br /> tags or are they supposed to show CR. Your BBCodes don't work... How can you select one line if all your file seems to be on an unique line ?

Member Avatar for Joe Hart
0
123
Member Avatar for goboman
Member Avatar for jice
0
90
Member Avatar for pelupelu

a fourth : [CODE] import re st = "abcd123" rdigit=re.compile("\d") print rdigit.findall(st) [/CODE] Which can be onelined : [CODE] import re print re.compile("\d").findall("abcd123") [/CODE]

Member Avatar for jice
0
86
Member Avatar for thoutmosis

[CODE] outfile = 'OUTPUT' output = open(outfile, 'w') for line in open('DATA'): # You don't need to open the file and load it in a list (bad for memory) linelist = line.strip().split() # Strip will remove trailing spaces and '\n' if linelist[1][4:6]=='MG' and linelist[1][-2:] not in ['RE', 'RD']: output.write(line) [/CODE]

Member Avatar for thoutmosis
0
71
Member Avatar for amadain

I think this one is better... [CODE] import re testStrings=[ "POST at the start without the other word", "GET at the start without the other word", "GET first\nthen POST and more", "POST first\nthen GET and more"] splitter = re.compile('(POST|GET)') for s in testStrings: splittedString=splitter.split(s)[ 1:] print [ splittedString[i]+splittedString[ i+1] for …

Member Avatar for jice
0
274
Member Avatar for lewashby

[ ] is generaly used for indexing (see the list, tuple or dictionary chapters in the doc). [CODE] mylist=[ 1,2,3,4,5,6] print mylist[ 3] > 4 [/CODE] If you see strings like some kind of char tuple (immutable list), everything appears to be very simple as it works exactly the same. …

Member Avatar for jice
0
122
Member Avatar for darkbow

First of all, rewrite your code with correct indent. This is very significant in python and your code is very strangely indented (i'm surprised this works...) class effectIllusion shouldn't be indented, nor def updateSimObjects(self): if not mount0: and following is inconsistent...

Member Avatar for woooee
-2
124
Member Avatar for oasuspender

and you should use float instead of int [CODE]print float(miles_driven) / float(gallons_of_gas_used) [/CODE]

Member Avatar for vegaseat
-1
98
Member Avatar for DMcQuinn

[QUOTE=woooee;1002040] [CODE] ## and if you have an unusual series of numbers, use a list iterate_list = [0.0, 0.2, 0.3, 0.5, 0.6] for r in iterate_list: print r[/CODE][/QUOTE] To continue in this direction, you can use a list you construct the same time (called list comprehension)... This is not very …

Member Avatar for vegaseat
-1
15K
Member Avatar for jasonehoss

Vegaseat forgot a little point [QUOTE=vegaseat;1001729] [code=python]# This script will determine the size if the gwarchive directories # in everyone's home folder import os folder_size = 0 for username in open("L:\\dirl.txt"): folder = "L:\\" + username.strip('\n') + "\\gwarchiv" # <== remove the ending "\n" print folder for (path, dirs, files) …

Member Avatar for jasonehoss
-1
99
Member Avatar for scrace89

Beware of your indent... Very important in python [code] print 'one' print 'two' # <== ERROR (one space too much) print 'three' if condition # < ERROR (missing : ) print "four" # < ERROR (missing indent) [/code]

Member Avatar for scrace89
-1
161
Member Avatar for redpython

[QUOTE=baki100;1000295]you can use a dictionary but it won't be wise to use the surname as the key instead use the position number. for the itemvalues you can use a list and you can append new values later if needed so basically you have a list in the dictionary.[/QUOTE] It is …

Member Avatar for redpython
0
191
Member Avatar for chico2009

[QUOTE=chico2009;999542]Hi Thanks folks for your replies. Testing the general format shown below returns a character and not the complete line [code=python] lpa=1 text_file = open("English101.txt", "r") print text_file.readline()[lpa] text_file.close() [/code] What I am trying to achieve is that a complete line of text is returned, from a text file that …

Member Avatar for ov3rcl0ck
0
279
Member Avatar for jtabak2

Could you post an extract of the input file and an example of what you would like in the output one...

Member Avatar for jice
0
165
Member Avatar for romes87

[QUOTE=gerard4143;995454]Why don't you def your function like [CODE] def second(s): str = string.split(s) return str [/CODE] then you can print it like print str(second(string))[/QUOTE] I don't understand the problem : if you do like this, you can call the function from the other file doing : print str(twond.second(string)) and it …

Member Avatar for romes87
0
4K
Member Avatar for zyrus001

I'd store the blocks in a list, looking for the pattern in each line and, if i find the pattern in one line, write the whole block out. [CODE] isBlockToWrite=False pattern="COMMS_MESSAGE_SENT" block=[] outfile=file("log3.log","w") for line in file("log2.log"): block.append(line) if line[:10] == "*" * 10: if isBlockToWrite: outfile.writelines(block) block=[] isBlockToWrite=False if …

Member Avatar for zyrus001
0
172
Member Avatar for Triverske

what is the precise error message ? How did you install python ? What is your OS ?

Member Avatar for Stefano Mtangoo
0
108
Member Avatar for akie2741

this may be working. [CODE] import re datas=open("file.html").read() expr=re.compile("<adress>(.*?)</adress>") for match in expr.findall(datas): print match [/CODE]

Member Avatar for jice
0
141
Member Avatar for chico2009

Here are somme comments on what you ask. This is not a working program but gives you functions you can use for the different steps using your way. I don't understand everything you are doing and this seems very complicated to me. Very old style to deal with files. Python …

Member Avatar for jice
0
163
Member Avatar for jtabak2

I post my answer here too (i did it first on your other thread) you've got an easy way of doing this : [code] datas="""[(0,1),(1,1),(2,1),(2,2),(1,2),(0,3),(-1,4),(-2,4),(-1,5)] [(0,1),(1,1),(2,1),(2,2),(1,2),(0,3),(-1,4),(-2,4),(-1,5)] [(0,1),(1,1),(2,1),(2,2),(1,2),(0,3),(-1,4),(-2,4),(-1,5)]""".split('\n') for data in datas: exec ("lst=%s" % data) Prot='HPPHPPHHP' for i, coord in enumerate(lst): for elt in coord: print elt, print Prot[i] [/code] …

Member Avatar for jice
0
155
Member Avatar for chico2009
Member Avatar for AutoPython

[QUOTE=AutoPython;988381] [CODE] def testfunc(): global c c = "test" testfunc() c1 = c del c print (c1) input () [/CODE] [/QUOTE] My question is : why don't you do [CODE] def testfunc(): return "test" c1 = testfunc() print (c1) [/CODE] I totally agree with what is said : globals should …

Member Avatar for AutoPython
0
331
Member Avatar for vlady

Just to help you to understand what you have to do : a is a power of b if it is divisible by b and a/b is a power of b : a is power b => a/b is power of b : example : 1000 is power of 10 …

Member Avatar for vlady
0
3K
Member Avatar for ravi_72

I don't know about this tool but i would guess that the script tries to delete an opened file (is it a zip file or a file inside a zip file, i don't know)

Member Avatar for Stefano Mtangoo
0
108
Member Avatar for klabak85

You can try this : [code] fileName = raw_input("Enter the file name you want to read (name.txt): ") comments=[] inComment=False for i, line in enumerate(open(filename)): # You can loop directly on the file lines if "//***" in line: inComment = not inComment if inComment: print "comment found at line %d" …

Member Avatar for jice
0
150
Member Avatar for lifeworks

[QUOTE=sravan953;986688] Also, for the GUI, you have tkinter and wxPython. tkinter is a little old, so wxPython is the order of the day! ;)[/QUOTE] But tkInter is included in the standard distribution...

Member Avatar for sravan953
0
168
Member Avatar for bolter

This may help you : [url]http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/2316047[/url]

Member Avatar for jice
0
98
Member Avatar for nunos

You should not remove elements from a list you are looping on [code] list=[1,2,3,4,5,6,7,8,9] for i in list: if i in [4,5,6]: list.remove(i) print list > [1, 2, 3, 5, 7, 8, 9] [/code] When you remove an element, the followings ranks are modified (minus 1) so some elements are …

Member Avatar for nunos
0
344
Member Avatar for miac09

Here is a solution... [code] datas="""2 1 863.8 300.2 0.0131 0.0759 0.1727 0.0879 1.5821 3 1 874.5 289.5 0.0574 0.1292 0.4447 0.2258 1.1846 3 2 874.5 289.5 0.0573 0.0527 1.0857 0.1684 1.1760 4 1 844.3 319.7 0.1306 1.3513 0.0967 1.3976 2.2659 4 2 849.2 314.8 0.1350 1.3332 0.1013 1.3773 1.9990 …

Member Avatar for jice
0
160
Member Avatar for stellalxin

You can get rid of encryption by converting your file to ps and back to pdf (using ghostscript for example).

Member Avatar for stellalxin
0
978
Member Avatar for katamole

you should use : [code=python] >>> mystring[13:0:-1] '!dlroW ,olle' [/code] But the first letter isn't taken as the second parameter of the slice is to be excluded... To have the first letter (H), you'll need to do [code=python] >>> mystring[13::-1] '!dlroW ,olleH' [/code]

Member Avatar for sravan953
0
144
Member Avatar for denniskhor

use fnmatch module to filter : [url]http://docs.python.org/library/fnmatch.html[/url] os.rename to move your file

Member Avatar for zachabesh
0
134
Member Avatar for jcmeyer

You can do more efficient : [code=python] sql = "SELECT Name FROM nameDatabase" self.cursor.execute(sql) list=[element[0] for element in self.cursor.fetchall()] print list [/code]

Member Avatar for jice
0
112
Member Avatar for gujjar19
Member Avatar for gujjar19
0
143

The End.