2,646 Posted Topics
Re: One way to learn how to produce python byte code without python is to look in python's source code. See how the compile function is implemented in C, and it should give you a clue. Also I suppose that if you want to do the same from java, you should … | |
Re: It's because when python reads a file, it has a position in the file and it reads from this position. After the call to open, the position is at the beginning of the file, but after readlines(), the position is at the end of the file. You could do this … | |
Re: Here is my output on scilab, which is similar to matlab [code] -->V=[1,2,3,4]; -->V V = 1. 2. 3. 4. -->V(5)=10; -->V V = 1. 2. 3. 4. 10. [/code] I found the idea here [url]http://www.spas.cnrs-gif.fr/ScilabPasapas-Ch17Sc02.html#c[/url] | |
Re: I guess you should better change your password at gmail.com now :) | |
Re: Did you read this documentation [url]http://peak.telecommunity.com/DevCenter/EggFormats[/url] ? It seems that you need an EGG-INFO directory. I don't create python eggs, so I can't help you much, but I think reading this is the starting point. If you manage creating your egg, please post the key tricks here :) | |
Re: There is also a killer search form at the top of this page, you can type 'python gui" and hit the "Search Site" button. There are many threads with this same question in the python forum. | |
Re: Perhaps you should check this link [url]http://drj11.wordpress.com/2007/05/14/python-how-is-sysstdoutencoding-chosen/[/url] and change the environment variable LC_CTYPE (you should also check if you can change it in your program, using [icode]os.environ[/icode]). I can't test your problem here, because I'm having a french configuration, so the é prints well. By the way, if this is … | |
Re: I posted recently a piece of code where I read the output of a subprocess using a non blocking socket instead of a pipe (linux only, but should work on cygwin). Perhaps you could try this technique [url]http://www.daniweb.com/forums/post777876-19.html[/url]. There is also a nice link, which I posted in the same … | |
Re: Well, 1) [icode]list[/icode] is the name of a standard type in python (the type of list objects). A type is just a particular kind of object. 2) Since [icode]list[/icode] is a standard name, it should be avoided as the name of a variable (it's not an error, but it's a … | |
Re: May be this will work [code=python] try: range = xrange except NameError: pass def filenames(): for i in range(1, 1001): yield "output%d" % (i * 10000) def average_list(): result = [0.0] * 101 cntfiles = 0 for name in filenames(): cntfiles += 1 file_in = open(name) for index, line in … | |
Re: What's the point in writing your own chat program anyway ? What will it have that existing great chat programs don't have ? | |
Re: I was more successful with a slightly modified version. I modified the query string. Also, it's a good habit to always use strings prefixed by 'r' when you pass a literal string to re.compile. [code=python] #format the raw_input string for searching raw_string = re.compile(r' ') #search for a space in … | |
Re: I have a solution which allows you to use a persistent dictionary between different excecutions of your program, using the with statement (python >= 2.5). Here is an exemple program: [code=python] from __future__ import with_statement from persistent import PersistentDict def main(pdict): if not 'x' in pdict: pdict['x'] = 0 pdict['x'] … ![]() | |
Re: I don't think numpy supports arbitrary precision computations, so your determinant was probably computed using floating numbers and you have a round off error in the end. There are libraries for arbitrary precision in python, but they usually don't have a determinant function included. | |
Re: I'd suggest [code=python] file_in = open("data/%s.txt" % data) file_list = [] for line in file_in: item = line.split(",")[5] file_list.append(item) [/code] oops, somebody gave the solution before I did :) | |
Re: [icode].{100}[/icode] matches 100 non newline characters, unless you put [icode]re.DOTALL[/icode]. Also I don't understand your replacement string. I think the 0 matches found mean that none of your lines is 100 characters long. You could print a report of the lengths of the lines in your file like this [code=python] … | |
Re: You can use the subprocess module [code=python] import subprocess child = subprocess.Popen("myprog.py") [/code] see the documentation of this module. There are other ways to call your program; [code=python] child = subprocess.Popen("python myprog.py", shell=True) [/code] for example. | |
![]() | Re: if you add a line [icode]print(item)[/icode] before your line [icode]data = urllib.urlopen(item)[/icode] you might see why urlopen can't open the url. ![]() |
Re: It could be an indentation problem, but since you don't wrap your code in code tags as paulthom says above, it's difficult to see what's wrong. | |
Re: Instead of 7 variables row1, row2, etc, you could have one variable rows, which is an array of rows [code=python] rows = [ [' ' for i in range(7)] for j in range(7)] template = " %s |" * 7 def make_board(): for i in range(6, -1, -1): print(("%d |" … | |
Re: Here is my console output on Mandriva linux 2009: [code=python] Python 3.0 (r30:67503, Dec 9 2008, 13:32:06) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> [/code] I think that all library module names have been converted to lowercase in python 3.0. | |
Re: Your problem is called "input validation". Each time that you ask some input to the user, there is a high probability that the user enters unexpected input and your program must handle this (= validate input). Here you could use a test like this [code=python] answer = raw_input("> ") answer … | |
Re: You can change addbook like this [code=python] def addbook(ISBN, author, title, stock): if ISBN in booklist: booklist[ISBN][2] += stock else: booklist[ISBN] = [author, title, stock] [/code] | |
Re: You should try [icode]if repetition in (2, 5, 8, 11):[/icode] | |
Re: Q2 for an expression like text[start: stop: step], if text is a string, it will return a string whith the characters text[start], text[start+step], text[start+2*step], etc, as long as start + k*step < stop if step is > 0 and start + k*step > stop if step < 0. When start … | |
Re: I quote the python 3.0 documentation: "If the subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread." So I think you should start your class like this [code=python] class UpdateLabels(Thread):#activates in main...did not work? def __init__(self): Thread.__init__(self) … | |
Re: It's because the builtin function open can only open a file in your filesystem and not an url. If you want to rewrite a file in your website, you should first write a file in your local file system and then use ftp or some other protocol to copy the … | |
Re: This seems to be a fix in the C++ source code of wxWidget. If you want to use this fix, you must recompile wxWidget yourself. This is not normally a solution for the end user. If this link really describes your problem, you will have to wait that the fix … | |
Re: You changed the indentation of [icode]for subelement in element:[/icode]. | |
Re: I can't resist giving you a sexy solution [code=python] import sys import webbrowser import cgitb def output_exc(): f = open("exception.html", "w") f.write(cgitb.html(sys.exc_info())) f.close() webbrowser.get("firefox").open("exception.html") # or webbrowser.open("exception.html") if you don't use firefox class incomplete: def __init__(self): self.first = 1 self.second = 2 i = incomplete() try: print i.first print i.second … | |
Re: [QUOTE=paulthom12345;782620] [code=python] file_in = open("myfile.txt", "r") allfile = '' for line in file_in: allfile += line [/code] [/QUOTE] why don't you just use [icode]allfile=file_in.read()[/icode] ? | |
What do you think would be the best way to write this structure [code=python] if testA: actionA() if testB: actionB() if textC: actionC() else: actionDefault() else: actionDefault() else: actionDefault() [/code] if I want to write only one call to actionDefault() ? | |
Re: try this [code=python] #Python code: import csv # first we need import necessary lib:csv file=open("dinesh.csv", "w") #prepare a csv file for our example testWriter = csv.writer(file, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) testWriter.writerow(['Test'] * 5 + ['Wow']) file.close() [/code] | |
Re: LINUX only possible solution: On linux, there is the standard module [inlinecode]commands[/inlinecode] so you could write [code=python] from commands import getstatusoutput cmd = "myAppli arg1 arg2 arg3" status, output = getstatusoutput(cmd) if not status: ... # process output else: raise Exception("command '%s' failed with exist status '%s'" % (cmd, status)) … | |
Re: I agree with Sillyboy, sum is not a syntax, it's a function which applies to a sequence. Here I think that the expression that you put in the sum is the value of your investment, so you can simply drop the sum. However I think your program is confusing because … | |
Re: There should be something here [icode]CHAR, ? CHAR)" (t_name, t_date[/icode] between the string and the opening parenthesis :) | |
Re: Here is another one (faster ?) [code=python] #!/usr/bin/env python import re def main(): regexes = [ re.compile(x) for x in (r"[^A-Z]+", r"[^a-z]+", r"[^0-9]+", r"[^\ ]+")] filename = "test.txt" content = open(filename).read() counts = [len(s) for s in (r.sub("", content) for r in regexes)] print("""There are %d uppercase letters %d lowercase … | |
Re: There's a built-in [icode]reload[/icode] function. It takes a module object as it's argument, so you can use [icode]reload(sys.modules["kitten"])[/icode] or [code=python] import kittens reload(kittens) [/code] It works only for python modules, not for shared libraries. | |
Re: Here is how you could write this [code=python] def create_message(message, msgstr): if msgstr[0:3].upper() == 'CMD': return message(msgstr) elif msgstr[0:3].upper() == 'RSP': return message(msgstr) elif msgstr[0:3].upper() == 'IND': return message(msgstr) elif msgstr[0:3].upper() not in 'CMDRSPIND': print "Miscellaneous message has been found with details", msgstr else: pass class message(object): def __init__(self, msgstr): … | |
Re: I suggest this if you want to see the pdf file [code=python] import webbrowser webbrowser.open("http://fetac.ie/MODULES/D20120.pdf") [/code] | |
In python, a "function object", that is to say an object which can be called as a function, is simply an instance of a class which has a [icode]__call__[/icode] method. An example is [code=python] class FuncObj(object): def __call__(self, *args): print("args were %s." % str(args)) func = FuncObj() func(1,2,3) # output … | |
Re: In fact, if you issue the command [icode]pydoc -w pkg1.pkg2[/icode], it will generate your [icode]pkg1.pkg2.html[/icode]. After [icode]pydoc -w[/icode], you must not put the path of a file or a directory, but the module path of a python module as if you were importing it in python with [icode]import pkg1.pkg2[/icode]. Now … | |
Re: I don't think you really need a tutorial. Start like this [code=python] >>> from wx.lib.mixins import listctrl >>> help(listctrl) [/code] Note that the help for the class [icode]TextEditMixin[/icode] shows you how to use the mixin class. You should try each mixin class in the same way, and then try to … | |
Re: Your cars are initialized with a speed of 0, 0. You should call their [icode]set_speed[/icode] method to define another value. If you don't start the cars, they won't move ! | |
Re: One day we should write the ultimate hangman program in this forum. It looks like a recurrent theme in CS classes :) | |
Re: I think you should copy the list like this [code=python] class MSULinkExtractor(htmllib.HTMLParser): ... def get_links(self): print '\tMSULinkExtractor.get_links has been called' return list(self.links) ... [/code] | |
Re: You could try [icode]print(set(img_I))[/icode] to see all the colors contained in your image. | |
Re: The pydoc module (used by the function 'help') finds all definitions in a module and produces text or html documentation. I read that it does this by importing the module first and then using objects introspection. If you look at the code of [icode]pydoc.py[/icode] in your standard library, you should … | |
Re: [QUOTE=jlm699;772442]Try out [URL="http://code.activestate.com/recipes/148061/"]this guy[/URL][/QUOTE] One of the comment of this snippet says that there is a standard module [icode]textwrap[/icode]. I think it will do a better job. | |
Re: Python is a high level object oriented programming language created at the beginning of the 90's bu Guido Van Rossum. Python allows for fast software development, which is the main reason of its success. The official site of the language is [url]www.python.org[/url]. |
The End.