2,646 Posted Topics

Member Avatar for bvrclvr1
Member Avatar for lllllIllIlllI
0
192
Member Avatar for SoulMazer
Member Avatar for SoulMazer
0
85
Member Avatar for drjekil

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 !

Member Avatar for Gribouillis
0
87
Member Avatar for sandmonkey

You say it doesn't open, but in that case there must be an exception traceback. What is the exception traceback ?

Member Avatar for sandmonkey
0
120
Member Avatar for iamoldest

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.

Member Avatar for tomtetlaw
0
175
Member Avatar for tomtetlaw

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

Member Avatar for tomtetlaw
0
2K
Member Avatar for Stefano Mtangoo
Member Avatar for mathijs
0
239
Member Avatar for massivefermion

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.

Member Avatar for massivefermion
0
155
Member Avatar for mece

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]

Member Avatar for mece
0
779
Member Avatar for blackrobe

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

Member Avatar for tyincali
0
159
Member Avatar for Clipper34

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

Member Avatar for Gribouillis
0
134
Member Avatar for Lardmeister

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.

Member Avatar for Gribouillis
0
142
Member Avatar for pyth0n

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

Member Avatar for woooee
0
82
Member Avatar for pyth0n

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 …

Member Avatar for pyth0n
0
106
Member Avatar for Azurea
Member Avatar for pyth0n

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

Member Avatar for pyth0n
0
5K
Member Avatar for doeman

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 …

Member Avatar for ZZucker
0
100
Member Avatar for johnyboy82

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.

Member Avatar for Gribouillis
0
2K
Member Avatar for malcolm4458

You should try with a spawn instead of exec to see if it gives better results, or more information.

Member Avatar for jlm699
0
3K
Member Avatar for srinivasanb4u

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 …

Member Avatar for srinivasanb4u
0
238
Member Avatar for vmars

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.

Member Avatar for jlm699
0
291
Member Avatar for mruane

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 …

Member Avatar for mruane
0
300
Member Avatar for kenji

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]

Member Avatar for Ene Uran
0
402
Member Avatar for luke77

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]

Member Avatar for Gribouillis
0
126
Member Avatar for luke77

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 …

Member Avatar for luke77
0
124
Member Avatar for jcafaro10

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" ?

Member Avatar for ZZucker
0
124
Member Avatar for Devlan

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 …

Member Avatar for Devlan
0
142
Member Avatar for MaxManus

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 …

Member Avatar for MaxManus
0
144
Member Avatar for danfi766

so the problem is the "even though i know the values and types are correct" part in your initial statement :)

Member Avatar for Gribouillis
0
114
Member Avatar for Chemist

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]

Member Avatar for Gribouillis
0
139
Member Avatar for massivefermion
Member Avatar for Gribouillis
0
160
Member Avatar for jcafaro10

That's because the current implementation uses the method [icode]__lt__[/icode] to sort (self < other). So you should implement this method.

Member Avatar for Gribouillis
0
106
Member Avatar for rajaram_l20

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 …

Member Avatar for Gribouillis
0
85
Member Avatar for crazzym

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 …

Member Avatar for crazzym
0
165
Member Avatar for Amisha_Sharma

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 …

Member Avatar for Stefano Mtangoo
0
79
Member Avatar for vmars

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 …

Member Avatar for sneekula
0
114
Member Avatar for dinilkarun
Member Avatar for dinilkarun
0
252
Member Avatar for jcafaro10

Dive into python is a good tutorial [url]http://diveintopython.org/toc/index.html[/url]

Member Avatar for lllllIllIlllI
0
99
Member Avatar for laspal

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 …

Member Avatar for woooee
0
107
Member Avatar for pravdexter

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

Member Avatar for pravdexter
0
108
Member Avatar for knish

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 …

Member Avatar for jlm699
0
146
Member Avatar for tillaart36

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 …

Member Avatar for tillaart36
0
900
Member Avatar for Dart82

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 …

Member Avatar for Gribouillis
0
138
Member Avatar for Dart82

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 …

Member Avatar for Dart82
0
110
Member Avatar for god0fgod
Member Avatar for Gribouillis
0
349
Member Avatar for SitiSlicker

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 …

Member Avatar for sneekula
0
2K
Member Avatar for Andymoore88

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 …

Member Avatar for Andymoore88
0
201
Member Avatar for vmars

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 …

Member Avatar for Stefano Mtangoo
0
167
Member Avatar for dr_hamburger

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

Member Avatar for lllllIllIlllI
0
140
Member Avatar for alleycot

The assignment is ridiculous. Suppose Ms B sells 500 different items in her store, would she ask the quantity for each item ?

Member Avatar for Ancient Dragon
1
266

The End.