Forum: Python 2 Days Ago |
| Replies: 3 Views: 61 Re: UnboundLocalError The local namespace of a method doesnt see the namespace of the class. Inside a method, you can only access the variables from the local namespace and the variables defined at module level. So your... |
Forum: Python 2 Days Ago |
| Replies: 6 Views: 119 Re: Regular expressions It's because the items in root.getchildren are not strings but Element objects. You could replace the end of your program with
root= tree.getroot()
text = root.getchildren()
expr =... |
Forum: Python 3 Days Ago |
| Replies: 30 Views: 1,070 |
Forum: Python 3 Days Ago |
| Replies: 6 Views: 119 Re: Regular expressions Well, in the regular expression language, the string "<Element ([^\s]+)" means the character < followed by the character E ... followed by t followed by a single space followed by a group (...)... |
Forum: Python 3 Days Ago |
| Replies: 6 Views: 119 Re: Regular expressions Here is a way
import re
data = """
<Element Generation at d66238>
<Element Vitals at d662b0>
<Element Network at d66670>
<Element Hardware at d66eb8>
<Element Memory at d6ac88> |
Forum: Python 4 Days Ago |
| Replies: 0 Views: 100 Downloading thread code. The following program is able to download the python programs contained in a thread of the python forum. Just start the program, it will prompt you for the thread number and create a directory with... |
Forum: Python 8 Days Ago |
| Replies: 17 Views: 364 |
Forum: Python 9 Days Ago |
| Replies: 17 Views: 364 |
Forum: Python 10 Days Ago |
| Replies: 9 Views: 271 Re: wxTreeCtrl - Load Tree structure from file Sorry, there is a syntax error in the code above. You should replace
@staticmethod readCtrl(ctrl):
by
@staticmethod
def readCtrl(ctrl):
However, since the code is untested, it's most... |
Forum: Python 10 Days Ago |
| Replies: 2 Views: 151 Re: Python Counterpart? I would say the pickle or shelve modules :) ... I found this with google, which might be interesting http://www.evilchuck.com/2008/02/tell-python-to-shove-it.html |
Forum: Python 10 Days Ago |
| Replies: 9 Views: 271 Re: wxTreeCtrl - Load Tree structure from file I would suggest something like this, with the pickle module (completely untested)
import pickle
class Tree(object):
# a tree class, with a single root (a Node object)
def __init__(self):
... |
Forum: Python 10 Days Ago |
| Replies: 4 Views: 209 Re: Reading XML data I suggest a generator
def find_text(element):
if element.text is None:
for subelement in element:
for txt in find_text(subelement):
yield txt
else:
... |
Forum: Python 10 Days Ago |
| Replies: 2 Views: 107 Re: Python Newbie is frustrated Here is how you could do this
import random
result = 0
while True: # means forever
roll = random.randint(1, 10)
result += roll
if roll != 10:
break
print result |
Forum: Python 12 Days Ago |
| Replies: 1 Views: 185 Re: Parsing in Python A nice module is ply which has the functionality of the lex and yacc tools but with a pure python implementation. It might not be the fastest parser in python, but I think it's a very good starting... |
Forum: Python 13 Days Ago |
| Replies: 3 Views: 160 |
Forum: Python 25 Days Ago |
| Replies: 2 Views: 132 |
Forum: Python 28 Days Ago |
| Replies: 30 Views: 1,070 Re: Python and Linux Assuming theOutput is a string, you could write
if theOutput == "10.0.0.2":
print("correct")
else:
print("incorrect") |
Forum: Python 28 Days Ago |
| Replies: 1 Views: 107 Re: help! There is a full course on biopython from the Pasteur institute which includes reading Fasta format http://www.pasteur.fr/recherche/unites/sis/formation/python/ch11s03.html#exa_seq_string
I think you... |
Forum: Python 29 Days Ago |
| Replies: 40 Views: 829 Re: Text games are frustrating! I cleaned up your code a while. Here is a code that runs. Compare the details with your version to understand how it works.
#!/usr/bin/env python
import random
class monster(object):
def... |
Forum: Python 29 Days Ago |
| Replies: 40 Views: 829 Re: Text games are frustrating! Also, your methods getAttribute info in troll and orc return None instead of what they should return. You shoud write
def getAttributeInfo(self):
return monster.getAttributeInfo(self) |
Forum: Python 29 Days Ago |
| Replies: 40 Views: 829 Re: Text games are frustrating! You must not call sword.getAttributeInfo2() because sword is a class and getAttributeInfo2 is an instance method. It applies to an instance (an object). Here, your sword object is self.weapon, so you... |
Forum: Python 29 Days Ago |
| Replies: 30 Views: 1,070 Re: Python and Linux Instead of printing the repr of the string you can write
print("> theOutput was")
print (theOutput)
the % is a string formatting operation. |
Forum: Python 29 Days Ago |
| Replies: 30 Views: 1,070 Re: Python and Linux Here is a complete example:
# FILE fooo.py
import sys
s = sys.stdin.read()
print s.upper()
raise Exception
# FILE bar.py
import subprocess as SP |
Forum: Python 29 Days Ago |
| Replies: 30 Views: 1,070 Re: Python and Linux communicate reads data from the subprocess stdout and stderr. It returns a pair of strings, so output = p2.communicate()[0] means wait until the child process is done and read the output which it... |
Forum: Python 29 Days Ago |
| Replies: 40 Views: 829 Re: Text games are frustrating! If you want to test code, I gave an example of how you could do this with doctest, here http://www.daniweb.com/forums/thread146672.html
Programming with tests is a very efficient method. |
Forum: Python 30 Days Ago |
| Replies: 40 Views: 829 Re: Text games are frustrating! An alternative to changing the method's name is this
class Troll(Monster):
def getAttributesInfo(self):
Monster.getAttributesInfo(self)
It's a standard way of overloading a method in... |
Forum: Python 30 Days Ago |
| Replies: 9 Views: 222 Re: Opening a file You say it doesn't open, but in that case there must be an exception traceback. What is the exception traceback ? |
Forum: Python 31 Days Ago |
| Replies: 7 Views: 369 Re: compare string from file Here is a way
def createData2():
L = [line.strip() for line in open("data.txt")]
L = [line for line in L if line]
data2 = open("data2.txt", "w")
data2.write(" ".join(L))
... |
Forum: Python 31 Days Ago |
| Replies: 6 Views: 434 Re: Read number of pages in PDF files I installed the program pdftk (on my linux distribution, it was a package). I think you can be interested in this little script
import os
from os.path import join as pjoin, expanduser
import... |
Forum: Python 32 Days Ago |
| Replies: 10 Views: 378 |
Forum: Python 32 Days Ago |
| Replies: 10 Views: 378 |
Forum: Python 34 Days Ago |
| Replies: 4 Views: 197 Re: Why Isn't This Working? I would suggest lists like this
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)]
Then you can use... |
Forum: Python 34 Days Ago |
| Replies: 6 Views: 250 |
Forum: Python 34 Days Ago |
| Replies: 7 Views: 222 Re: Superscribe and subscribe 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. |
Forum: Python Oct 30th, 2008 |
| Replies: 8 Views: 259 Re: C to Python Translation anyone? A word to word translation would go like this
def traverse(p):
if not p:
return
traverse(p.lokid)
if p.splitchar:
traverse(p.eqkid)
else:
print(p.eqkid) |
Forum: Python Oct 30th, 2008 |
| Replies: 2 Views: 120 Re: Quick Question.... socket 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... |
Forum: Python Oct 30th, 2008 |
| Replies: 4 Views: 184 Re: Strange list.append() results The effect of list(dice) is the same as dice[:]: it returns a copy of the list. It's important to understand that python methods manipulate references to python objects. When you write dice =... |
Forum: Python Oct 29th, 2008 |
| Replies: 4 Views: 184 Re: Strange list.append() results There is nothing strange, the shuffle happens in place, so rolls contains 3 references to the same list. You should write rolls.append(list(dice)) if you want to keep the intermediary states of the... |
Forum: Python Oct 29th, 2008 |
| Replies: 4 Views: 243 Re: Batch Processing An easy way of communication is the pyro module. pyro stands for Python Remote Objects, it allows a process to register a python object in a name server and other processes to obtain proxies for the... |
Forum: Python Oct 29th, 2008 |
| Replies: 4 Views: 171 |