2,646 Posted Topics
Re: It's a good idea, for example I don't know what an IDX shell is | |
Re: this way [code=python] mylist = ["whatever"] * 100 [/code] | |
Re: There is a full course on biopython from the Pasteur institute which includes reading Fasta format [url]http://www.pasteur.fr/recherche/unites/sis/formation/python/ch11s03.html#exa_seq_string[/url] I think you should read this course and use the Bio modules. Don't reinvent the wheel at first ! | |
Re: You say it doesn't open, but in that case there must be an exception traceback. What is the exception traceback ? | |
Re: I would suggest lists like this [code=python] cnt_img = 15 E_Path = [os.path.join("data", "E%d.gif" % k) for k in xrange(cnt_img)] E = [pygame.image.load(E_Path[k]) for k in xrange(cnt_img)] [/code] Then you can use [icode]E[k][/icode] and [icode]E_Path[k][/icode] to get the k-th image or path. | |
Re: you should call the method with the instance [icode]new_monster[/icode] and not with the class (orc or troll) [code=python] def main(): monster_attacking = random.randrange(1,2) if monster_attacking == 1: new_monster = orc() elif monster_attacking == 2: new_monster = troll() choce = raw_input('Do you want to attack:') if choice == 'yes' or 'yer' … | |
Re: If you're using linux, I would recommend kate, which has very nice features. | |
Re: Your question is not at all obvious. Where are you trying to write a superscript ? in a terminal ? a Tkinter canvas ? a printer ? a pdf document ? This is the main problem. | |
Re: Try this [code=python] for line ... if other_date ... ... more_logs = open(..., "w") try: new_log_data ... for line_data ... ... more_logs.write(new_data) finally: more_log.close() [/code] | |
Re: [QUOTE=blackrobe;724343]I've been reading an article but the code is written in C language which I don't get at all... The code is: [CODE]void traverse(Tptr p) { if (!p) return; traverse(p->lokid); if (p->splitchar) traverse(p->eqkid); else printf("%s/n", (char *) p->eqkid); traverse(p->hikid); [/CODE] Someone please translate it to python...[/QUOTE] A word to word … | |
Re: [icode]socket[/icode] is a standard class in the socket module. You should use it if you want to create a socket. However it often happens that one writes functions to create new objects. These functions call the normal object constructors. For example if you want to create a new socket connected … | |
Re: There is nothing strange, the shuffle happens in place, so rolls contains 3 references to the same list. You should write [icode]rolls.append(list(dice))[/icode] if you want to keep the intermediary states of the dice. | |
Re: I think you should use lists and tuples instead of just using strings, for example you could define a list of the previous guesses like this [code=python] previousguesses = [] [/code] Then you append triples to this list, in the game's main loop, like this [code=python] def main(): while ..... … | |
Re: A nice way is to use an exception. An exception allows you to exit the game at any moment, for example you could write this [code=python] class RestartException(Exception): pass class QuitException(Exception): pass def askUser(): # somewhere deep inside the game s = raw_input("do you want to restart ?") if s … | |
Re: there is also [icode]random.choice(let)[/icode] which would choose a random element of your list instead of choosing a random index. After that, use del let[pos]. | |
Re: A recursive way [code=python] def sum_cubes(n): if n <= 0: if n < 0: raise ValueError else: return 0 else: return n ** 3 + sum_cubes(n-1) if __name__ == "__main__": print sum_cubes(10) [/code] and a non recursive way [code=python] def sum_cubes2(n): if n < 0: raise ValueError res = 0 … | |
Re: From the documentation of Py_Initialize(), I think it would be a good idea to try [code=C++] Py_SetProgramName("path to the python executable"); [/code] before the call to Py_Initialize. Also check that your python 2.5.2 library contains a file site.py. | |
Re: You should try with a spawn instead of exec to see if it gives better results, or more information. | |
Re: Here is a code which should read your file and produce a python list of points. Check that it works. [code=python] colors = { "ST": "green", "SL": "red", "OP": "black", } point_colors = {} class Point(object): "class for point objects" def __init__(self, id, x, y, z): self.id = id self.x … | |
Re: Another way is to just distribute the python files and tell the users that the program depends on python and wxpython, which anyone can install. | |
Re: There are many ways to avoid all the global declarations in your program, for example you could put this at the top of your program [code=python] class var(object): shoes = 0 underwear = 0 bottoms = 0 tops = 0 bags = 0 # etc [/code] Then in the rest … | |
Re: I'm not sure that python 3.0 will be so different from the previous versions from the point of vue of the end user. You can already try python 2.6 wich was written as to incorporate many new features of python 3.0. Read the what's new at python.org [url]http://docs.python.org/whatsnew/2.6.html[/url] | |
Re: I suggest you try using a module like BeautifulSoup which contains functions to extract informations from html pages. See this link [url]http://www.crummy.com/software/BeautifulSoup/documentation.html[/url] | |
Re: Here is a possible code to generate the permutations of a number [code=python] def permutations(L): "generates all the permutations of a list" if len(L) == 1: yield L for i in xrange(len(L)-1, -1, -1): x, LL = L[i], L[:i] + L[i+1:] for p in permutations(LL): p = list(p) p.append(x) yield … | |
Re: I think the first ressource is the python documentation on the re module [url]http://www.python.org/doc/2.5.2/lib/module-re.html[/url]. For your specific question, what do you call "punctuation at the beginning or end of a word" ? | |
Re: You could use this, if you want to access the tuples [code=python] # select the tuples which first element is word selection = [item for item in tuplelist if item[0] == word] if selection: print word, "was found!" print selection else: print word, "was not found" [/code] However, a more … | |
Re: Writing [icode]line = x[i], resultat[/icode] defines line as the pair [icode](x[i], resultat)[/icode], whihc is a tuple and not a string. Python complains with [icode]line+ "\n"[/icode], which adds a tuple and a string. You could write [icode]"%s\n" % line[/icode] if you want to see the tuple in your output file. Otherwise … | |
Re: so the problem is the "even though i know the values and types are correct" part in your initial statement :) | |
![]() | Re: According to Guido Van Rossum's python regrets, you should better write [icode]sys.stdin.readline()[/icode] rather than [icode]raw_input()[/icode]. [url]http://www.python.org/doc/essays/ppt/regrets/PythonRegrets.pdf[/url] |
Re: Many packages can be found with google's help. What are you looking for ? | |
Re: That's because the current implementation uses the method [icode]__lt__[/icode] to sort (self < other). So you should implement this method. | |
Re: A solution is not to import your library xlwt but to start a child process which will import the library. You can then communicate with the child process through pipes, or using a module like pyro. When you are done with the xlwt, you terminate the child process and the … | |
Re: Here is a more pythonic approach [code=python] def getlist(file): nrlist = [] try: for line in file: n = float(line) nrlist.append(n) except ValueError: raise ValueError("Introdu data numerice!") return nrlist data = open("data.txt") list = getlist(data) print list [/code] Some remarks -- you don't need [icode]readline[/icode] to iterate over the lines … | |
Re: Perhaps you should start reading this other thread of the python forum [url]http://www.daniweb.com/forums/thread27561.html[/url]. Personnaly I'd say that python is the most productive programming language around. If you must learn a programming language, start with python. The language is here to stay, it's widely used. [url]www.python.org[/url] has a list of companies … | |
Re: If python says there is a syntax error, it means that you did something wrong. A good idea would be to ask python to tell us what your file really contains, so I suggest that you type this command in the python shell window [code=python] >>> open("HelloMP1.py").read() [/code] then please … | |
Re: why don't you just post Mod1 and Mod2, or attach them to your post ? | |
Re: Dive into python is a good tutorial [url]http://diveintopython.org/toc/index.html[/url] | |
Re: try this [code=python] some_list_A = [1, 2, 3] some_list_B = [11, 12, 13] li_A = ['companies'] + [str(item) for item in some_list_A] li_B = ['industries'] + [str(item) for item in some_list_B] print "li_A", li_A print "li_B", li_B li_C = zip(li_A, li_B) print "li_C", li_C data = [ list(item) for item … | |
Re: I think that you should first find how to enable or disable the port from a terminal, and then simply put your command in a call to [icode]os.system[/icode]. | |
Re: Yes you can, with [icode]os.chmod[/icode] like this [code=python] import os import stat try: # create a folder with mode 777 (octal) os.mkdir("montypython") # change mode to 577 os.chmod("montypython", 0577) # don't forget the 0 # get the current mode and print it print stat.S_IMODE(os.stat("montypython")[stat.ST_MODE]) finally: # in any case, attempt … | |
Re: I'd suggest a non recursive method using 2 sets like this one, which generates the cluster [code=python] class Grid(object): def floodFill(self, x, y, landUse): visited = set() todo = set([(x, y)]) while todo: x, y = todo.pop() if (x, y) in visited: continue visited.add((x, y)) if (x < 0 or … | |
Re: A way to handle nested lists is to treat them as trees where a list is a node and it's elements are other nodes (lists) or leafs (strings). In a tree (like in a folder tree for example), the position of an element is not given by an index, but … | |
Re: I'm surprised that nobody suggests to use the re module, like this [code=python] import re sentence = raw_input("Please type a sentence: ") first = raw_input("Please type the first word to find: ") last = raw_input("Please type the last word to find: ") pattern = re.compile( "%s(.*)%s" % (re.escape(first), re.escape(last)), re.DOTALL … | |
Re: [code=python] my_list = eval(open("filename").read().strip()) [/code] | |
Re: It's very simple, the [icode]if[/icode] statement looks like this [code=python] if expression: statements [/code] optionally followed by zero or more blocks like [code=python] elif expression: statements [/code] and finally zero ore only one block like [code=python] else: statements [/code] The "statements" part may contain other if statements, but for a … | |
Re: In this menu program, you're programming an automaton in fact. This automaton has nodes which represent states where your system can be, these states are "SystemMenu", "UserAccess", "UserDeleteAccess", "Exit". When you're in one of these states, a callback function is called to show a menu and then move to a … | |
Re: 32 or 64 means is your processor a 32 bits or a 64 bits. If you don't know, it's most certainly a 32 bits. ansi or unicode. I don't know if this is a reference to wxpython or to your OS. I think you should choose osx-unicode. The package does … | |
Re: I wrote a little code which takes your data and builds a regular expression to find the expressions in your list. The following code snippet will print the regex, so that you can see it and allow you to test it when you enter sentences. [code=python] # add reflections = … | |
Re: The assignment is ridiculous. Suppose Ms B sells 500 different items in her store, would she ask the quantity for each item ? |
The End.